public static RemoveWhiteSpace ( string articleText ) : string | ||
articleText | string | The wiki text of the article. |
Résultat | string |
/// <summary> /// /// </summary> /// <param name="ArticleText"></param> /// <param name="ArticleTitle"></param> /// <returns></returns> internal string Sort(string ArticleText, string ArticleTitle) { if (Tools.CalculateNS(ArticleTitle) == 10) //Dont really want to be fooling around with templates { return(ArticleText); } string strSave = ArticleText; try { ArticleText = Regex.Replace(ArticleText, "<!-- ?\\[\\[en:.*?\\]\\] ?-->", ""); string strPersonData = Newline(removePersonData(ref ArticleText)); string strDisambig = Newline(removeDisambig(ref ArticleText)); string strCategories = Newline(removeCats(ref ArticleText, ArticleTitle)); string strInterwikis = Newline(interwikis(ref ArticleText)); ArticleText = moveDablinks(ArticleText); // two newlines here per http://en.wikipedia.org/w/index.php?title=Wikipedia_talk:AutoWikiBrowser&oldid=243224092#Blank_lines_before_stubs string strStub = Newline(removeStubs(ref ArticleText), 2); //filter out excess white space and remove "----" from end of article ArticleText = Parsers.RemoveWhiteSpace(ArticleText) + "\r\n"; ArticleText += strDisambig; switch (Variables.LangCode) { case LangCodeEnum.de: case LangCodeEnum.sl: ArticleText += strStub + strCategories + strPersonData; break; case LangCodeEnum.pl: case LangCodeEnum.ru: case LangCodeEnum.simple: ArticleText += strPersonData + strStub + strCategories; break; default: ArticleText += strPersonData + strCategories + strStub; break; } return(ArticleText + strInterwikis); } catch (Exception ex) { if (!ex.Message.Contains("DEFAULTSORT")) { ErrorHandler.Handle(ex); } return(strSave); } }
internal string Sort(string ArticleText, string ArticleTitle) { string strSave = ArticleText; try { ArticleText = Regex.Replace(ArticleText, "<!-- ?\\[\\[en:.*?\\]\\] ?-->", ""); string strPersonData = Newline(removePersonData(ref ArticleText)); string strDisambig = Newline(removeDisambig(ref ArticleText)); string strCategories = Newline(removeCats(ref ArticleText, ArticleTitle)); string strInterwikis = Newline(interwikis(ref ArticleText)); string strStub = Newline(removeStubs(ref ArticleText)); //filter out excess white space and remove "----" from end of article ArticleText = Parsers.RemoveWhiteSpace(ArticleText) + "\r\n"; ArticleText += strDisambig; switch (Variables.LangCode) { case LangCodeEnum.de: ArticleText += strStub + strCategories + strPersonData; break; case LangCodeEnum.pl: ArticleText += strPersonData + strStub + strCategories; break; case LangCodeEnum.ru: ArticleText += strPersonData + strStub + strCategories; break; case LangCodeEnum.simple: ArticleText += strPersonData + strStub + strCategories; break; default: ArticleText += strPersonData + strCategories + strStub; break; } return(ArticleText + strInterwikis); } catch (Exception ex) { if (!ex.Message.Contains("DEFAULTSORT")) { ErrorHandler.Handle(ex); } return(strSave); } }
/// <summary> /// Sorts article meta data /// </summary> /// <param name="articleText">The wiki text of the article.</param> /// <param name="articleTitle">Title of the article</param> /// <param name="fixExcessWhitespace">Whether to request optional excess whitespace to be fixed</param> /// <returns>The updated article text</returns> internal string Sort(string articleText, string articleTitle, bool fixOptionalWhitespace) { if (Namespace.Determine(articleTitle) == Namespace.Template) // Don't really want to be fooling around with templates { return(articleText); } string strSave = articleText; try { articleText = Regex.Replace(articleText, "<!-- ?\\[\\[en:.*?\\]\\] ?-->", ""); string personData = Tools.Newline(RemovePersonData(ref articleText)); string disambig = Tools.Newline(RemoveDisambig(ref articleText)); string categories = Tools.Newline(RemoveCats(ref articleText, articleTitle)); string interwikis = Tools.Newline(Interwikis(ref articleText)); // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Move_orphan_tags_on_the_top // Dablinks above orphan tags per [[WP:LAYOUT]] if (Variables.LangCode == "en") { articleText = MoveMaintenanceTags(articleText); } articleText = MoveDablinks(articleText); // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Placement_of_portal_template // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests.html#Move_nofootnotes_to_the_references_section if (Variables.LangCode == "en") { articleText = MovePortalTemplates(articleText); articleText = MoveSisterlinks(articleText); articleText = MoveTemplateToReferencesSection(articleText, WikiRegexes.Ibid); articleText = MoveExternalLinks(articleText); articleText = MoveSeeAlso(articleText); } // two newlines here per http://en.wikipedia.org/w/index.php?title=Wikipedia_talk:AutoWikiBrowser&oldid=243224092#Blank_lines_before_stubs // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs/Archive_11#Two_empty_lines_before_stub-templates // Russian wiki uses only one newline string strStub = Tools.Newline(RemoveStubs(ref articleText), Variables.LangCode == "ru" ? 1 : 2); //filter out excess white space and remove "----" from end of article articleText = Parsers.RemoveWhiteSpace(articleText, fixOptionalWhitespace) + "\r\n"; articleText += disambig; switch (Variables.LangCode) { case "de": case "sl": articleText += strStub + categories + personData; // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser#Removal_of_blank_lines // on de wiki a blank line is desired between persondata and interwikis if (Variables.LangCode == "de" && personData.Length > 0 && interwikis.Length > 0) { articleText += "\r\n"; } break; case "pl": case "ru": case "simple": articleText += personData + strStub + categories; break; default: articleText += personData + categories + strStub; break; } return((articleText + interwikis).TrimEnd()); } catch (Exception ex) { if (!ex.Message.Contains("DEFAULTSORT")) { ErrorHandler.Handle(ex); } return(strSave); } }
/// <summary> /// /// </summary> /// <param name="articleText"></param> /// <param name="articleTitle"></param> /// <returns></returns> internal string Sort(string articleText, string articleTitle) { if (Namespace.Determine(articleTitle) == 10) //Dont really want to be fooling around with templates { return(articleText); } string strSave = articleText; try { articleText = Regex.Replace(articleText, "<!-- ?\\[\\[en:.*?\\]\\] ?-->", ""); string strPersonData = Newline(RemovePersonData(ref articleText)); string strDisambig = Newline(RemoveDisambig(ref articleText)); string strCategories = Newline(RemoveCats(ref articleText, articleTitle)); string strInterwikis = Newline(Interwikis(ref articleText)); // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Move_orphan_tags_on_the_top // Dablinks above orphan tags per [[WP:LAYOUT]] if (Variables.LangCode == LangCodeEnum.en) { articleText = MoveOrphanTags(articleText); } articleText = MoveDablinks(articleText); // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Placement_of_portal_template // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests.html#Move_nofootnotes_to_the_references_section if (Variables.LangCode == LangCodeEnum.en) { articleText = MovePortalTemplates(articleText); articleText = MoveMoreNoFootnotes(articleText); articleText = MoveExternalLinks(articleText); articleText = MoveSeeAlso(articleText); } // two newlines here per http://en.wikipedia.org/w/index.php?title=Wikipedia_talk:AutoWikiBrowser&oldid=243224092#Blank_lines_before_stubs // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs#Two_empty_lines_before_stub-templates // Russian wiki uses only one newline string strStub = Newline(RemoveStubs(ref articleText), Variables.LangCode == LangCodeEnum.ru ? 1 : 2); //filter out excess white space and remove "----" from end of article articleText = Parsers.RemoveWhiteSpace(articleText) + "\r\n"; articleText += strDisambig; switch (Variables.LangCode) { case LangCodeEnum.de: case LangCodeEnum.sl: articleText += strStub + strCategories + strPersonData; // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser#Removal_of_blank_lines // on de wiki a blank line is desired between persondata and interwikis if (Variables.LangCode == LangCodeEnum.de && strPersonData.Length > 0 && strInterwikis.Length > 0) { articleText += "\r\n"; } break; case LangCodeEnum.pl: case LangCodeEnum.ru: case LangCodeEnum.simple: articleText += strPersonData + strStub + strCategories; break; default: articleText += strPersonData + strCategories + strStub; break; } return(articleText + strInterwikis); } catch (Exception ex) { if (!ex.Message.Contains("DEFAULTSORT")) { ErrorHandler.Handle(ex); } return(strSave); } }
/// <summary> /// Sorts article meta data /// </summary> /// <param name="articleText">The wiki text of the article.</param> /// <param name="articleTitle">Title of the article</param> /// <param name="fixOptionalWhitespace">Whether to request optional excess whitespace to be fixed</param> /// <returns>The updated article text</returns> internal string Sort(string articleText, string articleTitle, bool fixOptionalWhitespace) { if (Namespace.Determine(articleTitle) == Namespace.Template) // Don't sort on templates { return(articleText); } // short pages monitor check for en-wiki: keep at very end of article if present // See [[Template:Long comment/doc]] // SPM regex quick check for performance on long pages string shortPagesMonitor = ""; if (Variables.LangCode.Equals("en") && SPMQuick.IsMatch(articleText)) { Match spm = WikiRegexes.ShortPagesMonitor.Match(articleText); if (spm.Success) { articleText = WikiRegexes.ShortPagesMonitor.Replace(articleText, "").TrimEnd(); shortPagesMonitor = spm.Value.TrimEnd(); } } articleText = CommentedOutEnInterwiki.Replace(articleText, ""); string personData = Tools.Newline(RemovePersonData(ref articleText)); string disambig = Tools.Newline(RemoveDisambig(ref articleText)); string categories = Tools.Newline(RemoveCats(ref articleText, articleTitle)); string interwikis = Tools.Newline(Interwikis(ref articleText)); if (Namespace.IsMainSpace(articleTitle)) { // maintenance templates above infoboxes etc., zeroth section only if (Variables.LangCode.Equals("en")) { string zerothSection = WikiRegexes.ZerothSection.Match(articleText).Value; string restOfArticle = articleText.Substring(zerothSection.Length); articleText = MoveMaintenanceTags(zerothSection) + restOfArticle; } // Dablinks above maintance tags per [[WP:LAYOUT]] articleText = MoveDablinks(articleText); if (Variables.LangCode.Equals("en")) { articleText = MovePortalTemplates(articleText); articleText = MoveTemplateToSeeAlsoSection(articleText, WikiRegexes.WikipediaBooks); articleText = MoveSisterlinks(articleText); articleText = MoveTemplateToReferencesSection(articleText, WikiRegexes.Ibid); articleText = MoveExternalLinks(articleText); articleText = MoveSeeAlso(articleText); } } // two newlines here per https://en.wikipedia.org/w/index.php?title=Wikipedia_talk:AutoWikiBrowser&oldid=243224092#Blank_lines_before_stubs // https://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs/Archive_11#Two_empty_lines_before_stub-templates // ru, sl, ar, arz wikis use only one newline string strStub = ""; // Category: can use {{Verylargestub}}/{{popstub}} which is not a stub template, don't do stub sorting if (!Namespace.Determine(articleTitle).Equals(Namespace.Category)) { strStub = Tools.Newline(RemoveStubs(ref articleText), (Variables.LangCode.Equals("ru") || Variables.LangCode.Equals("sl") || Variables.LangCode.Equals("ar") || Variables.LangCode.Equals("arz")) ? 1 : 2); } // filter out excess white space and remove "----" from end of article articleText = Parsers.RemoveWhiteSpace(articleText, fixOptionalWhitespace) + "\r\n"; articleText += disambig; articleText = WikiRegexes.MultipleIssues.Replace(articleText, m => Regex.Replace(m.Value, "(\r\n)+", "\r\n")); switch (Variables.LangCode) { case "de": case "sl": articleText += strStub + categories + personData; // https://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser#Removal_of_blank_lines // on de wiki a blank line is desired between persondata and interwikis if (Variables.LangCode.Equals("de") && personData.Length > 0 && interwikis.Length > 0) { articleText += "\r\n"; } break; case "ar": case "arz": case "cs": case "el": case "pl": case "ru": case "simple": articleText += personData + strStub + categories; break; case "it": if (Variables.Project == ProjectEnum.wikiquote) { articleText += personData + strStub + categories; } else { articleText += personData + categories + strStub; } break; default: articleText += personData + categories + strStub; break; } articleText = (articleText + interwikis); // Only trim start on Category namespace, restore any saved short page monitor text return((Namespace.Determine(articleTitle) == Namespace.Category ? articleText.Trim() : articleText.TrimEnd()) + shortPagesMonitor); }
/// <summary> /// Sorts article meta data /// </summary> /// <param name="articleText">The wiki text of the article.</param> /// <param name="articleTitle">Title of the article</param> /// <param name="fixOptionalWhitespace">Whether to request optional excess whitespace to be fixed</param> /// <returns>The updated article text</returns> internal string Sort(string articleText, string articleTitle, bool fixOptionalWhitespace) { if (Namespace.Determine(articleTitle) == Namespace.Template) // Don't sort on templates { return(articleText); } string strSave = articleText; try { articleText = Regex.Replace(articleText, "<!-- ?\\[\\[en:.*?\\]\\] ?-->", ""); string personData = Tools.Newline(RemovePersonData(ref articleText)); string disambig = Tools.Newline(RemoveDisambig(ref articleText)); string categories = Tools.Newline(RemoveCats(ref articleText, articleTitle)); string interwikis = Tools.Newline(Interwikis(ref articleText)); // Dablinks above orphan tags per [[WP:LAYOUT]] if (Variables.LangCode.Equals("en")) { articleText = MoveMaintenanceTags(articleText); } articleText = MoveDablinks(articleText); if (Variables.LangCode.Equals("en")) { articleText = MovePortalTemplates(articleText); articleText = MoveTemplateToSeeAlsoSection(articleText, Tools.NestedTemplateRegex("Wikipedia-Books")); articleText = MoveSisterlinks(articleText); articleText = MoveTemplateToReferencesSection(articleText, WikiRegexes.Ibid); articleText = MoveExternalLinks(articleText); articleText = MoveSeeAlso(articleText); } // two newlines here per http://en.wikipedia.org/w/index.php?title=Wikipedia_talk:AutoWikiBrowser&oldid=243224092#Blank_lines_before_stubs // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs/Archive_11#Two_empty_lines_before_stub-templates // Russian wiki uses only one newline string strStub = ""; // Category: can use {{Verylargestub}}/{{popstub}} which is not a stub template, don't do stub sorting if (!Namespace.Determine(articleTitle).Equals(Namespace.Category)) { strStub = Tools.Newline(RemoveStubs(ref articleText), Variables.LangCode.Equals("ru") ? 1 : 2); } //filter out excess white space and remove "----" from end of article articleText = Parsers.RemoveWhiteSpace(articleText, fixOptionalWhitespace) + "\r\n"; articleText += disambig; switch (Variables.LangCode) { case "de": case "sl": articleText += strStub + categories + personData; // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser#Removal_of_blank_lines // on de wiki a blank line is desired between persondata and interwikis if (Variables.LangCode.Equals("de") && personData.Length > 0 && interwikis.Length > 0) { articleText += "\r\n"; } break; case "pl": case "ru": case "simple": articleText += personData + strStub + categories; break; case "it": if (Variables.Project == ProjectEnum.wikiquote) { articleText += personData + strStub + categories; } else { articleText += personData + categories + strStub; } break; default: articleText += personData + categories + strStub; break; } articleText = (articleText + interwikis); if (Namespace.Determine(articleTitle) == Namespace.Category) { return(articleText.Trim()); } else { return(articleText.TrimEnd()); } } catch (Exception ex) { if (!ex.Message.Contains("DEFAULTSORT")) { ErrorHandler.Handle(ex); } return(strSave); } }