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

public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)

{

Skip = false;

Summary = "";

string myRedirectTarget = "";

// Skip if title doesn't contain the whole word "Organi[sz]ation(s)"

Match titleCheck = Regex.Match(ArticleTitle, @"^(.*?\b[oO]rgani)([sz])(ations?\b.*)$");

if (!titleCheck.Success) {

Skip = true;

return ArticleText;

}

// First see if this page is OrganiSations (i.e. spelt with a "S")

titleCheck = Regex.Match(ArticleTitle, @"^(.*?\b[oO]rgani)s(ations?\b.*)$");

if (titleCheck.Success) {

// create the new title by relacing S with Z

myRedirectTarget = Regex.Replace(ArticleTitle, @"^(.*?\b[oO]rgani)s(ations?\b.*)$", "$1z$2");

if (myRedirectTarget == ArticleTitle) {

// Something went wrong. The redirect target is the same as the page title.

// We don't want a self-redirect, so skip this page

Skip = true;

return ArticleText;

}

Summary = makeEditSummary(myRedirectTarget);

return makeRedirectMarkup(myRedirectTarget);

}

// Now see if this page is OrganiZations (i.e. spelt with an "Z")

titleCheck = Regex.Match(ArticleTitle, @"^(.*?\b[oO]rgani)z(ations?\b.*)$");

if (titleCheck.Success) {

// create the new title by relacing Z with S

myRedirectTarget = Regex.Replace(ArticleTitle, @"^(.*?\b[oO]rgani)z(ations?\b.*)$", "$1s$2");

if (myRedirectTarget == ArticleTitle) {

// Something went wrong. The redirect target is the same as the page title.

// We don't want a self-redirect, so skip this page

Skip = true;

return ArticleText;

}

Summary = makeEditSummary(myRedirectTarget);

return makeRedirectMarkup(myRedirectTarget);

}

// If we get here, something weird has happened, so skip this page

Skip = true;

return ArticleText;

}

public string makeRedirectMarkup(string s)

{

return "{{Category redirect|" + s + "|bot=BHGbot}}";

}

public string makeEditSummary(string s)

{

return "WP:BHGbot 7: create soft category redirect to :" + s + " ... to resolve the s/z WP:ENGVAR variation in the spelling of "organisation"/"organization"";

}