9 require_once( 'normal/UtfNormal.php' );
11 define ( 'GAID_FOR_UPDATE', 1 );
13 # Title::newFromTitle maintains a cache to avoid
14 # expensive re-normalization of commonly used titles.
15 # On a batch operation this can become a memory leak
16 # if not bounded. After hitting this many titles,
18 define( 'MW_TITLECACHE_MAX', 1000 );
20 # Constants for pr_cascade bitfield
21 define( 'CASCADE', 1 );
25 * - Represents a title, which may contain an interwiki designation or namespace
26 * - Can fetch various kinds of data from the database, albeit inefficiently.
32 * Static cache variables
34 static private $titleCache=array();
35 static private $interwikiCache=array();
39 * All member variables should be considered private
40 * Please use the accessor functions
47 var $mTextform; # Text form (spaces not underscores) of the main part
48 var $mUrlform; # URL-encoded form of the main part
49 var $mDbkeyform; # Main part with underscores
50 var $mNamespace; # Namespace index, i.e. one of the NS_xxxx constants
51 var $mInterwiki; # Interwiki prefix (or null string)
52 var $mFragment; # Title fragment (i.e. the bit after the #)
53 var $mArticleID; # Article ID, fetched from the link cache on demand
54 var $mLatestID; # ID of most recent revision
55 var $mRestrictions; # Array of groups allowed to edit this article
56 var $mCascadeRestriction; # Cascade restrictions on this page to included templates and images?
57 var $mHasCascadingRestrictions; # Are cascading restrictions in effect on this page?
58 var $mCascadeRestrictionSources;# Where are the cascading restrictions coming from on this page?
59 var $mRestrictionsLoaded; # Boolean for initialisation on demand
60 var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
61 var $mDefaultNamespace; # Namespace index when there is no namespace
62 # Zero except in {{transclusion}} tags
63 var $mWatched; # Is $wgUser watching this page? NULL if unfilled, accessed through userIsWatching()
71 /* private */ function Title() {
72 $this->mInterwiki
= $this->mUrlform
=
73 $this->mTextform
= $this->mDbkeyform
= '';
74 $this->mArticleID
= -1;
75 $this->mNamespace
= NS_MAIN
;
76 $this->mRestrictionsLoaded
= false;
77 $this->mRestrictions
= array();
78 # Dont change the following, NS_MAIN is hardcoded in several place
80 $this->mDefaultNamespace
= NS_MAIN
;
81 $this->mWatched
= NULL;
82 $this->mLatestID
= false;
83 $this->mOldRestrictions
= false;
87 * Create a new Title from a prefixed DB key
88 * @param string $key The database key, which has underscores
89 * instead of spaces, possibly including namespace and
91 * @return Title the new object, or NULL on an error
95 /* static */ function newFromDBkey( $key ) {
97 $t->mDbkeyform
= $key;
98 if( $t->secureAndSplit() )
105 * Create a new Title from text, such as what one would
106 * find in a link. Decodes any HTML entities in the text.
108 * @param string $text the link text; spaces, prefixes,
109 * and an initial ':' indicating the main namespace
111 * @param int $defaultNamespace the namespace to use if
112 * none is specified by a prefix
113 * @return Title the new object, or NULL on an error
117 public static function newFromText( $text, $defaultNamespace = NS_MAIN
) {
118 if( is_object( $text ) ) {
119 throw new MWException( 'Title::newFromText given an object' );
123 * Wiki pages often contain multiple links to the same page.
124 * Title normalization and parsing can become expensive on
125 * pages with many links, so we can save a little time by
128 * In theory these are value objects and won't get changed...
130 if( $defaultNamespace == NS_MAIN
&& isset( Title
::$titleCache[$text] ) ) {
131 return Title
::$titleCache[$text];
135 * Convert things like é ā or 〗 into real text...
137 $filteredText = Sanitizer
::decodeCharReferences( $text );
140 $t->mDbkeyform
= str_replace( ' ', '_', $filteredText );
141 $t->mDefaultNamespace
= $defaultNamespace;
143 static $cachedcount = 0 ;
144 if( $t->secureAndSplit() ) {
145 if( $defaultNamespace == NS_MAIN
) {
146 if( $cachedcount >= MW_TITLECACHE_MAX
) {
147 # Avoid memory leaks on mass operations...
148 Title
::$titleCache = array();
152 Title
::$titleCache[$text] =& $t;
162 * Create a new Title from URL-encoded text. Ensures that
163 * the given title's length does not exceed the maximum.
164 * @param string $url the title, as might be taken from a URL
165 * @return Title the new object, or NULL on an error
169 public static function newFromURL( $url ) {
170 global $wgLegalTitleChars;
173 # For compatibility with old buggy URLs. "+" is usually not valid in titles,
174 # but some URLs used it as a space replacement and they still come
175 # from some external search tools.
176 if ( strpos( $wgLegalTitleChars, '+' ) === false ) {
177 $url = str_replace( '+', ' ', $url );
180 $t->mDbkeyform
= str_replace( ' ', '_', $url );
181 if( $t->secureAndSplit() ) {
189 * Create a new Title from an article ID
191 * @todo This is inefficiently implemented, the page row is requested
192 * but not used for anything else
194 * @param int $id the page_id corresponding to the Title to create
195 * @return Title the new object, or NULL on an error
199 public static function newFromID( $id ) {
200 $fname = 'Title::newFromID';
201 $dbr =& wfGetDB( DB_SLAVE
);
202 $row = $dbr->selectRow( 'page', array( 'page_namespace', 'page_title' ),
203 array( 'page_id' => $id ), $fname );
204 if ( $row !== false ) {
205 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
213 * Make an array of titles from an array of IDs
215 function newFromIDs( $ids ) {
216 $dbr =& wfGetDB( DB_SLAVE
);
217 $res = $dbr->select( 'page', array( 'page_namespace', 'page_title' ),
218 'page_id IN (' . $dbr->makeList( $ids ) . ')', __METHOD__
);
221 while ( $row = $dbr->fetchObject( $res ) ) {
222 $titles[] = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
228 * Create a new Title from a namespace index and a DB key.
229 * It's assumed that $ns and $title are *valid*, for instance when
230 * they came directly from the database or a special page name.
231 * For convenience, spaces are converted to underscores so that
232 * eg user_text fields can be used directly.
234 * @param int $ns the namespace of the article
235 * @param string $title the unprefixed database key form
236 * @return Title the new object
240 public static function &makeTitle( $ns, $title ) {
244 $t->mNamespace
= intval( $ns );
245 $t->mDbkeyform
= str_replace( ' ', '_', $title );
246 $t->mArticleID
= ( $ns >= 0 ) ?
-1 : 0;
247 $t->mUrlform
= wfUrlencode( $t->mDbkeyform
);
248 $t->mTextform
= str_replace( '_', ' ', $title );
253 * Create a new Title from a namespace index and a DB key.
254 * The parameters will be checked for validity, which is a bit slower
255 * than makeTitle() but safer for user-provided data.
257 * @param int $ns the namespace of the article
258 * @param string $title the database key form
259 * @return Title the new object, or NULL on an error
263 public static function makeTitleSafe( $ns, $title ) {
265 $t->mDbkeyform
= Title
::makeName( $ns, $title );
266 if( $t->secureAndSplit() ) {
274 * Create a new Title for the Main Page
277 * @return Title the new object
280 public static function newMainPage() {
281 return Title
::newFromText( wfMsgForContent( 'mainpage' ) );
285 * Create a new Title for a redirect
286 * @param string $text the redirect title text
287 * @return Title the new object, or NULL if the text is not a
290 public static function newFromRedirect( $text ) {
291 $mwRedir = MagicWord
::get( 'redirect' );
293 if ( $mwRedir->matchStart( $text ) ) {
295 if ( preg_match( '/\[{2}(.*?)(?:\||\]{2})/', $text, $m ) ) {
296 # categories are escaped using : for example one can enter:
297 # #REDIRECT [[:Category:Music]]. Need to remove it.
298 if ( substr($m[1],0,1) == ':') {
299 # We don't want to keep the ':'
300 $m[1] = substr( $m[1], 1 );
303 $rt = Title
::newFromText( $m[1] );
304 # Disallow redirects to Special:Userlogout
305 if ( !is_null($rt) && $rt->isSpecial( 'Userlogout' ) ) {
313 #----------------------------------------------------------------------------
315 #----------------------------------------------------------------------------
318 * Get the prefixed DB key associated with an ID
319 * @param int $id the page_id of the article
320 * @return Title an object representing the article, or NULL
321 * if no such article was found
325 function nameOf( $id ) {
326 $fname = 'Title::nameOf';
327 $dbr =& wfGetDB( DB_SLAVE
);
329 $s = $dbr->selectRow( 'page', array( 'page_namespace','page_title' ), array( 'page_id' => $id ), $fname );
330 if ( $s === false ) { return NULL; }
332 $n = Title
::makeName( $s->page_namespace
, $s->page_title
);
337 * Get a regex character class describing the legal characters in a link
338 * @return string the list of characters, not delimited
342 public static function legalChars() {
343 global $wgLegalTitleChars;
344 return $wgLegalTitleChars;
348 * Get a string representation of a title suitable for
349 * including in a search index
351 * @param int $ns a namespace index
352 * @param string $title text-form main part
353 * @return string a stripped-down title string ready for the
356 public static function indexTitle( $ns, $title ) {
359 $lc = SearchEngine
::legalSearchChars() . '&#;';
360 $t = $wgContLang->stripForSearch( $title );
361 $t = preg_replace( "/[^{$lc}]+/", ' ', $t );
362 $t = $wgContLang->lc( $t );
365 $t = preg_replace( "/([{$lc}]+)'s( |$)/", "\\1 \\1's ", $t );
366 $t = preg_replace( "/([{$lc}]+)s'( |$)/", "\\1s ", $t );
368 $t = preg_replace( "/\\s+/", ' ', $t );
370 if ( $ns == NS_IMAGE
) {
371 $t = preg_replace( "/ (png|gif|jpg|jpeg|ogg)$/", "", $t );
377 * Make a prefixed DB key from a DB key and a namespace index
378 * @param int $ns numerical representation of the namespace
379 * @param string $title the DB key form the title
380 * @return string the prefixed form of the title
382 public static function makeName( $ns, $title ) {
385 $n = $wgContLang->getNsText( $ns );
386 return $n == '' ?
$title : "$n:$title";
390 * Returns the URL associated with an interwiki prefix
391 * @param string $key the interwiki prefix (e.g. "MeatBall")
392 * @return the associated URL, containing "$1", which should be
393 * replaced by an article title
397 function getInterwikiLink( $key ) {
398 global $wgMemc, $wgInterwikiExpiry;
399 global $wgInterwikiCache, $wgContLang;
400 $fname = 'Title::getInterwikiLink';
402 $key = $wgContLang->lc( $key );
404 $k = wfMemcKey( 'interwiki', $key );
405 if( array_key_exists( $k, Title
::$interwikiCache ) ) {
406 return Title
::$interwikiCache[$k]->iw_url
;
409 if ($wgInterwikiCache) {
410 return Title
::getInterwikiCached( $key );
413 $s = $wgMemc->get( $k );
414 # Ignore old keys with no iw_local
415 if( $s && isset( $s->iw_local
) && isset($s->iw_trans
)) {
416 Title
::$interwikiCache[$k] = $s;
420 $dbr =& wfGetDB( DB_SLAVE
);
421 $res = $dbr->select( 'interwiki',
422 array( 'iw_url', 'iw_local', 'iw_trans' ),
423 array( 'iw_prefix' => $key ), $fname );
428 $s = $dbr->fetchObject( $res );
430 # Cache non-existence: create a blank object and save it to memcached
436 $wgMemc->set( $k, $s, $wgInterwikiExpiry );
437 Title
::$interwikiCache[$k] = $s;
443 * Fetch interwiki prefix data from local cache in constant database
445 * More logic is explained in DefaultSettings
447 * @return string URL of interwiki site
450 function getInterwikiCached( $key ) {
451 global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
455 $db=dba_open($wgInterwikiCache,'r','cdb');
456 /* Resolve site name */
457 if ($wgInterwikiScopes>=3 and !$site) {
458 $site = dba_fetch('__sites:' . wfWikiID(), $db);
460 $site = $wgInterwikiFallbackSite;
462 $value = dba_fetch( wfMemcKey( $key ), $db);
463 if ($value=='' and $wgInterwikiScopes>=3) {
465 $value = dba_fetch("_{$site}:{$key}", $db);
467 if ($value=='' and $wgInterwikiScopes>=2) {
469 $value = dba_fetch("__global:{$key}", $db);
478 list($local,$url)=explode(' ',$value,2);
480 $s->iw_local
=(int)$local;
482 Title
::$interwikiCache[wfMemcKey( 'interwiki', $key )] = $s;
486 * Determine whether the object refers to a page within
489 * @return bool TRUE if this is an in-project interwiki link
490 * or a wikilink, FALSE otherwise
494 if ( $this->mInterwiki
!= '' ) {
495 # Make sure key is loaded into cache
496 $this->getInterwikiLink( $this->mInterwiki
);
497 $k = wfMemcKey( 'interwiki', $this->mInterwiki
);
498 return (bool)(Title
::$interwikiCache[$k]->iw_local
);
505 * Determine whether the object refers to a page within
506 * this project and is transcludable.
508 * @return bool TRUE if this is transcludable
512 if ($this->mInterwiki
== '')
514 # Make sure key is loaded into cache
515 $this->getInterwikiLink( $this->mInterwiki
);
516 $k = wfMemcKey( 'interwiki', $this->mInterwiki
);
517 return (bool)(Title
::$interwikiCache[$k]->iw_trans
);
521 * Update the page_touched field for an array of title objects
522 * @todo Inefficient unless the IDs are already loaded into the
524 * @param array $titles an array of Title objects to be touched
525 * @param string $timestamp the timestamp to use instead of the
526 * default current time
530 function touchArray( $titles, $timestamp = '' ) {
532 if ( count( $titles ) == 0 ) {
535 $dbw =& wfGetDB( DB_MASTER
);
536 if ( $timestamp == '' ) {
537 $timestamp = $dbw->timestamp();
540 $page = $dbw->tableName( 'page' );
541 $sql = "UPDATE $page SET page_touched='{$timestamp}' WHERE page_id IN (";
544 foreach ( $titles as $title ) {
545 if ( $wgUseFileCache ) {
546 $cm = new HTMLFileCache($title);
547 @unlink($cm->fileCacheName());
554 $sql .= $title->getArticleID();
558 $dbw->query( $sql, 'Title::touchArray' );
561 // hack hack hack -- brion 2005-07-11. this was unfriendly to db.
562 // do them in small chunks:
563 $fname = 'Title::touchArray';
564 foreach( $titles as $title ) {
565 $dbw->update( 'page',
566 array( 'page_touched' => $timestamp ),
568 'page_namespace' => $title->getNamespace(),
569 'page_title' => $title->getDBkey() ),
575 * Escape a text fragment, say from a link, for a URL
577 static function escapeFragmentForURL( $fragment ) {
578 $fragment = str_replace( ' ', '_', $fragment );
579 $fragment = urlencode( Sanitizer
::decodeCharReferences( $fragment ) );
580 $replaceArray = array(
584 return strtr( $fragment, $replaceArray );
587 #----------------------------------------------------------------------------
589 #----------------------------------------------------------------------------
591 /** Simple accessors */
593 * Get the text form (spaces not underscores) of the main part
597 function getText() { return $this->mTextform
; }
599 * Get the URL-encoded form of the main part
603 function getPartialURL() { return $this->mUrlform
; }
605 * Get the main part with underscores
609 function getDBkey() { return $this->mDbkeyform
; }
611 * Get the namespace index, i.e. one of the NS_xxxx constants
615 function getNamespace() { return $this->mNamespace
; }
617 * Get the namespace text
621 function getNsText() {
622 global $wgContLang, $wgCanonicalNamespaceNames;
624 if ( '' != $this->mInterwiki
) {
625 // This probably shouldn't even happen. ohh man, oh yuck.
626 // But for interwiki transclusion it sometimes does.
627 // Shit. Shit shit shit.
629 // Use the canonical namespaces if possible to try to
630 // resolve a foreign namespace.
631 if( isset( $wgCanonicalNamespaceNames[$this->mNamespace
] ) ) {
632 return $wgCanonicalNamespaceNames[$this->mNamespace
];
635 return $wgContLang->getNsText( $this->mNamespace
);
638 * Get the namespace text of the subject (rather than talk) page
642 function getSubjectNsText() {
644 return $wgContLang->getNsText( Namespace::getSubject( $this->mNamespace
) );
648 * Get the namespace text of the talk page
651 function getTalkNsText() {
653 return( $wgContLang->getNsText( Namespace::getTalk( $this->mNamespace
) ) );
657 * Could this title have a corresponding talk page?
661 return( Namespace::canTalk( $this->mNamespace
) );
665 * Get the interwiki prefix (or null string)
669 function getInterwiki() { return $this->mInterwiki
; }
671 * Get the Title fragment (i.e. the bit after the #) in text form
675 function getFragment() { return $this->mFragment
; }
677 * Get the fragment in URL form, including the "#" character if there is one
682 function getFragmentForURL() {
683 if ( $this->mFragment
== '' ) {
686 return '#' . Title
::escapeFragmentForURL( $this->mFragment
);
690 * Get the default namespace index, for when there is no namespace
694 function getDefaultNamespace() { return $this->mDefaultNamespace
; }
697 * Get title for search index
698 * @return string a stripped-down title string ready for the
701 function getIndexTitle() {
702 return Title
::indexTitle( $this->mNamespace
, $this->mTextform
);
706 * Get the prefixed database key form
707 * @return string the prefixed title, with underscores and
708 * any interwiki and namespace prefixes
711 function getPrefixedDBkey() {
712 $s = $this->prefix( $this->mDbkeyform
);
713 $s = str_replace( ' ', '_', $s );
718 * Get the prefixed title with spaces.
719 * This is the form usually used for display
720 * @return string the prefixed title, with spaces
723 function getPrefixedText() {
724 if ( empty( $this->mPrefixedText
) ) { // FIXME: bad usage of empty() ?
725 $s = $this->prefix( $this->mTextform
);
726 $s = str_replace( '_', ' ', $s );
727 $this->mPrefixedText
= $s;
729 return $this->mPrefixedText
;
733 * Get the prefixed title with spaces, plus any fragment
734 * (part beginning with '#')
735 * @return string the prefixed title, with spaces and
736 * the fragment, including '#'
739 function getFullText() {
740 $text = $this->getPrefixedText();
741 if( '' != $this->mFragment
) {
742 $text .= '#' . $this->mFragment
;
748 * Get the base name, i.e. the leftmost parts before the /
749 * @return string Base name
751 function getBaseText() {
752 global $wgNamespacesWithSubpages;
753 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) && $wgNamespacesWithSubpages[ $this->mNamespace
] ) {
754 $parts = explode( '/', $this->getText() );
755 # Don't discard the real title if there's no subpage involved
756 if( count( $parts ) > 1 )
757 unset( $parts[ count( $parts ) - 1 ] );
758 return implode( '/', $parts );
760 return $this->getText();
765 * Get the lowest-level subpage name, i.e. the rightmost part after /
766 * @return string Subpage name
768 function getSubpageText() {
769 global $wgNamespacesWithSubpages;
770 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) && $wgNamespacesWithSubpages[ $this->mNamespace
] ) {
771 $parts = explode( '/', $this->mTextform
);
772 return( $parts[ count( $parts ) - 1 ] );
774 return( $this->mTextform
);
779 * Get a URL-encoded form of the subpage text
780 * @return string URL-encoded subpage name
782 function getSubpageUrlForm() {
783 $text = $this->getSubpageText();
784 $text = wfUrlencode( str_replace( ' ', '_', $text ) );
785 $text = str_replace( '%28', '(', str_replace( '%29', ')', $text ) ); # Clean up the URL; per below, this might not be safe
790 * Get a URL-encoded title (not an actual URL) including interwiki
791 * @return string the URL-encoded form
794 function getPrefixedURL() {
795 $s = $this->prefix( $this->mDbkeyform
);
796 $s = str_replace( ' ', '_', $s );
798 $s = wfUrlencode ( $s ) ;
800 # Cleaning up URL to make it look nice -- is this safe?
801 $s = str_replace( '%28', '(', $s );
802 $s = str_replace( '%29', ')', $s );
808 * Get a real URL referring to this title, with interwiki link and
811 * @param string $query an optional query string, not used
812 * for interwiki links
813 * @param string $variant language variant of url (for sr, zh..)
814 * @return string the URL
817 function getFullURL( $query = '', $variant = false ) {
818 global $wgContLang, $wgServer, $wgRequest;
820 if ( '' == $this->mInterwiki
) {
821 $url = $this->getLocalUrl( $query, $variant );
823 // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
824 // Correct fix would be to move the prepending elsewhere.
825 if ($wgRequest->getVal('action') != 'render') {
826 $url = $wgServer . $url;
829 $baseUrl = $this->getInterwikiLink( $this->mInterwiki
);
831 $namespace = wfUrlencode( $this->getNsText() );
832 if ( '' != $namespace ) {
833 # Can this actually happen? Interwikis shouldn't be parsed.
834 # Yes! It can in interwiki transclusion. But... it probably shouldn't.
837 $url = str_replace( '$1', $namespace . $this->mUrlform
, $baseUrl );
839 if( false === strpos( $url, '?' ) ) {
848 # Finally, add the fragment.
849 $url .= $this->getFragmentForURL();
851 wfRunHooks( 'GetFullURL', array( &$this, &$url, $query ) );
856 * Get a URL with no fragment or server name. If this page is generated
857 * with action=render, $wgServer is prepended.
858 * @param string $query an optional query string; if not specified,
859 * $wgArticlePath will be used.
860 * @param string $variant language variant of url (for sr, zh..)
861 * @return string the URL
864 function getLocalURL( $query = '', $variant = false ) {
865 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
866 global $wgVariantArticlePath, $wgContLang, $wgUser;
868 // internal links should point to same variant as current page (only anonymous users)
869 if($variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn()){
870 $pref = $wgContLang->getPreferredVariant(false);
871 if($pref != $wgContLang->getCode())
875 if ( $this->isExternal() ) {
876 $url = $this->getFullURL();
878 // This is currently only used for edit section links in the
879 // context of interwiki transclusion. In theory we should
880 // append the query to the end of any existing query string,
881 // but interwiki transclusion is already broken in that case.
885 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
886 if ( $query == '' ) {
887 if($variant!=false && $wgContLang->hasVariants()){
888 if($wgVariantArticlePath==false)
889 $variantArticlePath = "$wgScript?title=$1&variant=$2"; // default
891 $variantArticlePath = $wgVariantArticlePath;
893 $url = str_replace( '$2', urlencode( $variant ), $variantArticlePath );
894 $url = str_replace( '$1', $dbkey, $url );
898 $url = str_replace( '$1', $dbkey, $wgArticlePath );
900 global $wgActionPaths;
903 if( !empty( $wgActionPaths ) &&
904 preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) )
906 $action = urldecode( $matches[2] );
907 if( isset( $wgActionPaths[$action] ) ) {
908 $query = $matches[1];
909 if( isset( $matches[4] ) ) $query .= $matches[4];
910 $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
911 if( $query != '' ) $url .= '?' . $query;
914 if ( $url === false ) {
915 if ( $query == '-' ) {
918 $url = "{$wgScript}?title={$dbkey}&{$query}";
922 // FIXME: this causes breakage in various places when we
923 // actually expected a local URL and end up with dupe prefixes.
924 if ($wgRequest->getVal('action') == 'render') {
925 $url = $wgServer . $url;
928 wfRunHooks( 'GetLocalURL', array( &$this, &$url, $query ) );
933 * Get an HTML-escaped version of the URL form, suitable for
934 * using in a link, without a server name or fragment
935 * @param string $query an optional query string
936 * @return string the URL
939 function escapeLocalURL( $query = '' ) {
940 return htmlspecialchars( $this->getLocalURL( $query ) );
944 * Get an HTML-escaped version of the URL form, suitable for
945 * using in a link, including the server name and fragment
947 * @return string the URL
948 * @param string $query an optional query string
951 function escapeFullURL( $query = '' ) {
952 return htmlspecialchars( $this->getFullURL( $query ) );
956 * Get the URL form for an internal link.
957 * - Used in various Squid-related code, in case we have a different
958 * internal hostname for the server from the exposed one.
960 * @param string $query an optional query string
961 * @param string $variant language variant of url (for sr, zh..)
962 * @return string the URL
965 function getInternalURL( $query = '', $variant = false ) {
966 global $wgInternalServer;
967 $url = $wgInternalServer . $this->getLocalURL( $query, $variant );
968 wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
973 * Get the edit URL for this Title
974 * @return string the URL, or a null string if this is an
978 function getEditURL() {
979 if ( '' != $this->mInterwiki
) { return ''; }
980 $s = $this->getLocalURL( 'action=edit' );
986 * Get the HTML-escaped displayable text form.
987 * Used for the title field in <a> tags.
988 * @return string the text, including any prefixes
991 function getEscapedText() {
992 return htmlspecialchars( $this->getPrefixedText() );
996 * Is this Title interwiki?
1000 function isExternal() { return ( '' != $this->mInterwiki
); }
1003 * Is this page "semi-protected" - the *only* protection is autoconfirm?
1005 * @param string Action to check (default: edit)
1008 function isSemiProtected( $action = 'edit' ) {
1009 if( $this->exists() ) {
1010 $restrictions = $this->getRestrictions( $action );
1011 if( count( $restrictions ) > 0 ) {
1012 foreach( $restrictions as $restriction ) {
1013 if( strtolower( $restriction ) != 'autoconfirmed' )
1022 # If it doesn't exist, it can't be protected
1028 * Does the title correspond to a protected article?
1029 * @param string $what the action the page is protected from,
1030 * by default checks move and edit
1034 function isProtected( $action = '' ) {
1035 global $wgRestrictionLevels;
1037 if ( NS_SPECIAL
== $this->mNamespace
) { return true; }
1039 if ( $this->isCascadeProtected() ) { return true; }
1041 if( $action == 'edit' ||
$action == '' ) {
1042 $r = $this->getRestrictions( 'edit' );
1043 foreach( $wgRestrictionLevels as $level ) {
1044 if( in_array( $level, $r ) && $level != '' ) {
1050 if( $action == 'move' ||
$action == '' ) {
1051 $r = $this->getRestrictions( 'move' );
1052 foreach( $wgRestrictionLevels as $level ) {
1053 if( in_array( $level, $r ) && $level != '' ) {
1063 * Is $wgUser is watching this page?
1067 function userIsWatching() {
1070 if ( is_null( $this->mWatched
) ) {
1071 if ( NS_SPECIAL
== $this->mNamespace ||
!$wgUser->isLoggedIn()) {
1072 $this->mWatched
= false;
1074 $this->mWatched
= $wgUser->isWatched( $this );
1077 return $this->mWatched
;
1081 * Can $wgUser perform $action on this page?
1082 * This skips potentially expensive cascading permission checks.
1084 * Suitable for use for nonessential UI controls in common cases, but
1085 * _not_ for functional access control.
1087 * May provide false positives, but should never provide a false negative.
1089 * @param string $action action that permission needs to be checked for
1092 public function quickUserCan( $action ) {
1093 return $this->userCan( $action, false );
1097 * Can $wgUser perform $action on this page?
1098 * @param string $action action that permission needs to be checked for
1099 * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
1102 public function userCan( $action, $doExpensiveQueries = true ) {
1103 $fname = 'Title::userCan';
1104 wfProfileIn( $fname );
1106 global $wgUser, $wgNamespaceProtection;
1109 wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) );
1110 if ( $result !== null ) {
1111 wfProfileOut( $fname );
1115 if( NS_SPECIAL
== $this->mNamespace
) {
1116 wfProfileOut( $fname );
1120 if ( array_key_exists( $this->mNamespace
, $wgNamespaceProtection ) ) {
1121 $nsProt = $wgNamespaceProtection[ $this->mNamespace
];
1122 if ( !is_array($nsProt) ) $nsProt = array($nsProt);
1123 foreach( $nsProt as $right ) {
1124 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1125 wfProfileOut( $fname );
1131 if( $this->mDbkeyform
== '_' ) {
1132 # FIXME: Is this necessary? Shouldn't be allowed anyway...
1133 wfProfileOut( $fname );
1137 # protect css/js subpages of user pages
1138 # XXX: this might be better using restrictions
1139 # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
1140 if( $this->isCssJsSubpage()
1141 && !$wgUser->isAllowed('editinterface')
1142 && !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) ) {
1143 wfProfileOut( $fname );
1147 if ( $doExpensiveQueries && $this->isCascadeProtected() ) {
1148 # We /could/ use the protection level on the source page, but it's fairly ugly
1149 # as we have to establish a precedence hierarchy for pages included by multiple
1150 # cascade-protected pages. So just restrict it to people with 'protect' permission,
1151 # as they could remove the protection anyway.
1152 if ( !$wgUser->isAllowed('protect') ) {
1153 wfProfileOut( $fname );
1158 foreach( $this->getRestrictions($action) as $right ) {
1159 // Backwards compatibility, rewrite sysop -> protect
1160 if ( $right == 'sysop' ) {
1163 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1164 wfProfileOut( $fname );
1169 if( $action == 'move' &&
1170 !( $this->isMovable() && $wgUser->isAllowed( 'move' ) ) ) {
1171 wfProfileOut( $fname );
1175 if( $action == 'create' ) {
1176 if( ( $this->isTalkPage() && !$wgUser->isAllowed( 'createtalk' ) ) ||
1177 ( !$this->isTalkPage() && !$wgUser->isAllowed( 'createpage' ) ) ) {
1178 wfProfileOut( $fname );
1183 wfProfileOut( $fname );
1188 * Can $wgUser edit this page?
1190 * @deprecated use userCan('edit')
1192 public function userCanEdit( $doExpensiveQueries = true ) {
1193 return $this->userCan( 'edit', $doExpensiveQueries );
1197 * Can $wgUser create this page?
1199 * @deprecated use userCan('create')
1201 public function userCanCreate( $doExpensiveQueries = true ) {
1202 return $this->userCan( 'create', $doExpensiveQueries );
1206 * Can $wgUser move this page?
1208 * @deprecated use userCan('move')
1210 public function userCanMove( $doExpensiveQueries = true ) {
1211 return $this->userCan( 'move', $doExpensiveQueries );
1215 * Would anybody with sufficient privileges be able to move this page?
1216 * Some pages just aren't movable.
1221 function isMovable() {
1222 return Namespace::isMovable( $this->getNamespace() )
1223 && $this->getInterwiki() == '';
1227 * Can $wgUser read this page?
1229 * @fixme fold these checks into userCan()
1231 public function userCanRead() {
1235 wfRunHooks( 'userCan', array( &$this, &$wgUser, 'read', &$result ) );
1236 if ( $result !== null ) {
1240 if( $wgUser->isAllowed('read') ) {
1243 global $wgWhitelistRead;
1246 * Always grant access to the login page.
1247 * Even anons need to be able to log in.
1249 if( $this->isSpecial( 'Userlogin' ) ||
$this->isSpecial( 'Resetpass' ) ) {
1253 /** some pages are explicitly allowed */
1254 $name = $this->getPrefixedText();
1255 if( $wgWhitelistRead && in_array( $name, $wgWhitelistRead ) ) {
1259 # Compatibility with old settings
1260 if( $wgWhitelistRead && $this->getNamespace() == NS_MAIN
) {
1261 if( in_array( ':' . $name, $wgWhitelistRead ) ) {
1270 * Is this a talk page of some sort?
1274 function isTalkPage() {
1275 return Namespace::isTalk( $this->getNamespace() );
1279 * Is this a subpage?
1283 function isSubpage() {
1284 global $wgNamespacesWithSubpages;
1286 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) ) {
1287 return ( strpos( $this->getText(), '/' ) !== false && $wgNamespacesWithSubpages[ $this->mNamespace
] == true );
1294 * Is this a .css or .js subpage of a user page?
1298 function isCssJsSubpage() {
1299 return ( NS_USER
== $this->mNamespace
and preg_match("/\\/.*\\.(css|js)$/", $this->mTextform
) );
1302 * Is this a *valid* .css or .js subpage of a user page?
1303 * Check that the corresponding skin exists
1305 function isValidCssJsSubpage() {
1306 if ( $this->isCssJsSubpage() ) {
1307 $skinNames = Skin
::getSkinNames();
1308 return array_key_exists( $this->getSkinFromCssJsSubpage(), $skinNames );
1314 * Trim down a .css or .js subpage title to get the corresponding skin name
1316 function getSkinFromCssJsSubpage() {
1317 $subpage = explode( '/', $this->mTextform
);
1318 $subpage = $subpage[ count( $subpage ) - 1 ];
1319 return( str_replace( array( '.css', '.js' ), array( '', '' ), $subpage ) );
1322 * Is this a .css subpage of a user page?
1326 function isCssSubpage() {
1327 return ( NS_USER
== $this->mNamespace
and preg_match("/\\/.*\\.css$/", $this->mTextform
) );
1330 * Is this a .js subpage of a user page?
1334 function isJsSubpage() {
1335 return ( NS_USER
== $this->mNamespace
and preg_match("/\\/.*\\.js$/", $this->mTextform
) );
1338 * Protect css/js subpages of user pages: can $wgUser edit
1342 * @todo XXX: this might be better using restrictions
1345 function userCanEditCssJsSubpage() {
1347 return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) );
1351 * Cascading protection: Return true if cascading restrictions apply to this page, false if not.
1353 * @return bool If the page is subject to cascading restrictions.
1356 function isCascadeProtected() {
1357 return ( $this->getCascadeProtectionSources( false ) );
1361 * Cascading protection: Get the source of any cascading restrictions on this page.
1363 * @param $get_pages bool Whether or not to retrieve the actual pages that the restrictions have come from.
1364 * @return mixed Array of the Title objects of the pages from which cascading restrictions have come, false for none, or true if such restrictions exist, but $get_pages was not set.
1367 function getCascadeProtectionSources( $get_pages = true ) {
1368 global $wgEnableCascadingProtection;
1369 if (!$wgEnableCascadingProtection)
1372 if ( isset( $this->mCascadeSources
) && $get_pages ) {
1373 return $this->mCascadeSources
;
1374 } else if ( isset( $this->mHasCascadingRestrictions
) && !$get_pages ) {
1375 return $this->mHasCascadingRestrictions
;
1378 wfProfileIn( __METHOD__
);
1380 $dbr =& wfGetDb( DB_SLAVE
);
1382 if ( $this->getNamespace() == NS_IMAGE
) {
1383 $cols = $get_pages ?
array('pr_page', 'page_namespace', 'page_title') : array( '1' );
1384 $tables = array ('imagelinks', 'page_restrictions');
1385 $where_clauses = array( 'il_to' => $this->getDBkey(), 'il_from=pr_page', 'pr_cascade' => 1 );
1387 $cols = $get_pages ?
array( 'pr_page', 'page_namespace', 'page_title' ) : array( '1' );
1388 $tables = array ('templatelinks', 'page_restrictions');
1389 $where_clauses = array( 'tl_namespace' => $this->getNamespace(), 'tl_title' => $this->getDBkey(), 'tl_from=pr_page', 'pr_cascade' => 1 );
1392 $options = array ();
1395 $where_clauses[] = 'page_id=pr_page';
1398 $options[] = "LIMIT 1";
1401 $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__
, $options);
1403 if ($dbr->numRows($res)) {
1405 $sources = array ();
1406 while ($row = $dbr->fetchObject($res)) {
1407 $page_id = $row->pr_page
;
1408 $page_ns = $row->page_namespace
;
1409 $page_title = $row->page_title
;
1410 $sources[$page_id] = Title
::makeTitle($page_ns, $page_title);
1419 wfProfileOut( __METHOD__
);
1422 $this->mCascadeSources
= $sources;
1424 $this->mHasCascadingRestrictions
= $sources;
1430 function areRestrictionsCascading() {
1431 if (!$this->mRestrictionsLoaded
) {
1432 $this->loadRestrictions();
1435 return $this->mCascadeRestriction
;
1439 * Loads a string into mRestrictions array
1440 * @param resource $res restrictions as an SQL result.
1443 function loadRestrictionsFromRow( $res, $oldFashionedRestrictions = NULL ) {
1444 $dbr =& wfGetDb( DB_SLAVE
);
1446 $this->mRestrictions
['edit'] = array();
1447 $this->mRestrictions
['move'] = array();
1449 # Backwards-compatibility: also load the restrictions from the page record (old format).
1451 if ( $oldFashionedRestrictions == NULL ) {
1452 $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleId() ), __METHOD__
);
1455 if ($oldFashionedRestrictions != '') {
1457 foreach( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) {
1458 $temp = explode( '=', trim( $restrict ) );
1459 if(count($temp) == 1) {
1460 // old old format should be treated as edit/move restriction
1461 $this->mRestrictions
["edit"] = explode( ',', trim( $temp[0] ) );
1462 $this->mRestrictions
["move"] = explode( ',', trim( $temp[0] ) );
1464 $this->mRestrictions
[$temp[0]] = explode( ',', trim( $temp[1] ) );
1468 $this->mOldRestrictions
= true;
1469 $this->mCascadeRestriction
= false;
1473 if ($dbr->numRows( $res) ) {
1474 # Current system - load second to make them override.
1475 while ($row = $dbr->fetchObject( $res ) ) {
1476 # Cycle through all the restrictions.
1478 $this->mRestrictions
[$row->pr_type
] = explode( ',', trim( $row->pr_level
) );
1480 $this->mCascadeRestriction |
= $row->pr_cascade
;
1484 $this->mRestrictionsLoaded
= true;
1487 function loadRestrictions( $oldFashionedRestrictions = NULL ) {
1488 if( !$this->mRestrictionsLoaded
) {
1489 $dbr =& wfGetDB( DB_SLAVE
);
1491 $res = $dbr->select( 'page_restrictions', '*',
1492 array ( 'pr_page' => $this->getArticleId() ), __METHOD__
);
1494 $this->loadRestrictionsFromRow( $res, $oldFashionedRestrictions );
1499 * Accessor/initialisation for mRestrictions
1502 * @param string $action action that permission needs to be checked for
1503 * @return array the array of groups allowed to edit this article
1505 function getRestrictions( $action ) {
1506 if( $this->exists() ) {
1507 if( !$this->mRestrictionsLoaded
) {
1508 $this->loadRestrictions();
1510 return isset( $this->mRestrictions
[$action] )
1511 ?
$this->mRestrictions
[$action]
1519 * Is there a version of this page in the deletion archive?
1520 * @return int the number of archived revisions
1523 function isDeleted() {
1524 $fname = 'Title::isDeleted';
1525 if ( $this->getNamespace() < 0 ) {
1528 $dbr =& wfGetDB( DB_SLAVE
);
1529 $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
1530 'ar_title' => $this->getDBkey() ), $fname );
1531 if( $this->getNamespace() == NS_IMAGE
) {
1532 $n +
= $dbr->selectField( 'filearchive', 'COUNT(*)',
1533 array( 'fa_name' => $this->getDBkey() ), $fname );
1540 * Get the article ID for this Title from the link cache,
1541 * adding it if necessary
1542 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select
1544 * @return int the ID
1546 public function getArticleID( $flags = 0 ) {
1547 $linkCache =& LinkCache
::singleton();
1548 if ( $flags & GAID_FOR_UPDATE
) {
1549 $oldUpdate = $linkCache->forUpdate( true );
1550 $this->mArticleID
= $linkCache->addLinkObj( $this );
1551 $linkCache->forUpdate( $oldUpdate );
1553 if ( -1 == $this->mArticleID
) {
1554 $this->mArticleID
= $linkCache->addLinkObj( $this );
1557 return $this->mArticleID
;
1560 function getLatestRevID() {
1561 if ($this->mLatestID
!== false)
1562 return $this->mLatestID
;
1564 $db =& wfGetDB(DB_SLAVE
);
1565 return $this->mLatestID
= $db->selectField( 'revision',
1567 array('rev_page' => $this->getArticleID()),
1568 'Title::getLatestRevID' );
1572 * This clears some fields in this object, and clears any associated
1573 * keys in the "bad links" section of the link cache.
1575 * - This is called from Article::insertNewArticle() to allow
1576 * loading of the new page_id. It's also called from
1577 * Article::doDeleteArticle()
1579 * @param int $newid the new Article ID
1582 function resetArticleID( $newid ) {
1583 $linkCache =& LinkCache
::singleton();
1584 $linkCache->clearBadLink( $this->getPrefixedDBkey() );
1586 if ( 0 == $newid ) { $this->mArticleID
= -1; }
1587 else { $this->mArticleID
= $newid; }
1588 $this->mRestrictionsLoaded
= false;
1589 $this->mRestrictions
= array();
1593 * Updates page_touched for this page; called from LinksUpdate.php
1594 * @return bool true if the update succeded
1597 function invalidateCache() {
1598 global $wgUseFileCache;
1600 if ( wfReadOnly() ) {
1604 $dbw =& wfGetDB( DB_MASTER
);
1605 $success = $dbw->update( 'page',
1607 'page_touched' => $dbw->timestamp()
1608 ), array( /* WHERE */
1609 'page_namespace' => $this->getNamespace() ,
1610 'page_title' => $this->getDBkey()
1611 ), 'Title::invalidateCache'
1614 if ($wgUseFileCache) {
1615 $cache = new HTMLFileCache($this);
1616 @unlink
($cache->fileCacheName());
1623 * Prefix some arbitrary text with the namespace or interwiki prefix
1626 * @param string $name the text
1627 * @return string the prefixed text
1630 /* private */ function prefix( $name ) {
1632 if ( '' != $this->mInterwiki
) {
1633 $p = $this->mInterwiki
. ':';
1635 if ( 0 != $this->mNamespace
) {
1636 $p .= $this->getNsText() . ':';
1642 * Secure and split - main initialisation function for this object
1644 * Assumes that mDbkeyform has been set, and is urldecoded
1645 * and uses underscores, but not otherwise munged. This function
1646 * removes illegal characters, splits off the interwiki and
1647 * namespace prefixes, sets the other forms, and canonicalizes
1649 * @return bool true on success
1652 /* private */ function secureAndSplit() {
1653 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
1656 static $rxTc = false;
1658 # % is needed as well
1659 $rxTc = '/[^' . Title
::legalChars() . ']|%[0-9A-Fa-f]{2}/S';
1662 $this->mInterwiki
= $this->mFragment
= '';
1663 $this->mNamespace
= $this->mDefaultNamespace
; # Usually NS_MAIN
1665 $dbkey = $this->mDbkeyform
;
1667 # Strip Unicode bidi override characters.
1668 # Sometimes they slip into cut-n-pasted page titles, where the
1669 # override chars get included in list displays.
1670 $dbkey = str_replace( "\xE2\x80\x8E", '', $dbkey ); // 200E LEFT-TO-RIGHT MARK
1671 $dbkey = str_replace( "\xE2\x80\x8F", '', $dbkey ); // 200F RIGHT-TO-LEFT MARK
1673 # Clean up whitespace
1675 $dbkey = preg_replace( '/[ _]+/', '_', $dbkey );
1676 $dbkey = trim( $dbkey, '_' );
1678 if ( '' == $dbkey ) {
1682 if( false !== strpos( $dbkey, UTF8_REPLACEMENT
) ) {
1683 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
1687 $this->mDbkeyform
= $dbkey;
1689 # Initial colon indicates main namespace rather than specified default
1690 # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
1691 if ( ':' == $dbkey{0} ) {
1692 $this->mNamespace
= NS_MAIN
;
1693 $dbkey = substr( $dbkey, 1 ); # remove the colon but continue processing
1696 # Namespace or interwiki prefix
1700 if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $dbkey, $m ) ) {
1702 $lowerNs = $wgContLang->lc( $p );
1703 if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
1704 # Canonical namespace
1706 $this->mNamespace
= $ns;
1707 } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) {
1708 # Ordinary namespace
1710 $this->mNamespace
= $ns;
1711 } elseif( $this->getInterwikiLink( $p ) ) {
1713 # Can't make a local interwiki link to an interwiki link.
1714 # That's just crazy!
1720 $this->mInterwiki
= $wgContLang->lc( $p );
1722 # Redundant interwiki prefix to the local wiki
1723 if ( 0 == strcasecmp( $this->mInterwiki
, $wgLocalInterwiki ) ) {
1724 if( $dbkey == '' ) {
1725 # Can't have an empty self-link
1728 $this->mInterwiki
= '';
1730 # Do another namespace split...
1734 # If there's an initial colon after the interwiki, that also
1735 # resets the default namespace
1736 if ( $dbkey !== '' && $dbkey[0] == ':' ) {
1737 $this->mNamespace
= NS_MAIN
;
1738 $dbkey = substr( $dbkey, 1 );
1741 # If there's no recognized interwiki or namespace,
1742 # then let the colon expression be part of the title.
1747 # We already know that some pages won't be in the database!
1749 if ( '' != $this->mInterwiki || NS_SPECIAL
== $this->mNamespace
) {
1750 $this->mArticleID
= 0;
1752 $fragment = strstr( $dbkey, '#' );
1753 if ( false !== $fragment ) {
1754 $this->setFragment( $fragment );
1755 $dbkey = substr( $dbkey, 0, strlen( $dbkey ) - strlen( $fragment ) );
1756 # remove whitespace again: prevents "Foo_bar_#"
1757 # becoming "Foo_bar_"
1758 $dbkey = preg_replace( '/_*$/', '', $dbkey );
1761 # Reject illegal characters.
1763 if( preg_match( $rxTc, $dbkey ) ) {
1768 * Pages with "/./" or "/../" appearing in the URLs will
1769 * often be unreachable due to the way web browsers deal
1770 * with 'relative' URLs. Forbid them explicitly.
1772 if ( strpos( $dbkey, '.' ) !== false &&
1773 ( $dbkey === '.' ||
$dbkey === '..' ||
1774 strpos( $dbkey, './' ) === 0 ||
1775 strpos( $dbkey, '../' ) === 0 ||
1776 strpos( $dbkey, '/./' ) !== false ||
1777 strpos( $dbkey, '/../' ) !== false ) )
1783 * Limit the size of titles to 255 bytes.
1784 * This is typically the size of the underlying database field.
1785 * We make an exception for special pages, which don't need to be stored
1786 * in the database, and may edge over 255 bytes due to subpage syntax
1787 * for long titles, e.g. [[Special:Block/Long name]]
1789 if ( ( $this->mNamespace
!= NS_SPECIAL
&& strlen( $dbkey ) > 255 ) ||
1790 strlen( $dbkey ) > 512 )
1796 * Normally, all wiki links are forced to have
1797 * an initial capital letter so [[foo]] and [[Foo]]
1798 * point to the same place.
1800 * Don't force it for interwikis, since the other
1801 * site might be case-sensitive.
1803 if( $wgCapitalLinks && $this->mInterwiki
== '') {
1804 $dbkey = $wgContLang->ucfirst( $dbkey );
1808 * Can't make a link to a namespace alone...
1809 * "empty" local links can only be self-links
1810 * with a fragment identifier.
1813 $this->mInterwiki
== '' &&
1814 $this->mNamespace
!= NS_MAIN
) {
1818 // Any remaining initial :s are illegal.
1819 if ( $dbkey !== '' && ':' == $dbkey{0} ) {
1824 $this->mDbkeyform
= $dbkey;
1825 $this->mUrlform
= wfUrlencode( $dbkey );
1827 $this->mTextform
= str_replace( '_', ' ', $dbkey );
1833 * Set the fragment for this title
1834 * This is kind of bad, since except for this rarely-used function, Title objects
1835 * are immutable. The reason this is here is because it's better than setting the
1836 * members directly, which is what Linker::formatComment was doing previously.
1838 * @param string $fragment text
1839 * @access kind of public
1841 function setFragment( $fragment ) {
1842 $this->mFragment
= str_replace( '_', ' ', substr( $fragment, 1 ) );
1846 * Get a Title object associated with the talk page of this article
1847 * @return Title the object for the talk page
1850 function getTalkPage() {
1851 return Title
::makeTitle( Namespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
1855 * Get a title object associated with the subject page of this
1858 * @return Title the object for the subject page
1861 function getSubjectPage() {
1862 return Title
::makeTitle( Namespace::getSubject( $this->getNamespace() ), $this->getDBkey() );
1866 * Get an array of Title objects linking to this Title
1867 * Also stores the IDs in the link cache.
1869 * WARNING: do not use this function on arbitrary user-supplied titles!
1870 * On heavily-used templates it will max out the memory.
1872 * @param string $options may be FOR UPDATE
1873 * @return array the Title objects linking here
1876 function getLinksTo( $options = '', $table = 'pagelinks', $prefix = 'pl' ) {
1877 $linkCache =& LinkCache
::singleton();
1880 $db =& wfGetDB( DB_MASTER
);
1882 $db =& wfGetDB( DB_SLAVE
);
1885 $res = $db->select( array( 'page', $table ),
1886 array( 'page_namespace', 'page_title', 'page_id' ),
1888 "{$prefix}_from=page_id",
1889 "{$prefix}_namespace" => $this->getNamespace(),
1890 "{$prefix}_title" => $this->getDbKey() ),
1891 'Title::getLinksTo',
1895 if ( $db->numRows( $res ) ) {
1896 while ( $row = $db->fetchObject( $res ) ) {
1897 if ( $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
) ) {
1898 $linkCache->addGoodLinkObj( $row->page_id
, $titleObj );
1899 $retVal[] = $titleObj;
1903 $db->freeResult( $res );
1908 * Get an array of Title objects using this Title as a template
1909 * Also stores the IDs in the link cache.
1911 * WARNING: do not use this function on arbitrary user-supplied titles!
1912 * On heavily-used templates it will max out the memory.
1914 * @param string $options may be FOR UPDATE
1915 * @return array the Title objects linking here
1918 function getTemplateLinksTo( $options = '' ) {
1919 return $this->getLinksTo( $options, 'templatelinks', 'tl' );
1923 * Get an array of Title objects referring to non-existent articles linked from this page
1925 * @param string $options may be FOR UPDATE
1926 * @return array the Title objects
1929 function getBrokenLinksFrom( $options = '' ) {
1931 $db =& wfGetDB( DB_MASTER
);
1933 $db =& wfGetDB( DB_SLAVE
);
1936 $res = $db->safeQuery(
1937 "SELECT pl_namespace, pl_title
1940 ON pl_namespace=page_namespace
1941 AND pl_title=page_title
1943 AND page_namespace IS NULL
1945 $db->tableName( 'pagelinks' ),
1946 $db->tableName( 'page' ),
1947 $this->getArticleId(),
1951 if ( $db->numRows( $res ) ) {
1952 while ( $row = $db->fetchObject( $res ) ) {
1953 $retVal[] = Title
::makeTitle( $row->pl_namespace
, $row->pl_title
);
1956 $db->freeResult( $res );
1962 * Get a list of URLs to purge from the Squid cache when this
1965 * @return array the URLs
1968 function getSquidURLs() {
1972 $this->getInternalURL(),
1973 $this->getInternalURL( 'action=history' )
1976 // purge variant urls as well
1977 if($wgContLang->hasVariants()){
1978 $variants = $wgContLang->getVariants();
1979 foreach($variants as $vCode){
1980 if($vCode==$wgContLang->getCode()) continue; // we don't want default variant
1981 $urls[] = $this->getInternalURL('',$vCode);
1988 function purgeSquid() {
1990 if ( $wgUseSquid ) {
1991 $urls = $this->getSquidURLs();
1992 $u = new SquidUpdate( $urls );
1998 * Move this page without authentication
1999 * @param Title &$nt the new page Title
2002 function moveNoAuth( &$nt ) {
2003 return $this->moveTo( $nt, false );
2007 * Check whether a given move operation would be valid.
2008 * Returns true if ok, or a message key string for an error message
2009 * if invalid. (Scarrrrry ugly interface this.)
2010 * @param Title &$nt the new title
2011 * @param bool $auth indicates whether $wgUser's permissions
2013 * @return mixed true on success, message name on failure
2016 function isValidMoveOperation( &$nt, $auth = true ) {
2017 if( !$this or !$nt ) {
2018 return 'badtitletext';
2020 if( $this->equals( $nt ) ) {
2023 if( !$this->isMovable() ||
!$nt->isMovable() ) {
2024 return 'immobile_namespace';
2027 $oldid = $this->getArticleID();
2028 $newid = $nt->getArticleID();
2030 if ( strlen( $nt->getDBkey() ) < 1 ) {
2031 return 'articleexists';
2033 if ( ( '' == $this->getDBkey() ) ||
2035 ( '' == $nt->getDBkey() ) ) {
2036 return 'badarticleerror';
2040 !$this->userCanEdit() ||
!$nt->userCanEdit() ||
2041 !$this->userCanMove() ||
!$nt->userCanMove() ) ) {
2042 return 'protectedpage';
2045 # The move is allowed only if (1) the target doesn't exist, or
2046 # (2) the target is a redirect to the source, and has no history
2047 # (so we can undo bad moves right after they're done).
2049 if ( 0 != $newid ) { # Target exists; check for validity
2050 if ( ! $this->isValidMoveTarget( $nt ) ) {
2051 return 'articleexists';
2058 * Move a title to a new location
2059 * @param Title &$nt the new title
2060 * @param bool $auth indicates whether $wgUser's permissions
2062 * @return mixed true on success, message name on failure
2065 function moveTo( &$nt, $auth = true, $reason = '' ) {
2066 $err = $this->isValidMoveOperation( $nt, $auth );
2067 if( is_string( $err ) ) {
2071 $pageid = $this->getArticleID();
2072 if( $nt->exists() ) {
2073 $this->moveOverExistingRedirect( $nt, $reason );
2074 $pageCountChange = 0;
2075 } else { # Target didn't exist, do normal move.
2076 $this->moveToNewTitle( $nt, $reason );
2077 $pageCountChange = 1;
2079 $redirid = $this->getArticleID();
2081 # Fixing category links (those without piped 'alternate' names) to be sorted under the new title
2082 $dbw =& wfGetDB( DB_MASTER
);
2083 $categorylinks = $dbw->tableName( 'categorylinks' );
2084 $sql = "UPDATE $categorylinks SET cl_sortkey=" . $dbw->addQuotes( $nt->getPrefixedText() ) .
2085 " WHERE cl_from=" . $dbw->addQuotes( $pageid ) .
2086 " AND cl_sortkey=" . $dbw->addQuotes( $this->getPrefixedText() );
2087 $dbw->query( $sql, 'SpecialMovepage::doSubmit' );
2091 $oldnamespace = $this->getNamespace() & ~
1;
2092 $newnamespace = $nt->getNamespace() & ~
1;
2093 $oldtitle = $this->getDBkey();
2094 $newtitle = $nt->getDBkey();
2096 if( $oldnamespace != $newnamespace ||
$oldtitle != $newtitle ) {
2097 WatchedItem
::duplicateEntries( $this, $nt );
2100 # Update search engine
2101 $u = new SearchUpdate( $pageid, $nt->getPrefixedDBkey() );
2103 $u = new SearchUpdate( $redirid, $this->getPrefixedDBkey(), '' );
2107 if( $this->isContentPage() && !$nt->isContentPage() ) {
2108 # No longer a content page
2109 # Not viewed, edited, removing
2110 $u = new SiteStatsUpdate( 0, 1, -1, $pageCountChange );
2111 } elseif( !$this->isContentPage() && $nt->isContentPage() ) {
2112 # Now a content page
2113 # Not viewed, edited, adding
2114 $u = new SiteStatsUpdate( 0, 1, +
1, $pageCountChange );
2115 } elseif( $pageCountChange ) {
2117 $u = new SiteStatsUpdate( 0, 0, 0, 1 );
2126 wfRunHooks( 'TitleMoveComplete', array( &$this, &$nt, &$wgUser, $pageid, $redirid ) );
2131 * Move page to a title which is at present a redirect to the
2134 * @param Title &$nt the page to move to, which should currently
2138 function moveOverExistingRedirect( &$nt, $reason = '' ) {
2140 $fname = 'Title::moveOverExistingRedirect';
2141 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
2144 $comment .= ": $reason";
2147 $now = wfTimestampNow();
2148 $newid = $nt->getArticleID();
2149 $oldid = $this->getArticleID();
2150 $dbw =& wfGetDB( DB_MASTER
);
2151 $linkCache =& LinkCache
::singleton();
2153 # Delete the old redirect. We don't save it to history since
2154 # by definition if we've got here it's rather uninteresting.
2155 # We have to remove it so that the next step doesn't trigger
2156 # a conflict on the unique namespace+title index...
2157 $dbw->delete( 'page', array( 'page_id' => $newid ), $fname );
2159 # Save a null revision in the page's history notifying of the move
2160 $nullRevision = Revision
::newNullRevision( $dbw, $oldid, $comment, true );
2161 $nullRevId = $nullRevision->insertOn( $dbw );
2163 # Change the name of the target page:
2164 $dbw->update( 'page',
2166 'page_touched' => $dbw->timestamp($now),
2167 'page_namespace' => $nt->getNamespace(),
2168 'page_title' => $nt->getDBkey(),
2169 'page_latest' => $nullRevId,
2171 /* WHERE */ array( 'page_id' => $oldid ),
2174 $linkCache->clearLink( $nt->getPrefixedDBkey() );
2176 # Recreate the redirect, this time in the other direction.
2177 $mwRedir = MagicWord
::get( 'redirect' );
2178 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
2179 $redirectArticle = new Article( $this );
2180 $newid = $redirectArticle->insertOn( $dbw );
2181 $redirectRevision = new Revision( array(
2183 'comment' => $comment,
2184 'text' => $redirectText ) );
2185 $redirectRevision->insertOn( $dbw );
2186 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
2187 $linkCache->clearLink( $this->getPrefixedDBkey() );
2190 $log = new LogPage( 'move' );
2191 $log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText() ) );
2193 # Now, we record the link from the redirect to the new title.
2194 # It should have no other outgoing links...
2195 $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), $fname );
2196 $dbw->insert( 'pagelinks',
2198 'pl_from' => $newid,
2199 'pl_namespace' => $nt->getNamespace(),
2200 'pl_title' => $nt->getDbKey() ),
2204 if ( $wgUseSquid ) {
2205 $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
2206 $u = new SquidUpdate( $urls );
2212 * Move page to non-existing title.
2213 * @param Title &$nt the new Title
2216 function moveToNewTitle( &$nt, $reason = '' ) {
2218 $fname = 'MovePageForm::moveToNewTitle';
2219 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
2221 $comment .= ": $reason";
2224 $newid = $nt->getArticleID();
2225 $oldid = $this->getArticleID();
2226 $dbw =& wfGetDB( DB_MASTER
);
2227 $now = $dbw->timestamp();
2228 $linkCache =& LinkCache
::singleton();
2230 # Save a null revision in the page's history notifying of the move
2231 $nullRevision = Revision
::newNullRevision( $dbw, $oldid, $comment, true );
2232 $nullRevId = $nullRevision->insertOn( $dbw );
2235 $dbw->update( 'page',
2237 'page_touched' => $now,
2238 'page_namespace' => $nt->getNamespace(),
2239 'page_title' => $nt->getDBkey(),
2240 'page_latest' => $nullRevId,
2242 /* WHERE */ array( 'page_id' => $oldid ),
2246 $linkCache->clearLink( $nt->getPrefixedDBkey() );
2249 $mwRedir = MagicWord
::get( 'redirect' );
2250 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
2251 $redirectArticle = new Article( $this );
2252 $newid = $redirectArticle->insertOn( $dbw );
2253 $redirectRevision = new Revision( array(
2255 'comment' => $comment,
2256 'text' => $redirectText ) );
2257 $redirectRevision->insertOn( $dbw );
2258 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
2259 $linkCache->clearLink( $this->getPrefixedDBkey() );
2262 $log = new LogPage( 'move' );
2263 $log->addEntry( 'move', $this, $reason, array( 1 => $nt->getPrefixedText()) );
2265 # Purge caches as per article creation
2266 Article
::onArticleCreate( $nt );
2268 # Record the just-created redirect's linking to the page
2269 $dbw->insert( 'pagelinks',
2271 'pl_from' => $newid,
2272 'pl_namespace' => $nt->getNamespace(),
2273 'pl_title' => $nt->getDBkey() ),
2276 # Purge old title from squid
2277 # The new title, and links to the new title, are purged in Article::onArticleCreate()
2278 $this->purgeSquid();
2282 * Checks if $this can be moved to a given Title
2283 * - Selects for update, so don't call it unless you mean business
2285 * @param Title &$nt the new title to check
2288 function isValidMoveTarget( $nt ) {
2290 $fname = 'Title::isValidMoveTarget';
2291 $dbw =& wfGetDB( DB_MASTER
);
2294 $id = $nt->getArticleID();
2295 $obj = $dbw->selectRow( array( 'page', 'revision', 'text'),
2296 array( 'page_is_redirect','old_text','old_flags' ),
2297 array( 'page_id' => $id, 'page_latest=rev_id', 'rev_text_id=old_id' ),
2298 $fname, 'FOR UPDATE' );
2300 if ( !$obj ||
0 == $obj->page_is_redirect
) {
2302 wfDebug( __METHOD__
. ": not a redirect\n" );
2305 $text = Revision
::getRevisionText( $obj );
2307 # Does the redirect point to the source?
2308 # Or is it a broken self-redirect, usually caused by namespace collisions?
2310 if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $text, $m ) ) {
2311 $redirTitle = Title
::newFromText( $m[1] );
2312 if( !is_object( $redirTitle ) ||
2313 ( $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() &&
2314 $redirTitle->getPrefixedDBkey() != $nt->getPrefixedDBkey() ) ) {
2315 wfDebug( __METHOD__
. ": redirect points to other page\n" );
2320 wfDebug( __METHOD__
. ": failsafe\n" );
2324 # Does the article have a history?
2325 $row = $dbw->selectRow( array( 'page', 'revision'),
2327 array( 'page_namespace' => $nt->getNamespace(),
2328 'page_title' => $nt->getDBkey(),
2329 'page_id=rev_page AND page_latest != rev_id'
2330 ), $fname, 'FOR UPDATE'
2333 # Return true if there was no history
2334 return $row === false;
2338 * Create a redirect; fails if the title already exists; does
2341 * @param Title $dest the destination of the redirect
2342 * @param string $comment the comment string describing the move
2343 * @return bool true on success
2346 function createRedirect( $dest, $comment ) {
2347 if ( $this->getArticleID() ) {
2351 $fname = 'Title::createRedirect';
2352 $dbw =& wfGetDB( DB_MASTER
);
2354 $article = new Article( $this );
2355 $newid = $article->insertOn( $dbw );
2356 $revision = new Revision( array(
2358 'comment' => $comment,
2359 'text' => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n",
2361 $revision->insertOn( $dbw );
2362 $article->updateRevisionOn( $dbw, $revision, 0 );
2365 $dbw->insert( 'pagelinks',
2367 'pl_from' => $newid,
2368 'pl_namespace' => $dest->getNamespace(),
2369 'pl_title' => $dest->getDbKey()
2373 Article
::onArticleCreate( $this );
2378 * Get categories to which this Title belongs and return an array of
2379 * categories' names.
2381 * @return array an array of parents in the form:
2382 * $parent => $currentarticle
2385 function getParentCategories() {
2388 $titlekey = $this->getArticleId();
2389 $dbr =& wfGetDB( DB_SLAVE
);
2390 $categorylinks = $dbr->tableName( 'categorylinks' );
2393 $sql = "SELECT * FROM $categorylinks"
2394 ." WHERE cl_from='$titlekey'"
2395 ." AND cl_from <> '0'"
2396 ." ORDER BY cl_sortkey";
2398 $res = $dbr->query ( $sql ) ;
2400 if($dbr->numRows($res) > 0) {
2401 while ( $x = $dbr->fetchObject ( $res ) )
2402 //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
2403 $data[$wgContLang->getNSText ( NS_CATEGORY
).':'.$x->cl_to
] = $this->getFullText();
2404 $dbr->freeResult ( $res ) ;
2412 * Get a tree of parent categories
2413 * @param array $children an array with the children in the keys, to check for circular refs
2417 function getParentCategoryTree( $children = array() ) {
2418 $parents = $this->getParentCategories();
2420 if($parents != '') {
2421 foreach($parents as $parent => $current) {
2422 if ( array_key_exists( $parent, $children ) ) {
2423 # Circular reference
2424 $stack[$parent] = array();
2426 $nt = Title
::newFromText($parent);
2428 $stack[$parent] = $nt->getParentCategoryTree( $children +
array($parent => 1) );
2440 * Get an associative array for selecting this title from
2446 function pageCond() {
2447 return array( 'page_namespace' => $this->mNamespace
, 'page_title' => $this->mDbkeyform
);
2451 * Get the revision ID of the previous revision
2453 * @param integer $revision Revision ID. Get the revision that was before this one.
2454 * @return integer $oldrevision|false
2456 function getPreviousRevisionID( $revision ) {
2457 $dbr =& wfGetDB( DB_SLAVE
);
2458 return $dbr->selectField( 'revision', 'rev_id',
2459 'rev_page=' . intval( $this->getArticleId() ) .
2460 ' AND rev_id<' . intval( $revision ) . ' ORDER BY rev_id DESC' );
2464 * Get the revision ID of the next revision
2466 * @param integer $revision Revision ID. Get the revision that was after this one.
2467 * @return integer $oldrevision|false
2469 function getNextRevisionID( $revision ) {
2470 $dbr =& wfGetDB( DB_SLAVE
);
2471 return $dbr->selectField( 'revision', 'rev_id',
2472 'rev_page=' . intval( $this->getArticleId() ) .
2473 ' AND rev_id>' . intval( $revision ) . ' ORDER BY rev_id' );
2477 * Get the number of revisions between the given revision IDs.
2479 * @param integer $old Revision ID.
2480 * @param integer $new Revision ID.
2481 * @return integer Number of revisions between these IDs.
2483 function countRevisionsBetween( $old, $new ) {
2484 $dbr =& wfGetDB( DB_SLAVE
);
2485 return $dbr->selectField( 'revision', 'count(*)',
2486 'rev_page = ' . intval( $this->getArticleId() ) .
2487 ' AND rev_id > ' . intval( $old ) .
2488 ' AND rev_id < ' . intval( $new ) );
2492 * Compare with another title.
2494 * @param Title $title
2497 function equals( $title ) {
2498 // Note: === is necessary for proper matching of number-like titles.
2499 return $this->getInterwiki() === $title->getInterwiki()
2500 && $this->getNamespace() == $title->getNamespace()
2501 && $this->getDbkey() === $title->getDbkey();
2505 * Check if page exists
2509 return $this->getArticleId() != 0;
2513 * Should a link should be displayed as a known link, just based on its title?
2515 * Currently, a self-link with a fragment and special pages are in
2516 * this category. Special pages never exist in the database.
2518 function isAlwaysKnown() {
2519 return $this->isExternal() ||
( 0 == $this->mNamespace
&& "" == $this->mDbkeyform
)
2520 || NS_SPECIAL
== $this->mNamespace
;
2524 * Update page_touched timestamps and send squid purge messages for
2525 * pages linking to this title. May be sent to the job queue depending
2526 * on the number of links. Typically called on create and delete.
2528 function touchLinks() {
2529 $u = new HTMLCacheUpdate( $this, 'pagelinks' );
2532 if ( $this->getNamespace() == NS_CATEGORY
) {
2533 $u = new HTMLCacheUpdate( $this, 'categorylinks' );
2539 * Get the last touched timestamp
2541 function getTouched() {
2542 $dbr =& wfGetDB( DB_SLAVE
);
2543 $touched = $dbr->selectField( 'page', 'page_touched',
2545 'page_namespace' => $this->getNamespace(),
2546 'page_title' => $this->getDBkey()
2553 * Get a cached value from a global cache that is invalidated when this page changes
2554 * @param string $key the key
2555 * @param callback $callback A callback function which generates the value on cache miss
2557 * @deprecated use DependencyWrapper
2559 function getRelatedCache( $memc, $key, $expiry, $callback, $params = array() ) {
2560 return DependencyWrapper
::getValueFromCache( $memc, $key, $expiry, $callback,
2561 $params, new TitleDependency( $this ) );
2564 function trackbackURL() {
2565 global $wgTitle, $wgScriptPath, $wgServer;
2567 return "$wgServer$wgScriptPath/trackback.php?article="
2568 . htmlspecialchars(urlencode($wgTitle->getPrefixedDBkey()));
2571 function trackbackRDF() {
2572 $url = htmlspecialchars($this->getFullURL());
2573 $title = htmlspecialchars($this->getText());
2574 $tburl = $this->trackbackURL();
2577 <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
2578 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
2579 xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">
2582 dc:identifier=\"$url\"
2584 trackback:ping=\"$tburl\" />
2589 * Generate strings used for xml 'id' names in monobook tabs
2592 function getNamespaceKey() {
2594 switch ($this->getNamespace()) {
2597 return 'nstab-main';
2600 return 'nstab-user';
2602 return 'nstab-media';
2604 return 'nstab-special';
2606 case NS_PROJECT_TALK
:
2607 return 'nstab-project';
2610 return 'nstab-image';
2612 case NS_MEDIAWIKI_TALK
:
2613 return 'nstab-mediawiki';
2615 case NS_TEMPLATE_TALK
:
2616 return 'nstab-template';
2619 return 'nstab-help';
2621 case NS_CATEGORY_TALK
:
2622 return 'nstab-category';
2624 return 'nstab-' . $wgContLang->lc( $this->getSubjectNsText() );
2629 * Returns true if this title resolves to the named special page
2630 * @param string $name The special page name
2633 function isSpecial( $name ) {
2634 if ( $this->getNamespace() == NS_SPECIAL
) {
2635 list( $thisName, /* $subpage */ ) = SpecialPage
::resolveAliasWithSubpage( $this->getDBkey() );
2636 if ( $name == $thisName ) {
2644 * If the Title refers to a special page alias which is not the local default,
2645 * returns a new Title which points to the local default. Otherwise, returns $this.
2647 function fixSpecialName() {
2648 if ( $this->getNamespace() == NS_SPECIAL
) {
2649 $canonicalName = SpecialPage
::resolveAlias( $this->mDbkeyform
);
2650 if ( $canonicalName ) {
2651 $localName = SpecialPage
::getLocalNameFor( $canonicalName );
2652 if ( $localName != $this->mDbkeyform
) {
2653 return Title
::makeTitle( NS_SPECIAL
, $localName );
2661 * Is this Title in a namespace which contains content?
2662 * In other words, is this a content page, for the purposes of calculating
2667 public function isContentPage() {
2668 return Namespace::isContent( $this->getNamespace() );