User:SMcCandlish/TidyCitations

is a user JavaScript for your common.js page. It adds two options to the "Tools" menu (on the left in most skins), " " and "  (vertically)". These only appear in the menu when in editing mode.

Neither function should be used without also making a more substantive change (at least fix a typo or something) in the same edit, per the human-editor rules at WP:COSMETICBOT.


 * " " normalizes the spacing used in horizontal CS1 (,, etc.) and CS2  templates, throughout the article (including fixing visually disruptive vertical ones to be horizontal).
 * " (vertically)" formats citations vertically with consistent spacing, and should only be used in a page-bottom citations section that is using vertical citations in list-defined references (LDR) style.
 * In an article using LDR, the article body will contain horizontal citations, and the LDR references at the bottom may be vertical (though this is not required). In such a case of mixed citation formatting, the way to use these scripts is to copy–paste the vertical LDR references into a user sandbox, run " " on the entire article (don't save it yet), run "  (vertically)" on the vertical references in the sandbox, and copy the cleaned up vertical references from the sandbox and paste them back over the undesirably horizontalized ones at the bottom of the article.

This script does do anything with the interior contents of the ref tag itself (i.e., it does not clean up   to  ). The script for doing that, to run along with TidyCitations, is User:SMcCandlish/TidyRefs.

Installation instructions
Put the line:

in either your common.js or the skin.js of your current skin, save the page, and bypass your browser cache.

The function was deprecated in the July 2017 release of MediaWiki 1.29, and mw.loader is prefered. But  is not obsolete and still works, in case you prefer the old method of manually installing with  or using ScriptInstaller.

Usage
TidyCitations will add two menu items to the  when in edit mode:

(vertically)

Clicking them will harmonize citations in a mess like this:

to one of the following:

 :

 (vertically):

wikEd compatibility
wikEd (an advanced editor you can install via "Gadgets" in the Wikipedia "Preferences" menu) is generally incompatible with scripts, add-ons, or extensions that rely on or change the standard text edit box, and TidyCitations is one of those scripts. The workaround is to temporarily turn off wikEd by pressing the button, making the changes with TidyCitations, then re-enabling wikEd.

There may be a way to fix this, but I would have to install it figure out what it's doing in detail.

Credits
This script is a modified version of User:Sam Sailor/Scripts/Tidy citations.js. That version was a modification of User:Zyxw/Tidy citations.js (permalink), which in turn was a mod of User:Meteor sandwich yum/Tidy citations.js, which in turn was a modified version of User:Waldir/formatcitations.js.

Change log
The SMcCandlish version:


 * 2 August 2018‎ – Fixed the  null-comparison error (  must be used).
 * 2 August 2018‎ – Removed "crammed" and "roomy" versions, which are shitey layout, should never be used, and just cluttered the Tools menu with junk. In detail, the old Sam Sailor script had variations for ultra-compacting the code into an unhelpful mess like, or grossly expanding it into a mess like  . This "feature" has been removed as antithetical to the purpose of a cleanup script and to editor-helpful coding practices; anyone who used one of those options in the old script should have been immediately reverted as doing more harm than good.
 * 1 January 2023 – The vertical version's formatting now uses  layout. This differs from Sam Sailor's earlier variant on this script, which did  . The old version produced:  The new version does: This is because A) code indentation is a standard practice in all code writing, and helps make the code easier to parse by humans; B) first formatting injects pointless whitespace after   which is the opposite of the intent of this cleanup script in the first place, as well as it being inconsistent with horizontal citation fomratting; C) it is easier to manually convert between horizontal and vertical citations by removing/adding line-breaks, without having to remove/add leading space characters too (though the spacing used to vertically align   is still an issue). The author of the immediately ancestral script imposed first formatting simply to make it look like infobox code, but 1) infoboxes should also be indented and not have extraneous spacing in them after , 2) many  formatted the better way (there is no codified standard for how to lay out infobox code), and 3) citations are not infoboxes and have nothing to do with them. That author actually added the unhelpful first style to earlier scripting which did not use it; I have simply undone that.
 * 1 January 2024 – Removed dead code, a one-result  that was detecting for a value of horizontal when the containing   already did that; replaced the entire switch with just the one result it contained, since it was always guaranteed to run inside that   and could not run if the corresponding   for horizontal was not already matched.
 * 1 January 2023 – Clearer  variable name (was just the vague   which could seem to mean anything).

Infrequently asked questions

 * Isn't there some rule against this?
 * No. See RfC here: there is definitely not a consensus against using citation-formatting tools, and a large discussion to affirm the acceptability of using citation tools is not needed. It would be possible to do something disruptive with one, like mass-changing a bunch of articles in a bot-like fashion and not checking the output and letting a bunch of errors get through. But who is doing that? Close continues: questions of editor behavior should be addressed as needed at noticeboards. See also other RfC here: changes to visual output for the reader generally require consensus, as do systematic changes across an entire article changing from one consistent citation style to another consistent citation style, but changes of coding that occur while updating the content of a citation and/or adding citations do not require consensus. Even reader-facing changes are permissible when making the visual output of citations consistent within an article where there has been no history of consistency. Also from the closer: An editor hopping from article to article converting everything to a template would be a 'no' without consensus. Next see third RfC here: There is a clear consensus that the usage of vertical and horizontal templates does not fall within the purview of WP:CITEVAR. ... the inclusion of wikitext formatting within a style guideline is a form of WP:CREEP as the coded structure of the citation does not visually alter the article and provides no difference to the reader ... The existence of established policies such as WP:BRD, WP:EW, WP:OWN, and WP:BUREAU eliminates the need to codify something as specific as this. ... the code structure does not require consensus to change ..., thought editwarring over such trivia is prohibited about this as it is about everything. In summary, forcing everything to be CS1 templates in articles using another citation style consistently is not okay (change of major citation style), but cleaning up the wikicode without changing to a different major citation style is fine. In short, the efforts of certain editors to get every aspect of internal formatting of citations deemed to be part of a "citation style" that was "protected" by WP:CITEVAR has been repeatedly rejected by consensus (despite strenuous efforts in that direction by various parties).