MediaWiki:NewsTools.js

/** * @Name           NewsTools * @Version        v1.1 * @Author         TheGoldenPatrik1 * @Protect * @Description    Adds a variety of tools for News Team writers */ (function {   /**     * Get config     * Only load once     * Restrict to certain usergroups, namespaces, and pages     */    var config = mw.config.get([ 'wgUserGroups', 'wgTitle', 'wgNamespaceNumber', 'wgPageName' ]);   if ( window.NewsToolsLoaded || !/sysop|content-moderator/.test(config.wgUserGroups.join) || config.wgNamespaceNumber !== 4 || ['NT/Changelog News', 'NT/Wiki Event News', 'NT/Wiki Policy News', 'NT/Tech News', 'NT/Fandom News', 'NT/Opinion Polls'].indexOf(config.wgTitle) === -1 ) {       return;    }    window.NewsToolsLoaded = true;    /**     * Custom edit buttons     */    if (config.wgPageName === 'Rings_of_the_Master_Wikia:NT/Opinion_Polls')    {        /**         * Opinion Polls buttons         */        if (mwCustomEditButtons) {            mwCustomEditButtons[mwCustomEditButtons.length] = {                'imageFile': ,                'speedTip': 'OPS',                'tagOpen': ,                'sampleText' : ' '            };            mwCustomEditButtons[mwCustomEditButtons.length] = {                'imageFile': ,                'speedTip': 'Poll',                'tagOpen': ' \n',                'tagClose': '\n '            };        }    } else {        /**         * Other buttons         */        if (mwCustomEditButtons) {            mwCustomEditButtons[mwCustomEditButtons.length] = {                'imageFile': ,                'speedTip': 'Code', 'tagOpen': ' ' };           mwCustomEditButtons[mwCustomEditButtons.length] = { 'imageFile': '', 'speedTip': 'Nowiki', 'tagOpen': ' ', 'tagClose': ' '// };           mwCustomEditButtons[mwCustomEditButtons.length] = { 'imageFile': '', 'speedTip': 'Strong', 'tagOpen': ' ', 'tagClose': ' ' };       }    }    /**     * Clear button * Changes text based on pagename */   var text = { 'Rings_of_the_Master_Wikia:NT/Changelog_News': '\n \n|-|Changelog News=\n\n\n\n \n\n\n\n', 'Rings_of_the_Master_Wikia:NT/Wiki_Event_News': '\n \n|-|Event News=\n\n\n\n \n\n\n\n', 'Rings_of_the_Master_Wikia:NT/Wiki_Policy_News': '\n \n|-|Policy News=\n\n\n\n \n\n\n\n', 'Rings_of_the_Master_Wikia:NT/Tech_News': '\n \n|-|Tech News=\n\n\n\n \n\n\n\n', 'Rings_of_the_Master_Wikia:NT/Fandom_News': '\n \n|-|FANDOM News=\n\n\n\n \n\n\n\n', 'Rings_of_the_Master_Wikia:NT/Opinion_Polls': '\n \n|-|Opinion Polls=\n\n\n\n \n\n\n\n' }[config.wgPageName]; $('.page-header__contribution-buttons .wds-list').append(       $('').append( $('', {               href: '#',                id: 'ca-clear',                text: 'Clear',                click: click            }) )   );        function click { $.ajax({               type: 'POST',                url: mw.util.wikiScript('api'),                dataType: 'json',                data: {                    action: 'edit',                    title: config.wgPageName,                    summary: 'Clearing',                    text: text,                    format: 'json',                    token: mw.user.tokens.get('editToken')                }            }).done(function(data) {                if (data.edit.result === 'Success') {                    new BannerNotification('Page cleared!', 'confirm').show;                    window.location.reload;                } else {                    new BannerNotification('An error occurred.', 'error').show;                }            }).fail(function(data) {                new BannerNotification('An error occurred.', 'error').show;            }); }   }) ;