2013-10-28

← Older revision

Revision as of 10:20, October 28, 2013

(One intermediate revision by one user not shown)

Line 2:

Line 2:

 

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

 

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

 

/*global mediaWiki */

 

/*global mediaWiki */



 

 

// Wikia added a safety feature to script pages which prevents site and user scripts

 

// 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

 

// 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

 

// 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.

 

// enough to screw yourself over and be unable to fix it.



(function(window, mw, $) {

+

(function (window, mw, $) {

 

"use strict";

 

"use strict";

 

// Only in User: and MediaWiki:

 

// Only in User: and MediaWiki:

 

if (mw.config.get('skin') !== 'oasis' || // Block doesn't apply in Monobook

 

if (mw.config.get('skin') !== 'oasis' || // Block doesn't apply in Monobook



$.inArray(mw.config.get('wgNamespaceNumber'), [0, 2, 8]) === -1 ||

+

$.inArray(mw.config.get('wgNamespaceNumber'), [2, 8]) === -1 ||



mw.config.get('wgAction') === 'edit' ||

+

mw.config.get('wgAction') === 'edit' ||



!/\.js(?:\/|$)/i.test(mw.config.get('wgPageName')) // JS only

+

!/\.js(?:\/|$)/i.test(mw.config.get('wgPageName')) // JS only



) {

+

) {

 

return;

 

return;

 

}

 

}

Line 20:

Line 19:

 

var i18n = {

 

var i18n = {

 

en: {

 

en: {



editSafe: 'Edit (Safe Mode)'

+

editSafe: 'Edit with js'

 

}

 

}

 

};

 

};

 

i18n = $.extend(i18n.en, i18n[mw.config.get('wgUserLanguage')]);

 

i18n = $.extend(i18n.en, i18n[mw.config.get('wgUserLanguage')]);

 

 



// Get all Edit links

+

// Add the button



var isEdit = /[\?&]action=edit(?:[&#]|$)/, isJs = /\.js[\/\?]/i;

+

$(function ($) {



$(window.document).on('click.ForceScriptsHack', function(ev) {

 



if (ev.target.tagName === 'A' &&

 



isEdit.test(ev.target.href) &&

 



isJs.test(ev.target.href) &&

 



ev.target.getAttribute('data-safe-mode') !== 'yes'

 



) {

 



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);

 



});

 



}

 



});

 



 



// Add Safe mode button

 



$(function($) {

 

 

var $menu = $('.WikiaPageHeader > .wikia-menu-button');

 

var $menu = $('.WikiaPageHeader > .wikia-menu-button');

 

$menu.find('.WikiaMenuElement').append(

 

$menu.find('.WikiaMenuElement').append(



$('<li><a href="#"></a></li>')

+

$('<li><a id="edit-js" href="#"></a></li>')



.children()

+

.children()



.text(i18n.editSafe).prop('href', $menu.find('a[data-id="edit"], a[data-id="source"]').prop('href'))

+

.text(i18n.editSafe).prop('href', $menu.find(



.attr('data-safe-mode', 'yes')

+

'a[data-id="edit"], a[data-id="source"]').prop('href'))



.end()

+

.end()

 

);

 

);

 

});

 

});

 

 



})(window, mediaWiki, jQuery);

+

$('#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));

 

 

 

// </syntaxhighlight>

 

// </syntaxhighlight>

Show more