Nenda kwa yaliyomo

Mtumiaji:MGA73/common.js

Kutoka Wikipedia, kamusi elezo huru

Elewa - Baada ya kuhifadhi, itakubidi uzungushe kivinjali kache chako ili kuona mabadiliko.

  • Firefox / Safari: Shikiria Shift wakati unabonyeza Reload, au aidha bonyeza Ctrl-F5 au Ctrl-R (⌘-R kwa Mac);
  • Google Chrome: Bonyeza Ctrl-Shift-R (⌘-Shift-R kwa Mac)
  • Konqueror: Bonyeza Reload au bonyeza F5;
  • Opera: Futa kache kwenye Tools → Preferences;
  • Internet Explorer: Shikiria Ctrl wakati unabonyeza Refresh, au bonyeza Ctrl-F5.
$(document).ready(function() {
    function addButtons() {
        if (mw.config.get('wgNamespaceNumber') === 6 || mw.config.get('wgPageName') === 'Kasutaja: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|GFDL-en)}}/g, newGFDLWithDisclaimersTemplate);
                editBox.val(updatedText);
            }
            
            if (summary) {
                $('#wpSummary').val(summary);
            }
        }
    }

    addButtons();
    applyChangesOnEditPage();
});