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