Jump to content
Wikipedia The Free Encyclopedia

User:Nardog/SmartDiff

From Wikipedia, the free encyclopedia
SmartDiff
DescriptionMakes links and template calls in diffs clickable (supports red links, avoids WP:SEAOFBLUE)
UpdatedDecember 2, 2025
    (7 months ago)
BrowsersChrome, Firefox, etc. (ES2018+ needed)
SourceUser:Nardog/SmartDiff.js

This script turns wikilinks, external links, and template/module calls in a diff into clickable links. It shows links to nonexistent pages in red, and keeps the linked part to a minimum to avoid WP:SEAOFBLUE, unlike fancy-diffs (further comparison).

Installation

[edit ]

Add the following to your common.js or global.js:

mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Nardog/SmartDiff.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.

Customization

[edit ]

Template parameter linking

[edit ]

You can instruct the script to link certain unnamed parameters in templates, so e.g. {{tl|reflist}} appears as {{tl|reflist}}. This is useful for linking templates like {{tl }} and hatnotes like {{About }}. Linking of named parameters is not supported, and the template call and parameters must be in the same line for the latter to be linked.

To do it, add code like below to your common.js (templates vary by wiki, so even if you have installed the script globally, it is recommended to have different code on each wiki).

window.smartdiffTemplates=[
// Objects go here
];

Example

[edit ]

Here is an example based on templates on English Wikipedia.

Example code
window.smartdiffTemplates=[
// {{t}}, {{tl}}
{
names:['T','Tl'],
end:1,
namespace:10,
forceNs:true
},
// {{tlx}}
{
names:['Tlx'],
end:1,
namespace:10
},
// {{u}}
{
names:['U'],
end:1,
namespace:1
},
// {{Reply to}}, {{Re}}, {{Ping}}
{
names:['Re','Reply to','Ping'],
namespace:1
},
// {{About}}
{
names:['About'],
start:3,
skipEven:true
},
// {{For}}
{
names:['For'],
start:2
},
// {{Other uses}}, {{Otheruses}}
{
names:['Other uses','Otheruses'],
end:1
},
// {{Distinguish}}, {{Further}}, {{Main}}, {{See also}}
{
names:['Distinguish','Further','Main','See also','Seealso']
},
// {{Redirect}}
{
names:['Redirect'],
skipEven:true,
noRedirectEnd:1
},
// {{Tracked}}
{
names:['Tracked'],
end:1,
prefix:'phab:'
},
];

Schema

[edit ]

The objects can have the following properties (only names is required):

names (array of strings)
Template names to apply this object to. Must be well-formed names (no Template:, no underscores, start with a capital letter except on Wiktionary). Redirects are not resolved, so include all you expect to find.
start, end (number); skipOdd, skipEven (boolean)
Specify the range of parameters to link. If omitted, all unnamed parameters will be linked.
namespace (number)
Namespace number for the link.
forceNs (boolean)
If true, the namespace prefix will be added even if the input begins with a valid namespace prefix (so e.g. {{tl|Wikipedia:Cleanup/Header}} is linked correctly).
prefix, suffix (string)
String to prepend or append to the input. prefix is useful for linking to a special page or sister site.
noRedirectStart, noRedirectEnd (number)
Specify the range of parameters to suppress redirects (by adding redirect=no to the URL) in.

Magic words

[edit ]

If you want the script to recognize certain magic words it does not by default and stop linking them as templates, you can do so by adding code like below to your common.js or global.js. This example adds localized variables for PAGENAME and DEFAULTSORT in Polish (a trailing colon is required if the magic word accepts a variable).

window.smartdiffMagicWords=['NAZWASTRONY','NAZWASTRONY:','SORTUJ:'];

Comparison with fancy-diffs

[edit ]

This script owes a great debt to Enterprisey's fancy-diffs in its concept, and makes improvements on it. Differences include:

  • Shows links to nonexistent pages in red.
  • Links only [[this part]] and [[this part|in piped links]], avoiding WP:SEAOFBLUE.
  • Links section headings (e.g. == Customization ==).
  • Recognizes template names without }} in the same line (e.g. {{Infobox person ).
  • Recognizes relative links to and transclusions of subpages (e.g. [[/Archive 1]]).
  • Does not mistake common magic words and template parameters ({{PAGENAME}}, {{#if:...}}, {{{1}}} etc.) for template calls.
  • Supports customizable linking of unnamed parameters in templates (e.g. {{tl|Cite web}}, {{distinguish|Foo}})—see above.
  • Links content inside tvar in multilingual wikis, as in [[<tvar name=1>Foo</tvar>|Foo]].
  • Shows external and interwiki links in the same color as in the page body.
  • Adds to links to redirects and disambiguation pages the respective mw-redirect and mw-disambig classes, so if you style them in your CSS (or use the gadget "Display links to disambiguation pages in orange"), they appear the same as in the page body.
  • Verifies the result after processing each line, so it will never alter the substance of a diff even if it makes a mistake (and notifies you in such an event so you can report it).
  • Does not support image previews.

Limitations

[edit ]
  • The detection/retrieval of red links and link classes is capped at 500 unique page names (10 API calls) per diff.
Nardog's scripts
Extra functionality
  • CatChangesViewer – Lists recent category additions/removals on a category page.
  • Consecudiff – Adds links to diffs of consecutive edits by the same user on watchlist, history, etc.
  • CopyCodeBlock – Adds a button to copy the content of each code block (<pre>).
  • CopySectLink – Adds a button to copy the unencoded page title or section path next to each heading.
  • MoveHistory – Lists the past moves a page has gone through.
  • RCMuter – Hides specified users' edits on Watchlist/RecentChanges.
  • SmartDiff – Makes links and template calls in diffs clickable (supports red links, avoids WP:SEAOFBLUE).

Editing assistance

  • DiffUndo – Adds an undo button to each line on the diff while editing.
  • ExpandContractions – Expands contractions.
  • InsertAnyChar – Insert any character by exploring or searching in the entire Unicode chart.
  • IPAInput – Type in IPA symbols by directly looking at an IPA key like Help:IPA/English and clicking on the symbols.
  • RefRenamer – Replaces reference names like ":0" with descriptive ones like "Smith-2015".
  • Unpipe – Converts each piped link to a non-piped one if both lead to the same article, enforcing WP:NOPIPE.

Itch scratchers

  • AutoSectionLink – Adds or refines the /* section link */ as you edit so only the modified section will be linked in the summary.
  • AutoTestcases – Autofills "Preview page with this template" with the most relevant /testcases page that exists.
  • PasteToCommons – Upload an image to Commons from anywhere on the site by pasting it.
  • SortCentralAuthByEditCount – Sorts the list of local accounts on CentralAuth by edit count.

AltStyle によって変換されたページ (->オリジナル) /