Nota: dopo aver pubblicato, potrebbe essere necessario pulire la cache del proprio browser per vedere i cambiamenti.

  • Firefox / Safari: tieni premuto il tasto delle maiuscole Shift e fai clic su Ricarica, oppure premi Ctrl-F5 o Ctrl-R (⌘-R su Mac)
  • Google Chrome: premi Ctrl-Shift-R (⌘-Shift-R su un Mac)
  • Edge: tieni premuto il tasto Ctrl e fai clic su Aggiorna, oppure premi Ctrl-F5.
$(document).ready(function() {
    function addButtons() {
        if (mw.config.get('wgNamespaceNumber') === 6 || mw.config.get('wgPageName') === 'Utente:MGA73/Sandbox') {
            var buttonContainer = $('<div>').css({'margin': '10px 0'});
            
            var relicenseButton = $('<button>')
                .text('Relicense')
                .css({
                    'cursor': 'pointer',
                    'margin-right': '10px'
                })
                .click(function(event) {
                    event.preventDefault();
                    // Redirect to the edit page with relicense marker
                    var editUrl = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', relicense: true });
                    window.location.href = editUrl;
                });
            
            var notEligibleButton = $('<button>')
                .text('Not-eligible')
                .css({
                    'cursor': 'pointer',
                    'margin-right': '10px'
                })
                .click(function(event) {
                    event.preventDefault();
                    // Redirect to the edit page with not-eligible marker
                    var editUrl = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', noteligible: true });
                    window.location.href = editUrl;
                });
            
            var redundantButton = $('<button>')
                .text('Redundant')
                .css({
                    'cursor': 'pointer'
                })
                .click(function(event) {
                    event.preventDefault();
                    // Redirect to the edit page with redundant marker
                    var editUrl = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit', redundant: true });
                    window.location.href = editUrl;
                });
            
            buttonContainer.append(relicenseButton).append(notEligibleButton).append(redundantButton);
            
            var content = $('#content');
            if (content.length) {
                content.prepend(buttonContainer);
            }
        }
    }
    
    function applyChangesOnEditPage() {
        if (mw.config.get('wgAction') === 'edit') {
            var urlParams = new URLSearchParams(window.location.search);
            var relicense = urlParams.get('relicense');
            var noteligible = urlParams.get('noteligible');
            var redundant = urlParams.get('redundant');
            
            var newGFDLTemplate;
            var newGFDLWithDisclaimersTemplate;
            var summary;
            
            if (relicense) {
                newGFDLTemplate = '{{GFDL|migration=relicense}}';
                newGFDLWithDisclaimersTemplate = '{{GFDL-with-disclaimers|migration=relicense}}';
                summary = 'Eligible for [[:w:en:Wikipedia:Image license migration|GFDL relicense]]. Uploaded before August 2009.';
            } else if (noteligible) {
                newGFDLTemplate = '{{GFDL|migration=not-eligible}}';
                newGFDLWithDisclaimersTemplate = '{{GFDL-with-disclaimers|migration=not-eligible}}';
                summary = 'Not eligible for [[:w:en:Wikipedia:Image license migration|GFDL relicense]]. Uploaded after August 2009. Uploader please consider adding {{Cc-by-sa-4.0}}.';
            } else if (redundant) {
                newGFDLTemplate = '{{GFDL|migration=redundant}}';
                newGFDLWithDisclaimersTemplate = '{{GFDL-with-disclaimers|migration=redundant}}';
                summary = 'File is considered redundant for [[:w:en:Wikipedia:Image license migration|GFDL relicense]]..';
            }
            
            if (newGFDLTemplate && newGFDLWithDisclaimersTemplate) {
                var editBox = $('#wpTextbox1');
                var currentText = editBox.val();
                
                // Replace {{GFDL}} and {{GFDL-with-disclaimers}} with the new templates
                var updatedText = currentText
                    .replace(/{{GFDL}}/g, newGFDLTemplate)
                    .replace(/{{GFDL-with-disclaimers}}/g, newGFDLWithDisclaimersTemplate);
                editBox.val(updatedText);
            }
            
            if (summary) {
                $('#wpSummary').val(summary);
            }
        }
    }

    addButtons();
    applyChangesOnEditPage();
});