User:Özün Oldun/global.js

////////////////////////////////////////////////////////////////////////// /************************************************************************/ /************************** Modified Wikimarks **************************/ /************************ Authors — Cqm & Pecoes ************************/ /***************** @http://dev.wikia.com/wiki/Wikimarks *****************/ /*************** @http://dev.wikia.com/wiki/User_talk:Cqm ***************/ /************** @http://dev.wikia.com/wiki/User_talk:Pecoes *************/ /************************************************************************/ ////////////////////////////////////////////////////////////////////////// /*global importStylesheetURI */ /*jshint bitwise:true, camelcase:true, curly:true, eqeqeq:true, es3:false, forin:true, immed:true, indent:4, latedef:true, newcap:true, noarg:true, noempty:true, nonew:true, plusplus:true, quotmark:single, undef:true, unused:true, strict:true, trailing:true, browser:true, devel:false, jquery:true, onevar:true 'use strict'; var conf = mw.config.get([           'skin',            'stylepath',            'wgPageName',            'wgServer',            'wgUserName'        ]), testUser = false; /**     * Calculate certain styles dynamically depending on the environment *   function calcCss { var chevCss, h;       // styles for chevron colour chevCss = '#wikimarks .chevron-right { border-left-color: ' + $('#wikimarks .subnav-3a').css('color') + '; }';       mw.util.addCSS(chevCss); // set position of level 3 menus // set border of level 4 menus (and remove weird padding) $('#wikimarks').find('.subnav-3 > li').one('mouseover', function {            // we have to wait until one of the menus are open to calculate the            // positioning, so wait until that happens, and then prevent it            // happening more than once            // else debugging css becomes a nightmare            if (h) {                return;            }            var $this = $(this),                $parent = $this.parent('ul'),                borderColor = $parent.css('border-left-color'),                borderStyle = $parent.css('border-left-style'),                borderWidth = $parent.css('border-left-width'),                border = borderWidth + ' ' + borderStyle + ' ' + borderColor,                css,                i;            h = $(this).height;            css = '#wikimarks .subnav-4 { border: ' + border + '; padding: 0; }\n';            for (i = 0; i < 30; i += 1) { css += '#wikimarks .subnav-3 li:nth-child(' + (i + 1) +                   ') ul { top: ' + Math.round(h * i)  + 'px !important; }\n'; }           mw.util.addCSS(css); });   }    /**     * Insert Wikimarks into the DOM and attach the relevant events     *    function addHtml($wikimarks) {        var $level2 = $wikimarks.find('.subnav-2-item'),            $wikinavLi = $('#WikiHeader').find('.nav-item');        $wikinavLi            // force wikimarks on top (easier than tracking which is currently open)            .removeClass('marked')            // and insert into the DOM            .first.replaceWith($wikimarks);        $wikimarks            .add($wikinavLi)            .off('mouseover')            .on('mouseover', function  { var $this = $(this), $siblings = $this.siblings; $siblings.removeClass('marked'); $this.addClass('marked'); $siblings .find('.marked2').removeClass('marked2') .find('.subnav-3').hide; });       $level2            .on('mouseover', function  { $('.marked2') .removeClass('marked2') .find('.subnav-3').hide; $(this).has('ul').addClass('marked2'); })           .on('mouseout', function  { $(this) .removeClass('marked2') .find('.subnav-3').hide; });       calcCss;        // everything is now done        // so fire an event so people can interact/extend it further        mw.hook('wikimarks.loaded').fire($wikimarks);    }    /**     * Prepare the parsed HTML and attach to the DOM     *    function prepareHtml(html) {        var $wikimarks = $('')                .attr('id', 'wikimarks')                // make sure to select the tab after loading                .addClass('nav-item marked wikimarks')                .append( $('') .attr(                           'href',                            'http://dev.wikia.com' +                                mw.util.wikiGetlink('User:' + conf.wgUserName + '/Wikimarks')                        ) .addClass('wikimarks-modded') .append(                           'Wikimarks'                        ), html );       // add classes to elements        $wikimarks            .children('ul').addClass('subnav-2 accent')                .children('li').addClass('subnav-2-item')                    .children('a').addClass('subnav-2a')                    .siblings('ul').addClass('subnav-3 subnav')                        .children('li').addClass('subnav-3-item')                            .children('a').addClass('subnav-3a')                            .siblings('ul').addClass('subnav-4')                                .children('li').addClass('subnav-4-item')                                    .children('a').addClass('subnav-4a');        // add chevrons        $wikimarks.find('.subnav-3').siblings('.subnav-2a').each(function  { var $this = $(this), $chevron = $(' ') .addClass('chevron') .attr('src', 'data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D'); $this.append($chevron); });       $wikimarks.find('.subnav-4').siblings('.subnav-3a').each(function  { var $this = $(this), $chevron = $(' ') .addClass('chevron-right') .attr('src', 'data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D'); $this.append($chevron); });       // remove href from text converted to links        $wikimarks.find('a[href="/wiki/"]')            .removeAttr('href')            .css('cursor', 'pointer');        $wikimarks.find('a')            // titles don't add annything to the links            .removeAttr('title')            // remove external link class for ease of reading the source html            .removeClass('extiw');        // kill chat opening in a new window        $wikimarks.find('.WikiaChatLink').removeClass('WikiaChatLink');        if (testUser) {            return;        }        addHtml($wikimarks);    }    /**     * Pass the preprocess wikimarks to action=parse to be converted into wikitext     *    function parseWikimarks(data) {        var params = {            action: 'parse',            text: data        };        (new mw.Api)            .post(params)            .done(function (data) { var text = data.parse.text['*']; // remove preprocessor comment // should be able to hide it in api config // but that's broken in mw1.19 text = text.replace(//g, '').trim; if (testUser) { mw.log(text); }               prepareHtml(text); });   }    /**     * Preprocesses a wikimarks page to make it compatible with the wikitext parser     *    function preprocessData(data) {        data = data.trim.split(/\n+/);        var invalidLink = false,            parsed = [],            // handles /wiki/, index.php, api.php, wikia.php and /d (discussions)            relativeUrlRe = /\/(wiki\/|(?:index|api|wikia)\.php|d)/;        data.forEach(function (elem) { // ignore comments if (elem.indexOf('//') === 0 || elem.indexOf('#') === 0) { return; }           // handle external links elem = elem.replace(/^(\*+)\s*\[([^\s]+)\s+(.+?)\]\s*$/, function (_, p1, p2, p3) {               // handle query strings                if (p2.indexOf('?') === 0) {                    return p1 + '[ ' + p3 + ']';                }                // allow appending to existing query strings as well                if (p2.indexOf('&') === 0) {                    return p1 + '[' + location.href + p2 + ' ' + p3 + ']';                }                // handle relative URLs                if (p2.search(relativeUrlRe) === 0) {                    p2 = conf.wgServer + p2;                }                // else just return it unchanged                return p1 + ' [' + p2 + ' ' + p3 + ']';            }); // don't touch raw html // assumes that all html will begin with a tag, e.g. <span... if (!/^\*+\s*</.test(elem)) { // parse old style links to wikitext for backwards compatibility elem = elem.replace(/^(\*+)\s*([^\[]+?)\s*=\s*(.+?)\s*$/, function (_, p1, p2, p3) {                   // handle absolute URLs                    // 'http://' or 'https://' or '//'                    if (p3.search(/(?:https?:)?\/\//) === 0) {                        return p1 + ' [' + p3 + ' ' + p2 + ']';                    }                    // handle query strings                    if (p3.indexOf('?') === 0) {                        return p1 + '[ ' + p2 + ']';                    }                    // allow appending to existing query strings as well                    if (p2.indexOf('&') === 0) {                        return p1 + '[' + location.href + p2 + ' ' + p3 + ']';                    }                    // attempt to fix instances of Foo?bar=baz                    // domain added below                    if (p3.indexOf('?') > -1) {                        p3 = '/wiki/' + p3; }                   // handle relative URLs if (p3.search(relativeUrlRe) === 0) { p3 = conf.wgServer + p3; return p1 + ' [' + p3 + ' ' + p2 + ']'; }                   // ## BREAKING CHANGE ## // don't allow 'javascript:' urls // ridiculously difficult to parse these in js without using `eval` if (p3.search(/(?:javascript:)?(?:url|win)\(/) === 0) {                       p3 = '#invalidLink';                        invalidLink = true;                    }                    // else we expect a normal wikilink                    return p1 + ' ' + p2 + '';                }); }           // remove css comment // caused by loading wikimarks config through RL and pretending it's CSS if (elem.search(/^\/\*.+?\*\/$/) === 0) { elem = ''; }           // substitute in global variables // syntax: {$VAR} where VAR is a global variable // @todo limit to stuff available in mw.config? elem = elem.replace(/\{\$(.+?)\}/g, function (_, p1) {               // fix for properties of globals                var parts = p1.split('.'),                    test = window,                    prop,                    i;                for (i = 0; i < parts.length; i += 1) {                    prop = parts[i];                    // @todo how secure is this?                    if (test.hasOwnProperty(prop)) {                        test = test[prop];                    } else {                        break;                    }                }                if (['string', 'number'].indexOf(typeof test) > -1) {                    return test;                }            }); // make simple text strings into a null link so it doesn't break the styling elem = elem.replace(/^(\*+)\s*([A-Za-z0-9\s]+)\s*$/, '$1 #|$2'); parsed.push(elem); });       data = parsed.join('\n').trim;        mw.log(data);        if (invalidLink) {            // @todo do something        }        return data;    }    /**     * Load the users wikimarks     *    function loadWikimarks(username) {        var load = mw.util.wikiScript('load'),            params = {                mode: 'articles',                only: 'styles',                debug: 'true',                // don't encode anything in the username here, $.get does it anyway                // otherwise stuff gets encoded twice and no results are returned                articles: 'u:dev:User:' + (username || conf.wgUserName).replace(/ /g, '_') + '/Wikimarks'            };        if (username) {            testUser = true;        }        mw.log('params', params);        $.get(load, params).done(function (data) { if (!data) { // just in case there was an error in the api request mw.log(this); }           data = preprocessData(data); parseWikimarks(data); });   }    /**     * Calculates whether the body and wikinav are light or dark     * Used to determine which colour star to use in the wikimarks logo     *    function calcBrightness {        var $header = $('#WikiHeader'),            bgColor,            $navBg,            menuColor,            $pageHeader;        function isBright (color) {            var m = color.match(/(?:([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2}))|(?:(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3}))/),                rgb;            if (!m) {                return false;            }            rgb = m[1] ?                { r: parseInt(m[1], 16), g: parseInt(m[2], 16), b: parseInt(m[3], 16) } :                { r: parseInt(m[4], 10), g: parseInt(m[5], 10), b: parseInt(m[6], 10) };            return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000 >= 128;        }        bgColor = $('#WikiaPageBackground').css('background-color'); if (bgColor === 'transparent') { bgColor = $('#WikiaPage').css('background-color'); }       $header.addClass(isBright(bgColor) ? 'bg-bright' : 'bg-dark'); $navBg = $header.find('.navbackground'); menuColor = bgColor; if ($navBg.length) { menuColor = $navBg.css('background-color'); } else { $pageHeader = $('#WikiaPageHeader'); if ($pageHeader.length) { menuColor = $pageHeader.css('border-bottom-color'); }       }        $header.addClass(isBright(menuColor) ? 'menu-bright' : 'menu-dark'); }   /**     * Shows loading status until the wikimarks have loaded *   function showLoading { $('.WikiNav .nav-item').first .css({               backgroundImage: 'url("' + conf.stylepath + '/common/images/ajax.gif")',                backgroundPosition: 'center center',                backgroundRepeat: 'no-repeat'            }) .children('a') .css('color', 'transparent'); }   /**     * Load stylesheets *   function loadStyles { importArticle({ 'type': 'style', 'article': 'u:dev:MediaWiki:Wikimarks/code.css' }); }   /**     * Checks for the correct environment before allowing the script to continue *   function init { // monobook isn't supported if (['oasis', 'wikia'].indexOf(conf.skin) === -1) { return; }       // prevent anyone trying to load this for anons if (!conf.wgUserName) { return; }       if (!$('#WikiHeader .WikiNav').length) { console.log('Wikimarks: wikinav not found, aborting...'); return; }       loadStyles; showLoading; calcBrightness; loadWikimarks; }   mw.loader.using(['mediawiki.api', 'mediawiki.util'], function  {        $(init);    }); dev.loadWikimarks = loadWikimarks; }(this.jQuery, this.mediaWiki, this.dev = this.dev || {})); //End MWM*/ ////////////////////////////////////////////////////////////////////////// /************************************************************************/ /*********************** 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([        'wgServer',        'wgArticlePath',        'wgUserLanguage'    ]), i18n = { 'en': { title: 'Quick Links', mpTitle: 'Personal', wwTitle: 'MediaWiki', 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 .module h2 {' +                'margin-bottom: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(           $(' ')                .attr('class', 'module railModule')                .attr('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(           $(' ')                .attr('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 (            mwVariables.wgServer.substr(7, mwVariables.wgServer.length-17) !== 'community' &&            ( (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 CQL*/ ////////////////////////////////////////////////////////////////////////// /************************************************************************/ /*************************** Modified Rollback **************************/ /*************************** Author — Ozuzanna **************************/ /*************** @http://dev.wikia.com/wiki/User:Ozank_Cx ***************/ /************************************************************************/ ////////////////////////////////////////////////////////////////////////// mw.loader.using('mediawiki.api', function {
 * (function ($, mw, dev) {

var main = { init: function { //check if user has rollback permission already var userGroups = ["rollback","content-moderator","sysop","vstf","helper","staff"], ownGroups = mw.config.get('wgUserGroups'), hasPermissionAlready = false;

for (var i in ownGroups) { if (userGroups.indexOf(ownGroups[i]) !== -1) { hasPermissionAlready = true; break; }		}

if (hasPermissionAlready) 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; API.post({		action: 'edit',		title: page,		text: text,		summary: 'Reverted edits by ' + user + ' (talk | block) to last version by ' + user2 + '',		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*/ ////////////////////////////////////////////////////////////////////////// /************************************************************************/ /***************************** Miscellaneous ****************************/ /************************************************************************/ ////////////////////////////////////////////////////////////////////////// /* Rail Priority */ $(function { mw.hook('DiscordIntegrator.added').add(function {       $('.DiscordIntegratorModule').appendTo('#WikiaRail');    }); });//End RP*/

/////////////////////////////////////////////////////////////////////////// /*************************************************************************/ /************************* Import Configurations *************************/ /*************************************************************************/ /////////////////////////////////////////////////////////////////////////// WHAMDelay = 1000;

/////////////////////////////////////////////////////////////////////////// /*************************************************************************/ /******************************** Imports ********************************/ /*************************************************************************/ /////////////////////////////////////////////////////////////////////////// importArticles({   type: 'script',    articles: [        'u:dev:AjaxUndo/code.js',        'u:dev:AutoEditDropdown/code.js',        'u:dev:DisableCode/code.js',        'u:dev:FindAndReplace/code.js',        'u:dev:MarkBlocked.js',        'u:dev:NullEditButton/code.js',        'u:dev:PortableCSSPad/code.js',        'u:dev:QuickToolsv2/code.js',        'u:dev:RTCL.js',        //'u:dev:ShowUserGroups.js',        'u:dev:SkinSwitchButton/code.js',        'u:dev:UnsafeScripts/code.js',        'u:dev:UserActivityTab/code.js',        'u:dev:WHAM/code.2.js'    ] });//End Imports*/