Jump to content

User:SMcCandlish/TidyCitations

From Wikipedia, the free encyclopedia
User script
TidyCitations
DescriptionHarmonize spacing in citation templates
Author(s)SMcCandlish, Sam Sailor, Zyxw, Meteor sandwich yum and Waldir
StatusWorking
Updated1 January 2024; 9 months ago (2024-01-01)
BrowsersLikely all
SkinsLikely all
SourceUser:SMcCandlish/TidyCitations.js

User:SMcCandlish/TidyCitations.js is a user JavaScript for your common.js page. It adds two options to the "Tools" menu (on the left in most skins), "{{Tidy}}" and "{{Tidy}} (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.

  • "{{Tidy}}" normalizes the spacing used in horizontal CS1 ({{cite book}}, {{cite journal}}, etc.) and CS2 ({{citation}}) templates, throughout the article (including fixing visually disruptive vertical ones to be horizontal).
  • "{{Tidy}} (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 "{{Tidy}}" on the entire article (don't save it yet), run "{{Tidy}} (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 not do anything with the interior contents of the <ref> tag itself (i.e., it does not clean up <ref   name = foo-bar >...</ref> to <ref name="foo-bar">...</ref>). The script for doing that, to run along with TidyCitations, is User:SMcCandlish/TidyRefs.

Installation instructions

[edit]

Put the line:

{{subst:Load user script|User:SMcCandlish/TidyCitations.js|User:SMcCandlish/TidyCitations}}

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

The function importScript was deprecated in the July 2017 release of MediaWiki 1.29, and mw.loader is prefered.[1] But importScript is not obsolete and still works, in case you prefer the old method of manually installing with {{subst:Install user script|User:SMcCandlish/TidyCitations.js}} or using ScriptInstaller.

Usage

[edit]

TidyCitations will add two menu items to the p-toolbar when in edit mode:

  • {{Tidy}}
  • {{Tidy}} (vertically)

Clicking them will harmonize citations in a mess like this:

<ref name="Jarnow 2018">{{cite web
 |first=Jesse|last = Jarnow |title
=The Ghost of John Perry Barlow Lives in His Posthumous Memoir|website=[[Wired (magazine)|Wired]] | date = 5 June 2018 |url=https://www.wired.com/story/the-ghost-of-john-perry-barlow-lives-in-his-posthumous-memoir/ |
archive-url=http://web.archive.org/web/20180606011712/https://www.wired.com/story/the-ghost-of-john-perry-barlow-lives-in-his-posthumous-memoir/|archive-date=6 June 2018|dead-url=no |access-date=
2 August 2018}}</ref>

to one of the following:

{{Tidy}}:

<ref name="Jarnow 2018">{{cite web |first=Jesse |last=Jarnow |title=The Ghost of John Perry Barlow Lives in His Posthumous Memoir |website=[[Wired (magazine)|Wired]] |date=5 June 2018 |url=https://www.wired.com/story/the-ghost-of-john-perry-barlow-lives-in-his-posthumous-memoir/ |archive-url=http://web.archive.org/web/20180606011712/https://www.wired.com/story/the-ghost-of-john-perry-barlow-lives-in-his-posthumous-memoir/ |archive-date=6 June 2018 |dead-url=no |access-date=2 August 2018}}</ref>

{{Tidy}} (vertically):

<ref name="Jarnow 2018">{{cite web
 |first        = Jesse
 |last         = Jarnow
 |title        = The Ghost of John Perry Barlow Lives in His Posthumous Memoir
 |website      = [[Wired (magazine)|Wired]]
 |date         = 5 June 2018
 |url          = https://www.wired.com/story/the-ghost-of-john-perry-barlow-lives-in-his-posthumous-memoir/
 |archive-url  = http://web.archive.org/web/20180606011712/https://www.wired.com/story/the-ghost-of-john-perry-barlow-lives-in-his-posthumous-memoir/
 |archive-date = 6 June 2018
 |access-date  = 2 August 2018
}}</ref>

wikEd compatibility

[edit]

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

[edit]

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

[edit]

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 {{cite web|first=Jesse|last=Jarnow|...}}, or grossly expanding it into a mess like {{cite web | first = Jesse | last = Jarnow | ... }}. 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  |first = Jesse layout. This differs from Sam Sailor's earlier variant on this script, which did | first = Jesse. The old version produced:
    <ref name="Jarnow 2018">{{cite web
    | first        = Jesse
    | last         = Jarnow
    ...
    | access-date  = 2 August 2018
    }}</ref>
    
    The new version does:
    <ref name="Jarnow 2018">{{cite web
     |first        = Jesse
     |last         = Jarnow
     ...
     |access-date  = 2 August 2018
    }}</ref>
    

    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 Values 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 are 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 switch that was detecting for a value of horizontal when the containing if...then already did that; replaced the entire switch with just the one result it contained, since it was always guaranteed to run inside that then and could not run if the corresponding then for horizontal was not already matched.
  • 1 January 2023 – Clearer orientation variable name (was just the vague str which could seem to mean anything).

Infrequently asked questions

[edit]
  • 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).

References

[edit]