User:Trappist the monk/CS1 maint: Date and year

From Wikipedia, the free encyclopedia

This is an AWB settings file and custom module that editors may use to assist in clearing Category:CS1 maint: date and year. CAVEAT: This code is not perfect, it won't do the right thing every time but for the vast majority of CS1 and CS2 citations that have both |year= and |date=, it will do the right thing.

The code deletes |year= when |date= has what appears to be a MOS compliant date where the year portion of |date= matches the value in |year=.

Settings file[edit]

<?xml version="1.0" encoding="utf-8"?>
<AutoWikiBrowserPreferences xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml:space="preserve" Version="5.5.5.0">
  <Project>wikipedia</Project>
  <LanguageCode>en</LanguageCode>
  <CustomProject />
  <Protocol>https://</Protocol>
  <LoginDomain />
  <List>
    <ListSource>CS1 maint: date and year</ListSource>
    <SelectedProvider>CategoryListProvider</SelectedProvider>
    <ArticleList />
  </List>
  <FindAndReplace>
    <Enabled>false</Enabled>
    <IgnoreSomeText>false</IgnoreSomeText>
    <IgnoreMoreText>false</IgnoreMoreText>
    <AppendSummary>true</AppendSummary>
    <Replacements />
    <AdvancedReps />
    <SubstTemplates />
    <IncludeComments>false</IncludeComments>
    <ExpandRecursively>true</ExpandRecursively>
    <IgnoreUnformatted>false</IgnoreUnformatted>
  </FindAndReplace>
  <Editprefs>
    <GeneralFixes>false</GeneralFixes>
    <Tagger>false</Tagger>
    <Unicodify>false</Unicodify>
    <Recategorisation>0</Recategorisation>
    <NewCategory />
    <NewCategory2 />
    <ReImage>0</ReImage>
    <ImageFind />
    <Replace />
    <SkipIfNoCatChange>false</SkipIfNoCatChange>
    <RemoveSortKey>false</RemoveSortKey>
    <SkipIfNoImgChange>false</SkipIfNoImgChange>
    <AppendText>false</AppendText>
    <AppendTextMetaDataSort>false</AppendTextMetaDataSort>
    <Append>true</Append>
    <Text />
    <Newlines>2</Newlines>
    <AutoDelay>10</AutoDelay>
    <BotMaxEdits>0</BotMaxEdits>
    <SupressTag>false</SupressTag>
    <RegexTypoFix>false</RegexTypoFix>
  </Editprefs>
  <General>
    <AutoSaveEdit>
      <Enabled>false</Enabled>
      <SavePeriod>30</SavePeriod>
      <SaveFile />
    </AutoSaveEdit>
    <SelectedSummary />
    <Summaries>
      <string>clean up</string>
      <string>re-categorisation per [[WP:CFD|CFD]]</string>
      <string>clean up and re-categorisation per [[WP:CFD|CFD]]</string>
      <string>removing category per [[WP:CFD|CFD]]</string>
      <string>[[Wikipedia:Template substitution|subst:'ing]]</string>
      <string>[[Wikipedia:WikiProject Stub sorting|stub sorting]]</string>
      <string>[[WP:AWB/T|Typo fixing]]</string>
      <string>bad link repair</string>
      <string>Fixing [[Wikipedia:Disambiguation pages with links|links to disambiguation pages]]</string>
      <string>Unicodifying</string>
      <string>Remove Lang-xx templates from CS1 citations; not COinS safe;</string>
    </Summaries>
    <PasteMore>
      <string />
      <string />
      <string />
      <string />
      <string />
      <string />
      <string />
      <string />
      <string />
      <string />
    </PasteMore>
    <FindText>\|\s*date</FindText>
    <FindRegex>true</FindRegex>
    <FindCaseSensitive>false</FindCaseSensitive>
    <WordWrap>true</WordWrap>
    <ToolBarEnabled>false</ToolBarEnabled>
    <BypassRedirect>true</BypassRedirect>
    <AutoSaveSettings>false</AutoSaveSettings>
    <noSectionEditSummary>false</noSectionEditSummary>
    <restrictDefaultsortAddition>true</restrictDefaultsortAddition>
    <restrictOrphanTagging>true</restrictOrphanTagging>
    <noMOSComplianceFixes>false</noMOSComplianceFixes>
    <syntaxHighlightEditBox>false</syntaxHighlightEditBox>
    <highlightAllFind>true</highlightAllFind>
    <PreParseMode>false</PreParseMode>
    <NoAutoChanges>false</NoAutoChanges>
    <OnLoadAction>0</OnLoadAction>
    <DiffInBotMode>false</DiffInBotMode>
    <Minor>true</Minor>
    <AddToWatchlist>2</AddToWatchlist>
    <TimerEnabled>false</TimerEnabled>
    <SortListAlphabetically>false</SortListAlphabetically>
    <AddIgnoredToLog>false</AddIgnoredToLog>
    <EditToolbarEnabled>true</EditToolbarEnabled>
    <filterNonMainSpace>false</filterNonMainSpace>
    <AutoFilterDuplicates>false</AutoFilterDuplicates>
    <FocusAtEndOfEditBox>false</FocusAtEndOfEditBox>
    <scrollToUnbalancedBrackets>false</scrollToUnbalancedBrackets>
    <TextBoxSize>10</TextBoxSize>
    <TextBoxFont>Courier New</TextBoxFont>
    <LowThreadPriority>false</LowThreadPriority>
    <Beep>false</Beep>
    <Flash>false</Flash>
    <Minimize>false</Minimize>
    <LockSummary>false</LockSummary>
    <SaveArticleList>true</SaveArticleList>
    <SuppressUsingAWB>false</SuppressUsingAWB>
    <AddUsingAWBToActionSummaries>false</AddUsingAWBToActionSummaries>
    <IgnoreNoBots>false</IgnoreNoBots>
    <ClearPageListOnProjectChange>false</ClearPageListOnProjectChange>
    <SortInterWikiOrder>true</SortInterWikiOrder>
    <ReplaceReferenceTags>true</ReplaceReferenceTags>
    <LoggingEnabled>true</LoggingEnabled>
    <AlertPreferences />
  </General>
  <SkipOptions>
    <SkipNonexistent>true</SkipNonexistent>
    <Skipexistent>false</Skipexistent>
    <SkipWhenNoChanges>true</SkipWhenNoChanges>
    <SkipSpamFilterBlocked>false</SkipSpamFilterBlocked>
    <SkipInuse>false</SkipInuse>
    <SkipWhenOnlyWhitespaceChanged>true</SkipWhenOnlyWhitespaceChanged>
    <SkipOnlyGeneralFixChanges>true</SkipOnlyGeneralFixChanges>
    <SkipOnlyMinorGeneralFixChanges>false</SkipOnlyMinorGeneralFixChanges>
    <SkipOnlyCosmetic>false</SkipOnlyCosmetic>
    <SkipOnlyCasingChanged>false</SkipOnlyCasingChanged>
    <SkipIfRedirect>false</SkipIfRedirect>
    <SkipIfNoAlerts>false</SkipIfNoAlerts>
    <SkipDoes>false</SkipDoes>
    <SkipDoesNot>false</SkipDoesNot>
    <SkipDoesText />
    <SkipDoesNotText />
    <Regex>false</Regex>
    <CaseSensitive>false</CaseSensitive>
    <AfterProcessing>false</AfterProcessing>
    <SkipNoFindAndReplace>false</SkipNoFindAndReplace>
    <SkipMinorFindAndReplace>false</SkipMinorFindAndReplace>
    <SkipNoRegexTypoFix>false</SkipNoRegexTypoFix>
    <SkipNoDisambiguation>false</SkipNoDisambiguation>
    <SkipNoLinksOnPage>false</SkipNoLinksOnPage>
    <GeneralSkipList />
  </SkipOptions>
  <Module>
    <Enabled>true</Enabled>
    <Language>C# 2.0</Language>
    <Code />
  </Module>
  <ExternalProgram>
    <Enabled>false</Enabled>
    <Skip>false</Skip>
    <Program />
    <Parameters />
    <PassAsFile>true</PassAsFile>
    <OutputFile />
  </ExternalProgram>
  <Disambiguation>
    <Enabled>false</Enabled>
    <Link />
    <Variants />
    <ContextChars>20</ContextChars>
  </Disambiguation>
  <Special>
    <namespaceValues>
      <int>0</int>
    </namespaceValues>
    <remDupes>true</remDupes>
    <sortAZ>true</sortAZ>
    <filterTitlesThatContain>false</filterTitlesThatContain>
    <filterTitlesThatContainText />
    <filterTitlesThatDontContain>false</filterTitlesThatDontContain>
    <filterTitlesThatDontContainText />
    <areRegex>false</areRegex>
    <opType>0</opType>
    <remove />
  </Special>
  <Tool>
    <ListComparerUseCurrentArticleList>0</ListComparerUseCurrentArticleList>
    <ListSplitterUseCurrentArticleList>0</ListSplitterUseCurrentArticleList>
    <DatabaseScannerUseCurrentArticleList>0</DatabaseScannerUseCurrentArticleList>
  </Tool>
  <Plugin />
</AutoWikiBrowserPreferences>

Custom module[edit]

// this script removes redundant |year= parameters from pages in Category:CS1 maint: date and year

public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
	{
	Skip = false;
	Summary = "Remove redundant |year= parameter from CS1 citations;";
	
	string pattern;		// local variable to hold regex pattern for reuse
	
	string IS_CS1 = @"(?:[Cc]ite[_ ](?=(?:(?:AV|av) [Mm]edia(?: notes)?)|article|blog|book|conference|document|(?:DVD|dvd) notes|encyclopa?edia|interview|journal|letter|[Mm]agazine|(?:news(?!group|paper))|paper|podcast|press release|sign|speech|techreport|thesis|video|web)|[Cc]itation|[Cc]ite(?=\s*\|))";

	string IS_DMY_DATE = @"\|\s*date\s*=\s*\d{0,2}\s*[a-zA-Z]+\s*(\d{4}\b)";
	string IS_MDY_DATE = @"\|\s*date\s*=\s*[a-zA-Z]+\s*\d{1,2},\s*(\d{4}\b)";

//---------------------------< H I D E >----------------------------------------------------------------------
// HIDE TEMPLATES: find templates that are not CS1; replace the opening {{ with __0P3N__ and the closing }} with __CL0S3__

	while (Regex.Match (ArticleText, @"\{\{\s*(?!" + IS_CS1 + @")([^\{\}]*)\}\}").Success)
		{
		ArticleText = Regex.Replace(ArticleText, @"\{\{\s*(?!" + IS_CS1 + @")([^\{\}]*)\}\}", "__0P3N__$1__CL0S3__");
		}


//---------------------------< Y E A R   B E F O R E   D M Y   D A T E >--------------------------------------
	
	
	// YEAR YYYYx ahead of dd Mmmm YYYYx DATE: where both date and year have disambiguators
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])([^\}]*\|\s*date\s*=\s*\d{1,2} [a-zA-Z]+ (\d{4})([a-zA-Z]))",
		delegate(Match match)
			{
			string year=match.Groups[2].Value;
			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[5].Value;
			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				if (0 == String.Compare(year_disambiguator, date_disambiguator, true))
					return match.Groups[1].Value + match.Groups[4].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YEAR YYYYx ahead of dd Mmmm YYYYx DATE: where only YEAR has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])([^\}]*" + IS_DMY_DATE + @")",
		delegate(Match match)
			{
			string year=match.Groups[2].Value;
			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[5].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[4].Value + match.Groups[3].Value; //remove |year=YYYY; append disambiguator onto |date=
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YEAR YYYYx ahead of dd Mmmm YYYYx DATE: where only DATE has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4}\b)([^\}]*\|\s*date\s*=\s*\d{1,2} [a-zA-Z]+ (\d{4})([a-zA-Z]))",
		delegate(Match match)
			{
			string year=match.Groups[2].Value;
//			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[4].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[3].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YEAR YYYYx ahead of dd Mmmm YYYYx DATE: NO disambiguators
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4}\b)([^\}]*" + IS_DMY_DATE + @")",
		delegate(Match match)
			{
			string year=match.Groups[2].Value;
//			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[4].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[3].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

//---------------------------< Y E A R   B E F O R E   M D Y   D A T E >--------------------------------------

	// YEAR YYYYx ahead of dd Mmmm YYYYx DATE: where both date and year have disambiguators
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])([^\}]*\|\s*date\s*=\s*[a-zA-Z]+ \d{1,2}, (\d{4})([a-zA-Z]))",
		delegate(Match match)
			{
			string year=match.Groups[2].Value;
			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[5].Value;
			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				if (0 == String.Compare(year_disambiguator, date_disambiguator, true))
					return match.Groups[1].Value + match.Groups[4].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YEAR YYYYx ahead of dd Mmmm YYYYx DATE: where only YEAR has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])([^\}]*" + IS_MDY_DATE + @")",
		delegate(Match match)
			{
			string year=match.Groups[2].Value;
			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[5].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[4].Value + match.Groups[3].Value; //remove |year=YYYY; append disambiguator onto |date=
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YEAR YYYYx ahead of dd Mmmm YYYYx DATE: where only DATE has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4}\b)([^\}]*\|\s*date\s*=\s*[a-zA-Z]+ \d{1,2}, (\d{4})([a-zA-Z]))",
		delegate(Match match)
			{
			string year=match.Groups[2].Value;
//			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[4].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[3].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YEAR YYYYx ahead of dd Mmmm YYYYx DATE: NO disambiguators
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4}\b)([^\}]*" + IS_MDY_DATE + @")",
		delegate(Match match)
			{
			string year=match.Groups[2].Value;
//			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[4].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[3].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

//---------------------------< D M Y   D A T E   B E F O R E   Y E A R >--------------------------------------
	
	
	// dd Mmmm YYYYx DATE ahead of YEAR YYYYx: where both date and year have disambiguators
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*\d{1,2} [a-zA-Z]+ (\d{4})([a-zA-Z])[^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])",
		delegate(Match match)
			{
			string date_year = match.Groups[2].Value;
			string date_disambiguator = match.Groups[3].Value;
			string year=match.Groups[4].Value;
			string year_disambiguator = match.Groups[5].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				if (0 == String.Compare(year_disambiguator, date_disambiguator, true))
					return match.Groups[1].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// dd Mmmm YYYYx DATE ahead of YEAR YYYYx: where only YEAR has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*" + IS_DMY_DATE + @")([^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])",	// ([^\}]*)
		delegate(Match match)
			{
			string year=match.Groups[4].Value;
			string year_disambiguator = match.Groups[5].Value;
			string date_year = match.Groups[2].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[5].Value + match.Groups[3].Value; //remove |year=YYYY; append disambiguator onto |date=
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// dd Mmmm YYYYx DATE ahead of YEAR YYYYx: where only DATE has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*\d{1,2} [a-zA-Z]+ (\d{4})[a-zA-Z][^\}]*)\|\s*year\s*=\s*(\d{4}\b)",
		delegate(Match match)
			{
			string year=match.Groups[3].Value;
//			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[2].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	//  dd Mmmm YYYY DATE ahead of YEAR YYYY: NO disambiguators
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*" + IS_DMY_DATE + @"[^\}]*)\|\s*year\s*=\s*(\d{4}\b)",
		delegate(Match match)
			{
			string year=match.Groups[3].Value;
//			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[2].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});


//---------------------------< M D Y   D A T E   B E F O R E   Y E A R >--------------------------------------
	
	
	// Mmmm dd, YYYYx DATE ahead of YEAR YYYYx: where both date and year have disambiguators
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*[a-zA-Z]+ \d{1,2}, (\d{4})([a-zA-Z])[^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])",
		delegate(Match match)
			{
			string date_year = match.Groups[2].Value;
			string date_disambiguator = match.Groups[3].Value;
			string year=match.Groups[4].Value;
			string year_disambiguator = match.Groups[5].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				if (0 == String.Compare(year_disambiguator, date_disambiguator, true))
					return match.Groups[1].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// Mmmm dd, YYYY DATE ahead of YEAR YYYYx: where only YEAR has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*" + IS_MDY_DATE + @")([^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])",	// ([^\}]*)
		delegate(Match match)
			{
			string year=match.Groups[4].Value;
			string year_disambiguator = match.Groups[5].Value;
			string date_year = match.Groups[2].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[5].Value + match.Groups[3].Value; //remove |year=YYYY; append disambiguator onto |date=
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// Mmmm dd, YYYYx DATE ahead of YEAR YYYY: where only DATE has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*[a-zA-Z]+ \d{1,2}, (\d{4})[a-zA-Z][^\}]*)\|\s*year\s*=\s*(\d{4}\b)",
		delegate(Match match)
			{
			string year=match.Groups[3].Value;
//			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[2].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// Mmmm dd, YYYY DATE ahead of YEAR YYYY: NO disambiguators
//	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*" + IS_MDY_DATE + @"[^\}]*)\|\s*year\s*=\s*(\d{4}\b)",
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*[a-zA-Z]+\s*\d{1,2},\s*(\d{4}\b)[^\}]*)\|\s*year\s*=\s*(\d{4}\b)",
		delegate(Match match)
			{
			string year=match.Groups[3].Value;
//			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[2].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});




//---------------------------< Y   D A T E   B E F O R E   Y E A R >------------------------------------------
	
	
	// YYYY–YYYY DATE ahead of YEAR YYYY–YYYY: no disambiguators (spaced or unspaced ndash, hyphen, comma, virgule separators)
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*(\d{4}\s*[–,/\-]\s*\d{2,4}\b)[^\}]*)\|\s*year\s*=\s*(\d{4}\s*[–,/\-]\s*\d{2,4}\b)",
		delegate(Match match)
			{
			string date_year = match.Groups[2].Value;
			string year=match.Groups[3].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YYYYx DATE ahead of YEAR YYYYx: where both date and year have disambiguators
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*(\d{4})([a-zA-Z])[^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])",
		delegate(Match match)
			{
			string date_year = match.Groups[2].Value;
			string date_disambiguator = match.Groups[3].Value;
			string year=match.Groups[4].Value;
			string year_disambiguator = match.Groups[5].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				if (0 == String.Compare(year_disambiguator, date_disambiguator, true))
					return match.Groups[1].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YYYY DATE ahead of YEAR YYYYx: where only year has disambiguator ++
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*(\d{4}(?![a-zA-Z–\-])))([^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])",
		delegate(Match match)
			{
			string date_year = match.Groups[2].Value;
//			string date_disambiguator = match.Groups[3].Value;
			string year=match.Groups[4].Value;
//			string year_disambiguator = match.Groups[4].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[5].Value + match.Groups[3].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YYYYx DATE ahead of YEAR YYYY: where only date has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*(\d{4})([a-zA-Z])[^\}]*)\|\s*year\s*=\s*(\d{4}\b)",
		delegate(Match match)
			{
			string date_year = match.Groups[2].Value;
//			string date_disambiguator = match.Groups[3].Value;
			string year=match.Groups[4].Value;
//			string year_disambiguator = match.Groups[5].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YYYYx DATE ahead of YEAR YYYYx: no disambiguators
	// also matches |date=YYYY-MM-DD and |date=YYYY–YY[YY] and |date=YYYY/YY[YY]; these are ok to fix.
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*(\d{4}\b)[^\}]*)\|\s*year\s*=\s*(\d{4}\b)",
		delegate(Match match)
			{
			string date_year = match.Groups[2].Value;
			string year=match.Groups[3].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

//---------------------------< Y E A R   B E F O R E   Y   D A T E >------------------------------------------	
	
	// YEAR YYYYx ahead of YYYYx DATE: where both date and year have disambiguators
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])([^\}]*\|\s*date\s*=\s*(\d{4})([a-zA-Z]))",
		delegate(Match match)
			{
			string date_year = match.Groups[5].Value;
			string date_disambiguator = match.Groups[6].Value;
			string year=match.Groups[2].Value;
			string year_disambiguator = match.Groups[3].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				if (0 == String.Compare(year_disambiguator, date_disambiguator, true))
					return match.Groups[1].Value + match.Groups[4].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YEAR YYYYx ahead of YYYY DATE: where only year has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])([^\}]*\|\s*date\s*=\s*(\d{4}))([\s\|\}][^\}]*)",
		delegate(Match match)
			{
			string year = match.Groups[2].Value;
			string year_disambiguator = match.Groups[3].Value;
			string date_year=match.Groups[5].Value;
//			string year_disambiguator = match.Groups[4].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[4].Value + match.Groups[3].Value + match.Groups[6].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YEAR YYYY ahead of YYYYx DATE: where only date has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4}\b)([^\}]*\|\s*date\s*=\s*(\d{4})[a-zA-Z])",
		delegate(Match match)
			{
			string date_year = match.Groups[4].Value;
//			string date_disambiguator = match.Groups[3].Value;
			string year=match.Groups[2].Value;
//			string year_disambiguator = match.Groups[5].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[3].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YEAR YYYY ahead of YYYY DATE: no disambiguators
	// also matches |date=YYYY-MM-DD and |date=YYYY–YY[YY] and |date=YYYY/YY[YY]; these are ok to fix.
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4}(?![a-zA-Z/–\-]))([^\}]*\|\s*date\s*=\s*(\d{4}\b))",
		delegate(Match match)
			{
			string date_year = match.Groups[4].Value;
			string year=match.Groups[2].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[3].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});


