Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/285141
Change subject: [WIP] Add TitleParser and TitleFormatter to MediaWikiServices
......................................................................
[WIP] Add TitleParser and TitleFormatter to MediaWikiServices
Change-Id: I81d48616afd1ab2bde1a5f1d12f4aefb1c866d43
---
M includes/MediaWikiServices.php
M includes/ServiceWiring.php
M includes/Title.php
M tests/phpunit/includes/MediaWikiServicesTest.php
4 files changed, 32 insertions(+), 40 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/41/285141/1
diff --git a/includes/MediaWikiServices.php b/includes/MediaWikiServices.php
index 3f4d8ed..75650f3 100644
--- a/includes/MediaWikiServices.php
+++ b/includes/MediaWikiServices.php
@@ -11,6 +11,8 @@
use MediaWiki\Services\ServiceContainer;
use SiteLookup;
use SiteStore;
+use TitleFormatter;
+use TitleParser;
/**
* Service locator for MediaWiki core services.
@@ -152,6 +154,20 @@
return $this->getService( 'StatsdDataFactory' );
}
+ /**
+ * @return TitleFormatter
+ */
+ public function getTitleFormatter() {
+ return $this->getService( 'MediaWikiTitleCodec' );
+ }
+
+ /**
+ * @return TitleParser
+ */
+ public function getTitleParser() {
+ return $this->getService( 'MediaWikiTitleCodec' );
+ }
+
///////////////////////////////////////////////////////////////////////////
// NOTE: When adding a service getter here, don't forget to add a test
// case for it in MediaWikiServicesTest::provideGetters() and in
diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php
index 7e1d4e3..1f84327 100644
--- a/includes/ServiceWiring.php
+++ b/includes/ServiceWiring.php
@@ -78,6 +78,16 @@
);
},
+ 'MediaWikiTitleCodec' => function( MediaWikiServices $services ) {
+ global $wgContLang;
+
+ return new MediaWikiTitleCodec(
+ $wgContLang,
+ GenderCache::singleton(), // @todo this should be a
service thing
+ $services->getMainConfig()->get( 'LocalInterwikis' )
+ );
+ }
+
///////////////////////////////////////////////////////////////////////////
// NOTE: When adding a service here, don't forget to add a getter
function
// in the MediaWikiServices class. The convenience getter should just
call
diff --git a/includes/Title.php b/includes/Title.php
index 7368bb0..88339df 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -21,6 +21,7 @@
*
* @file
*/
+use MediaWiki\MediaWikiServices;
/**
* Represents a title within MediaWiki.
@@ -162,48 +163,10 @@
* Avoid usage of this singleton by using TitleValue
* and the associated services when possible.
*
- * @return MediaWikiTitleCodec
- */
- private static function getMediaWikiTitleCodec() {
- global $wgContLang, $wgLocalInterwikis;
-
- static $titleCodec = null;
- static $titleCodecFingerprint = null;
-
- // $wgContLang and $wgLocalInterwikis may change (especially
while testing),
- // make sure we are using the right one. To detect changes over
the course
- // of a request, we remember a fingerprint of the config used
to create the
- // codec singleton, and re-create it if the fingerprint doesn't
match.
- $fingerprint = spl_object_hash( $wgContLang ) . '|' . implode(
'+', $wgLocalInterwikis );
-
- if ( $fingerprint !== $titleCodecFingerprint ) {
- $titleCodec = null;
- }
-
- if ( !$titleCodec ) {
- $titleCodec = new MediaWikiTitleCodec(
- $wgContLang,
- GenderCache::singleton(),
- $wgLocalInterwikis
- );
- $titleCodecFingerprint = $fingerprint;
- }
-
- return $titleCodec;
- }
-
- /**
- * B/C kludge: provide a TitleParser for use by Title.
- * Ideally, Title would have no methods that need this.
- * Avoid usage of this singleton by using TitleValue
- * and the associated services when possible.
- *
* @return TitleFormatter
*/
private static function getTitleFormatter() {
- // NOTE: we know that getMediaWikiTitleCodec() returns a
MediaWikiTitleCodec,
- // which implements TitleFormatter.
- return self::getMediaWikiTitleCodec();
+ return MediaWikiServices::getInstance()->getTitleFormatter();
}
function __construct() {
@@ -3327,7 +3290,7 @@
// @note: splitTitleString() is a temporary hack to allow
MediaWikiTitleCodec to share
// the parsing code with Title, while avoiding massive
refactoring.
// @todo: get rid of secureAndSplit, refactor parsing code.
- $titleParser = self::getMediaWikiTitleCodec();
+ $titleParser =
MediaWikiServices::getInstance()->getTitleParser();
// MalformedTitleException can be thrown here
$parts = $titleParser->splitTitleString( $dbkey,
$this->getDefaultNamespace() );
diff --git a/tests/phpunit/includes/MediaWikiServicesTest.php
b/tests/phpunit/includes/MediaWikiServicesTest.php
index 1889575..1face19 100644
--- a/tests/phpunit/includes/MediaWikiServicesTest.php
+++ b/tests/phpunit/includes/MediaWikiServicesTest.php
@@ -25,6 +25,8 @@
'SiteStore' => [ 'getSiteStore', SiteStore::class ],
'SiteLookup' => [ 'getSiteLookup', SiteLookup::class ],
'StatsdDataFactory' => [ 'getStatsdDataFactory',
StatsdDataFactory::class ],
+ 'TitleFormatter' => [ 'getTitleFormatter',
TitleFormatter::class ],
+ 'TitleParser' => [ 'getTitleParser', TitleParser::class
],
];
}
@@ -49,6 +51,7 @@
'SiteStore' => [ 'SiteStore', SiteStore::class ],
'SiteLookup' => [ 'SiteLookup', SiteLookup::class ],
'StatsdDataFactory' => [ 'StatsdDataFactory',
StatsdDataFactory::class ],
+ 'MediaWikiTitleCodec' => [ 'MediaWikiTitleCodec',
MediaWikiTitleCodec::class ],
];
}
--
To view, visit https://gerrit.wikimedia.org/r/285141
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I81d48616afd1ab2bde1a5f1d12f4aefb1c866d43
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits