Merge "RCFilters: Fix validation for single_option groups"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 17 Aug 2017 20:33:32 +0000 (20:33 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 17 Aug 2017 20:33:33 +0000 (20:33 +0000)
includes/db/MWLBFactory.php
includes/libs/rdbms/lbfactory/ILBFactory.php
includes/libs/rdbms/lbfactory/LBFactory.php
includes/libs/rdbms/loadbalancer/ILoadBalancer.php
includes/libs/rdbms/loadbalancer/LoadBalancer.php
includes/libs/rdbms/loadmonitor/ILoadMonitor.php
includes/libs/rdbms/loadmonitor/LoadMonitor.php
includes/libs/rdbms/loadmonitor/LoadMonitorMySQL.php
includes/libs/rdbms/loadmonitor/LoadMonitorNull.php
includes/skins/SkinTemplate.php
resources/src/mediawiki/page/watch.js

index 464a918..5196ac2 100644 (file)
@@ -149,7 +149,7 @@ abstract class MWLBFactory {
                }
                $cCache = ObjectCache::getLocalClusterInstance();
                if ( $cCache->getQoS( $cCache::ATTR_EMULATION ) > $cCache::QOS_EMULATION_SQL ) {
-                       $lbConf['memCache'] = $cCache;
+                       $lbConf['memStash'] = $cCache;
                }
                $wCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                if ( $wCache->getQoS( $wCache::ATTR_EMULATION ) > $wCache::QOS_EMULATION_SQL ) {
index 117df68..ff6635d 100644 (file)
@@ -44,7 +44,7 @@ interface ILBFactory {
         *  - localDomain: A DatabaseDomain or domain ID string.
         *  - readOnlyReason : Reason the master DB is read-only if so [optional]
         *  - srvCache : BagOStuff object for server cache [optional]
-        *  - memCache : BagOStuff object for cluster memory cache [optional]
+        *  - memStash : BagOStuff object for cross-datacenter memory storage [optional]
         *  - wanCache : WANObjectCache object [optional]
         *  - hostname : The name of the current server [optional]
         *  - cliMode: Whether the execution context is a CLI script. [optional]
index 919f103..c891fb6 100644 (file)
@@ -55,7 +55,7 @@ abstract class LBFactory implements ILBFactory {
        /** @var BagOStuff */
        protected $srvCache;
        /** @var BagOStuff */
-       protected $memCache;
+       protected $memStash;
        /** @var WANObjectCache */
        protected $wanCache;
 
@@ -93,7 +93,7 @@ abstract class LBFactory implements ILBFactory {
                }
 
                $this->srvCache = isset( $conf['srvCache'] ) ? $conf['srvCache'] : new EmptyBagOStuff();
-               $this->memCache = isset( $conf['memCache'] ) ? $conf['memCache'] : new EmptyBagOStuff();
+               $this->memStash = isset( $conf['memStash'] ) ? $conf['memStash'] : new EmptyBagOStuff();
                $this->wanCache = isset( $conf['wanCache'] )
                        ? $conf['wanCache']
                        : WANObjectCache::newEmpty();
@@ -435,7 +435,7 @@ abstract class LBFactory implements ILBFactory {
                }
 
                $this->chronProt = new ChronologyProtector(
-                       $this->memCache,
+                       $this->memStash,
                        [
                                'ip' => $this->requestInfo['IPAddress'],
                                'agent' => $this->requestInfo['UserAgent'],
index fc50961..c940392 100644 (file)
@@ -94,7 +94,6 @@ interface ILoadBalancer {
         *  - readOnlyReason : Reason the master DB is read-only if so [optional]
         *  - waitTimeout : Maximum time to wait for replicas for consistency [optional]
         *  - srvCache : BagOStuff object for server cache [optional]
-        *  - memCache : BagOStuff object for cluster memory cache [optional]
         *  - wanCache : WANObjectCache object [optional]
         *  - chronologyProtector: ChronologyProtector object [optional]
         *  - hostname : The name of the current server [optional]
index 72217da..1df2409 100644 (file)
@@ -62,8 +62,6 @@ class LoadBalancer implements ILoadBalancer {
        private $chronProt;
        /** @var BagOStuff */
        private $srvCache;
-       /** @var BagOStuff */
-       private $memCache;
        /** @var WANObjectCache */
        private $wanCache;
        /** @var object|string Class name or object With profileIn/profileOut methods */
@@ -187,11 +185,6 @@ class LoadBalancer implements ILoadBalancer {
                } else {
                        $this->srvCache = new EmptyBagOStuff();
                }
-               if ( isset( $params['memCache'] ) ) {
-                       $this->memCache = $params['memCache'];
-               } else {
-                       $this->memCache = new EmptyBagOStuff();
-               }
                if ( isset( $params['wanCache'] ) ) {
                        $this->wanCache = $params['wanCache'];
                } else {
@@ -244,7 +237,7 @@ class LoadBalancer implements ILoadBalancer {
                        }
 
                        $this->loadMonitor = new $class(
-                               $this, $this->srvCache, $this->memCache, $this->loadMonitorConfig );
+                               $this, $this->srvCache, $this->wanCache, $this->loadMonitorConfig );
                        $this->loadMonitor->setLogger( $this->replLogger );
                }
 
index 4f6701f..fba5e13 100644 (file)
@@ -25,6 +25,7 @@ namespace Wikimedia\Rdbms;
 
 use Psr\Log\LoggerAwareInterface;
 use BagOStuff;
+use WANObjectCache;
 
 /**
  * An interface for database load monitoring
@@ -37,11 +38,11 @@ interface ILoadMonitor extends LoggerAwareInterface {
         *
         * @param ILoadBalancer $lb LoadBalancer this instance serves
         * @param BagOStuff $sCache Local server memory cache
-        * @param BagOStuff $cCache Local cluster memory cache
+        * @param WANObjectCache $wCache Local cluster memory cache
         * @param array $options Options map
         */
        public function __construct(
-               ILoadBalancer $lb, BagOStuff $sCache, BagOStuff $cCache, array $options = []
+               ILoadBalancer $lb, BagOStuff $sCache, WANObjectCache $wCache, array $options = []
        );
 
        /**
index 4300e9f..d4e73c9 100644 (file)
@@ -25,6 +25,7 @@ use Psr\Log\LoggerInterface;
 use Psr\Log\NullLogger;
 use Wikimedia\ScopedCallback;
 use BagOStuff;
+use WANObjectCache;
 
 /**
  * Basic DB load monitor with no external dependencies
@@ -37,8 +38,8 @@ class LoadMonitor implements ILoadMonitor {
        protected $parent;
        /** @var BagOStuff */
        protected $srvCache;
-       /** @var BagOStuff */
-       protected $mainCache;
+       /** @var WANObjectCache */
+       protected $wanCache;
        /** @var LoggerInterface */
        protected $replLogger;
 
@@ -48,11 +49,11 @@ class LoadMonitor implements ILoadMonitor {
        const VERSION = 1; // cache key version
 
        public function __construct(
-               ILoadBalancer $lb, BagOStuff $srvCache, BagOStuff $cache, array $options = []
+               ILoadBalancer $lb, BagOStuff $srvCache, WANObjectCache $wCache, array $options = []
        ) {
                $this->parent = $lb;
                $this->srvCache = $srvCache;
-               $this->mainCache = $cache;
+               $this->wanCache = $wCache;
                $this->replLogger = new NullLogger();
 
                $this->movingAveRatio = isset( $options['movingAveRatio'] )
@@ -109,7 +110,7 @@ class LoadMonitor implements ILoadMonitor {
                $staleValue = $value ?: false;
 
                # (b) Check the shared cache and backfill APC
-               $value = $this->mainCache->get( $key );
+               $value = $this->wanCache->get( $key );
                if ( $value && $value['timestamp'] > ( microtime( true ) - $ttl ) ) {
                        $this->srvCache->set( $key, $value, $staleTTL );
                        $this->replLogger->debug( __METHOD__ . ": got lag times ($key) from main cache" );
@@ -119,12 +120,12 @@ class LoadMonitor implements ILoadMonitor {
                $staleValue = $value ?: $staleValue;
 
                # (c) Cache key missing or expired; regenerate and backfill
-               if ( $this->mainCache->lock( $key, 0, 10 ) ) {
-                       # Let this process alone update the cache value
-                       $cache = $this->mainCache;
+               if ( $this->srvCache->lock( $key, 0, 10 ) ) {
+                       # Let only this process update the cache value on this server
+                       $sCache = $this->srvCache;
                        /** @noinspection PhpUnusedLocalVariableInspection */
-                       $unlocker = new ScopedCallback( function () use ( $cache, $key ) {
-                               $cache->unlock( $key );
+                       $unlocker = new ScopedCallback( function () use ( $sCache, $key ) {
+                               $sCache->unlock( $key );
                        } );
                } elseif ( $staleValue ) {
                        # Could not acquire lock but an old cache exists, so use it
@@ -196,7 +197,7 @@ class LoadMonitor implements ILoadMonitor {
                        'weightScales' => $weightScales,
                        'timestamp' => microtime( true )
                ];
-               $this->mainCache->set( $key, $value, $staleTTL );
+               $this->wanCache->set( $key, $value, $staleTTL );
                $this->srvCache->set( $key, $value, $staleTTL );
                $this->replLogger->info( __METHOD__ . ": re-calculated lag times ($key)" );
 
index ff72dbc..f8ad329 100644 (file)
@@ -22,6 +22,7 @@
 namespace Wikimedia\Rdbms;
 
 use BagOStuff;
+use WANObjectCache;
 
 /**
  * Basic MySQL load monitor with no external dependencies
@@ -34,9 +35,9 @@ class LoadMonitorMySQL extends LoadMonitor {
        private $warmCacheRatio;
 
        public function __construct(
-               ILoadBalancer $lb, BagOStuff $srvCache, BagOStuff $cache, array $options = []
+               ILoadBalancer $lb, BagOStuff $srvCache, WANObjectCache $wCache, array $options = []
        ) {
-               parent::__construct( $lb, $srvCache, $cache, $options );
+               parent::__construct( $lb, $srvCache, $wCache, $options );
 
                $this->warmCacheRatio = isset( $options['warmCacheRatio'] )
                        ? $options['warmCacheRatio']
index 8bbf9e5..6dae8cc 100644 (file)
@@ -23,10 +23,11 @@ namespace Wikimedia\Rdbms;
 
 use Psr\Log\LoggerInterface;
 use BagOStuff;
+use WANObjectCache;
 
 class LoadMonitorNull implements ILoadMonitor {
        public function __construct(
-               ILoadBalancer $lb, BagOStuff $sCache, BagOStuff $cCache, array $options = []
+               ILoadBalancer $lb, BagOStuff $sCache, WANObjectCache $wCache, array $options = []
        ) {
        }
 
index f49d46c..5ad1b11 100644 (file)
@@ -1080,7 +1080,12 @@ class SkinTemplate extends Skin {
                                                ),
                                                // uses 'watch' or 'unwatch' message
                                                'text' => $this->msg( $mode )->text(),
-                                               'href' => $title->getLocalURL( [ 'action' => $mode ] )
+                                               'href' => $title->getLocalURL( [ 'action' => $mode ] ),
+                                               // Set a data-mw=interface attribute, which the mediawiki.page.ajax
+                                               // module will look for to make sure it's a trusted link
+                                               'data' => [
+                                                       'mw' => 'interface',
+                                               ],
                                        ];
                                }
                        }
index 6322ccd..e56e807 100644 (file)
        );
 
        $( function () {
-               var $links = $( '.mw-watchlink a, a.mw-watchlink' );
-               // Restrict to core interfaces, ignore user-generated content
-               $links = $links.filter( ':not( #bodyContent *, #content * )' );
+               var $links = $( '.mw-watchlink a[data-mw="interface"], a.mw-watchlink[data-mw="interface"]' );
+               if ( !$links.length ) {
+                       // Fallback to the class-based exclusion method for backwards-compatibility
+                       $links = $( '.mw-watchlink a, a.mw-watchlink' );
+                       // Restrict to core interfaces, ignore user-generated content
+                       $links = $links.filter( ':not( #bodyContent *, #content * )' );
+               }
 
                $links.click( function ( e ) {
                        var mwTitle, action, api, $link;