User:Mattflaschen/editNew.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// Adds a n to let you edit the latest version of a page if you are viewing an old version. 

if(wgAction == "view" && window.location.href.indexOf("oldid") != -1)
{
  addOnloadHook(addNewEdit)
}

// Function based on addEditZero (which shows a 0 to edit 0th section), and intended to be right of that.
function addNewEdit () {
    var x;
    if (!(x = document.getElementById('ca-edit') )) return;
    var url = mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + wgPageName + "&action=edit";
    var y = mw.util.addPortletLink('p-cactions', url, 'n', 'ca-edit-new',
                           'Edit the latest of this page', '0', x.nextSibling.nextSibling);
 
    y.className = x.className;  // steal classes from the the edit tab...
    x.nextSibling.className = 'istalk';     // ...and make the edit tab have no right margin
};