Jump to content

英文维基 | 中文维基 | 日文维基 | 草榴社区

User:Trappist the monk/CS1 maint: display-authors

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: display-authors. CAVEAT: This code is not perfect, it may not do the right thing every time but for the vast majority of CS1 and CS2 citations with |display-authors= or |displayauthors=, it will do the right thing.

The code deletes |display-authors= and |displayauthors= when the value assigned to either parameter is greater than or equal to the last enumerated |authorn=, |lastn= or |firstn= parameter in the citation. This script assumes that enumerated author parameters are listed n, n+1, n+2, etc, which appears to be the usual condition.

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>http://</Protocol>
  <LoginDomain />
  <List>
    <ListSource>CS1 maint: display-authors</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>
    </Summaries>
    <PasteMore>
      <string />
      <string />
      <string />
      <string />
      <string />
      <string />
      <string />
      <string />
      <string />
      <string />
    </PasteMore>
    <FindText>\|\s*(?:last|author|first)</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>
    <PluginPrefs>
      <Name>CSV Loader</Name>
      <PluginSettings>
        <anyType xsi:type="PrefsKeyPair">
          <Name>TextMode</Name>
          <Setting xsi:type="xsd:string">Append</Setting>
        </anyType>
        <anyType xsi:type="PrefsKeyPair">
          <Name>InputText</Name>
          <Setting xsi:type="xsd:string" />
        </anyType>
        <anyType xsi:type="PrefsKeyPair">
          <Name>ColumnHeaders</Name>
          <Setting xsi:type="xsd:string" />
        </anyType>
        <anyType xsi:type="PrefsKeyPair">
          <Name>Skip</Name>
          <Setting xsi:type="xsd:boolean">true</Setting>
        </anyType>
        <anyType xsi:type="PrefsKeyPair">
          <Name>Separator</Name>
          <Setting xsi:type="xsd:string">,</Setting>
        </anyType>
        <anyType xsi:type="PrefsKeyPair">
          <Name>CreateLists</Name>
          <Setting xsi:type="xsd:boolean">false</Setting>
        </anyType>
        <anyType xsi:type="PrefsKeyPair">
          <Name>ListSeparator</Name>
          <Setting xsi:type="xsd:string">^</Setting>
        </anyType>
        <anyType xsi:type="PrefsKeyPair">
          <Name>FindReplace</Name>
          <Setting xsi:type="xsd:boolean">false</Setting>
        </anyType>
        <anyType xsi:type="PrefsKeyPair">
          <Name>EditSummary</Name>
          <Setting xsi:type="xsd:string" />
        </anyType>
      </PluginSettings>
    </PluginPrefs>
  </Plugin>
</AutoWikiBrowserPreferences>

Custom module

[edit]
// This script looks at a CS1 citation and removes |displayauthors=<value> if <value> is greater than or equal to the number
// of author or last parameters (|lastn= or |authorn= <= <value>

public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
	{
	Skip = false;
	Summary = "Remove unnecessary |display-author= parameters from CS1 templates;";
	
	string IS_CS1 = @"(?:[Cc]ite (?=(?:AV media(?: notes)?)|article|book|conference|document|encyclopa?edia|interview|journal|magazine|(?:news(?!group|paper))|paper|podcast|press release|sign|speech|techreport|thesis|video|web)|[Cc]itation|[Cc]ite(?=\s*\|))";

//---------------------------< 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__");
		}

//---------------------------< E M P T Y   P A R A M E T E R S >----------------------------------------------

// EMPTY DISPLAYAUTHORS: Remove empty |display-authors= and |displayauthors= parameters.
	ArticleText = Regex.Replace(ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*display\-?authors\s*=\s*([\|\}])", "$1$2");
	
// EMPTY AUTHORn: Remove empty |authorn= parameters.
	while (Regex.Match (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*author\d+\s*=\s*([\|\}])").Success)
		{
		ArticleText = Regex.Replace(ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*author\d+\s*=\s*([\|\}])", "$1$2");
		}
	
// EMPTY LASTn: Remove empty |lastn= parameters.
	while (Regex.Match (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*last\d+\s*=\s*([\|\}])").Success)
		{
		ArticleText = Regex.Replace(ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*last\d+\s*=\s*([\|\}])", "$1$2");
		}

// EMPTY FIRSTn: Remove empty |lastn= parameters.
	while (Regex.Match (ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*first\d+\s*=\s*([\|\}])").Success)
		{
		ArticleText = Regex.Replace(ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*first\d+\s*=\s*([\|\}])", "$1$2");
		}

//---------------------------< C O U N T   A U T H O R S >----------------------------------------------------

//When the number of authors is the same as the value in |displayauthors= then all authors are displayed.
//When the number of authors is less than the value in |displayauthors= then all authors are displayed.

//When the number of authors is greater than the value in |displayauthors= then all authors are not displayed.

// If we take the value from |displayauthors=<value> and then look for |author<value+1>, if we find it then keep
// |displayauthors=; else, we know that |displayauthors=<value> is greater than or equal to the number of authors:
//		|author1=Author1 |author2=Author2 |author3=Author3 |displayauthors=2
//			|displayauthors=<value> = 2; add 1 <value> = 3;
//			we can find |author3= so keep |displayauthors=2
//
//		|author1=Author1 |author2=Author2 |author3=Author3 |displayauthors=3
//			|displayauthors=<value> = 3; add 1 <value> = 4;
//			we can't find |author4= so delete |displayauthors=3
//

	ArticleText = Regex.Replace(ArticleText, @"(\{\{\s*" + IS_CS1 + @"[^\}]*)\|\s*display\-?authors\s*=\s*(\d+)(\s*[^\}]*\}\})",
		delegate(Match match)
			{
			string raw_capture = match.Groups[0].Value;						// citation template through |displayauthors=<value>; return this if <value> < #authors
			string raw_prefix = match.Groups[1].Value;						// citation template up to the start of |displayauthors=; return this if <value> >= #authors
			int disp_authors = Convert.ToInt32(match.Groups[2].Value) + 1;	// <value> + 1
			string raw_suffix = match.Groups[3].Value;						// citation template |displayauthors=; return this if <value> >= #authors

			if (Regex.Match (raw_capture, @"\|\s*(?:author|last|first)" + disp_authors.ToString()).Success)	// include first in case cite is missing a |lastn= parameter
				return raw_capture;											// found |authorn= where 'n' = <value>+1
			return raw_prefix + raw_suffix;
			});

//---------------------------< 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;
	}