//---------------------------< M–M Y   D A T E   B E F O R E   Y E A R >--------------------------------------
	
	
	// Mmmm–Mmmm YYYYx DATE ahead of YEAR YYYYx: where both date and year have disambiguators
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*[a-zA-Z]+[ –\-][a-zA-Z]+ (\d{4})([a-zA-Z])[^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])",
		delegate(Match match)
			{
			string date_year = match.Groups[2].Value;
			string date_disambiguator = match.Groups[3].Value;
			string year=match.Groups[4].Value;
			string year_disambiguator = match.Groups[5].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				if (0 == String.Compare(year_disambiguator, date_disambiguator, true))
					return match.Groups[1].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// Mmmm–Mmmm YYYYx DATE ahead of YEAR YYYYx: where only YEAR has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*[a-zA-Z]+[ –\-][a-zA-Z]+ (\d{4})[^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])",	// ([^\}]*)
		delegate(Match match)
			{
			string year=match.Groups[4].Value;
			string year_disambiguator = match.Groups[5].Value;
			string date_year = match.Groups[2].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[5].Value + match.Groups[3].Value; //remove |year=YYYY; append disambiguator onto |date=
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// Mmmm–Mmmm YYYYx DATE ahead of YEAR YYYYx: where only DATE has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*[a-zA-Z]+[ –\-][a-zA-Z]+ (\d{4})[a-zA-Z][^\}]*)\|\s*year\s*=\s*(\d{4}\b)",
		delegate(Match match)
			{
			string year=match.Groups[3].Value;
//			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[2].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	//  Mmmm–Mmmm YYYY DATE ahead of YEAR YYYY: NO disambiguators
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*\|\s*date\s*=\s*[a-zA-Z]+[ –\-][a-zA-Z]+ (\d{4})[^\}]*)\|\s*year\s*=\s*(\d{4}\b)",
		delegate(Match match)
			{
			string year=match.Groups[3].Value;
//			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[2].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});



//---------------------------< Y E A R   B E F O R E   M–M Y   D A T E >--------------------------------------
	
	
	// YEAR YYYYx ahead of Mmmm–Mmmm YYYYx DATE: where both date and year have disambiguators
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])([^\}]*\|\s*date\s*=\s*[a-zA-Z]+[ –\-][a-zA-Z]+ (\d{4})([a-zA-Z]))",
		delegate(Match match)
			{
			string year=match.Groups[2].Value;
			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[5].Value;
			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				if (0 == String.Compare(year_disambiguator, date_disambiguator, true))
					return match.Groups[1].Value + match.Groups[4].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YEAR YYYYx ahead of dd Mmmm YYYYx DATE: where only YEAR has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4})([a-zA-Z])([^\}]*\|\s*date\s*=\s*[a-zA-Z]+[ –\-][a-zA-Z]+ (\d{4}))",
		delegate(Match match)
			{
			string year=match.Groups[2].Value;
			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[5].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[4].Value + match.Groups[3].Value; //remove |year=YYYY; append disambiguator onto |date=
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YEAR YYYYx ahead of dd Mmmm YYYYx DATE: where only DATE has disambiguator
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4}\b)([^\}]*\|\s*date\s*=\s*[a-zA-Z]+[ –\-][a-zA-Z]+ (\d{4})([a-zA-Z]))",
		delegate(Match match)
			{
			string year=match.Groups[2].Value;
//			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[4].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[3].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});

	// YEAR YYYYx ahead of dd Mmmm YYYYx DATE: NO disambiguators
	ArticleText = Regex.Replace (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*year\s*=\s*(\d{4}\b)([^\}]*\|\s*date\s*=\s*[a-zA-Z]+[ –\-][a-zA-Z]+ (\d{4}))",
		delegate(Match match)
			{
			string year=match.Groups[2].Value;
//			string year_disambiguator = match.Groups[3].Value;
			string date_year = match.Groups[4].Value;
//			string date_disambiguator = match.Groups[6].Value;

			if (0 == String.Compare(year, date_year, true))
				{
				return match.Groups[1].Value + match.Groups[3].Value;
				}

			return match.Groups[0].Value;	// return the original capture
			});





//---------------------------< U N H I D E >------------------------------------------------------------------

// UNHIDE: replace __0P3N__ with {{
	ArticleText = Regex.Replace(ArticleText, @"__0P3N__", "{{");

// UNHIDE: replace __CL0S3__ with }}
	ArticleText = Regex.Replace(ArticleText, @"__CL0S3__", "}}");

	return ArticleText;
	}