MediaWiki:Gadget-FastRevert.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Note – after saving, you may have to bypass your browser’s cache to see the changes.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

See also: Special:Gadgets.


/**
 ************* FastRevert *******************
 * Allows one to restore an old version     *
 *                                          *
 * Author: Quentinv57, for Wikimedia        *
 *          -- 06 Feb. 2010 --              *
 ********************************************
 */

$( document ).ready( function () { 
	if (mw.util.getParamValue('action') === 'history') {
		var chemin = '//en.wiktionary.org/w/index.php?action=edit&retablir';
		
		var pageHistory = document.getElementById('pagehistory');
        pageHistory = pageHistory && pageHistory.getElementsByTagName('li');
        var prevUser;
		
        for (var i = 0; i < pageHistory.length; i++) {
            var li = pageHistory[i];
            var oldid = li.dataset.mwRevid; // data-mw-revid="..."
            var userLink = li.querySelector(".history-user .mw-userlink");
            // Get inside of bdi tag if it's present.
            while (userLink.firstElementChild) {
                userLink = userLink.firstElementChild;
            }
            var username = userLink.textContent;
			if (i !== 0) {
				var revertLink = document.createElement( "a" );
				revertLink.href = chemin + '&oldid=' + oldid + '&user=' + username + '&user2=' + prevUser;
				revertLink.appendChild( document.createTextNode( "FastRevert" ) );
				li.appendChild( document.createTextNode( " \u2014 (" ) );
				li.appendChild( revertLink );
				li.appendChild( document.createTextNode( ")" ) );
            }
            prevUser = username;
		}
    } else if (location.href.match(/&retablir&/)) {
        var user2 = mw.util.getParamValue('user2');
        var message = prompt(
            'What message do you want to leave?',
            'Reverted edits by [[Special:Contributions/' + user2 + '|' + user2 + ']]'
        );
		
        var user = mw.util.getParamValue('user');
        document.getElementById('wpSummary').value = (message ? message + '; ' : '')
            + 'Restore to version ' + mw.util.getParamValue('oldid')
            + ' by [[Special:Contributions/' + user + '|' + user + ']]';
		
		if (message != null) document.getElementById('editform').submit();
	}
});