User:SDrewthbot/AWB modules
Appearance
removing [[Category:\d\d\d\d works]], replace with year in header
[edit]create October 2010
public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip) { Summary ="remove category tag and add as year field in header, tidy header (custom module)"; Skip = false; // captures 2 fields either side of pipe if present, otherwise just one String year = @"\[\[[Cc]ategory:\s?(\d\d\d\ds?)\sworks\|?([^\]]+)?\]\]"; String notes = @"(\n\s*\|\s*notes)"; Match m = Regex.Match(ArticleText, year); Match n = Regex.Match(ArticleText, notes); if (m.Success) { String yearnotes = m.Result(" | year = $1") + n.Result("$1"); ArticleText = Regex.Replace(ArticleText, notes, yearnotes); ArticleText = Regex.Replace(ArticleText, year, ""); } // check for an existing DEFAULTSORT, if not present then add it with sort info Match d = Regex.Match(ArticleText, "DEFAULTSORT"); if (!d.Success) { // if second parameter (sort) was captured from category test then makes that DefSort if (m.Result("$2") != "") { ArticleText = ArticleText + "\n" + m.Result("{{DEFAULTSORT:$2}}"); } } return ArticleText; }
match override author and <pages=
[edit]created Sep 2010 — billinghurst sDrewth 23:39, 13 September 2010 (UTC)
public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip) { Summary =""; Match m = Regex.Match(ArticleText, "override_author"); Match n = Regex.Match(ArticleText, "<pages"); Skip = (m.Success && n.Success); return ArticleText; }
created Mar 2011; in response to Wikisource:Bot requests#Template:Portals, Template:Indexes & headers
public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip) { Summary ="remove {{indexes}} template and add data to portal parameter in header (custom module)"; Skip = false; // captures {{indexes}} data for portal parameter, and notes parameter String indexes = @"\{\{[Ii]ndexes\|\s?([^\}]+)\}\}"; String notes = @"(\n\s*\|\s*notes)"; Match m = Regex.Match(ArticleText, indexes); Match n = Regex.Match(ArticleText, notes); // where successful, replace any "|" character between $1 $2 $3 ... and replace with "/" character if (m.Success) { string portal = m.Result("$1").Replace("|", "/"); String portalnotes = " | portal = " + portal + n.Result("$1"); ArticleText = Regex.Replace(ArticleText, notes, portalnotes); ArticleText = Regex.Replace(ArticleText, indexes, ""); } return ArticleText; }