User:Kww-newbie/common.js

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