Florianschmidtwelzow has uploaded a new change for review.

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

Change subject: WIP: Pass a caching interface to the GoogleClient
......................................................................

WIP: Pass a caching interface to the GoogleClient

Currently, a simple implementation which selects the Memcached or Redis
servers configured for MediaWiki, if any, and doesn't set a cache when
no server is configured.

Change-Id: Ica7396744ae9dc5ed558942b27f3c8d0ff6d836d
---
M composer.json
M includes/GoogleLogin.body.php
2 files changed, 29 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GoogleLogin 
refs/changes/21/291521/1

diff --git a/composer.json b/composer.json
index 886219e..97984e3 100644
--- a/composer.json
+++ b/composer.json
@@ -3,7 +3,8 @@
        "description": "Allow users to login to MediaWiki with their Google 
Account",
        "license": "MIT",
        "require": {
-               "google/apiclient": "^2.0.0@RC"
+               "google/apiclient": "^2.0.0@RC",
+               "tedivm/stash": "*"
        },
        "require-dev": {
                "jakub-onderka/php-parallel-lint": "0.9.2",
diff --git a/includes/GoogleLogin.body.php b/includes/GoogleLogin.body.php
index fd449b4..a6820f8 100755
--- a/includes/GoogleLogin.body.php
+++ b/includes/GoogleLogin.body.php
@@ -5,6 +5,11 @@
 use ConfigFactory;
 
 use Google_Client;
+use MediaWiki\MediaWikiServices;
+use Stash\Driver\FileSystem;
+use Stash\Driver\Memcache;
+use Stash\Driver\Redis;
+use Stash\Pool;
 
 class GoogleLogin {
        /** @var $mGoogleClient Stores an instance of GoogleClient */
@@ -21,7 +26,29 @@
        public static function getClient( $returnToUrl, $token ) {
                if ( empty( self::$mGoogleClient ) ) {
                        $glConfig = self::getGLConfig();
+                       $config = 
MediaWikiServices::getInstance()->getMainConfig();
+                       $objectCaches = $config->get( 'ObjectCaches' );
+                       $cache = null;
+                       if ( $config->get( 'MainCacheType' ) === 
CACHE_MEMCACHED ) {
+                               $memcachedServers = $config->get( 
'MemCachedServers' );
+                               $servers = [];
+                               foreach ( $memcachedServers as $host ) {
+                                       $servers[] = \IP::splitHostAndPort( 
$host );
+                               }
+                               $cache = new Pool( new Memcache( $servers ) );
+                       } elseif ( isset( $objectCaches['redis'] ) ) {
+                               $redisServers = 
$objectCaches['redis']['servers'];
+                               $servers = [];
+                               foreach ( $redisServers as $host ) {
+                                       $servers[] = \IP::splitHostAndPort( 
$host );
+                               }
+                               $cache = new Pool( new Redis( $servers ) );
+                       }
+
                        $client = new Google_Client();
+                       if ( $cache ) {
+                               $client->setCache( $cache );
+                       }
                        $client->setClientId( $glConfig->get( 'GLAppId' ) );
                        $client->setClientSecret( $glConfig->get( 'GLSecret' ) 
);
                        $client->setRedirectUri( $returnToUrl );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ica7396744ae9dc5ed558942b27f3c8d0ff6d836d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GoogleLogin
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to