User:WOSlinker/common.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.
// <nowiki>

//Add a 'null edit' tab
if(mw.config.get('wgNamespaceNumber') != -1 && mw.config.get('wgArticleId') != 0) { 
    $( function nullEditButton() {
        mw.util.addPortletLink('p-cactions', 
                       mw.util.getUrl(null,{action:'edit',nulledit:true}),
                       'null',
                       'p-null',
                       'Null edit this page2');
    }
)}
 
if(mw.config.get('wgAction') == 'edit' && queryString('nulledit') == 'true') {
    $(function nullEdit() {
        document.getElementById('wpSave').click();
    }
)}
 
function queryString(p) {
    var re = RegExp('[&?]' + p + '=([^&]*)');
    var matches;
    if (matches = re.exec(document.location)) {
        try { 
            return decodeURI(matches[1]);
        } catch (e) { }
    }
    return null;
}

//Add a 'thumb edit' tab
if(mw.config.get('wgArticleId') != 0 ) { 
    $( function thumbEditButton() {
        mw.util.addPortletLink('p-cactions', 
                       mw.util.getUrl(null,{action:'edit',thumb:true}),
                       'thumb',
                       'p-thumb',
                       'thumb edit');
    }
)}

if(mw.config.get('wgAction') == 'edit' && queryString('thumb') == 'true') {
    $(function thumb() {
        var myContent = document.getElementById('wpTextbox1').value;

          myContent = myContent.replace(/\n((Image|File)\:[^\|\n]*\|)thumb\|/gi,'\n$1');
          myContent = myContent.replace(/\n((Image|File)\:[^\|\n]*\|[^\|\n]*\|)thumb\|/gi,'\n$1');
          myContent = myContent.replace(/\n((Image|File)\:[^\|\n]*\|[^\|\n]*\|[^\|\n]*\|)thumb\|/gi,'\n$1');

          myContent = myContent.replace(/\n([^\|\n\.\{\[]*\.(jpg|jpeg|png|svg)\|)thumb\|/gi,'\n$1');
          myContent = myContent.replace(/\n([^\|\n\.\{\[]*\.(jpg|jpeg|png|svg)\|[^\|\n]*\|)thumb\|/gi,'\n$1');

        if(document.getElementById('wpTextbox1').value != myContent) {
           document.getElementById('wpTextbox1').value=myContent;
           document.getElementById('wpSummary').value='Fix [[Special:LintErrors/bogus-image-options|lint errors]] with image options';
           document.getElementById('wpMinoredit').checked = true;
        }


   }
)}

// </nowiki>