Jump to content
Wikipedia The Free Encyclopedia

User:Tom.Bot/Task5 code

From Wikipedia, the free encyclopedia

Source

[edit ]
publicstringProcessArticle(stringArticleText,stringArticleTitle,intwikiNamespace,outstringSummary,outboolSkip)
{
Skip=false;
Summary="[[Wikipedia:Bots/Requests for approval/Tom.Bot 5|Task 5]]: +{{WikiProject Olympics|class=<inherit>|importance=Low}}; [[WP:GenFixes]] on,";
//	Summary = "+{{WikiProject Olympics|class=<inherit>|importance=Low}}; [[WP:GenFixes]] on,";

// skip conditions

boolNotTalk=!Regex.IsMatch(ArticleTitle,@"^Talk:");
if(NotTalk)
{
Summary="Convert to talks!";
Skip=true;
}

boolListArticle=Regex.IsMatch(ArticleTitle,@"^Talk:List of");
if(ListArticle)
{
Summary="List article; do manually";
Skip=true;
}

stringWP_Olympics_Regex=@"\{\{\s*(?:[Oo]lympicsWikiProject|[Ww]ikiProjectOlympics|[Ww]ikiProject[ _]+Olympics|[Ww]POlympics|WPOLY|[Ww]P[ _]+Olympics)(?=\s*[\|\}]|\s*\<\!--)";
boolHasWP_Olympics=Regex.IsMatch(ArticleText,WP_Olympics_Regex,RegexOptions.IgnoreCase);
if(HasWP_Olympics)
{
Summary="Already has {{WP Olympics}}";
Skip=true;
}

stringWP_Bio_Regex=@"\{\{\s*(?:[Bb]io|[Ww]ikiProject[ _]+Biographies|[Ww]ikiProject[ _]+Biography|[Ww]ikiProject[ _]+biography|[Ww]ikiproject[ _]+Biography|[Ww]ikiproject[ _]+biography|[Ww]ikiProject[ _]+Bio|WPBIOGRAPHY|[Ww]PBiography|[Ww]Pbiography|WPBIO|[Ww]PBio|[Ww]pbio|[Ww]P[ _]+Biography|[Ww]P[ _]+biography|[Ww]P[ _]+Bio)(?=\s*[\|\}]|\s*\<\!--)";
boolHasWP_Bio=Regex.IsMatch(ArticleText,WP_Bio_Regex,RegexOptions.IgnoreCase);
if(!HasWP_Bio)
{
Summary="Doesn't have {{WP Bio}}";
Skip=true;
}

if(!Skip)
{
// standardize {{WP Bio}}
ArticleText=Regex.Replace(ArticleText,WP_Bio_Regex,"{{WikiProject Biography",RegexOptions.IgnoreCase);

stringWP_BioAll_Regex=@"\{\{WikiProject Biography\s*([^\{\}]*(\}\})?)";
stringWP_BioAll=Regex.Match(ArticleText,WP_BioAll_Regex).Groups[1].Value;

stringWP_BioClassAll_Regex=@"(\s*\|\s*)class(\s*=\s*)(List|FL|Stub|Start|C|B|GA|A|FA)\b(?=(\s*)\|)?";// 4 grps
MatchmClassAll=Regex.Match(WP_BioAll,WP_BioClassAll_Regex,RegexOptions.IgnoreCase);
stringWP_BioClass=mClassAll.Groups[3].Value;
stringPipe=mClassAll.Groups[1].Value;
Pipe=(string.IsNullOrEmpty(Pipe)||Regex.IsMatch(Pipe,@"[\r\n]"))?"|":mClassAll.Groups[1].Value;// i.e. Talk:Loredana Auletta
stringEq=mClassAll.Groups[2].Value;
Eq=(string.IsNullOrEmpty(Eq)||Regex.IsMatch(Eq,@"[\r\n]"))?"=":mClassAll.Groups[2].Value;
stringClass=(string.IsNullOrEmpty(WP_BioClass))?"Stub":WP_BioClass;// default to Stub per botreq
stringSep=mClassAll.Groups[4].Value;// add ws if needed, but not too much (Talk:Agneta Engström, Talk:Estha Essombe, Talk:Annalisa Turci, Talk:Nicklas Holm)
Sep=(Regex.IsMatch(Pipe,@"\s+\|")||Regex.IsMatch(Sep,@"[\r\n]"))?"":Sep;// avoided problems on Talk:Leslie Malerich
stringImport=(Regex.IsMatch(Class,@"^[A-Z]"))?"Low":"low";// match case; hard-code [Ll]ow per botreq
// good overall ex: Talk:Jeanne Vaussard, Talk:Alessandra Gorla, Talk:Peter Attrill

stringWP_BioEnd=Regex.Match(WP_BioAll,@"(\s*\}\})$",RegexOptions.IgnoreCase).Groups[1].Value;
stringEnd=(Regex.IsMatch(WP_BioEnd,@"[\r\n]"))?"}}":WP_BioEnd;// some WP_Bios like to end on a NL (Talk:Eddie Dix)

// place after {{WP Bio}}
stringWP_Olympics=@"{{WikiProject Olympics"+Pipe+"class"+Eq+Class+Sep+Pipe+"importance"+Eq+Import+End;
stringPutAfterBio_Regex=@"\{\{WikiProject Biography\s*([^\}]*\}\})";
boolPutAfterBio=Regex.IsMatch(ArticleText,PutAfterBio_Regex,RegexOptions.IgnoreCase);
if(PutAfterBio)
{
ArticleText=Regex.Replace(ArticleText,PutAfterBio_Regex,@"0ドル"+"\n"+WP_Olympics,RegexOptions.IgnoreCase);
if(string.IsNullOrEmpty(WP_BioClass))Summary=Summary.Replace("<inherit>",Class);// to track via edit summary: inherited or default (Stub)
Summary=Summary.Replace("Low",Import);
}
else
{
Summary="{{WP Bio}} error; do manually";
Skip=true;
}
}

returnArticleText;
}

AltStyle によって変換されたページ (->オリジナル) /