Merge "registration: Improve schema validation for some properties"
[lhc/web/wiklou.git] / includes / WatchedItemStore.php
index 4f3d640..fcf6d3b 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
+use MediaWiki\Linker\LinkTarget;
 use Wikimedia\Assert\Assert;
 
 /**
@@ -11,7 +12,7 @@ use Wikimedia\Assert\Assert;
  *
  * @since 1.27
  */
-class WatchedItemStore {
+class WatchedItemStore implements StatsdAwareInterface {
 
        const SORT_DESC = 'DESC';
        const SORT_ASC = 'ASC';
@@ -57,20 +58,22 @@ class WatchedItemStore {
        /**
         * @param LoadBalancer $loadBalancer
         * @param HashBagOStuff $cache
-        * @param StatsdDataFactoryInterface $stats
         */
        public function __construct(
                LoadBalancer $loadBalancer,
-               HashBagOStuff $cache,
-               StatsdDataFactoryInterface $stats
+               HashBagOStuff $cache
        ) {
                $this->loadBalancer = $loadBalancer;
                $this->cache = $cache;
-               $this->stats = $stats;
+               $this->stats = new NullStatsdDataFactory();
                $this->deferredUpdatesAddCallableUpdateCallback = [ 'DeferredUpdates', 'addCallableUpdate' ];
                $this->revisionGetTimestampFromIdCallback = [ 'Revision', 'getTimestampFromId' ];
        }
 
+       public function setStatsdDataFactory( StatsdDataFactoryInterface $stats ) {
+               $this->stats = $stats;
+       }
+
        /**
         * Overrides the DeferredUpdates::addCallableUpdate callback
         * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.
@@ -155,9 +158,9 @@ class WatchedItemStore {
                if ( !self::$instance ) {
                        self::$instance = new self(
                                wfGetLB(),
-                               new HashBagOStuff( [ 'maxKeys' => 100 ] ),
-                               RequestContext::getMain()->getStats()
+                               new HashBagOStuff( [ 'maxKeys' => 100 ] )
                        );
+                       self::$instance->setStatsdDataFactory( RequestContext::getMain()->getStats() );
                }
                return self::$instance;
        }
@@ -618,7 +621,7 @@ class WatchedItemStore {
                $this->reuseConnection( $dbr );
 
                foreach ( $res as $row ) {
-                       $timestamps[(int)$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp;
+                       $timestamps[$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp;
                }
 
                return $timestamps;
@@ -903,12 +906,8 @@ class WatchedItemStore {
         * @param LinkTarget $newTarget
         */
        public function duplicateAllAssociatedEntries( LinkTarget $oldTarget, LinkTarget $newTarget ) {
-               if ( !$oldTarget instanceof Title ) {
-                       $oldTarget = Title::newFromLinkTarget( $oldTarget );
-               }
-               if ( !$newTarget instanceof Title ) {
-                       $newTarget = Title::newFromLinkTarget( $newTarget );
-               }
+               $oldTarget = Title::newFromLinkTarget( $oldTarget );
+               $newTarget = Title::newFromLinkTarget( $newTarget );
 
                $this->duplicateEntry( $oldTarget->getSubjectPage(), $newTarget->getSubjectPage() );
                $this->duplicateEntry( $oldTarget->getTalkPage(), $newTarget->getTalkPage() );