* @see https://www.mediawiki.org/wiki/Requests_for_comment/TitleValue
*/
class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
-
/**
* @var Language
*/
* @param GenderCache $genderCache the gender cache for generating gendered namespace names
* @param string[]|string $localInterwikis
*/
- public function __construct( Language $language, GenderCache $genderCache, $localInterwikis = array() ) {
+ public function __construct( Language $language, GenderCache $genderCache,
+ $localInterwikis = array()
+ ) {
$this->language = $language;
$this->genderCache = $genderCache;
$this->localInterwikis = (array)$localInterwikis;
* @param string $text
*
* @throws InvalidArgumentException if the namespace is invalid
- * @return String
+ * @return string
*/
public function getNamespaceName( $namespace, $text ) {
if ( $this->language->needsGenderDistinction() &&
- MWNamespace::hasGenderDistinction( $namespace ) ) {
+ MWNamespace::hasGenderDistinction( $namespace )
+ ) {
//NOTE: we are assuming here that the title text is a user name!
$gender = $this->genderCache->getGenderOf( $text, __METHOD__ );
* Parses the given text and constructs a TitleValue. Normalization
* is applied according to the rules appropriate for the form specified by $form.
*
- * @param string $text the text to parse
- * @param int $defaultNamespace namespace to assume per default (usually NS_MAIN)
+ * @param string $text The text to parse
+ * @param int $defaultNamespace Namespace to assume per default (usually NS_MAIN)
*
* @throws MalformedTitleException
* @return TitleValue
# Note: use of the /u option on preg_replace here will cause
# input with invalid UTF-8 sequences to be nullified out in PHP 5.2.x,
# conveniently disabling them.
- $dbkey = preg_replace( '/[ _\xA0\x{1680}\x{180E}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}]+/u', '_', $dbkey );
+ $dbkey = preg_replace(
+ '/[ _\xA0\x{1680}\x{180E}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}]+/u',
+ '_',
+ $dbkey
+ );
$dbkey = trim( $dbkey, '_' );
if ( strpos( $dbkey, UTF8_REPLACEMENT ) !== false ) {
}
# Namespace or interwiki prefix
- $firstPass = true;
$prefixRegexp = "/^(.+?)_*:_*(.*)$/S";
do {
$m = array();
}
}
} elseif ( Interwiki::isValidInterwiki( $p ) ) {
- if ( !$firstPass ) {
- //TODO: get rid of global state!
- # Can't make a local interwiki link to an interwiki link.
- # That's just crazy!
- throw new MalformedTitleException( 'Interwiki prefix found in title: ' . $text );
- }
-
# Interwiki link
$dbkey = $m[2];
$parts['interwiki'] = $this->language->lc( $p );
throw new MalformedTitleException( 'Local interwiki with empty title: ' . $text );
}
$parts['interwiki'] = '';
- $firstPass = false;
# Do another namespace split...
continue 2;
# Fill fields
$parts['dbkey'] = $dbkey;
+
return $parts;
}
-
}