MediaWiki:LangSetup.js

/** * Name:       LangSwitch * Description: Creates MediaWiki:Lang/xx pages required for *             Template:LangSwitch to work * Version:    v1.0 * Author:     KockaAdmiralac <1405223@gmail.com> */ $.get(mw.util.wikiScript('load'), {   mode: 'articles',    articles: 'u:dev:MediaWiki:Custom-language-code-sorting',    only: 'styles' }, function(d) {    var languages = JSON.parse(d.replace(/\/\*.*\*\//g, '')), api,        contentLang = mw.config.get('wgContentLanguage'),        token = mw.user.tokens.get('editToken');    function log(text) {        $('.langswitch-log').append(' ' + text);   }    function createPage {        if (!api) {            api = new mw.Api;        }        var language = languages.shift,            title = 'MediaWiki:Lang' + (language === contentLang ? '' : '/' + language);       if (language) {            api.post({ action: 'edit', title: title, text: language, bot: true, minor: true, token: token, summary: 'Creating page required for Template:LangSwitch to work' }).done(function(d) { var link = mw.html.element('a', { href: mw.util.getUrl(title) }, title); if (d.error) { log('An error occurred while creating ' + link + ': ' + d.error.code); } else if (d.edit.nochange === '') { log(link + ' already exists!'); } else { log(link + ' successfully created!'); }               createPage; });       } else {            log('Done installing!');        }    }    function click {        $.showCustomModal( 'Install LangSwitch', $(' ', {               'class': 'langswitch-log',                text: 'Click on the "Execute" button to start creating MediaWiki pages required for LangSwitch to work. Results will be logged here.'            }).prop('outerHTML'), {               id: 'langswitch-modal', width: 500, buttons: [ {                       id: 'langswitch-execute', message: 'Execute', defaultButton: true, handler: createPage },                   {                        id: 'langswitch-close', message: 'Close', handler: function { $('#langswitch-modal').closeModal; }                   }                ]            }        );    }    $('#my-tools-menu').append( $('').append(           $('', { 'class': 'langswitch-link', text: 'Install LangSwitch' }).click(click).wrap('')       ) ); }); importArticle({   type: 'style',    article: 'u:dev:MediaWiki:LangSwitch/code.css' });