User:Monkbot/Task 2: CS1 deprecated coauthor parameters

This script is intended to pluck some of the low hanging fruit from Category:Pages containing cite templates with deprecated parameters. Editors often place multiple coauthors in either |coauthor= or |coauthors= (these two parameters are aliases of each other so hereafter |coauthor=) and separate the coauthors with a semicolon with or without a following space. This script replaces |coauthor= with an appropriate number of |authorn= parameters beginning with |author2=.

The script will not do a replacement when:

  • the template contains |ref=harv. |coauthor= is not used when Module:Citation/CS1 creates the CITEREF (used by {{sfn}} and the {{harv}} family of templates) but |author2=, |author3=, and |author4= are used.
  • the template is a {{citation}} template because this template automatically sets |ref=harv.
  • the template contains |lastn= or |authorn= where n is greater than 1 and when:
    • |lastn= or |authorn= contains a value and precedes |coauthor= – if a stray |author2= is empty and precedes |coauthor= the replacement |author2= value overrides the empty |author2=; or
    • |lastn= or |authorn= with or without an assigned value follows |coauthor= – a |author2= that follows the replacement |author2= will override the replacement

When |coauthor= in CS1 citations have only one coauthor name, or a list of names separated by semicolons, replace |coauthor= and subsequent semicolons with |author2=, |author3=, etc. When |coauthor= is empty, remove it from the citation. For example replace:

|coauthor=First Coauthor; Second Coauthor; Third Coauthor

with

|author2=First Coauthor|author3=Second Coauthor|author4=Third Coauthor

The rules for one coauthor name and multiple coauthor names are different. For a single name in |coauthor=:

must have at least one name component with up to three others allowed (|coauthor=Bono, |coauthor=John Philip Sousa |coauthor=Matakoni, J. L. B.
<name>[<comma><space><name><space><name><space><name>]
where <name>:
any letter, period, apostrophe, or hyphen
name may be prefixed with and or &:
|coauthor=and John Philip Sousa |coauthor=& Matakoni, J. L. B. (these prefixes are removed)

For multiple (2–9) names in |coauthor= each name:

any letter, period, apostrophe, hyphen, spaces
all but the last name may be wikilinked ([[Abraham Lincoln]] but not [[Abraham Lincoln|Lincoln, Abraham]])
the last name in the list may be separated with ; and or ; & (these prefixes are removed)

The individual authors listed in |coauthor= must be separated by a semicolon.

|coauthor= may not end with a semicolon.

The script does not evaluate or validate the content of |coauthor=.