User:Ursuul/common.js

////////////////////////////////////////////////////////////////////////// /************************************************************************/ /*********************** Modified Code Quick Links **********************/ /*********************** Author — Count of Howard ***********************/ /********* @http://dev.wikia.com/wiki/User_talk:Count_of_Howard *********/ /************************************************************************/ ////////////////////////////////////////////////////////////////////////// (function {   if ($('#mwModule').length) {        return;    }    var mwVariables = mw.config.get([ 'wgCityId', 'wgServer', 'wgArticlePath', 'wgUserLanguage' ]),   i18n = {        'en': { //English            title: 'Code Quick Links',            wwTitle: 'MediaWiki Files',            mpTitle: 'Personal Files',            hCSS: 'Chat.css',            hJS: 'Chat.js',            cCSS: 'Common.css',            cJS: 'Common.js',            mCSS: 'Monobook.css',            mJS: 'Monobook.js',            wCSS: 'Wikia.css',            wJS: 'Wikia.js',            gCSS: 'Global.css',            gJS: 'Global.js',            iJS: 'ImportJS',            sJS: 'JS Pages'        },        'be': { //Belarusian            title: 'Код хуткіх спасылак',            wwTitle: 'Старонкі MediaWiki',            mpTitle: 'Асабістыя старонкі',            hCSS: 'Chat.css',            hJS: 'Chat.js',            cCSS: 'Common.css',            cJS: 'Common.js',            mCSS: 'Monobook.css',            mJS: 'Monobook.js',            wCSS: 'Wikia.css',            wJS: 'Wikia.js', gCSS: 'Global.css', gJS: 'Global.js', iJS: 'ImportJS', sJS: 'JS Pages' },       'pl': { //Polish title: 'Szybkie linki kodów', wwTitle: 'Pliki MediaWiki', mpTitle: 'Pliki osobiste', hCSS: 'Chat.css', hJS: 'Chat.js', cCSS: 'Common.css', cJS: 'Common.js', mCSS: 'Monobook.css', mJS: 'Monobook.js', wCSS: 'Wikia.css', wJS: 'Wikia.js', gCSS: 'Global.css', gJS: 'Global.js', iJS: 'ImportJS', sJS: 'JS Pages' },       'pt-br': { //Brazilian Portuguese title: 'Links rápidos de código', wwTitle: 'Arquivos MediaWiki', mpTitle: 'Arquivos pessoais', hCSS: 'Chat.css', hJS: 'Chat.js', cCSS: 'Common.css', cJS: 'Common.js', mCSS: 'Monobook.css', mJS: 'Monobook.js', wCSS: 'Wikia.css', wJS: 'Wikia.js', gCSS: 'Global.css', gJS: 'Global.js', iJS: 'ImportJS', sJS: 'JS Pages' },       'ru': { //Russian title: 'Код быстрых ссылок', wwTitle: 'Страницы MediaWiki', mpTitle: 'Личные страницы', hCSS: 'Chat.css', hJS: 'Chat.js', cCSS: 'Common.css', cJS: 'Common.js', mCSS: 'Monobook.css', mJS: 'Monobook.js', wCSS: 'Wikia.css', wJS: 'Wikia.js', gCSS: 'Global.css', gJS: 'Global.js', iJS: 'ImportJS', sJS: 'JS Pages' },       'sv': { //Swedish title: 'Källkod Snabba Hyperlänkar', wwTitle: 'MediaWiki Filer', mpTitle: 'Personliga Filer', hCSS: 'Pratstund.css', hJS: 'Pratstund.js', cCSS: 'Gemensam.css', cJS: 'Gemensam.js', mCSS: 'Monobook.css', mJS: 'Monobook.js', wCSS: 'Wikia.css', wJS: 'Wikia.js', gCSS: 'Global.css', gJS: 'Global.js', iJS: 'ImportJS', sJS: 'JS Pages' },       'uk': { //Ukrainian title: 'Код швидких посилань', wwTitle: 'Сторінки MediaWiki', mpTitle: 'Особисті сторінки', hCSS: 'Chat.css', hJS: 'Chat.js', cCSS: 'Common.css', cJS: 'Common.js', mCSS: 'Monobook.css', mJS: 'Monobook.js', wCSS: 'Wikia.css', wJS: 'Wikia.js', gCSS: 'Global.css', gJS: 'Global.js', iJS: 'ImportJS', sJS: 'JS Pages' },   },    lang = i18n[mwVariables.wgUserLanguage] || i18n[mwVariables.wgUserLanguage.split('-')[0]] || i18n.en, mwFiles = [ {           title: lang.mpTitle, pages: [ {                   url:'global.js', name:lang.gJS },               {                    url:'global.css', name:lang.gCSS },               {                    url:'common.js', name:lang.cJS },               {                    url:'wikia.js', name:lang.wJS },               {                    url:'monobook.js', name:lang.mJS },               {                    url:'chat.js', name:lang.hJS },               {                    url:'common.css', name:lang.cCSS },               {                    url:'wikia.css', name:lang.wCSS },               {                    url:'monobook.css', name:lang.mCSS },               {                    url:'chat.css', name:lang.hCSS }           ]        },        {            title: lang.wwTitle, pages: [ {                   url:'Special:JSPages', name:lang.sJS },               {                    url:'MediaWiki:ImportJS', name:lang.iJS },               {                    url:'MediaWiki:Common.js', name:lang.cJS },               {                    url:'MediaWiki:Wikia.js', name:lang.wJS },               {                    url:'MediaWiki:Monobook.js', name:lang.mJS },               {                    url:'MediaWiki:Chat.js', name:lang.hJS },               {                    url:'MediaWiki:Common.css', name:lang.cCSS },               {                    url:'MediaWiki:Wikia.css', name:lang.wCSS },               {                    url:'MediaWiki:Monobook.css', name:lang.mCSS },               {                    url:'MediaWiki:Chat.css', name:lang.hCSS }           ]        }    ];    function init { mw.util.addCSS(           '.WikiaRail .rail-module h2 {' +                'margin-bottom: 0;' +            '}' +            '#mwModule {' +                'background: transparent;' +                'border: none;' +                'padding:20px 0 0;' +            '}' +            '#mwModuleContent {' +                'position: relative;' +            '}' +            '#mwModuleDiv-0 {' +                'float:left;' +            '}' +            '#mwModuleDiv-1 {' +                'float:right;' +            '}' +            '#mwModuleTitle {' +                'font-size: 14px;' +                'white-space: pre-line;' +            '}' +            '#mwModuleText {' +                'display: block;' +                'text-align: left;' +                'font-size: 12px;' +                'font-weight: bold;' +                'margin: 5px 0;' +                'padding: 0 20px;' + '}'       );        $('#WikiaRail').prepend( $(' ', {               'class': 'module rail-module',                id: 'mwModule'            }) .html(                   ' ' + lang.title + ' ' +                    ' '                ) );       for (var i = 0; i < mwFiles.length; i++) {            columns(i);            for (var j = 0; j < mwFiles[i].pages.length; j++) {                instances(i, j);            }        }    }    function columns(i) {        $('#mwModuleContent').append( $(' ', { id: 'mwModuleDiv-' + i }) .html(                   $(' ')                        .attr('id', 'mwModuleTitle')                        .text(mwFiles[i].title)                ) );   }    function instances(i, j) {        var address = mwVariables.wgServer + mwVariables.wgArticlePath;        if (i === 0) {            address = address.replace( "$1", 'Special:MyPage/' + mwFiles[i].pages[j].url);        } else if (i === 1) {            address = address.replace( "$1", mwFiles[i].pages[j].url);        }        if ( //Yikes mwVariables.wgCityId !== 177 && (               (i === 0 && j === 0) ||                 (i === 0 && j === 1)            ) ) {           address = 'http://community.wikia.com/wiki/Special:MyPage/' + mwFiles[i].pages[j].url;        }        $('#mwModuleDiv-' + i).append( $('') .attr('id', 'mwModuleText') .attr('href', address) .text(mwFiles[i].pages[j].name) );   }    init; });//End MCQL*/

