20after4 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/236822
Change subject: Converted api-token store to CentralAuthUser::getSessionCache()
......................................................................
Converted api-token store to CentralAuthUser::getSessionCache()
Bug: T108253
Change-Id: I4d42aa2135c7d2b8ace3084d80c317a0a024ceff
(cherry picked from commit b8c385296ecb5620824146be24f76a20236f6e4b)
---
M includes/CentralAuthHooks.php
M includes/CentralAuthUser.php
M includes/api/ApiCentralAuthToken.php
3 files changed, 18 insertions(+), 15 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth
refs/changes/22/236822/1
diff --git a/includes/CentralAuthHooks.php b/includes/CentralAuthHooks.php
index 345e76d..47951bf 100644
--- a/includes/CentralAuthHooks.php
+++ b/includes/CentralAuthHooks.php
@@ -260,17 +260,18 @@
return null;
}
- global $wgRequest, $wgMemc;
+ global $wgRequest;
static $cachedUser = false;
+ $cache = CentralAuthUser::getSessionCache();
if ( $cachedUser === false ) {
$loginToken = $wgRequest->getVal( 'centralauthtoken' );
$key = CentralAuthUser::memcKey( 'api-token',
$loginToken );
$cachedUser = null;
- $data = $wgMemc->get( $key );
+ $data = $cache->get( $key );
if ( $invalidateToken ) {
- $wgMemc->delete( $key );
+ $cache->delete( $key );
}
if ( !is_array( $data ) ) {
return null;
@@ -302,7 +303,7 @@
} elseif ( $invalidateToken ) {
$loginToken = $wgRequest->getVal( 'centralauthtoken' );
$key = CentralAuthUser::memcKey( 'api-token',
$loginToken );
- $wgMemc->delete( $key );
+ $cache->delete( $key );
}
return $cachedUser;
@@ -339,9 +340,9 @@
// @see CentralAuthHooks::hasApiToken()
$centralUser = self::getApiCentralUser( false );
if ( $centralUser ) {
- global $wgMemc;
+ $cache = CentralAuthUser::getSessionCache();
$key = CentralAuthUser::memcKey( 'api-cookies', md5(
$centralUser->getName() ), wfWikiID() );
- $cookies = $wgMemc->get( $key );
+ $cookies = $cache->get( $key );
if ( !is_array( $cookies ) ) {
$cookies = array();
}
@@ -352,7 +353,7 @@
if ( !isset( $cookies[$wgCentralAuthCookiePrefix .
'Session'] ) ) {
$cookies[$wgCentralAuthCookiePrefix .
'Session'] = MWCryptRand::generateHex( 32 );
}
- $wgMemc->set( $key, $cookies, 86400 );
+ $cache->set( $key, $cookies, 86400 );
$_COOKIE = $cookies;
wfSetupSession( $cookies[session_name()] );
}
@@ -641,7 +642,7 @@
* @return String
*/
public static function getDomainAutoLoginHtml( User $user,
CentralAuthUser $centralUser ) {
- global $wgCentralAuthLoginWiki, $wgCentralAuthAutoLoginWikis,
$wgMemc;
+ global $wgCentralAuthLoginWiki, $wgCentralAuthAutoLoginWikis;
// No other domains
if ( !$wgCentralAuthAutoLoginWikis ) {
@@ -962,7 +963,7 @@
* @return bool
*/
static function onUserLogoutComplete( &$user, &$inject_html, $userName
) {
- global $wgCentralAuthCookies, $wgCentralAuthLoginWiki,
$wgCentralAuthAutoLoginWikis, $wgMemc;
+ global $wgCentralAuthCookies, $wgCentralAuthLoginWiki,
$wgCentralAuthAutoLoginWikis;
if ( !$wgCentralAuthCookies ) {
return true;
@@ -1744,14 +1745,16 @@
if ( !$wgUser->isAnon() && !self::hasApiToken() ) {
$centralUser = CentralAuthUser::getInstance( $wgUser );
if ( $centralUser->exists() &&
$centralUser->isAttached() ) {
+ $loginToken = MWCryptRand::generateHex( 32 ) .
dechex( $centralUser->getId() );
+
$data = array(
'userName' => $wgUser->getName(),
'token' => $centralUser->getAuthToken(),
);
- global $wgMemc;
- $loginToken = MWCryptRand::generateHex( 32 ) .
dechex( $centralUser->getId() );
+
$key = CentralAuthUser::memcKey( 'api-token',
$loginToken );
- $wgMemc->add( $key, $data, 60 );
+ CentralAuthUser::getSessionCache()->add( $key,
$data, 60 );
+
return $loginToken;
}
}
diff --git a/includes/CentralAuthUser.php b/includes/CentralAuthUser.php
index 6e13a6e..b164a37 100644
--- a/includes/CentralAuthUser.php
+++ b/includes/CentralAuthUser.php
@@ -2819,7 +2819,7 @@
/**
* @return BagOStuff
*/
- private static function getSessionCache() {
+ public static function getSessionCache() {
global $wgSessionsInObjectCache, $wgSessionCacheType;
return $wgSessionsInObjectCache
diff --git a/includes/api/ApiCentralAuthToken.php
b/includes/api/ApiCentralAuthToken.php
index dc0127b..2b1bd3b 100644
--- a/includes/api/ApiCentralAuthToken.php
+++ b/includes/api/ApiCentralAuthToken.php
@@ -59,10 +59,10 @@
'userName' => $user->getName(),
'token' => $centralUser->getAuthToken(),
);
- global $wgMemc;
+
$loginToken = MWCryptRand::generateHex( 32 ) . dechex(
$centralUser->getId() );
$key = CentralAuthUser::memcKey( 'api-token', $loginToken );
- $wgMemc->add( $key, $data, 60 );
+ CentralAuthUser::getSessionCache()->add( $key, $data, 60 );
$this->getResult()->addValue( null, $this->getModuleName(),
array(
'centralauthtoken' => $loginToken
--
To view, visit https://gerrit.wikimedia.org/r/236822
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4d42aa2135c7d2b8ace3084d80c317a0a024ceff
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: wmf/1.26wmf21
Gerrit-Owner: 20after4 <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits