From: jenkins-bot Date: Mon, 19 Aug 2019 16:04:04 +0000 (+0000) Subject: Merge "Use injected services instead of static method" X-Git-Tag: 1.34.0-rc.0~678 X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_add%27%29%20%7D%7D?a=commitdiff_plain;h=db0c27a96534d81ef0432dcedeb7bc40ef7e6121;hp=-c;p=lhc%2Fweb%2Fwiklou.git Merge "Use injected services instead of static method" --- db0c27a96534d81ef0432dcedeb7bc40ef7e6121 diff --combined includes/title/MediaWikiTitleCodec.php index 7e7d85a38e,039cf4e6d6..3bd66d40c6 --- a/includes/title/MediaWikiTitleCodec.php +++ b/includes/title/MediaWikiTitleCodec.php @@@ -62,7 -62,8 +62,8 @@@ class MediaWikiTitleCodec implements Ti protected $nsInfo; /** - * @param Language $language The language object to use for localizing namespace names. + * @param Language $language The language object to use for localizing namespace names, + * capitalization, etc. * @param GenderCache $genderCache The gender cache for generating gendered namespace names * @param string[]|string $localInterwikis * @param InterwikiLookup|null $interwikiLookup @@@ -185,40 -186,6 +186,40 @@@ ); } + /** + * Given a namespace and title, return a TitleValue if valid, or null if invalid. + * + * @param int $namespace + * @param string $text + * @param string $fragment + * @param string $interwiki + * + * @return TitleValue|null + */ + public function makeTitleValueSafe( $namespace, $text, $fragment = '', $interwiki = '' ) { + if ( !$this->nsInfo->exists( $namespace ) ) { + return null; + } + + $canonicalNs = $this->nsInfo->getCanonicalName( $namespace ); + $fullText = $canonicalNs == '' ? $text : "$canonicalNs:$text"; + if ( strval( $interwiki ) != '' ) { + $fullText = "$interwiki:$fullText"; + } + if ( strval( $fragment ) != '' ) { + $fullText .= '#' . $fragment; + } + + try { + $parts = $this->splitTitleString( $fullText ); + } catch ( MalformedTitleException $e ) { + return null; + } + + return new TitleValue( + $parts['namespace'], $parts['dbkey'], $parts['fragment'], $parts['interwiki'] ); + } + /** * @see TitleFormatter::getText() * @@@ -467,8 -434,8 +468,8 @@@ # and [[Foo]] point to the same place. Don't force it for interwikis, since the # other site might be case-sensitive. $parts['user_case_dbkey'] = $dbkey; - if ( $parts['interwiki'] === '' ) { - $dbkey = Title::capitalize( $dbkey, $parts['namespace'] ); + if ( $parts['interwiki'] === '' && $this->nsInfo->isCapitalized( $parts['namespace'] ) ) { + $dbkey = $this->language->ucfirst( $dbkey ); } # Can't make a link to a namespace alone... "empty" local links can only be