From: <pb...@us...> - 2007-03-27 10:23:57
|
Revision: 233 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=233&view=rev Author: pbb72 Date: 2007-03-27 03:23:29 -0700 (Tue, 27 Mar 2007) Log Message: ----------- added AssemblyInfo Added Paths: ----------- trunk/plugins/Documentation plugin/Properties/ trunk/plugins/Documentation plugin/Properties/AssemblyInfo.cs Added: trunk/plugins/Documentation plugin/Properties/AssemblyInfo.cs =================================================================== --- trunk/plugins/Documentation plugin/Properties/AssemblyInfo.cs (rev 0) +++ trunk/plugins/Documentation plugin/Properties/AssemblyInfo.cs 2007-03-27 10:23:29 UTC (rev 233) @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Documentation")] +[assembly: AssemblyDescription("MediaPortal Documentation Plugin")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Peter Bremer")] +[assembly: AssemblyProduct("Documentation")] +[assembly: AssemblyCopyright("Copyright \xA9 2007")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("dfa46817-9ad5-47d0-b442-4150769a8e1b")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pb...@us...> - 2007-03-27 10:35:49
|
Revision: 234 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=234&view=rev Author: pbb72 Date: 2007-03-27 03:35:10 -0700 (Tue, 27 Mar 2007) Log Message: ----------- fixed projectfile, renamed identifiers, some simplifications Modified Paths: -------------- trunk/plugins/Documentation plugin/Documentation.cs trunk/plugins/Documentation plugin/Documentation.csproj trunk/plugins/Documentation plugin/DocumentationImage.cs trunk/plugins/Documentation plugin/DocumentationPage.cs Modified: trunk/plugins/Documentation plugin/Documentation.cs =================================================================== --- trunk/plugins/Documentation plugin/Documentation.cs 2007-03-27 10:23:29 UTC (rev 233) +++ trunk/plugins/Documentation plugin/Documentation.cs 2007-03-27 10:35:10 UTC (rev 234) @@ -36,18 +36,17 @@ using MediaPortal.Util; using MediaPortal.Configuration; -namespace Wikipedia +namespace Documentation { /// <summary> - /// Windowplugin to search in Wikipedia and display articles using the MP Wikipedia Classes. + /// MediaPortal Window plugin to display the documentation wiki. /// </summary> - public class GUIWikipedia : GUIWindow, ISetupForm + public class GUIDocumentation : GUIWindow, ISetupForm { #region SkinControls + // map skin controls to member variables [SkinControlAttribute(10)] protected GUIButtonControl buttonSearch = null; - [SkinControlAttribute(11)] - protected GUIButtonControl buttonLocal = null; [SkinControlAttribute(14)] protected GUIButtonControl buttonBack = null; [SkinControlAttribute(12)] @@ -66,35 +65,36 @@ protected GUIImage imageControl = null; #endregion - private string language = "Default"; - private string articletext = string.Empty; - private ArrayList linkArray = new ArrayList(); - private ArrayList imagenameArray = new ArrayList(); - private ArrayList imagedescArray = new ArrayList(); + public string _PluginName = "Documentation"; + private int _WindowID = 9999; + private string _pageText = string.Empty; + private ArrayList _linkArray = new ArrayList(); + private ArrayList _imageNameArray = new ArrayList(); + private ArrayList _imageDescArray = new ArrayList(); - - public GUIWikipedia() + public GUIDocumentation() { - GetID = (int)GUIWindow.Window.WINDOW_WIKIPEDIA; + GetID = _WindowID; } + #region ISetupForm Members // Returns the name of the plugin which is shown in the plugin menu public string PluginName() { - return "Wikipedia"; + return _PluginName; } // Returns the description of the plugin is shown in the plugin menu public string Description() { - return "A Plugin to search in Wikipedia"; + return "Displays the MediaPortal Documentation wiki."; } // Returns the author of the plugin which is shown in the plugin menu public string Author() { - return "Maschine"; + return "Peter"; } // show the setup dialog @@ -112,19 +112,19 @@ // get ID of windowplugin belonging to this setup public int GetWindowId() { - return 4711; + return _WindowID; } // Indicates if plugin is enabled by default; public bool DefaultEnabled() { - return false; + return true; } // indicates if a plugin has its own setup screen public bool HasSetup() { - return false; + return true; } /// <summary> @@ -138,22 +138,24 @@ /// <param name="strPictureImage">subpicture for the button or empty for none</param> /// <returns>true : plugin needs its own button on home /// false : plugin does not need its own button on home</returns> - public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) + public bool GetHome(out string strButtonText, out string strButtonImage, + out string strButtonImageFocus, out string strPictureImage) { - strButtonText = GUILocalizeStrings.Get(2516); - strButtonImage = ""; - strButtonImageFocus = ""; - strPictureImage = ""; + strButtonText = _PluginName; + strButtonImage = String.Empty; + strButtonImageFocus = String.Empty; + strPictureImage = String.Empty; return true; } #endregion public override bool Init() { - return Load(GUIGraphicsContext.Skin + @"\wikipedia.xml"); + return Load(GUIGraphicsContext.Skin + @"\Documentation.xml"); } - protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType) + protected override void OnClicked(int controlId, GUIControl control, + MediaPortal.GUI.Library.Action.ActionType actionType) { // we don't want the user to start another search while one is already active if (_workerCompleted == false) @@ -163,7 +165,8 @@ if (control == buttonSearch) { // If the search Button was clicked we need to bring up the search keyboard. - VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD); + VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow( + (int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD); if (null == keyboard) return; string searchterm = string.Empty; keyboard.IsSearchKeyboard = true; @@ -171,7 +174,7 @@ keyboard.Text = ""; keyboard.DoModal(GetID); // show it... - Log.Info("Wikipedia: OSD keyboard loaded!"); + Log.Info(_PluginName + ": OSD keyboard loaded!"); // If input is finished, the string is saved to the searchterm var. if (keyboard.IsConfirmed) @@ -180,76 +183,53 @@ // If there was a string entered try getting the article. if (searchterm != "") { - Log.Info("Wikipedia: Searchterm gotten from OSD keyboard: {0}", searchterm); + Log.Info(_PluginName + ": Searchterm gotten from OSD keyboard: {0}", + searchterm); GetAndDisplayArticle(searchterm); } // Else display an error dialog. else { - GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); + GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow( + (int)GUIWindow.Window.WINDOW_DIALOG_OK); dlg.SetHeading(GUILocalizeStrings.Get(257)); // Error dlg.SetLine(1, GUILocalizeStrings.Get(2500)); // No searchterm entered! dlg.SetLine(2, String.Empty); - dlg.SetLine(3, GUILocalizeStrings.Get(2501)); // Please enter a valid searchterm! + dlg.SetLine(3, GUILocalizeStrings.Get(2501)); // Please enter valid searchterm! dlg.DoModal(GUIWindowManager.ActiveWindow); } } - // This is the control to select the local Wikipedia site. - if (control == buttonLocal) - { - // Create a new selection dialog. - GUIDialogMenu pDlgOK = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); - if (pDlgOK != null) - { - pDlgOK.Reset(); - pDlgOK.SetHeading(GUILocalizeStrings.Get(2502)); //Select your local Wikipedia: - - // Add all the local sites we want to be displayed starting with int 0. - MediaPortal.Profile.Settings langreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "wikipedia.xml")); - String allsites = langreader.GetValueAsString("Allsites", "sitenames", ""); - Log.Info("Wikipedia: available sites: " + allsites); - String[] siteArray = allsites.Split(','); - for (int i = 0; i < siteArray.Length; i++) - { - int stringno = langreader.GetValueAsInt(siteArray[i], "string", 2006); - pDlgOK.Add(GUILocalizeStrings.Get(stringno)); //English, German, French ... - } - - pDlgOK.DoModal(GetID); - if (pDlgOK.SelectedLabel >= 0) - { - SelectLocalWikipedia(pDlgOK.SelectedLabel, siteArray); - } - } - } // The Button holding the Links to other articles if (control == buttonLinks) { - if (linkArray.Count > 0) + if (_linkArray.Count > 0) { // Create a new selection dialog. - GUIDialogMenu pDlgOK = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); + GUIDialogMenu pDlgOK = (GUIDialogMenu)GUIWindowManager.GetWindow( + (int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (pDlgOK != null) { pDlgOK.Reset(); pDlgOK.SetHeading(GUILocalizeStrings.Get(2505)); //Links to other articles: // Add all the links from the linkarray. - foreach (string link in linkArray) + foreach (string link in _linkArray) { pDlgOK.Add(link); } pDlgOK.DoModal(GetID); if (pDlgOK.SelectedLabel >= 0) { - Log.Info("Wikipedia: new search from the links array: {0}", pDlgOK.SelectedLabelText); + Log.Info(_PluginName + ": new search from the links array: {0}", + pDlgOK.SelectedLabelText); GetAndDisplayArticle(pDlgOK.SelectedLabelText); } } } else { - GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); + GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow( + (int)GUIWindow.Window.WINDOW_DIALOG_OK); dlg.SetHeading(GUILocalizeStrings.Get(257)); // Error dlg.SetLine(1, GUILocalizeStrings.Get(2506)); // No Links from this article. dlg.DoModal(GUIWindowManager.ActiveWindow); @@ -259,33 +239,37 @@ // The Button containing a list of all images from the article if (control == buttonImages) { - if (imagedescArray.Count > 0) + if (_imageDescArray.Count > 0) { // Create a new selection dialog. - GUIDialogMenu pDlgOK = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); + GUIDialogMenu pDlgOK = (GUIDialogMenu)GUIWindowManager.GetWindow( + (int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (pDlgOK != null) { pDlgOK.Reset(); pDlgOK.SetHeading(GUILocalizeStrings.Get(2507)); //Images from this article // Add all the images from the imagearray. - foreach (string image in imagedescArray) + foreach (string image in _imageDescArray) { pDlgOK.Add(image); } pDlgOK.DoModal(GetID); if (pDlgOK.SelectedLabel >= 0) { - Log.Info("Wikipedia: new search from the image array: {0}", imagedescArray[pDlgOK.SelectedId - 1]); - GetAndDisplayImage(imagenameArray[pDlgOK.SelectedId - 1].ToString(), imagedescArray[pDlgOK.SelectedId - 1].ToString()); + Log.Info(_PluginName + ": new search from the image array: {0}", + _imageDescArray[pDlgOK.SelectedId - 1]); + GetAndDisplayImage(_imageNameArray[pDlgOK.SelectedId - 1].ToString(), + _imageDescArray[pDlgOK.SelectedId - 1].ToString()); } } } else { - GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); + GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow( + (int)GUIWindow.Window.WINDOW_DIALOG_OK); dlg.SetHeading(GUILocalizeStrings.Get(257)); // Error - dlg.SetLine(1, GUILocalizeStrings.Get(2508)); // No Images referenced in this article. + dlg.SetLine(1, GUILocalizeStrings.Get(2508)); // No Images referenced in art. dlg.DoModal(GUIWindowManager.ActiveWindow); } } @@ -306,24 +290,11 @@ base.OnClicked(controlId, control, actionType); } - // Depending on which Entry was selected from the listbox we chose the language here. - private void SelectLocalWikipedia(int labelnumber, String[] siteArray) - { - MediaPortal.Profile.Settings langreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "wikipedia.xml")); - language = siteArray[labelnumber]; - - if (searchtermLabel.Label != string.Empty && searchtermLabel.Label != "Wikipedia") - { - Log.Info("Wikipedia: language changed to {0}. Display article {1} again.", language, searchtermLabel.Label); - GetAndDisplayArticle(searchtermLabel.Label); - } - } - private void GetAndDisplayImage(string imagename, string imagedesc) { - WikipediaImage image = new WikipediaImage(imagename, language); + WikipediaImage image = new WikipediaImage(imagename); string imagefilename = image.GetImageFilename(); - Log.Info("Wikipedia: Trying to display image file: {0}", imagefilename); + Log.Info(_PluginName + ": Trying to display image file: {0}", imagefilename); if (imagefilename != string.Empty && System.IO.File.Exists(imagefilename)) { @@ -342,7 +313,8 @@ } else { - GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); + GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow( + (int)GUIWindow.Window.WINDOW_DIALOG_OK); dlg.SetHeading(GUILocalizeStrings.Get(257)); // Error dlg.SetLine(1, GUILocalizeStrings.Get(2512)); // Can't display image. dlg.SetLine(2, GUILocalizeStrings.Get(2513)); // Please have a look at the logfile. @@ -380,23 +352,27 @@ GUIControl.HideControl(GetID, imagedescLabel.GetID); if (buttonBack.IsVisible) GUIControl.HideControl(GetID, buttonBack.GetID); - linkArray.Clear(); - imagenameArray.Clear(); - imagedescArray.Clear(); + _linkArray.Clear(); + _imageNameArray.Clear(); + _imageDescArray.Clear(); searchtermLabel.Label = e.Argument.ToString(); - WikipediaArticle article = new WikipediaArticle(e.Argument.ToString(), language); - articletext = article.GetArticleText(); - linkArray = article.GetLinkArray(); - imagenameArray = article.GetImageArray(); - imagedescArray = article.GetImagedescArray(); - language = article.GetLanguage(); + DocumentationPage page = + new DocumentationPage(e.Argument.ToString()); + _pageText = page.GetText(); + _linkArray = page.GetLinkArray(); + _imageNameArray = page.GetImageArray(); + _imageDescArray = page.GetImagedescArray(); - if (articletext == "REDIRECT") - txtArticle.Label = GUILocalizeStrings.Get(2509) + "\n" + GUILocalizeStrings.Get(2510); //This page is only a redirect. Please chose the redirect aim from the link list. - else if (articletext == string.Empty) - txtArticle.Label = GUILocalizeStrings.Get(2504); //Sorry, no Article was found for your searchterm... + if (_pageText == "REDIRECT") + txtArticle.Label = GUILocalizeStrings.Get(2509) + "\n" + + GUILocalizeStrings.Get(2510); + //This page is only a redirect. + //Please chose the redirect aim from the link list. + else if (_pageText == string.Empty) + txtArticle.Label = GUILocalizeStrings.Get(2504); + //Sorry, no Article was found for your searchterm... else - txtArticle.Label = articletext; + txtArticle.Label = _pageText; } _workerCompleted = true; Modified: trunk/plugins/Documentation plugin/Documentation.csproj =================================================================== --- trunk/plugins/Documentation plugin/Documentation.csproj 2007-03-27 10:23:29 UTC (rev 233) +++ trunk/plugins/Documentation plugin/Documentation.csproj 2007-03-27 10:35:10 UTC (rev 234) @@ -32,15 +32,30 @@ <SpecificVersion>False</SpecificVersion> <HintPath>D:\Apps\Desktop\MediaPortal\Core.DLL</HintPath> </Reference> + <Reference Include="Dialogs, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>D:\Apps\Desktop\MediaPortal\Plugins\Windows\Dialogs.DLL</HintPath> + </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Windows.Forms" /> <Reference Include="System.Xml" /> + <Reference Include="Utils, Version=1.0.2588.17918, Culture=neutral, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>D:\Apps\Desktop\MediaPortal\Utils.DLL</HintPath> + </Reference> </ItemGroup> <ItemGroup> - <Compile Include="Class1.cs" /> + <Compile Include="Documentation.cs" /> + <Compile Include="DocumentationImage.cs" /> + <Compile Include="DocumentationPage.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> + <ItemGroup> + <Content Include="skin\Documentation.xml"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. Modified: trunk/plugins/Documentation plugin/DocumentationImage.cs =================================================================== --- trunk/plugins/Documentation plugin/DocumentationImage.cs 2007-03-27 10:23:29 UTC (rev 233) +++ trunk/plugins/Documentation plugin/DocumentationImage.cs 2007-03-27 10:35:10 UTC (rev 234) @@ -35,7 +35,7 @@ using MediaPortal.Util; using MediaPortal.Configuration; -namespace Wikipedia +namespace Documentation { /// <summary> /// This class holds all the logic to get an image from Wikipedia for further using in MP. Modified: trunk/plugins/Documentation plugin/DocumentationPage.cs =================================================================== --- trunk/plugins/Documentation plugin/DocumentationPage.cs 2007-03-27 10:23:29 UTC (rev 233) +++ trunk/plugins/Documentation plugin/DocumentationPage.cs 2007-03-27 10:35:10 UTC (rev 234) @@ -35,23 +35,23 @@ using MediaPortal.Util; using MediaPortal.Configuration; -namespace Wikipedia +namespace Documentation { /// <summary> - /// This class holds all the logic to get info from Wikipedia and parse it for further using in MP. + /// This class holds all the logic to get info from the MediaPortal Wiki and parse it for + /// further usage. /// </summary> - public class WikipediaArticle + public class DocumentationPage { #region vars - private string WikipediaURL = "http://en.wikipedia.org/wiki/Special:Export/"; - private string imagePattern = "Image"; - private string title = string.Empty; - private string unparsedArticle = string.Empty; - private string parsedArticle = string.Empty; - private string language = "Default"; - private ArrayList linkArray = new ArrayList(); - private ArrayList imageArray = new ArrayList(); - private ArrayList imagedescArray = new ArrayList(); + private string _WikiURL = "http://wiki.team-mediaportal.com/{0}?action=raw"; + private string _imagePattern = "attachment:"; + private string _title = string.Empty; + private string _unparsedPage = string.Empty; + private string _parsedPage = string.Empty; + private ArrayList _linkArray = new ArrayList(); + private ArrayList _imageArray = new ArrayList(); + private ArrayList _imageDescArray = new ArrayList(); #endregion #region constructors @@ -59,106 +59,68 @@ /// <summary>Searchterm and language need to be given</summary> /// <param name="title">The article's title</param> /// <param name="language">Language of the Wikipedia page</param> - public WikipediaArticle(string title, string language) + public DocumentationPage(string title) { - SetLanguage(language); - this.title = title; + this._title = title; GetWikipediaXML(); ParseWikipediaArticle(); ParseLinksAndImages(); } - - /// <summary>This constructor creates a new WikipediaArticle.</summary> - /// <summary>Only called with a title string, language set to default.</summary> - /// <param name="title">The article's title</param> - public WikipediaArticle(string title) - : this(title, "Default") - { - } - - /// <summary>This constructor creates a new WikipediaArticle if no parameter is given.</summary> - /// <summary>Uses an empty searchterm and the default language.</summary> - public WikipediaArticle() - : this(string.Empty, "Default") - { - } #endregion - /// <summary>Gets the current MP language from mediaportal.xml and sets the Wikipedia URL accordingly</summary> - private void SetLanguage(string language) - { - if (language == "Default") - { - MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml")); - language = xmlreader.GetValueAsString("skin", "language", "English"); - } - - this.language = language; - - MediaPortal.Profile.Settings detailxmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "wikipedia.xml")); - this.WikipediaURL = detailxmlreader.GetValueAsString(language, "url", "http://en.wikipedia.org/wiki/Special:Export/"); - this.imagePattern = detailxmlreader.GetValueAsString(language, "imagepattern", "Image"); - Log.Info("Wikipedia: Language set to " + language + "."); - } - /// <summary>Returns the parsed article text.</summary> /// <returns>String: parsed article</returns> - public string GetArticleText() + public string GetText() { - return parsedArticle; + return _parsedPage; } - /// <summary>Returns the title of the article. Can differ from the passed parameter on redirects for example.</summary> + /// <summary>Returns the title of the article. Can differ from the passed parameter on + /// redirects for example.</summary> /// <returns>String: title of the article</returns> public string GetTitle() { - return title; + return _title; } /// <summary>Returns all names of images.</summary> /// <returns>StringArray: images used in this article</returns> public ArrayList GetImageArray() { - return imageArray; + return _imageArray; } /// <summary>Returns all descriptions of images.</summary> /// <returns>StringArray: images used in this article</returns> public ArrayList GetImagedescArray() { - return imagedescArray; + return _imageDescArray; } /// <summary>Returns the titles of all linked articles.</summary> /// <returns>StringArray: titles of linked (internal) Wikipedia articles</returns> public ArrayList GetLinkArray() { - return linkArray; + return _linkArray; } - /// <summary>Returns the currently active language.</summary> - /// <returns>String: language</returns> - public string GetLanguage() - { - return language; - } - - /// <summary>Downloads the xml content from Wikipedia and cuts metadata like version info.</summary> + /// <summary>Downloads the xml content from Wikipedia and cuts metadata like version + /// info.</summary> private void GetWikipediaXML() { - string wikipediaXML = string.Empty; // Build the URL to the Wikipedia page - System.Uri url = new System.Uri(WikipediaURL + this.title); + System.Uri url = new System.Uri(String.Format(_WikiURL, this._title)); Log.Info("Wikipedia: Trying to get following URL: {0}", url.ToString()); // Here we get the content from the web and put it to a string 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.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); - wikipediaXML = reader.ReadToEnd(); + this._unparsedPage = reader.ReadToEnd(); reader.Close(); Log.Info("Wikipedia: Success! Downloaded all data."); } @@ -167,36 +129,21 @@ Log.Info("Wikipedia: Exception during downloading:"); Log.Info(e.ToString()); } - - if (wikipediaXML.IndexOf("<text xml:space=\"preserve\">") > 0) - { - Log.Info("Wikipedia: Extracting unparsed string."); - int iStart = 0; - int iEnd = wikipediaXML.Length; - // Start of the Entry - iStart = wikipediaXML.IndexOf("<text xml:space=\"preserve\">") + 27; - // End of the Entry - iEnd = wikipediaXML.IndexOf("</text>"); - // Extract the Text and update the var - this.unparsedArticle = wikipediaXML.Substring(iStart, iEnd - iStart); - Log.Info("Wikipedia: Unparsed string extracted."); - } - else - this.unparsedArticle = string.Empty; } /// <summary>Cuts all special wiki syntax from the article to display plain text</summary> private void ParseWikipediaArticle() { - string tempParsedArticle = this.unparsedArticle; + string tempParsedArticle = this._unparsedPage; // Check if the article is empty, if so do not parse. if (tempParsedArticle == string.Empty) { Log.Info("Wikipedia: Empty article found. Try another Searchterm."); - this.unparsedArticle = string.Empty; + this._unparsedPage = string.Empty; } - // Here we check if there is only a redirect as article to handle it as a special article type + // Here we check if there is only a redirect as article to handle it as a special + // article type else if (tempParsedArticle.IndexOf("#REDIRECT") == 0) { Log.Info("Wikipedia: #REDIRECT found."); @@ -204,8 +151,8 @@ int iEnd = tempParsedArticle.IndexOf("]]", iStart); // Extract the Text string keyword = tempParsedArticle.Substring(iStart, iEnd - iStart); - this.unparsedArticle = string.Empty; - this.title = keyword; + this._unparsedPage = string.Empty; + this._title = keyword; GetWikipediaXML(); ParseWikipediaArticle(); } @@ -247,7 +194,8 @@ iEnd = tempParsedArticle.IndexOf("}}") + 2; // Between {{ and }} we can again have inner sets of {{ and }} - while (tempParsedArticle.IndexOf("{{", iStart2 + 2) >= 0 && tempParsedArticle.IndexOf("{{", iStart2 + 2) < iEnd) + while (tempParsedArticle.IndexOf("{{", iStart2 + 2) >= 0 && + tempParsedArticle.IndexOf("{{", iStart2 + 2) < iEnd) { iStart2 = tempParsedArticle.IndexOf("{{", iStart2 + 2); iEnd = tempParsedArticle.IndexOf("}}", iStart2) + 2; @@ -401,32 +349,37 @@ if (tempParsedArticle.IndexOf("\n") == 0) tempParsedArticle.Remove(0, 2); - // For Debug purposes it is nice to see how the whole article text is parsed until here + // For Debug purposes it is nice to see how the whole article text is parsed until + // here //Log.Debug(tempParsedArticle); Log.Info("Wikipedia: Finished parsing."); - this.unparsedArticle = tempParsedArticle; + this._unparsedPage = tempParsedArticle; } } - /// <summary>Gets Links out of the article. External links are thrown away, links to other wikipedia articles get into the link array, images to the image array</summary> + /// <summary>Gets Links out of the article. External links are thrown away, links to other + /// wikipedia articles get into the link array, images to the image array</summary> private void ParseLinksAndImages() { Log.Info("Wikipedia: Starting parsing of links and images."); - string tempParsedArticle = this.unparsedArticle; + string tempParsedArticle = this._unparsedPage; int iStart = 0, iEnd = 0, iPipe = 0; // Surrounded by [[IMAGEPATTERN: and ]] are the links to IMAGES. - // We need to check for the localized image keyword but also for the English as this is commonly used in some local sites. + // We need to check for the localized image keyword but also for the English as this + // is commonly used in some local sites. // Example: [[Bild:H_NeuesRathaus1.jpg|left|thumb|Das [[Neues Rathaus (Hannover)|Neue Rathaus]] mit Maschteich]] - while ((iStart = tempParsedArticle.IndexOf("[[" + imagePattern + ":", iStart)) >= 0 || (iStart = tempParsedArticle.IndexOf("[[Image:")) >= 0) + while ((iStart = tempParsedArticle.IndexOf("[[" + _imagePattern + ":", iStart)) >= 0 || + (iStart = tempParsedArticle.IndexOf("[[Image:")) >= 0) { iEnd = tempParsedArticle.IndexOf("]]", (iStart + 2)) + 2; int disturbingLink = iStart; // Descriptions of images can contain links! - // [[Bild:Hannover Merian.png|thumb|[[Matth?us Merian|Merian]]-Kupferstich um 1650, im Vordergrund Windm?hle auf dem [[Lindener Berg]]]] - while (tempParsedArticle.IndexOf("[[", disturbingLink + 2) >= 0 && tempParsedArticle.IndexOf("[[", disturbingLink + 2) < iEnd) + // [[Bild:Hannover Merian.png|thumb|[[Mattheus Merian|Merian]]-Kupferstich um 1650, im Vordergrund Windmohle auf dem [[Lindener Berg]]]] + while (tempParsedArticle.IndexOf("[[", disturbingLink + 2) >= 0 && + tempParsedArticle.IndexOf("[[", disturbingLink + 2) < iEnd) { disturbingLink = tempParsedArticle.IndexOf("[[", disturbingLink + 2); iEnd = tempParsedArticle.IndexOf("]]", disturbingLink) + 2; @@ -447,11 +400,14 @@ // 1st type of keywords is like [[article|displaytext]] // for the 2nd the article and displayed text are equal [[article]]. if (linkkeyword.IndexOf("|") > 0) - linkkeyword = linkkeyword.Substring(linkkeyword.IndexOf("|") + 1, linkkeyword.IndexOf("]]") - linkkeyword.IndexOf("|") - 1); + linkkeyword = linkkeyword.Substring(linkkeyword.IndexOf("|") + 1, + linkkeyword.IndexOf("]]") - linkkeyword.IndexOf("|") - 1); else - linkkeyword = linkkeyword.Substring(linkkeyword.IndexOf("[[") + 2, linkkeyword.IndexOf("]]") - linkkeyword.IndexOf("[[") - 2); + linkkeyword = linkkeyword.Substring(linkkeyword.IndexOf("[[") + 2, + linkkeyword.IndexOf("]]") - linkkeyword.IndexOf("[[") - 2); - keyword = keyword.Substring(0, iStartlink) + linkkeyword + keyword.Substring(iEndlink, keyword.Length - iEndlink); + keyword = keyword.Substring(0, iStartlink) + linkkeyword + + keyword.Substring(iEndlink, keyword.Length - iEndlink); } int iStartname = keyword.IndexOf(":") + 1; @@ -465,11 +421,12 @@ int iEnddesc = keyword.LastIndexOf("]]"); string imagedesc = keyword.Substring(iStartdesc, iEnddesc - iStartdesc); ; - this.imageArray.Add(imagename); - this.imagedescArray.Add(imagedesc); + this._imageArray.Add(imagename); + this._imageDescArray.Add(imagedesc); Log.Debug("Wikipedia: Image added: {0}, {1}", imagedesc, imagename); - tempParsedArticle = tempParsedArticle.Substring(0, iStart) + tempParsedArticle.Substring(iEnd, tempParsedArticle.Length - iEnd); + tempParsedArticle = tempParsedArticle.Substring(0, iStart) + + tempParsedArticle.Substring(iEnd, tempParsedArticle.Length - iEnd); } // surrounded by [[ and ]] are the links to other articles. @@ -490,9 +447,9 @@ { parsedKeyword = keyword.Substring(iPipe + 1, keyword.Length - iPipe - 3); parsedLink = keyword.Substring(2, iPipe - 2); - if (!this.linkArray.Contains(parsedLink)) + if (!this._linkArray.Contains(parsedLink)) { - this.linkArray.Add(parsedLink); + this._linkArray.Add(parsedLink); //Log.Debug("Wikipedia: Link added: {0}, {1}", parsedLink, parsedKeyword); } } @@ -506,9 +463,9 @@ { // for the 3rd the article and displayed text are equal [[article]]. parsedKeyword = keyword.Substring(2, keyword.Length - 4); - if (!this.linkArray.Contains(parsedKeyword)) + if (!this._linkArray.Contains(parsedKeyword)) { - this.linkArray.Add(parsedKeyword); + this._linkArray.Add(parsedKeyword); //Log.Debug("Wikipedia: Link added: {0}", parsedKeyword); } } @@ -524,7 +481,7 @@ Log.Error("Wikipedia: {0}", e.ToString()); Log.Error("Wikipedia: tempArticle: {0}", tempParsedArticle); } - Log.Debug("Wikipedia: Finished Link parsing: {0} Links added.", linkArray.Count); + Log.Debug("Wikipedia: Finished Link parsing: {0} Links added.", _linkArray.Count); // surrounded by [ and ] are external Links. Need to be removed. Log.Debug("Wikipedia: Removing external links"); @@ -543,11 +500,12 @@ catch (Exception e) { Log.Error("Wikipedia: {0}", e.ToString()); - Log.Error("Parsing Error: " + tempParsedArticle + "\nSTART: " + iStart + "\nEND: " + iEnd); + Log.Error("Parsing Error: " + tempParsedArticle + "\nSTART: " + iStart + "\nEND: " + + iEnd); } Log.Info("Wikipedia: Finished parsing of links and images."); - this.parsedArticle = tempParsedArticle; + this._parsedPage = tempParsedArticle; } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pb...@us...> - 2007-03-27 10:49:53
|
Revision: 235 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=235&view=rev Author: pbb72 Date: 2007-03-27 03:49:51 -0700 (Tue, 27 Mar 2007) Log Message: ----------- more simplification and identifier renaming, fixed redirects, replaced substring conversion by regex conversion, added skin file Modified Paths: -------------- trunk/plugins/Documentation plugin/Documentation.cs trunk/plugins/Documentation plugin/DocumentationPage.cs Added Paths: ----------- trunk/plugins/Documentation plugin/skin/ trunk/plugins/Documentation plugin/skin/Documentation.xml Property Changed: ---------------- trunk/plugins/Documentation plugin/ Property changes on: trunk/plugins/Documentation plugin ___________________________________________________________________ Name: svn:ignore + *.bak Modified: trunk/plugins/Documentation plugin/Documentation.cs =================================================================== --- trunk/plugins/Documentation plugin/Documentation.cs 2007-03-27 10:35:10 UTC (rev 234) +++ trunk/plugins/Documentation plugin/Documentation.cs 2007-03-27 10:49:51 UTC (rev 235) @@ -46,7 +46,7 @@ #region SkinControls // map skin controls to member variables [SkinControlAttribute(10)] - protected GUIButtonControl buttonSearch = null; + protected GUIButtonControl buttonOpen = null; [SkinControlAttribute(14)] protected GUIButtonControl buttonBack = null; [SkinControlAttribute(12)] @@ -154,7 +154,13 @@ return Load(GUIGraphicsContext.Skin + @"\Documentation.xml"); } - protected override void OnClicked(int controlId, GUIControl control, + protected override void OnPageLoad() + { + GetAndDisplayArticle(String.Empty); // display start page + base.OnPageLoad(); + } + + protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType) { // we don't want the user to start another search while one is already active @@ -162,7 +168,7 @@ return; // Here we want to open the OSD Keyboard to enter the searchstring - if (control == buttonSearch) + if (control == buttonOpen) { // If the search Button was clicked we need to bring up the search keyboard. VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow( @@ -181,23 +187,9 @@ searchterm = keyboard.Text; // If there was a string entered try getting the article. - if (searchterm != "") - { - Log.Info(_PluginName + ": Searchterm gotten from OSD keyboard: {0}", - searchterm); - GetAndDisplayArticle(searchterm); - } - // Else display an error dialog. - else - { - GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow( - (int)GUIWindow.Window.WINDOW_DIALOG_OK); - dlg.SetHeading(GUILocalizeStrings.Get(257)); // Error - dlg.SetLine(1, GUILocalizeStrings.Get(2500)); // No searchterm entered! - dlg.SetLine(2, String.Empty); - dlg.SetLine(3, GUILocalizeStrings.Get(2501)); // Please enter valid searchterm! - dlg.DoModal(GUIWindowManager.ActiveWindow); - } + Log.Info(_PluginName + ": Searchterm gotten from OSD keyboard: {0}", + searchterm); + GetAndDisplayArticle(searchterm); } // The Button holding the Links to other articles if (control == buttonLinks) @@ -322,7 +314,7 @@ } } - // The main function. + // The core function. void GetAndDisplayArticle(string searchterm) { BackgroundWorker worker = new BackgroundWorker(); @@ -358,8 +350,8 @@ searchtermLabel.Label = e.Argument.ToString(); DocumentationPage page = new DocumentationPage(e.Argument.ToString()); - _pageText = page.GetText(); - _linkArray = page.GetLinkArray(); + _pageText = page.text; + _linkArray = page.linkArray(); _imageNameArray = page.GetImageArray(); _imageDescArray = page.GetImagedescArray(); Modified: trunk/plugins/Documentation plugin/DocumentationPage.cs =================================================================== --- trunk/plugins/Documentation plugin/DocumentationPage.cs 2007-03-27 10:35:10 UTC (rev 234) +++ trunk/plugins/Documentation plugin/DocumentationPage.cs 2007-03-27 10:49:51 UTC (rev 235) @@ -29,6 +29,7 @@ using System.Net; using System.IO; using System.Text; +using System.Text.RegularExpressions; using System.Threading; using System.Collections; using MediaPortal.GUI.Library; @@ -44,72 +45,30 @@ public class DocumentationPage { #region vars - private string _WikiURL = "http://wiki.team-mediaportal.com/{0}?action=raw"; + public string text = string.Empty; + public ArrayList linkArray = new ArrayList(); + public ArrayList imageArray = new ArrayList(); + public ArrayList imageDescArray = new ArrayList(); + private string _WikiURL = "http://wiki.team-mediaportal.com/{0}?action=raw"; private string _imagePattern = "attachment:"; - private string _title = string.Empty; - private string _unparsedPage = string.Empty; - private string _parsedPage = string.Empty; - private ArrayList _linkArray = new ArrayList(); - private ArrayList _imageArray = new ArrayList(); - private ArrayList _imageDescArray = new ArrayList(); #endregion #region constructors /// <summary>This constructor creates a new WikipediaArticle</summary> - /// <summary>Searchterm and language need to be given</summary> - /// <param name="title">The article's title</param> - /// <param name="language">Language of the Wikipedia page</param> - public DocumentationPage(string title) + /// <param name="pageName">The article's page name</param> + public DocumentationPage(string pageName) { - this._title = title; - GetWikipediaXML(); + GetWikiPage(pageName); ParseWikipediaArticle(); ParseLinksAndImages(); } #endregion - /// <summary>Returns the parsed article text.</summary> - /// <returns>String: parsed article</returns> - public string GetText() + /// <summary>Downloads the raw Wiki code.</summary> + private void GetWikiPage(string pageName) { - return _parsedPage; - } - - /// <summary>Returns the title of the article. Can differ from the passed parameter on - /// redirects for example.</summary> - /// <returns>String: title of the article</returns> - public string GetTitle() - { - return _title; - } - - /// <summary>Returns all names of images.</summary> - /// <returns>StringArray: images used in this article</returns> - public ArrayList GetImageArray() - { - return _imageArray; - } - - /// <summary>Returns all descriptions of images.</summary> - /// <returns>StringArray: images used in this article</returns> - public ArrayList GetImagedescArray() - { - return _imageDescArray; - } - - /// <summary>Returns the titles of all linked articles.</summary> - /// <returns>StringArray: titles of linked (internal) Wikipedia articles</returns> - public ArrayList GetLinkArray() - { - return _linkArray; - } - - /// <summary>Downloads the xml content from Wikipedia and cuts metadata like version - /// info.</summary> - private void GetWikipediaXML() - { // Build the URL to the Wikipedia page - System.Uri url = new System.Uri(String.Format(_WikiURL, this._title)); + System.Uri url = new System.Uri(String.Format(_WikiURL, this._pageName)); Log.Info("Wikipedia: Trying to get following URL: {0}", url.ToString()); // Here we get the content from the web and put it to a string @@ -120,7 +79,8 @@ "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); - this._unparsedPage = reader.ReadToEnd(); + //this._unparsedPage = reader.ReadToEnd(); + this.text = reader.ReadToEnd(); reader.Close(); Log.Info("Wikipedia: Success! Downloaded all data."); } @@ -134,227 +94,83 @@ /// <summary>Cuts all special wiki syntax from the article to display plain text</summary> private void ParseWikipediaArticle() { - string tempParsedArticle = this._unparsedPage; + //string tempParsedPage = this._unparsedPage; + string tempParsedPage = this.text; - // Check if the article is empty, if so do not parse. - if (tempParsedArticle == string.Empty) + if (this.text.Length > 10 && this.text.Substring(0, 10) == "#REDIRECT ") { - Log.Info("Wikipedia: Empty article found. Try another Searchterm."); - this._unparsedPage = string.Empty; - } - // Here we check if there is only a redirect as article to handle it as a special - // article type - else if (tempParsedArticle.IndexOf("#REDIRECT") == 0) - { Log.Info("Wikipedia: #REDIRECT found."); - int iStart = tempParsedArticle.IndexOf("[[") + 2; - int iEnd = tempParsedArticle.IndexOf("]]", iStart); - // Extract the Text - string keyword = tempParsedArticle.Substring(iStart, iEnd - iStart); - this._unparsedPage = string.Empty; - this._title = keyword; - GetWikipediaXML(); + GetWikiPage(this.text.Substring(10)); ParseWikipediaArticle(); } - // Finally a well-formed article ;-) else { Log.Info("Wikipedia: Starting parsing."); - StringBuilder builder = new StringBuilder(tempParsedArticle); - int iStart = 0; - int iEnd = 0; - // Remove HTML comments - Log.Debug("Wikipedia: Remove HTML comments."); - while (tempParsedArticle.IndexOf("<!--") >= 0) - { - builder = new StringBuilder(tempParsedArticle); - iStart = tempParsedArticle.IndexOf("<!--"); - iEnd = tempParsedArticle.IndexOf("-->", iStart) + 6; + // remove control codes & remarks (#blah) + this.text = Regex.Replace(this.text, @"^#.+\n", String.Empty, + RegexOptions.Multiline); - try - { - builder.Remove(iStart, iEnd - iStart); - } - catch (Exception e) - { - Log.Error(e.ToString()); - Log.Error(builder.ToString()); - } - tempParsedArticle = builder.ToString(); - } + // TODO: no interpretation in headers (not even ``) + + // explicit hyperlinks ([:pagename:link text]) + this.text = Regex.Replace(this.text, @"\[:[^:]+:(?: |\t)*([^\]]+)\]", + "[$1]"); - // surrounded by {{ and }} is (atm) unusable stuff. - //Log.Debug("Wikipedia: Remove stuff between {{ and }}."); - while (tempParsedArticle.IndexOf("{{") >= 0) - { - builder = new StringBuilder(tempParsedArticle); - iStart = tempParsedArticle.IndexOf("{{"); - int iStart2 = iStart; - iEnd = tempParsedArticle.IndexOf("}}") + 2; + // TODO: [:page name] + // TODO: ["page name"] + + // camelcase hyperlinks that are not in headers (PageName) + // TODO: prevent camelcase links inside explicit hyperlinks + this.text = Regex.Replace(this.text, @"(?<!^=(?: )+|\w)((?:[A-Z][a-z0-9]+){2,})(?!\w)", + "[$1]", RegexOptions.Multiline); - // Between {{ and }} we can again have inner sets of {{ and }} - while (tempParsedArticle.IndexOf("{{", iStart2 + 2) >= 0 && - tempParsedArticle.IndexOf("{{", iStart2 + 2) < iEnd) - { - iStart2 = tempParsedArticle.IndexOf("{{", iStart2 + 2); - iEnd = tempParsedArticle.IndexOf("}}", iStart2) + 2; - iEnd = tempParsedArticle.IndexOf("}}", iEnd) + 2; - } + // de-linked camelcase (!PageName) + this.text = Regex.Replace(this.text, @"(?<=\W)!((?:[A-Z][a-z0-9]+){2,})(?=\W)", + "$1"); - try - { - builder.Remove(iStart, iEnd - iStart); - } - catch (Exception e) - { - Log.Error(e.ToString()); - Log.Error(builder.ToString()); - } + // TODO: /SubPage, SomePage/SomeSubPage + + // TODO: Wiki:WikiPage, MoinMoin:SomePage + + // enclosed external hyperlinks ([http://example.com]) + this.text = Regex.Replace(this.text, @"\[(http://[^ \]]+)\]", "$1"); - tempParsedArticle = builder.ToString(); - } + // external hyperlinks with label ([http://example.com an example]) + this.text = Regex.Replace(this.text, @"\[(http://[^ \]]+) ([^\]]+)\]", "$2 ($1)"); - // surrounded by {| and |} is (atm) unusable stuff. - //Log.Debug("Wikipedia: Remove stuff between {| and |}."); - while (tempParsedArticle.IndexOf("{|") >= 0) - { - builder = new StringBuilder(tempParsedArticle); - iStart = tempParsedArticle.IndexOf("{|"); - iEnd = tempParsedArticle.IndexOf("|}") + 2; + // images (attachment:file.gif) + this.text = Regex.Replace(this.text, @"attachment:([^\s\|]+)(?:\.gif|\.jpg)", + "[img:$1]"); - try - { - builder.Remove(iStart, iEnd - iStart); - } - catch (Exception e) - { - Log.Error(e.ToString()); - Log.Error(builder.ToString()); - } + // TODO: attachment:file.zip + + // TODO: bold & italic ('''text''' -> *text* & /text/) - tempParsedArticle = builder.ToString(); - } + // TODO: lists + + // tables (|| cell 1 || cell 2 ||) + this.text = Regex.Replace(this.text, @"\|{2,}<[^>]*>", "|"); - // Remove audio links. - Log.Debug("Wikipedia: Remove audio links."); - while (tempParsedArticle.IndexOf("<span") >= 0) - { - builder = new StringBuilder(tempParsedArticle); - iStart = tempParsedArticle.IndexOf("<span"); - iEnd = tempParsedArticle.IndexOf("</span>") + 13; + // single linebreaks in code, except ones around headers and tables + this.text = Regex.Replace(this.text, @"(?<!\r\n|=|\|)\r\n(?!\r\n|=|\|)", + " "); - try - { - builder.Remove(iStart, iEnd - iStart); - } - catch (Exception e) - { - Log.Error(e.ToString()); - Log.Error(builder.ToString()); - } + // paragraphs with excessive linebreaks + this.text = Regex.Replace(this.text, @"(?:\r\n){2,}", + Environment.NewLine + Environment.NewLine); - tempParsedArticle = builder.ToString(); - } + // whitespace around titles + this.text = Regex.Replace(this.text, @"(?:\r\n)+(=.+=)(?:\r\n)+", + Environment.NewLine + Environment.NewLine + "$1" + Environment.NewLine); - // Remove web references. - Log.Debug("Wikipedia: Remove web references."); - while (tempParsedArticle.IndexOf("<ref>") >= 0) - { - builder = new StringBuilder(tempParsedArticle); - iStart = tempParsedArticle.IndexOf("<ref"); - iEnd = tempParsedArticle.IndexOf("</ref>") + 12; + // forced linebreaks ([[BR]]) + this.text = Regex.Replace(this.text, @"\[\[BR\]\]", Environment.NewLine); - try - { - builder.Remove(iStart, iEnd - iStart); - } - catch (Exception e) - { - Log.Error(e.ToString()); - Log.Error(builder.ToString()); - } + // quote escaping (``) + this.text = Regex.Replace(this.text, @"``", String.Empty); - tempParsedArticle = builder.ToString(); - } - - // Remove <br /> - Log.Debug("Wikipedia: Remove <br />."); - builder.Replace("<br />", "\n"); - builder.Replace("<br style="clear:both"/>", "\n"); - builder.Replace("<br style="clear:left"/>", "\n"); - builder.Replace("<br style="clear:right"/>", "\n"); - - // Remove <sup> - Log.Debug("Wikipedia: Remove <sup>."); - builder.Replace("<sup>", "^"); - builder.Replace("</sup>", ""); - - // surrounded by ''' and ''' is bold text, atm also unusable. - Log.Debug("Wikipedia: Remove \'\'\'."); - builder.Replace("'''", ""); - - // surrounded by '' and '' is italic text, atm also unusable. - Log.Debug("Wikipedia: Remove \'\'."); - builder.Replace("''", ""); - - // Display === as newlines (meaning new line for every ===). - Log.Debug("Wikipedia: Display === as 1 newlines."); - builder.Replace("===", "\n"); - - // Display == as newlines (meaning new line for every ==). - Log.Debug("Wikipedia: Display == as 1 newline."); - builder.Replace("==", "\n"); - - // Display * as list (meaning new line for every *). - Log.Debug("Wikipedia: Display * as list."); - builder.Replace("*", "\n +"); - - // Remove HTML whitespace. - Log.Debug("Wikipedia: Remove HTML whitespace."); - builder.Replace(" ", " "); - - // Display " as ". - Log.Debug("Wikipedia: Remove Quotations."); - builder.Replace(""", "\""); - - // Display — as -. - Log.Debug("Wikipedia: Remove —."); - builder.Replace("—", "-"); - - // Remove gallery tags. - Log.Debug("Wikipedia: Remove gallery tags."); - builder.Replace("<gallery>", ""); - builder.Replace("</gallery>", ""); - - // Remove gallery tags. - Log.Debug("Wikipedia: Remove &."); - builder.Replace("&", "&"); - - // Remove (too many) newlines - Log.Debug("Wikipedia: Remove (too many) newlines."); - builder.Replace("\n\n\n\n", "\n"); - builder.Replace("\n\n\n", "\n"); - builder.Replace("\n\n", "\n"); - - // Remove (too many) newlines - Log.Debug("Wikipedia: Remove (too many) whitespaces."); - builder.Replace(" ", " "); - builder.Replace(" ", " "); - builder.Replace(" ", " "); - - tempParsedArticle = builder.ToString(); - - // The text shouldn't start with a newline. - if (tempParsedArticle.IndexOf("\n") == 0) - tempParsedArticle.Remove(0, 2); - - // For Debug purposes it is nice to see how the whole article text is parsed until - // here - //Log.Debug(tempParsedArticle); - Log.Info("Wikipedia: Finished parsing."); - this._unparsedPage = tempParsedArticle; } } @@ -363,8 +179,9 @@ private void ParseLinksAndImages() { Log.Info("Wikipedia: Starting parsing of links and images."); - string tempParsedArticle = this._unparsedPage; - int iStart = 0, iEnd = 0, iPipe = 0; + //string tempParsedArticle = this._unparsedPage; + string tempParsedArticle = this.text; + int iStart = 0, iEnd = 0, iPipe = 0; // Surrounded by [[IMAGEPATTERN: and ]] are the links to IMAGES. // We need to check for the localized image keyword but also for the English as this @@ -421,8 +238,8 @@ int iEnddesc = keyword.LastIndexOf("]]"); string imagedesc = keyword.Substring(iStartdesc, iEnddesc - iStartdesc); ; - this._imageArray.Add(imagename); - this._imageDescArray.Add(imagedesc); + this.imageArray.Add(imagename); + this.imageDescArray.Add(imagedesc); Log.Debug("Wikipedia: Image added: {0}, {1}", imagedesc, imagename); tempParsedArticle = tempParsedArticle.Substring(0, iStart) + @@ -447,9 +264,9 @@ { parsedKeyword = keyword.Substring(iPipe + 1, keyword.Length - iPipe - 3); parsedLink = keyword.Substring(2, iPipe - 2); - if (!this._linkArray.Contains(parsedLink)) + if (!this.linkArray.Contains(parsedLink)) { - this._linkArray.Add(parsedLink); + this.linkArray.Add(parsedLink); //Log.Debug("Wikipedia: Link added: {0}, {1}", parsedLink, parsedKeyword); } } @@ -463,9 +280,9 @@ { // for the 3rd the article and displayed text are equal [[article]]. parsedKeyword = keyword.Substring(2, keyword.Length - 4); - if (!this._linkArray.Contains(parsedKeyword)) + if (!this.linkArray.Contains(parsedKeyword)) { - this._linkArray.Add(parsedKeyword); + this.linkArray.Add(parsedKeyword); //Log.Debug("Wikipedia: Link added: {0}", parsedKeyword); } } @@ -481,7 +298,7 @@ Log.Error("Wikipedia: {0}", e.ToString()); Log.Error("Wikipedia: tempArticle: {0}", tempParsedArticle); } - Log.Debug("Wikipedia: Finished Link parsing: {0} Links added.", _linkArray.Count); + Log.Debug("Wikipedia: Finished Link parsing: {0} Links added.", linkArray.Count); // surrounded by [ and ] are external Links. Need to be removed. Log.Debug("Wikipedia: Removing external links"); @@ -505,7 +322,7 @@ } Log.Info("Wikipedia: Finished parsing of links and images."); - this._parsedPage = tempParsedArticle; + //this._parsedPage = tempParsedArticle; } } } \ No newline at end of file Added: trunk/plugins/Documentation plugin/skin/Documentation.xml =================================================================== --- trunk/plugins/Documentation plugin/skin/Documentation.xml (rev 0) +++ trunk/plugins/Documentation plugin/skin/Documentation.xml 2007-03-27 10:49:51 UTC (rev 235) @@ -0,0 +1,106 @@ +<?xml version="1.0" encoding="utf-8" standalone="yes"?> +<window> + <id>9999</id> + <defaultcontrol>10</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> + <controls> + <import>common.window.xml</import> + <control> + <type>group</type> + <description>group element</description> + <animation effect="fade" time="250">WindowOpen</animation> + <animation effect="fade" time="500">WindowClose</animation> + <animation effect="slide" time="250" start="-300,0">WindowOpen</animation> + <animation effect="slide" time="500" end="0,-300">WindowClose</animation> + <layout>StackLayout</layout> + <posX>60</posX> + <posY>97</posY> + <control> + <description>Page name entry</description> + <type>button</type> + <id>10</id> + <onup>17</onup> + <label>Go to...</label> + </control> + <control> + <description>Back to the text (when viewing an image)</description> + <type>button</type> + <id>14</id> + <label>2514</label> + <visible>no</visible> + </control> + <control> + <description>Links Button</description> + <type>button</type> + <id>12</id> + <label>2511</label> + </control> + <control> + <description>Images Button</description> + <type>button</type> + <id>13</id> + <ondown>99</ondown> + <label>2515</label> + </control> + </control> + <control> + <animation effect="fade" time="250">WindowOpen</animation> + <animation effect="fade" time="500">WindowClose</animation> + <description>Article title/searchterm</description> + <type>label</type> + <id>4</id> + <posX>280</posX> + <posY>70</posY> + <visible>no</visible> + <label>Article title/searchterm</label> + <font>font16</font> + <align>left</align> + </control> + <control> + <animation effect="fade" time="250">WindowOpen</animation> + <animation effect="fade" time="500">WindowClose</animation> + <description>Image description</description> + <type>label</type> + <id>5</id> + <posX>264</posX> + <posY>70</posY> + <visible>no</visible> + <label>Image description</label> + <font>font16</font> + <align>left</align> + </control> + <control> + <animation effect="fade" time="250">WindowOpen</animation> + <animation effect="fade" time="500">WindowClose</animation> + <description>Here is the article text displayed</description> + <type>textbox</type> + <id>20</id> + <posX>280</posX> + <posY>92</posY> + <visible>no</visible> + <width>380</width> + <height>444</height> + <text /> + </control> + <control> + <animation effect="fade" time="250">WindowOpen</animation> + <animation effect="fade" time="500">WindowClose</animation> + <description>Article Image</description> + <type>image</type> + <id>25</id> + <posX>264</posX> + <posY>72</posY> + <visible>no</visible> + <width>440</width> + <height>466</height> + <texture /> + <colorkey>00000000</colorkey> + <colordiffuse>White</colordiffuse> + <centered>yes</centered> + <keepaspectratio>yes</keepaspectratio> + </control> + </controls> +</window> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pb...@us...> - 2007-03-27 11:06:40
|
Revision: 236 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=236&view=rev Author: pbb72 Date: 2007-03-27 04:06:38 -0700 (Tue, 27 Mar 2007) Log Message: ----------- simplification again, disabled configuration dialog, converted image loader, code cleanup, extended interpretation regex's Modified Paths: -------------- trunk/plugins/Documentation plugin/Documentation.cs trunk/plugins/Documentation plugin/DocumentationImage.cs trunk/plugins/Documentation plugin/DocumentationPage.cs Property Changed: ---------------- trunk/plugins/Documentation plugin/skin/ Modified: trunk/plugins/Documentation plugin/Documentation.cs =================================================================== --- trunk/plugins/Documentation plugin/Documentation.cs 2007-03-27 10:49:51 UTC (rev 235) +++ trunk/plugins/Documentation plugin/Documentation.cs 2007-03-27 11:06:38 UTC (rev 236) @@ -38,338 +38,334 @@ namespace Documentation { - /// <summary> - /// MediaPortal Window plugin to display the documentation wiki. - /// </summary> - public class GUIDocumentation : GUIWindow, ISetupForm - { - #region SkinControls - // map skin controls to member variables - [SkinControlAttribute(10)] - protected GUIButtonControl buttonOpen = null; - [SkinControlAttribute(14)] - protected GUIButtonControl buttonBack = null; - [SkinControlAttribute(12)] - protected GUIButtonControl buttonLinks = null; - [SkinControlAttribute(13)] - protected GUIButtonControl buttonImages = null; + /// <summary> + /// MediaPortal Window plugin to display the documentation wiki. + /// </summary> + public class GUIDocumentation : GUIWindow, ISetupForm + { + #region SkinControls + // map skin controls to member variables + [SkinControlAttribute(10)] + protected GUIButtonControl buttonOpen = null; + [SkinControlAttribute(14)] + protected GUIButtonControl buttonBack = null; + [SkinControlAttribute(12)] + protected GUIButtonControl buttonLinks = null; + [SkinControlAttribute(13)] + protected GUIButtonControl buttonImages = null; - [SkinControlAttribute(4)] - protected GUILabelControl searchtermLabel = null; - [SkinControlAttribute(5)] - protected GUILabelControl imagedescLabel = null; - [SkinControlAttribute(20)] - protected GUITextControl txtArticle = null; + [SkinControlAttribute(4)] + protected GUILabelControl searchtermLabel = null; + [SkinControlAttribute(5)] + protected GUILabelControl imagedescLabel = null; + [SkinControlAttribute(20)] + protected GUITextControl txtArticle = null; - [SkinControlAttribute(25)] - protected GUIImage imageControl = null; - #endregion + [SkinControlAttribute(25)] + protected GUIImage imageControl = null; + #endregion - public string _PluginName = "Documentation"; + private string _PluginName = "Documentation"; private int _WindowID = 9999; - private string _pageText = string.Empty; - private ArrayList _linkArray = new ArrayList(); - private ArrayList _imageNameArray = new ArrayList(); - private ArrayList _imageDescArray = new ArrayList(); + private string _currentPage = string.Empty; + private string _pageText = string.Empty; + private ArrayList _linkLabels = new ArrayList(); + private ArrayList _linkValues = new ArrayList(); + private ArrayList _imageLabels = new ArrayList(); + private ArrayList _imageValues = new ArrayList(); - public GUIDocumentation() - { - GetID = _WindowID; - } + public GUIDocumentation() + { + GetID = _WindowID; + } - #region ISetupForm Members + #region ISetupForm Members - // Returns the name of the plugin which is shown in the plugin menu - public string PluginName() - { - return _PluginName; - } + // Returns the name of the plugin which is shown in the plugin menu + public string PluginName() + { + return _PluginName; + } - // Returns the description of the plugin is shown in the plugin menu - public string Description() - { - return "Displays the MediaPortal Documentation wiki."; - } + // Returns the description of the plugin is shown in the plugin menu + public string Description() + { + return "Displays the MediaPortal Documentation wiki."; + } - // Returns the author of the plugin which is shown in the plugin menu - public string Author() - { - return "Peter"; - } + // Returns the author of the plugin which is shown in the plugin menu + public string Author() + { + return "Peter"; + } - // show the setup dialog - public void ShowPlugin() - { - MessageBox.Show("Edit the wikipedia.xml file in MP's root directory to add new sites."); - } + // show the setup dialog + public void ShowPlugin() + { + } - // Indicates whether plugin can be enabled/disabled - public bool CanEnable() - { - return true; - } + // Indicates whether plugin can be enabled/disabled + public bool CanEnable() + { + return true; + } - // get ID of windowplugin belonging to this setup - public int GetWindowId() - { - return _WindowID; - } + // get ID of windowplugin belonging to this setup + public int GetWindowId() + { + return _WindowID; + } - // Indicates if plugin is enabled by default; - public bool DefaultEnabled() - { - return true; - } + // Indicates if plugin is enabled by default; + public bool DefaultEnabled() + { + return true; + } - // indicates if a plugin has its own setup screen - public bool HasSetup() - { - return true; - } + // indicates if a plugin has its own setup screen + public bool HasSetup() + { + return false; + } - /// <summary> - /// If the plugin should have its own button on the main menu of Media Portal then it - /// should return true to this method, otherwise if it should not be on home - /// it should return false - /// </summary> - /// <param name="strButtonText">text the button should have</param> - /// <param name="strButtonImage">image for the button, or empty for default</param> - /// <param name="strButtonImageFocus">image for the button, or empty for default</param> - /// <param name="strPictureImage">subpicture for the button or empty for none</param> - /// <returns>true : plugin needs its own button on home - /// false : plugin does not need its own button on home</returns> - public bool GetHome(out string strButtonText, out string strButtonImage, - out string strButtonImageFocus, out string strPictureImage) - { - strButtonText = _PluginName; - strButtonImage = String.Empty; - strButtonImageFocus = String.Empty; - strPictureImage = String.Empty; - return true; - } - #endregion + /// <summary> + /// If the plugin should have its own button on the main menu of Media Portal then it + /// should return true to this method, otherwise if it should not be on home + /// it should return false + /// </summary> + /// <param name="strButtonText">text the button should have</param> + /// <param name="strButtonImage">image for the button, or empty for default</param> + /// <param name="strButtonImageFocus">image for the button, or empty for default</param> + /// <param name="strPictureImage">subpicture for the button or empty for none</param> + /// <returns>true : plugin needs its own button on home + /// false : plugin does not need its own button on home</returns> + public bool GetHome(out string strButtonText, out string strButtonImage, + out string strButtonImageFocus, out string strPictureImage) + { + strButtonText = _PluginName; + strButtonImage = String.Empty; + strButtonImageFocus = String.Empty; + strPictureImage = String.Empty; + return true; + } + #endregion - public override bool Init() - { - return Load(GUIGraphicsContext.Skin + @"\Documentation.xml"); - } + public override bool Init() + { + return Load(GUIGraphicsContext.Skin + @"\Documentation.xml"); + } protected override void OnPageLoad() { - GetAndDisplayArticle(String.Empty); // display start page + GetAndDisplayArticle(_currentPage); // display start page base.OnPageLoad(); } protected override void OnClicked(int controlId, GUIControl control, - MediaPortal.GUI.Library.Action.ActionType actionType) - { - // we don't want the user to start another search while one is already active - if (_workerCompleted == false) - return; + MediaPortal.GUI.Library.Action.ActionType actionType) + { + // we don't want the user to start another search while one is already active + if (_workerCompleted == false) + return; - // Here we want to open the OSD Keyboard to enter the searchstring - if (control == buttonOpen) - { - // If the search Button was clicked we need to bring up the search keyboard. - VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow( - (int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD); - if (null == keyboard) return; - string searchterm = string.Empty; - keyboard.IsSearchKeyboard = true; - keyboard.Reset(); - keyboard.Text = ""; - keyboard.DoModal(GetID); // show it... + // Here we want to open the OSD Keyboard to enter the searchstring + if (control == buttonOpen) + { + // If the search Button was clicked we need to bring up the search keyboard. + VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow( + (int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD); + if (null == keyboard) return; + keyboard.IsSearchKeyboard = true; + keyboard.Reset(); + keyboard.Text = ""; + keyboard.DoModal(GetID); // show it... - Log.Info(_PluginName + ": OSD keyboard loaded!"); + Log.Info(_PluginName + ": OSD keyboard loaded!"); - // If input is finished, the string is saved to the searchterm var. - if (keyboard.IsConfirmed) - searchterm = keyboard.Text; + // If input is finished, the string is saved to the searchterm var. + if (keyboard.IsConfirmed) + { + _currentPage = keyboard.Text; + Log.Info(_PluginName + ": Searchterm gotten from OSD keyboard: {0}", _currentPage); + GetAndDisplayArticle(_currentPage); + } + } + // The Button holding the Links to other articles + if (control == buttonLinks) + { + if (_linkLabels.Count > 0) + { + // Create a new selection dialog. + GUIDialogMenu pDlgOK = (GUIDialogMenu)GUIWindowManager.GetWindow( + (int)GUIWindow.Window.WINDOW_DIALOG_MENU); + if (pDlgOK != null) + { + pDlgOK.Reset(); + pDlgOK.SetHeading(GUILocalizeStrings.Get(2505)); //Links to other articles: - // If there was a string entered try getting the article. - Log.Info(_PluginName + ": Searchterm gotten from OSD keyboard: {0}", - searchterm); - GetAndDisplayArticle(searchterm); - } - // The Button holding the Links to other articles - if (control == buttonLinks) - { - if (_linkArray.Count > 0) - { - // Create a new selection dialog. - GUIDialogMenu pDlgOK = (GUIDialogMenu)GUIWindowManager.GetWindow( - (int)GUIWindow.Window.WINDOW_DIALOG_MENU); - if (pDlgOK != null) - { - pDlgOK.Reset(); - pDlgOK.SetHeading(GUILocalizeStrings.Get(2505)); //Links to other articles: + // Add all the links from the linkarray. + for (int i = 0; i < _linkLabels.Count; i++) + { + pDlgOK.Add(_linkLabels[i].ToString()); + } + pDlgOK.DoModal(GetID); + if (pDlgOK.SelectedLabel >= 0) + { + _currentPage = _linkValues[pDlgOK.SelectedId-1].ToString() + Log.Info(_PluginName + ": new search from the links array: {0}", _currentPage); + GetAndDisplayArticle(_currentPage); + } + } + } + else + { + // no links available + GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow( + (int)GUIWindow.Window.WINDOW_DIALOG_OK); + dlg.SetHeading(GUILocalizeStrings.Get(257)); // Error + dlg.SetLine(1, GUILocalizeStrings.Get(2506)); // No Links from this article. + dlg.DoModal(GUIWindowManager.ActiveWindow); + } - // Add all the links from the linkarray. - foreach (string link in _linkArray) - { - pDlgOK.Add(link); - } - pDlgOK.DoModal(GetID); - if (pDlgOK.SelectedLabel >= 0) - { - Log.Info(_PluginName + ": new search from the links array: {0}", - pDlgOK.SelectedLabelText); - GetAndDisplayArticle(pDlgOK.SelectedLabelText); - } - } - } - else - { - GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow( - (int)GUIWindow.Window.WINDOW_DIALOG_OK); - dlg.SetHeading(GUILocalizeStrings.Get(257)); // Error - dlg.SetLine(1, GUILocalizeStrings.Get(2506)); // No Links from this article. - dlg.DoModal(GUIWindowManager.ActiveWindow); - } + } + // The Button containing a list of all images from the article + if (control == buttonImages) + { + if (_imageLabels.Count > 0) + { + // Create a new selection dialog. + GUIDialogMenu pDlgOK = (GUIDialogMenu)GUIWindowManager.GetWindow( + (int)GUIWindow.Window.WINDOW_DIALOG_MENU); + if (pDlgOK != null) + { + pDlgOK.Reset(); + pDlgOK.SetHeading(GUILocalizeStrings.Get(2507)); //Images from this article - } - // The Button containing a list of all images from the article - if (control == buttonImages) - { - if (_imageDescArray.Count > 0) - { - // Create a new selection dialog. - GUIDialogMenu pDlgOK = (GUIDialogMenu)GUIWindowManager.GetWindow( - (int)GUIWindow.Window.WINDOW_DIALOG_MENU); - if (pDlgOK != null) - { - pDlgOK.Reset(); - pDlgOK.SetHeading(GUILocalizeStrings.Get(2507)); //Images from this article + // Add all the images from the imagearray. + for (int i = 0; i < _imageLabels.Count; i++) + { + pDlgOK.Add(_imageLabels[i].ToString()); + } + pDlgOK.DoModal(GetID); + 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()); + } + } + } + else + { + // no images available + GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow( + (int)GUIWindow.Window.WINDOW_DIALOG_OK); + dlg.SetHeading(GUILocalizeStrings.Get(257)); // Error + dlg.SetLine(1, GUILocalizeStrings.Get(2508)); // No Images referenced in art. + dlg.DoModal(GUIWindowManager.ActiveWindow); + } + } + // Back to the text button to switch from image view + if (control == buttonBack) + { + 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); + } + base.OnClicked(controlId, control, actionType); + } - // Add all the images from the imagearray. - foreach (string image in _imageDescArray) - { - pDlgOK.Add(image); - } - pDlgOK.DoModal(GetID); - if (pDlgOK.SelectedLabel >= 0) - { - Log.Info(_PluginName + ": new search from the image array: {0}", - _imageDescArray[pDlgOK.SelectedId - 1]); - GetAndDisplayImage(_imageNameArray[pDlgOK.SelectedId - 1].ToString(), - _imageDescArray[pDlgOK.SelectedId - 1].ToString()); - } - } - } - else - { - GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow( - (int)GUIWindow.Window.WINDOW_DIALOG_OK); - dlg.SetHeading(GUILocalizeStrings.Get(257)); // Error - dlg.SetLine(1, GUILocalizeStrings.Get(2508)); // No Images referenced in art. - dlg.DoModal(GUIWindowManager.ActiveWindow); - } - } - // Back to the text button to switch from image view - if (control == buttonBack) - { - 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); - } - base.OnClicked(controlId, control, actionType); - } + private void GetAndDisplayImage(string pagename, string imagename, string imagedesc) + { + DocumentationImage image = new DocumentationImage(pagename, imagename); + string imagefilename = image.GetImageFilename(); + Log.Info(_PluginName + ": Trying to display image file: {0}", imagefilename); - private void GetAndDisplayImage(string imagename, string imagedesc) - { - WikipediaImage image = new WikipediaImage(imagename); - string imagefilename = image.GetImageFilename(); - Log.Info(_PluginName + ": Trying to display image file: {0}", imagefilename); + if (imagefilename != string.Empty && System.IO.File.Exists(imagefilename)) + { + if (txtArticle.IsVisible) + 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; + imageControl.SetFileName(imagefilename); + } + else + { + GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow( + (int)GUIWindow.Window.WINDOW_DIALOG_OK); + dlg.SetHeading(GUILocalizeStrings.Get(257)); // Error + dlg.SetLine(1, GUILocalizeStrings.Get(2512)); // Can't display image. + dlg.SetLine(2, GUILocalizeStrings.Get(2513)); // Please have a look at the logfile. + dlg.DoModal(GUIWindowManager.ActiveWindow); + } + } - if (imagefilename != string.Empty && System.IO.File.Exists(imagefilename)) - { - if (txtArticle.IsVisible) - 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; - imageControl.SetFileName(imagefilename); - } - else - { - GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow( - (int)GUIWindow.Window.WINDOW_DIALOG_OK); - dlg.SetHeading(GUILocalizeStrings.Get(257)); // Error - dlg.SetLine(1, GUILocalizeStrings.Get(2512)); // Can't display image. - dlg.SetLine(2, GUILocalizeStrings.Get(2513)); // Please have a look at the logfile. - dlg.DoModal(GUIWindowManager.ActiveWindow); - } - } + // The core function. + void GetAndDisplayArticle(string searchterm) + { + BackgroundWorker worker = new BackgroundWorker(); - // The core function. - void GetAndDisplayArticle(string searchterm) - { - BackgroundWorker worker = new BackgroundWorker(); + worker.DoWork += new DoWorkEventHandler(DownloadWorker); + worker.RunWorkerAsync(searchterm); - worker.DoWork += new DoWorkEventHandler(DownloadWorker); - worker.RunWorkerAsync(searchterm); + while (_workerCompleted == false) + GUIWindowManager.Process(); + } - while (_workerCompleted == false) - GUIWindowManager.Process(); - } + // All kind of stuff because of the wait cursor ;-) + void DownloadWorker(object sender, DoWorkEventArgs e) + { + _workerCompleted = false; - // All kind of stuff because of the wait cursor ;-) - void DownloadWorker(object sender, DoWorkEventArgs e) - { - _workerCompleted = false; + using (WaitCursor cursor = new WaitCursor()) + lock (this) + { + 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); + _linkLabels.Clear(); + _imageLabels.Clear(); + searchtermLabel.Label = e.Argument.ToString(); + DocumentationPage page = + new DocumentationPage(e.Argument.ToString()); + _pageText = page.text; + _linkLabels = page.linkLabels; + _linkValues = page.linkValues; + _imageLabels = page.imageLabels; + _imageValues = page.imageValues; - using (WaitCursor cursor = new WaitCursor()) - lock (this) - { - 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); - _linkArray.Clear(); - _imageNameArray.Clear(); - _imageDescArray.Clear(); - searchtermLabel.Label = e.Argument.ToString(); - DocumentationPage page = - new DocumentationPage(e.Argument.ToString()); - _pageText = page.text; - _linkArray = page.linkArray(); - _imageNameArray = page.GetImageArray(); - _imageDescArray = page.GetImagedescArray(); + if (_pageText == string.Empty) + txtArticle.Label = "This page does not exist (yet)."; + else + txtArticle.Label = _pageText; + } - if (_pageText == "REDIRECT") - txtArticle.Label = GUILocalizeStrings.Get(2509) + "\n" + - GUILocalizeStrings.Get(2510); - //This page is only a redirect. - //Please chose the redirect aim from the link list. - else if (_pageText == string.Empty) - txtArticle.Label = GUILocalizeStrings.Get(2504); - //Sorry, no Article was found for your searchterm... - else - txtArticle.Label = _pageText; - } + _workerCompleted = true; + } - _workerCompleted = true; - } - - volatile bool _workerCompleted = true; - } -} \ No newline at end of file + volatile bool _workerCompleted = true; + } +} Modified: trunk/plugins/Documentation plugin/DocumentationImage.cs =================================================================== --- trunk/plugins/Documentation plugin/DocumentationImage.cs 2007-03-27 10:49:51 UTC (rev 235) +++ trunk/plugins/Documentation plugin/DocumentationImage.cs 2007-03-27 11:06:38 UTC (rev 236) @@ -37,160 +37,123 @@ namespace Documentation { - /// <summary> - /// This class holds all the logic to get an image from Wikipedia for further using in MP. - /// </summary> - public class WikipediaImage - { - #region vars - private string WikipediaURL = "http://en.wikipedia.org/wiki/Special:Export/"; - private string imagename = string.Empty; - private string imagedesc = string.Empty; - private string imageurl = string.Empty; - private string imagelocal = string.Empty; + /// <summary> + /// This class holds all the logic to get an image from the MediaPortal wiki + /// </summary> + public class DocumentationImage + { + 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 imagedesc = string.Empty; + private string imageurl = string.Empty; + private string imagelocal = string.Empty; - #endregion + /// <summary>This constructor creates a new WikipediaImage</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) + { + this.pagename = pagename; + this.imagename = imagename; + GetImageUrl(); + GetImageFile(); + } - #region constructors - /// <summary>This constructor creates a new WikipediaImage</summary> - /// <summary>The name of the image and language 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> - /// <param name="language">Language of the Wikipedia page</param> - public WikipediaImage(string imagename, string language) - { - SetLanguage(language); - this.imagename = imagename; - GetImageUrl(); - GetImageFile(); - } + /// <summary>Getting the link to the full-size image.</summary> + private void GetImageUrl() + { + string imagepage = string.Empty; - /// <summary>This constructor creates a new WikipediaArticle.</summary> - /// <summary>Only called with a title string, language set to default.</summary> - /// <param name="title">The article's title</param> - public WikipediaImage(string imagename) - : this(imagename, "Default") - { - } + // 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()); - /// <summary>This constructor creates a new WikipediaArticle if no parameter is given.</summary> - /// <summary>Uses an empty searchterm and the default language.</summary> - public WikipediaImage() - : this(string.Empty, "Default") - { - } - #endregion + // Here we get the content from the web and put it to a string + 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;)"); + 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()); + } - #region class methods - /// <summary>Gets the current MP language from mediaportal.xml and sets the Wikipedia URL accordingly</summary> - private void SetLanguage(string language) - { - if (language == "Default") - { - MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml")); - language = xmlreader.GetValueAsString("skin", "language", "English"); - } + //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); - MediaPortal.Profile.Settings detailxmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "wikipedia.xml")); - this.WikipediaURL = detailxmlreader.GetValueAsString(language, "imageurl", "http://en.wikipedia.org/wiki/Image:"); - Log.Info("Wikipedia: Image language set to " + language + "."); - } + iStart = imagepage.IndexOf("href") + 6; + int iEnd = imagepage.IndexOf("\"", iStart); - /// <summary>Get the local filename of the downloaded image.</summary> - /// <returns>String: filename of the downloaded image.</returns> - public string GetImageFilename() - { - string imagelocal = Config.GetFile(Config.Dir.Thumbs, @"wikipedia\" + imagename); - return imagelocal; - } + 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>Getting the link to the full-size image.</summary> - /// <returns>String: parsed article</returns> - private void GetImageUrl() - { - string imagepage = 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\"); - // Build the URL to the Image page - System.Uri url = new System.Uri(WikipediaURL + this.imagename); - Log.Info("Wikipedia: Trying to get following Image page: {0}", url.ToString()); + //Create the wikipedia 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 - { - 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()); - } + if (!System.IO.File.Exists(thumbspath + imagename)) + { - //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); + 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()); + } + } + else + { + Log.Info("Wikipedia: Image exists, no need to redownload!"); + } + } + else + { + Log.Info("Wikipedia: No imageurl. Can't download file."); + } + } - iStart = imagepage.IndexOf("href") + 6; - int iEnd = imagepage.IndexOf("\"", iStart); + /// <summary>Get the local filename of the downloaded image.</summary> + /// <returns>String: filename of the downloaded image.</returns> + public string GetImageFilename() + { + string imagelocal = Config.GetFile(Config.Dir.Thumbs, @"wikipedia\" + imagename); + return imagelocal; + } - 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("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()); - } - } - else - { - Log.Info("Wikipedia: Image exists, no need to redownload!"); - } - } - else - { - Log.Info("Wikipedia: No imageurl. Can't download file."); - } - } - - #endregion - } - -} \ No newline at end of file +} Modified: trunk/plugins/Documentation plugin/DocumentationPage.cs =================================================================== --- trunk/plugins/Documentation plugin/DocumentationPage.cs 2007-03-27 10:49:51 UTC (rev 235) +++ trunk/plugins/Documentation plugin/DocumentationPage.cs 2007-03-27 11:06:38 UTC (rev 236) @@ -1,6 +1,6 @@ #region Copyright (C) 2005-2007 Team MediaPortal -/* +/* * Copyright (C) 2005-2007 Team MediaPortal * http://www.team-mediaportal.com * @@ -8,15 +8,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. - * + * * This Program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -38,131 +38,138 @@ namespace Documentation { - /// <summary> - /// This class holds all the logic to get info from the MediaPortal Wiki and parse it for - /// further usage. - /// </summary> - public class DocumentationPage - { - #region vars + /// <summary> + /// This class holds all the logic to get info from the MediaPortal Wiki and parse it for + /// further usage. + /// </summary> + public class DocumentationPage + { public string text = string.Empty; - public ArrayList linkArray = new ArrayList(); - public ArrayList imageArray = new ArrayList(); - public ArrayList imageDescArray = new ArrayList(); + public ArrayList linkLabels = new ArrayList(); + public ArrayList linkValues = new ArrayList(); + public ArrayList imageLabels = new ArrayList(); + public ArrayList imageValues = new ArrayList(); + private string _PluginName = "Documentation"; private string _WikiURL = "http://wiki.team-mediaportal.com/{0}?action=raw"; - private string _imagePattern = "attachment:"; - #endregion + private string _currentPage; + private ArrayList headers = new ArrayList(); + private ArrayList elms = new ArrayList(); - #region constructors - /// <summary>This constructor creates a new WikipediaArticle</summary> - /// <param name="pageName">The article's page name</param> - public DocumentationPage(string pageName) - { - GetWikiPage(pageName); - ParseWikipediaArticle(); - ParseLinksAndImages(); - } - #endregion + /// <summary>This constructor creates a new DocumentationPage</summary> + /// <param name="pageName">The article's page name</param> + public DocumentationPage(string pageName) + { + _currentPage = pageName; + GetWikiPage(); + ParseArticle(); + } - /// <summary>Downloads the raw Wiki code.</summary> - private void GetWikiPage(string pageName) - { - // Build the URL to the Wikipedia page - System.Uri url = new System.Uri(String.Format(_WikiURL, this._pageName)); - Log.Info("Wikipedia: Trying to get following URL: {0}", url.ToString()); + /// <summary>Downloads the raw Wiki code.</summary> + private void GetWikiPage() + { + // Build the URL to the Wiki page + System.Uri url = new System.Uri(String.Format(_WikiURL, _currentPage)); + Log.Info(_PluginName + ": Trying to get following URL: {0}", url.ToString()); - // Here we get the content from the web and put it to a string - 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;)"); - Stream data = client.OpenRead(url); - StreamReader reader = new StreamReader(data); - //this._unparsedPage = reader.ReadToEnd(); + // Here we get the content from the web and put it to a string + try + { + WebClient client = new WebClient(); + Stream data = client.OpenRead(url); + StreamReader reader = new StreamReader(data); + //this._unparsedPage = reader.ReadToEnd(); this.text = reader.ReadToEnd(); - reader.Close(); - Log.Info("Wikipedia: Success! Downloaded all data."); - } - catch (Exception e) - { - Log.Info("Wikipedia: Exception during downloading:"); - Log.Info(e.ToString()); - } - } + reader.Close(); + Log.Info(_PluginName + ": Success! Downloaded all data."); + } + catch (Exception e) + { + Log.Info(_PluginName + ": Exception during downloading."); + Log.Info(e.ToString()); + } + } - /// <summary>Cuts all special wiki syntax from the article to display plain text</summary> - private void ParseWikipediaArticle() - { - //string tempParsedPage = this._unparsedPage; + /// <summary>Cuts all special wiki syntax from the article to display plain text</summary> + private void ParseArticle() + { + //string tempParsedPage = this._unparsedPage; string tempParsedPage = this.text; if (this.text.Length > 10 && this.text.Substring(0, 10) == "#REDIRECT ") - { - Log.Info("Wikipedia: #REDIRECT found."); - GetWikiPage(this.text.Substring(10)); - ParseWikipediaArticle(); - } - else - { - Log.Info("Wikipedia: Starting parsing."); + { + Log.Info(_PluginName + ": #REDIRECT found."); + _currentPage = this.text.Substring(10); + GetWikiPage(); + ParseArticle(); + } + else + { + Log.Info(_PluginName + ": Starting parsing."); // remove control codes & remarks (#blah) - this.text = Regex.Replace(this.text, @"^#.+\n", String.Empty, + // $ only matches \n, not \r\n ???? + this.text = Regex.Replace(this.text, @"^#.+\r\n", String.Empty, RegexOptions.Multiline); - // TODO: no interpretation in headers (not even ``) - - // explicit hyperlinks ([:pagename:link text]) - this.text = Regex.Replace(this.text, @"\[:[^:]+:(?: |\t)*([^\]]+)\]", - "[$1]"); + // sorry, no TOC + this.text = Regex.Replace(this.text, @"\[\[TableOfContents\]\](?:\r\n)?", String.Empty); - // TODO: [:page name] - // TODO: ["page name"] - - // camelcase hyperlinks that are not in headers (PageName) - // TODO: prevent camelcase links inside explicit hyperlinks - this.text = Regex.Replace(this.text, @"(?<!^=(?: )+|\w)((?:[A-Z][a-z0-9]+){2,})(?!\w)", - "[$1]", RegexOptions.Multiline); + // remove certain elements from further processing (to prevent camelcase words in them from + // being converted to links) - // de-linked camelcase (!PageName) - this.text = Regex.Replace(this.text, @"(?<=\W)!((?:[A-Z][a-z0-9]+){2,})(?=\W)", - "$1"); + // headers + this.text = Regex.Replace(this.text, @"(?:\r|\n)*(?<headlvl>=+) (?<header>[^=]+) =+(?:\r|\n)+", + new MatchEvaluator(StripElements)); - // TODO: /SubPage, SomePage/SomeSubPage - - // TODO: Wiki:WikiPage, MoinMoin:SomePage - - // enclosed external hyperlinks ([http://example.com]) - this.text = Regex.Replace(this.text, @"\[(http://[^ \]]+)\]", "$1"); + // image attachments + this.text = Regex.Replace(this.text, @"attachment:(?<img>[\w\-_]+)(?<ext>\.gif|\.jpg|.png)", + new MatchEvaluator(StripElements)); + // TODO: external images (http://example.org/image.jpg) + // TODO: attachment:file.zip + // enclosed external hyperlinks ([http://example.com]) // external hyperlinks with label ([http://example.com an example]) - this.text = Regex.Replace(this.text, @"\[(http://[^ \]]+) ([^\]]+)\]", "$2 ($1)"); + this.text = Regex.Replace(this.text, @"\[(?<url>http://[^ \]]+)(?: (?<label>[^\]]+))?\]", + new MatchEvaluator(StripElements)); - // images (attachment:file.gif) - this.text = Regex.Replace(this.text, @"attachment:([^\s\|]+)(?:\.gif|\.jpg)", - "[img:$1]"); + // 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]) + @"\[:(?<page>[^:\]]+)(?::(?: |\t)*(?<label>[^\]]+))?\]" + // wiki-labelled links ([wiki:pagename], [wiki:pagename link text]) + + "|" + @"\[wiki:(?<page>[^ \]]+)(?: (?<label>[^\]]+))?\]" + // quoted links (["page name"]) + + "|" + @"\[""(?<page>[^\]]+)""\]" + // camelcase links (PageName) + + "|" + @"\b(?<!!)(?<page>/?(?:[A-Z][a-z0-9]+){2,})\b" + // TODO: SomePage/SomeSubPage + // TODO: Wiki:WikiPage, MoinMoin:SomePage + , new MatchEvaluator(StripElements)); - // TODO: attachment:file.zip - - // TODO: bold & italic ('''text''' -> *text* & /text/) + // re-insert elements + this.text = Regex.Replace(this.text, @"{elm(?<index>[^}]+)}", new MatchEvaluator(ReturnElements)); - // TODO: lists - + 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,}<[^>]*>", "|"); + + // 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|=|\|)", - " "); + //this.text = Regex.Replace(this.text, @"(?<!\r\n|=|\|)\r\n(?!\r\n|=|\|)", " "); // paragraphs with excessive linebreaks - this.text = Regex.Replace(this.text, @"(?:\r\n){2,}", + this.text = Regex.Replace(this.text, @"(?:\r\n){2,}", Environment.NewLine + Environment.NewLine); // whitespace around titles - this.text = Regex.Replace(this.text, @"(?:\r\n)+(=.+=)(?:\r\n)+", - Environment.NewLine + Environment.NewLine + "$1" + Environment.NewLine); + //this.text = Regex.Replace(this.text, @"(?:\r\n)+(=.+=)(?:\r\n)+", + // Environment.NewLine + Environment.NewLine + "$1" + Environment.NewLine); // forced linebreaks ([[BR]]) this.text = Regex.Replace(this.text, @"\[\[BR\]\]", Environment.NewLine); @@ -170,159 +177,82 @@ // quote escaping (``) this.text = Regex.Replace(this.text, @"``", String.Empty); - Log.Info("Wikipedia: Finished parsing."); - } - } + Log.Info(_PluginName + ": Finished parsing."); + } + } - /// <summary>Gets Links out of the article. External links are thrown away, links to other - /// wikipedia articles get into the link array, images to the image array</summary> - private void ParseLinksAndImages() - { - Log.Info("Wikipedia: Starting parsing of links and images."); - //string tempParsedArticle = this._unparsedPage; - string tempParsedArticle = this.text; - int iStart = 0, iEnd = 0, iPipe = 0; + private string StripElements ( Match m ) + { + Log.Info(_PluginName + ": Strip element " + m.Value); + Log.Info("match found at " + m.Index); + if (m.Groups["header"].Value != "") + { + // headers + if (m.Index < 10) + { + // no newlines when first header + elms.Add(m.Value.ToUpper().Trim() + Environment.NewLine); + } + else + { + elms.Add(Environment.NewLine + Environment.NewLine + m.Value.ToUpper().Trim() + + Environment.NewLine); + } + } + else if (m.Groups["page"].Value != "") + { + // wiki links + string label = m.Groups["label"].Value; + string page = m.Groups["page"].Value; + if (label == "") label = page; + if (page == _currentPage) + { + // don't return links to current page, but do format them properly + elms.Add(label); + } + else + { + if (page[0] == '/') page = _currentPage + page; + // FIXME: different links with identical labels may exist! + if (!linkLabels.Contains(label)) + { + linkLabels.Add(label); + linkValues.Add(m.Groups["page"].Value); + } + elms.Add("<" + label + "(" + (linkLabels.IndexOf(label)+1) + ")>"); + } + } + else if (m.Groups["url"].Value != "") + { + // external hyperlinks + if (m.Groups["label"].Value == "") + { + elms.Add(m.Groups["url"].Value); + } + else + { + elms.Add(m.Groups["label"].Value + " (" + m.Groups["url"].Value + ")"); + } + } + else if (m.Groups["img"].Value != "") + { + // image attachments + string img = m.Groups["img"].Value; + // FIXME: images with same name but different extension may exist! + if (!imageLabels.Contains(img)) + { + imageLabels.Add(img); + imageValues.Add(m.Groups["img"].Value + m.Groups["ext"].Value); + } + elms.Add("[" + img + "(" + (imageLabels.IndexOf(img)+1) + ")]"); + } + return "{elm" + (elms.Count-1) + "}"; + } - // Surrounded by [[IMAGEPATTERN: and ]] are the links to IMAGES. - // We need to check for the localized image keyword but also for the English as this - // is commonly used in some local sites. - // Example: [[Bild:H_NeuesRathaus1.jpg|left|thumb|Das [[Neues Rathaus (Hannover)|Neue Rathaus]] mit Maschteich]] - while ((iStart = tempParsedArticle.IndexOf("[[" + _imagePattern + ":", iStart)) >= 0 || - (iStart = tempParsedArticle.IndexOf("[[Image:")) >= 0) - { - iEnd = tempParsedArticle.IndexOf("]]", (iStart + 2)) + 2; - int disturbingLink = iStart; - - // Descriptions of images can contain links! - // [[Bild:Hannover Merian.png|thumb|[[Mattheus Merian|Merian]]-Kupferstich um 1650, im Vordergrund Windmohle auf dem [[Lindener Berg]]]] - while (tempParsedArticle.IndexOf("[[", disturbingLink + 2) >= 0 && - tempParsedArticle.IndexOf("[[", disturbingLink + 2) < iEnd) - { - disturbingLink = tempParsedArticle.IndexOf("[[", disturbingLink + 2); - iEnd = tempParsedArticle.IndexOf("]]", disturbingLink) + 2; - iEnd = tempParsedArticle.IndexOf("]]", iEnd) + 2; - } - // Extract the Text - string keyword = tempParsedArticle.Substring(iStart, iEnd - iStart); - - //Remove all links from the image description. - while (keyword.IndexOf("[[", 2) >= 0) - { - int iStartlink = keyword.IndexOf("[[", 2); - int iEndlink = keyword.IndexOf("]]", iStartlink) + 2; - // Extract the Text - string linkkeyword = keyword.Substring(iStartlink, iEndlink - iStartlink); - - // Parse Links to other keywords. - // 1st type of keywords is like [[article|displaytext]] - // for the 2nd the article and displayed text are equal [[article]]. - if (linkkeyword.IndexOf("|") > 0) - linkkeyword = linkkeyword.Substring(linkkeyword.IndexOf("|") + 1, - linkkeyword.IndexOf("]]") - linkkeyword.IndexOf("|") - 1); - else - linkkeyword = linkkeyword.Substring(linkkeyword.IndexOf("[[") + 2, - linkkeyword.IndexOf("]]") - linkkeyword.IndexOf("[[") - 2); - - keyword = keyword.Substring(0, iStartlink) + linkkeyword + - keyword.Substring(iEndlink, keyword.Length - iEndlink); - } - - int iStartname = keyword.IndexOf(":") + 1; - int iEndname = keyword.IndexOf("|"); - string imagename = keyword.Substring(iStartname, iEndname - iStartname); - - //Image names must not contain spaces! - imagename = imagename.Replace(" ", "_"); - - int iStartdesc = keyword.LastIndexOf("|") + 1; - int iEnddesc = keyword.LastIndexOf("]]"); - string imagedesc = keyword.Substring(iStartdesc, iEnddesc - iStartdesc); ; - - this.imageArray.Add(imagename); - this.imageDescArray.Add(imagedesc); - Log.Debug("Wikipedia: Image added: {0}, {1}", imagedesc, imagename); - - tempParsedArticle = tempParsedArticle.Substring(0, iStart) + - tempParsedArticle.Substring(iEnd, tempParsedArticle.Length - iEnd); - } - - // surrounded by [[ and ]] are the links to other articles. - Log.Debug("Wikipedia: Starting Link parsing."); - string parsedKeyword, parsedLink; - iStart = iEnd = 0; - try - { - while ((iStart = tempParsedArticle.IndexOf("[[", iStart)) >= 0) - { - iEnd = tempParsedArticle.IndexOf("]]") + 2; - // Extract the Text - string keyword = tempParsedArticle.Substring(iStart, iEnd - iStart); - - // Parse Links to other keywords. - // 1st type of keywords is like [[article|displaytext]] - if ((iPipe = keyword.IndexOf("|")) > 0) - { - parsedKeyword = keyword.Substring(iPipe + 1, keyword.Length - iPipe - 3); - parsedLink = keyword.Substring(2, iPipe - 2); - if (!this.linkArray.Contains(parsedLink)) - { - this.linkArray.Add(parsedLink); - //Log.Debug("Wikipedia: Link added: {0}, {1}", parsedLink, parsedKeyword); - } - } - else if (keyword.IndexOf(":") > 0) - { - // for the 2nd a ":" is a link to the article in another language. - // TODO Add links to other languages!!! - parsedKeyword = String.Empty; - } - else - { - // for the 3rd the article and displayed text are equal [[article]]. - parsedKeyword = keyword.Substring(2, keyword.Length - 4); - if (!this.linkArray.Contains(parsedKeyword)) - { - this.linkArray.Add(parsedKeyword); - //Log.Debug("Wikipedia: Link added: {0}", parsedKeyword); - } - } - - StringBuilder builder = new StringBuilder(tempParsedArticle); - builder.Remove(iStart, iEnd - iStart); - builder.Insert(iStart, parsedKeyword); - tempParsedArticle = builder.ToString(); - } - } - catch (Exception e) - { - Log.Error("Wikipedia: {0}", e.ToString()); - Log.Error("Wikipedia: tempArticle: {0}", tempParsedArticle); - } - Log.Debug("Wikipedia: Finished Link parsing: {0} Links added.", linkArray.Count); - - // surrounded by [ and ] are external Links. Need to be removed. - Log.Debug("Wikipedia: Removing external links"); - iStart = -1; - try - { - while ((iStart = tempParsedArticle.IndexOf("[")) >= 0) - { - iEnd = tempParsedArticle.IndexOf("]") + 1; - - StringBuilder builder = new StringBuilder(tempParsedArticle); - builder.Remove(iStart, iEnd - iStart); - tempParsedArticle = builder.ToString(); - } - } - catch (Exception e) - { - Log.Error("Wikipedia: {0}", e.ToString()); - Log.Error("Parsing Error: " + tempParsedArticle + "\nSTART: " + iStart + "\nEND: " - + iEnd); - } - - Log.Info("Wikipedia: Finished parsing of links and images."); - //this._parsedPage = tempParsedArticle; - } - } -} \ No newline at end of file + private string ReturnElements ( Match m ) + { + return elms[ Int32.Parse( m.Groups["index"].Value ) ].ToString(); + } + + } +} Property changes on: trunk/plugins/Documentation plugin/skin ___________________________________________________________________ Name: svn:ignore + *.bak This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |