Merge "Call overrideMwServices() in TitlePermissionTest"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 13 Aug 2018 16:44:59 +0000 (16:44 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 13 Aug 2018 16:44:59 +0000 (16:44 +0000)
16 files changed:
autoload.php
includes/filerepo/file/File.php
includes/filerepo/file/ForeignDBFile.php
includes/filerepo/file/LocalFile.php
includes/logging/BlockLogFormatter.php
includes/parser/DateFormatter.php
includes/specials/SpecialBlock.php
includes/specials/pagers/AllMessagesTablePager.php
languages/FakeConverter.php
languages/LanguageConverter.php
languages/classes/LanguageCrh.php
languages/classes/LanguageGan.php
languages/classes/LanguageKk.php
languages/classes/LanguageZh.php
maintenance/benchmarks/benchmarkTitleValue.php [new file with mode: 0644]
maintenance/dumpTextPass.php

index feddcdd..d3ab3af 100644 (file)
@@ -200,6 +200,7 @@ $wgAutoloadLocalClasses = [
        'BenchmarkPurge' => __DIR__ . '/maintenance/benchmarks/benchmarkPurge.php',
        'BenchmarkSanitizer' => __DIR__ . '/maintenance/benchmarks/benchmarkSanitizer.php',
        'BenchmarkTidy' => __DIR__ . '/maintenance/benchmarks/benchmarkTidy.php',
+       'BenchmarkTitleValue' => __DIR__ . '/maintenance/benchmarks/benchmarkTitleValue.php',
        'Benchmarker' => __DIR__ . '/maintenance/benchmarks/Benchmarker.php',
        'BitmapHandler' => __DIR__ . '/includes/media/BitmapHandler.php',
        'BitmapHandler_ClientOnly' => __DIR__ . '/includes/media/BitmapHandler_ClientOnly.php',
index 370ebb4..5a0cf6a 100644 (file)
@@ -2051,17 +2051,17 @@ abstract class File implements IDBAccessObject {
        /**
         * Get the HTML text of the description page, if available
         *
-        * @param bool|Language $lang Optional language to fetch description in
+        * @param Language|null $lang Optional language to fetch description in
         * @return string|false
         */
-       function getDescriptionText( $lang = false ) {
+       function getDescriptionText( Language $lang = null ) {
                global $wgLang;
 
                if ( !$this->repo || !$this->repo->fetchDescription ) {
                        return false;
                }
 
-               $lang = $lang ?: $wgLang;
+               $lang = $lang ?? $wgLang;
 
                $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
                if ( $renderUrl ) {
index 7a982bd..ee4df1d 100644 (file)
@@ -126,14 +126,14 @@ class ForeignDBFile extends LocalFile {
         * @param Language|null $lang Optional language to fetch description in.
         * @return string|false
         */
-       function getDescriptionText( $lang = null ) {
+       function getDescriptionText( Language $lang = null ) {
                global $wgLang;
 
                if ( !$this->repo->fetchDescription ) {
                        return false;
                }
 
-               $lang = $lang ?: $wgLang;
+               $lang = $lang ?? $wgLang;
                $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
                if ( !$renderUrl ) {
                        return false;
index 742d78d..1fc6bd0 100644 (file)
@@ -2115,7 +2115,7 @@ class LocalFile extends File {
         * @param Language|null $lang What language to get description in (Optional)
         * @return string|false
         */
-       function getDescriptionText( $lang = null ) {
+       function getDescriptionText( Language $lang = null ) {
                $revision = Revision::newFromTitle( $this->title, false, Revision::READ_NORMAL );
                if ( !$revision ) {
                        return false;
index 0d22382..3762d62 100644 (file)
@@ -130,7 +130,7 @@ class BlockLogFormatter extends LogFormatter {
         * @param Language $lang
         * @return string
         */
-       public static function formatBlockFlags( $flags, $lang ) {
+       public static function formatBlockFlags( $flags, Language $lang ) {
                $flags = trim( $flags );
                if ( $flags === '' ) {
                        return ''; // nothing to do
@@ -153,7 +153,7 @@ class BlockLogFormatter extends LogFormatter {
         * @param Language $lang Language object to use
         * @return string
         */
-       public static function formatBlockFlag( $flag, $lang ) {
+       public static function formatBlockFlag( $flag, Language $lang ) {
                static $messages = [];
 
                if ( !isset( $messages[$flag] ) ) {
index 3be4353..de02861 100644 (file)
@@ -135,7 +135,7 @@ class DateFormatter {
        public static function getInstance( Language $lang = null ) {
                global $wgMainCacheType;
 
-               $lang = $lang ?: MediaWikiServices::getInstance()->getContentLanguage();
+               $lang = $lang ?? MediaWikiServices::getInstance()->getContentLanguage();
                $cache = ObjectCache::getLocalServerInstance( $wgMainCacheType );
 
                static $dateFormatter = false;
index 3b25c6c..a60595a 100644 (file)
@@ -858,7 +858,7 @@ class SpecialBlock extends FormSpecialPage {
         *     suggestions
         * @return array
         */
-       public static function getSuggestedDurations( $lang = null, $includeOther = true ) {
+       public static function getSuggestedDurations( Language $lang = null, $includeOther = true ) {
                $a = [];
                $msg = $lang === null
                        ? wfMessage( 'ipboptions' )->inContentLanguage()->text()
index 2e451ec..6d5f64b 100644 (file)
@@ -44,7 +44,7 @@ class AllMessagesTablePager extends TablePager {
         */
        public $custom;
 
-       function __construct( $page, $conds, $langObj = null ) {
+       function __construct( $page, $conds, Language $langObj = null ) {
                parent::__construct( $page->getContext() );
                $this->mIndexField = 'am_title';
                $this->mPage = $page;
@@ -56,7 +56,7 @@ class AllMessagesTablePager extends TablePager {
                $this->talk = $this->msg( 'talkpagelinktext' )->escaped();
 
                $contLang = MediaWikiServices::getInstance()->getContentLanguage();
-               $this->lang = $langObj ?: $contLang;
+               $this->lang = $langObj ?? $contLang;
                $this->langcode = $this->lang->getCode();
                $this->foreign = !$this->lang->equals( $contLang );
 
index 22377c2..c4ec638 100644 (file)
@@ -37,7 +37,7 @@ class FakeConverter {
         */
        public $mLang;
 
-       function __construct( $langobj ) {
+       function __construct( Language $langobj ) {
                $this->mLang = $langobj;
        }
 
index 6ab6e8f..c098518 100644 (file)
@@ -85,7 +85,7 @@ class LanguageConverter {
         * @param array $flags Defining the custom strings that maps to the flags
         * @param array $manualLevel Limit for supported variants
         */
-       public function __construct( $langobj, $maincode, $variants = [],
+       public function __construct( Language $langobj, $maincode, $variants = [],
                                                                $variantfallbacks = [], $flags = [],
                                                                $manualLevel = [] ) {
                global $wgDisabledVariants;
index e652a52..27af14b 100644 (file)
@@ -63,7 +63,7 @@ class CrhConverter extends LanguageConverter {
         * @param array $variantfallbacks
         * @param array $flags
         */
-       function __construct( $langobj, $maincode,
+       function __construct( Language $langobj, $maincode,
                                                                $variants = [],
                                                                $variantfallbacks = [],
                                                                $flags = [] ) {
index d6f90df..f315473 100644 (file)
@@ -32,7 +32,7 @@ class GanConverter extends LanguageConverter {
         * @param array $flags
         * @param array $manualLevel
         */
-       function __construct( $langobj, $maincode,
+       function __construct( Language $langobj, $maincode,
                $variants = [],
                $variantfallbacks = [],
                $flags = [],
index 1a1438c..dc8a9f8 100644 (file)
@@ -44,7 +44,7 @@ class KkConverter extends LanguageConverter {
         * @param array $variantfallbacks
         * @param array $flags
         */
-       function __construct( $langobj, $maincode,
+       function __construct( Language $langobj, $maincode,
                                                                $variants = [],
                                                                $variantfallbacks = [],
                                                                $flags = [] ) {
index e1099f8..27d6972 100644 (file)
@@ -33,7 +33,7 @@ class ZhConverter extends LanguageConverter {
         * @param array $flags
         * @param array $manualLevel
         */
-       function __construct( $langobj, $maincode,
+       function __construct( Language $langobj, $maincode,
                                                                $variants = [],
                                                                $variantfallbacks = [],
                                                                $flags = [],
diff --git a/maintenance/benchmarks/benchmarkTitleValue.php b/maintenance/benchmarks/benchmarkTitleValue.php
new file mode 100644 (file)
index 0000000..c60f4bb
--- /dev/null
@@ -0,0 +1,136 @@
+<?php
+/**
+ * Copyright (C) 2018 Kunal Mehta <legoktm@member.fsf.org>
+ *
+ * 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.
+ *
+ */
+
+use MediaWiki\MediaWikiServices;
+
+require_once __DIR__ . '/Benchmarker.php';
+
+/**
+ * Maintenance script that benchmarks TitleValue vs Title.
+ *
+ * @ingroup Benchmark
+ */
+class BenchmarkTitleValue extends Benchmarker {
+
+       /**
+        * @var TitleFormatter
+        */
+       private $titleFormatter;
+       /**
+        * @var TitleParser
+        */
+       private $titleParser;
+
+       /**
+        * @var string
+        */
+       private $dbKey = 'FooBar';
+       /**
+        * @var TitleValue
+        */
+       private $titleValue;
+       /**
+        * @var Title
+        */
+       private $title;
+
+       /**
+        * @var string
+        */
+       private $toParse;
+
+       public function __construct() {
+               parent::__construct();
+               $this->addDescription( 'Benchmark TitleValue vs Title.' );
+       }
+
+       public function execute() {
+               $this->titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
+               $this->titleParser = MediaWikiServices::getInstance()->getTitleParser();
+               $this->titleValue = $this->constructTitleValue();
+               $this->title = $this->constructTitle();
+               $this->toParse = 'Category:FooBar';
+               $this->bench( [
+                       [
+                               'function' => [ $this, 'constructTitleValue' ],
+                       ],
+                       [
+                               'function' => [ $this, 'constructTitle' ],
+                       ],
+                       [
+                               'function' => [ $this, 'constructTitleSafe' ],
+                       ],
+                       [
+                               'function' => [ $this, 'getPrefixedTextTitleValue' ],
+                       ],
+                       [
+                               'function' => [ $this, 'getPrefixedTextTitle' ],
+                       ],
+                       [
+                               'function' => [ $this, 'parseTitleValue' ],
+                               'setup' => [ $this, 'randomize' ],
+                       ],
+                       [
+                               'function' => [ $this, 'parseTitle' ],
+                               'setup' => [ $this, 'randomize' ],
+                       ],
+               ] );
+       }
+
+       /**
+        * Use a different dbKey each time to avoid influence of Title caches
+        */
+       protected function randomize() {
+               $this->dbKey = ucfirst( wfRandomString( 10 ) );
+       }
+
+       protected function constructTitleValue() {
+               return new TitleValue( NS_CATEGORY, $this->dbKey );
+       }
+
+       protected function constructTitle() {
+               return Title::makeTitle( NS_CATEGORY, $this->dbKey );
+       }
+
+       protected function constructTitleSafe() {
+               return Title::makeTitleSafe( NS_CATEGORY, $this->dbKey );
+       }
+
+       protected function getPrefixedTextTitleValue() {
+               // This is really showing TitleFormatter aka MediaWikiTitleCodec perf
+               return $this->titleFormatter->getPrefixedText( $this->titleValue );
+       }
+
+       protected function getPrefixedTextTitle() {
+               return $this->title->getPrefixedText();
+       }
+
+       protected function parseTitleValue() {
+               // This is really showing TitleParser aka MediaWikiTitleCodec perf
+               $this->titleParser->parseTitle( 'Category:' . $this->dbKey, NS_MAIN );
+       }
+
+       protected function parseTitle() {
+               Title::newFromText( 'Category:' . $this->dbKey );
+       }
+}
+
+$maintClass = BenchmarkTitleValue::class;
+require_once RUN_MAINTENANCE_IF_MAIN;
index e1df1f1..05db622 100644 (file)
@@ -127,6 +127,7 @@ TEXT
                        'first pageid written for the first %s (required) and the last pageid written for the ' .
                        'second %s if it exists.', false, true, false, true ); // This can be specified multiple times
                $this->addOption( 'quiet', 'Don\'t dump status reports to stderr.' );
+               $this->addOption( 'full', 'Dump all revisions of every page' );
                $this->addOption( 'current', 'Base ETA on number of pages in database instead of all revisions' );
                $this->addOption( 'spawn', 'Spawn a subprocess for loading text records' );
                $this->addOption( 'buffersize', 'Buffer size in bytes to use for reading the stub. ' .