|
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.
|