Anomie has uploaded a new change for review.

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


Change subject: Skip Special:CentralAutoLogin/start for JS anons
......................................................................

Skip Special:CentralAutoLogin/start for JS anons

The call to Special:CentralAutoLogin/start from
ext.centralauth.centralautologin.js isn't strictly necessary, we can
just pass in (via ResourceLoader) the central wiki URL for
Special:CentralAutoLogin/checkLoggedIn, append some parameters, and go
there directly. And apparently that would be a big win cache-wise, so
let's do it.

Bug: 54195
Change-Id: I2817a1b1b01f0719b460b3a745010884b26b1774
---
M CentralAuth.php
M CentralAuthHooks.php
M modules/ext.centralauth.centralautologin.js
3 files changed, 41 insertions(+), 14 deletions(-)


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

diff --git a/CentralAuth.php b/CentralAuth.php
index 3f08459..0026379 100644
--- a/CentralAuth.php
+++ b/CentralAuth.php
@@ -257,6 +257,7 @@
 $wgHooks['UserLogout'][] = 'CentralAuthHooks::onUserLogout';
 $wgHooks['UserLogoutComplete'][] = 'CentralAuthHooks::onUserLogoutComplete';
 $wgHooks['GetCacheVaryCookies'][] = 'CentralAuthHooks::onGetCacheVaryCookies';
+$wgHooks['ResourceLoaderGetConfigVars'][] = 
'CentralAuthHooks::onResourceLoaderGetConfigVars';
 $wgHooks['UserArrayFromResult'][] = 'CentralAuthHooks::onUserArrayFromResult';
 $wgHooks['UserGetEmail'][] = 'CentralAuthHooks::onUserGetEmail';
 $wgHooks['UserGetEmailAuthenticationTimestamp'][] = 
'CentralAuthHooks::onUserGetEmailAuthenticationTimestamp';
diff --git a/CentralAuthHooks.php b/CentralAuthHooks.php
index efeec28..9fa0489 100644
--- a/CentralAuthHooks.php
+++ b/CentralAuthHooks.php
@@ -956,6 +956,32 @@
        }
 
        /**
+        * @param &$vars
+        * @return bool
+        */
+       static function onResourceLoaderGetConfigVars( &$vars ) {
+               global $wgCentralAuthLoginWiki, $wgSecureLogin;
+               if ( $wgCentralAuthLoginWiki && $wgCentralAuthLoginWiki !== 
wfWikiID() ) {
+                       $url = WikiMap::getForeignURL(
+                               $wgCentralAuthLoginWiki, 
'Special:CentralAutoLogin/checkLoggedIn'
+                       );
+                       if ( $url !== false ) {
+                               if ( $wgSecureLogin &&
+                                       wfCanIPUseHTTPS( 
RequestContext::getMain()->getRequest()->getIP() )
+                               ) {
+                                       $url = wfExpandUrl( $url, PROTO_HTTPS );
+                               } else {
+                                       $url = wfExpandUrl( $url, PROTO_CURRENT 
);
+                               }
+                               $vars['wgCentralAuthCheckLoggedInURL'] = 
wfAppendQuery( $url, array(
+                                       'type' => 'script',
+                                       'wikiid' => wfWikiID(),
+                               ) );
+                       }
+               }
+       }
+
+       /**
         * Destroy local login cookies so that remote logout works
         * @param $user User
         * @param $session
diff --git a/modules/ext.centralauth.centralautologin.js 
b/modules/ext.centralauth.centralautologin.js
index 015ed57..a50942f 100644
--- a/modules/ext.centralauth.centralautologin.js
+++ b/modules/ext.centralauth.centralautologin.js
@@ -22,22 +22,22 @@
        // JavaScript to complete the process.
        var url, params, len, param, i;
 
-       url = mw.config.get( 'wgServer' ) +
-               mw.config.get( 'wgArticlePath' ).replace( '$1', 
'Special:CentralAutoLogin/start' );
-       url += ( url.indexOf( '?' ) < 0 ? '?' : '&' ) + 'type=script';
-       if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Userlogin' ) {
-               url += '&return=1';
+       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];
+                       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.loader.load( url );
 }( mediaWiki ) );

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

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

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

Reply via email to