X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ftitle%2FMediaWikiTitleCodec.php;h=778fb3f0330c4cfc3dc13d82f4145252708a36e9;hb=81c91fd493fd52926b454826d621c60b7818503f;hp=e06bfb53d81a380540e3e32630781f0ccbe9c93a;hpb=2dbfa098daab668ff3ba49d6502d2cdd957545f0;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/title/MediaWikiTitleCodec.php b/includes/title/MediaWikiTitleCodec.php index e06bfb53d8..778fb3f033 100644 --- a/includes/title/MediaWikiTitleCodec.php +++ b/includes/title/MediaWikiTitleCodec.php @@ -56,20 +56,35 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { */ protected $interwikiLookup; + /** + * @var NamespaceInfo + */ + protected $nsInfo; + /** * @param Language $language The language object to use for localizing namespace names. * @param GenderCache $genderCache The gender cache for generating gendered namespace names * @param string[]|string $localInterwikis * @param InterwikiLookup|null $interwikiLookup + * @param NamespaceInfo|null $nsInfo */ public function __construct( Language $language, GenderCache $genderCache, - $localInterwikis = [], $interwikiLookup = null + $localInterwikis = [], InterwikiLookup $interwikiLookup = null, + NamespaceInfo $nsInfo = null ) { + if ( !$interwikiLookup ) { + wfDeprecated( __METHOD__ . ' with no InterwikiLookup argument', '1.34' ); + $interwikiLookup = MediaWikiServices::getInstance()->getInterwikiLookup(); + } + if ( !$nsInfo ) { + wfDeprecated( __METHOD__ . ' with no NamespaceInfo argument', '1.34' ); + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); + } $this->language = $language; $this->genderCache = $genderCache; $this->localInterwikis = (array)$localInterwikis; - $this->interwikiLookup = $interwikiLookup ?: - MediaWikiServices::getInstance()->getInterwikiLookup(); + $this->interwikiLookup = $interwikiLookup; + $this->nsInfo = $nsInfo; } /** @@ -83,7 +98,7 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { */ public function getNamespaceName( $namespace, $text ) { if ( $this->language->needsGenderDistinction() && - MWNamespace::hasGenderDistinction( $namespace ) + $this->nsInfo->hasGenderDistinction( $namespace ) ) { // NOTE: we are assuming here that the title text is a user name! $gender = $this->genderCache->getGenderOf( $text, __METHOD__ ); @@ -139,8 +154,7 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { } /** - * Parses the given text and constructs a TitleValue. Normalization - * is applied according to the rules appropriate for the form specified by $form. + * Parses the given text and constructs a TitleValue. * * @param string $text The text to parse * @param int $defaultNamespace Namespace to assume per default (usually NS_MAIN) @@ -149,13 +163,17 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { * @return TitleValue */ public function parseTitle( $text, $defaultNamespace = NS_MAIN ) { + // Convert things like é ā or 〗 into normalized (T16952) text + $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text ); + // NOTE: this is an ugly cludge that allows this class to share the // code for parsing with the old Title class. The parser code should // be refactored to avoid this. - $parts = $this->splitTitleString( $text, $defaultNamespace ); + $parts = $this->splitTitleString( $filteredText, $defaultNamespace ); - // Relative fragment links are not supported by TitleValue - if ( $parts['dbkey'] === '' ) { + // Fragment-only is okay, but only with no namespace + if ( $parts['dbkey'] === '' && + ( $parts['fragment'] === '' || $parts['namespace'] !== NS_MAIN ) ) { throw new MalformedTitleException( 'title-invalid-empty', $text ); } @@ -421,10 +439,8 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { # Can't make a link to a namespace alone... "empty" local links can only be # self-links with a fragment identifier. - if ( $dbkey == '' && $parts['interwiki'] === '' ) { - if ( $parts['namespace'] != NS_MAIN ) { - throw new MalformedTitleException( 'title-invalid-empty', $text ); - } + if ( $dbkey == '' && $parts['interwiki'] === '' && $parts['namespace'] != NS_MAIN ) { + throw new MalformedTitleException( 'title-invalid-empty', $text ); } // Allow IPv6 usernames to start with '::' by canonicalizing IPv6 titles.