Merge "resourceloader: Remove obsolete '$that = $this' closure pattern"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 10 Feb 2016 19:42:24 +0000 (19:42 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 10 Feb 2016 19:42:24 +0000 (19:42 +0000)
21 files changed:
includes/Title.php
includes/api/ApiMain.php
includes/api/ApiMessage.php
includes/db/Database.php
includes/db/DatabaseMysqlBase.php
includes/deferred/LinksUpdate.php
includes/filebackend/SwiftFileBackend.php
includes/jobqueue/JobQueueDB.php
includes/jobqueue/JobQueueMemory.php
includes/jobqueue/JobQueueRedis.php
includes/libs/objectcache/BagOStuff.php
includes/session/SessionBackend.php
includes/session/SessionInfo.php
includes/session/SessionManager.php
includes/user/BotPassword.php
includes/user/User.php
includes/utils/AutoloadGenerator.php
tests/phpunit/includes/api/ApiMessageTest.php
tests/phpunit/includes/session/CookieSessionProviderTest.php
tests/phpunit/includes/session/SessionInfoTest.php
tests/phpunit/includes/session/SessionManagerTest.php

index 55c7179..50721af 100644 (file)
@@ -161,9 +161,9 @@ class Title implements LinkTarget {
         * Avoid usage of this singleton by using TitleValue
         * and the associated services when possible.
         *
-        * @return TitleParser
+        * @return MediaWikiTitleCodec
         */
-       private static function getTitleParser() {
+       private static function getMediaWikiTitleCodec() {
                global $wgContLang, $wgLocalInterwikis;
 
                static $titleCodec = null;
@@ -200,9 +200,9 @@ class Title implements LinkTarget {
         * @return TitleFormatter
         */
        private static function getTitleFormatter() {
-               // NOTE: we know that getTitleParser() returns a MediaWikiTitleCodec,
+               // NOTE: we know that getMediaWikiTitleCodec() returns a MediaWikiTitleCodec,
                //      which implements TitleFormatter.
-               return self::getTitleParser();
+               return self::getMediaWikiTitleCodec();
        }
 
        function __construct() {
@@ -3353,7 +3353,7 @@ class Title implements LinkTarget {
                // @note: splitTitleString() is a temporary hack to allow MediaWikiTitleCodec to share
                //        the parsing code with Title, while avoiding massive refactoring.
                // @todo: get rid of secureAndSplit, refactor parsing code.
-               $titleParser = self::getTitleParser();
+               $titleParser = self::getMediaWikiTitleCodec();
                // MalformedTitleException can be thrown here
                $parts = $titleParser->splitTitleString( $dbkey, $this->getDefaultNamespace() );
 
index f8192e5..eb76024 100644 (file)
@@ -1181,27 +1181,44 @@ class ApiMain extends ApiBase {
                        && in_array( 'bot', $this->getUser()->getGroups() )
                        && wfGetLB()->getServerCount() > 1
                ) {
-                       // Figure out how many servers have passed the lag threshold
-                       $numLagged = 0;
-                       $lagLimit = $this->getConfig()->get( 'APIMaxLagThreshold' );
-                       foreach ( wfGetLB()->getLagTimes() as $lag ) {
-                               if ( $lag > $lagLimit ) {
-                                       ++$numLagged;
-                               }
-                       }
-                       // If a majority of slaves are too lagged then disallow writes
-                       $slaveCount = wfGetLB()->getServerCount() - 1;
-                       if ( $numLagged >= ceil( $slaveCount / 2 ) ) {
-                               $parsed = $this->parseMsg( array( 'readonlytext' ) );
-                               $this->dieUsage(
-                                       $parsed['info'],
-                                       $parsed['code'],
-                                       /* http error */
-                                       0,
-                                       array( 'readonlyreason' => "Waiting for $numLagged lagged database(s)" )
-                               );
+                       $this->checkBotReadOnly();
+               }
+       }
+
+       /**
+        * Check whether we are readonly for bots
+        */
+       private function checkBotReadOnly() {
+               // Figure out how many servers have passed the lag threshold
+               $numLagged = 0;
+               $lagLimit = $this->getConfig()->get( 'APIMaxLagThreshold' );
+               $laggedServers = array();
+               $loadBalancer = wfGetLB();
+               foreach ( $loadBalancer->getLagTimes() as $serverIndex => $lag ) {
+                       if ( $lag > $lagLimit ) {
+                               ++$numLagged;
+                               $laggedServers[] = $loadBalancer->getServerName( $serverIndex ) . " ({$lag}s)";
                        }
                }
+
+               // If a majority of slaves are too lagged then disallow writes
+               $slaveCount = wfGetLB()->getServerCount() - 1;
+               if ( $numLagged >= ceil( $slaveCount / 2 ) ) {
+                       $laggedServers = join( ', ', $laggedServers );
+                       wfDebugLog(
+                               'api-readonly',
+                               "Api request failed as read only because the following DBs are lagged: $laggedServers"
+                       );
+
+                       $parsed = $this->parseMsg( array( 'readonlytext' ) );
+                       $this->dieUsage(
+                               $parsed['info'],
+                               $parsed['code'],
+                               /* http error */
+                               0,
+                               array( 'readonlyreason' => "Waiting for $numLagged lagged database(s)" )
+                       );
+               }
        }
 
        /**
index 5c3434f..f24a7cc 100644 (file)
@@ -63,15 +63,57 @@ interface IApiMessage extends MessageSpecifier {
        public function setApiData( array $data );
 }
 
+/**
+ * Trait to implement the IApiMessage interface for Message subclasses
+ * @since 1.27
+ * @ingroup API
+ */
+trait ApiMessageTrait {
+       protected $apiCode = null;
+       protected $apiData = array();
+
+       public function getApiCode() {
+               return $this->apiCode === null ? $this->getKey() : $this->apiCode;
+       }
+
+       public function setApiCode( $code, array $data = null ) {
+               $this->apiCode = $code;
+               if ( $data !== null ) {
+                       $this->setApiData( $data );
+               }
+       }
+
+       public function getApiData() {
+               return $this->apiData;
+       }
+
+       public function setApiData( array $data ) {
+               $this->apiData = $data;
+       }
+
+       public function serialize() {
+               return serialize( array(
+                       'parent' => parent::serialize(),
+                       'apiCode' => $this->apiCode,
+                       'apiData' => $this->apiData,
+               ) );
+       }
+
+       public function unserialize( $serialized ) {
+               $data = unserialize( $serialized );
+               parent::unserialize( $data['parent'] );
+               $this->apiCode = $data['apiCode'];
+               $this->apiData = $data['apiData'];
+       }
+}
+
 /**
  * Extension of Message implementing IApiMessage
  * @since 1.25
  * @ingroup API
- * @todo: Would be nice to use a Trait here to avoid code duplication
  */
 class ApiMessage extends Message implements IApiMessage {
-       protected $apiCode = null;
-       protected $apiData = array();
+       use ApiMessageTrait;
 
        /**
         * Create an IApiMessage for the message
@@ -119,51 +161,15 @@ class ApiMessage extends Message implements IApiMessage {
                $this->apiCode = $code;
                $this->apiData = (array)$data;
        }
-
-       public function getApiCode() {
-               return $this->apiCode === null ? $this->getKey() : $this->apiCode;
-       }
-
-       public function setApiCode( $code, array $data = null ) {
-               $this->apiCode = $code;
-               if ( $data !== null ) {
-                       $this->setApiData( $data );
-               }
-       }
-
-       public function getApiData() {
-               return $this->apiData;
-       }
-
-       public function setApiData( array $data ) {
-               $this->apiData = $data;
-       }
-
-       public function serialize() {
-               return serialize( array(
-                       'parent' => parent::serialize(),
-                       'apiCode' => $this->apiCode,
-                       'apiData' => $this->apiData,
-               ) );
-       }
-
-       public function unserialize( $serialized ) {
-               $data = unserialize( $serialized );
-               parent::unserialize( $data['parent'] );
-               $this->apiCode = $data['apiCode'];
-               $this->apiData = $data['apiData'];
-       }
 }
 
 /**
  * Extension of RawMessage implementing IApiMessage
  * @since 1.25
  * @ingroup API
- * @todo: Would be nice to use a Trait here to avoid code duplication
  */
 class ApiRawMessage extends RawMessage implements IApiMessage {
-       protected $apiCode = null;
-       protected $apiData = array();
+       use ApiMessageTrait;
 
        /**
         * @param RawMessage|string|array $msg
@@ -189,38 +195,4 @@ class ApiRawMessage extends RawMessage implements IApiMessage {
                $this->apiCode = $code;
                $this->apiData = (array)$data;
        }
-
-       public function getApiCode() {
-               return $this->apiCode === null ? $this->getKey() : $this->apiCode;
-       }
-
-       public function setApiCode( $code, array $data = null ) {
-               $this->apiCode = $code;
-               if ( $data !== null ) {
-                       $this->setApiData( $data );
-               }
-       }
-
-       public function getApiData() {
-               return $this->apiData;
-       }
-
-       public function setApiData( array $data ) {
-               $this->apiData = $data;
-       }
-
-       public function serialize() {
-               return serialize( array(
-                       'parent' => parent::serialize(),
-                       'apiCode' => $this->apiCode,
-                       'apiData' => $this->apiData,
-               ) );
-       }
-
-       public function unserialize( $serialized ) {
-               $data = unserialize( $serialized );
-               parent::unserialize( $data['parent'] );
-               $this->apiCode = $data['apiCode'];
-               $this->apiData = $data['apiData'];
-       }
 }
index a4d0ad0..564cd2e 100644 (file)
@@ -1929,10 +1929,7 @@ abstract class DatabaseBase implements IDatabase {
         * @param string $index
         * @return string
         */
-       public function indexName( $index ) {
-               // @FIXME: Make this protected once we move away from PHP 5.3
-               // Needs to be public because of usage in closure (in DatabaseBase::replaceVars)
-
+       protected function indexName( $index ) {
                // Backwards-compatibility hack
                $renamed = array(
                        'ar_usertext_timestamp' => 'usertext_timestamp',
@@ -3100,7 +3097,6 @@ abstract class DatabaseBase implements IDatabase {
         * @return string The new SQL statement with variables replaced
         */
        protected function replaceVars( $ins ) {
-               $that = $this;
                $vars = $this->getSchemaVars();
                return preg_replace_callback(
                        '!
@@ -3109,19 +3105,19 @@ abstract class DatabaseBase implements IDatabase {
                                `\{\$ (\w+) }`                    | # 4. addIdentifierQuotes
                                /\*\$ (\w+) \*/                     # 5. leave unencoded
                        !x',
-                       function ( $m ) use ( $that, $vars ) {
+                       function ( $m ) use ( $vars ) {
                                // Note: Because of <https://bugs.php.net/bug.php?id=51881>,
                                // check for both nonexistent keys *and* the empty string.
                                if ( isset( $m[1] ) && $m[1] !== '' ) {
                                        if ( $m[1] === 'i' ) {
-                                               return $that->indexName( $m[2] );
+                                               return $this->indexName( $m[2] );
                                        } else {
-                                               return $that->tableName( $m[2] );
+                                               return $this->tableName( $m[2] );
                                        }
                                } elseif ( isset( $m[3] ) && $m[3] !== '' && array_key_exists( $m[3], $vars ) ) {
-                                       return $that->addQuotes( $vars[$m[3]] );
+                                       return $this->addQuotes( $vars[$m[3]] );
                                } elseif ( isset( $m[4] ) && $m[4] !== '' && array_key_exists( $m[4], $vars ) ) {
-                                       return $that->addIdentifierQuotes( $vars[$m[4]] );
+                                       return $this->addIdentifierQuotes( $vars[$m[4]] );
                                } elseif ( isset( $m[5] ) && $m[5] !== '' && array_key_exists( $m[5], $vars ) ) {
                                        return $vars[$m[5]];
                                } else {
@@ -3179,10 +3175,9 @@ abstract class DatabaseBase implements IDatabase {
                        return null;
                }
 
-               $that = $this;
-               $unlocker = new ScopedCallback( function () use ( $that, $lockKey, $fname ) {
-                       $that->commit( __METHOD__, 'flush' );
-                       $that->unlock( $lockKey, $fname );
+               $unlocker = new ScopedCallback( function () use ( $lockKey, $fname ) {
+                       $this->commit( __METHOD__, 'flush' );
+                       $this->unlock( $lockKey, $fname );
                } );
 
                $this->commit( __METHOD__, 'flush' );
index 29106ab..c5aafea 100644 (file)
@@ -692,17 +692,16 @@ abstract class DatabaseMysqlBase extends Database {
                        $this->getLBInfo( 'clusterMasterHost' ) ?: $this->getServer()
                );
 
-               $that = $this;
                return $cache->getWithSetCallback(
                        $key,
                        $cache::TTL_INDEFINITE,
-                       function () use ( $that, $cache, $key ) {
+                       function () use ( $cache, $key ) {
                                // Get and leave a lock key in place for a short period
                                if ( !$cache->lock( $key, 0, 10 ) ) {
                                        return false; // avoid master connection spike slams
                                }
 
-                               $conn = $that->getLazyMasterHandle();
+                               $conn = $this->getLazyMasterHandle();
                                if ( !$conn ) {
                                        return false; // something is misconfigured
                                }
index 3021af1..9cd20fc 100644 (file)
@@ -143,9 +143,8 @@ class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate {
                Hooks::run( 'LinksUpdate', array( &$this ) );
                $this->doIncrementalUpdate();
 
-               $that = $this;
-               $this->mDb->onTransactionIdle( function() use ( $that ) {
-                       Hooks::run( 'LinksUpdateComplete', array( &$that ) );
+               $this->mDb->onTransactionIdle( function() {
+                       Hooks::run( 'LinksUpdateComplete', array( &$this ) );
                } );
        }
 
index 93d8d07..1f64692 100644 (file)
@@ -278,16 +278,15 @@ class SwiftFileBackend extends FileBackendStore {
                        'body' => $params['content']
                ) );
 
-               $that = $this;
                $method = __METHOD__;
-               $handler = function ( array $request, Status $status ) use ( $that, $method, $params ) {
+               $handler = function ( array $request, Status $status ) use ( $method, $params ) {
                        list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request['response'];
                        if ( $rcode === 201 ) {
                                // good
                        } elseif ( $rcode === 412 ) {
                                $status->fatal( 'backend-fail-contenttype', $params['dst'] );
                        } else {
-                               $that->onError( $status, $method, $params, $rerr, $rcode, $rdesc );
+                               $this->onError( $status, $method, $params, $rerr, $rcode, $rdesc );
                        }
                };
 
@@ -343,16 +342,15 @@ class SwiftFileBackend extends FileBackendStore {
                        'body' => $handle // resource
                ) );
 
-               $that = $this;
                $method = __METHOD__;
-               $handler = function ( array $request, Status $status ) use ( $that, $method, $params ) {
+               $handler = function ( array $request, Status $status ) use ( $method, $params ) {
                        list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request['response'];
                        if ( $rcode === 201 ) {
                                // good
                        } elseif ( $rcode === 412 ) {
                                $status->fatal( 'backend-fail-contenttype', $params['dst'] );
                        } else {
-                               $that->onError( $status, $method, $params, $rerr, $rcode, $rdesc );
+                               $this->onError( $status, $method, $params, $rerr, $rcode, $rdesc );
                        }
                };
 
@@ -392,16 +390,15 @@ class SwiftFileBackend extends FileBackendStore {
                        ) + $this->sanitizeHdrs( $params ), // extra headers merged into object
                ) );
 
-               $that = $this;
                $method = __METHOD__;
-               $handler = function ( array $request, Status $status ) use ( $that, $method, $params ) {
+               $handler = function ( array $request, Status $status ) use ( $method, $params ) {
                        list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request['response'];
                        if ( $rcode === 201 ) {
                                // good
                        } elseif ( $rcode === 404 ) {
                                $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
                        } else {
-                               $that->onError( $status, $method, $params, $rerr, $rcode, $rdesc );
+                               $this->onError( $status, $method, $params, $rerr, $rcode, $rdesc );
                        }
                };
 
@@ -450,9 +447,8 @@ class SwiftFileBackend extends FileBackendStore {
                        );
                }
 
-               $that = $this;
                $method = __METHOD__;
-               $handler = function ( array $request, Status $status ) use ( $that, $method, $params ) {
+               $handler = function ( array $request, Status $status ) use ( $method, $params ) {
                        list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request['response'];
                        if ( $request['method'] === 'PUT' && $rcode === 201 ) {
                                // good
@@ -461,7 +457,7 @@ class SwiftFileBackend extends FileBackendStore {
                        } elseif ( $rcode === 404 ) {
                                $status->fatal( 'backend-fail-move', $params['src'], $params['dst'] );
                        } else {
-                               $that->onError( $status, $method, $params, $rerr, $rcode, $rdesc );
+                               $this->onError( $status, $method, $params, $rerr, $rcode, $rdesc );
                        }
                };
 
@@ -491,9 +487,8 @@ class SwiftFileBackend extends FileBackendStore {
                        'headers' => array()
                ) );
 
-               $that = $this;
                $method = __METHOD__;
-               $handler = function ( array $request, Status $status ) use ( $that, $method, $params ) {
+               $handler = function ( array $request, Status $status ) use ( $method, $params ) {
                        list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request['response'];
                        if ( $rcode === 204 ) {
                                // good
@@ -502,7 +497,7 @@ class SwiftFileBackend extends FileBackendStore {
                                        $status->fatal( 'backend-fail-delete', $params['src'] );
                                }
                        } else {
-                               $that->onError( $status, $method, $params, $rerr, $rcode, $rdesc );
+                               $this->onError( $status, $method, $params, $rerr, $rcode, $rdesc );
                        }
                };
 
@@ -550,16 +545,15 @@ class SwiftFileBackend extends FileBackendStore {
                        'headers' => $metaHdrs + $customHdrs
                ) );
 
-               $that = $this;
                $method = __METHOD__;
-               $handler = function ( array $request, Status $status ) use ( $that, $method, $params ) {
+               $handler = function ( array $request, Status $status ) use ( $method, $params ) {
                        list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $request['response'];
                        if ( $rcode === 202 ) {
                                // good
                        } elseif ( $rcode === 404 ) {
                                $status->fatal( 'backend-fail-describe', $params['src'] );
                        } else {
-                               $that->onError( $status, $method, $params, $rerr, $rcode, $rdesc );
+                               $this->onError( $status, $method, $params, $rerr, $rcode, $rdesc );
                        }
                };
 
index f10866e..51dec65 100644 (file)
@@ -181,11 +181,10 @@ class JobQueueDB extends JobQueue {
        protected function doBatchPush( array $jobs, $flags ) {
                $dbw = $this->getMasterDB();
 
-               $that = $this;
                $method = __METHOD__;
                $dbw->onTransactionIdle(
-                       function () use ( $dbw, $that, $jobs, $flags, $method ) {
-                               $that->doBatchPushInternal( $dbw, $jobs, $flags, $method );
+                       function () use ( $dbw, $jobs, $flags, $method ) {
+                               $this->doBatchPushInternal( $dbw, $jobs, $flags, $method );
                        }
                );
        }
index 7dad748..7e9c0c9 100644 (file)
@@ -175,11 +175,10 @@ class JobQueueMemory extends JobQueue {
                        return new ArrayIterator( array() );
                }
 
-               $that = $this;
                return new MappedIterator(
                        $unclaimed,
-                       function ( $value ) use ( $that ) {
-                               $that->jobFromSpecInternal( $value );
+                       function ( $value ) {
+                               $this->jobFromSpecInternal( $value );
                        }
                );
        }
@@ -195,11 +194,10 @@ class JobQueueMemory extends JobQueue {
                        return new ArrayIterator( array() );
                }
 
-               $that = $this;
                return new MappedIterator(
                        $claimed,
-                       function ( $value ) use ( $that ) {
-                               $that->jobFromSpecInternal( $value );
+                       function ( $value ) {
+                               $this->jobFromSpecInternal( $value );
                        }
                );
        }
index eda3e9c..408828d 100644 (file)
@@ -573,12 +573,10 @@ LUA;
         * @return MappedIterator
         */
        protected function getJobIterator( RedisConnRef $conn, array $uids ) {
-               $that = $this;
-
                return new MappedIterator(
                        $uids,
-                       function ( $uid ) use ( $that, $conn ) {
-                               return $that->getJobFromUidInternal( $uid, $conn );
+                       function ( $uid ) use ( $conn ) {
+                               return $this->getJobFromUidInternal( $uid, $conn );
                        },
                        array( 'accept' => function ( $job ) {
                                return is_object( $job );
index 3736103..a7e8a47 100644 (file)
@@ -397,18 +397,15 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
                }
 
                $lSince = microtime( true ); // lock timestamp
-               // PHP 5.3: Can't use $this in a closure
-               $that = $this;
-               $logger = $this->logger;
 
-               return new ScopedCallback( function() use ( $that, $logger, $key, $lSince, $expiry ) {
+               return new ScopedCallback( function() use ( $key, $lSince, $expiry ) {
                        $latency = .050; // latency skew (err towards keeping lock present)
                        $age = ( microtime( true ) - $lSince + $latency );
                        if ( ( $age + $latency ) >= $expiry ) {
-                               $logger->warning( "Lock for $key held too long ($age sec)." );
+                               $this->logger->warning( "Lock for $key held too long ($age sec)." );
                                return; // expired; it's not "safe" to delete the key
                        }
-                       $that->unlock( $key );
+                       $this->unlock( $key );
                } );
        }
 
index a79c5cb..fe446e3 100644 (file)
@@ -549,13 +549,11 @@ final class SessionBackend {
         * @return \ScopedCallback When this goes out of scope, a save will be triggered
         */
        public function delaySave() {
-               $that = $this;
                $this->delaySave++;
-               $ref = &$this->delaySave;
-               return new \ScopedCallback( function () use ( $that, &$ref ) {
-                       if ( --$ref <= 0 ) {
-                               $ref = 0;
-                               $that->save();
+               return new \ScopedCallback( function () {
+                       if ( --$this->delaySave <= 0 ) {
+                               $this->delaySave = 0;
+                               $this->save();
                        }
                } );
        }
@@ -692,9 +690,8 @@ final class SessionBackend {
        private function checkPHPSession() {
                if ( !$this->checkPHPSessionRecursionGuard ) {
                        $this->checkPHPSessionRecursionGuard = true;
-                       $ref = &$this->checkPHPSessionRecursionGuard;
-                       $reset = new \ScopedCallback( function () use ( &$ref ) {
-                               $ref = false;
+                       $reset = new \ScopedCallback( function () {
+                               $this->checkPHPSessionRecursionGuard = false;
                        } );
 
                        if ( $this->usePhpSessionHandling && session_id() === '' && PHPSessionHandler::isEnabled() &&
index 9fe2cdf..ff40aa5 100644 (file)
 
 namespace MediaWiki\Session;
 
-use Psr\Log\LoggerInterface;
-use BagOStuff;
-use WebRequest;
-
 /**
  * Value object returned by SessionProvider
  *
index 07291e9..83c30ab 100644 (file)
@@ -28,8 +28,6 @@ use BagOStuff;
 use CachedBagOStuff;
 use Config;
 use FauxRequest;
-use Language;
-use Message;
 use User;
 use WebRequest;
 
index 6f713f1..fca7775 100644 (file)
@@ -18,9 +18,6 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 
-use MediaWiki\Session\BotPasswordSessionProvider;
-use MediaWiki\Session\SessionInfo;
-
 /**
  * Utility class for bot passwords
  * @since 1.27
index 6638fb7..da63075 100644 (file)
@@ -1789,14 +1789,14 @@ class User implements IDBAccessObject {
                        // ip-based limits
                        if ( isset( $limits['ip'] ) ) {
                                $ip = $this->getRequest()->getIP();
-                               $keys[wfMemcKey( 'limiter', $action, 'ip', $ip )] = $limits['ip'];
+                               $keys["mediawiki:limiter:$action:ip:$ip"] = $limits['ip'];
                        }
                        // subnet-based limits
                        if ( isset( $limits['subnet'] ) ) {
                                $ip = $this->getRequest()->getIP();
                                $subnet = IP::getSubnet( $ip );
                                if ( $subnet !== false ) {
-                                       $keys[wfMemcKey( 'limiter', $action, 'subnet', $subnet )] = $limits['subnet'];
+                                       $keys["mediawiki:limiter:$action:subnet:$subnet"] = $limits['subnet'];
                                }
                        }
                }
index 7d63156..69426d7 100644 (file)
@@ -310,6 +310,7 @@ class ClassCollector {
                case T_NAMESPACE:
                case T_CLASS:
                case T_INTERFACE:
+               case T_TRAIT:
                        $this->startToken = $token;
                }
        }
@@ -331,6 +332,7 @@ class ClassCollector {
 
                case T_CLASS:
                case T_INTERFACE:
+               case T_TRAIT:
                        $this->tokens[] = $token;
                        if ( is_array( $token ) && $token[0] === T_STRING ) {
                                $this->classes[] = $this->namespace . $this->implodeTokens();
index 08a984e..56bbd06 100644 (file)
@@ -25,6 +25,7 @@ class ApiMessageTest extends MediaWikiTestCase {
 
        /**
         * @covers ApiMessage
+        * @covers ApiMessageTrait
         */
        public function testApiMessage() {
                $msg = new Message( array( 'foo', 'bar' ), array( 'baz' ) );
@@ -63,6 +64,7 @@ class ApiMessageTest extends MediaWikiTestCase {
 
        /**
         * @covers ApiRawMessage
+        * @covers ApiMessageTrait
         */
        public function testApiRawMessage() {
                $msg = new RawMessage( 'foo', array( 'baz' ) );
index f5c8b05..659826f 100644 (file)
@@ -568,8 +568,6 @@ class CookieSessionProviderTest extends MediaWikiTestCase {
        }
 
        public function testPersistSessionWithHook() {
-               $that = $this;
-
                $provider = new CookieSessionProvider( array(
                        'priority' => 1,
                        'sessionName' => 'MySessionName',
@@ -620,14 +618,14 @@ class CookieSessionProviderTest extends MediaWikiTestCase {
                // Logged-in user, no remember
                $mock = $this->getMock( __CLASS__, array( 'onUserSetCookies' ) );
                $mock->expects( $this->once() )->method( 'onUserSetCookies' )
-                       ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $that, $user ) {
-                               $that->assertSame( $user, $u );
-                               $that->assertEquals( array(
+                       ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $user ) {
+                               $this->assertSame( $user, $u );
+                               $this->assertEquals( array(
                                        'wsUserID' => $user->getId(),
                                        'wsUserName' => $user->getName(),
                                        'wsToken' => $user->getToken(),
                                ), $sessionData );
-                               $that->assertEquals( array(
+                               $this->assertEquals( array(
                                        'UserID' => $user->getId(),
                                        'UserName' => $user->getName(),
                                        'Token' => false,
@@ -663,14 +661,14 @@ class CookieSessionProviderTest extends MediaWikiTestCase {
                // Logged-in user, remember
                $mock = $this->getMock( __CLASS__, array( 'onUserSetCookies' ) );
                $mock->expects( $this->once() )->method( 'onUserSetCookies' )
-                       ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $that, $user ) {
-                               $that->assertSame( $user, $u );
-                               $that->assertEquals( array(
+                       ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $user ) {
+                               $this->assertSame( $user, $u );
+                               $this->assertEquals( array(
                                        'wsUserID' => $user->getId(),
                                        'wsUserName' => $user->getName(),
                                        'wsToken' => $user->getToken(),
                                ), $sessionData );
-                               $that->assertEquals( array(
+                               $this->assertEquals( array(
                                        'UserID' => $user->getId(),
                                        'UserName' => $user->getName(),
                                        'Token' => $user->getToken(),
index b411f3c..f9c9b8e 100644 (file)
@@ -2,7 +2,6 @@
 
 namespace MediaWiki\Session;
 
-use Psr\Log\LogLevel;
 use MediaWikiTestCase;
 
 /**
index 6be8957..16beb72 100644 (file)
@@ -760,8 +760,6 @@ class SessionManagerTest extends MediaWikiTestCase {
        public function testAutoCreateUser() {
                global $wgGroupPermissions;
 
-               $that = $this;
-
                \ObjectCache::$instances[__METHOD__] = new TestBagOStuff();
                $this->setMwGlobals( array( 'wgMainCacheType' => __METHOD__ ) );
                $this->setMWGlobals( array(
@@ -1012,10 +1010,10 @@ class SessionManagerTest extends MediaWikiTestCase {
                $logger->clearBuffer();
 
                // Sanity check that creation still works, and test completion hook
-               $cb = $this->callback( function ( User $user ) use ( $that ) {
-                       $that->assertNotEquals( 0, $user->getId() );
-                       $that->assertSame( 'UTSessionAutoCreate4', $user->getName() );
-                       $that->assertEquals(
+               $cb = $this->callback( function ( User $user ) {
+                       $this->assertNotEquals( 0, $user->getId() );
+                       $this->assertSame( 'UTSessionAutoCreate4', $user->getName() );
+                       $this->assertEquals(
                                $user->getId(), User::idFromName( 'UTSessionAutoCreate4', User::READ_LATEST )
                        );
                        return true;
@@ -1649,7 +1647,6 @@ class SessionManagerTest extends MediaWikiTestCase {
                $this->assertSame( array(), $logger->getBuffer() );
 
                // Hook
-               $that = $this;
                $called = false;
                $data = array( 'foo' => 1 );
                $this->store->setSession( $id, array( 'metadata' => $metadata, 'data' => $data ) );
@@ -1660,14 +1657,14 @@ class SessionManagerTest extends MediaWikiTestCase {
                ) );
                $this->mergeMwGlobalArrayValue( 'wgHooks', array(
                        'SessionCheckInfo' => array( function ( &$reason, $i, $r, $m, $d ) use (
-                               $that, $info, $metadata, $data, $request, &$called
+                               $info, $metadata, $data, $request, &$called
                        ) {
-                               $that->assertSame( $info->getId(), $i->getId() );
-                               $that->assertSame( $info->getProvider(), $i->getProvider() );
-                               $that->assertSame( $info->getUserInfo(), $i->getUserInfo() );
-                               $that->assertSame( $request, $r );
-                               $that->assertEquals( $metadata, $m );
-                               $that->assertEquals( $data, $d );
+                               $this->assertSame( $info->getId(), $i->getId() );
+                               $this->assertSame( $info->getProvider(), $i->getProvider() );
+                               $this->assertSame( $info->getUserInfo(), $i->getUserInfo() );
+                               $this->assertSame( $request, $r );
+                               $this->assertEquals( $metadata, $m );
+                               $this->assertEquals( $data, $d );
                                $called = true;
                                return false;
                        } )