MediaWiki:Gadget-common-action-history.js

/ ** * Due to its small size, there is no reason to spend a separate request to download this gadget; it is loading * certainly (due to the "| default" in MediaWiki: Gadgets-definition). If the code grows to * several kilobytes, you can delegate its download MediaWiki: Common.js and download by * terms / conditions. * * Since at the moment the gadget contains only functions for registered * participants, it is loaded only by them. If this changes, remove "| rights = minoredit" from * MediaWiki: Gadgets-definition for this gadget. * / if (mw.config.get ('wgAction') === 'history') { $ (function { // Function for adding a link to the menu under the title function addSubLink ($ link, toolName) { $ ('.mw-history-subtitle') .append ( '•', $ link .attr ('href', 'javascript:') .css ('font-style', 'italic') .click (showRevertToLinks) ); }

// Add "Back To" Links for Auto Patrollers, Patrollers and Admins var wgUserGroups = mw.config.get ('wgUserGroups'); if (wgUserGroups && /editor|sysop/.test (wgUserGroups.join ('|'))) {// Including autoeditor addSubLink ($ ('') .attr ('title', 'Add links to revert to old versions') .text ('Revert to ...') ); }

// Icons "updated since my last visit" $ ('.updatedmarker') .attr ('title', 'updated since my last visit');

function plural (number, one, few, many) { number = Math.abs (number)% 100; if (number <10 || number> 20) { var x = number% 10; if (x == 1) { return one; } if (0 <x && x <5) { return few; } } return many; }

function showRevertToLinks (e) { e.preventDefault ; if (! window.revertLinksCSS) { appendRevertToLinks ; } revertLinksCSS.disabled = false; setTimeout (function { revertLinksCSS.disabled = true; }, 5000); }

function appendRevertToLinks { var $ ul = $ ('#pagehistory'); if (! $ ul.length) { alert ('The history of page changes is empty'); return; } var $ li, $ link, version, user, url, $ lis = $ ul.find ('li'); for (var i = 2; i <$ lis.length; i ++) { $ li = $ lis.eq (i); $ link = $ li.find ('.mw-changeslist-date'); version = $ li.find ('input') .val ; user = $ li.find ('a.mw-userlink') .text ; url = $ link.attr ('href') + '& action = edit & summary =' + encodeURIComponent ( i +  + plural (i, 'revision', 'revisions', 'revisions') +  + plural (i, 'returned', 'returned', 'returned') + ' to version' + version + '' + user + ':' ) + '#wpSummary'; $ link.after ( '(', $ ('') .attr ('href', url) .attr ('title', 'Revert this version') .addClass ('revertTo') .text ('return'), ')' ); } revertLinksCSS = mw.util.addCSS ('.revertTo {font-weight: bold;}'); // Global variable } }); }