Template talk:Diff

Sandbox and test cases
This template now has a sandbox and test cases. If you edit this page, please verify that the test cases still work. See Template test cases for more information.

Problems with the current version
I initialised the sandbox with an old (believed to be working) version of the template. Right now, the code in the sandbox (derived from of the template) works, and the code in the main template (as of ) is wrong in the following ways: &mdash;AlanBarrett 15:00, 1 May 2008 (UTC)
 * 1) It gets the URLs slightly wrong (e.g. "Main+Page" instead of "Main_Page");
 * 2) It makes the links look like external links, whereas they should look like internal links.
 * I'm going to go ahead and Be Bold. The sandbox version seems to work fine, I'm going to move it to the main template page. Feel free to revert if it doesn't work out and if you have time, contact me about it. (its also a much simpler implementation of template syntax) Atyndall93  |  talk  12:35, 4 May 2008 (UTC)

White space
White space on either side of the third '|' pipe symbol causes peculiar output:
 * without white space either side of the third '|' pipe symbol:


 * with white space before the third '|' pipe symbol:


 * with white space after the third '|' pipe symbol:


 * with white space both sides of the third '|' pipe symbol:

If one clicks on the links, the "peculiar" output links lead to a page that is different from the page linked to by the "correctly" output link.

This issue should either be corrected in the template code or the documentation should be changed to note this anomaly. This editor votes for fixing the template because all other templates appear to accept white space around '|' pipe symbols without producing anomalous output.

—Trappist the monk (talk) 17:57, 8 July 2012 (UTC)

oldid
Hi guys; I added Template:Oldid to cover the situation of linking to an old version; it seemed like I was doing that all the time and could never remember where the blank parameter in diff went! :-) I reused the code from diff rather than transcluding it through.  -- tiny plastic Grey Knight &#x2296; 14:40, 17 July 2008 (UTC)

Adding new categories
Apparently adding new categories to this template's sub-page doesn't work for some reason. I added Category:Diff templates but it won't show up, even after purging both pages, including the category page itself. Why? Hey Mid  (contributions) 16:03, 26 September 2010 (UTC)
 * Sometimes you need to add them to the main template, in the no-include section where documentation resides, or make sure you hit purge on the documentation page. Unless you mean a different subpage, if so left us know. I hope this helps. -- Wolfnix •  Talk  • 16:12, 26 September 2010 (UTC)
 * Also, In the docs section make sure it is in the includeonly section. -- Wolfnix •  Talk  • 16:14, 26 September 2010 (UTC)
 * But why is it like this in this template? I tried adding it to Template:Diff/doc and purged all related pages, but it still won't show up. What makes this template different from others then? Hey  Mid  (contributions) 16:17, 26 September 2010 (UTC)
 * Yes, I have already checked that. Also, I have the same problem with Template:Oldid. Hey  Mid  (contributions) 16:22, 26 September 2010 (UTC)
 * Shows for me. Amalthea  16:29, 26 September 2010 (UTC)
 * Yes, it shows up on the main page, but when you click on the actual category, it doesn't show up there. Hey  Mid  (contributions) 16:34, 26 September 2010 (UTC)
 * Oh, in the category? That's a Mediawiki thing, just wait until the job queue gets around to it (or someone (null) edits the page). See Help:Category. Amalthea  16:40, 26 September 2010 (UTC)
 * This seems to only affect sysop-protected templates; the non-protected ones show up immediately. And because of this, I am unable to null edit these pages. Hey  Mid  (contributions) 16:43, 26 September 2010 (UTC)
 * No, that impression is incorrect. Amalthea  16:50, 26 September 2010 (UTC)
 * My impression is that you null-edited this page. I was forced to do so at Template:Diff2 for making it appear in Category:Internal link templates. Or I need more patience. Hey  Mid  (contributions) 17:01, 26 September 2010 (UTC)
 * That impression is correct. ;) And yes, jobs can take hours or days sometimes to get processed (and sometimes, in the past at least, were dropped entirely). Amalthea  17:09, 26 September 2010 (UTC)

Edit request: remove extra ampersand
See my edit to Template:diff/sandbox. Please remove the ampersand from the first "&diff", following "fullurl:" (but not the other "&diff" following "index.php"). Just fixes a minor eyesore in the URL:


 * http://en.wikipedia.org/w/index.php?title=Main_Page&&diff=prev&oldid=204901573: Before
 * http://en.wikipedia.org/w/index.php?title=Main_Page&diff=prev&oldid=204901573: After

