static void ExportPlantsTableToMediawikiAPI() { string url=Globals.Options.GetElementAsString("xml.Options.Mediawiki.URL"); string username=Globals.Options.GetElementAsString("xml.Options.Mediawiki.Username"); string password=Globals.Options.GetElementAsString("xml.Options.Mediawiki.Passwort"); Site wiki=new Site(url, username, password); Page page=new Page(wiki, "Liste der Pflanzen"); page.Load(); string monsterlist=GetPlantAsMediaWiki(); //Monster Vorkommen ermitteln string text=page.text; string start="{{Anker|AutomaticStartPlantList}}"; string end="{Anker|AutomaticEndPlantList}}"; int idxBeginInfobox=text.IndexOf(start, 0); int idxEndInfobox=text.IndexOf(end, 0); int lengthOfString=(idxEndInfobox-idxBeginInfobox)-start.Length-1; string monsterdrops=text.Substring(idxBeginInfobox+start.Length, lengthOfString); if(monsterdrops!="\n") { text=text.Replace(monsterdrops, ""); } string replaceString="{{Anker|AutomaticStartPlantList}}\n"+monsterlist; text=text.Replace(start, replaceString); if(page.text!=text) { page.text=text; page.Save("Bot: Liste der Pflanzen aktualisiert.", true); } }
static void UpdateLuaInMediaWiki() { if(Globals.folder_root=="") { Console.WriteLine("Bitte geben sie in den Optionen den Pfad zum Invertika Repository an."); return; } if(Globals.Options.GetElementAsString("xml.Options.Mediawiki.URL")=="") { Console.WriteLine("Bitte geben sie eine Mediawiki URL in den Optionen an."); return; } if(Globals.Options.GetElementAsString("xml.Options.Mediawiki.Username")=="") { Console.WriteLine("Bitte geben sie einen Mediawiki Nutzernamen in den Optionen an."); return; } if(Globals.Options.GetElementAsString("xml.Options.Mediawiki.Passwort")=="") { Console.WriteLine("Bitte geben sie einen Mediawiki Passwort in den Optionen an."); return; } string url=Globals.Options.GetElementAsString("xml.Options.Mediawiki.URL"); string username=Globals.Options.GetElementAsString("xml.Options.Mediawiki.Username"); string password=Globals.Options.GetElementAsString("xml.Options.Mediawiki.Passwort"); Site wiki=new Site(url, username, password); List<string> luafiles=FileSystem.GetFiles(Globals.folder_data_scripts_libs, true, "*.lua"); foreach(string file in luafiles) { LuaDocParser ldp=new LuaDocParser(file); LucDocReturn ret=ldp.ExportLuaDocToMediaWiki(); switch(ret.DocType) { case LuaDocType.Module: { Page page=new Page(wiki, ret.Name+" (Lua Modul)"); page.Load(); string text=page.text; if(text=="") { List<string> lines=new List<string>(); lines.Add("{{Status_Green}}"); lines.Add("{{Automatic}}"); lines.Add(""); lines.Add("==Funktionen=="); //Funktions lines.Add("{{Anker|AutomaticStartFunctions}}"); lines.AddRange(ret.Functions); lines.Add("{{Anker|AutomaticEndFunctions}}"); lines.Add(""); lines.Add("[[Kategorie: Lua]]"); lines.Add("[[Kategorie: Lua Modul]]"); foreach(string ll in lines) { text+=ll+"\n"; } if(page.text!=text) { page.text=text; page.Save("Sourcecode Dokumentation erstellt.", false); } } else //Entsprechende Bereiche ersetzen { string start="{{Anker|AutomaticStartFunctions}}"; string end="{Anker|AutomaticEndFunctions}}"; int idxBeginInfobox=text.IndexOf(start, 0); int idxEndInfobox=text.IndexOf(end, 0); int lengthOfString=(idxEndInfobox-idxBeginInfobox)-start.Length-1; string vorkommen=text.Substring(idxBeginInfobox+start.Length, lengthOfString); if(vorkommen!="\n") { text=text.Replace(vorkommen, ""); } string replaceString="{{Anker|AutomaticStartFunctions}}\n"; foreach(string ll in ret.Functions) { replaceString+=ll+"\n"; } text=text.Replace(start, replaceString); if(page.text!=text) { page.text=text; page.Save("Sourcecode Dokumentation aktualisiert.", true); } } break; } default: { break; } } } Console.WriteLine("Lua Dokumentation aktualisiert."); }
/// <summary>Gets page titles for this PageList from links in some wiki page. All links /// will be retrieved, from all namespaces, except interwiki links to other /// sites. Use FilterNamespaces() or RemoveNamespaces() function to remove pages from /// unwanted namespaces (categories, images, etc.)</summary> /// <param name="pageTitle">Page title as string.</param> /// <example><code>pageList.FillFromAllPageLinks("Art");</code></example> public void FillFromPageLinks(string pageTitle) { if (string.IsNullOrEmpty(pageTitle)) throw new ArgumentNullException("pageTitle"); Regex wikiLinkRegex = new Regex(@"\[\[ *:*(.+?)(]]|\|)"); Page page = new Page(site, pageTitle); page.Load(); MatchCollection matches = wikiLinkRegex.Matches(page.text); Regex outWikiLink = new Regex("^(" + site.generalData["interwiki"] + "):"); foreach (Match match in matches) if (!outWikiLink.IsMatch(match.Groups[1].Value)) pages.Add(new Page(site, match.Groups[1].Value)); Console.WriteLine( Bot.Msg("PageList filled with links, found on \"{0}\" page."), pageTitle); }