User:Dominic1743/global.js

/** * MassEdit/code.js * @file Adds/deletes/replaces content from pages/categories/namespaces * @author Eizen  * @external "mediawiki.util" * @external "jQuery" * @external "wikia.ui.factory" * @external "wikia.window" * @external "I18n-js" * @external "mw" */

/*jslint browser, this:true */ /*global mw, jQuery, window, require, wk, ui */

require(["jquery", "mw", "wikia.window", "wikia.ui.factory"],       function (jQuery, mw, wk, ui) {    "use strict";

if (jQuery("#massEdit-li").exists || window.isMassEditLoaded) { return; }   window.isMassEditLoaded = true;

// Constant for future testing const DEBUG = false;

//I18n-js var $i18n;

/**    * @class MassEdit * @classdesc The central MassEdit class */   var MassEdit = { meta: { author: "User:Eizen", created: "05/02/17", lastEdit: "03/09/18", version: "2.4.4" },       legalChars: new RegExp("^[" + wk.wgLegalTitleChars + "]*$"),

/**        * @method addLogEntry * @description Method allows for quick adding of a MassEdit log entry *             to the appropriate text field. * @param {String} $key - The name of the JSON field * @returns {void} */       addLogEntry: function ($key) { jQuery("#massEdit-log").prepend($i18n.msg($key).escape + " "); },

/**        * @method addLogEntry * @description "Overloaded" two-parameter variation of the method above *             that accepts a JSON key and an entry substitute for $1 *             or $2. * @param {String} $key - The name of the JSON field * @param {String} $entry - Name of the page to substitute * @returns {void} */       addLogEntry: function ($key, $entry) { jQuery("#massEdit-log").prepend(               $i18n.msg($key, $entry).escape + " "); },

/**        * @method constructItem * @description Method returns a completed *             representing the menu link item. Is comprised of a        *              link inside a list item. * @param {String} $text - Text to be displayed in the item and title * @returns {String} */       constructItem: function ($text) { return mw.html.element("li", {               "class": "overflow",                "id": "massEdit-li"            }, new mw.html.Raw( mw.html.element("a", {                   "id": "massEdit-a",                    "href": "#",                    "title": $text                }, $text) ));       },

/**        * @method isLegalPage * @description Utility function used to test if inputted page name *             matches the legal characters regex. Returns a boolean *             flag depending on result. * @param {String} $page - Inputted page name * @returns {boolean} */       isLegalPage: function ($page) { if (!this.legalChars.test($page)) { jQuery("#massEdit-modal-form")[0].reset; this.addLogEntry("modalSecurity"); return false; } else { return true; }       },

/**        * @method displayModal * @description Method constructs and displays the main user interface. *             Injects custom CSS prior to construction and handles all *             button click events. * @param {String} $modalHTML - The modal HTML layout * @returns {void} */       displayModal: function ($modalHTML) { var that = this;

mw.util.addCSS(               ".massEdit-menu," +                ".massEdit-textbox {" +                    "width: 100%;" +                    "padding: 0;" +                "}" +                ".massEdit-textarea {" +                    "height: 50px;" +                    "width: 100%;" +                    "padding: 0;" +                    "overflow: auto;" +                "}" +                "#massEdit-log {" +                    "height: 55px;" +                    "width: 100%;" +                    "border: 1px solid;" +                    "font-family: monospace;" +                    "background: #fff;" +                    "color: #aeaeae;" +                    "overflow: auto;" +                    "padding:0;" +                "}"            );

ui.init(["modal"]).then(function (modal) {               var config = {                    vars: {                        id: "massEdit-modal",                        size: "medium",                        title: $i18n.msg("itemTitle").escape,                        content: $modalHTML,                        buttons: [{                            vars: {                                value: $i18n.msg("buttonCancel").escape,                                classes: ["normal", "primary"],                                data: [{                                    key: "event",                                    value: "cancel"                                }]                            }                        }, {                            vars: {                                value: $i18n.msg("buttonClear").escape,                                classes: ["normal", "primary"], data: [{ key: "event", value: "clear" }]                           }                        }, {                            vars: { value: $i18n.msg("buttonSubmit").escape, classes: ["normal", "primary"], data: [{ key: "event", value: "submit" }]                           }                        }]                    }                };

modal.createComponent(config, function (massEditModal) {                   massEditModal.bind("cancel", function  { massEditModal.trigger("close"); });

massEditModal.bind("clear", function {                        jQuery("#massEdit-modal-form")[0].reset;                    });

massEditModal.bind("submit", function {                        that.main;                    });

massEditModal.show; });           });

// Disable replacements menu depending on current selected option jQuery(document).on("change", "#massEdit-actionType", function {                if (jQuery("#massEdit-actionType").val === "replace") {                    jQuery("#massEdit-replaceThis-value")                        .prop("disabled", false);                } else {                    jQuery("#massEdit-replaceThis-value")                        .prop("disabled", true);                }            }); },

/**        * @method getContent * @description This method retrieves the content of the inputted page, *             including information about its time of creation and *             relevant timestamp info. Used exclusively by the find *             and dropdown option. * @param {String} $action - Editing action (prepend, append, replace) * @param {String} $editSummary - Edit summary * @param {String} $page - The page in question * @param {String} $newContent - New text to replace the target * @param {String} $replace - The target to be replaced in the callback * @param {function} callback - The callback handler */       getContent: function ($action, $editSummary, $page, $newContent,                $replace, callback) {

var that = this; this.api.get({               action: "query",                prop: "info|revisions",                intoken: "edit",                titles: $page,                rvprop: "content|timestamp",                rvlimit: "1",                indexpageids: "true",                format : "json"            }).done(function ($data) {                if (!$data.error) {                    callback(           // handleContent that,          // this $action,       // "replace" $editSummary,  // "#massEdit-summary-value" $data,         // $data $page,         // $pagesArray[$counter] $newContent,   // "#massEdit-content-value" $replace       // "#massEdit-replaceThis-value" );               }            });        },

/**        * @method handleContent * @description Callback function for. Sifts *             through included data and passes relevant bits to the *               method. Used exclusively by the *             find and replace dropdown option. * @param {this} that - Scope variable * @param {String} $action - Editing action (prepend, append, replace) * @param {String} $editSummary - Edit summary * @param {JSON} $data - Passed data from * @param {String} $page - Specific page in question * @param {String} $newContent - New text to replace the target * @param {String} $replaceThis - Text to be replaced by $newContent * @returns {void} */       handleContent: function (that, $action, $editSummary, $data, $page,                $newContent, $replaceThis) {

// Check if page actually exists if (Object.keys($data.query.pages)[0] === "-1") { jQuery("#massEdit-modal-form")[0].reset; that.addLogEntry("noSuchPage", $page); return; }

var $newText; var $result = $data.query.pages[Object.keys($data.query.pages)[0]]; var $text = $result.revisions[0]["*"]; var $timestamp = $result.revisions[0].timestamp; var $starttimestamp = $result.starttimestamp; var $token = $result.edittoken;

// Replace all instances of chosen text with inputted new text $newText = $text.split($replaceThis).join($newContent);

// Check if old & new revisions are identical in content if ($newText === $text) { jQuery("#massEdit-log").prepend(                   $i18n.msg("noMatch", $replaceThis, $page).escape +                    " "                ); } else { that.editPage(that, $page, $newText, $action, $editSummary,                   $timestamp, $starttimestamp, $token); }       },

/**        * @method editPage * @description The one-size-fits-all editing handler for use by all *             three main MassEdit functions. Takes several different *             numbers of input parameters depending on the action to         *              be taken by the handler. * @param {this} that - Scope variable * @param {String} $page - The page to be edited * @param {String} $content - The content to be added to the page * @param {String} $action - Editing action (prepend, append, replace) * @param {String} $editSummary - Edit summary * @param {String} $timestamp - Optional, for replace option only * @param {String} $starttimestamp - Optional, for replace option only * @param {String} $token - Optional, for replace option only * @returns {void} */       editPage: function (that, $page, $content, $action, $editSummary,                $timestamp, $starttimestamp, $token) {

// Edit without editing; for testing purposes if (DEBUG) { that.addLogEntry("editSuccess", $page); return; }

// Default base properties var $params = { action: "edit", minor: true, bot: true, title: $page, summary: $editSummary };

// Set additional Object properties depending on action to be taken switch ($action) { case "prepend": $params.prependtext = $content; $params.token = mw.user.tokens.get("editToken"); break; case "append": $params.appendtext = $content; $params.token = mw.user.tokens.get("editToken"); break; case "replace": $params.text = $content; $params.basetimestamp = $timestamp; $params.startimestamp = $starttimestamp; $params.token = $token; break; }

that.api.post($params).done(function ($data) {               jQuery("#massEdit-modal-form")[0].reset;                if (!$data.error) {                    that.addLogEntry("editSuccess", $page);                } else {                    that.addLogEntry("editFailure", $page);                }            }); },

/**        * @method getNamespaceMembers * @description As the name implies, this method returns the results of        *              a request for an inputted namespace's associated page *             contents. * @param {String} $namespace - Number of the namespace in question * @return {JSON} */       getNamespaceMembers: function ($namespace) { return jQuery.ajax({               type: "GET",                url: mw.util.wikiScript("api"),                data: {                    action: "query",                    list: "allpages",                    aplimit: "max",                    apnamespace: $namespace,                    format: "json"                }            }); },

/**        * @method getCategoryMembers * @description As the name implies, this method returns the results of        *              a request for an inputted category's associated page *             contents. * @param {String} $category - Name of the category in question * @return {JSON} */       getCategoryMembers: function ($category) { return jQuery.ajax({               type: "GET",                url: mw.util.wikiScript("api"),                data: {                    action: "query",                    list: "categorymembers",                    cmtitle: $category,                    cmprop: "title",                    cmdir: "desc",                    cmlimit: "max",                    format: "json"                }            }); },

/**        * @method membersHandler * @description This method, inspired by Java-style reflection, is a        *              general purpose handler for use by both namespace and *             category bulk editing. The method accepts either the *             getCategoryMembers or         *              getNamespaceMembers methods as the requests of         *              choice, running basically the same process with the *             results of each once all calls have been completed. *

*

*             Basically, once the calls have been made, the method *             assembles all the pages from the request results and *             pushes them into an array for processing by the *             actionHandler method. * @param {String[]} $inputArray * @param {String} $newContent * @param {String} $toReplace * @param {int} $actionIndex * @param {String} $action * @param {String} $editSummary * @param {function} getMembers * @param {String} $queryProperty * @returns {void} */       membersHandler: function ($inputArray, $newContent, $toReplace,                $actionIndex, $action, $editSummary, getMembers,                $queryProperty) {

var that = this; var $members; var $requests; var $arguments; var $defer; var $data;

$members = []; $requests = []; $arguments = [];

$inputArray.forEach(function ($member) {               if ( $queryProperty === "categorymembers" && !$member.startsWith("Category:") ) {                   $member = "Category:" + $member;                }

if (                   ( // If is category-based and member is legal $queryProperty === "categorymembers" && that.isLegalPage($member) ) ||                   ( // If is namespace-based and member is integer $queryProperty === "allpages" && $member.match(/^[0-9]+$/) !== null )               ) {                    $members.push($member); $requests.push(getMembers($member)); }           });

if (               !$members.length ||                !$requests.length ||                $members.length !== $requests.length            ) { return; }

$inputArray = []; $defer = jQuery.when.apply(jQuery, $requests);

$defer.done(function {                if ($requests.length === 1) {                    $arguments.push(arguments);                } else {                    $arguments = Array.prototype.slice.call(arguments);                }

jQuery.each($arguments, function ($index, $results) {                   if ($results[1] === "success") {                        $data = $results[0].query[$queryProperty];

if ($data === undefined || $data.length === 0) { that.addLogEntry("noSuchPage", $members[$index]); return; }

$data.forEach(function ($page) {                           $inputArray.push($page.title);                        }); }               });

if ($inputArray.length) { that.actionHandler($inputArray, $newContent, $toReplace,                       $actionIndex, $action, $editSummary); }           });        },

/**        * @method actionHandler * @description This function invokes methods based on user's desired *             action. If the user is not in the proper user rights *             group, access is denied. If no action is selected, the *             user is prompted to select an action. *             setInterval is employed to ensure that the *             script does not make too many consecutive content GETs *             or edit POSTs; replaces forEach *             implementation. *

*

*             Addition of global pages-based find-and-replace option *             replaces old find-and-delete option, and now checks for *             cases of empty pages or empty target text. * @param {String[]} $inputArray * @param {String} $newContent * @param {String} $toReplace * @param {int} $actionIndex * @param {String} $action * @param {String} $editSummary * @returns {void} */       actionHandler: function ($inputArray, $newContent, $toReplace,                $actionIndex, $action, $editSummary) {

var that = this; var $counter = 0; var $editInterval;

switch ($actionIndex) { case 0: // No action selected this.addLogEntry("noOptionSelected"); break; case 1: case 2: // Edit methods (prepend and append) this.addLogEntry("loading");

$editInterval = setInterval(function {                    if (that.isLegalPage($inputArray[$counter])) {                        that.editPage(that, $inputArray[$counter], $newContent, $action, $editSummary);                   }                    $counter++;                    if ($counter === $inputArray.length) {                        clearInterval($editInterval);                    }                }, that.config.editInterval); break; case 3: // Find and replace this.addLogEntry("loading");

$editInterval = setInterval(function {                    if (that.isLegalPage($inputArray[$counter])) {                        that.getContent($action, $editSummary, $inputArray[$counter], $newContent, $toReplace, that.handleContent);                   }

$counter++; if ($counter === $inputArray.length) { clearInterval($editInterval); }               }, that.config.editInterval);                break;            }        },

/**        * @method main * @description The main method handles the collection of user input *             from the GUI modal and tests against a series of base *             cases to ensure ill-formed or illegitimate input is not *             included in the program's operations. Furthermore, the *             new category-based function necessitated the removal of         *              some old code used to execute different actions (i.e.         *              prepend, append, etc.) to a different method, namely *             actionHandler. The main method now handles the *             acquisition of category members from user input cats, *             passing the array of pages to the handler above. *

*

*             Addition of global pages-based find-and-replace option *             replaces old find-and-delete option, and now checks for *             cases of empty pages or empty target text. * @returns {void} */       main: function  { var that = this;

// Values of textareas var $newContent = jQuery("#massEdit-content-value")[0].value; var $toReplace = jQuery("#massEdit-replaceThis-value")[0].value; var $pagesInput = jQuery("#massEdit-pages-value")[0].value; var $editSummary = jQuery("#massEdit-summary-value")[0].value; var $pagesArray = $pagesInput.split(/[\n]+/);

// Dropdown menu var $actionIndex = jQuery("#massEdit-actionType")[0].selectedIndex; var $action = jQuery("#massEdit-actionType").val; var $typeIndex = jQuery("#massEdit-contentType")[0].selectedIndex;

// Is not in the proper rights group if (!this.hasRights) { jQuery("#massEdit-modal-form")[0].reset; this.addLogEntry("modalUserRights"); return;

// No pages included } else if (!$pagesInput) { this.addLogEntry("noPages"); return;

// Is either append/prepend with no content input included } else if ($action !== "replace" && !$newContent) { this.addLogEntry("noContent"); return;

// Is find-and-replace with no target content included } else if ($action === "replace" && !$toReplace) { this.addLogEntry("noTarget"); return;

// If user forgot to select dropdown options (no reset b/c annoying) } else if ($actionIndex === 0 || $typeIndex === 0) { this.addLogEntry("noOptionSelected"); return;

// If edit summary is greater than permitted max of 800 characters } else if ($editSummary.length > 800) { this.addLogEntry("overlongSummary"); return; }

switch ($typeIndex) { case 1: // Loose pages that.actionHandler($pagesArray, $newContent, $toReplace,                   $actionIndex, $action, $editSummary); break; case 2: // Categories that.membersHandler($pagesArray, $newContent, $toReplace,                   $actionIndex, $action, $editSummary,                    that.getCategoryMembers, "categorymembers"); break; case 3: // Namespaces that.membersHandler($pagesArray, $newContent, $toReplace,                   $actionIndex, $action, $editSummary,                    that.getNamespaceMembers, "allpages"); break; }       },

/**        * @method init * @description Method initializes the program, assembling the toolbar *             link and handling click events. Config options are set *             per user input or the defaults. * @param {JSON} $lang - I18n-js content * @returns {void} */       init: function ($lang) { var that = this;

$i18n = $lang; $i18n.useContentLang;

this.api = new mw.Api; this.config = jQuery.extend({               editInterval: 1500            }, window.massEditConfig);

$i18n.useUserLang;

/**            * Handle removal of   right for bots/users * Current rate limit for default user/Users/etc. is 40 edits/minute * Current rate limit for bot (not bot-global) is 80 edits/minute * @see SUS-4775 * @see VariablesBase.php</a> */           if (                jQuery.inArray("bot", wk.wgUserGroups) !== -1 &&                this.config.editInterval < 750            ) { this.config.editInterval = 750; // Reset to max 80 edits/minute } else if (               jQuery.inArray("user", wk.wgUserGroups) !== -1 &&                this.config.editInterval < 1500            ) { this.config.editInterval = 1500; // Reset to max 40 edits/minute }

var $modalHTML = "<form id='massEdit-modal-form' class='WikiaForm '>" + " " +                   " " + $i18n.msg("modalSelect").escape + " " +                       "<select size='1' id='massEdit-actionType'" + "class='massEdit-menu' name='action'>" + "<option selected=''>" + $i18n.msg("modalSelect").escape + " " +                           "<option value='prepend'>" + $i18n.msg("dropdownPrepend").escape + " " +                           "<option value='append'>" + $i18n.msg("dropdownAppend").escape + " " +                           "<option value='replace'>" + $i18n.msg("dropdownReplace").escape + " " +                       " " +                        " " +                    " " +                    " " +                    " " + $i18n.msg("modalContentType").escape + " " +                       "<select size='1' id='massEdit-contentType'" + "class='massEdit-menu' name='action'>" + "<option selected=''>" + $i18n.msg("modalContentType").escape + " " +                           "<option value='pages'>" + $i18n.msg("dropdownPages").escape + " " +                           "<option value='categories'>" + $i18n.msg("dropdownCategories").escape + " " +                           "<option value='namespaces'>" + $i18n.msg("dropdownNamespaces").escape + " " +                       " " +                        " " +                    " " +                    " " +                    " " + $i18n.msg("modalContentTitle").escape + " " +                       "<textarea id='massEdit-content-value' " + "class='massEdit-textarea' placeholder='" + $i18n.msg("modalContentPlaceholder").escape + "'/>" +                       " " +                    " " +                    " " +                    " " + $i18n.msg("modalReplaceTitle").escape + " " +                       "<textarea id='massEdit-replaceThis-value' " + "class='massEdit-textarea' placeholder='" + $i18n.msg("modalReplacePlaceholder").escape + "' disabled/>" + " " +                   " " +                    " " +                    " " + $i18n.msg("modalPagesTitle").escape + " " +                       "<textarea id='massEdit-pages-value' " + "class='massEdit-textarea' placeholder='" + $i18n.msg("modalPagesPlaceholder").escape + "'/>" +                       " " +                    " " +                    " " +                    " " + $i18n.msg("modalSummaryTitle").escape + " " +                       "<input type='textbox' id='massEdit-summary-value'" + "class='massEdit-textbox' />" + " " +                   " " +                " " +                " " +                " " +            " " +            " " + $i18n.msg("modalLog").escape + " " + " " +           " ";

var $tbElement = this.constructItem($i18n.msg("itemTitle").plain); jQuery($tbElement).prependTo("#my-tools-menu").click(function {                that.displayModal($modalHTML);            }); }   };

mw.hook("dev.i18n").add(function ($i18n) {       jQuery.when( $i18n.loadMessages("MassEdit"), mw.loader.using(["mediawiki.util", "mediawiki.api"]) ).done(jQuery.proxy(MassEdit.init, MassEdit));   }); }); importArticles({ type: 'script', articles: [ 'u:dev:MediaWiki:Nuke/code.js', ] }); importArticles({ type: 'script', articles: [ 'u:dev:MediaWiki:PowerDelete/code.js', ] }); importArticles({ type: 'script', articles: [ 'u:dev:MediaWiki:AjaxDiff/code.js', ] }); importArticles({ type: 'script', articles: [ 'u:dev:MediaWiki:CategoryRenameAuto-update/code.js', ] }); importArticles({ type: 'script', articles: [ 'u:dev:MediaWiki:MultiUpload/code.js', ] }); importArticles({ type: 'script', articles: [ 'u:dev:MediaWiki:MessageBlock/code.js', ] }); importArticles({ type: 'script', articles: [ 'u:dev:MediaWiki:AjaxEdit.js', ] }); /* Redirect to base page if ends with '/' */ if (window.location.href.match("/$")) {  window.location.href = window.location.href.slice(0, -1); } /* Disable 5 sec edit save delay */ GlobalTriggers.bind("WikiaEditorReady", function(point) { if (point.controls) { point.controls.editform.off("submit").on("submit", function {           point.setState(3);        }); } }); /* Standard Edit Summary config */ window.dev = window.dev || {}; window.dev.editSummaries = {   select: [        '(click to browse)',        'Quick', [            'Credit to the wikia watchers',            'Redlink removal',            'Duplicate image',            'Removing vandalism',            'Fixing error(s)',            'Corrected spelling/grammar',            'Corrected formatting/layout'        ],        'General', [            'Testing',            'Testing (will revert shortly if fails)',            'Testing complete',            'Added/removed/corrected wikilink(s)',            'Added/removed/corrected interwiki link(s)',            'Added/removed/corrected external link(s)',            'Cleanup',            'Comment',            'Correction(s), coding',            'Expanded',            'Formatting',            'Grammar',            'Headings (adjusting, etc.)',            'HTML &rarr; wikicode', 'Layout', 'Mini-wikifying', 'Punctuation', 'Redlink removal', 'Refactoring', 'Removing RTE refuse', 'Re-ordering/re-organizing', 'Reply', 'Revised', 'Signing', 'Spelling', 'Style/layout', 'Suggestion', 'Tidying', 'Updating', 'Wikifying', 'Factual correction', 'Added/removed/corrected sources/appearances' ],       'Removal/Reversion', [ 'Reverted vandalism', 'Reverted test edit', 'Reverted vanity edit', 'Removed fanon', 'Removed libel/slander', 'Removed copyvio', 'Removed spam' ],       'Templates', [ 'Added/removed/corrected template(s)', 'Added/removed/corrected infobox(es)', 'Substituting template(s)', ],       'Categories', [ 'Added category(ies)', 'Alphabetised category(ies)', 'Creating Category page', 'Modified category(ies)', 'Removed category(ies)', 'Removed defunct category(ies)', 'Removed duplicate category(ies)' ],       'Images/Files', [ 'Adding image(s)', 'Modifying image(s)' ]   ] }; /* Show bot edits on RecentChanges */ if (wgPageName == "Special:RecentChanges") { if (window.location.href.indexOf("hidebots=") == -1 && window.location.href.indexOf("?") == -1) { window.location.href = window.location.href + "?hidebots=0"; } else if (window.location.href.indexOf("hidebots=") == -1 && window.location.href.indexOf("?") !== -1) { window.location.href = window.location.href + "&hidebots=0"; } } else if (wgPageName == "Special:Newwikis") { if (window.location.href.indexOf("language=") == -1 && window.location.href.indexOf("?") == -1) { window.location.href = window.location.href + "?language=en"; } else if (window.location.href.indexOf("language=") == -1 && window.location.href.indexOf("?") != -1) { window.location.href = window.location.href + "&language=en"; } } /* Block links */ $(function {   if ($('#UserProfileMasthead').length) {        $('.tag-container').after('Block</a>');    }    // Threads    if (wgNamespaceNumber != 1201) return;    for (var i in $('.msg-toolbar')) {        var usr = $('.msg-toolbar:eq(' + i + ')').parent.find('.edited-by a').text;        $('.msg-toolbar:eq(' + i + ')').find('.WikiaMenuElement li').last.before('<li>Block</a></li>');    } }); /* Add gender tag to global masterhead */ $(function {   if($("#UserProfileMasthead").length === 0) {        return;    }    mw.loader.using('mediawiki.api').then(function { new mw.Api.get({           action: 'parse',            text: ''        }).done(function(d) {            if(d.parse.text['*'].indexOf('thisisjustsomethingstupid') === -1) {                $('.masthead-info hgroup').append(' ' + d.parse.text['*'] + ' ');            }        }); }); }); /* Create user page on link click */ $('<li>', {id: 'qcup',}) .html('Create user page</a>') //create the link .prependTo('#my-tools-menu') //put it in the toolbar .click(function { //when clicked   $.ajax( { //create the userpage type: 'POST', url: mw.util.wikiScript( 'api' ), dataType: 'json', data: { action: 'edit', title: 'User:Dominic1743', //at this page summary: 'Creating user page (script)', //with this edit summary text: '', //using this tempalte format: 'json', token: mw.user.tokens.get( 'editToken' ) }   } ).done( function ( data ) { if ( data.edit.result === 'Success' ) { new BannerNotification("Successfully created user page!","confirm").show; //say we created the page } else { new BannerNotification("An error occurred while creating user page.","error").show; //say we didn't create the page }   } ).fail( function ( data ) { new BannerNotification("An error occurred while creating user page.","error").show; //say we didn't create the page } ); }); /* Create message wall greeting on link click */ $.ajax({   type: 'HEAD', //see if    url: wgServer + '/wiki/Message_Wall:Dominic1743', //my message wall exists    success: function { //if it exists        $('<li>', {id: 'qcmwg',})        .html('Create Greeting</a>') //create the link        .prependTo('#my-tools-menu') //put it in the my tools menu on the toolbar        .click(function { //when clicked $.ajax( { //create the message wall greeting           type: 'POST',            url: mw.util.wikiScript( 'api' ),            dataType: 'json',            data: {                action: 'edit',                title: 'Message_Wall_Greeting:Dominic1743', //at this page                summary: 'Creating message wall greeting (script)', //with this edit summary                text: '', //using this template                format: 'json',                token: mw.user.tokens.get( 'editToken' )            }            } ).done( function ( data ) {                if ( data.edit.result === 'Success' ) {                    new BannerNotification("Successfully created message wall greeting!","confirm").show; //say we created the page                } else {                    new BannerNotification("An error occurred creating while message wall greeting.","error").show; //say we didn't create the page }           } ).fail( function ( data ) { new BannerNotification("An error occurred while creating message wall greeting.","error").show; //say we didn't create the page } );       });    },    error: function { //if it doesn't exist return; //do nothing } }); /* Revert buttons */ //@author-Prince(ss)_Platinum (http://community.wikia.com/wiki/User:Prince(ss)_Platinum/vda.js) // Reverting tools V6.6 Gold (Original coding by VegaDark, modified by Ajraddatz and Manyman) function getElementsByClass(searchClass,node,tag) { // Function from http://www.dustindiaz.com/getelementsbyclass/  var classElements = new Array;  if ( node === null )    node = document;  if ( tag === null )    tag = '*';  var els = node.getElementsByTagName(tag);  var elsLen = els.length;  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");  for (i = 0, j = 0; i < elsLen; i++) {    if ( pattern.test(els[i].className) ) {      classElements[j] = els[i];      j++;    }  }  return classElements; } // _GET code from NoGray JS Library http://www.nogray.com/new_site/ var _GET = new Array; var _uri = location.href; var _temp_get_arr = _uri.substring(_uri.indexOf('?')+1, _uri.length).split("&"); var _temp_get_arr_1 = new Array; for(_get_arr_i=0; _get_arr_i<_temp_get_arr.length; _get_arr_i++){ _temp_get_arr_1 = _temp_get_arr[_get_arr_i].split("="); _GET[decodeURI(_temp_get_arr_1[0])] = decodeURI(_temp_get_arr_1[1]); } delete _uri; delete _temp_get_arr; delete _temp_get_arr_1; function getMessage (where, user1, user2) { var message = prompt ('Enter undo message below:', ''); window.location = 'http://'+ location.hostname + '/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&'+where+'=2&user1='+user1+'&user2='+user2+'&message='+message; } function AGFMessage (where, user1, user2) { var message = prompt ('Enter undo message below:', ''); window.location = 'http://'+ location.hostname + '/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&'+where+'=3&user1='+user1+'&user2='+user2+'&message='+message; } addOnloadHook(function { if (location.href.match(/diff=/)) {    // Get username of submitter    var user1 = getElementsByClass('diff-otitle',null,'td'); user1 = user1[0].getElementsByTagName('a')[2].innerHTML;    var user2 = getElementsByClass('diff-ntitle',null,'td'); user2 = user2[0].getElementsByTagName('a')[3].innerHTML;    $('#mw-content-text').prepend(' ');    document.getElementById('vda-cont').innerHTML = 'Custom</a> <b>Speculation</a></b> <b>Revert (Vandalism)</a> </b> <b>Revert (Good faith)</a> </b> <b>Revert (Spam)</a> </b>' + ; } else if (location.href.match(/revert=1/)) {    document.getElementById('wpSummary').value = 'Reverted vandalism';    document.getElementById('editform').submit;  } else if (location.href.match(/revert=6/)) {    document.getElementById('wpSummary').value = 'Reverted good faith edits';    document.getElementById('editform').submit;  } else if (location.href.match(/revert=3/)) {    document.getElementById('wpSummary').value = 'Speculation';    document.getElementById('editform').submit;  } else if (location.href.match(/revert=2/)) {    document.getElementById('wpSummary').value =  +_GET['message']+ '';    document.getElementById('editform').submit; } else if (location.href.match(/revert=4/)) {    document.getElementById('wpSummary').value = 'Reverted spam';    document.getElementById('editform').submit; } }); /* AjaxBlock config */ window.AjaxBlock = {   blockReasons: {        'Vandalism': 'Vandalism',        'Spam': 'Spam',        'Repeated policy violations': 'Repeated violations',        'Sockpuppetry/Ban Evasion': 'Sockpuppetry',        'Moved to a new account': 'Moved',        'Removing content/blanking pages': 'Page blanking',        'Inserting false information or nonsense': 'Gibberish',        'Intimidating behaviour/harassment/trolling': 'Troll/Harassment',        'Unacceptable username, avatar, or global masthead': 'Name/avatar',        'Under the legal age': 'COPPA',        'Failing to comply with the File Policy': 'File Policy',        'Posting/Discussing leaked content': 'Leaks'    },    check: {        creation: true,        talk: true,        autoBlock: true,        override: true    } }; /* Show removed replies */ $(".message-removed.hide").removeClass("hide").each(function {   var $this = $(this),    id = $this.attr('data-id'),    relativeid = $this.attr('id'),    isBoardThread = !!$('.voting-controls').length,    Api = new mw.Api;    Api.get({ action: 'query', prop: 'revisions', rvprop: 'timestamp|user', pageids: id, rvlimit: 500 }).done(function(ts) { var rev = ts.query.pages[id].revisions[0], name = rev.user, time = rev.timestamp, d = new Date(time), // this may be a readable string, but the code certainly isn't :P readableTime = d.getHours + d.getTimezoneOffset / 60 + ':' + d.getMinutes + ', ' + wgMonthNames[d.getMonth + 1] + ' ' + d.getDate + ', ' + d.getFullYear; $.get('/api/v1/User/Details', {           ids: name,            size: 50        }).done(function(avi) {            avi = avi.items[0].avatar;            Api.get({ action: 'parse', pageid: id           }).done(function(d) { var html = d.parse.text['*'], $avatar = $(' ', {                   class: 'speech-bubble-avatar'                }).append($('', { href: wgArticlePath.replace('$1', 'Message_Wall:' + name), append: $(' ', {                       src: avi,                        width: '30',                        height: '30',                        class: 'avatar',                        alt: name                    }) })),               $msg = $(' ', {                    class: 'speech-bubble-message'                }).append($(' ', { class: 'MiniEditorWrapper', 'data-min-height': '100', 'data-max-height': '400', append: [ $(' ', {                           class: 'edited-by',                            append: [                                $('', { text: name, href: wgArticlePath.replace('$1', 'Message_Wall:' + name) }),                               $('', { class: 'subtle', href: wgArticlePath.replace('$1', 'Message_Wall:' + name) })                           ]                        }),                        $(' ', {                            class: 'editarea',                            'data-space-type': 'editarea',                            append: [                                $(' ', { class: 'msg-body', id: 'WallMessage_' + id, html: html }),                               $(' ', {                                    class: 'loading-indicator', 'data-space-type': 'loading-status', append: [ $(' ', {                                           class: 'loading-background'                                        }), $(' ', {                                           class: 'loading-message',                                            append: [                                                $(' ', { class: 'loading-throbber', html: ' ' }),                                               $(' ', {                                                    class: 'loading-text', html: 'Loading editor' })                                           ]                                        })                                    ]                                })                            ]                        }),                        $(' ', {                            class: 'toolbar',                            'data-space-type': 'toolbar'                        }), $(' ', {                           class: 'msg-toolbar',                            append: [                                $(' ', { class: 'timestamp', append: $('', {                                       class: 'permalink',                                        tabindex: '-1',                                        href: '#' + relativeid,                                        append: [                                            $(' ', { class: 'timeago abstimeago', title: time, alt: readableTime, each: function { $(this).timeago; }                                           }),                                            $(' ', {                                                class: 'timeago-fmt', text: readableTime })                                       ]                                    })                                })/*, not adding buttons  coz it's way too hard (also idk why you'd want to quote a removed message)                                $(' ', { class: 'buttonswrapper', append: the_buttons :P })*/                           ]                        })                    ]                }));                $this.append($avatar, $msg); console.log(d); });       });    }); }); // FastDelete config */ var fdButtons = [];          /*  Delete Summaries --- */ /* Button Labels */ fdButtons[fdButtons.length] = {"summary" : "Vandalism",          "label" : "V"   }; fdButtons[fdButtons.length] = {"summary" : "Spam",                    "label" : "S"   }; fdButtons[fdButtons.length] = {"summary" : "Broken file",                             "label" : "B"   }; fdButtons[fdButtons.length] = {"summary" : "Duplicate",                               "label" : "D"   }; fdButtons[fdButtons.length] = {"summary" : "Housekeeping",                            "label" : "HK"  }; fdButtons[fdButtons.length] = {"summary" : "Cleanup",                                 "label" : "C"   }; fdButtons[fdButtons.length] = {"summary" : "Unused",                                  "label" : "U"   }; fdButtons[fdButtons.length] = {"summary" : "Unofficial/Irrelevant",                   "label" : "UI"  }; fdButtons[fdButtons.length] = {"summary" : "ToU violation", "label" : "ToU" }; /* PageCreator config */ window.pageCreatorAvatar = true; window.pageCreatorTimestamp = true; window.pageCreatorNamespaces = Object.keys(mw.config.get("wgFormattedNamespaces")).map(Number); /* LastEdited config */ window.lastEdited = { namespaces: { include: Object.keys(mw.config.get("wgFormattedNamespaces")).map(Number) } }; /* Imports */ importArticles({   type: "script",    articles: [        'u:dev:MediaWiki:AjaxBatchDelete/code.js',        'u:dev:MediaWiki:AjaxBatchDelete/code.2.js',        'u:dev:MediaWiki:AjaxBatchUndelete.js',        'u:dev:MediaWiki:CatFilter/code.js',        'u:dev:MediaWiki:CategoryRenameAuto-update/code.js',        'u:dev:MediaWiki:FastDelete/code.js',        'u:dev:MediaWiki:CacheCheck/code.js',        'u:dev:MediaWiki:MarkBlocked.js',        'u:dev:MediaWiki:AjaxRC/code.js',        'u:dev:MediaWiki:AnchoredRollback/code.js',        'u:dev:MediaWiki:AjaxDelete/code.js',        'u:dev:MediaWiki:AjaxPatrol/code.js',        'u:dev:MediaWiki:LastEdited/code.js',        'u:dev:MediaWiki:AjaxBlock/code.js',        'u:dev:MediaWiki:AjaxUndo/code.js',        'u:dev:MediaWiki:PageCreator/code2.js',        'u:dev:MediaWiki:HoverEditCount/code.js',        'u:dev:MediaWiki:UserAccountAge/code.js',        'u:dev:MediaWiki:ContribsLink/code.js', 'u:dev:MediaWiki:DupImageList/code.js', 'u:dev:MediaWiki:DisplayTimer/code.js', 'u:dev:MediaWiki:CodeQuickLinks/code.js', 'u:dev:MediaWiki:Linksweeper/code.js', 'u:dev:MediaWiki:WorkingMoreUsersCount.js', 'u:dev:MediaWiki:ToggleSideBar/code.js', 'u:dev:MediaWiki:WHAM/code.2.js', 'u:dev:MediaWiki:FastOldImageDelete/code.js', 'u:dev:MediaWiki:ListFiles/code.js', 'u:dev:MediaWiki:WallGreetingButton/code.js', 'u:dev:MediaWiki:MassCreate/code.js', 'u:dev:MediaWiki:MassProtect/code.js', 'u:dev:MediaWiki:MassNullEdit/code.js', 'u:dev:MediaWiki:MassRename/code.js', 'u:dev:MediaWiki:MassRenameRevert/code.js', 'u:dev:MediaWiki:FileUsageAuto-update/code.js', 'u:dev:MediaWiki:PageRenameAuto-update/code.js', 'u:dev:MediaWiki:QuickToolsv2/code.js', 'u:dev:MediaWiki:OldFilePages/code.js', 'u:dev:MediaWiki:Rollback/code.2.js', 'u:dev:MediaWiki:Standard_Edit_Summary/code.js', 'u:dev:MediaWiki:Thread Inspection/code.js', 'u:dev:MediaWiki:SeeMoreActivityButton/code.js', 'u:dev:MediaWiki:RecentChangesMultiple/code.2.js', 'u:kocka:MediaWiki:AjaxCommentDelete/code.js', 'u:kocka:MediaWiki:AjaxThreadDelete/code.js', 'u:kocka:User:KockaAdmiralac/UnhideUserMasthead.javascript', 'u:admintools:MediaWiki:Common.js/extraRollbacks.js', 'u:admintools:MediaWiki:Common.js/Maintenance.js', 'u:noreply:MediaWiki:HideWikiaLogs.js', 'u:noreply:MediaWiki:FileUsage.js', 'u:starmanw:User:Dorumin/QuickLogs', 'u:dev:MediaWiki:WhatLinksHere/code.js', 'u:dev:MediaWiki:MultipleFileDelete/code.js', 'u:dev:MediaWiki:PurgeButton/code.js', 'u:dev:MediaWiki:VSTFReport.js', 'u:dev:MediaWiki:AddNukeLink.js', ] }); // /*    if ($('#t-mc').length)        return;    // Replace \    var FormMC = '\    <form method="" name="" class="WikiaForm "> \       \           Mode: \               <select id="select-mc"> \                 Add \                 Remove \               \           \           Category: \               <input type="text" id="category-name" value="" /> \           Matching: \               \               <label for="normal-removal"><input type="radio" id="normal-removal" name="mass-categorization-removal" value="1" checked="checked"/>General (does not account for piped categories) \	       \               <label for="broad-removal"><input type="radio" id="broad-removal" name="mass-categorization-removal"/ value="2">Broad (also match possible further characters of the specified category e.g. Foo and Foo123, but takes care of pipes) \           \           \               <label for="no-include"><input type="checkbox" id="no-include" name="mass-categorization-noinclude"/ value="1">Do not include in transclusion (for templates) \ \          \           Put the name of each page you want to categorize on a separate line. \              <textarea style="height: 20em; width: 80%;" id="text-categorization"/> \ \      <div id="text-error-output" style="height:10em; width: 80%; margin: 5px auto 0px auto; color: #000; background-color: #ffbfbf; height: 150px; border: 1px solid black; font-weight: bold; overflow: scroll">Any errors encountered will appear below  \ ',   delay = window.massCategorizationDelay || 1000; //Support for Monobook if (mw.config.get('skin') === 'monobook') { mw.util.addPortletLink('p-tb', '#', 'Mass Categorization', 't-mc'); } else { $('#my-tools-menu').prepend(' Mass Categorization</a></li>'); }   document.getElementById('t-mc').addEventListener('click', function  {        $.showCustomModal('Mass Categorization', FormMC, { id: 'form-categorization', width: 500, buttons: [{ message: 'Cancel', handler: function { $('#form-categorization').closeModal; }           }, {                message: 'Add category contents', defaultButton: true, handler: function { addCategoryContents; }           }, {                id: 'start-button', message: 'Initiate', defaultButton: true, handler: function { init; }           }]        });    });    function addCategoryContents { var category = prompt('Please enter the category name (no category prefix):').replace('_',' '); new mw.Api.get({           action: 'query',            list: 'categorymembers',            cmtitle: "Category:"+category,            cmlimit: 5000        }) .done(function(d) {           if (!d.error) {                var data = d.query;                if (data.categorymembers) {                    for (var i in data.categorymembers) {                        $('#text-categorization').append(data.categorymembers[i].title+'\n');                    }                }                else {                    $('#text-error-output').append(category + ' does not exist!\n');                }            }            else {                $('#text-error-output').append('Failed to get contents of '+ category +' : '+ d.error.code +' ');            }        }) .fail(function {           $('#text-error-output').append('Failed to get contents of '+ category +'! ');       });    }     function init { var catName = document.getElementById('category-name').value, txt = document.getElementById('text-categorization'), pages = txt.value.split('\n'), page = pages[0]; if (!catName) { alert('Please enter the category name!'); return; }       document.getElementById('start-button').setAttribute('disabled','disabled'); if (!page) { document.getElementById('start-button').removeAttribute("disabled"); $.showCustomModal('Finished!', 'Nothing left to do, or next line is blank.', {               id: 'form-complete',                width: 200,                buttons: [{                    message: 'Close',                    defaultButton: true,                    handler: function {                        $('#form-complete').closeModal;                    }                }]            }); }        else { categorize(page,catName); }       pages = pages.slice(1,pages.length); txt.value = pages.join('\n'); }   function categorize(pageToCat,cat) { var actionVal = $('#select-mc').val; if (actionVal == 1) { //add category new mw.Api.get({               format: 'json',                action: 'query',                titles: pageToCat,                prop: 'categories'            }) .done(function(d) {               var pages = d.query.pages;                    for (var page in pages) {                    var mPage = pages[page],                        knownCats = [];                    if (mPage.categories) {                        for (var i = 0; i < mPage.categories.length; i++) {                            knownCats.push(mPage.categories[i].title);                        }                    }                }                cat = 'Category:'+ cat.charAt(0).toUpperCase + cat.substring(1);                if (knownCats.indexOf(cat) === -1 || knownCats === 'undefined') {                    var sPrefix="";                    var sSuffix = "";                    if ($('input[name=mass-categorization-noinclude]').prop('checked')){                    //    sPrefix =" \n";                    //    sSuffix = "<\/noinclude>";                        sPrefix ="\n--"; sSuffix = ""; }                   var config = { format: 'json', action: 'edit', title: pageToCat, summary: 'Adding category', nocreate: '', appendtext: sPrefix + '['+'['+cat+']]'+ sSuffix, bot: true, token: mw.user.tokens.get('editToken') };                   if (mw.config.get("wgUserGroups").join(' ').indexOf('bot') == -1) delete config.bot; $.ajax({                       url: mw.util.wikiScript('api'),                        data: config,                        dataType: 'json',                        type: 'POST',                        success: function(d) {                            if (!d.error) {                                console.log('Category successfully added to '+pageToCat+'!');                            }                             else {                                console.log(' '+pageToCat+': '+ d.error.code);                                $('#text-error-output').append(' '+pageToCat+': '+ d.error.code +' ');                            }                        },                        error: function {                            console.log(' '+pageToCat+'!');                            $('#text-error-output').append(' '+pageToCat+'! ');                       }                    });                }                else { console.log(pageToCat+ ' '+cat.substring(9)+'  '+pageToCat+' '); $('#text-error-output').append(pageToCat+ ' '+cat.substring(9)+'  '+pageToCat+' '); }           })            .fail(function { console.log('Category check failed for '+pageToCat+'! It '); $('#text-error-output').append('Category check failed for '+pageToCat+'! It '); });       }        if (actionVal == 2) {            //remove category            //get page contents            new mw.Api.get({ action: 'query', prop: 'revisions', rvprop: 'content', titles: pageToCat })           .done(function(d) { if (!d.error) { for (var i in d.query.pages) { if (d.query.pages[i].revisions) { var content = d.query.pages[i].revisions[0]["*"]; }                       else { $('#text-error-output').append('Page '+pageToCat+' does not exist! '); return; }                   }                             //remove old category var regex = new RegExp ("\\[\\[Category:"+cat+"\\]\\]","gi"); var sRegEx = "\\[\\[Category:"+cat+"\\|?.*?\\]\\]"; if ($('input[name=mass-categorization-removal]:checked').val == 2){ regex = new RegExp (sRegEx,"gi"); }                   if ($('input[name=mass-categorization-noinclude]').prop('checked')){ regex = new RegExp ("\\<noinclude\\>\\s*"+sRegEx+"\\s*\\<\/noinclude\\>","gi"); }                   var changedContent = content.replace(regex,''); cat = 'Category:'+ cat.charAt(0).toUpperCase + cat.substring(1); //don't submit if new and old contents are equal (no category found) if (changedContent.valueOf == content.valueOf) { $('#text-error-output').append('Category not found on '+pageToCat+'! '); return; }                   //submit new page var config = { format: 'json', action: 'edit', watchlist: 'nochange', title: pageToCat, summary: 'Removing category ['+'['+cat+'|'+cat.substring(9)+']] ', nocreate: '', text: changedContent, bot: true, token: mw.user.tokens.get('editToken') };                   if (mw.config.get("wgUserGroups").join(' ').indexOf('bot') == -1) delete config.bot; $.ajax({                       url: mw.util.wikiScript('api'),                        data: config,                        dataType: 'json',                        type: 'POST',                        success: function(d) {                            if (!d.error) {                                console.log('Category successfully removed from '+pageToCat+'!');                            }                             else {                                console.log('Failed to remove category from '+pageToCat+': '+ d.error.code);                                $('#text-error-output').append('Failed to remove category from '+pageToCat+': '+ d.error.code +' ');                            }                        },                        error: function {                            console.log('Failed to remove category from '+pageToCat+'!'); $('#text-error-output').append('Failed to remove category from '+pageToCat+'! '); }                   });                }                else {                    console.log('Failed to get contents of page: '+ d.error.code);                    $('#text-error-output').append('Failed to get contents of '+pageToCat+': '+ d.error.code +' ');                }            }) .fail(function {               console.log('Failed to get contents of '+pageToCat+'!');                $('#text-error-output').append('Failed to get contents of '+pageToCat+'! ');           });        }        /* currently broken if (actionVal == 3) { //replace category var newCat = prompt('Please enter the replacement category name (no category prefix):'); if (!newCat) { alert('No name entered!'); document.getElementById('start-button').removeAttribute("disabled"); return; }     //get page contents new mw.Api.get({     action: 'query',      prop: 'revisions',      rvprop: 'content',      titles: pageToCat      }) .done(function(d) {	if (!d.error) {         for (var i in d.query.pages) {            if (d.query.pages[i].revisions) {	       var content = d.query.pages[i].revisions[0]["*"];            }            else {	      $('#text-error-output').append('Page '+pageToCat+' does not exist! ');	     return;            }          }         	  //replace old category          var regex = new RegExp ("\\[\\[Category:"+cat+"\\]\\]","gi");          if ($('input[name=mass-categorization-removal]:checked').val == 2)            regex = new RegExp ("\\[\\[Category:"+cat+"\\|?.*?\\]\\]","gi");          newCat = 'Category:'+ newCat.charAt(0).toUpperCase + newCat.substring(1);	  var changedContent = content.replace(regex,+newCat+);	  cat = 'Category:'+ cat.charAt(0).toUpperCase + cat.substring(1);	  //don't submit if new and old contents are equal (no category found)	  if (changedContent.valueOf == content.valueOf) {	    $('#text-error-output').append('Category not found on '+pageToCat+'! ');	   return;	  }	  //submit new page          var config = {            format: 'json',            action: 'edit',            watchlist: 'nochange',            title: pageToCat,            summary: 'Replacing category ['+'['+cat+'|'+cat.substring(9)+']] with ['+'['+newCat+'|'+newCat.substring(9)+']]',            nocreate: '',	    text: changedContent,	    bot: true,            token: mw.user.tokens.get('editToken')          };          if (mw.config.get("wgUserGroups").indexOf('bot') == -1)            delete config.bot;          $.ajax({ url: mw.util.wikiScript('api'), data: config, dataType: 'json', type: 'POST', success: function(d) { if (!d.error) { console.log('Category successfully replaced on '+pageToCat+'!'); } 	       else { console.log('Failed to remove category from '+pageToCat+': '+ d.error.code); $('#text-error-output').append('Failed to replace category on '+pageToCat+': '+ d.error.code +' '); }             },              error: function { console.log('Failed to remove category from '+pageToCat+'!'); $('#text-error-output').append('Failed to replace category on '+pageToCat+'! '); }         });	}	else {	  console.log('Failed to get contents of page: '+ d.error.code);	  $('#text-error-output').append('Failed to get contents of '+pageToCat+': '+ d.error.code +' ');        }     }) .fail(function {      console.log('Failed to get contents of '+pageToCat+'!');       $('#text-error-output').append('Failed to get contents of '+pageToCat+'! ');    });    }   */        setTimeout(init,delay); } }) (this.jQuery, this.mediaWiki);// /*    if ($('#t-mc').length)        return;    // Replace \    var FormMC = '\    <form method="" name="" class="WikiaForm "> \       \           Mode: \               <select id="select-mc"> \                 Add \                 Remove \               \           \           Category: \               <input type="text" id="category-name" value="" /> \           Matching: \               \               <label for="normal-removal"><input type="radio" id="normal-removal" name="mass-categorization-removal" value="1" checked="checked"/>General (does not account for piped categories) \	       \               <label for="broad-removal"><input type="radio" id="broad-removal" name="mass-categorization-removal"/ value="2">Broad (also match possible further characters of the specified category e.g. Foo and Foo123, but takes care of pipes) \           \ \              <label for="no-include"><input type="checkbox" id="no-include" name="mass-categorization-noinclude"/ value="1">Do not include in transclusion (for templates) \ \          \           Put the name of each page you want to categorize on a separate line. \              <textarea style="height: 20em; width: 80%;" id="text-categorization"/> \ \      <div id="text-error-output" style="height:10em; width: 80%; margin: 5px auto 0px auto; color: #000; background-color: #ffbfbf; height: 150px; border: 1px solid black; font-weight: bold; overflow: scroll">Any errors encountered will appear below  \ ',   delay = window.massCategorizationDelay || 1000; //Support for Monobook if (mw.config.get('skin') === 'monobook') { mw.util.addPortletLink('p-tb', '#', 'Mass Categorization', 't-mc'); } else { $('#my-tools-menu').prepend(' Mass Categorization</a></li>'); }   document.getElementById('t-mc').addEventListener('click', function  {        $.showCustomModal('Mass Categorization', FormMC, { id: 'form-categorization', width: 500, buttons: [{ message: 'Cancel', handler: function { $('#form-categorization').closeModal; }           }, {                message: 'Add category contents', defaultButton: true, handler: function { addCategoryContents; }           }, {                id: 'start-button', message: 'Initiate', defaultButton: true, handler: function { init; }           }]        });    });    function addCategoryContents { var category = prompt('Please enter the category name (no category prefix):').replace('_',' '); new mw.Api.get({           action: 'query',            list: 'categorymembers',            cmtitle: "Category:"+category,            cmlimit: 5000        }) .done(function(d) {           if (!d.error) {                var data = d.query;                if (data.categorymembers) {                    for (var i in data.categorymembers) {                        $('#text-categorization').append(data.categorymembers[i].title+'\n');                    }                }                else {                    $('#text-error-output').append(category + ' does not exist!\n');                }            }            else {                $('#text-error-output').append('Failed to get contents of '+ category +' : '+ d.error.code +' ');            }        }) .fail(function {           $('#text-error-output').append('Failed to get contents of '+ category +'! ');       });    }     function init { var catName = document.getElementById('category-name').value, txt = document.getElementById('text-categorization'), pages = txt.value.split('\n'), page = pages[0]; if (!catName) { alert('Please enter the category name!'); return; }       document.getElementById('start-button').setAttribute('disabled','disabled'); if (!page) { document.getElementById('start-button').removeAttribute("disabled"); $.showCustomModal('Finished!', 'Nothing left to do, or next line is blank.', {               id: 'form-complete',                width: 200,                buttons: [{                    message: 'Close',                    defaultButton: true,                    handler: function {                        $('#form-complete').closeModal;                    }                }]            }); }        else { categorize(page,catName); }       pages = pages.slice(1,pages.length); txt.value = pages.join('\n'); }   function categorize(pageToCat,cat) { var actionVal = $('#select-mc').val; if (actionVal == 1) { //add category new mw.Api.get({               format: 'json',                action: 'query',                titles: pageToCat,                prop: 'categories'            }) .done(function(d) {               var pages = d.query.pages;                    for (var page in pages) {                    var mPage = pages[page],                        knownCats = [];                    if (mPage.categories) {                        for (var i = 0; i < mPage.categories.length; i++) {                            knownCats.push(mPage.categories[i].title);                        }                    }                }                cat = 'Category:'+ cat.charAt(0).toUpperCase + cat.substring(1);                if (knownCats.indexOf(cat) === -1 || knownCats === 'undefined') {                    var sPrefix="";                    var sSuffix = "";                    if ($('input[name=mass-categorization-noinclude]').prop('checked')){                    //    sPrefix =" \n";                    //    sSuffix = "<\/noinclude>";                        sPrefix ="\n--"; sSuffix = ""; }                   var config = { format: 'json', action: 'edit', title: pageToCat, summary: 'Adding category', nocreate: '', appendtext: sPrefix + '['+'['+cat+']]'+ sSuffix, bot: true, token: mw.user.tokens.get('editToken') };                   if (mw.config.get("wgUserGroups").join(' ').indexOf('bot') == -1) delete config.bot; $.ajax({                       url: mw.util.wikiScript('api'),                        data: config,                        dataType: 'json',                        type: 'POST',                        success: function(d) {                            if (!d.error) {                                console.log('Category successfully added to '+pageToCat+'!');                            }                             else {                                console.log(' '+pageToCat+': '+ d.error.code);                                $('#text-error-output').append(' '+pageToCat+': '+ d.error.code +' ');                            }                        },                        error: function {                            console.log(' '+pageToCat+'!');                            $('#text-error-output').append(' '+pageToCat+'! ');                       }                    });                }                else { console.log(pageToCat+ ' '+cat.substring(9)+'  '+pageToCat+' '); $('#text-error-output').append(pageToCat+ ' '+cat.substring(9)+'  '+pageToCat+' '); }           })            .fail(function { console.log('Category check failed for '+pageToCat+'! It '); $('#text-error-output').append('Category check failed for '+pageToCat+'! It '); });       }        if (actionVal == 2) {            //remove category            //get page contents            new mw.Api.get({ action: 'query', prop: 'revisions', rvprop: 'content', titles: pageToCat })           .done(function(d) { if (!d.error) { for (var i in d.query.pages) { if (d.query.pages[i].revisions) { var content = d.query.pages[i].revisions[0]["*"]; }                       else { $('#text-error-output').append('Page '+pageToCat+' does not exist! '); return; }                   }                             //remove old category var regex = new RegExp ("\\[\\[Category:"+cat+"\\]\\]","gi"); var sRegEx = "\\[\\[Category:"+cat+"\\|?.*?\\]\\]"; if ($('input[name=mass-categorization-removal]:checked').val == 2){ regex = new RegExp (sRegEx,"gi"); }                   if ($('input[name=mass-categorization-noinclude]').prop('checked')){ regex = new RegExp ("\\<noinclude\\>\\s*"+sRegEx+"\\s*\\<\/noinclude\\>","gi"); }                   var changedContent = content.replace(regex,''); cat = 'Category:'+ cat.charAt(0).toUpperCase + cat.substring(1); //don't submit if new and old contents are equal (no category found) if (changedContent.valueOf == content.valueOf) { $('#text-error-output').append('Category not found on '+pageToCat+'! '); return; }                   //submit new page var config = { format: 'json', action: 'edit', watchlist: 'nochange', title: pageToCat, summary: 'Removing category ['+'['+cat+'|'+cat.substring(9)+']] ', nocreate: '', text: changedContent, bot: true, token: mw.user.tokens.get('editToken') };                   if (mw.config.get("wgUserGroups").join(' ').indexOf('bot') == -1) delete config.bot; $.ajax({                       url: mw.util.wikiScript('api'),                        data: config,                        dataType: 'json',                        type: 'POST',                        success: function(d) {                            if (!d.error) {                                console.log('Category successfully removed from '+pageToCat+'!');                            }                             else {                                console.log('Failed to remove category from '+pageToCat+': '+ d.error.code);                                $('#text-error-output').append('Failed to remove category from '+pageToCat+': '+ d.error.code +' ');                            }                        },                        error: function {                            console.log('Failed to remove category from '+pageToCat+'!'); $('#text-error-output').append('Failed to remove category from '+pageToCat+'! '); }                   });                }                else {                    console.log('Failed to get contents of page: '+ d.error.code);                    $('#text-error-output').append('Failed to get contents of '+pageToCat+': '+ d.error.code +' ');                }            }) .fail(function {               console.log('Failed to get contents of '+pageToCat+'!');                $('#text-error-output').append('Failed to get contents of '+pageToCat+'! ');           });        }        /* currently broken if (actionVal == 3) { //replace category var newCat = prompt('Please enter the replacement category name (no category prefix):'); if (!newCat) { alert('No name entered!'); document.getElementById('start-button').removeAttribute("disabled"); return; }     //get page contents new mw.Api.get({     action: 'query',      prop: 'revisions',      rvprop: 'content',      titles: pageToCat      }) .done(function(d) {	if (!d.error) {         for (var i in d.query.pages) {            if (d.query.pages[i].revisions) {	       var content = d.query.pages[i].revisions[0]["*"];            }            else {	      $('#text-error-output').append('Page '+pageToCat+' does not exist! ');	     return;            }          }         	  //replace old category          var regex = new RegExp ("\\[\\[Category:"+cat+"\\]\\]","gi");          if ($('input[name=mass-categorization-removal]:checked').val == 2)            regex = new RegExp ("\\[\\[Category:"+cat+"\\|?.*?\\]\\]","gi");          newCat = 'Category:'+ newCat.charAt(0).toUpperCase + newCat.substring(1);	  var changedContent = content.replace(regex,+newCat+);	  cat = 'Category:'+ cat.charAt(0).toUpperCase + cat.substring(1);	  //don't submit if new and old contents are equal (no category found)	  if (changedContent.valueOf == content.valueOf) {	    $('#text-error-output').append('Category not found on '+pageToCat+'! ');	   return;	  }	  //submit new page          var config = {            format: 'json',            action: 'edit',            watchlist: 'nochange',            title: pageToCat,            summary: 'Replacing category ['+'['+cat+'|'+cat.substring(9)+']] with ['+'['+newCat+'|'+newCat.substring(9)+']]',            nocreate: '',	    text: changedContent,	    bot: true,            token: mw.user.tokens.get('editToken')          };          if (mw.config.get("wgUserGroups").indexOf('bot') == -1)            delete config.bot;          $.ajax({ url: mw.util.wikiScript('api'), data: config, dataType: 'json', type: 'POST', success: function(d) { if (!d.error) { console.log('Category successfully replaced on '+pageToCat+'!'); } 	       else { console.log('Failed to remove category from '+pageToCat+': '+ d.error.code); $('#text-error-output').append('Failed to replace category on '+pageToCat+': '+ d.error.code +' '); }             },              error: function { console.log('Failed to remove category from '+pageToCat+'!'); $('#text-error-output').append('Failed to replace category on '+pageToCat+'! '); }         });	}	else {	  console.log('Failed to get contents of page: '+ d.error.code);	  $('#text-error-output').append('Failed to get contents of '+pageToCat+': '+ d.error.code +' ');        }     }) .fail(function {      console.log('Failed to get contents of '+pageToCat+'!');       $('#text-error-output').append('Failed to get contents of '+pageToCat+'! ');    });    }   */        setTimeout(init,delay); } }) (this.jQuery, this.mediaWiki);
 * Mass Categorization
 * @description (De)Categorize listed multiple pages.
 * @author Ozuzanna
 * @TODO fix replace
 * Added option for (Dessamator)
 * (function($, mw) {
 * Mass Categorization
 * @description (De)Categorize listed multiple pages.
 * @author Ozuzanna
 * @TODO fix replace
 * Added option for (Dessamator)
 * (function($, mw) {