Warning: You take full responsibility for any action you perform using RefRenamer. You must understand Wikipedia policies and use this tool within these policies, or risk being blocked from editing. |
Description | Replaces reference names like ":0" with descriptive ones like "Smith-2015" |
---|---|
Updated | August 13, 2023 (8 months ago) |
Browser support | Chrome, Firefox, etc. ( ES2019+ needed) |
Source |
This is a script for replacing the name attributes of <ref>
tags with something descriptive like "Smith-2015". It was developed with focus on names like ":0", ":1" and so on, which are
generated by VisualEditor, so by default it only renames them, but you can rename other names found in the source as well.
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.
Add the following to your common.js:
mw.loader.load('//en.wikipedia.org/?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.
When the dialog is opened, only references with autogenerated names (":0", "auto1", etc.) are eligible for being renamed. Other named references are listed in the other tab, and you can make them eligible by clicking "+" or "Add all".
The script relies on two main sources for generating new names. One is COinS metadata, which is 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 is appended. You can then manually edit the generated ref names in the table. Clicking Continue opens the editing page with the modified source and diff preloaded.
rft.aulast
rft.aufirst
rft.au
rft.jtitle
rft.pub
, rft.inst
rft.atitle
, rft.title
rft.btitle
rft_id
rft.date
will be appended to the string.
<ref name="..." />
), remove the name="..."
part entirely rather than replace the name.<ref name="..." />
). Uncheck it to remove the name="..."
part entirely rather than replace the name.a b
and a_b
(which is technically allowed), both references are ignored because the script can't match up the names and the references.While the script has checks in place for invalid or 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.
You may generate ref names in more complex ways than the script's GUI allows, by adding a callback to the MediaWiki front-end hook refrenamer.rename
in your common.js. For example, this code renames references with an author last name, a year, and a page number to "Chen 2017 p. 1", "Chen 2017 pp. 2-3", etc., depending on the value of the page number.
mw.hook('refrenamer.rename').add(function (ref) {
if (ref.props.aulast && ref.props.year && ref.props.pages) {
var separator = /[-,]/.test(ref.props.pages) ? ' pp. ' : ' p. ';
ref.newName = ref.props.aulast + ' ' + ref.props.year + separator + ref.props.pages;
}
});
ref
is an object containing information about each reference. It comes with two properties and one method:
name
– original reference nameprops
– an object consisting of key–value pairs of properties obtained from COinS metadata and reference textgetElement()
– returns an HTML element for the reference textIf a string is added to the ref
object as property newName
after the callback runs, RefRenamer will use the string as the new name for the reference. The automatic collision resolution will still take place.
Click under "New name" for what properties are available.
You may create a translated version of this script with the following code. Note though that the script is built on the assumption that COinS metadata is usually available, which may not be the case on your wiki, and that your wiki may have other needs or conventions in ref names the script does not support.
window.refrenamerMessages = {
portlet: 'RefRenamer',
loading: 'Loading RefRenamer...',
loadingSource: 'Loading the source...',
loadingHtml: 'Loading HTML...',
parsing: 'Parsing wikitext...',
opening: 'Opening the diff...',
continue: 'Continue',
main: 'Main fallback stack:',
lastName: 'Last name',
firstName: 'First name',
author: 'Author',
periodical: 'Periodical/website',
publisher: 'Publisher',
article: 'Article',
book: 'Book',
domain: 'Domain',
firstPhrase: 'First phrase',
lowercase: 'Lowercase',
removeDia: 'Remove diacritics',
removePunct: 'Remove punctuation',
replaceSpace: 'Replace space with:',
year: 'Year',
yearFallback: 'Fall back on any 4-digit number',
yearConvert: 'Convert to ASCII',
latinIncrement: 'Append Latin letters on collision',
increment: 'Collision resolution:',
incrementExample: 'Example',
incrementExamples: '$1, $2...',
delimiter: 'Delimiter:',
delimitConditional: 'Insert delimiters only after numerals',
removeUnreused: 'Remove unreused names',
apply: 'Apply',
reset: 'Reset',
tableName: 'Name',
tableCaption: 'References to rename',
tableRef: 'Reference',
tableNewName: 'New name',
tableAddRemove: '±',
reapplyTooltip: 'Reapply current options',
propsTooltip: 'View/insert properties',
keepTooltip: 'Uncheck to remove',
tableRemove: '(Remove)',
removeTooltip: 'Remove from references to rename',
otherTableCaption: 'Other named references',
notReused: '(not reused)',
expand: 'Expand',
collapse: 'Collapse',
addTooltip: 'Add to references to rename',
addAll: 'Add all',
resetSelection: 'Reset selection',
noNamesAlert: 'The source does not contain ref names to rename.',
noChangesError: 'No names have been modified.',
numericError: 'The following names are invalid as they consist only of numerals:',
duplicatesError: 'The following names are already used or input more than once:',
templatesWarn: 'Ref names in the following templates will not be replaced:',
invalidWarn: 'The following names have been ignored because it could not be determined which references correspond to them:',
summary: 'Replaced [[$1|VE ref names]] using [[$2|RefRenamer]]',
genericSummary: 'Renamed references using [[$1|RefRenamer]]'
};
mw.loader.load('//en.wikipedia.org/?title=User:Nardog/RefRenamer.js&action=raw&ctype=text/javascript');