101 if ( $this->language->needsGenderDistinction() &&
102 $this->nsInfo->hasGenderDistinction( $namespace )
105 $gender = $this->genderCache->getGenderOf( $text, __METHOD__ );
106 $name = $this->language->getGenderNsText( $namespace, $gender );
108 $name = $this->language->getNsText( $namespace );
111 if ( $name ===
false ) {
112 throw new InvalidArgumentException(
'Unknown namespace ID: ' . $namespace );
200 if ( !$this->nsInfo->exists( $namespace ) ) {
204 $canonicalNs = $this->nsInfo->getCanonicalName( $namespace );
205 $fullText = $canonicalNs ==
'' ? $text :
"$canonicalNs:$text";
206 if ( strval( $interwiki ) !=
'' ) {
207 $fullText =
"$interwiki:$fullText";
209 if ( strval( $fragment ) !=
'' ) {
210 $fullText .=
'#' . $fragment;
220 $parts[
'namespace'], $parts[
'dbkey'], $parts[
'fragment'], $parts[
'interwiki'] );
307 $dbkey = str_replace(
' ',
'_', $text );
312 'local_interwiki' =>
false,
314 'namespace' => $defaultNamespace,
316 'user_case_dbkey' => $dbkey,
319 # Strip Unicode bidi override characters.
320 # Sometimes they slip into cut-n-pasted page titles, where the
321 # override chars get included in list displays.
322 $dbkey = preg_replace(
'/[\x{200E}\x{200F}\x{202A}-\x{202E}]+/u',
'', $dbkey );
324 # Clean up whitespace
325 # Note: use of the /u option on preg_replace here will cause
326 # input with invalid UTF-8 sequences to be nullified out in PHP 5.2.x,
327 # conveniently disabling them.
328 $dbkey = preg_replace(
329 '/[ _\xA0\x{1680}\x{180E}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}]+/u',
333 $dbkey = trim( $dbkey,
'_' );
335 if ( strpos( $dbkey, UtfNormal\Constants::UTF8_REPLACEMENT ) !==
false ) {
336 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
340 $parts[
'dbkey'] = $dbkey;
342 # Initial colon indicates main namespace rather than specified default
343 # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
344 if ( $dbkey !==
'' && $dbkey[0] ==
':' ) {
346 $dbkey = substr( $dbkey, 1 ); #
remove the colon but
continue processing
347 $dbkey = trim( $dbkey,
'_' ); #
remove any subsequent whitespace
350 if ( $dbkey ==
'' ) {
354 # Namespace or interwiki prefix
355 $prefixRegexp =
"/^(.+?)_*:_*(.*)$/S";
358 if ( preg_match( $prefixRegexp, $dbkey, $m ) ) {
360 $ns = $this->language->getNsIndex( $p );
361 if ( $ns !==
false ) {
364 $parts[
'namespace'] = $ns;
365 # For Talk:X pages, check if X has a "namespace" prefix
366 if ( $ns ==
NS_TALK && preg_match( $prefixRegexp, $dbkey, $x ) ) {
367 if ( $this->language->getNsIndex( $x[1] ) ) {
368 # Disallow Talk:File:x type titles...
370 } elseif ( $this->interwikiLookup->isValidInterwiki( $x[1] ) ) {
371 # Disallow Talk:Interwiki:x type titles...
375 } elseif ( $this->interwikiLookup->isValidInterwiki( $p ) ) {
378 $parts[
'interwiki'] = $this->language->lc( $p );
380 # Redundant interwiki prefix to the local wiki
381 foreach ( $this->localInterwikis as $localIW ) {
382 if ( strcasecmp( $parts[
'interwiki'], $localIW ) == 0 ) {
383 if ( $dbkey ==
'' ) {
384 # Empty self-links should point to the Main Page, to ensure
385 # compatibility with cross-wiki transclusions and the like.
386 $mainPage = Title::newMainPage();
388 'interwiki' => $mainPage->getInterwiki(),
389 'local_interwiki' =>
true,
390 'fragment' => $mainPage->getFragment(),
391 'namespace' => $mainPage->getNamespace(),
392 'dbkey' => $mainPage->getDBkey(),
393 'user_case_dbkey' => $mainPage->getUserCaseDBKey()
396 $parts[
'interwiki'] =
'';
397 # local interwikis should behave like initial-colon links
398 $parts[
'local_interwiki'] =
true;
400 # Do another namespace split...
405 # If there's an initial colon after the interwiki, that also
406 # resets the default namespace
407 if ( $dbkey !==
'' && $dbkey[0] ==
':' ) {
409 $dbkey = substr( $dbkey, 1 );
410 $dbkey = trim( $dbkey,
'_' );
413 # If there's no recognized interwiki or namespace,
414 # then let the colon expression be part of the title.
419 $fragment = strstr( $dbkey,
'#' );
420 if ( $fragment !==
false ) {
421 $parts[
'fragment'] = str_replace(
'_',
' ', substr( $fragment, 1 ) );
422 $dbkey = substr( $dbkey, 0, strlen( $dbkey ) - strlen( $fragment ) );
423 # remove whitespace again: prevents "Foo_bar_#"
424 # becoming "Foo_bar_"
425 $dbkey = preg_replace(
'/_*$/',
'', $dbkey );
428 # Reject illegal characters.
429 $rxTc = self::getTitleInvalidRegex();
431 if ( preg_match( $rxTc, $dbkey,
$matches ) ) {
435 # Pages with "/./" or "/../" appearing in the URLs will often be un-
436 # reachable due to the way web browsers deal with 'relative' URLs.
437 # Also, they conflict with subpage syntax. Forbid them explicitly.
439 strpos( $dbkey,
'.' ) !==
false &&
441 $dbkey ===
'.' || $dbkey ===
'..' ||
442 strpos( $dbkey,
'./' ) === 0 ||
443 strpos( $dbkey,
'../' ) === 0 ||
444 strpos( $dbkey,
'/./' ) !==
false ||
445 strpos( $dbkey,
'/../' ) !==
false ||
446 substr( $dbkey, -2 ) ==
'/.' ||
447 substr( $dbkey, -3 ) ==
'/..'
453 # Magic tilde sequences? Nu-uh!
454 if ( strpos( $dbkey,
'~~~' ) !==
false ) {
458 # Limit the size of titles to 255 bytes. This is typically the size of the
459 # underlying database field. We make an exception for special pages, which
460 # don't need to be stored in the database, and may edge over 255 bytes due
461 # to subpage syntax for long titles, e.g. [[Special:Block/Long name]]
462 $maxLength = ( $parts[
'namespace'] !=
NS_SPECIAL ) ? 255 : 512;
463 if ( strlen( $dbkey ) > $maxLength ) {
468 # Normally, all wiki links are forced to have an initial capital letter so [[foo]]
469 # and [[Foo]] point to the same place. Don't force it for interwikis, since the
470 # other site might be case-sensitive.
471 $parts[
'user_case_dbkey'] = $dbkey;
472 if ( $parts[
'interwiki'] ===
'' && $this->nsInfo->isCapitalized( $parts[
'namespace'] ) ) {
473 $dbkey = $this->language->ucfirst( $dbkey );
476 # Can't make a link to a namespace alone... "empty" local links can only be
477 # self-links with a fragment identifier.
478 if ( $dbkey ==
'' && $parts[
'interwiki'] ===
'' && $parts[
'namespace'] !=
NS_MAIN ) {
489 $dbkey = IP::sanitizeIP( $dbkey );
493 if ( $dbkey !==
'' && $dbkey[0] ==
':' ) {
498 $parts[
'dbkey'] = $dbkey;