Jump to content

User:Nardog/RefRenamer: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
ce
Line 77: Line 77:


==Limitations==
==Limitations==
*Ref names inside templates like {{tl|refn}} are detected but do not get not replaced on clicking Continue.
*Ref names inside templates like {{tl|refn}} are detected but do not get replaced on clicking Continue.


==Caveats==
==Caveats==

Revision as of 18:04, 10 February 2023

RefRenamer
DescriptionReplaces reference names like ":0" with descriptive ones like "Smith-2015"
UpdatedAugust 13, 2023
    (10 months ago)
Browser supportChrome, Firefox, etc. (ES2017+ needed)
Source

This is a script for replacing numeric values like ":0", ":1" and so on in the name attribute of <ref> tags, which are produced by VisualEditor, with something more descriptive like "Smith-2015". Installing it adds the link "RefRenamer" to the Tools section of the sidebar on pages related to existing wikipages, which opens a dialog. If it's opened while editing, the source in the edit box will be parsed (slower); otherwise the latest version of the page will be analyzed.

Installation

Add the following to your common.js:

mw.loader.load('//en.chped.com/w/index.php?title=User:Nardog/RefRenamer.js&action=raw&ctype=text/javascript');

Or you may enable the script installer in Preferences → Gadgets and click "Install" in the infobox on this page.

Usage

The script relies on two main sources for generating new names. One is COinS metadata, which are output by CS1/CS2 templates ({{cite web}}, {{citation}}, etc.). The other is "First phrase", which takes whatever the first characters before any punctuation in the reference text are. The extraction of years works in a similar way. If a date is available in COinS, the greatest integer in it is treated as the year. In case it's not, you may opt in to use any first-occurring four-digit number in the reference text. To avoid collisions, autogenerated names are compared against each other and against the existing ref names within the source. If a name is already taken, a number ("increment") is appended.

Options

Main fallback stack
Here you can choose which properties to look for and reorder the priority by dragging the items. If no properties specified here are available in a reference, the textbox in the table will be left blank (which means the name will not be replaced unless input manually).
Properties correspond to COinS as follows (see Module:Citation/CS1/COinS for the logic):
  • Last name: rft.aulast
  • First name: rft.aufirst
  • Author: rft.au
  • Periodical/website: rft.jtitle
  • Publisher: rft.pub, rft.inst
  • Article: rft.atitle, rft.title
  • Book: rft.btitle
Lowercase
Remove diacritics
Remove punctuation
Replace space with
These affect the main string found through the fallback stack. You can remove spaces by leaving the "Replace space with" textbox blank.
Year
If this is checked, the greatest integer in COinS rft.date will be appended to the string.
Fall back on any 4-digit number
If this is checked and a COinS date is not availabe, any first-occurring four-digit number in the reference text will be appended to the string.
Delimiter preceding year
String to be inserted between the main string and the year. May be empty. Ignored if no year is found.
Increment starts at
Number to be appended in case a name is already used.
Delimiter preceding increment
String to be inserted after the year or, if no year is found, the main string. May be empty. Ignored if no increment is added.
Always insert increment
If this is checked, the increment number is appended whether a collision has occurred or not.
Insert delimiters only after numerals
If this is checked, the delimiters will be inserted only if the preceding character is a numeral (e.g. "Lee2015" instead of "Lee-2015").
Remove unreused names
If the reference is used only once (i.e. no <ref name="..." />), remove the  name="..." part entirely rather than replace the name.
Apply
Regenerates the new names using the above options. Any changes made in the table will be discarded.
Reset
Restores the script's default options. Does not regenerate new names yet.

Table

#
Number after the colon in the original name. The references are sorted by this number rather than the superscript number in the output.
Reference
Output text of the reference.
New name
Here you can see and change the new name generated based on the options above. Leave it empty to keep the original name. You can use the tab key to jump to the next item. Hitting Enter here has the same effect as clicking the Continue button.
Checkbox
If a checkbox appears inside the textbox, it means the reference is used only once (i.e. no <ref name="..." />). Uncheck it to remove the  name="..." part entirely rather than replace the name.

Other

Other ref names in the source
List of ref names that are not of the ":0" type, so you can see if any conventions have been established within the source.
Continue
Opens the editing page with the modified source and diff preloaded. Saves the options to your browser's local storage so they will be loaded the next time you open the dialog. Gives you an error instead if there are duplicate names or if no names have been modified.

Limitations

  • Ref names inside templates like {{refn}} are detected but do not get replaced on clicking Continue.

Caveats

While the script has checks in place for duplicate names, there might be unforeseen cases where it removes or replaces something it shouldn't. Please use it at your own risk (as you must any script) and make sure the result is correct before/after saving.

Excessive use of this script may be considered WP:COSMETICBOT.