User:Mattflaschen/Compare link.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Mattflaschen/Compare link. |
/**
* Convert the "Compare selected versions" button to a link
* (Based on [[w:en:User:Superm401/Compare_link.js]])
* @source: http://www.mediawiki.org/wiki/Snippets/Compare_link
* @rev: 2
* @see: [[bugzilla:16165]]
*
* Copyright 2006-2013 Matthew Flaschen ([[User:Superm401]]), [[User:Helder.wiki]]
*
* In addition to the GFDL and CC-BY-SA:
*
* This function (compare link) is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This function is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* A copy of the GPL is available at https://www.gnu.org/licenses/gpl-2.0.txt .
*
* By modifying [[Snippets/Compare_link]]:
* You agree to dual-license your contributions under both the
* GFDL (http://en.wikipedia.org/wiki/WP:GFDL) and version 2 of the GPL
* (https://www.gnu.org/licenses/gpl-2.0.txt) or any later version
* of the GPL published by the FSF.
*
*/
function fixCompare() {
var $histForm = $('#mw-history-compare'),
$diffList = $('#pagehistory'),
$buttons = $histForm.find('input.historysubmit'),
buttonText, $compareLink;
if ( $buttons.length === 0 ) {
// Only one version, so do nothing
return;
}
buttonText = $buttons
.remove()
.first().val();
$compareLink = $('<a></a>', {
'class': 'compare-link',
'text': buttonText
});
$histForm
.prepend($compareLink)
.append($compareLink.clone());
var updateCompare = function(){
var $radio = $histForm.find('input[type=radio]:checked'),
genLink = mw.config.get('wgScript')
+ '?title=' + mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) )
+ '&diff=' + $radio.eq(0).val()
+ '&oldid=' + $radio.eq(1).val();
$('.compare-link').each(function() {
$(this).attr('href', genLink);
});
};
updateCompare();
$diffList.change(updateCompare);
}
if ( mw.config.get('wgAction') === 'history' ) {
mw.util.addCSS( '.compare-link { border-radius:5px; color:black; text-decoration:none; border-width:1px 2px 2px 1px; border-style:solid; border-color:#DDDDDD #BBBBBB #BBBBBB #DDDDDD; padding:0.2em 1em; background-color:#EEEEEE; white-space:nowrap; } .compare-link:active{ border-width:0.1em; margin:0.1em; }' );
$(fixCompare);
}