本文整理汇总了C#中DotNetWikiBot.Page.GetNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# Page.GetNamespace方法的具体用法?C# Page.GetNamespace怎么用?C# Page.GetNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DotNetWikiBot.Page
的用法示例。
在下文中一共展示了Page.GetNamespace方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessPage
protected override void ProcessPage(Page p, EditStatus edit)
{
if (p.GetNamespace() != 0) return;
p.Load();
var changes = new List<string>();
p.InsertPlaceholders(GeneralExtensions.Placeholder.Default);
foreach (var replacement in Replacements.Where(replacement => p.text.Contains(replacement.Key)))
{
p.text = p.text.Replace(replacement.Key, replacement.Value);
changes.Add(replacement.Key + " → " + replacement.Value);
}
foreach (var replacement in RegexReplacements)
{
var pattern = replacement.Key;
var replace = replacement.Value;
pattern.Replace(p.text, match =>
{
var replaceWith = RegexParseReplaceWithString(match, replace);
changes.Add(match.Value + " → " + replaceWith);
return replaceWith;
});
}
p.RemovePlaceholders();
if (changes.Count > 0)
{
edit.Save = true;
edit.EditComment = "Ersetzt: " + string.Join(", ", changes);
}
}
示例2: ProcessPage
protected override void ProcessPage(Page p, EditStatus edit)
{
if (p.GetNamespace() != 0) return;
p.Load();
var before = p.text;
var changes = new List<string>();
Match m;
while ((m = MuenzenRegex.Match(p.text)).Success)
{
var kupfer = 0;
var silber = 0;
var gold = 0;
int.TryParse(m.Groups["kupfer"].Value, out kupfer);
int.TryParse(m.Groups["silber"].Value, out silber);
int.TryParse(m.Groups["gold"].Value, out gold);
var muenzen = kupfer + 100*silber + 10000*gold;
p.text = p.text.Replace(m.Value.Trim(), "{{Münzen|" + muenzen + "}}");
changes.Add(string.Format("{0}g {1}s {2}k → {3}", gold, silber, kupfer, muenzen));
}
if (changes.Count > 0)
{
edit.EditComment = string.Format("Münzen ({0}x): {1}", changes.Count, string.Join(", ", changes));
edit.Save = true;
}
}
示例3: Main
/// The entry point function. Start coding here.
public static void Main()
{
// Compiled documentation is available in Documentation.chm file.
// A very compehensive DotNetWikiBot usage examples can be found
// in unit testing file called DebugBot.cs:
// http://sourceforge.net/p/dotnetwikibot/svn/HEAD/tree/DebugBot.cs
// Bot scripts repository is being created at
// https://sourceforge.net/apps/mediawiki/dotnetwikibot/index.php?title=BSR
// You are welcome to share your scripts.
// And here you can find some basic usage examples:
Site site = new Site("https://en.wikipedia.org", "YourBotLogin", "YourBotPassword");
//Site site = new Site("http://mywikisite.com", "YourBotLogin", "YourBotPassword");
//Site site = new Site("https://sourceforge.net/apps/mediawiki/YourProjectName/",
//"YourSourceForgeLogin", "YourSourceForgePassword");
site.ShowNamespaces();
Page p = new Page(site, "Wikipedia:Sandbox");
p.LoadWithMetadata();
if (p.Exists())
Console.WriteLine(p.text);
p.SaveToFile("MyArticles\\file.txt");
p.LoadFromFile("MyArticles\\file.txt");
p.ResolveRedirect();
Console.WriteLine(p.GetNamespace());
p.text = "new text";
site.defaultEditComment = "saving test";
site.minorEditByDefault = true;
p.Save();
/**
string[] arr = {"Art", "Poetry", "Cinematography", "Camera", "Image"};
PageList pl = new PageList(site, arr);
pl.LoadWithMetadata();
pl.FillFromAllPages("Sw", 0, true, 100);
pl.SaveTitlesToFile("MyArticles\\list.txt");
pl.FillFromFile("MyArticles\\list.txt");
pl.FillFromCategory("Category:Cinematography");
pl.FillFromLinksToPage("Cinematography");
pl.RemoveEmpty();
pl.RemoveDisambigs();
pl.ResolveRedirects();
Console.WriteLine(pl[2].text);
pl[1].text = "#REDIRECT [[Some Page]]";
pl.FilterNamespaces(new int[] {0,3});
pl.RemoveNamespaces(new int[] {2,4});
pl.Clear();
site.defaultEditComment = "my edit comment";
site.minorEditByDefault = true;
pl.Save();
/**/
}
示例4: ProcessPage
protected override void ProcessPage(Page p, EditStatus edit)
{
if (p.GetNamespace() != 0) return;
p.Load();
var templates = p.GetAllTemplates().Where(t => t.Title.ToLower() == "infobox gegenstand");
foreach (var template in templates)
{
if (template.Parameters.ContainsKey("beschreibung") && _regex.IsMatch(template.Parameters["beschreibung"]))
{
template.Parameters["beschreibung"] = _regex.Replace(template.Parameters["beschreibung"], "[[$1]]");
template.Save();
edit.Save = true;
edit.EditComment = "Attribute in Gegenstandsbeschreibung verlinkt";
}
}
}
示例5: ProcessPage
protected override void ProcessPage(Page p, Job.EditStatus edit)
{
if(p.GetNamespace() != 0) return;
p.Load();
foreach (var template in p.GetAllTemplates().Where(
template => (template.Title.Equals("Ausrüstungswerte", StringComparison.OrdinalIgnoreCase)
|| template.Title.Equals("Rezept", StringComparison.OrdinalIgnoreCase)) &&
(template.Parameters.HasValueIgnoreCase("seltenheit", "Aufgestiegen") &&
!template.Parameters.ContainsKey("aufwertung"))))
{
template.InsertParameterAfter("aufwertung", "nein", "infusion2", "infusion");
template.Save();
edit.EditComment = "'aufwertung = nein' hinzugefügt";
edit.Save = true;
}
}
示例6: ProcessPage
protected override void ProcessPage(Page p, EditStatus edit)
{
if (p.GetNamespace() != 0)
return;
p.Load();
//Nur Seiten mit Vorlage:Infobox NSC
if (p.GetAllTemplates().All(t => t.Title.ToLower() != "infobox nsc")) return;
//Nur Seiten, die eine Unterseite mit Angeboten haben...
var m = Regex.Match(p.text, "\\{\\{:" + p.title + "/([^}]+)}}");
if (!m.Success) return;
var subpageTitle = m.Groups[1].Value;
var subpage = new Page(p.site, p.title + "/" + subpageTitle);
subpage.Load();
if (!subpage.Exists())
{
p.text = p.text.Replace(m.Value, "");
edit.EditComment = "Verweis auf nicht vorhandene Angebots-Unterseite „" + subpage.title + "“ entfernt";
edit.Save = true;
}
else
{
var pl2 = new PageList(p.site);
pl2.FillFromLinksToPage(subpage.title);
if (pl2.Count() > 1) return;
var subpageContent = Regex.Replace(subpage.text, "<noinclude>.*?</noinclude>", "").Trim();
p.text = p.text.Replace(m.Value, subpageContent);
subpage.text = "{{Löschantrag|[Bot] In den Hauptartikel „[[" + p.title + "]]“ verschoben}}\n" +
subpage.text;
subpage.Save("[Bot] In Hauptartikel „[[" + p.title + "]]“ verschoben", true);
edit.EditComment = "Angebot von „" + subpage.title + "“ in den Hauptartikel verschoben";
edit.Save = true;
}
}
示例7: ProcessPage
protected override void ProcessPage(Page p, EditStatus edit)
{
if (p.GetNamespace() != 0)
return;
p.Load();
var before = p.text;
foreach (var template in p.GetAllTemplates())
{
if (template.Title == "#dpl:" && template.Parameters.ContainsKey("category") &&
template.Parameters.ContainsKey("linksto") && template.Parameters.ContainsKey("format"))
{
var linksTo = template.Parameters["linksto"];
linksTo = linksTo == p.title ? "{{PAGENAME}}" : linksTo;
if (template.Parameters["category"].ToLower() == "trophäe")
p.text = p.text.Replace(template.Text, "Beschaffung|gegenstand=" + linksTo + "|kategorie=Trophäe");
else if (template.Parameters["category"].ToLower() == "behälter")
p.text = p.text.Replace(template.Text, "Beschaffung|gegenstand=" + linksTo + "|kategorie=Behälter");
}
}
if (p.text.Contains("#dpl:") && p.text.Contains("Behälter"))
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("{0} still contains dpl", p.title);
Console.ResetColor();
}
if (p.text != before)
{
edit.Save = true;
edit.EditComment = "DPL durch {{Beschaffung}} ersetzt";
}
}
示例8: ProcessPage
protected override void ProcessPage(Page p, EditStatus edit)
{
if (p.GetNamespace() != 0) return;
p.Load();
var allChanges = new List<string>();
var before = p.text;
foreach (var template in p.GetAllTemplates())
{
var templateChanges = new List<string>();
if (Replacements.ContainsKey(template.Title))
{
foreach (var parameter in template.Parameters)
{
if (Replacements[template.Title].ContainsKey(parameter.Key))
{
template.ChangeParametername(parameter.Key, Replacements[template.Title][parameter.Key]);
templateChanges.Add(parameter.Key + " → " + Replacements[template.Title][parameter.Key]);
}
}
}
if (templateChanges.Count > 0)
{
template.Save();
allChanges.Add(template.Title + ": " + string.Join(", ", templateChanges));
}
}
if (allChanges.Count > 0)
{
edit.Save = true;
edit.EditComment = "Parameter umbenannt: " + string.Join("; ", allChanges);
}
}
示例9: ProcessPage
protected override void ProcessPage(Page p, EditStatus edit)
{
if (p.GetNamespace() != 0)
return;
p.Load();
var changes = new List<string>();
var templates = p.GetAllTemplates();
foreach (var template in templates)
{
if (template.Title == "Rezept")
{
if (template.Parameters.ContainsKey("seltenheit")
&&
new[] {"meisterwerk", "selten", "exotisch", "legendär"}.Contains(
template.Parameters["seltenheit"].ToLower())
&& template.Parameters.ContainsKey("gebunden") &&
template.Parameters["gebunden"].ToLower() == "benutzung")
{
template.Parameters.Remove("gebunden");
template.Save();
changes.Add("Rezept: 'gebunden = benutzung' entfernt");
}
}
else if (template.Title == "Eventbelohnung")
{
string[] parametersToRemove =
{
"ep-gold", "ep-silber", "ep-bronze",
"ep-gold-niederlage", "ep-silber-niederlage", "ep-bronze-niederlage",
"ep-niederlage",
"karma-gold", "karma-silber", "karma-bronze",
"karma-gold-niederlage", "karma-silber-niederlage", "karma-bronze-niederlage",
"karma-niederlage",
"münzen-gold", "münzen-silber", "münzen-bronze",
"münzen-gold-niederlage", "münzen-silber-niederlage", "münzen-bronze-niederlage",
"münzen-niederlage"
};
var removed = new List<string>();
foreach (var parameter in parametersToRemove)
{
if (template.Parameters.ContainsKey(parameter))
{
template.Parameters.Remove(parameter);
removed.Add(parameter);
}
}
if (removed.Any())
{
template.Save();
changes.Add("Eventbelohnung: '" + string.Join("', '", removed) + "' entfernt");
}
}
else if (template.Title == "Infobox Aufgabe")
{
string[] parametersToRemove =
{
"erfahrung", "münzen"
};
var removed = new List<string>();
foreach (var parameter in parametersToRemove)
{
if (template.Parameters.ContainsKey(parameter))
{
template.Parameters.Remove(parameter);
removed.Add(parameter);
}
}
if (removed.Any())
{
template.Save();
changes.Add("Infobox Aufgabe: '" + string.Join("', '", removed) + "' entfernt");
}
}
else if (template.Title == "Infobox Farbstoff")
{
string[] parametersToRemove =
{
"seltenheit"
};
var removed = new List<string>();
foreach (var parameter in parametersToRemove)
{
if (template.Parameters.ContainsKey(parameter))
{
template.Parameters.Remove(parameter);
removed.Add(parameter);
}
}
if (removed.Any())
{
template.Save();
changes.Add("Infobox Farbstoff: '" + string.Join("', '", removed) + "' entfernt");
}
}
}
//.........这里部分代码省略.........
示例10: ProcessPage
protected override void ProcessPage(Page p, EditStatus edit)
{
var changes = new List<string>();
if (p.GetNamespace() != 0) return;
p.Load();
var templates = p.GetAllTemplates();
foreach (var template in templates)
{
var changeCountBeforeTemplate = changes.Count;
#region [G] Infobox Gegenstand
if (template.Title.Equals("Infobox Gegenstand", StringComparison.OrdinalIgnoreCase))
{
//stapelbar = ja/###/...
if (template.Parameters.HasNotValueIgnoreCase("stapelbar", "nein"))
{
changes.Add(string.Format("'stapelbar = {0}' entfernt", template.Parameters["stapelbar"]));
template.Parameters.Remove("stapelbar");
}
//wert -> händlerwert
if (template.Parameters.ContainsKey("wert"))
{
//wenn händlerwert schon existiert löschen
if (template.Parameters.ContainsKey("händlerwert"))
{
template.Parameters.Remove("wert");
changes.Add("'wert' entfernt");
}
else
{
template.ChangeParametername("wert", "händlerwert");
changes.Add("'wert' zu 'händlerwert' geändert");
}
}
//seelengebunden = ja -> gebunden = seele
if (template.Parameters.HasValueIgnoreCase("seelengebunden", "ja"))
{
//wenn gebunden schon existiert löschen
if (template.Parameters.ContainsKey("gebunden"))
{
changes.Add(string.Format("'seelengebunden = {0}' entfernt", template.Parameters["seelengebunden"]));
template.Parameters.Remove("seelengebunden");
}
else
{
changes.Add(string.Format("'seelengebunden = {0}' zu 'gebunden = seele' geändert", template.Parameters["seelengebunden"]));
template.ChangeParametername("seelengebunden", "gebunden");
template.Parameters["gebunden"] = "seele";
}
}
//seltenheit = ramsch -> seltenheit = scrhott
if (template.Parameters.HasValueIgnoreCase("seltenheit", "ramsch"))
{
changes.Add(string.Format("'seltenheit = {0}' zu 'seltenheit = Schrott' geändert", template.Parameters["seltenheit"]));
template.Parameters["seltenheit"] = "Schrott";
}
//benutzungen = 1
if (template.Parameters.HasValue("benutzungen","1"))
{
changes.Add("'benutzungen = 1' entfernt");
template.Parameters.Remove("benutzungen");
}
}
#endregion
#region [J] Angebot
if (template.Title.Equals("angebot", StringComparison.OrdinalIgnoreCase))
{
//seltenheit = ja entfernen
if (template.Parameters.HasValueIgnoreCase("seltenheit", "ja"))
{
changes.Add("'seltenheit = ja' entfernt");
template.Parameters.Remove("seltenheit");
}
//stufe = ja entfernen
if (template.Parameters.HasValueIgnoreCase("stufe", "ja"))
{
changes.Add("'stufe = ja' entfernt");
template.Parameters.Remove("stufe");
}
//typ = ja entfernen
if (template.Parameters.HasValueIgnoreCase("typ", "ja"))
{
changes.Add("'typ = ja' entfernt");
template.Parameters.Remove("typ");
}
//werte = ja entfernen
if (template.Parameters.HasValueIgnoreCase("werte", "ja"))
{
changes.Add("'werte = ja' entfernt");
template.Parameters.Remove("werte");
}
}
//.........这里部分代码省略.........
示例11: ProcessPage
protected override void ProcessPage(Page p, EditStatus edit)
{
if (p.GetNamespace() != 0) return;
p.Load();
//ignore pages which already have {{standort}}
if (p.GetAllTemplates().Any(t => t.Title == "Standort")) return;
var section = p.GetSectionByName("Standort", false);
if (section == null) return;
var standorte = new List<string>();
Match lastMatch = null;
var prependText = "";
var remainingText = "";
var foundNonSchauplatz = false;
var compactTemplate = true;
var lines = section.Content.GetLines().Skip(1).ToList();
var addAdditionalStar = !lines.First().Contains('*') && lines.First().Length > 2 && PageIsSchauplatz(lines.First().Trim('[', ']', '\'', ';'));
foreach (var line in lines)
{
//just add the line to the remaining text as soon as we found a non schauplatz
if (foundNonSchauplatz) remainingText += "\r\n" + line;
if (string.IsNullOrWhiteSpace(line))
continue;
var match = StandortItemRegex.Match((addAdditionalStar ? "*" : "") + line);
//if the line is no listitem and no schauplatz, we are done with the standort list
//all remaining text will be added to remainingText
if (!match.Success || !PageIsSchauplatz(match.Groups[2].Value))
{
if (standorte.Count == 0 && lastMatch == null)
{
prependText += line + "\r\n";
}
else
{
foundNonSchauplatz = true;
remainingText = line;
}
continue;
}
var added = false;
//has a descripting text
if (match.Groups[3].Length > 0)
{
standorte.Add(match.Groups[2].Value + " = " + match.Groups[4].Value);
compactTemplate = false;
added = true;
}
if (lastMatch != null && match.Groups[1].Length <= lastMatch.Groups[1].Length)
{
//add last
standorte.Add(lastMatch.Groups[2].Value + (lastMatch.Groups[4].Length > 0 ? " = " + lastMatch.Groups[4].Value : ""));
lastMatch = null;
}
lastMatch = !added ? match : null;
}
if (lastMatch != null)
{
standorte.Add(lastMatch.Groups[2].Value + (lastMatch.Groups[4].Length > 0 ? " = " + lastMatch.Groups[4].Value : ""));
}
if (standorte.Count == 0) return;
if (!foundNonSchauplatz) remainingText += "\r\n";
if (standorte.Count > 3) compactTemplate = false;
//build the new section content
section.Content = section.Content.GetLines().First() + "\r\n" + prependText +
(compactTemplate
? "{{Standort|" + string.Join("|", standorte) + "}}"
: "{{Standort\r\n | " + string.Join("\r\n | ", standorte) + "\r\n}}")
+ "\r\n" + remainingText;
section.Save();
edit.Save = true;
edit.EditComment = "/* "+section.Title+" */ [[Benutzer: Darthmaim Bot/Projekte#Standort|Standortvorlage eingebaut]] ("+standorte.Count+")";
}
示例12: ProcessPage
protected override void ProcessPage(Page p, EditStatus edit)
{
if (p.GetNamespace() != 0) return;
p.Load();
var before = p.text;
var templates = p.GetAllTemplates().Where(t => t.Title.ToLower() == "fehlende informationen");
foreach (var template in templates)
{
var fehlendeInformation = template.Parameters["0"].Trim();
if(fehlendeInformation.ToLower() == "interwiki" || fehlendeInformation.ToLower() == "fr" || fehlendeInformation.ToLower() == "en" || fehlendeInformation.ToLower() == "es")
{
RemoveTemplate(p, template);
edit.Save = true;
edit.EditComment = "[[Vorlage:Fehlende Informationen]] entfernt (nur interwiki)";
}
else if (fehlendeInformation == "")
{
RemoveTemplate(p, template);
edit.Save = true;
edit.EditComment = "[[Vorlage:Fehlende Informationen]] entfernt (leer)";
}
else
{
var modifiedFehlendeInformationen = fehlendeInformation;
while(true)
{
var match = _regex.Match(modifiedFehlendeInformationen);
if (!match.Success) break;
modifiedFehlendeInformationen = _regex.Replace(modifiedFehlendeInformationen, "", 1);
}
if (modifiedFehlendeInformationen == fehlendeInformation) continue;
var removed = fehlendeInformation.FindRemovedPart(modifiedFehlendeInformationen);
modifiedFehlendeInformationen = modifiedFehlendeInformationen.RemoveTrailingPunctuation();
if (string.IsNullOrWhiteSpace(modifiedFehlendeInformationen))
{
RemoveTemplate(p, template);
edit.Save = true;
edit.EditComment = string.Format("[[Vorlage:Fehlende Informationen]] entfernt (Inhalt war: „{0}“)", fehlendeInformation);
}
else
{
p.text = p.text.Replace(fehlendeInformation, modifiedFehlendeInformationen);
edit.Save = true;
edit.EditComment = string.Format("Aus fehlenden Informationen entfernt: „{0}“", removed);
}
}
}
}