User:Effan R/common.js

importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:AjaxBatchDelete.js',    ] });

/** * Mass Rename * @description Rename pages quickly. * @author Ozuzanna */ mw.loader.using('mediawiki.api', function {    if ( window.MassRenameLoaded || !/sysop|content-moderator|bot|bot-global|staff|helper|wiki-manager|global-discussions-moderator|content-volunteer|content-team-member|soap/.test(mw.config.get('wgUserGroups').join) ) {       return;    }    window.MassRenameLoaded = true;    var i18n,        placement,        renameModal,        preloads = 3,        paused = false;    /**     * @method formHtml     * @description Creates the modal HTML     */    function formHtml  {        return $(' ', { 'class': 'WikiaForm' }).append( $(' ').append(               $(' ', { text: i18n.msg('instructions').plain }),               $(' ', {                    text: i18n.msg('instructions2').plain }),               $(' ', {                    'for': 'redirect-check', text: i18n.msg('redirect').plain }).append( $(' ', {                       type: 'checkbox',                        id: 'redirect-check'                    }) ),               $(' '),                $(' ', {                    'for': 'file-pattern', text: 'File Pattern:' }).append( $(' ', {                       type: 'text',                        name: 'file-pattern',                        id: 'file-pattern'                    }) ),               $(' ', {                    'for': 'exclude-check', text: 'Exclude?:' }).append( $(' ', {                       type: 'checkbox',                        id: 'exclude-check'                    }) ),               $(' '),                $(' ', {                    'for': 'match-regex', text: 'Match Pattern:' }).append( $(' ', {                       type: 'text',                        name: 'match-regex',                        id: 'match-regex'                    }) ),               $(' ', {                    'for': 'replace-string', text: 'Replace With:' }).append( $(' ', {                       type: 'text',                        name: 'replace-string',                        id: 'replace-string'                    }) ),               $(' '),                $(' ', {                    id: 'text-rename', placeholder: 'old_name new_name' }),               $(' ', {                    id: 'text-error-output', text: i18n.msg('outputInitial').plain, append: ' ' })           )        ).prop('outerHTML');    }    /**     * @method preload     * @description Loads the hooks and I18n messages     */    function preload  {        if (--preloads === 0) {            placement = window.dev.placement.loader;            window.dev.i18n.loadMessages('MassRename').then(init);        }    }    /**     * @method init     * @description Initiates the script     * @param {String} i18nData - Variable for I18n-js     */    function init (i18nData) {        i18n = i18nData;        placement.script('MassRename');        $(placement.element('tools'))[placement.type('prepend')]( $('').append(               $('', { id: 't-mr', text: i18n.msg('title').plain, click: click })           )        );    }    /**     * @method click     * @description Opens the MassRename modal     */    function click  {        if (renameModal) {            renameModal.show;            return;        }        renameModal = new window.dev.modal.Modal({ content: formHtml, id: 'form-mass-rename', size: 'medium', title: i18n.msg('title').escape, buttons: [ {                   id: 'mr1-start', text: i18n.msg('initiate').escape, primary: true, event: 'start' },               {                    id: 'mr1-pause', text: i18n.msg('pause').escape, primary: true, event: 'pause', disabled: true },               {                    text: 'Add Category', primary: true, event: 'addCategoryContents' },               {                    text: i18n.msg('close').escape, event: 'close' }           ],            events: { addCategoryContents: addCategoryContents, pause: pause, start: start }       });        renameModal.create;        renameModal.show;    }    /**     * @method pause     * @description Pauses the operation     */    function pause  {        paused = true;        document.getElementById('mr1-pause').setAttribute('disabled', );        document.getElementById('mr1-start').removeAttribute('disabled');    }    /**     * @method start     * @description Starts the operation     */    function start  {        paused = false;        document.getElementById('mr1-start').setAttribute('disabled', );        document.getElementById('mr1-pause').removeAttribute('disabled');        process;    }    /**     * @method process     * @description Analyzes the inputted data     */    function process  {        if (paused) {            return;        }        var txt = document.getElementById('text-rename'),            pages = txt.value.split('\n'), page = pages[0]; if (!page) { $('#text-error-output').append(               i18n.msg('finished').escape +                ' ' +                i18n.msg('nothingLeftToDo').escape +                ' '            ); pause; } else { rename(page); }       pages = pages.slice(1, pages.length); txt.value = pages.join('\n'); }   /**     * @method addCategoryContents * @description Adds all members of a category */   function addCategoryContents { var category = prompt('Enter Category' + ':'); if (!category) { return; }       new mw.Api.get({            action: 'query',            list: 'categorymembers',            cmtitle: 'Category:' + category,            cmlimit: 5000        }).done(function(d) {            if (!d.error) {                var data = d.query;                for (var i in data.categorymembers) {                    var Incl = true;                    if (document.getElementById('file-pattern').value) {                        var rgx = new RegExp(document.getElementById('file-pattern').value);                        if (document.getElementById('exclude-check').checked) {                            if (rgx.test(data.categorymembers[i].title)) {                                Incl = false;                            }                        }                        else {                            if (!rgx.test(data.categorymembers[i].title)) {                                Incl = false; }                       }                    }                    if (Incl) { $('#text-rename').append(data.categorymembers[i].title.replace(/ /g, "_") + '\n'); }               }            } else { $('#text-error-output').append(i18n.msg('invalidInput', category).escape + ' '); }       }).fail(function { $('#text-error-output').append(i18n.msg('invalidInput', category).escape + ' '); });   }    /**     * @method rename     * @description Renames the page     * @param {String} name - The rename data     */    function rename (name) {        if (name.split(' ').length !== 2) {            $('#text-error-output').append(i18n.msg('invalidInput', name).escape + ' ');        } else {            var oldName = name.split(' ')[0],                newName = name.split(' ')[1],                config = {                    action: 'move',                    from: oldName.replace('_', ' '),                    to: newName.replace('_', ' '),                    noredirect: '',                    reason:                        window.massRenameSummary ||                        i18n.inContentLang.msg('summary').plain,                    bot: true,                    token: mw.user.tokens.get('editToken')                };            if (document.getElementById('redirect-check').checked) { delete config.noredirect; } /*           new mw.Api.post(config) .done(function (d) {               if (!d.error) {                    console.log(i18n.msg('renameDone', oldName, newName).plain);                } else {                    console.log(i18n.msg('renameFail', oldName, newName).escape + ': ' + d.error.code);                    $('#text-error-output').append(i18n.msg('renameFail', oldName, newName).escape + ': ' + d.error.code + ' ');                }            }) .fail(function {                console.log(i18n.msg('renameFail2', oldName, newName).plain);                $('#text-error-output').append(i18n.msg('renameFail2', oldName, newName).escape + ' ');            }); }       setTimeout(process, window.massRenameDelay || 1000); }   mw.hook('dev.i18n').add(preload); mw.hook('dev.modal').add(preload); mw.hook('dev.placement').add(preload); importArticles(       {            type: 'script',            articles: [                'u:dev:MediaWiki:I18n-js/code.js',                'u:dev:MediaWiki:Modal.js',                'u:dev:MediaWiki:Placement.js'            ]        },        {            type: 'style',            articles: ['u:dev:MediaWiki:MassRename.css']        }    ); });

/**/ /*window.HashAnchorInTabView = { AutoSelectTabs: false, };*/

/** * Ajax Delete Archived * @description Delete previous/archived versions of * listed multiple pages * Does not need to go to Special:BlankPage to use * Includes the option to grab a whole category's contents * Modified from AjaxBatchDelete by Ozank Cx * @author Effan R */

mw.loader.using('mediawiki.api', function {   'use strict';    if ( window.AjaxDeleteArchivedLoaded || !/sysop|vstf|staff|helper|wiki-manager|content-team-member|content-volunteer|content-moderator/.test(mw.config.get('wgUserGroups').join) ) {       return;    }    window.AjaxDeleteArchivedLoaded = true;    var api = new mw.Api,        i18n,        placement,        preloads = 3,        deleteModal,        paused = true;

function preload { if (--preloads === 0) { placement = window.dev.placement.loader; window.dev.i18n.loadMessages('AjaxBatchDelete').then(init); }   }    function init(i18nData) { i18n = i18nData; placement.script('AjaxDeleteArchived'); $(placement.element('tools'))[placement.type('prepend')](           $('').append( $('', {                   id: 't-bd',                    text: 'Delete Archived', //i18n.msg('toolsTitle').plain,                    click: click                }) )       );    }    function click { if (deleteModal) { deleteModal.show; return; }       deleteModal = new window.dev.modal.Modal({            content: formHtml,            id: 'form-batch-delete',            size: 'medium',            title: 'Delete Archived Versions', //i18n.msg('modalTitle').escape,            buttons: [                {                    id: 'abd-start',                    text: i18n.msg('initiate').escape,                    primary: true,                    event: 'start'                },                {                    id: 'abd-pause',                    text: i18n.msg('pause').escape,                    primary: true,                    event: 'pause',                    disabled: true                },                {                    text: i18n.msg('addCategoryContents').escape,                    primary: true,                    event: 'addCategoryContents'                },                {                    text: i18n.msg('close').escape, event: 'close' }           ],            events: { addCategoryContents: addCategoryContents, pause: pause, start: start }       });        deleteModal.create;        deleteModal.show;    }    function formHtml {        return $(' ', { 'class': 'WikiaForm' }).append( $(' ').append(               $(' ').append( $(' ', {                       'for': 'delete-reason',                        text: i18n.msg('inputReason').plain                    }), $(' ', {                       type: 'text',                        name: 'delete-reason',                        id: 'delete-reason'                    }), $(' '),                   $(' ', {                        'for': 'archived-check',                        text: 'Only Delete Archived Versions'//i18n.msg('onlyArchived').plain                    }), $(' ', {                       type: 'checkbox',                        id: 'archived-check',                        name: 'archived-check'                    }) ),               $(' ', {                    text: i18n.msg('inputPages').plain + ':' }),               $(' ', {                    id: 'text-mass-delete' }),               $(' ', {                    text: i18n.msg('errorsForm').plain + ':' }),               $(' ', {                    id: 'text-error-output' })           )        ).prop('outerHTML');    }    function pause {        paused = true;        document.getElementById('abd-pause').setAttribute('disabled', );        document.getElementById('abd-start').removeAttribute('disabled');    }    function start {        if (!document.getElementById('delete-reason').value) {            alert(i18n.msg('stateReason').plain);            return;        }        paused = false;        document.getElementById('abd-start').setAttribute('disabled', );        document.getElementById('abd-pause').removeAttribute('disabled');        process;    }    function process {        if (paused) {            return;        }        var txt = document.getElementById('text-mass-delete'),            pages = txt.value.split('\n'),            pageName = pages[0];        if (!pageName) {            $('#text-error-output').append( i18n.msg('endTitle').escape + ' ' + i18n.msg('endMsg').escape + ' '           );            pause;        } else {            var currentPage =                     /^([^\|]+)\|(\d{14}!.+)$/.exec(pageName)                    || [];            if (currentPage[1]) {                performAction(currentPage[1], currentPage[2], document.getElementById('delete-reason').value);           }        }        pages = pages.slice(1,pages.length);        txt.value = pages.join('\n');    }

function addArchived(page) { api.get({           action: 'query',            titles: page,            prop: 'imageinfo',            iiprop: 'archivename',            iilimit: 50,        }).done(function(d) {            if (!d.error) {                var data = d.query;                for (var i in data.pages) {                    for (var j in data.pages[i].imageinfo) {                        if (data.pages[i].imageinfo[j].archivename) {                            $('#text-mass-delete').append(data.pages[i].title + "|"                            + data.pages[i].imageinfo[j].archivename + '\n');                       }                    }                }            } else {                outputError('GetContents', page, d.error.code);            }        }).fail(function {            outputError('GetContents', page, i18n.msg('ajaxError').plain);        }); }   function addCategoryContents { var category = prompt(i18n.msg('enterCategory').plain + ':'); if (!category) { return; }       api.get({            action: 'query',            list: 'categorymembers',            cmtitle: 'Category:' + category,            cmlimit: 5000        }).done(function(d) {            if (!d.error) {                var data = d.query;                for (var i in data.categorymembers) {                    addArchived(data.categorymembers[i].title); //                    $('#text-mass-delete').append(data.categorymembers[i].title + '\n');                }            } else {                outputError('GetContents', category, d.error.code);            }        }).fail(function {            outputError('GetContents', category, i18n.msg('ajaxError').plain);        }); }

function outputError(error, param1, param2) { $('#text-error-output').append(i18n.msg('error' + error, param1, param2).escape, ' '); }   function performAction(page, archived, reason) { var token = mw.user.tokens.get('editToken'); api.post({           action: 'delete',            watchlist: 'preferences',            title: page,            reason: reason,            oldimage: archived,            token: token,            bot: true        }).done(function(d) {            if (!d.error) {                console.log(i18n.msg('deleteSuccess',                                        page + "|" + archived).plain); /*                if (document.getElementById('protect-check').checked) {                    api.post({ action: 'protect', expiry: 'infinite', protections: 'create=sysop', watchlist: 'preferences', title: page, reason: reason, token: token }).done(function(d) { if (!d.error) { console.log(i18n.msg('protectSuccess', page).plain); } else { console.log(i18n.msg('errorProtect', page, d.error.code).plain); outputError('Protect', page, d.error.code); }                   }).fail(function { console.log(i18n.msg('errorProtect', page, i18n.ajaxError).plain); outputError('Protect', page, i18n.msg('ajaxError').plain); });               }*/            } else {                console.log(i18n.msg('errorDelete', page, d.error.code).plain);                outputError('Delete', page, d.error.code);            }        }).fail(function {            console.log(i18n.msg('errorDelete', page, i18n.msg('ajaxError').plain).plain);            outputError('Delete', page, i18n.msg('ajaxError').plain);        }); setTimeout(process, window.batchDeleteDelay || 1000); }   mw.hook('dev.i18n').add(preload); mw.hook('dev.modal').add(preload); mw.hook('dev.placement').add(preload); importArticles(       {            type: 'script',            articles: [                'u:dev:MediaWiki:I18n-js/code.js',                'u:dev:MediaWiki:Modal.js',                'u:dev:MediaWiki:Placement.js'            ]        },        {            type: 'style',            articles: ['u:dev:MediaWiki:AjaxBatchDelete.css']        }    ); });