MediaWiki:NotabilityMove/draft.js

// Please do not submit this version for review.

/*
 * NotabilityMove v2.0 (indev)
 * @description Allows for quick moving of pages deemed non-notable.
 * @authors "The JoTS", "Ozuzanna"
 * Based off of
 * w:c:dev:AjaxRedirect by Ozuzanna
 * w:c:dev:AjaxRedirect by Ozuzanna

var ug = mw.config.get("wgUserGroups").join(' '); var sysop = ug.indexOf('sysop') + 1, cmod = ug.indexOf('content-moderator') + 1;

//var actions = mw.config.get("wgWikiaPageActions"), //   hotkeys = mw.config.get("wgWikiaShortcutKeys");

var modalContents = " Target editor " // Select namespace + " Namespace " + " User " + " User blog " // Select reason + " Reason " + " NCU " + " Not relevant in content namespaces. " + " Other reason: " + " " // Protection options + " Protection " + " Original page: create=sysop (1 hour) " + " New page: move=sysop (1 week) " // Check player (through article name) if notability guidelines are met + " "   + "( Check player ) ";

if (sysop + cmod) {

;(function($, mw) {       if ($('#ca-ncu').length // already exists || mw.config.get('wgCanonicalNamespace') === "Thread" || mw.config.get('wgCanonicalNamespace') === "File" || mw.config.get('wgCanonicalNamespace') === "MediaWiki" || mw.config.get('wgCanonicalSpecialPageName')) return;       // insert buttons        if (({"oasis": 1, "wikia": 1})[mw.config.get('skin')] === 1) {            $('#WikiaPageHeader > .wikia-menu-button > .WikiaMenuElement > li:last-child').after( $('<li/>').append('NCU move</a>'));       } else if (mw.config.get('wgNamespaceNumber') !== -1 && mw.config.get('wgAction') === 'view') {            $('#p-cactions > .pBody > ul > li:last-child').after( $('<li/>').append('NCU move</a>'));       }        function respHandler (res, type) {            if (res === true) {                console.log(type + ' successful!');                new BannerNotification(type + ' succesful!','confirm').show;                if (type === "Protect")                    setTimeout((function { window.location.reload; }), 3000);            } else {                console.log('Failiure: ' + type);                new BannerNotification('Failiure: ' + type,'error').show;            }        }        // Declare vars        var api,token;        var oldPageName,basePageName;        var newPageName;        var modal;        $('#ca-ncu').click(launchModal);        function launchModal {            // Initialize vars            token = mw.user.tokens.get('editToken');            oldPageName = mw.config.get('wgPageName'); basePageName = /^(?:[A-Za-z]*:)?(.+)/.exec(oldPageName)[1]; // removes namespace newPageName = 'User:' + targUser + '/' + basePageName; api = new mw.Api; // Modal modal = $.showCustomModal("Notability move", modalContents.replace("$PLAYER", oldPageName),           {                id: "NotabilityMoveModal",                buttons: [{                    id: "ncu-exe",                    defaultButton: true,                    message: "Move",                    handler: function {                        idunno;                        $('#NotabilityMoveModal').closeModal;                    }                }]            }); }       function idunno { // WIP BELOW if (!targUser) { console.log('You need to specify the target user!'); return; }           // Confirm move if (!confirm('"'               + oldPageName.replace(/_/g, ' ') + '" will be moved to\n"'                + newPageName.replace(/_/g, ' ') + '".')) return; // Move page api.post({             action: 'move',              from: oldPageName,              to:   newPageName,              noredirect: '',              reason: 'Does not meet notability policy.',              token: token            }).done(function(d) {                respHandler(!d.error, "Move"); // move succesful                // Temporarily protect page                api.post({ format: 'json', action: 'protect', expiry: '1 hour', protections: 'create=sysop', watchlist: 'nochange', title: oldPageName, reason: 'Automatically protected page when moving to user space.', token: token })               .done(function(d) { respHandler(!d.error, "Protect"); })                .fail(function  { resphandler(false,    "Protect"); });            }).fail(function {              respHandler(false, "Move");            }); }   })(this.jQuery, this.mediaWiki); }