Jump to content

User:Sohom Datta/PageTriageUserspaceLogger.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Sohom Datta (talk | contribs) at 19:38, 6 November 2023. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/***
 * Untested, do not install
 */
 
const standardError = 'If you are seeing this on enwiki, something is very wrong, ping {{ping|Sohom Datta}} or interface administators.';

function convertTagsToTwinkleFormat( tag ) {
    const { params } = tag;
    const keys = Object.keys(params);
    let templateParams = {};
    for( var i = 0; i < keys.length; i++ ) {
        templateParams[keys[i]] = params[keys[i]].value;
    }
    return { normalized: tag[ 'code' ].toLowerCase(), templateParams };
} 

mw.loader.using( [ 'ext.gadget.Twinkle' ] ).then( function () {
    if ( !Twinkle ) {
        mw.notify( 'User:Sohom_Datta/PageTriageCSDLog.js requires twinkle to be installed on your wiki.' + standardError );
    }

    if ( !Twinkle.speedy ) {
        mw.notify( 'User:Sohom_Datta/PageTriageCSDLog.js requires the twinkle speedy deletion module to function correctly' + standardError );
    }
    mw.hook( 'ext.pageTriage.toolbar.ready' ).add( function ( queue ) {
        queue.add( 'delete', function ( data ) {
            const { tags } = data;
            const keys = Object.keys(tags);
            let twinkleParams = { normalizeds: [], templateParams: [], values: [] };
            for ( var i = 0; i < keys.length; i++ ) {
                const tag = tags[ keys[ i ] ];
                if ( !tag.tag.startWith( 'speedy deletion' ) ) {
                    continue;
                }
                const { normalizedTag, templateParams } = convertTagsToTwinkleFormat( tag );
                twinkleParams.normalizeds.append( normalizedTag );
                twinkleParams.templateParams.append( templateParams );
                twinkleParams.values.append( tag.tag );
            }
            Twinkle.speedy.addToLog( twinkleParams, data.creator );
        } );
    } );
} );