MediaWiki:UnsafeScripts/code.js

/*jshint jquery:true browser:true smarttabs:true */ /*global mediaWiki */

// Wikia added a safety feature to script pages which prevents site and user scripts // from running on those pages. That's generally a good thing but power users find it // annoying. THIS SCRIPT IS ONLY FOR PEOPLE WHO KNOW WHAT THEY ARE DOING. It is easy // enough to screw yourself over and be unable to fix it. (function (window, mw, $) {	"use strict";	// Only in User: and MediaWiki:	if ( mw.config.get('skin') !== 'oasis' || // Block is Oasis only $.inArray(mw.config.get('wgNamespaceNumber'), [2, 8]) === -1 || mw.config.get('wgAction') === 'edit' || $('#edit-js').length || // Double runs !/\.js(?:\/|$)/i.test(mw.config.get('wgPageName')) // JS only ) {		return;	}

var i18n = { en: { editSafe: 'Edit with JS' },		es: { editSafe: 'Editar con JavaScript' },		be: { editSafe: 'Рэдагаваць з дапамогай JS' },		ru: { editSafe: 'Редактировать с помощью JS' },		uk: { editSafe: 'Редагувати з допомогою JS' }	};	i18n = $.extend(i18n.en, i18n[mw.config.get('wgUserLanguage')]);

// Add the button $(function ($) {		var $menu = $('.page-header__contribution-buttons');		$menu.find('.wds-list').append( $('') .children .text(i18n.editSafe).prop('href', $menu.find( '#ca-edit, #ca-viewsource').prop('href')) .end );	});

$('#edit-js').on('click.ForceScriptsHack', function (ev) {		ev.preventDefault;		var w = window.open(ev.target.href);		$(w).load(function callback { $(w).off('load', callback); // Direct the loader to request the site scripts w.mediaWiki.loader.load('site'); // We can't load the user scripts this way because RL gets confused. // It needs a user=UserName to work. var s = w.document.createElement('script'); s.type = 'text/javascript'; s.src = w.mediaWiki.config.get('wgLoadScript') + '?debug=false&lang=' + w.mediaWiki.config.get('wgUserLanguage') + '&skin=' + w.mediaWiki.config.get('skin') + '&only=scripts&modules=user&user=' + w.encodeURIComponent(w.mediaWiki.config					.get('wgUserName')) + '&*';			w.document.body.appendChild(s); });	}); }(window, mediaWiki, jQuery));