CSteipp has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/233091

Change subject: Set mobile flag for autologin js
......................................................................

Set mobile flag for autologin js

Set "mobile=1" when doing autologin from a mobile domain with
javascript.

Bug: T100413
Change-Id: Ib88ac635747db823fee7b38d92599ba7d50747bd
---
M CentralAuth.php
M includes/CentralAuthHooks.php
M modules/ext.centralauth.centralautologin.js
A modules/ext.centralauth.centralautologin.mobile.js
A modules/ext.centralauth.utils.js
5 files changed, 84 insertions(+), 48 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth 
refs/changes/91/233091/1

diff --git a/CentralAuth.php b/CentralAuth.php
index 693d5de..516c7d0 100644
--- a/CentralAuth.php
+++ b/CentralAuth.php
@@ -519,9 +519,8 @@
        ),
 ) + $commonModuleInfo;
 
-$wgResourceModules['ext.centralauth.centralautologin'] = array(
-       'scripts' => 'ext.centralauth.centralautologin.js',
-       'styles' => 'ext.centralauth.centralautologin.css',
+$wgResourceModules['ext.centralauth.utils'] = array(
+       'scripts' => 'ext.centralauth.utils.js',
        'position' => 'top',
        'targets' => array( 'mobile', 'desktop' ),
        'dependencies' => array(
@@ -529,6 +528,25 @@
                'mediawiki.jqueryMsg',
        ),
 ) + $commonModuleInfo;
+$wgResourceModules['ext.centralauth.centralautologin'] = array(
+       'scripts' => 'ext.centralauth.centralautologin.js',
+       'styles' => 'ext.centralauth.centralautologin.css',
+       'position' => 'top',
+       'targets' => array( 'mobile', 'desktop' ),
+       'dependencies' => array(
+               'ext.centralauth.utils',
+       ),
+) + $commonModuleInfo;
+$wgResourceModules['ext.centralauth.centralautologin.mobile'] = array(
+       'scripts' => 'ext.centralauth.centralautologin.mobile.js',
+       'styles' => 'ext.centralauth.centralautologin.css',
+       'position' => 'top',
+       'targets' => array( 'mobile', 'desktop' ),
+       'dependencies' => array(
+               'ext.centralauth.utils',
+       ),
+) + $commonModuleInfo;
+
 $wgResourceModules['ext.centralauth.centralautologin.clearcookie'] = array(
        'scripts' => 'ext.centralauth.centralautologin.clearcookie.js',
        'position' => 'top',
diff --git a/includes/CentralAuthHooks.php b/includes/CentralAuthHooks.php
index f67f5f9..8361f9d 100644
--- a/includes/CentralAuthHooks.php
+++ b/includes/CentralAuthHooks.php
@@ -1491,8 +1491,11 @@
                global $wgCentralAuthLoginWiki, $wgCentralAuthUseEventLogging;
                if ( $out->getUser()->isAnon() ) {
                        if ( $wgCentralAuthLoginWiki && wfWikiID() !== 
$wgCentralAuthLoginWiki ) {
-                               $out->addModules( 
'ext.centralauth.centralautologin' );
-
+                               if ( self::isMobileDomain() ) {
+                                       $out->addModules( 
'ext.centralauth.centralautologin.mobile' );
+                               } else {
+                                       $out->addModules( 
'ext.centralauth.centralautologin' );
+                               }
                                // For non-JS clients. Use WikiMap to avoid 
localization of the
                                // 'Special' namespace, see bug 54195.
                                $wiki = WikiMap::getWiki( wfWikiID() );
diff --git a/modules/ext.centralauth.centralautologin.js 
b/modules/ext.centralauth.centralautologin.js
index 7fc71c6..f72dfcb 100644
--- a/modules/ext.centralauth.centralautologin.js
+++ b/modules/ext.centralauth.centralautologin.js
@@ -1,45 +1,3 @@
 ( function ( mw ) {
-       // Are we already logged in?
-       if ( mw.config.get( 'wgUserName' ) !== null ) {
-               return;
-       }
-
-       // Do we already know we're logged out centrally?
-       if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Userlogin' ) {
-               try {
-                       if ( +localStorage.getItem( 'CentralAuthAnon' ) > new 
Date().getTime() ) {
-                               return;
-                       }
-               } catch ( e ) {}
-
-               // Can't use $.cookie(), because we want to check this at the 
top of
-               // the page and that isn't loaded until the bottom.
-               if ( /(^|; )CentralAuthAnon=1/.test( document.cookie ) ) {
-                       return;
-               }
-       }
-
-       // Ok, perform the acutal logged-in check via a <script> tag. The
-       // referenced URL will 302 a few times and then return appropriate
-       // JavaScript to complete the process.
-       var url, params, len, param, i;
-
-       url = mw.config.get( 'wgCentralAuthCheckLoggedInURL' );
-       if ( url ) {
-               url += '&proto=' + encodeURIComponent( 
location.protocol.replace( ':', '' ) );
-               if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 
'Userlogin' ) {
-                       url += '&return=1';
-
-                       params = location.search.slice( 1 ).split( '&' );
-                       len = params.length;
-                       for ( i = 0; i < len; i++ ) {
-                               param = params[i].split( '=' );
-                               param = decodeURIComponent( param[0] );
-                               if ( param === 'returnto' || param === 
'returntoquery' ) {
-                                       url += '&' + params[i];
-                               }
-                       }
-               }
-               mw.loader.load( url );
-       }
+       mw.centralauth.autologin( false );
 }( mediaWiki ) );
diff --git a/modules/ext.centralauth.centralautologin.mobile.js 
b/modules/ext.centralauth.centralautologin.mobile.js
new file mode 100644
index 0000000..7df9505
--- /dev/null
+++ b/modules/ext.centralauth.centralautologin.mobile.js
@@ -0,0 +1,3 @@
+( function ( mw ) {
+       mw.centralauth.autologin( true );
+}( mediaWiki ) );
diff --git a/modules/ext.centralauth.utils.js b/modules/ext.centralauth.utils.js
new file mode 100644
index 0000000..03cec9d
--- /dev/null
+++ b/modules/ext.centralauth.utils.js
@@ -0,0 +1,54 @@
+( function ( $, mw ) {
+       'use strict';
+
+       mw.centralauth = {
+               autologin: function( mobile ) {
+                       // Are we already logged in?
+                       if ( mw.config.get( 'wgUserName' ) !== null ) {
+                               return;
+                       }
+
+                       // Do we already know we're logged out centrally?
+                       if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 
'Userlogin' ) {
+                               try {
+                                       if ( +localStorage.getItem( 
'CentralAuthAnon' ) > new Date().getTime() ) {
+                                               return;
+                                       }
+                               } catch ( e ) {}
+
+                               // Can't use $.cookie(), because we want to 
check this at the top of
+                               // the page and that isn't loaded until the 
bottom.
+                               if ( /(^|; )CentralAuthAnon=1/.test( 
document.cookie ) ) {
+                                       return;
+                               }
+                       }
+
+                       // Ok, perform the acutal logged-in check via a 
<script> tag. The
+                       // referenced URL will 302 a few times and then return 
appropriate
+                       // JavaScript to complete the process.
+                       var url, params, len, param, i;
+
+                       url = mw.config.get( 'wgCentralAuthCheckLoggedInURL' );
+                       if ( url ) {
+                               url += '&proto=' + encodeURIComponent( 
location.protocol.replace( ':', '' ) );
+                               if ( mobile ) {
+                                       url += '&mobile=1';
+                               }
+                               if ( mw.config.get( 
'wgCanonicalSpecialPageName' ) === 'Userlogin' ) {
+                                       url += '&return=1';
+
+                                       params = location.search.slice( 1 
).split( '&' );
+                                       len = params.length;
+                                       for ( i = 0; i < len; i++ ) {
+                                               param = params[i].split( '=' );
+                                               param = decodeURIComponent( 
param[0] );
+                                               if ( param === 'returnto' || 
param === 'returntoquery' ) {
+                                                       url += '&' + params[i];
+                                               }
+                                       }
+                               }
+                               mw.loader.load( url );
+                       }
+               }
+       };
+} ) ( jQuery, mediaWiki );

-- 
To view, visit https://gerrit.wikimedia.org/r/233091
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib88ac635747db823fee7b38d92599ba7d50747bd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: CSteipp <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to