User:Tom.Bot/Task4 code
Source
public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
{
// global switches //////////////////////////////////////////////////////////
bool SaveSkipSummaries = true;
bool Debug = false;
Skip = false;
// globally-used vars ///////////////////////////////////////////////////////
Summary = @"Fix [[:Category:Pages using deprecated image syntax]]";
string OrigSummary = Summary;
string Infobox = ""; // will contain the key of the infobox found on the page (i.e. "football club")
string Infobox_Regex = ""; // will contain regexes for {{infobox}} aliases
string Image_Regex = ""; // will contain regexes for "image" parameter aliases
string ImageSize_Regex = ""; // will contain regexes for "image_size" parameter aliases
string InfoboxText_Old = ""; // original IB text
string InfoboxText_New = ""; // new & improved IB text
string TempOpenBraces = @"$R3PL4C3_0P3N1N6_8R4C35";
string TempCloseBraces = @"$R3PL4C3_CL051N6_8R4C35";
string ImageTypes_Regex = @"(?:jpe?g|gif|bmp|png|svg|tiff?|xcf)";
string ImageWithSize_Regex = ""; // defined later due to dependent variables
string ImageWithoutSize_Regex = ""; // ""
string LastImageFileWikilink = ""; // used as Summary if no sig changes made
string DupSizesRemoved = ""; // used with int IBImageSize & bool DesiredSize_Eq_IBSize
bool ImageWithSize = false;
bool ImageWithoutSize = false;
bool SigChangesMade = false;
bool RedundantDefaultSize = false; // i.e. for when "|300px]]" specified for ship image
bool DesiredSize_Eq_IBSize = false; // i.e. for when "|###px]]" specified & image_size=### already exists
int IBImageSize = -1; // > 0 if used with bool DesiredSize_Eq_IBSize
// dictionaries /////////////////////////////////////////////////////////////
// {{infobox}} aliases
Dictionary<string, string> dIBAliases = new Dictionary<string, string>(); // [parent infobox, regex aliases copy+pasta'd from Rdcheck]
dIBAliases.Add(@"football club", @"(?:[Ff]ootball[ _]+club[ _]+infobox|[Ii]ndoor[ _]+Football[ _]+League[ _]+team|[Ii]nfobox[ _]+football[ _]+club|[Ii]nfobox[ _]+Football[ _]+Club|[Ii]nfobox[ _]+Football[ _]+club|[Ii]nfobox[ _]+football[ _]+team|[Mm]LS[ _]+Canada)");
dIBAliases.Add(@"military conflict", @"(?:[Bb]attle|[Ii]nfobox[ _]+battle|[Ii]nfobox[ _]+Military[ _]+Conflict[ _]+\(3[ _]+sided\)|[Ii]nfobox[ _]+military[ _]+conflict[ _]+timeline|[Ii]nfobox[ _]+military[ _]+conflict|[Ii]nfobox[ _]+Military[ _]+Conflict|[Ii]nfobox[ _]+Militärischer[ _]+Konflikt|[Ii]nfobox[ _]+Siege|[Ii]nfobox[ _]+War|[Ii]nfobox[ _]+war|[Mm]ultiWarbox|[Ww]arboxNew|[Ww]arbox|(?:[Ww]ikipedia:)?(?:[Ww]ikiProject[ _]+Military[ _]+history/Military[ _]+conflict[ _]+infobox))");
dIBAliases.Add(@"Olympic event", @"(?:Infobox[ _]+Olympic[ _]+event)");
dIBAliases.Add(@"university", @"(?:[Ii]nfobox[ _]+art[ _]+school|[Ii]nfobox[ _]+business[ _]+school|[Ii]nfobox[ _]+College|[Ii]nfobox[ _]+college|[Ii]nfobox[ _]+dental[ _]+school|[Ii]nfobox[ _]+faculty|[Ii]nfobox[ _]+graduate[ _]+school|[Ii]nfobox[ _]+institute[ _]+department|[Ii]nfobox[ _]+medical[ _]+college|[Ii]nfobox[ _]+music[ _]+school|[Ii]nfobox[ _]+seminary[ _]+school|[Ii]nfobox[ _]+university[ _]+faculty|[Ii]nfobox[ _]+University[ _]+School|[Ii]nfobox[ _]+university[ _]+school|[Ii]nfobox[ _]+university|[Ii]nfobox[ _]+University|(?:[Ww]ikipedia:)?UNI/BOX)");
dIBAliases.Add(@"military unit", @"(?:[Ff]AA[ _]+Squadron|[Ii]nfobox[ _]+military[ _]+aviation[ _]+unit|[Ii]nfobox[ _]+military[ _]+unit|[Ii]nfobox[ _]+Military[ _]+Unit|[Rr]AF[ _]+Squadron)");
dIBAliases.Add(@"school", @"(?:[Hh]igh[ _]+school|[Ii]nfobox[ _]+boarding[ _]+school|[Ii]nfobox[ _]+cadet[ _]+college|[Ii]nfobox[ _]+Education[ _]+in[ _]+Canada|[Ii]nfobox[ _]+education[ _]+in[ _]+Canada|[Ii]nfobox[ _]+education[ _]+in[ _]+canada|[Ii]nfobox[ _]+Education[ _]+in[ _]+the[ _]+United[ _]+States|[Ii]nfobox[ _]+education[ _]+in[ _]+the[ _]+United[ _]+States|[Ii]nfobox[ _]+HighSchool|[Ii]nfobox[ _]+High[ _]+School|[Ii]nfobox[ _]+high[ _]+school|[Ii]nfobox[ _]+Hochschule|[Ii]nfobox[ _]+K\-12[ _]+School|[Ii]nfobox[ _]+Malaysia[ _]+School|[Ii]nfobox[ _]+Malaysia[ _]+school|[Ii]nfobox[ _]+middle[ _]+school|[Ii]nfobox[ _]+New[ _]+Zealand[ _]+school|[Ii]nfobox[ _]+NZ[ _]+school|[Ii]nfobox[ _]+OtherEducation|[Ii]nfobox[ _]+Private[ _]+School|[Ii]nfobox[ _]+private[ _]+school|[Ii]nfobox[ _]+Public[ _]+School|[Ii]nfobox[ _]+School2|[Ii]nfobox[ _]+School3|[Ii]nfobox[ _]+School[ _]+IN|[Ii]nfobox[ _]+School[ _]+UK|[Ii]nfobox[ _]+school|[Ii]nfobox[ _]+School|[Ii]nfobox[ _]+Schule|[Ii]nfobox[ _]+scottish[ _]+primary\,[ _]+secondary[ _]+and[ _]+nursery[ _]+school|[Ii]nfobox[ _]+scottish[ _]+primary[ _]+school|[Ii]nfobox[ _]+Secondary[ _]+School|[Ii]nfobox[ _]+Secondary[ _]+school|[Ii]nfobox[ _]+secondary[ _]+school|[Ii]nfobox[ _]+US[ _]+school|[Ii]nfobox[ _]+yeshiva|[Ss]chool[ _]+infobox|[Ss]chool)");
dIBAliases.Add(@"food", @"(?:[Bb]eefbox|[Ii]nfobox[ _]+beef|[Ii]nfobox[ _]+candy[ _]+bar|[Ii]nfobox[ _]+food|[Ii]nfobox[ _]+meat|[Ii]nfobox[ _]+Prepared[ _]+Food|[Ii]nfobox[ _]+prepared[ _]+food)");
dIBAliases.Add(@"venue", @"(?:[Bb]roadway\-theatre|[Ii]nfobox[ _]+cinema|[Ii]nfobox[ _]+Sports[ _]+Centre|[Ii]nfobox[ _]+sports[ _]+centre|[Ii]nfobox[ _]+Sport[ _]+Centre|[Ii]nfobox[ _]+sport[ _]+centre|[Ii]nfobox[ _]+Stadium|[Ii]nfobox[ _]+stadium|[Ii]nfobox[ _]+Theater|[Ii]nfobox[ _]+theater|[Ii]nfobox[ _]+Theatre|[Ii]nfobox[ _]+theatre|[Ii]nfobox[ _]+venue|[Ii]nfobox[ _]+Venue)");
dIBAliases.Add(@"organization", @"(?:[Ii]nfobox[ _]+Association|[Ii]nfobox[ _]+association|[Ii]nfobox[ _]+Charity|[Ii]nfobox[ _]+charity|[Ii]nfobox[ _]+Deutsche[ _]+Behörde|[Ii]nfobox[ _]+foundations|[Ii]nfobox[ _]+foundation|[Ii]nfobox[ _]+gang|[Ii]nfobox[ _]+group|[Ii]nfobox[ _]+intergovernmental[ _]+organization|[Ii]nfobox[ _]+international[ _]+organization|[Ii]nfobox[ _]+LARP[ _]+Group|[Ii]nfobox[ _]+LARP[ _]+group|[Ii]nfobox[ _]+learned[ _]+society|[Ii]nfobox[ _]+NGO|[Ii]nfobox[ _]+non\-profit[ _]+Organisation|[Ii]nfobox[ _]+Non\-Profit|[Ii]nfobox[ _]+Non\-profit|[Ii]nfobox[ _]+non\-profit|[Ii]nfobox[ _]+nonprofit|[Ii]nfobox[ _]+NPO|[Ii]nfobox[ _]+Organisation|[Ii]nfobox[ _]+organisation|[Ii]nfobox[ _]+organization|[Ii]nfobox[ _]+Organization|[Ii]nfobox[ _]+org|[Ii]nfobox[ _]+Professional[ _]+Association|[Ii]nfobox[ _]+professional[ _]+association|[Ii]nfobox[ _]+Societies|[Ii]nfobox[ _]+societies|[Ii]nfobox[ _]+Student[ _]+Group|[Ii]nfobox[ _]+Verband|[Ii]nfobox[ _]+Verein)");
dIBAliases.Add(@"animanga/Header", @"(?:[Ii]nfobox[ _]+animanga/Header2|[Ii]nfobox[ _]+animanga/Header|[Ii]nfobox[ _]+animanga/header)");
dIBAliases.Add(@"Paralympic event", @"(?:[Ii]nfobox[ _]+Paralympic[ _]+event)");
dIBAliases.Add(@"newspaper", @"(?:[Ii]nfobox[ _]+Irish[ _]+Newspaper|[Ii]nfobox[ _]+newsletter|[Ii]nfobox[ _]+newspaper|[Ii]nfobox[ _]+Newspaper|[Ii]nfobox[ _]+papernumbers|[Ii]nfobox[ _]+student[ _]+newspaper)");
dIBAliases.Add(@"character", @"(?:[Cc]haracterInfoBox|[Dd]une[ _]+character[ _]+box|[Ff]irefly[ _]+Character|[Ii]nfobox[ _]+Avatar:[ _]+The[ _]+Last[ _]+Airbender[ _]+character|[Ii]nfobox[ _]+Beano|[Ii]nfobox[ _]+biblical[ _]+character|[Ii]nfobox[ _]+cartoon[ _]+character|[Ii]nfobox[ _]+character|[Ii]nfobox[ _]+Character|[Ii]nfobox[ _]+Charmed[ _]+group|[Ii]nfobox[ _]+Dune[ _]+character|[Ii]nfobox[ _]+epic[ _]+character|[Ii]nfobox[ _]+fictional[ _]+character|[Ii]nfobox[ _]+James[ _]+Bond[ _]+character|[Ii]nfobox[ _]+mythical[ _]+character|[Ii]nfobox[ _]+mythological[ _]+character|[Ii]nfobox[ _]+player|[Ii]nfobox[ _]+religious[ _]+character|[Ii]nfobox[ _]+Sea[ _]+Patrol[ _]+character|[Ii]nfobox[ _]+television[ _]+character|[Jj]ames[ _]+Bond[ _]+Character)");
dIBAliases.Add(@"radio station", @"(?:[Ii]nfobox[ _]+AM[ _]+Radio|[Ii]nfobox[ _]+FM[ _]+Radio|[Ii]nfobox[ _]+NYC[ _]+AM[ _]+Radio|[Ii]nfobox[ _]+NYC[ _]+FM[ _]+Radio|[Ii]nfobox[ _]+radio[ _]+station|[Ii]nfobox[ _]+Radio[ _]+Station|[Ii]nfobox[ _]+Radio[ _]+station|[Ii]RLUK[ _]+radio[ _]+infobox|[Rr]adio[ _]+Station[ _]+Information|[Rr]adio[ _]+station)");
dIBAliases.Add(@"supercluster", @"(?:[Ii]nfobox[ _]+supercluster|[Ii]nfobox[ _]+Supercluster)");
dIBAliases.Add(@"television episode", @"(?:[Ee]pisode[ _]+infobox|[Ii]nfobox[ _]+episode|[Ii]nfobox[ _]+television[ _]+episode|[Ii]nfobox[ _]+Television[ _]+Episode|[Ii]nfobox[ _]+Television[ _]+episode|[Ii]nfobox[ _]+TV[ _]+episode|[Tt]elevision[ _]+Episode|[Tt]elevision[ _]+episode)");
dIBAliases.Add(@"television season", @"(?:[Ii]nfobox[ _]+dancingwiththestarsseason|[Ii]nfobox[ _]+Dancing[ _]+on[ _]+Ice[ _]+series|[Ii]nfobox[ _]+Dancing[ _]+with[ _]+the[ _]+Stars[ _]+season|[Ii]nfobox[ _]+dancing[ _]+with[ _]+the[ _]+stars|[Ii]nfobox[ _]+reality[ _]+dance[ _]+competition|[Ii]nfobox[ _]+Smallville[ _]+season|[Ii]nfobox[ _]+Strictly[ _]+Come[ _]+Dancing[ _]+Series|[Ii]nfobox[ _]+Television[ _]+Project[ _]+Runway|[Ii]nfobox[ _]+television[ _]+Project[ _]+Runway|[Ii]nfobox[ _]+television[ _]+season|[Ii]nfobox[ _]+Television[ _]+Season|[Ii]nfobox[ _]+Television[ _]+season|[Ii]nfobox[ _]+television[ _]+series|[Ii]nfobox[ _]+Television[ _]+Top[ _]+Chef|[Ii]nfobox[ _]+tvseason|[Ii]nfobox[ _]+TV[ _]+series)");
dIBAliases.Add(@"person", @"(?:[Ii]nfobox[ _]+actor[ _]+voice|[Ii]nfobox[ _]+Actor|[Ii]nfobox[ _]+actor|[Ii]nfobox[ _]+Actress|[Ii]nfobox[ _]+actress|[Ii]nfobox[ _]+adult[ _]+biography|[Ii]nfobox[ _]+adult[ _]+female|[Ii]nfobox[ _]+adult[ _]+male|[Ii]nfobox[ _]+Biography|[Ii]nfobox[ _]+biography|[Ii]nfobox[ _]+bio|[Ii]nfobox[ _]+Celebrity|[Ii]nfobox[ _]+director|[Ii]nfobox[ _]+entertainer|[Ii]nfobox[ _]+Fashion[ _]+Designer|[Ii]nfobox[ _]+fashion[ _]+designer|[Ii]nfobox[ _]+film[ _]+actor|[Ii]nfobox[ _]+film[ _]+director|[Ii]nfobox[ _]+human[ _]+being|[Ii]nfobox[ _]+human|[Ii]nfobox[ _]+Indian[ _]+Businessmen|[Ii]nfobox[ _]+Journalist|[Ii]nfobox[ _]+journalist|[Ii]nfobox[ _]+people|[Ii]nfobox[ _]+performer|[Ii]nfobox[ _]+person/measurements|[Ii]nfobox[ _]+person[ _]+ii|[Ii]nfobox[ _]+person|[Ii]nfobox[ _]+Person|[Ii]nfobox[ _]+photographer|[Ii]nfobox[ _]+Real[ _]+Person|[Ii]nfobox[ _]+trade[ _]+unionist|[Ii]nfobox[ _]+victim|[Pp]ersonbox)");
dIBAliases.Add(@"military award", @"(?:[Ii]nfobox[ _]+civilian[ _]+award|[Ii]nfobox[ _]+civilian[ _]+decoration|[Ii]nfobox[ _]+decoration|[Ii]nfobox[ _]+military[ _]+award|[Ii]nfobox[ _]+Military[ _]+Award|[Ii]nfobox[ _]+state[ _]+award)");
dIBAliases.Add(@"comics character", @"(?:[Cc]omiccharacterbox|[Ii]nfobox[ _]+animated[ _]+superhero|[Ii]nfobox[ _]+comics[ _]+character[ _]+alt|[Ii]nfobox[ _]+comics[ _]+character|[Ii]nfobox[ _]+superhero|[Ii]nfobox[ _]+television[ _]+superhero|SHB|[Ss]uperalienbox|[Ss]uperherobox|[Ss]upersupportingbox|[Ss]upervillianbox)");
dIBAliases.Add(@"motorcycle", @"(?:[Ii]nfobox[ _]+motorcycle|[Ii]nfobox[ _]+Motorcycle|[Mm]otorcycle)");
dIBAliases.Add(@"military person", @"(?:[Ii]nfobox[ _]+colonel|[Ii]nfobox[ _]+military[ _]+officer|[Ii]nfobox[ _]+military[ _]+person|[Ii]nfobox[ _]+Military[ _]+Person|[Ii]nfobox[ _]+Military[ _]+person|[Ii]nfobox[ _]+military[ _]+Person|[Ii]nfobox[ _]+Soldier|[Ii]nfobox[ _]+soldier|[Ii]nfobox[ _]+veteran|[Ii]nfobox[ _]+voivod|[Pp]ersonbox[ _]+military)");
dIBAliases.Add(@"company", @"(?:[Cc]ompany[ _]+infobox|[Cc]ompany|[Ii]nfobox[ _]+bank|[Ii]nfobox[ _]+Co\-operative|[Ii]nfobox[ _]+co\-operative|[Ii]nfobox[ _]+companies|[Ii]nfobox[ _]+company|[Ii]nfobox[ _]+Company|[Ii]nfobox[ _]+cooperative|[Ii]nfobox[ _]+Corporation|[Ii]nfobox[ _]+Defunct[ _]+Company|[Ii]nfobox[ _]+Defunct[ _]+company|[Ii]nfobox[ _]+defunct[ _]+company|[Ii]nfobox[ _]+financial|[Ii]nfobox[ _]+Korean[ _]+company|[Ii]nfobox[ _]+manufacturing[ _]+company|[Ii]nfobox[ _]+Verkehrsbetrieb)");
dIBAliases.Add(@"ship image", @"(?:[Ii]nfobox[ _]+ship[ _]+image|[Ii]nfobox[ _]+Ship[ _]+Image)");
dIBAliases.Add(@"uk place", @"(?:[Ii]nfobox[ _]+UK[ _]+place)");
dIBAliases.Add(@"political party", @"(?:[Ii]nfobox[ _]+Belgian[ _]+Political[ _]+Party|[Ii]nfobox[ _]+Belgian[ _]+political[ _]+party|[Ii]nfobox[ _]+British[ _]+Political[ _]+Party|[Ii]nfobox[ _]+French[ _]+Political[ _]+Party|[Ii]nfobox[ _]+Irish[ _]+political[ _]+party|[Ii]nfobox[ _]+Israeli[ _]+Political[ _]+Party|[Ii]nfobox[ _]+Israeli[ _]+political[ _]+party|[Ii]nfobox[ _]+Italian[ _]+former[ _]+political[ _]+party|[Ii]nfobox[ _]+Japanese[ _]+political[ _]+party|[Ii]nfobox[ _]+political[ _]+coalition|[Ii]nfobox[ _]+political[ _]+organization|[Ii]nfobox[ _]+political[ _]+party|[Ii]nfobox[ _]+Political[ _]+Party|[Ii]nfobox[ _]+Political[ _]+party|[Ii]nfobox[ _]+political[ _]+society)");
dIBAliases.Add(@"software", @"(?:[Ii]nfobox[ _]+Software2|[Ii]nfobox[ _]+software2|[Ii]nfobox[ _]+Software3|[Ii]nfobox[ _]+Software[ _]+2|[Ii]nfobox[ _]+software|[Ii]nfobox[ _]+Software|[Ss]oftware[ _]+infobox)");
dIBAliases.Add(@"journal", @"(?:[Ii]nfobox[ _]+Academic[ _]+Journal|[Ii]nfobox[ _]+academic[ _]+journal|[Ii]nfobox[ _]+journal[ _]+series|[Ii]nfobox[ _]+journal|[Ii]nfobox[ _]+Journal|[Ii]nfobox[ _]+serial[ _]+publication|[Jj]ournal[ _]+infobox|[Jj]ournal)");
dIBAliases.Add(@"broadcast", @"(?:[Ii]nfobox[ _]+broadcast|[Ii]nfobox[ _]+Broadcast|[Ii]nfobox[ _]+television[ _]+station)");
dIBAliases.Add(@"website", @"(?:[Dd]otcom[ _]+company|[Ii]nfobox[ _]+blog|[Ii]nfobox[ _]+dot\-com[ _]+company|[Ii]nfobox[ _]+Dotcom[ _]+company|[Ii]nfobox[ _]+dotcom[ _]+company|[Ii]nfobox[ _]+dotcom|[Ii]nfobox[ _]+dot[ _]+com[ _]+company|[Ii]nfobox[ _]+site|[Ii]nfobox[ _]+Website/With[ _]+logo|[Ii]nfobox[ _]+website/With[ _]+logo|[Ii]nfobox[ _]+Website2|[Ii]nfobox[ _]+website[ _]+with[ _]+IPv6|[Ii]nfobox[ _]+website|[Ii]nfobox[ _]+Website|[Ii]nfobox[ _]+web[ _]+company|[Ii]nfobox[ _]+web|[Ii]nfobox[ _]+Wikipedia)");
dIBAliases.Add(@"television", @"(?:[Ii]nfobox[ _]+British[ _]+television|[Ii]nfobox[ _]+cartoon|[Ii]nfobox[ _]+miniseries|[Ii]nfobox[ _]+Minisodes|[Ii]nfobox[ _]+Telenovela|[Ii]nfobox[ _]+telenovela|[Ii]nfobox[ _]+television[ _]+\(animated\)|[Ii]nfobox[ _]+Television[ _]+Film|[Ii]nfobox[ _]+Television[ _]+film|[Ii]nfobox[ _]+Television[ _]+series|[Ii]nfobox[ _]+Television[ _]+show|[Ii]nfobox[ _]+television[ _]+show|[Ii]nfobox[ _]+Television[ _]+Soap[ _]+Operas|[Ii]nfobox[ _]+Television[ _]+Soap[ _]+Opera|[Ii]nfobox[ _]+television[ _]+soap[ _]+opera|[Ii]nfobox[ _]+television[ _]+talkshow|[Ii]nfobox[ _]+television|[Ii]nfobox[ _]+Television|[Ii]nfobox[ _]+TV[ _]+film|[Ii]nfobox[ _]+TV[ _]+Movie|[Ii]nfobox[ _]+TV[ _]+show|[Ii]nfobox[ _]+TV|[Ii]nfobox[ _]+tv|[Ii]nfobox[ _]+UK[ _]+television|[Tt]elenovela)");
dIBAliases.Add(@"pan american games event", @"(?:Infobox[ _]+Pan[ _]+American[ _]+Games[ _]+event)");
dIBAliases.Add(@"galaxy", @"(?:[Ii]nfobox[ _]+galaxy|[Ii]nfobox[ _]+Galaxy)");
dIBAliases.Add(@"video game", @"(?:[Gg]ameInfobox|[Ii]nfobox[ _]+Arcade[ _]+Game|[Ii]nfobox[ _]+Arcade[ _]+game|[Ii]nfobox[ _]+arcade|[Ii]nfobox[ _]+computer[ _]+game|[Ii]nfobox[ _]+console[ _]+game|[Ii]nfobox[ _]+CVG|[Ii]nfobox[ _]+cvg|[Ii]nfobox[ _]+VG|[Ii]nfobox[ _]+vg|[Ii]nfobox[ _]+Videogame|[Ii]nfobox[ _]+videogame|[Ii]nfobox[ _]+video[ _]+games|[Ii]nfobox[ _]+video[ _]+game|[Ii]nfobox[ _]+Video[ _]+Game|[Ii]OS[ _]+App|[Vv]g[ _]+infobox)");
// [1]
// [1] image/image_size (hard-coded defaults)
// [1]
// [1] "image" default [1]
// n/a
// [1] "image"/alias regex [1]
Dictionary<string, string> dImageAliases1 = new Dictionary<string, string>(); // [parent infobox, regex]
dImageAliases1.Add(@"football club", @"(image)");
dImageAliases1.Add(@"military conflict", @"(image)");
dImageAliases1.Add(@"Olympic event", @"(image)");
dImageAliases1.Add(@"university", @"(image|image_name)");
dImageAliases1.Add(@"military unit", @"(image)");
dImageAliases1.Add(@"school", @"(image|image_name|imagewikilink)");
dImageAliases1.Add(@"food", @"(image)");
dImageAliases1.Add(@"venue", @"(image)");
dImageAliases1.Add(@"organization", @"(image)");
dImageAliases1.Add(@"animanga/Header", @"(image)");
dImageAliases1.Add(@"Paralympic event", @"(image)");
dImageAliases1.Add(@"newspaper", @"(image)");
dImageAliases1.Add(@"character", @"(image)");
dImageAliases1.Add(@"radio station", @"(image)");
dImageAliases1.Add(@"supercluster", @"(image)");
dImageAliases1.Add(@"television episode", @"(image)");
dImageAliases1.Add(@"television season", @"(image)");
dImageAliases1.Add(@"person", @"(image)");
dImageAliases1.Add(@"military award", @"(image)");
dImageAliases1.Add(@"comics character", @"(image)");
dImageAliases1.Add(@"motorcycle", @"(image)");
dImageAliases1.Add(@"military person", @"(image)");
dImageAliases1.Add(@"company", @"(image)"); // first proper run with iMaster loop
dImageAliases1.Add(@"journal", @"(image|cover)");
dImageAliases1.Add(@"broadcast", @"(image|hq_photo)");
dImageAliases1.Add(@"television", @"(image)");
dImageAliases1.Add(@"pan american games event", @"(image)");
dImageAliases1.Add(@"galaxy", @"(image)");
dImageAliases1.Add(@"video game", @"(image)");
// [1] "image_size" default [1]
// n/a
// [1] "image_size"/alias regex [1]
Dictionary<string, string> dImageSizeAliases1 = new Dictionary<string, string>(); // [parent infobox, regex]
dImageSizeAliases1.Add(@"football club", @"(?:image_size)");
dImageSizeAliases1.Add(@"military conflict", @"(?:image_size)");
dImageSizeAliases1.Add(@"Olympic event", @"(?:image_size)");
dImageSizeAliases1.Add(@"university", @"(?:image_size)");
dImageSizeAliases1.Add(@"military unit", @"(?:image_size)");
dImageSizeAliases1.Add(@"school", @"(?:image[ _]?size|size)");
dImageSizeAliases1.Add(@"food", @"(?:image_size)");
dImageSizeAliases1.Add(@"venue", @"(?:image_size)");
dImageSizeAliases1.Add(@"organization", @"(?:image_?size|size)");
dImageSizeAliases1.Add(@"animanga/Header", @"(?:image_?size)");
dImageSizeAliases1.Add(@"Paralympic event", @"(?:image_size)");
dImageSizeAliases1.Add(@"newspaper", @"(?:image_size)");
dImageSizeAliases1.Add(@"character", @"(?:image_size)");
dImageSizeAliases1.Add(@"radio station", @"(?:image_size)");
dImageSizeAliases1.Add(@"supercluster", @"(?:image_size)");
dImageSizeAliases1.Add(@"television episode", @"(?:image_size)");
dImageSizeAliases1.Add(@"television season", @"(?:image_?size)");
dImageSizeAliases1.Add(@"person", @"(?:image[ _]?size)");
dImageSizeAliases1.Add(@"military award", @"(?:image_size)");
dImageSizeAliases1.Add(@"comics character", @"(?:image_?size)");
dImageSizeAliases1.Add(@"motorcycle", @"(?:image_size)");
dImageSizeAliases1.Add(@"military person", @"(?:image_size)");
dImageSizeAliases1.Add(@"company", @"(?:image_size)");
dImageSizeAliases1.Add(@"journal", @"(?:image_size)");
dImageSizeAliases1.Add(@"broadcast", @"(?:image_size)");
dImageSizeAliases1.Add(@"television", @"(?:image_size)");
dImageSizeAliases1.Add(@"pan american games event", @"(?:image_size)"); // had to add image_size to template...
dImageSizeAliases1.Add(@"galaxy", @"(?:image_size)");
dImageSizeAliases1.Add(@"video game", @"(?:image[ _]?size)"); // no default specified
// [2]
// [2] logo/logo_size, etc. (variable defaults)
// [2]
// [2] "logo" default [2]
Dictionary<string, string> dImageDefault2 = new Dictionary<string, string>(); // [parent infobox, param]
dImageDefault2.Add(@"newspaper", @"logo");
dImageDefault2.Add(@"venue", @"logo_image");
dImageDefault2.Add(@"company", @"logo");
dImageDefault2.Add(@"ship image", @"Ship image");
dImageDefault2.Add(@"uk place", @"static_image_name");
dImageDefault2.Add(@"school", @"logo");
dImageDefault2.Add(@"political party", @"logo");
dImageDefault2.Add(@"software", @"logo");
dImageDefault2.Add(@"university", @"logo");
dImageDefault2.Add(@"broadcast", @"station_logo");
dImageDefault2.Add(@"military award", @"image2");
dImageDefault2.Add(@"organization", @"logo");
dImageDefault2.Add(@"website", @"logo");
dImageDefault2.Add(@"person", @"signature");
// [2] "logo"/alias regex [2]
Dictionary<string, string> dImageAliases2 = new Dictionary<string, string>(); // [parent infobox, regex]
dImageAliases2.Add(@"newspaper", @"(logo)");
dImageAliases2.Add(@"venue", @"(logo_image)");
dImageAliases2.Add(@"company", @"(logo|company_logo)");
dImageAliases2.Add(@"ship image", @"(Ship image|image)");
dImageAliases2.Add(@"uk place", @"(static_image|static_image_name)"); // static_image deprecated
dImageAliases2.Add(@"school", @"(logo)");
dImageAliases2.Add(@"political party", @"(logo|party[ _]logo)");
dImageAliases2.Add(@"software", @"(logo)");
dImageAliases2.Add(@"university", @"(logo)");
dImageAliases2.Add(@"broadcast", @"(station_logo)");
dImageAliases2.Add(@"military award", @"(image2)");
dImageAliases2.Add(@"organization", @"(logo|organization_logo|Non\-profit_logo)");
dImageAliases2.Add(@"website", @"(logo|company[ _]logo|[Ww]ebsite ?logo)");
dImageAliases2.Add(@"person", @"(signature)");
// [2] "logo_size" default [2]
Dictionary<string, string> dImageSizeDefault2 = new Dictionary<string, string>(); // [parent infobox, param]
dImageSizeDefault2.Add(@"newspaper", @"logo_size");
dImageSizeDefault2.Add(@"venue", @"logo_size");
dImageSizeDefault2.Add(@"company", @"logo_size");
dImageSizeDefault2.Add(@"ship image", @"Ship image size");
dImageSizeDefault2.Add(@"uk place", @"static_image_width");
dImageSizeDefault2.Add(@"school", @"logo_size");
dImageSizeDefault2.Add(@"political party", @"logo_size");
dImageSizeDefault2.Add(@"software", @"logo size");
dImageSizeDefault2.Add(@"university", @"logo_size");
dImageSizeDefault2.Add(@"broadcast", @"logo_size");
dImageSizeDefault2.Add(@"military award", @"image_size2");
dImageSizeDefault2.Add(@"organization", @"logo_size");
dImageSizeDefault2.Add(@"website", @"logo_size");
dImageSizeDefault2.Add(@"person", @"signature_size");
// [2] "logo_size"/alias regex [2]
Dictionary<string, string> dImageSizeAliases2 = new Dictionary<string, string>(); // [parent infobox, regex]
dImageSizeAliases2.Add(@"newspaper", @"(?:logo_size)");
dImageSizeAliases2.Add(@"venue", @"(?:logo_size)");
dImageSizeAliases2.Add(@"company", @"(?:logo_size)");
dImageSizeAliases2.Add(@"ship image", @"(?:Ship image size|image size)");
dImageSizeAliases2.Add(@"uk place", @"(?:static_image_width)");
dImageSizeAliases2.Add(@"school", @"(?:logo_size)");
dImageSizeAliases2.Add(@"political party", @"(?:logo_size)");
dImageSizeAliases2.Add(@"software", @"(?:logo[ _]size)");
dImageSizeAliases2.Add(@"university", @"(?:logo_size)");
dImageSizeAliases2.Add(@"broadcast", @"(?:logo_size)");
dImageSizeAliases2.Add(@"military award", @"(?:image_size2)");
dImageSizeAliases2.Add(@"organization", @"(?:logo_size)");
dImageSizeAliases2.Add(@"website", @"(?:logo[ _]size)");
dImageSizeAliases2.Add(@"person", @"(?:signature_size)");
// [3]
// [3] image3/image3_size, etc. (variable defaults)
// [3]
// [3] "image3" default [3]
Dictionary<string, string> dImageDefault3 = new Dictionary<string, string>(); // [parent infobox, param]
dImageDefault3.Add(@"uk place", @"static_image_2_name");
dImageDefault3.Add(@"school", @"seal_image");
dImageDefault3.Add(@"software", @"screenshot");
dImageDefault3.Add(@"organization", @"map");
dImageDefault3.Add(@"website", @"screenshot");
dImageDefault3.Add(@"venue", @"image_map");
dImageDefault3.Add(@"political party", @"flag"); // but NO associated flag_size
// [3] "image3"/alias regex [3]
Dictionary<string, string> dImageAliases3 = new Dictionary<string, string>(); // [parent infobox, regex]
dImageAliases3.Add(@"uk place", @"(static_image_2|static_image_2_name)"); // static_image_2 deprecated
dImageAliases3.Add(@"school", @"(seal_image)");
dImageAliases3.Add(@"software", @"(screenshot)");
dImageAliases3.Add(@"organization", @"(map)");
dImageAliases3.Add(@"website", @"(screenshot)");
dImageAliases3.Add(@"venue", @"(image_map)");
dImageAliases3.Add(@"political party", @"(flag)"); // but NO associated flag_size
// [3] "image3_size" default [3]
Dictionary<string, string> dImageSizeDefault3 = new Dictionary<string, string>(); // [parent infobox, param]
dImageSizeDefault3.Add(@"uk place", @"static_image_2_width");
dImageSizeDefault3.Add(@"school", @"seal_size");
dImageSizeDefault3.Add(@"software", @"screenshot size");
dImageSizeDefault3.Add(@"organization", @"map_size");
dImageSizeDefault3.Add(@"website", @"screenshot_size");
dImageSizeDefault3.Add(@"venue", @"map_size"); // implied...b/c "image_size" is reused from [2] if DNE
dImageSizeDefault3.Add(@"political party", @"DOES NOT EXIST"); // summarily skipped
// [3] "image3_size"/alias regex [3]
Dictionary<string, string> dImageSizeAliases3 = new Dictionary<string, string>(); // [parent infobox, regex]
dImageSizeAliases3.Add(@"uk place", @"(?:static_image_2_width)");
dImageSizeAliases3.Add(@"school", @"(?:seal_size)");
dImageSizeAliases3.Add(@"software", @"(?:screenshot[ _]size)");
dImageSizeAliases3.Add(@"organization", @"(?:map_size|msize)");
dImageSizeAliases3.Add(@"website", @"(?:screenshot[ _]size)");
dImageSizeAliases3.Add(@"venue", @"(?:map_size|image_size)");
dImageSizeAliases3.Add(@"political party", @"(?:DOES NOT EXIST)"); // summarily skipped
// [4]
// [4] image4/image4_size, etc. (variable defaults)
// [4]
// [4] "image4" default [4]
Dictionary<string, string> dImageDefault4 = new Dictionary<string, string>(); // [parent infobox, param]
dImageDefault4.Add(@"organization", @"map2");
// [4] "image4"/alias regex [4]
Dictionary<string, string> dImageAliases4 = new Dictionary<string, string>(); // [parent infobox, regex]
dImageAliases4.Add(@"organization", @"(map2)"); // static_image_2 deprecated
// [4] "image4_size" default [4]
Dictionary<string, string> dImageSizeDefault4 = new Dictionary<string, string>(); // [parent infobox, param]
dImageSizeDefault4.Add(@"organization", @"map2_size");
// [4] "image4_size"/alias regex [4]
Dictionary<string, string> dImageSizeAliases4 = new Dictionary<string, string>(); // [parent infobox, regex]
dImageSizeAliases4.Add(@"organization", @"(?:map2_size)");
// master loop //////////////////////////////////////////////////////////////
int iMaster = 0;
int iMasterMax = 4;
bool TryNextMaster = false;
string DefaultImageParam = "";
string DefaultImageSizeParam = "";
while ((iMaster + 1) <= iMasterMax)
{
iMaster++; // iMaster = dict. #
int iIBs = 0;
TryNextMaster = false;
bool Local_DesiredSize_Eq_IBSize = false;
foreach (KeyValuePair<string, string> iba in dIBAliases)
{
string IBA_Regex = @"\{\{\s*" + iba.Value + @"\s*\|";
bool IBA = Regex.IsMatch(ArticleText, IBA_Regex, RegexOptions.IgnoreCase);
if (IBA)
{
Infobox = iba.Key;
Infobox_Regex = iba.Value;
if (iMaster == 1)
{ // iMaster = dict. #
bool KeysExist = (dImageAliases1.ContainsKey(Infobox) && dImageSizeAliases1.ContainsKey(Infobox));
if (KeysExist)
{
Image_Regex = dImageAliases1[Infobox];
ImageSize_Regex = dImageSizeAliases1[Infobox];
DefaultImageParam = "image"; // hardcoded for iMaster = 1 only
DefaultImageSizeParam = "image_size"; // hardcoded for iMaster = 1 only
}
else
{
TryNextMaster = true;
break;
}
}
else if (iMaster == 2)
{ // iMaster = dict. #
bool KeysExist = (dImageAliases2.ContainsKey(Infobox) && dImageSizeAliases2.ContainsKey(Infobox));
if (KeysExist)
{
Image_Regex = dImageAliases2[Infobox];
ImageSize_Regex = dImageSizeAliases2[Infobox];
DefaultImageParam = dImageDefault2[Infobox];
DefaultImageSizeParam = dImageSizeDefault2[Infobox];
}
else
{
TryNextMaster = true;
break;
}
}
else if (iMaster == 3)
{ // iMaster = dict. #
bool KeysExist = (dImageAliases3.ContainsKey(Infobox) && dImageSizeAliases3.ContainsKey(Infobox));
if (KeysExist)
{
Image_Regex = dImageAliases3[Infobox];
ImageSize_Regex = dImageSizeAliases3[Infobox];
DefaultImageParam = dImageDefault3[Infobox];
DefaultImageSizeParam = dImageSizeDefault3[Infobox];
}
else
{
TryNextMaster = true;
break;
}
}
else if (iMaster == 4)
{ // iMaster = dict. #
bool KeysExist = (dImageAliases4.ContainsKey(Infobox) && dImageSizeAliases4.ContainsKey(Infobox));
if (KeysExist)
{
Image_Regex = dImageAliases4[Infobox];
ImageSize_Regex = dImageSizeAliases4[Infobox];
DefaultImageParam = dImageDefault4[Infobox];
DefaultImageSizeParam = dImageSizeDefault4[Infobox];
}
else
{
TryNextMaster = true;
break;
}
}
iIBs += Regex.Matches(ArticleText, IBA_Regex, RegexOptions.IgnoreCase).Count;
}
} // end foreach dIBAliases
// try again? ////////////////////////////////////////////////////////////
if (TryNextMaster) continue;
// auto-skip conditions //////////////////////////////////////////////////
if (iIBs != 1)
{
Summary = "Unexpected # of infoboxes: " + iIBs + ". ";
Skip = true;
}
if (!Skip)
{
// collapse non-IB templates
string NonInfobox_Regex = @"\{\{\s*(?!\s*" + Infobox_Regex + @"\s*\|)([^\{\}]*)\}\}";
ArticleText = Regex.Replace(ArticleText, NonInfobox_Regex, TempOpenBraces + @"$1" + TempCloseBraces, RegexOptions.IgnoreCase);
ArticleText = Regex.Replace(ArticleText, NonInfobox_Regex, TempOpenBraces + @"$1" + TempCloseBraces, RegexOptions.IgnoreCase); // again for nested templates
ArticleText = Regex.Replace(ArticleText, NonInfobox_Regex, TempOpenBraces + @"$1" + TempCloseBraces, RegexOptions.IgnoreCase); // again for nested templates, jic
InfoboxText_Old = Regex.Match(ArticleText, @"\{\{\s*" + Infobox_Regex + @"\s*\|[^\{\}]+\}\}", RegexOptions.IgnoreCase).Value;
InfoboxText_New = InfoboxText_Old;
// convert EoL pipes to SoL pipes...
string EoL2SoL_Regex = @"\s*(\|)[ ]*(?:\n|\r\n)([ ]*)([a-z][\w\s\|_-]+\=)";
Match mEoL2SoL = Regex.Match(InfoboxText_New, EoL2SoL_Regex, RegexOptions.IgnoreCase);
string SoLws2 = (mEoL2SoL.Groups[2].Value == " ") ? " " : mEoL2SoL.Groups[2].Value; // to maintain alignment with "{{Infobox"
InfoboxText_New = Regex.Replace(InfoboxText_New, EoL2SoL_Regex, "\n" + @"$1" + SoLws2 + @"$3", RegexOptions.IgnoreCase);
// rem trailing pipe before }}
InfoboxText_New = Regex.Replace(InfoboxText_New, @"\s*\|\s*\}\}$", "\n}}");
string NullOrTrivialParams = @"(?:(?:\s*\|\s*(?:center|centre|thumb)|\s*\|\s*(?:caption|alt)\s*\=?\s*(?=[\|\]]))*)";
// special case(s)
if (Infobox == "ship image")
{ // if size=300px, remove & ignore it; per suggestion by Trappist
// mod'd ImageWithSize_Regex
string ImageWithSize300_Regex = @"([\r\n]+)([ ]*\|\s*)" + Image_Regex + @"(\s*)(=\s*\[\[\s*(?:Image|File):\s*)([^\r\n\[\]\|]+?\." + ImageTypes_Regex + ")" + // grps 1-6
NullOrTrivialParams + @"\s*\|\s*(300)\s*(px)?(" + NullOrTrivialParams + @"[\|\s]*\]\][ ]*)(?=[\r\n]?\s*(?:\|\s*[a-z][\w\s_-]+=|\}\}))"; // grps 7-9
RedundantDefaultSize = Regex.IsMatch(InfoboxText_New, ImageWithSize300_Regex, RegexOptions.IgnoreCase);
InfoboxText_New = Regex.Replace(InfoboxText_New, ImageWithSize300_Regex, @"$1$2$3$4$5$6$9", RegexOptions.IgnoreCase);
}
// do we need to make way for an image_size value?
ImageWithSize_Regex = @"([\r\n]+)([ ]*\|)\s*" + Image_Regex + @"(\s*)(=)\s*\[\[\s*(?:Image|File):\s*([^\r\n\[\]\|]+?\." + ImageTypes_Regex + ")" + // grps 1-6
NullOrTrivialParams + @"\s*\|\s*(\d+)\s*(px)?" + NullOrTrivialParams + @"[\|\s]*\]\][ ]*(?=[\r\n]?\s*(?:\|\s*[a-z][\w\s_-]+=|\}\}))"; // grps 7-8
ImageWithoutSize_Regex = @"([\r\n]+)([ ]*\|\s*)" + Image_Regex + @"(\s*=)\s*\[\[\s*(?:Image|File):\s*([^\r\n\[\]\|]+?\." + ImageTypes_Regex + ")" + // grps 1-5
NullOrTrivialParams + @"[\|\s]*\]\][ ]*(?=[\r\n]?\s*(?:\|\s*[a-z][\w\s_-]+=|\}\}))"; // must find "[[]]": that's what's deprecated
Match mImageWithSize = Regex.Match(InfoboxText_New, ImageWithSize_Regex, RegexOptions.IgnoreCase);
ImageWithSize = mImageWithSize.Success;
ImageWithoutSize = Regex.IsMatch(InfoboxText_New, ImageWithoutSize_Regex, RegexOptions.IgnoreCase);
// special case(s)
if (Infobox == "political party" && iMaster == 3 && ImageWithSize)
{ // "political party" doesn't use "flag_size" or equivalent, and it is the only case so far where no associated size param exists
continue;
}
// search IB for aliases of "image_size"
Match mIBHasImageSize = Regex.Match(InfoboxText_New, @"\|\s*" + ImageSize_Regex + @"\s*=(?:\s*(\d+)\s*(?:px|\|))?", RegexOptions.IgnoreCase); // 1 grp
bool IBHasImageSize = mIBHasImageSize.Success;
if (IBHasImageSize)
{
bool IBHasImageSizeNull = Regex.IsMatch(InfoboxText_New, @"\|\s*" + ImageSize_Regex + @"\s*=\s*[\|\}]", RegexOptions.IgnoreCase);
if (IBHasImageSizeNull)
{ // *if needed*, remove it to make way for the new value
if (ImageWithSize)
{
string RemNullImageSize_Regex = @"[\r\n]+[ ]*\|\s*" + ImageSize_Regex + @"\s*=[ ]*(?=[\r\n]*\s*[\|\}])";
InfoboxText_New = Regex.Replace(InfoboxText_New, RemNullImageSize_Regex, "", RegexOptions.IgnoreCase);
// rerun the check, jtbs
IBHasImageSize = Regex.IsMatch(InfoboxText_New, @"\|\s*" + ImageSize_Regex + @"\s*=", RegexOptions.IgnoreCase);
if (IBHasImageSize)
{ // TODO: there are some weird infobox syntax exceptions out there...
Summary = "IB still contains an " + DefaultImageSizeParam + " param. ";
Skip = true;
}
}
}
else
{
if (ImageWithSize)
{
string sIBImageSize = mIBHasImageSize.Groups[1].Value;
IBImageSize = (string.IsNullOrEmpty(sIBImageSize)) ? -1 : Convert.ToInt32(sIBImageSize);
bool IBImageSizeError = (IBImageSize == -1);
int DesiredImageSize = Convert.ToInt32(mImageWithSize.Groups[7].Value);
Local_DesiredSize_Eq_IBSize = (DesiredImageSize == IBImageSize && DesiredImageSize > 0 && IBImageSize > 0);
if (Local_DesiredSize_Eq_IBSize)
{ // OK to proceed (see final instance of DesiredSize_Eq_IBSize)
DesiredSize_Eq_IBSize = Local_DesiredSize_Eq_IBSize;
if (string.IsNullOrEmpty(DupSizesRemoved)) DupSizesRemoved = IBImageSize.ToString();
else DupSizesRemoved += "px, " + IBImageSize; // "," is required, per DupPlural
}
else if (IBImageSizeError)
{
Summary = "IB " + DefaultImageSizeParam + " error for manual follow up. ";
Skip = true;
}
else
{
Summary = "IB " + DefaultImageSizeParam + @" value != 'desired' size (" + IBImageSize + @" != " + DesiredImageSize + "). ";
Skip = true;
}
}
else if (ImageWithoutSize)
{ // TODO: make sure existing size param isn't too big...
Summary = "TODO: make sure existing size param isn't too big... ";
Skip = true;
}
else
{
Summary = "Manually check IB. ";
Skip = true;
}
}
} // end if (IBHasImageSize)
if (!ImageWithSize && !ImageWithoutSize)
{ // TODO: fix alt text and/or captions too; for now, just output text to Summary for future examination
string ImageFileWikilink_Regex = @"([\r\n]+)([ ]*\|)\s*" + Image_Regex + @"(\s*)(=)\s*(\[\[\s*(?:Image|File):[^\]]+\]\][^\r\n]*)"; // 6 grps
string ImageFileWikilink = Regex.Match(InfoboxText_New, ImageFileWikilink_Regex, RegexOptions.IgnoreCase).Groups[6].Value;
if (!string.IsNullOrEmpty(ImageFileWikilink)) LastImageFileWikilink = ImageFileWikilink;
continue;
}
} // end if (!Skip)
// main //////////////////////////////////////////////////////////////////
if (!Skip)
{
// determine whitespace#3 alignment
//
// image -> image_size image_name -> image_size imagewikilink -> size
// 0 WS -> 0 WS |image= x WS -> x WS |image_name= 0 WS -> 0 WS |imagewikilink=
// |image_size= |image_size= |size=
//
// 1 WS -> 1 WS |image = . . 1 WS -> 1 WS |imagewikilink =
// |image_size = . . |size =
//
// 2 WS -> 1 WS |image = . . 2+ WS -> (2+)9+ |imagewikilink =
// |image_size = . . |size =
//
// 3 WS -> 1 WS |image = . . . .
// |image_size = . . . .
//
// 4 WS -> 1 WS |image = . . . .
// |image_size = . . . .
//
// 5 WS -> 1 WS |image = . . . .
// |image_size = . . . .
//
// 6 WS -> 1 WS |image = . . . .
// |image_size = . . . .
//
// 7+ WS -> (7+)-5 |image = . . . .
// |image_size = . . . .
// generalize the above, most common, forms of alignment for different "image" & "image_size" aliases
// determine "image"/alias characteristics
Match mImageWS = Regex.Match(InfoboxText_New, @"[\r\n]+[ ]*\|(\s*)" + Image_Regex + @"(\s*)=(\s*)\[\[\s*(?:Image|File):", RegexOptions.IgnoreCase); // 4 grps
string ImageWS2 = mImageWS.Groups[1].Value;
string ImageAlias = mImageWS.Groups[2].Value;
string ImageWS3 = mImageWS.Groups[3].Value;
string ImageWS4 = mImageWS.Groups[4].Value;
int ImageLen = ImageAlias.Length;
bool ExtraWS4 = Regex.IsMatch(ImageWS4, @"\s{3,}"); // WS > 2 (1's normal, 2's probably a typo, 3+ means there's some alignment going on)
bool WeirdWS4 = Regex.IsMatch(ImageWS4, @"[ \r\n]+"); // tab/NL
if (ExtraWS4 || WeirdWS4)
{ // TODO: fix some not-too-weird WS4 typos, i.e. [[Warrensburg Junior – Senior High School]]
Summary = "WS4 ";
Summary += (ExtraWS4) ? "extra-long/alignment" : "";
Summary += (ExtraWS4 && WeirdWS4) ? " & " : "";
Summary += (WeirdWS4) ? @"tab/\r\n" : "";
Summary += "; batch later.";
Skip = true;
}
if (!mImageWS.Success)
{
continue; // could do this earlier, but here it doubles as an unknown-error check
}
if (ImageWS4.Length == 1 || ImageWS4.Length == 2) ImageWS4 = " "; // UK place transclusions sometimes align using WS4...
// if "image_size"/alias still exists, then it's needed
string ImageSizeAlias = Regex.Match(InfoboxText_New, @"\|\s*(" + ImageSize_Regex + @")\s*=", RegexOptions.IgnoreCase).Groups[1].Value;
if (string.IsNullOrEmpty(ImageSizeAlias)) ImageSizeAlias = DefaultImageSizeParam; // default
int ImageSizeLen = ImageSizeAlias.Length;
string ImageSizeWS3 = ""; // what this is trying to find
if (ImageLen == ImageSizeLen)
{ // easy
ImageSizeWS3 = ImageWS3;
}
else if (ImageLen < ImageSizeLen)
{ // i.e. "image" & "image_size"
if (ImageWS3.Length <= 1) ImageSizeWS3 = ImageWS3; // no change
else
{
int TotLen = ImageLen + ImageWS3.Length;
if (TotLen <= (ImageSizeLen + 1)) ImageSizeWS3 = " ";
else ImageSizeWS3 = new String(' ', (TotLen - ImageSizeLen));
}
}
else if (ImageLen > ImageSizeLen)
{ // i.e. "imagewikilink" & "size"
if (ImageWS3.Length <= 1) ImageSizeWS3 = ImageWS3; // no change
else
{
int TotLen = ImageLen + ImageWS3.Length;
ImageSizeWS3 = new String(' ', (TotLen - ImageSizeLen));
}
}
else
{
Summary = "Unknown WS 3 error.";
Skip = true;
}
// check for alignment via WS2, i.e.:
// | logo =
// | logo_size =
string ImageSizeWS2 = ImageWS2; // what this is trying to find
bool WS2align = (ImageWS2.Length > 3 && ImageWS3.Length < 2 && ImageWS4.Length < 2);
if (WS2align)
{
if (ImageLen == ImageSizeLen)
{ // easy
ImageSizeWS2 = ImageWS2;
}
else if (ImageLen < ImageSizeLen)
{ // i.e. "image" & "image_size"
int TotLen = ImageLen + ImageWS2.Length;
if (TotLen <= (ImageSizeLen + 1)) ImageSizeWS2 = " ";
else ImageSizeWS2 = new String(' ', (TotLen - ImageSizeLen));
}
else if (ImageLen > ImageSizeLen)
{ // i.e. "imagewikilink" & "size"
int TotLen = ImageLen + ImageWS2.Length;
ImageSizeWS2 = new String(' ', (TotLen - ImageSizeLen));
}
else
{
Summary = "Unknown WS 2 error.";
Skip = true;
}
}
// main main //////////////////////////////////////////////////////////
// [[Image:....jpg|#px]] ->
if (Local_DesiredSize_Eq_IBSize)
{ // [[Image:....jpg|#px]] -> ....jpg
string ImageWithDupSize_Replace = @"$1$2" + ImageWS2 + @"$3$4$5" + ImageWS4 + @"$6";
InfoboxText_New = Regex.Replace(InfoboxText_New, ImageWithSize_Regex, ImageWithDupSize_Replace, RegexOptions.IgnoreCase);
}
else
{ // [[Image:....jpg|#px]] -> ....jpg | image_size = #px
string ImageWithSize_Replace = @"$1$2" + ImageWS2 + @"$3$4$5" + ImageWS4 + @"$6" + "\n" +
@"$2" + ImageSizeWS2 + DefaultImageSizeParam + ImageSizeWS3 + @"$5" + ImageWS4 + @"${7}${8}";
InfoboxText_New = Regex.Replace(InfoboxText_New, ImageWithSize_Regex, ImageWithSize_Replace, RegexOptions.IgnoreCase);
}
// [[Image:....jpg]] -> ....jpg
string ImageWithoutSize_Replace = @"$1$2$3$4" + ImageWS4 + @"$5";
InfoboxText_New = Regex.Replace(InfoboxText_New, ImageWithoutSize_Regex, ImageWithoutSize_Replace, RegexOptions.IgnoreCase);
// special cases...
// remove "px" from comics character's image_size
if (iMaster == 1)
{
if (Infobox == "comics character")
{
string RemPx_Regex = @"(\|\s*" + dImageSizeAliases1["comics character"] + @"\s*=\s*\d+)\s*px";
InfoboxText_New = Regex.Replace(InfoboxText_New, RemPx_Regex, @"$1", RegexOptions.IgnoreCase);
}
}
// validation/error checking
if (string.IsNullOrEmpty(InfoboxText_New))
{
Summary = "Check IB for weird EoL pipes...";
Skip = true;
}
else
{
if (InfoboxText_Old != InfoboxText_New)
{
ArticleText = ArticleText.Replace(InfoboxText_Old, InfoboxText_New);
if (ImageWithSize || ImageWithoutSize)
SigChangesMade = true;
}
else
{
// nothing; not all iMaster loops fire
}
}
} // end main if (!Skip)
} // end while iMaster
// housekeeping/finalize ////////////////////////////////////////////////////
ArticleText = ArticleText.Replace(TempOpenBraces, "{{");
ArticleText = ArticleText.Replace(TempCloseBraces, "}}");
if (!Skip && SigChangesMade)
{
if (RedundantDefaultSize) Summary += " (default size specified)";
string DupPlural = (Regex.IsMatch(DupSizesRemoved, ",")) ? "s" : "";
if (DesiredSize_Eq_IBSize) Summary += " (dup size" + DupPlural + " removed: " + DupSizesRemoved + "px)";
Summary += "; [[WP:GenFixes]] on,";
}
else
{
Summary = Summary.Replace(OrigSummary, "");
if (!string.IsNullOrEmpty(LastImageFileWikilink)) Summary += "No changes made: " + LastImageFileWikilink;
Skip = true;
if (SaveSkipSummaries && !Debug)
{
string Message = ArticleTitle + "\t" + Summary + "\n";
string File = @"Module output - Deprecated image syntax (skip summaries).txt";
string Path = @"F:\"; // desktop
string FullPath = Path + File;
const bool APPEND = true;
Tools.WriteTextFileAbsolutePath(Message, FullPath, APPEND);
}
}
if (Debug) Skip = false;
return ArticleText;
}
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.