Wikipedia:Bots/Requests for approval/BHGbot 8/BHGbot-8-AWB-module

// AWB custom module to replace Bare URL inline with Cleanup bare URLs // v 1.00, 3 August 2021 // -- BHG

public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip) {   Skip = false; Summary = "WP:BHGbot 8: ";

string nuArticleText = ""; int bareURLinlineTagCount = 0; int bareURLinlineTagRemovedCount = 0;

string bareURLinlineTagMatcher = @"\s*\{\{ *([tT]emplate *: *)?([Bb]are[_ ]+URL[\- ]inline|[Ll]inkrot-inline|[Bb]are-inline|[Bb]are[_ ]+inline|[Bb]are[_ ]+url[_ ]+inline|[Bb]are-url[_ ]+inline|[Bb]are[_ ]+link[_ ]+inline|[Bb]are-link-inline|[Bb]are-url-inline|[Bb]are[_ ]+url) *(\|[^\}]*)?\}\}";

// first, check if we have any tags MatchCollection bareURLinlineTagmatches = Regex.Matches(ArticleText, bareURLinlineTagMatcher, RegexOptions.Singleline); bareURLinlineTagCount = bareURLinlineTagmatches.Count; if (bareURLinlineTagCount == 0) { // No tags, so skip this page Skip = false; return "no matches"; // ArticleText; } 	// So we have tags // Now remove them all nuArticleText = Regex.Replace(ArticleText, bareURLinlineTagMatcher, "", RegexOptions.Singleline); MatchCollection remainingbareURLinlineTagmatches = Regex.Matches(nuArticleText, bareURLinlineTagMatcher, RegexOptions.Singleline); bareURLinlineTagRemovedCount = bareURLinlineTagCount - remainingbareURLinlineTagmatches.Count; Summary = Summary + "removed " + bareURLinlineTagRemovedCount + " of " + bareURLinlineTagCount + " . "; // Now see if we have an existing tag string cleanupBareURLsTagMatcher = @"(? \{\{ *([tT]emplate *: *)?([Cc]leanup[_ ]+bare[_ ]+URLs|[Ll]inkrot|[Bb]are[_ ]+URLs|[Ll]ink[_ ]+rot|[Bb]are[_ ]+links|[Bb]arelinks|[Bb]areurls|[Bb]are[_ ]+urls|[Cc]leanup-linkrot|[Bb]are[_ ]+URL|[Bb]areURLs|[Bb]are-URLs|[Cc]leanup[_ ]+link-rot|[Cc]leanup[_ ]+link[_ ]+rot|[Bb]are[_ ]+refs|[Bb]are[_ ]+references|[Bb]areurl|[Bb]areURL|[Bb]are|[Cc]leanup-link-rot|[Cc]leanup-link[_ ]+rot|[Bb]are[_ ]+linkname|[Cc]leanup-Bare[_ ]+URLs|[Cc]leanup-barelinks|[Bb]are[_ ]+link|[Ll]R|[Ll]r|[Ll]INKROT|[Cc]leanup-bare[_ ]+URLs|[Cc]leanup[_ ]+bare-URLs|[Cc]UBURL\s*))(? (\|[^\}]*)?\}\})";

MatchCollection cleanupBareURLsTagMatches = Regex.Matches(ArticleText, cleanupBareURLsTagMatcher, RegexOptions.Singleline); if (cleanupBareURLsTagMatches.Count == 0) { // No existing tag, so add one nuArticleText = "\n" + nuArticleText; Summary = Summary + "Added "; }	else { // We have an existing tag Summary = Summary + "Already tagged with "; nuArticleText = Regex.Replace(ArticleText, cleanupBareURLsTagMatcher, "{{Cleanup bare URLs${params}"); }

return nuArticleText; }