Instantly share code, notes, and snippets.

Embed
What would you like to do?
an AWB 'Make module' module for adding reflists to articles that don't have them
// Copyright (C) Tom Morris 2011. Released under the GNU General Public License.
public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
{
Skip = false;
Summary = "added reflist";
// the cool shit is private, so copypasta time
Regex ReferencesSectionRegex = new Regex(@"^== *[Rr]eferences *==\s*", RegexOptions.Multiline);
Regex NotesSectionRegex = new Regex(@"^== *[Nn]otes(?: and references)? *==\s*", RegexOptions.Multiline);
Regex FootnotesSectionRegex = new Regex(@"^== *(?:[Ff]ootnotes|Sources) *==\s*", RegexOptions.Multiline);
// ReferencesSectionRegex, NotesSectionRegex, FootnotesSectionRegex
// skip loop logic
if (Regex.Match(ArticleText, @"{{[Rr]eflist").Success || Regex.Match(ArticleText, @"<references").Success) {
Skip = true;
} else {
// checks to see if an existing section exists, then uses MetaDataSorter to add it.
if (ReferencesSectionRegex.Match(ArticleText).Success ||
NotesSectionRegex.Match(ArticleText).Success ||
FootnotesSectionRegex.Match(ArticleText).Success) {
ArticleText = "{{Reflist}}\r\n" + ArticleText;
Regex ReflistRegex = new Regex(@"{{Reflist}}");
ArticleText = WikiFunctions.Parse.MetaDataSorter.MoveTemplateToReferencesSection(ArticleText, ReflistRegex, false);
// if not, add it ourselves in a clumsyish way.
} else {
ArticleText = ArticleText + "\r\n\r\n== References ==\r\n{{Reflist}}\r\n";
}
}
return ArticleText;
}
@tommorris

This comment has been minimized.

Owner

tommorris commented Jul 8, 2011

Warning: this code doesn't properly implement WP:FOOTERS. It is a very clumsy hack, so if you use it, be prepared to manually edit the results. Don't just hit Save. I'm not responsible for you getting blocked if you don't use the brain evolution gave you. I'm also not responsible if your brain fails to meet the minimum required standard necessary to edit Wikipedia.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment