MediaWiki talk:Gadget-ShortDiff.js

From Meta, a Wikimedia project coordination wiki

Fix for secure server[edit]

{{editprotected}}

Hi!

Currently the gadget is not working well with links like this:

https://secure.wikimedia.org/wikipedia/mediawiki/w/index.php?title=SomePage&diff=prev&oldid=99999

(they appear in user contributions's pages) I think this will fix it:

$(function(){
	$('a').live( 'click', function(){
		var href = $(this).attr('href');
		var diffVal = mw.util.getParamValue( 'diff', href );
		if ( !href || diffVal === '0' || diffVal === null ) {
			return;
		}
		var newHref = mw.config.get( 'wgServer' );
		if ( 'https://' === newHref.substr( 0, 8 ) || newHref.indexOf('translatewiki') > -1 ) {
			newHref += mw.config.get( 'wgScript' );
		}
		newHref += '/?diff=' + diffVal;
		var oldidVal = mw.util.getParamValue( 'oldid', href );
		if ( oldidVal ) {
			newHref += '&oldid=' + oldidVal;
		}
		$(this).attr( 'href',  newHref );
	});
});

Helder 23:38, 24 February 2011 (UTC)

PS: For some reason it was necessary to add wgScript to the url in order to get the script working on Translatewiki for links such as
http://translatewiki.net/wiki/Translating:Interface_translation_guidelines?diff=3029412&oldid=2717623&curid=44193
(which can be found at translatewiki:Special:RecentChanges). So, I've updated the code above as well (maybe there is a general solution? what do they have different from other wikis?). Helder 00:04, 17 May 2011 (UTC)
Done edit. Instead of checking manually for https:// or translatewiki (neither of which on itself is related to the url parameter, both are a workaround), I've choosen to just add wgScript in front of the URLs (wgServer is not needed). Now it works everywhere. The fact that Wikimedia wikis reroute URL-parameters from the root path to the scriptpath is probably not officially supported, so let's not dependant on it :). –Krinkletalk 23:00, 17 May 2011 (UTC)[reply]
Great! I knew the should be a way to avoid such special cases... Thanks! Helder 00:30, 18 May 2011 (UTC)

Bugs[edit]

If a page has a link such as

https://secure.wikimedia.org/wikipedia/en/w/index.php?diff=166145694&oldid=117099781

(which points to other wiki) and I click on it I get

https://secure.wikimedia.org/wikipedia/meta/w/index.php?diff=166145694&oldid=117099781

which results in an error in the current wiki. Helder 20:32, 21 May 2011 (UTC)

It also fails with the link displayed in the "You have new messages (last change)." message:
https://secure.wikimedia.org/wikipedia/en/w/index.php?title=User_talk:USERNAME&diff=cur
is converted to
https://secure.wikimedia.org/wikipedia/en/w/index.php?diff=cur
Helder 17:35, 26 May 2011 (UTC)

Usecase ?[edit]

So, I've been wondering about this gadget. What do people who have this enabled actually use it for ? What kind of links ? (Permalink, Recent changes diff-link, Watchlist diff-link, New page patrol, History page, previous/next on a diff page etc.).

Perhaps we can optimize it for something more specific, rather than trying to rewrite any and all links on the page, which, imho, may have unwanted side-effects (like in a technical discussion about parameters, you'd click a link and the title-parameter would get stripped..). And ofcourse external links as mentioned above in #BugsKrinkletalk 20:38, 21 May 2011 (UTC)[reply]

I use it whenever I can, in order to save bytes in the edit summaries (to workaround Bug 4714). So, it is usually convenient if every link I open is always converted to its shortest form since then I can just copy the URL from address bar of my browser and paste it where needed. Whenever I need the original link I just use the middle or right button of the mouse to open it in a new tab, since it doesn't change anything in this cases.
It is a good complement to mw:Snippets/Last revision action and MediaWiki:Gadget-ShortLink.js. Helder 20:03, 22 May 2011 (UTC)