private string Hide(string text, bool hideExternalLinks, bool leaveMetaHeadings, bool hideImages) { Hider = new HideText(hideExternalLinks, leaveMetaHeadings, hideImages); string s = Hider.Hide(text); Assert.AreEqual(text, Hider.AddBack(s)); return s; }
/// <summary> /// Extracts all of the interwiki and interwiki featured article links from the article text /// Ignores interwikis in comments/nowiki tags /// </summary> /// <param name="articleText">Article text with interwiki and interwiki featured article links removed</param> /// <returns>string of interwiki and interwiki featured article links</returns> public string Interwikis(ref string articleText) { string interWikiComment = ""; if (InterLangRegex.IsMatch(articleText)) { interWikiComment = InterLangRegex.Match(articleText).Value; articleText = articleText.Replace(interWikiComment, ""); } // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs/Archive_12#Interwiki_links_moved_out_of_comment HideText hider = new HideText(false, true, false); articleText = hider.Hide(articleText); string interWikis = ListToString(RemoveLinkFGAs(ref articleText)); if (interWikiComment.Length > 0) { interWikis += interWikiComment + "\r\n"; } interWikis += ListToString(RemoveInterWikis(ref articleText)); articleText = hider.AddBack(articleText); return(interWikis); }
/// <summary> /// Applies a series of defined find and replacements to the supplied article text. /// </summary> /// <param name="articleText">The wiki text of the article.</param> /// <param name="editSummary"></param> /// <param name="strTitle"></param> /// <returns>The modified article text.</returns> public string MultipleFindAndReplace(string articleText, string strTitle, ref string editSummary) { if (!HasReplacements) { return(articleText); } EditSummary = ""; RemovedSummary = ""; if (chkIgnoreMore.Checked) { articleText = Remove.HideMore(articleText); } else if (chkIgnoreLinks.Checked) { articleText = Remove.Hide(articleText); } foreach (Replacement rep in ReplacementList) { if (!rep.Enabled) { continue; } articleText = PerformFindAndReplace(rep.Find, rep.Replace, articleText, strTitle, rep.RegularExpressionOptions); } if (chkIgnoreMore.Checked) { articleText = Remove.AddBackMore(articleText); } else if (chkIgnoreLinks.Checked) { articleText = Remove.AddBack(articleText); } if (chkAddToSummary.Checked) { if (!string.IsNullOrEmpty(EditSummary)) { editSummary = ", Replaced: " + EditSummary.Trim(); } if (!string.IsNullOrEmpty(RemovedSummary)) { editSummary += ", Removed: " + RemovedSummary.Trim(); } } return(articleText); }
/// <summary> /// Extracts all of the interwiki and interwiki featured article links from the article text /// Ignores interwikis in comments/nowiki tags /// </summary> /// <param name="articleText">Article text with interwiki and interwiki featured article links removed</param> /// <returns>string of interwiki and interwiki featured article links</returns> public string Interwikis(ref string articleText) { // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs/Archive_12#Interwiki_links_moved_out_of_comment HideText hider = new HideText(false, true, false); articleText = hider.Hide(articleText); string interWikis = ListToString(RemoveLinkFGAs(ref articleText)) + ListToString(RemoveInterWikis(ref articleText)); articleText = hider.AddBack(articleText); return(interWikis); }
/// <summary> /// Applies a series of defined find and replacements to the supplied article text. /// </summary> /// <param name="ArticleText">The wiki text of the article.</param> /// <param name="EditSummary"></param> /// <param name="strTitle"></param> /// <returns>The modified article text.</returns> public string MultipleFindAndReplace(string ArticleText, string strTitle, ref string EditSummary) { streditsummary = ""; if (chkIgnoreMore.Checked) { ArticleText = Remove.HideMore(ArticleText); } else if (chkIgnoreLinks.Checked) { ArticleText = Remove.Hide(ArticleText); } foreach (Replacement rep in ReplacementList) { if (!rep.Enabled) { continue; } ArticleText = PerformFindAndReplace(rep.Find, rep.Replace, ArticleText, strTitle, rep.RegularExpressionOptions); } if (chkIgnoreMore.Checked) { ArticleText = Remove.AddBackMore(ArticleText); } else if (chkIgnoreLinks.Checked) { ArticleText = Remove.AddBack(ArticleText); } if (chkAddToSummary.Checked && !string.IsNullOrEmpty(streditsummary)) { EditSummary = ", Replaced: " + summary.Trim(); } return(ArticleText); }
/// <summary> /// Applies a series of defined find and replacements to the supplied article text. /// </summary> /// <param name="articleText">The wiki text of the article.</param> /// <param name="editSummary"></param> /// <param name="strTitle"></param> /// <param name="beforeOrAfter">False if "before", true if "after"</param> /// <param name="majorChangesMade"></param> /// <returns>The modified article text.</returns> public string MultipleFindAndReplace(string articleText, string strTitle, bool beforeOrAfter, ref string editSummary, out bool majorChangesMade) { majorChangesMade = false; if (!HasReplacements) { return(articleText); } _replacedSummary = ""; _removedSummary = ""; if (chkIgnoreMore.Checked) { articleText = _remove.HideMore(articleText); } else if (chkIgnoreLinks.Checked) { articleText = _remove.Hide(articleText); } foreach (Replacement rep in _replacementList) { if (!rep.Enabled || rep.BeforeOrAfter != beforeOrAfter) { continue; } bool changeMade; articleText = PerformFindAndReplace(rep, articleText, strTitle, out changeMade); if (changeMade && !rep.Minor) { majorChangesMade = true; } } if (chkIgnoreMore.Checked) { articleText = _remove.AddBackMore(articleText); } else if (chkIgnoreLinks.Checked) { articleText = _remove.AddBack(articleText); } if (chkAddToSummary.Checked) { if (!string.IsNullOrEmpty(_replacedSummary)) { editSummary = "replaced: " + _replacedSummary.Trim(); } if (!string.IsNullOrEmpty(_removedSummary)) { if (!string.IsNullOrEmpty(editSummary)) { editSummary += ", "; } editSummary += "removed: " + _removedSummary.Trim(); } } return(articleText); }
private string Hide(string text, bool HideExternalLinks, bool LeaveMetaHeadings, bool HideImages) { Hider = new HideText(HideExternalLinks, LeaveMetaHeadings, HideImages); return Hider.Hide(text); }
/// <summary> /// Extracts all of the interwiki and interwiki featured article links from the article text /// Ignores interwikis in comments/nowiki tags /// </summary> /// <param name="articleText">Article text with interwiki and interwiki featured article links removed</param> /// <returns>string of interwiki and interwiki featured article links</returns> public string Interwikis(ref string articleText) { // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs/Archive_12#Interwiki_links_moved_out_of_comment HideText hider = new HideText(false, true, false); articleText = hider.Hide(articleText); string interWikis = ListToString(RemoveLinkFGAs(ref articleText)) + ListToString(RemoveInterWikis(ref articleText)); articleText = hider.AddBack(articleText); return interWikis; }
/// <summary> /// Applies a series of defined find and replacements to the supplied article text. /// </summary> /// <param name="articleText">The wiki text of the article.</param> /// <param name="editSummary"></param> /// <param name="strTitle"></param> /// <param name="beforeOrAfter">False if "before", true if "after"</param> /// <param name="majorChangesMade"></param> /// <returns>The modified article text.</returns> public string MultipleFindAndReplace(string articleText, string strTitle, bool beforeOrAfter, ref string editSummary, out bool majorChangesMade) { majorChangesMade = false; if (!HasReplacements) { return(articleText); } ReplacedSummary = ""; RemovedSummary = ""; if (chkIgnoreMore.Checked) { articleText = _remove.HideMore(articleText); } else if (chkIgnoreLinks.Checked) { articleText = _remove.Hide(articleText); } foreach (Replacement rep in _replacementList) { if (!rep.Enabled || rep.BeforeOrAfter != beforeOrAfter) { continue; } bool changeMade; articleText = PerformFindAndReplace(rep, articleText, strTitle, out changeMade); if (changeMade && !rep.Minor) { majorChangesMade = true; } } if (chkIgnoreMore.Checked) { // https://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs#FormatException_in_HideText.AddBackMore // FIXME: Usages of IgnoreMore with number (or M) replacement done in the FindAndReplace can cause corruption // e.g. Replacing 2 with "" ⌊⌊⌊⌊M2⌋⌋⌋⌋ becomes ⌊⌊⌊⌊M⌋⌋⌋⌋ // This cannot then be added back articleText = _remove.AddBackMore(articleText); } else if (chkIgnoreLinks.Checked) { articleText = _remove.AddBack(articleText); } if (chkAddToSummary.Checked) { if (!string.IsNullOrEmpty(ReplacedSummary)) { if (Variables.LangCode.Equals("ar")) { editSummary = "استبدل: " + ReplacedSummary.Trim(); } else if (Variables.LangCode.Equals("arz")) { editSummary = "غير: " + ReplacedSummary.Trim(); } else if (Variables.LangCode.Equals("el")) { editSummary = "αντικατέστησε: " + ReplacedSummary.Trim(); } else if (Variables.LangCode.Equals("eo")) { editSummary = "anstataŭigis: " + ReplacedSummary.Trim(); } else if (Variables.LangCode.Equals("fr")) { editSummary = "remplacement: " + ReplacedSummary.Trim(); } else if (Variables.LangCode.Equals("hy")) { editSummary = "փոխարինվեց: " + ReplacedSummary.Trim(); } else if (Variables.LangCode.Equals("tr")) { editSummary = "değiştirildi: " + ReplacedSummary.Trim(); } else { editSummary += "replaced: " + ReplacedSummary.Trim(); } } if (!string.IsNullOrEmpty(RemovedSummary)) { if (!string.IsNullOrEmpty(editSummary)) { if (Variables.LangCode.Equals("ar") || Variables.LangCode.Equals("arz") || Variables.LangCode.Equals("fa")) { editSummary += "، "; } else { editSummary += ", "; } } if (Variables.LangCode.Equals("ar")) { editSummary += "أزال: " + RemovedSummary.Trim(); } else if (Variables.LangCode.Equals("arz")) { editSummary += "شال: " + RemovedSummary.Trim(); } else if (Variables.LangCode.Equals("el")) { editSummary += "αφαίρεσε: " + RemovedSummary.Trim(); } else if (Variables.LangCode.Equals("eo")) { editSummary += "forigis: " + RemovedSummary.Trim(); } else if (Variables.LangCode.Equals("fr")) { editSummary += "retrait: " + RemovedSummary.Trim(); } else if (Variables.LangCode.Equals("hy")) { editSummary += "ջնջվեց: " + RemovedSummary.Trim(); } else { editSummary += "removed: " + RemovedSummary.Trim(); } } } return(articleText); }
/// <summary> /// Extracts all of the interwiki and interwiki featured article links from the article text /// Ignores interwikis in comments/nowiki tags /// </summary> /// <param name="articleText">Article text with interwiki and interwiki featured article links removed</param> /// <returns>string of interwiki and interwiki featured article links</returns> public string Interwikis(ref string articleText) { string interWikiComment = ""; if (InterLangRegex.IsMatch(articleText)) { interWikiComment = InterLangRegex.Match(articleText).Value; articleText = articleText.Replace(interWikiComment, ""); } // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs/Archive_12#Interwiki_links_moved_out_of_comment HideText hider = new HideText(false, true, false); articleText = hider.Hide(articleText); string interWikis = ListToString(RemoveLinkFGAs(ref articleText)); if(interWikiComment.Length > 0) interWikis += interWikiComment + "\r\n"; interWikis += ListToString(RemoveInterWikis(ref articleText)); articleText = hider.AddBack(articleText); return interWikis; }