User:TotallyEthan/global.js

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

require([   'wikia.window',    'jquery',    'mw',    'BannerNotification' ], function (window, $, mw, BannerNotification) {    'use strict';    // Config    var config = mw.config.get([ 'wgCityId', 'wgFormattedNamespaces', 'wgUserName' ]);   // Load Protection    if ( window.QuickCreateUserPageLoaded || config.wgCityId === '65099' || config.wgUserName === null ) {       return;    }    window.QuickCreateUserPageLoaded = true;    // Variables    var Api,        i18n,        page = config.wgFormattedNamespaces[2] + ':' + config.wgUserName;    /**     * @class Main     * @classdesc Central QuickCreateUserPage class     */    var Main = {        /**         * @method init         * @description Initiates the script and creates the button         * @param {String} i18nData - Variable for I18n-js         */        init: function (i18nData) {            i18n = i18nData;            Api = new mw.Api;            $('.wds-global-navigation__user-menu > div >.wds-list').append( $('', {                   'id': 'quick-cup',                    'class': 'QuickCreateUserPage'                }).append(                    $('', { 'title': i18n.msg('button-tooltip-text').plain, 'text': i18n.msg('button-link-text').plain, 'href': '#', 'click': Main.createPage })               )            );        },        /**         * @method createPage         * @description Analyzes the data and acts accordingly         */        createPage: function  {            if (window.qtEnableUserPageOverwrite) {                Main.makeEdit;            } else {                Api.get({ action: 'query', titles: page }).done(function(d) { if (d.query.pages[-1]) { Main.makeEdit; } else { if (                           confirm( i18n.msg('cup-confirm').plain ) === true                       ) { Main.makeEdit; } else { Main.showResult('cup-error-exists'); }                   }                });            }        },        /**         * @method makeEdit         * @description Edits the page         */        makeEdit: function  {            Api.post({ action: 'edit', title: page, text: window.qtUserPageTemplate || '',               summary: "Inserting User Template (automatic)" , token: mw.user.tokens.get('editToken'), watchlist: 'preferences' }).done(function(d) { if (d.edit.result === 'Success') { Main.showResult('cup-success-text', true); } else { Main.showResult('cup-error-failed'); }           }).fail(function(d) { Main.showResult('cup-error-failed'); });       },        /**         * @method showResult         * @description Outputs a BannerNotification         * @param {String} msg - The message to output         * @param {String} confirm - Whether the result is a success         */        showResult: function (msg, confirm) {            new BannerNotification( i18n.msg(msg).escape, confirm ? 'confirm' : 'error' ).show;       }    };    // Load Script    mw.hook('dev.i18n').add(function(i18n) { $.when(           i18n.loadMessages('QuickCreateUserPage'),            mw.loader.using('mediawiki.api')        ).done(Main.init); });   // Import    importArticle({ type: 'script', article: 'u:dev:MediaWiki:I18n-js/code.js' }); }); }; window.qtEnableUserPageOverwrite = true;