User:Euphoria/common.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
fix
fix
Line 1: Line 1:

//<nowiki>
//<nowiki>
mw.loader.using('mediawiki.util', function () {
mw.loader.using('mediawiki.util', function () {
if (mw.config.get('wgPageName').startsWith('User:Euphoria/TestVfD/')) {
if (mw.config.get('wgPageName').startsWith('User:Euphoria/TestVfD/')) {
// Add "Close as delete"
mw.util.addPortletLink(
'p-cactions',
'#',
'Close as delete',
'ca-close-delete',
'Close this VfD as delete'
).addEventListener('click', function (e) {
e.preventDefault();
insertClosure('delete');
});


function addClosureButton(label, action) {
// Add "Close as keep"
mw.util.addPortletLink(
mw.util.addPortletLink(
'p-cactions',
'p-cactions',
'#',
'#',
'Close as keep',
label,
'ca-close-keep',
'ca-close-' + action.replace(/\s+/g, '-'),
'Close this VfD as keep'
'Close this VfD as ' + action
).addEventListener('click', function (e) {
).addEventListener('click', function (e) {
e.preventDefault();
e.preventDefault();
insertClosure('keep');
redirectToEdit(action);
});
});
}


// Add "Close as no consensus"
// Add buttons
addClosureButton('Close as delete', 'delete');
mw.util.addPortletLink(
'p-cactions',
addClosureButton('Close as keep', 'keep');
'#',
addClosureButton('Close as no consensus', 'no consensus');
'Close as no consensus',
'ca-close-nc',
'Close this VfD as no consensus'
).addEventListener('click', function (e) {
e.preventDefault();
insertClosure('no consensus');
});


function insertClosure(action) {
function redirectToEdit(action) {
var page = mw.config.get('wgPageName');
var topText = '{{subst:vt|' + action + '. --~~~~}}\n\n';
var topText = '{{subst:vt|' + action + '. --~~~~}}\n\n';
var bottomText = '\n\n{{subst:vb}}';
var bottomText = '\n\n{{subst:vb}}';
var summary = 'Closed as ' + action;


// Access the edit box
// Build edit URL with prefill
var textbox = document.getElementById('wpTextbox1');
var editUrl = mw.util.getUrl(page, {
if (!textbox) {
action: 'edit',
alert('Edit box not found!');
prefill: topText + bottomText,
return;
summary: summary
}
});


// Insert templates at top and bottom
// Redirect to edit page
textbox.value = topText + textbox.value + bottomText;
window.location.href = editUrl;

// Prefill summary
document.getElementById('wpSummary').value = 'Closed as ' + action;
}
}

}
}
});
});

Revision as of 08:10, 25 September 2025

//<nowiki>
mw.loader.using('mediawiki.util', function () {
    if (mw.config.get('wgPageName').startsWith('User:Euphoria/TestVfD/')) {

        function addClosureButton(label, action) {
            mw.util.addPortletLink(
                'p-cactions',
                '#',
                label,
                'ca-close-' + action.replace(/\s+/g, '-'),
                'Close this VfD as ' + action
            ).addEventListener('click', function (e) {
                e.preventDefault();
                redirectToEdit(action);
            });
        }

        // Add buttons
        addClosureButton('Close as delete', 'delete');
        addClosureButton('Close as keep', 'keep');
        addClosureButton('Close as no consensus', 'no consensus');

        function redirectToEdit(action) {
            var page = mw.config.get('wgPageName');
            var topText = '{{subst:vt|' + action + '. --~~~~}}\n\n';
            var bottomText = '\n\n{{subst:vb}}';
            var summary = 'Closed as ' + action;

            // Build edit URL with prefill
            var editUrl = mw.util.getUrl(page, {
                action: 'edit',
                prefill: topText + bottomText,
                summary: summary
            });

            // Redirect to edit page
            window.location.href = editUrl;
        }

    }
});
//</nowiki>