////////////////////////////////////////////////////////////////////////// /************************************************************************/ /*************************** Modified Rollback **************************/ /*************************** Author — Ozuzanna **************************/ /*************** @http://dev.wikia.com/wiki/User:Ozank_Cx ***************/ /************************************************************************/ ////////////////////////////////////////////////////////////////////////// mw.loader.using('mediawiki.api', function {

var main = { init: function { //check if conventional rollback links are present if ($('.mw-rollback-link').length === 0) return; if (mw.config.get('wgAction') == "history" && $('#pagehistory li').length > 1) $('#pagehistory li:first .mw-history-undo a').before(' rollback | '); else if (mw.config.get('wgCanonicalSpecialPageName') == "Contributions") { $('#mw-content-text ul').find('li').each(function {				if ($(this).find('.mw-uctop').length)					$(this).append(' [rollback] ');			}); }		else if (($.getUrlVar('diff') || $.getUrlVar('oldid')) && $('#differences-nextlink').length === 0) $('.mw-usertoollinks:last').after('   [rollback] '); $('.mw-custom-rollback-link a').click(function {			main.getRevisionIdAndContent($(this).attr('data-id'));			$(this).parent.remove;		}); },	getRevisionIdAndContent: function(title) { var API = new mw.Api; API.get({		action: 'query',		prop: 'revisions',		titles: title,		rvprop: 'user|ids',		rvlimit: 500,		cb: new Date.getTime		}) .done(function(d) {			if (!d.error) {				var revisions;				for (var i in d.query.pages) {					revisions = d.query.pages[i].revisions;				}				var currentUser = revisions[0].user, //current user rollbacking from				lastUser,				revId;				for (var i in revisions) {					if (revisions[i].user != currentUser) {						lastUser = revisions[i].user; //remember last author						revId = revisions[i].revid; //get revision to revert to						break;					}				}				if (lastUser) {					API.get({ action: 'query', prop: 'revisions', rvprop: 'content', revids: revId, cb: new Date.getTime })					.done(function(d) { if (!d.error) { var content = ""; //can be no content on page so initialise empty as failsafe for (var i in d.query.pages) { if (d.query.pages[i].revisions) content = d.query.pages[i].revisions[0]["*"]; }							main.performRollback(title,content,currentUser,lastUser); }						else new BannerNotification('Unable to rollback (failed to get page content): ' + d.error.code,'error').show; })					.fail(function { new BannerNotification('Unable to rollback: failed to get page content!','error').show; });				}				else					new BannerNotification('Unable to rollback: no different editor found!','error').show;			}			else				new BannerNotification('Unable to rollback (failed to get revisions): ' + d.error.code,'error').show;		}) .fail(function {			new BannerNotification('Unable to rollback: failed to get revisions!','error').show;		}); },	performRollback: function(page,text,user,user2) { var API = new mw.Api, summary = 'Reverted edits by ' + user + ' (talk | block) to last version by ' + user2 + ''; if (summary.length > 150) summary = 'Reverted edits by ' + user; API.post({		action: 'edit',		title: page,		text: text,		summary: summary,		token: mw.user.tokens.values.editToken		}) .done(function(d) {			if (!d.error) {				new BannerNotification('Rollback successful!','confirm').show;							}			else				new BannerNotification('Unable to rollback (failed to publish edit): ' + d.error.code,'error').show;		}) .fail(function {			new BannerNotification('Unable to rollback: failed to publish edit!','error').show;		}); } };

main.init; });//End MR*/