|
From: <pb...@us...> - 2007-03-27 11:13:36
|
Revision: 237
http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=237&view=rev
Author: pbb72
Date: 2007-03-27 04:13:31 -0700 (Tue, 27 Mar 2007)
Log Message:
-----------
changed id values to avoid conflicts, added home and glossary buttons, more renaming, further conversion imageloader, fixed regex's
Modified Paths:
--------------
trunk/plugins/Documentation plugin/Documentation.cs
trunk/plugins/Documentation plugin/DocumentationImage.cs
trunk/plugins/Documentation plugin/DocumentationPage.cs
trunk/plugins/Documentation plugin/skin/Documentation.xml
Modified: trunk/plugins/Documentation plugin/Documentation.cs
===================================================================
--- trunk/plugins/Documentation plugin/Documentation.cs 2007-03-27 11:06:38 UTC (rev 236)
+++ trunk/plugins/Documentation plugin/Documentation.cs 2007-03-27 11:13:31 UTC (rev 237)
@@ -45,23 +45,29 @@
{
#region SkinControls
// map skin controls to member variables
- [SkinControlAttribute(10)]
+ [SkinControlAttribute(981)]
+ protected GUIButtonControl buttonHome = null;
+ [SkinControlAttribute(982)]
+ protected GUIButtonControl buttonGlossary = null;
+ [SkinControlAttribute(983)]
protected GUIButtonControl buttonOpen = null;
- [SkinControlAttribute(14)]
- protected GUIButtonControl buttonBack = null;
- [SkinControlAttribute(12)]
+ [SkinControlAttribute(984)]
+ protected GUIButtonControl buttonSearch = null;
+ [SkinControlAttribute(985)]
+ protected GUIButtonControl buttonPrevious = null;
+ [SkinControlAttribute(986)]
+ protected GUIButtonControl buttonText = null;
+ [SkinControlAttribute(987)]
protected GUIButtonControl buttonLinks = null;
- [SkinControlAttribute(13)]
+ [SkinControlAttribute(988)]
protected GUIButtonControl buttonImages = null;
-
- [SkinControlAttribute(4)]
- protected GUILabelControl searchtermLabel = null;
- [SkinControlAttribute(5)]
- protected GUILabelControl imagedescLabel = null;
- [SkinControlAttribute(20)]
+ [SkinControlAttribute(989)]
+ protected GUILabelControl labelPagename = null;
+ [SkinControlAttribute(990)]
+ protected GUILabelControl labelImagename = null;
+ [SkinControlAttribute(991)]
protected GUITextControl txtArticle = null;
-
- [SkinControlAttribute(25)]
+ [SkinControlAttribute(992)]
protected GUIImage imageControl = null;
#endregion
@@ -190,6 +196,16 @@
GetAndDisplayArticle(_currentPage);
}
}
+ if (control == buttonHome)
+ {
+ _currentPage = string.Empty;
+ GetAndDisplayArticle(_currentPage);
+ }
+ if (control == buttonGlossary)
+ {
+ _currentPage = "glossary";
+ GetAndDisplayArticle(_currentPage);
+ }
// The Button holding the Links to other articles
if (control == buttonLinks)
{
@@ -211,7 +227,7 @@
pDlgOK.DoModal(GetID);
if (pDlgOK.SelectedLabel >= 0)
{
- _currentPage = _linkValues[pDlgOK.SelectedId-1].ToString()
+ _currentPage = _linkValues[pDlgOK.SelectedId-1].ToString();
Log.Info(_PluginName + ": new search from the links array: {0}", _currentPage);
GetAndDisplayArticle(_currentPage);
}
@@ -250,10 +266,10 @@
if (pDlgOK.SelectedLabel >= 0)
{
Log.Info(_PluginName + ": new search from the image array: {0}",
- _imageLabels[pDlgOK.SelectedId - 1]);
- GetAndDisplayImage(_currentPage,
- _imageLabels[pDlgOK.SelectedId - 1].ToString(),
- _imageValues[pDlgOK.SelectedId - 1].ToString());
+ _imageValues[pDlgOK.SelectedId - 1]);
+ GetAndDisplayImage(_currentPage,
+ _imageValues[pDlgOK.SelectedId - 1].ToString(),
+ _imageLabels[pDlgOK.SelectedId - 1].ToString());
}
}
}
@@ -268,25 +284,25 @@
}
}
// Back to the text button to switch from image view
- if (control == buttonBack)
+ if (control == buttonText)
{
if (!txtArticle.IsVisible)
GUIControl.ShowControl(GetID, txtArticle.GetID);
if (imageControl.IsVisible)
GUIControl.HideControl(GetID, imageControl.GetID);
- if (!searchtermLabel.IsVisible)
- GUIControl.ShowControl(GetID, searchtermLabel.GetID);
- if (imagedescLabel.IsVisible)
- GUIControl.HideControl(GetID, imagedescLabel.GetID);
- if (buttonBack.IsVisible)
- GUIControl.HideControl(GetID, buttonBack.GetID);
+ if (!labelPagename.IsVisible)
+ GUIControl.ShowControl(GetID, labelPagename.GetID);
+ if (labelImagename.IsVisible)
+ GUIControl.HideControl(GetID, labelImagename.GetID);
+ if (buttonText.IsVisible)
+ GUIControl.HideControl(GetID, buttonText.GetID);
}
base.OnClicked(controlId, control, actionType);
}
- private void GetAndDisplayImage(string pagename, string imagename, string imagedesc)
+ private void GetAndDisplayImage(string pagename, string imagefile, string imagename)
{
- DocumentationImage image = new DocumentationImage(pagename, imagename);
+ DocumentationImage image = new DocumentationImage(pagename, imagefile);
string imagefilename = image.GetImageFilename();
Log.Info(_PluginName + ": Trying to display image file: {0}", imagefilename);
@@ -296,13 +312,13 @@
GUIControl.HideControl(GetID, txtArticle.GetID);
if (!imageControl.IsVisible)
GUIControl.ShowControl(GetID, imageControl.GetID);
- if (searchtermLabel.IsVisible)
- GUIControl.HideControl(GetID, searchtermLabel.GetID);
- if (!imagedescLabel.IsVisible)
- GUIControl.ShowControl(GetID, imagedescLabel.GetID);
- if (!buttonBack.IsVisible)
- GUIControl.ShowControl(GetID, buttonBack.GetID);
- imagedescLabel.Label = imagedesc;
+ if (labelPagename.IsVisible)
+ GUIControl.HideControl(GetID, labelPagename.GetID);
+ if (!labelImagename.IsVisible)
+ GUIControl.ShowControl(GetID, labelImagename.GetID);
+ if (!buttonText.IsVisible)
+ GUIControl.ShowControl(GetID, buttonText.GetID);
+ labelImagename.Label = imagename;
imageControl.SetFileName(imagefilename);
}
else
@@ -340,15 +356,15 @@
GUIControl.ShowControl(GetID, txtArticle.GetID);
if (imageControl.IsVisible)
GUIControl.HideControl(GetID, imageControl.GetID);
- if (!searchtermLabel.IsVisible)
- GUIControl.ShowControl(GetID, searchtermLabel.GetID);
- if (imagedescLabel.IsVisible)
- GUIControl.HideControl(GetID, imagedescLabel.GetID);
- if (buttonBack.IsVisible)
- GUIControl.HideControl(GetID, buttonBack.GetID);
+ if (!labelPagename.IsVisible)
+ GUIControl.ShowControl(GetID, labelPagename.GetID);
+ if (labelImagename.IsVisible)
+ GUIControl.HideControl(GetID, labelImagename.GetID);
+ if (buttonText.IsVisible)
+ GUIControl.HideControl(GetID, buttonText.GetID);
_linkLabels.Clear();
_imageLabels.Clear();
- searchtermLabel.Label = e.Argument.ToString();
+ labelPagename.Label = e.Argument.ToString();
DocumentationPage page =
new DocumentationPage(e.Argument.ToString());
_pageText = page.text;
@@ -368,4 +384,4 @@
volatile bool _workerCompleted = true;
}
-}
+}
\ No newline at end of file
Modified: trunk/plugins/Documentation plugin/DocumentationImage.cs
===================================================================
--- trunk/plugins/Documentation plugin/DocumentationImage.cs 2007-03-27 11:06:38 UTC (rev 236)
+++ trunk/plugins/Documentation plugin/DocumentationImage.cs 2007-03-27 11:13:31 UTC (rev 237)
@@ -42,107 +42,53 @@
/// </summary>
public class DocumentationImage
{
+ private string PluginName = "Documentation";
private string ImageURL = "http://wiki.team-mediaportal.com/{0}?action=AttachFile&do=get&target={1}";
private string pagename = string.Empty;
- private string imagename = string.Empty;
+ private string imagefile = string.Empty;
private string imagedesc = string.Empty;
- private string imageurl = string.Empty;
private string imagelocal = string.Empty;
- /// <summary>This constructor creates a new WikipediaImage</summary>
+ /// <summary>This constructor creates a new Image</summary>
/// <summary>The name of the image need to be given</summary>
- /// <param name="imagename">The internal name of the image like "Bild_478.jpg" in "http://de.wikipedia.org/wiki/Bild:Bild_478.jpg"</param>
- public DocumentationImage(string pagename, string imagename)
+ public DocumentationImage(string pagename, string imagefile)
{
this.pagename = pagename;
- this.imagename = imagename;
- GetImageUrl();
+ this.imagefile = imagefile;
GetImageFile();
}
- /// <summary>Getting the link to the full-size image.</summary>
- private void GetImageUrl()
+ /// <summary>Downloads the full-size image from the wiki</summary>
+ private void GetImageFile()
{
- string imagepage = string.Empty;
+ System.Uri url = new System.Uri(String.Format(ImageURL, this.pagename, this.imagefile));
+ //Check if we already have the file.
+ string thumbspath = Config.GetSubFolder(Config.Dir.Thumbs, @"mpwiki\");
- // Build the URL to the Image page
- System.Uri url = new System.Uri(String.Format(ImageURL, this.pagename, this.imagename));
- Log.Info("Wikipedia: Trying to get following Image page: {0}", url.ToString());
+ //Create the mpwiki subdir in thumbs when it not exists.
+ if (!System.IO.Directory.Exists(thumbspath))
+ System.IO.Directory.CreateDirectory(thumbspath);
- // Here we get the content from the web and put it to a string
- try
+ if (!System.IO.File.Exists(thumbspath + imagefile))
{
- WebClient client = new WebClient();
- client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
- Stream data = client.OpenRead(url);
- StreamReader reader = new StreamReader(data);
- imagepage = reader.ReadToEnd();
- reader.Close();
- Log.Info("Wikipedia: Success! Downloaded all data from the image page.");
- }
- catch (Exception e)
- {
- Log.Info("Wikipedia: Exception during downloading image page:");
- Log.Info(e.ToString());
- }
- //We're searching for something like this:
- //<div class="fullImageLink" id="file"><a href="http://upload.wikimedia.org/wikipedia/commons/7/7d/Bild_478.jpg">
- if (imagepage.IndexOf("class=\"fullImageLink\"") >= 0)
- {
- Log.Info("Wikipedia: Extracting link to full-size image.");
- int iStart = imagepage.IndexOf("class=\"fullImageLink\"");
- imagepage = imagepage.Substring(iStart, 1000);
-
- iStart = imagepage.IndexOf("href") + 6;
- int iEnd = imagepage.IndexOf("\"", iStart);
-
- this.imageurl = imagepage.Substring(iStart, iEnd - iStart);
- Log.Info("Wikipedia: URL of full-size image extracted.");
- Log.Info(imageurl);
- }
- else
- this.imageurl = string.Empty;
- }
-
- /// <summary>Downloads the full-size image from the wikipedia page</summary>
- private void GetImageFile()
- {
- if (imageurl != "")
- {
- //Check if we already have the file.
- string thumbspath = Config.GetSubFolder(Config.Dir.Thumbs, @"wikipedia\");
-
- //Create the wikipedia subdir in thumbs when it not exists.
- if (!System.IO.Directory.Exists(thumbspath))
- System.IO.Directory.CreateDirectory(thumbspath);
-
- if (!System.IO.File.Exists(thumbspath + imagename))
+ Log.Info(PluginName + ": Trying to get following URL: {0}", url);
+ // Here we get the image from the web and save it to disk
+ try
{
-
- Log.Info("Wikipedia: Trying to get following URL: {0}", imageurl);
- // Here we get the image from the web and save it to disk
- try
- {
- WebClient client = new WebClient();
- client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
- client.DownloadFile(imageurl, thumbspath + imagename);
- Log.Info("Wikipedia: Success! Image downloaded.");
- }
- catch (Exception e)
- {
- Log.Info("Wikipedia: Exception during downloading:");
- Log.Info(e.ToString());
- }
+ WebClient client = new WebClient();
+ client.DownloadFile(url, thumbspath + imagefile);
+ Log.Info(PluginName + ": Success! Image downloaded.");
}
- else
+ catch (Exception e)
{
- Log.Info("Wikipedia: Image exists, no need to redownload!");
+ Log.Info(PluginName + ": Exception during downloading:");
+ Log.Info(e.ToString());
}
}
else
{
- Log.Info("Wikipedia: No imageurl. Can't download file.");
+ Log.Info(PluginName + ": Image exists, no need to redownload!");
}
}
@@ -150,10 +96,10 @@
/// <returns>String: filename of the downloaded image.</returns>
public string GetImageFilename()
{
- string imagelocal = Config.GetFile(Config.Dir.Thumbs, @"wikipedia\" + imagename);
+ string imagelocal = Config.GetFile(Config.Dir.Thumbs, @"mpwiki\" + imagefile);
return imagelocal;
}
}
-}
+}
\ No newline at end of file
Modified: trunk/plugins/Documentation plugin/DocumentationPage.cs
===================================================================
--- trunk/plugins/Documentation plugin/DocumentationPage.cs 2007-03-27 11:06:38 UTC (rev 236)
+++ trunk/plugins/Documentation plugin/DocumentationPage.cs 2007-03-27 11:13:31 UTC (rev 237)
@@ -132,10 +132,14 @@
this.text = Regex.Replace(this.text, @"\[(?<url>http://[^ \]]+)(?: (?<label>[^\]]+))?\]",
new MatchEvaluator(StripElements));
+ // prevent camelcase links in code ({{{...}}})
+ this.text = Regex.Replace(this.text, @"{{{[^(?:}}})]}}}", new MatchEvaluator(StripElements));
+
// wikilinks
// this needs to be in one big regex, to maintain their order in the document
this.text = Regex.Replace(this.text,
// enclosed, labelled links ([:page name], [:pagename:link text])
+ // TODO: subpage
@"\[:(?<page>[^:\]]+)(?::(?: |\t)*(?<label>[^\]]+))?\]"
// wiki-labelled links ([wiki:pagename], [wiki:pagename link text])
+ "|" + @"\[wiki:(?<page>[^ \]]+)(?: (?<label>[^\]]+))?\]"
@@ -150,16 +154,17 @@
// re-insert elements
this.text = Regex.Replace(this.text, @"{elm(?<index>[^}]+)}", new MatchEvaluator(ReturnElements));
- Log.Info(_PluginName + ": General replacements.");
+ //Log.Info(_PluginName + ": General replacements.");
// de-linked camelcase (!PageName)
this.text = Regex.Replace(this.text, @"(?<=\W)!((?:[A-Z][a-z0-9]+){2,})(?=\W)",
"$1");
// tables (|| cell 1 || cell 2 ||)
- this.text = Regex.Replace(this.text, @"\|{2,}<[^>]*>", "|");
+ this.text = Regex.Replace(this.text, @"(?<=\r\n) *\|\|.*?\|\|(?:\r\n|$)(?!\|)",
+ new MatchEvaluator(ParseTables), RegexOptions.Singleline);
// TODO: numbered lists (1., 1., 1., ...)
-
+
// single linebreaks in code, except ones around headers and tables
//this.text = Regex.Replace(this.text, @"(?<!\r\n|=|\|)\r\n(?!\r\n|=|\|)", " ");
@@ -167,6 +172,12 @@
this.text = Regex.Replace(this.text, @"(?:\r\n){2,}",
Environment.NewLine + Environment.NewLine);
+ // excessive spaces
+ this.text = Regex.Replace(this.text, @" {2,}", " ");
+
+ // indents (just removed) ( . indented line)
+ this.text = Regex.Replace(this.text, @"(?<=\r\n)[ \.]*(.*) *(?=\r\n)", "$1");
+
// whitespace around titles
//this.text = Regex.Replace(this.text, @"(?:\r\n)+(=.+=)(?:\r\n)+",
// Environment.NewLine + Environment.NewLine + "$1" + Environment.NewLine);
@@ -183,8 +194,8 @@
private string StripElements ( Match m )
{
- Log.Info(_PluginName + ": Strip element " + m.Value);
- Log.Info("match found at " + m.Index);
+ //Log.Info(_PluginName + ": Strip element " + m.Value);
+ //Log.Info("match found at " + m.Index);
if (m.Groups["header"].Value != "")
{
// headers
@@ -202,6 +213,7 @@
else if (m.Groups["page"].Value != "")
{
// wiki links
+ //Log.Info("wiki link found");
string label = m.Groups["label"].Value;
string page = m.Groups["page"].Value;
if (label == "") label = page;
@@ -217,7 +229,7 @@
if (!linkLabels.Contains(label))
{
linkLabels.Add(label);
- linkValues.Add(m.Groups["page"].Value);
+ linkValues.Add(page);
}
elms.Add("<" + label + "(" + (linkLabels.IndexOf(label)+1) + ")>");
}
@@ -246,6 +258,10 @@
}
elms.Add("[" + img + "(" + (imageLabels.IndexOf(img)+1) + ")]");
}
+ else
+ {
+ elms.Add(m.Value);
+ }
return "{elm" + (elms.Count-1) + "}";
}
@@ -254,5 +270,14 @@
return elms[ Int32.Parse( m.Groups["index"].Value ) ].ToString();
}
+ private string ParseTables ( Match m )
+ {
+ string str = m.Value;
+ Log.Info(_PluginName + ": table found: " + Environment.NewLine + str);
+ Log.Info("number of rows: " + str.Split(Environment.NewLine.ToCharArray()).Length);
+ str = Regex.Replace(str, @"\|{2,}(?:<[^>]*>)?", "|");
+ return "{"+str+"}";
+ }
+
}
-}
+}
\ No newline at end of file
Modified: trunk/plugins/Documentation plugin/skin/Documentation.xml
===================================================================
--- trunk/plugins/Documentation plugin/skin/Documentation.xml 2007-03-27 11:06:38 UTC (rev 236)
+++ trunk/plugins/Documentation plugin/skin/Documentation.xml 2007-03-27 11:13:31 UTC (rev 237)
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<window>
<id>9999</id>
- <defaultcontrol>10</defaultcontrol>
+ <defaultcontrol>1</defaultcontrol>
<allowoverlay>yes</allowoverlay>
<define>#header.label:Documentation</define>
<define>#header.image:wiki.team-mediaportal.com.png</define>
- <define>#header.hover:hover_wikipedia.png</define>
+ <define>#header.hover:hover_test.png</define>
<controls>
<import>common.window.xml</import>
<control>
@@ -19,30 +19,53 @@
<posX>60</posX>
<posY>97</posY>
<control>
+ <description>Homepage</description>
+ <type>button</type>
+ <id>981</id>
+ <onup>17</onup>
+ <label>Startpage</label>
+ </control>
+ <control>
+ <description>Keyword reference</description>
+ <type>button</type>
+ <id>982</id>
+ <label>Glossary</label>
+ </control>
+ <control>
<description>Page name entry</description>
<type>button</type>
- <id>10</id>
- <onup>17</onup>
+ <id>983</id>
<label>Go to...</label>
</control>
<control>
+ <description>Search pages</description>
+ <type>button</type>
+ <id>984</id>
+ <label>Search...</label>
+ </control>
+ <control>
+ <description>Previous page</description>
+ <type>button</type>
+ <id>985</id>
+ <label>Back</label>
+ </control>
+ <control>
<description>Back to the text (when viewing an image)</description>
<type>button</type>
- <id>14</id>
+ <id>986</id>
<label>2514</label>
<visible>no</visible>
</control>
<control>
<description>Links Button</description>
<type>button</type>
- <id>12</id>
+ <id>987</id>
<label>2511</label>
</control>
<control>
<description>Images Button</description>
<type>button</type>
- <id>13</id>
- <ondown>99</ondown>
+ <id>988</id>
<label>2515</label>
</control>
</control>
@@ -51,7 +74,7 @@
<animation effect="fade" time="500">WindowClose</animation>
<description>Article title/searchterm</description>
<type>label</type>
- <id>4</id>
+ <id>989</id>
<posX>280</posX>
<posY>70</posY>
<visible>no</visible>
@@ -64,7 +87,7 @@
<animation effect="fade" time="500">WindowClose</animation>
<description>Image description</description>
<type>label</type>
- <id>5</id>
+ <id>990</id>
<posX>264</posX>
<posY>70</posY>
<visible>no</visible>
@@ -77,7 +100,7 @@
<animation effect="fade" time="500">WindowClose</animation>
<description>Here is the article text displayed</description>
<type>textbox</type>
- <id>20</id>
+ <id>991</id>
<posX>280</posX>
<posY>92</posY>
<visible>no</visible>
@@ -90,7 +113,7 @@
<animation effect="fade" time="500">WindowClose</animation>
<description>Article Image</description>
<type>image</type>
- <id>25</id>
+ <id>992</id>
<posX>264</posX>
<posY>72</posY>
<visible>no</visible>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|