'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',
/**
* 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 ) {
* @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;
* @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;
* @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
* @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] ) ) {
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;
* 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()
*/
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;
$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 );
*/
public $mLang;
- function __construct( $langobj ) {
+ function __construct( Language $langobj ) {
$this->mLang = $langobj;
}
* @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;
* @param array $variantfallbacks
* @param array $flags
*/
- function __construct( $langobj, $maincode,
+ function __construct( Language $langobj, $maincode,
$variants = [],
$variantfallbacks = [],
$flags = [] ) {
* @param array $flags
* @param array $manualLevel
*/
- function __construct( $langobj, $maincode,
+ function __construct( Language $langobj, $maincode,
$variants = [],
$variantfallbacks = [],
$flags = [],
* @param array $variantfallbacks
* @param array $flags
*/
- function __construct( $langobj, $maincode,
+ function __construct( Language $langobj, $maincode,
$variants = [],
$variantfallbacks = [],
$flags = [] ) {
* @param array $flags
* @param array $manualLevel
*/
- function __construct( $langobj, $maincode,
+ function __construct( Language $langobj, $maincode,
$variants = [],
$variantfallbacks = [],
$flags = [],
--- /dev/null
+<?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;
'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. ' .