Vadmium (talk) 10:59, 24 February 2011 (UTC)
 * Good job. ✅ &mdash; Martin (MSGJ · talk) 11:35, 24 February 2011 (UTC)

Why the title parameter?
Is there any good reason why this template wants the page title as its first parameter? The "title=" part in a diff link or a link to an old version is simply ignored. You can even compare two specific versions of two completely different pages with a diff link. Is there any reason not to propose in the documentation that the first parameter be left empty for simplicity? Hans Adler 08:48, 24 April 2011 (UTC)
 * I've wondered that too, it seams the Wiki servers don't look at the title, just the diff numbers. 117Avenue (talk) 20:37, 24 April 2011 (UTC)
 * The title appears on top of the diff screen.  — Edokter  ( talk ) — 00:13, 25 April 2011 (UTC)
 * 117Avenue (talk) 01:29, 25 April 2011 (UTC)
 * The Main Page being the only exception (as javascript hides it).  — Edokter  ( talk ) — 12:10, 25 April 2011 (UTC)
 * 117Avenue (talk) 17:44, 25 April 2011 (UTC)
 * Indeed the title is no longer required, but some scripts still depend on it being present (but most have since been updated as well). The documentation needs to be updated to reflect that the title is no longer mandatory.  — Edokter  ( talk ) — 01:15, 26 April 2011 (UTC)


 * Hi, . Is the documentation regarding this ever going to be updated? Ping me back. Cheers!  04:36, 4 January 2016 (UTC)
 * You can do it yourself; the /doc page is not protected.  11:49, 4 January 2016 (UTC)

Edit request: remove the other extra ampersand
Another cosmetic fix similar to the one above, please see. This removes the extra ampersand in the event that a page name is passed without a diff (i.e., it's being used like oldid). – RobinHood70 talk 22:26, 26 July 2011 (UTC)
 * Yes check.svg Done Dabomb87 (talk) 15:25, 30 July 2011 (UTC)

Poor documentation
The page doesn't say what to do with the template. Apparently those characters do something somewhere if you do something, but the page doesn't say where to use them or what might happen if you do. Poor documentation. --Ring Cinema (talk) 14:29, 26 August 2012 (UTC)

Feature request: diffonly
Could someone who's better at template logic than me please add diffonly as an option to this template? Many thanks. —  Scott  •  talk  12:22, 10 October 2013 (UTC)


 * What would be the purpose and function? How would this parameter be used?


 * —Trappist the monk (talk) 12:59, 10 October 2013 (UTC)
 * Shows the diff only. See parameter documentation at Help:Diff. —  Scott  •  talk  16:48, 10 October 2013 (UTC)


 * Like this in the sandbox?
 * → – diffonly not present
 * → – diffonly present but empty
 * → – diffonly present and assigned anything but
 * → – yes


 * —Trappist the monk (talk) 17:22, 10 October 2013 (UTC)
 * Yes, that's great. —  Scott  •  talk  18:19, 10 October 2013 (UTC)


 * Done.


 * —Trappist the monk (talk) 20:00, 10 October 2013 (UTC)
 * Wonderful! Thanks very much. —  Scott  •  talk  21:58, 10 October 2013 (UTC)

readability
I found I had a very hard time in reading the examples in the Code column, trying to keep straight which parts were variable and which were constant. I have
 * italicized the variables[1]
 * bolded "Diff"[1,2]
 * bolded and underlined the constant parameters
 * bolded and underlined the double pipes where there is an empty parameter.

1. as is already done in § Usage

2. though this only shows up in Template talk:Diff, not in Template talk:Diff/doc

If you would like to discuss this with me, please me. --Thnidu (talk) 01:56, 15 December 2014 (UTC)

No way to suppress displaying "&=[oldid]"
No matter how I set the parameters, I can't get rid of &oldid=[oldid number].

produces
 * (and what the heck is the diffonly parameter doing showing up there?)
 * (and what the heck is the diffonly parameter doing showing up there?)
 * (and what the heck is the diffonly parameter doing showing up there?)

The example on the doc page works (and of course initial capital or small letter in the template name doesn't matter): produces

but yields instead of the link labeled just "foobar".

It's not a question of whether the first id parameter is more recent than the second one, as in the example (204934693 > 204901573), or older, as in mine (443485171 < 443805461). If I swap mine into newer-older order, it still happens: produces

Is the template supposed to work differently in Wikipedia namespace? It shouldn't, and the doc sure doesn't mention it. Can someone please fix this?? --Thnidu (talk) 16:27, 11 June 2015 (UTC)


 * White space is important. The template is creating an external wikilink.  That space after 'prev' ends the external link and begins the linked text:
 * Here are your examples without white space:
 * —Trappist the monk (talk) 16:42, 11 June 2015 (UTC)
 * I've updated the template to no longer be sensitive to leading and trailing whitespace in the parameters. --Krinkle (talk) 17:02, 11 June 2015 (UTC)
 * Ah! Thank you! --Thnidu (talk) 18:00, 11 June 2015 (UTC)
 * especially since I find long solid strings of code extremely hard to read - and on a smart phone! - so I tend to insert spaces before the pipes. --Thnidu (talk) 18:17, 11 June 2015 (UTC)
 * —Trappist the monk (talk) 16:42, 11 June 2015 (UTC)
 * I've updated the template to no longer be sensitive to leading and trailing whitespace in the parameters. --Krinkle (talk) 17:02, 11 June 2015 (UTC)
 * Ah! Thank you! --Thnidu (talk) 18:00, 11 June 2015 (UTC)
 * especially since I find long solid strings of code extremely hard to read - and on a smart phone! - so I tend to insert spaces before the pipes. --Thnidu (talk) 18:17, 11 June 2015 (UTC)
 * —Trappist the monk (talk) 16:42, 11 June 2015 (UTC)
 * I've updated the template to no longer be sensitive to leading and trailing whitespace in the parameters. --Krinkle (talk) 17:02, 11 June 2015 (UTC)
 * Ah! Thank you! --Thnidu (talk) 18:00, 11 June 2015 (UTC)
 * especially since I find long solid strings of code extremely hard to read - and on a smart phone! - so I tend to insert spaces before the pipes. --Thnidu (talk) 18:17, 11 June 2015 (UTC)


 * I was still finding the examples hard to use as models, so I added pseudocode to the table. --Thnidu (talk) 05:05, 12 June 2015 (UTC)

Template-protected edit request on 4 January 2016
Edit the template so page version values can be put in either the 1st or 2nd parameter position and the template will automatically ensure that the largest page version value is used as the latest page version when creating the rendered Diff page. Ping me back. Cheers! 02:32, 4 January 2016 (UTC)

02:32, 4 January 2016 (UTC)
 * Please make your edits in the Template:Diff/sandbox, verify the Template:Diff/testcases, then reactivate your edit request when ready. — xaosflux  Talk 02:45, 4 January 2016 (UTC)

added title= ?
You've modified the code, but you haven't documented what's new. Please do so! I can't tell from the code how it's to be used, and I shouldn't have to; that's what user documentation is for. --Thnidu (talk) 19:58, 10 April 2016 (UTC)
 * In essence, nothing has changed. You normally use unnamed parameters, but I added 'title' as an option to be used as a named paramenter (because that what's usually in an URL).  20:20, 10 April 2016 (UTC)
 * You've answered my question but you haven't solved the problem. The documentation now mentions the  parameter in a half-dozen places or so, but it's nowhere in the examples. For instance,
 * {| class="wikitable"

! style="width:33%;" | Code !! Output


 * The diff= parameter (parameter number 2) should be the larger revision number.
 * The oldid= parameter (parameter number 3) should be the smaller revision number.
 * }
 * The example should show the  parameter in use, but it doesn't. It's not hard for me to figure out, but I've been a Wikipedian for ten years. Please edit it in appropriately everywhere you mention it. Besides the quotation above, it's needed in
 * Usage
 * Diff between two numbered versions of a page
 * Code:
 * Output:
 * The diff= parameter (parameter number 2) should be the larger revision number.
 * The oldid= parameter (parameter number 3) should be the smaller revision number.
 * Diff between two numbered versions of a page
 * Code:
 * Output:
 * The diff= parameter (parameter number 2) should be the larger revision number.
 * The oldid= parameter (parameter number 3) should be the smaller revision number.
 * The diff= parameter (parameter number 2) should be the larger revision number.
 * The oldid= parameter (parameter number 3) should be the smaller revision number.
 * The oldid= parameter (parameter number 3) should be the smaller revision number.


 * Diff between two numbered versions of a page in Wikipedia namespace
 * Code:
 * Output:
 * The diff= parameter (parameter number 2) should be the page revision to appear on the right (proposed change).
 * The oldid= parameter (parameter number 3) should be the page revision to appear on the left (original).
 * Comparison display without page display of two numbered versions of a page
 * Code:
 * Output:
 * The diff= parameter (parameter number 2) should be the larger revision number.
 * The oldid= parameter (parameter number 3) should be the smaller revision number.
 * The diffonly= parameter, which must include the parameter name, can only be set to
 * Output:
 * The diff= parameter (parameter number 2) should be the larger revision number.
 * The oldid= parameter (parameter number 3) should be the smaller revision number.
 * The diffonly= parameter, which must include the parameter name, can only be set to
 * The diff= parameter (parameter number 2) should be the larger revision number.
 * The oldid= parameter (parameter number 3) should be the smaller revision number.
 * The diffonly= parameter, which must include the parameter name, can only be set to


 * TemplateData
 * In the first row of the table.
 * Please me to discuss. --Thnidu (talk) 19:22, 23 April 2016 (UTC)


 * That is because it continues to work as an unnamed parameter. No need to use it explicitly.  19:33, 23 April 2016 (UTC)


 * By that argument there's no need to mention it at all. But since the page does mention it now, the documentation must tell the user how to use it. --Thnidu (talk) 20:37, 23 April 2016 (UTC)


 * "page=" was also never mentioned in the examples. The only change is that the primary parameter name is now "title".  21:50, 23 April 2016 (UTC)

White space added in rendered page
In a conversation on my talk page, I wrote, and discovered that it rendered an extraneous space between the link and the comma:

The diff template seems to be spitting out an extraneous whitespace character. Can this be remedied? Thanks! —jameslucas ▄▄▄ ▄ ▄▄▄ ▄▄▄ ▄  15:42, 23 May 2017 (UTC)
 * You're using the template in the wrong way. You should put
 * which yields
 * or alternatively
 * which yields
 * Nardog (talk) 17:47, 24 August 2017 (UTC)
 * which yields
 * Nardog (talk) 17:47, 24 August 2017 (UTC)
 * Nardog (talk) 17:47, 24 August 2017 (UTC)
 * Nardog (talk) 17:47, 24 August 2017 (UTC)

Your feedback helped me make a few mental leaps, and after some experimentation and consideration, I would actually suggest that the best end-use solution for this issue is adding a double pipe to explicitly leave the (supposedly optional) title parameter blank: For example, the code I'd write intuitively—.—renders:

whereas the version hacked with an extra verical bar—.—renders:

Obviously having a solution is great, and at the very least we can improve the half-assed documentation that says that title is "optional in most cases" but doesn't mention the double piping workaround. Beyond this, though, I feel like this is still too hacky a solution for a template that editors of all levels of experience should be using regularly. I have tried to get my head around 's reasons for the existence of title parameter (as he or she was discussing back in 2011 and 2016; see above), but it's never made any sense to me. I guess my ultimate question is: is there a way we can modify the template to make the intuitive use of diff work rather than merely improve the documentation? Thanks —jameslucas ▄▄▄ ▄ ▄▄▄ ▄▄▄ ▄  19:10, 24 August 2017 (UTC)

Template-protected edit request on 23 August 2017
This template is adding extra whitespace at the end, which is problematic if the template is followed by a comma or fullstop. I noted this problem 3 months ago but didn't manage to get anyone's attention. I haven't determined the solution, but I'd appreciate a fix if it's possible! —jameslucas ▄▄▄ ▄ ▄▄▄ ▄▄▄ ▄  21:01, 23 August 2017 (UTC)
 * ❌ There's nothing wrong with the template. See above. Nardog (talk) 17:47, 24 August 2017 (UTC)

Substitution
Can I ask why this template isn't substituted? It seems like a utility template like unsigned or done that doesn't need to change over time. If there is no real reason it isn't substituted, then I propose that it be substituted. Thanks, --DannyS712 (talk) 17:58, 25 March 2019 (UTC)
 * It would probably be better to subst with Special:Diff. I believe this template could be changed to use that easily. 50.53.21.2 (talk) 19:08, 22 August 2019 (UTC)

Possible bug added to testcases
I have added a possibly buggy case that I found in the wild. It looks like this: The first word ("undo") is stripped. It appears that the cause may be the omission of the title parameter, which the documentation says is optional, but then the other options are each "promoted" by one level, in a way that fails poorly and does not generate an error message. I am not a fan of templates with multiple unnamed parameters, for reasons like this, unless they have significant error-checking. – Jonesey95 (talk) 15:33, 8 October 2021 (UTC)