User:Kww-newbie/common.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
The accompanying .css page for this skin can be added at User:Kww-newbie/common.css. |
// Though VisualEditor is already available for all users (including anonymous users),
// many pages cached for anonymous users don't have the Edit tab. This ensures it is
// consistently available for all pages for anonymous users while the cache rolls over.
// It has no effect on logged-in users or pages edited after VE was enabled.
// This does NOT override namespace, skin and user conditions as those are evaluated
// inside the init module.
// * Remove after 1 September 2013.
// * Keep the below mw.loader.load call outside mw.loader.using!
// --
// Hi again, so yeah, mw.loader.load queue is cached for anonymous users and stuck
// in a state where VE isn't loaded yet. However the init script bravely checks the
// 'visualeditor-enable' preference which also didn't exist yet, so it still fails.
// Here we set that preference to 1 if it is undefined, which is only the case for
// anonymous users viewing pages that got last purged before July 2013.
// * Remove after 1 September 2013.
// * Keep mw.user.options.set before mw.loader.load
mw.loader.using( ['mediawiki.util', 'jquery.client','mediawiki.api'],
function ()
{
if (autoconfirmed() === 0)
{
mw.user.options.set('visualeditor-enable',0);
if ( mw.config.get( 'wgUserName' ) != null )
{
var api = new mw.Api();
api.get({ action: 'tokens', type: 'options' }).done(function (json)
{
api.post(
{
action: 'options',
change: 'visualeditor-betatempdisable=1',
token: json.tokens.optionstoken
});
});
}
}
function autoconfirmed()
{
var userGroups = mw.config.get( 'wgUserGroups' );
if ( userGroups )
{
for ( var i = 0; i < userGroups.length; i++ )
{
if ( userGroups[i] === 'autoconfirmed' )
{
return(1);
}
}
}
return(0);
}
}
);
mw.loader.load( 'ext.visualEditor.viewPageTarget.init' );