Merge "Split Page interface into own file"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 2 Apr 2016 13:52:04 +0000 (13:52 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 2 Apr 2016 13:52:04 +0000 (13:52 +0000)
RELEASE-NOTES-1.27
autoload.php
includes/Title.php
includes/WatchedItemStore.php
includes/libs/BufferingStatsdDataFactory.php [deleted file]
includes/libs/stats/BufferingStatsdDataFactory.php [new file with mode: 0644]
includes/libs/stats/NullStatsdDataFactory.php [new file with mode: 0644]
includes/libs/stats/StatsdAwareInterface.php [new file with mode: 0644]
tests/phpunit/includes/WatchedItemStoreUnitTest.php
tests/phpunit/includes/content/JavaScriptContentTest.php
tests/phpunit/includes/content/TextContentTest.php

index b0d45b8..b6161da 100644 (file)
@@ -400,6 +400,7 @@ changes to languages because of Phabricator reports.
 * Article::getUndoText() and WikiPage::getUndoText were removed (deprecated since
  1.21).
 * DifferenceEngine::setText() was removed (deprecated in 1.21).
+* Title::newFromRedirectArray() was removed (deprecated in 1.21).
 
 == Compatibility ==
 
index 5aa47fe..2d1f086 100644 (file)
@@ -185,7 +185,7 @@ $wgAutoloadLocalClasses = [
        'BmpHandler' => __DIR__ . '/includes/media/BMP.php',
        'BotPassword' => __DIR__ . '/includes/user/BotPassword.php',
        'BrokenRedirectsPage' => __DIR__ . '/includes/specials/SpecialBrokenRedirects.php',
-       'BufferingStatsdDataFactory' => __DIR__ . '/includes/libs/BufferingStatsdDataFactory.php',
+       'BufferingStatsdDataFactory' => __DIR__ . '/includes/libs/stats/BufferingStatsdDataFactory.php',
        'CLIParser' => __DIR__ . '/maintenance/parse.php',
        'CSSMin' => __DIR__ . '/includes/libs/CSSMin.php',
        'CacheDependency' => __DIR__ . '/includes/cache/CacheDependency.php',
@@ -893,6 +893,7 @@ $wgAutoloadLocalClasses = [
        'NullJob' => __DIR__ . '/includes/jobqueue/jobs/NullJob.php',
        'NullLockManager' => __DIR__ . '/includes/filebackend/lockmanager/LockManager.php',
        'NullRepo' => __DIR__ . '/includes/filerepo/NullRepo.php',
+       'NullStatsdDataFactory' => __DIR__ . '/includes/libs/stats/NullStatsdDataFactory.php',
        'OOUIHTMLForm' => __DIR__ . '/includes/htmlform/OOUIHTMLForm.php',
        'ORAField' => __DIR__ . '/includes/db/DatabaseOracle.php',
        'ORAResult' => __DIR__ . '/includes/db/DatabaseOracle.php',
@@ -1266,6 +1267,7 @@ $wgAutoloadLocalClasses = [
        'SquidPurgeClientPool' => __DIR__ . '/includes/clientpool/SquidPurgeClientPool.php',
        'SquidUpdate' => __DIR__ . '/includes/deferred/CdnCacheUpdate.php',
        'SrConverter' => __DIR__ . '/languages/classes/LanguageSr.php',
+       'StatsdAwareInterface' => __DIR__ . '/includes/libs/stats/StatsdAwareInterface.php',
        'StatsOutput' => __DIR__ . '/maintenance/language/StatOutputs.php',
        'Status' => __DIR__ . '/includes/Status.php',
        'StatusValue' => __DIR__ . '/includes/libs/StatusValue.php',
index ec17ef5..a6163f0 100644 (file)
@@ -589,23 +589,6 @@ class Title implements LinkTarget {
                return $content->getUltimateRedirectTarget();
        }
 
-       /**
-        * Extract a redirect destination from a string and return an
-        * array of Titles, or null if the text doesn't contain a valid redirect
-        * The last element in the array is the final destination after all redirects
-        * have been resolved (up to $wgMaxRedirects times)
-        *
-        * @param string $text Text with possible redirect
-        * @return Title[] Array of Titles, with the destination last
-        * @deprecated since 1.21, use Content::getRedirectChain instead.
-        */
-       public static function newFromRedirectArray( $text ) {
-               ContentHandler::deprecated( __METHOD__, '1.21' );
-
-               $content = ContentHandler::makeContent( $text, null, CONTENT_MODEL_WIKITEXT );
-               return $content->getRedirectChain();
-       }
-
        /**
         * Get the prefixed DB key associated with an ID
         *
index 4f3d640..8ae7932 100644 (file)
@@ -11,7 +11,7 @@ use Wikimedia\Assert\Assert;
  *
  * @since 1.27
  */
-class WatchedItemStore {
+class WatchedItemStore implements StatsdAwareInterface {
 
        const SORT_DESC = 'DESC';
        const SORT_ASC = 'ASC';
@@ -57,20 +57,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 +157,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;
        }
diff --git a/includes/libs/BufferingStatsdDataFactory.php b/includes/libs/BufferingStatsdDataFactory.php
deleted file mode 100644 (file)
index 9c18b10..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-<?php
-/**
- * Copyright 2015
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- */
-
-use Liuggio\StatsdClient\Entity\StatsdData;
-use Liuggio\StatsdClient\Entity\StatsdDataInterface;
-use Liuggio\StatsdClient\Factory\StatsdDataFactory;
-
-/**
- * A factory for application metric data.
- *
- * This class prepends a context-specific prefix to each metric key and keeps
- * a reference to each constructed metric in an internal array buffer.
- *
- * @since 1.25
- */
-class BufferingStatsdDataFactory extends StatsdDataFactory {
-       protected $buffer = [];
-
-       public function __construct( $prefix ) {
-               parent::__construct();
-               $this->prefix = $prefix;
-       }
-
-       /**
-        * Normalize a metric key for StatsD
-        *
-        * Replace occurences of '::' with dots and any other non-alphanumeric
-        * characters with underscores. Combine runs of dots or underscores.
-        * Then trim leading or trailing dots or underscores.
-        *
-        * @param string $key
-        * @since 1.26
-        */
-       private static function normalizeMetricKey( $key ) {
-               $key = preg_replace( '/[:.]+/', '.', $key );
-               $key = preg_replace( '/[^a-z0-9.]+/i', '_', $key );
-               $key = trim( $key, '_.' );
-               return str_replace( [ '._', '_.' ], '.', $key );
-       }
-
-       public function produceStatsdData(
-               $key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT
-       ) {
-               $entity = $this->produceStatsdDataEntity();
-               if ( $key !== null ) {
-                       $key = self::normalizeMetricKey( "{$this->prefix}.{$key}" );
-                       $entity->setKey( $key );
-               }
-               if ( $value !== null ) {
-                       $entity->setValue( $value );
-               }
-               if ( $metric !== null ) {
-                       $entity->setMetric( $metric );
-               }
-               // Don't bother buffering a counter update with a delta of zero.
-               if ( !( $metric === StatsdDataInterface::STATSD_METRIC_COUNT && !$value ) ) {
-                       $this->buffer[] = $entity;
-               }
-               return $entity;
-       }
-
-       /**
-        * @return StatsdData[]
-        */
-       public function getBuffer() {
-               return $this->buffer;
-       }
-}
diff --git a/includes/libs/stats/BufferingStatsdDataFactory.php b/includes/libs/stats/BufferingStatsdDataFactory.php
new file mode 100644 (file)
index 0000000..9c18b10
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+/**
+ * Copyright 2015
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+use Liuggio\StatsdClient\Entity\StatsdData;
+use Liuggio\StatsdClient\Entity\StatsdDataInterface;
+use Liuggio\StatsdClient\Factory\StatsdDataFactory;
+
+/**
+ * A factory for application metric data.
+ *
+ * This class prepends a context-specific prefix to each metric key and keeps
+ * a reference to each constructed metric in an internal array buffer.
+ *
+ * @since 1.25
+ */
+class BufferingStatsdDataFactory extends StatsdDataFactory {
+       protected $buffer = [];
+
+       public function __construct( $prefix ) {
+               parent::__construct();
+               $this->prefix = $prefix;
+       }
+
+       /**
+        * Normalize a metric key for StatsD
+        *
+        * Replace occurences of '::' with dots and any other non-alphanumeric
+        * characters with underscores. Combine runs of dots or underscores.
+        * Then trim leading or trailing dots or underscores.
+        *
+        * @param string $key
+        * @since 1.26
+        */
+       private static function normalizeMetricKey( $key ) {
+               $key = preg_replace( '/[:.]+/', '.', $key );
+               $key = preg_replace( '/[^a-z0-9.]+/i', '_', $key );
+               $key = trim( $key, '_.' );
+               return str_replace( [ '._', '_.' ], '.', $key );
+       }
+
+       public function produceStatsdData(
+               $key, $value = 1, $metric = StatsdDataInterface::STATSD_METRIC_COUNT
+       ) {
+               $entity = $this->produceStatsdDataEntity();
+               if ( $key !== null ) {
+                       $key = self::normalizeMetricKey( "{$this->prefix}.{$key}" );
+                       $entity->setKey( $key );
+               }
+               if ( $value !== null ) {
+                       $entity->setValue( $value );
+               }
+               if ( $metric !== null ) {
+                       $entity->setMetric( $metric );
+               }
+               // Don't bother buffering a counter update with a delta of zero.
+               if ( !( $metric === StatsdDataInterface::STATSD_METRIC_COUNT && !$value ) ) {
+                       $this->buffer[] = $entity;
+               }
+               return $entity;
+       }
+
+       /**
+        * @return StatsdData[]
+        */
+       public function getBuffer() {
+               return $this->buffer;
+       }
+}
diff --git a/includes/libs/stats/NullStatsdDataFactory.php b/includes/libs/stats/NullStatsdDataFactory.php
new file mode 100644 (file)
index 0000000..3b272e2
--- /dev/null
@@ -0,0 +1,111 @@
+<?php
+
+use Liuggio\StatsdClient\Entity\StatsdData;
+use Liuggio\StatsdClient\Entity\StatsdDataInterface;
+use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
+
+/**
+ * @author Addshore
+ * @since 1.27
+ */
+class NullStatsdDataFactory implements StatsdDataFactoryInterface {
+
+       /**
+        * This function creates a 'timing' StatsdData.
+        *
+        * @param string|array $key The metric(s) to set.
+        * @param float $time The elapsed time (ms) to log
+        **/
+       public function timing( $key, $time ) {
+       }
+
+       /**
+        * This function creates a 'gauge' StatsdData.
+        *
+        * @param string|array $key The metric(s) to set.
+        * @param float $value The value for the stats.
+        **/
+       public function gauge( $key, $value ) {
+       }
+
+       /**
+        * This function creates a 'set' StatsdData object
+        * A "Set" is a count of unique events.
+        * This data type acts like a counter, but supports counting
+        * of unique occurrences of values between flushes. The backend
+        * receives the number of unique events that happened since
+        * the last flush.
+        *
+        * The reference use case involved tracking the number of active
+        * and logged in users by sending the current userId of a user
+        * with each request with a key of "uniques" (or similar).
+        *
+        * @param  string|array $key The metric(s) to set.
+        * @param  float $value The value for the stats.
+        *
+        * @return array
+        **/
+       public function set( $key, $value ) {
+               return [];
+       }
+
+       /**
+        * This function creates a 'increment' StatsdData object.
+        *
+        * @param string|array $key The metric(s) to increment.
+        * @param float|1      $sampleRate The rate (0-1) for sampling.
+        *
+        * @return array
+        **/
+       public function increment( $key ) {
+               return [];
+       }
+
+       /**
+        * This function creates a 'decrement' StatsdData object.
+        *
+        *
+        * @param string|array $key The metric(s) to decrement.
+        * @param float|1      $sampleRate The rate (0-1) for sampling.
+        *
+        * @return mixed
+        **/
+       public function decrement( $key ) {
+               return [];
+       }
+
+       /**
+        * This function creates a 'updateCount' StatsdData object.
+        *
+        * @param string|array $key The metric(s) to decrement.
+        * @param integer $delta The delta to add to the each metric
+        *
+        * @return mixed
+        **/
+       public function updateCount( $key, $delta ) {
+               return [];
+       }
+
+       /**
+        * Produce a StatsdDataInterface Object.
+        *
+        * @param string $key The key of the metric
+        * @param int $value The amount to increment/decrement each metric by.
+        * @param string $metric The metric type
+        *                      ("c" for count, "ms" for timing, "g" for gauge, "s" for set)
+        *
+        * @return StatsdDataInterface
+        **/
+       public function produceStatsdData(
+               $key,
+               $value = 1,
+               $metric = StatsdDataInterface::STATSD_METRIC_COUNT
+       ) {
+               $data = new StatsdData();
+               $data->setKey( $key );
+               $data->setValue( $value );
+               $data->setMetric( $metric );
+               return $data;
+       }
+
+}
diff --git a/includes/libs/stats/StatsdAwareInterface.php b/includes/libs/stats/StatsdAwareInterface.php
new file mode 100644 (file)
index 0000000..5151b26
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
+
+/**
+ * Describes a Statsd aware interface
+ *
+ * @since 1.27
+ * @author Addshore
+ */
+interface StatsdAwareInterface {
+
+       /**
+        * Sets a logger instance on the object
+        *
+        * @param StatsdDataFactoryInterface $statsFactory
+        * @return null
+        */
+       public function setStatsdDataFactory( StatsdDataFactoryInterface $statsFactory );
+
+}
index bc846d3..9dd38df 100644 (file)
@@ -86,8 +86,7 @@ class WatchedItemStoreUnitTest extends PHPUnit_Framework_TestCase {
        private function newWatchedItemStore( LoadBalancer $loadBalancer, HashBagOStuff $cache ) {
                return new WatchedItemStore(
                        $loadBalancer,
-                       $cache,
-                       $this->getMock( StatsdDataFactory::class )
+                       $cache
                );
        }
 
index 8cbbfb8..97e0b1c 100644 (file)
@@ -141,16 +141,6 @@ class JavaScriptContentTest extends TextContentTest {
                ];
        }
 
-       /**
-        * @todo Test needs database!
-        */
-       /*
-       public function getRedirectChain() {
-               $text = $this->getNativeData();
-               return Title::newFromRedirectArray( $text );
-       }
-       */
-
        /**
         * @todo Test needs database!
         */
index 93bf716..d89f3eb 100644 (file)
@@ -180,16 +180,6 @@ class TextContentTest extends MediaWikiLangTestCase {
                $this->assertEquals( !is_null( $expected ), $content->isRedirect() );
        }
 
-       /**
-        * @todo Test needs database! Should be done by a test class in the Database group.
-        */
-       /*
-       public function getRedirectChain() {
-               $text = $this->getNativeData();
-               return Title::newFromRedirectArray( $text );
-       }
-       */
-
        /**
         * @todo Test needs database! Should be done by a test class in the Database group.
         */