8 if ( !class_exists( 'UtfNormal' ) ) {
9 require_once( dirname(__FILE__
) . '/normal/UtfNormal.php' );
12 define ( 'GAID_FOR_UPDATE', 1 );
14 # Title::newFromTitle maintains a cache to avoid
15 # expensive re-normalization of commonly used titles.
16 # On a batch operation this can become a memory leak
17 # if not bounded. After hitting this many titles,
19 define( 'MW_TITLECACHE_MAX', 1000 );
21 # Constants for pr_cascade bitfield
22 define( 'CASCADE', 1 );
26 * - Represents a title, which may contain an interwiki designation or namespace
27 * - 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 $mRestrictionsExpiry; # When do the restrictions on this page expire?
58 var $mHasCascadingRestrictions; # Are cascading restrictions in effect on this page?
59 var $mCascadeRestrictionSources;# Where are the cascading restrictions coming from on this page?
60 var $mRestrictionsLoaded; # Boolean for initialisation on demand
61 var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
62 var $mDefaultNamespace; # Namespace index when there is no namespace
63 # Zero except in {{transclusion}} tags
64 var $mWatched; # Is $wgUser watching this page? NULL if unfilled, accessed through userIsWatching()
72 /* private */ function __construct() {
73 $this->mInterwiki
= $this->mUrlform
=
74 $this->mTextform
= $this->mDbkeyform
= '';
75 $this->mArticleID
= -1;
76 $this->mNamespace
= NS_MAIN
;
77 $this->mRestrictionsLoaded
= false;
78 $this->mRestrictions
= array();
79 # Dont change the following, NS_MAIN is hardcoded in several place
81 $this->mDefaultNamespace
= NS_MAIN
;
82 $this->mWatched
= NULL;
83 $this->mLatestID
= false;
84 $this->mOldRestrictions
= false;
88 * Create a new Title from a prefixed DB key
89 * @param string $key The database key, which has underscores
90 * instead of spaces, possibly including namespace and
92 * @return Title the new object, or NULL on an error
94 public static function newFromDBkey( $key ) {
96 $t->mDbkeyform
= $key;
97 if( $t->secureAndSplit() )
104 * Create a new Title from text, such as what one would
105 * find in a link. Decodes any HTML entities in the text.
107 * @param string $text the link text; spaces, prefixes,
108 * and an initial ':' indicating the main namespace
110 * @param int $defaultNamespace the namespace to use if
111 * none is specified by a prefix
112 * @return Title the new object, or NULL on an error
114 public static function newFromText( $text, $defaultNamespace = NS_MAIN
) {
115 if( is_object( $text ) ) {
116 throw new MWException( 'Title::newFromText given an object' );
120 * Wiki pages often contain multiple links to the same page.
121 * Title normalization and parsing can become expensive on
122 * pages with many links, so we can save a little time by
125 * In theory these are value objects and won't get changed...
127 if( $defaultNamespace == NS_MAIN
&& isset( Title
::$titleCache[$text] ) ) {
128 return Title
::$titleCache[$text];
132 * Convert things like é ā or 〗 into real text...
134 $filteredText = Sanitizer
::decodeCharReferences( $text );
137 $t->mDbkeyform
= str_replace( ' ', '_', $filteredText );
138 $t->mDefaultNamespace
= $defaultNamespace;
140 static $cachedcount = 0 ;
141 if( $t->secureAndSplit() ) {
142 if( $defaultNamespace == NS_MAIN
) {
143 if( $cachedcount >= MW_TITLECACHE_MAX
) {
144 # Avoid memory leaks on mass operations...
145 Title
::$titleCache = array();
149 Title
::$titleCache[$text] =& $t;
159 * Create a new Title from URL-encoded text. Ensures that
160 * the given title's length does not exceed the maximum.
161 * @param string $url the title, as might be taken from a URL
162 * @return Title the new object, or NULL on an error
164 public static function newFromURL( $url ) {
165 global $wgLegalTitleChars;
168 # For compatibility with old buggy URLs. "+" is usually not valid in titles,
169 # but some URLs used it as a space replacement and they still come
170 # from some external search tools.
171 if ( strpos( $wgLegalTitleChars, '+' ) === false ) {
172 $url = str_replace( '+', ' ', $url );
175 $t->mDbkeyform
= str_replace( ' ', '_', $url );
176 if( $t->secureAndSplit() ) {
184 * Create a new Title from an article ID
186 * @todo This is inefficiently implemented, the page row is requested
187 * but not used for anything else
189 * @param int $id the page_id corresponding to the Title to create
190 * @return Title the new object, or NULL on an error
192 public static function newFromID( $id ) {
193 $fname = 'Title::newFromID';
194 $dbr = wfGetDB( DB_SLAVE
);
195 $row = $dbr->selectRow( 'page', array( 'page_namespace', 'page_title' ),
196 array( 'page_id' => $id ), $fname );
197 if ( $row !== false ) {
198 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
206 * Make an array of titles from an array of IDs
208 public static function newFromIDs( $ids ) {
209 $dbr = wfGetDB( DB_SLAVE
);
210 $res = $dbr->select( 'page', array( 'page_namespace', 'page_title' ),
211 'page_id IN (' . $dbr->makeList( $ids ) . ')', __METHOD__
);
214 while ( $row = $dbr->fetchObject( $res ) ) {
215 $titles[] = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
221 * Create a new Title from a namespace index and a DB key.
222 * It's assumed that $ns and $title are *valid*, for instance when
223 * they came directly from the database or a special page name.
224 * For convenience, spaces are converted to underscores so that
225 * eg user_text fields can be used directly.
227 * @param int $ns the namespace of the article
228 * @param string $title the unprefixed database key form
229 * @return Title the new object
231 public static function &makeTitle( $ns, $title ) {
235 $t->mNamespace
= intval( $ns );
236 $t->mDbkeyform
= str_replace( ' ', '_', $title );
237 $t->mArticleID
= ( $ns >= 0 ) ?
-1 : 0;
238 $t->mUrlform
= wfUrlencode( $t->mDbkeyform
);
239 $t->mTextform
= str_replace( '_', ' ', $title );
244 * Create a new Title from a namespace index and a DB key.
245 * The parameters will be checked for validity, which is a bit slower
246 * than makeTitle() but safer for user-provided data.
248 * @param int $ns the namespace of the article
249 * @param string $title the database key form
250 * @return Title the new object, or NULL on an error
252 public static function makeTitleSafe( $ns, $title ) {
254 $t->mDbkeyform
= Title
::makeName( $ns, $title );
255 if( $t->secureAndSplit() ) {
263 * Create a new Title for the Main Page
264 * @return Title the new object
266 public static function newMainPage() {
267 return Title
::newFromText( wfMsgForContent( 'mainpage' ) );
271 * Create a new Title for a redirect
272 * @param string $text the redirect title text
273 * @return Title the new object, or NULL if the text is not a
276 public static function newFromRedirect( $text ) {
277 $mwRedir = MagicWord
::get( 'redirect' );
279 if ( $mwRedir->matchStart( $text ) ) {
281 if ( preg_match( '/\[{2}(.*?)(?:\||\]{2})/', $text, $m ) ) {
282 # categories are escaped using : for example one can enter:
283 # #REDIRECT [[:Category:Music]]. Need to remove it.
284 if ( substr($m[1],0,1) == ':') {
285 # We don't want to keep the ':'
286 $m[1] = substr( $m[1], 1 );
289 $rt = Title
::newFromText( $m[1] );
290 # Disallow redirects to Special:Userlogout
291 if ( !is_null($rt) && $rt->isSpecial( 'Userlogout' ) ) {
299 #----------------------------------------------------------------------------
301 #----------------------------------------------------------------------------
304 * Get the prefixed DB key associated with an ID
305 * @param int $id the page_id of the article
306 * @return Title an object representing the article, or NULL
307 * if no such article was found
311 function nameOf( $id ) {
312 $fname = 'Title::nameOf';
313 $dbr = wfGetDB( DB_SLAVE
);
315 $s = $dbr->selectRow( 'page', array( 'page_namespace','page_title' ), array( 'page_id' => $id ), $fname );
316 if ( $s === false ) { return NULL; }
318 $n = Title
::makeName( $s->page_namespace
, $s->page_title
);
323 * Get a regex character class describing the legal characters in a link
324 * @return string the list of characters, not delimited
326 public static function legalChars() {
327 global $wgLegalTitleChars;
328 return $wgLegalTitleChars;
332 * Get a string representation of a title suitable for
333 * including in a search index
335 * @param int $ns a namespace index
336 * @param string $title text-form main part
337 * @return string a stripped-down title string ready for the
340 public static function indexTitle( $ns, $title ) {
343 $lc = SearchEngine
::legalSearchChars() . '&#;';
344 $t = $wgContLang->stripForSearch( $title );
345 $t = preg_replace( "/[^{$lc}]+/", ' ', $t );
346 $t = $wgContLang->lc( $t );
349 $t = preg_replace( "/([{$lc}]+)'s( |$)/", "\\1 \\1's ", $t );
350 $t = preg_replace( "/([{$lc}]+)s'( |$)/", "\\1s ", $t );
352 $t = preg_replace( "/\\s+/", ' ', $t );
354 if ( $ns == NS_IMAGE
) {
355 $t = preg_replace( "/ (png|gif|jpg|jpeg|ogg)$/", "", $t );
361 * Make a prefixed DB key from a DB key and a namespace index
362 * @param int $ns numerical representation of the namespace
363 * @param string $title the DB key form the title
364 * @return string the prefixed form of the title
366 public static function makeName( $ns, $title ) {
369 $n = $wgContLang->getNsText( $ns );
370 return $n == '' ?
$title : "$n:$title";
374 * Returns the URL associated with an interwiki prefix
375 * @param string $key the interwiki prefix (e.g. "MeatBall")
376 * @return the associated URL, containing "$1", which should be
377 * replaced by an article title
380 public function getInterwikiLink( $key ) {
381 global $wgMemc, $wgInterwikiExpiry;
382 global $wgInterwikiCache, $wgContLang;
383 $fname = 'Title::getInterwikiLink';
385 $key = $wgContLang->lc( $key );
387 $k = wfMemcKey( 'interwiki', $key );
388 if( array_key_exists( $k, Title
::$interwikiCache ) ) {
389 return Title
::$interwikiCache[$k]->iw_url
;
392 if ($wgInterwikiCache) {
393 return Title
::getInterwikiCached( $key );
396 $s = $wgMemc->get( $k );
397 # Ignore old keys with no iw_local
398 if( $s && isset( $s->iw_local
) && isset($s->iw_trans
)) {
399 Title
::$interwikiCache[$k] = $s;
403 $dbr = wfGetDB( DB_SLAVE
);
404 $res = $dbr->select( 'interwiki',
405 array( 'iw_url', 'iw_local', 'iw_trans' ),
406 array( 'iw_prefix' => $key ), $fname );
411 $s = $dbr->fetchObject( $res );
413 # Cache non-existence: create a blank object and save it to memcached
419 $wgMemc->set( $k, $s, $wgInterwikiExpiry );
420 Title
::$interwikiCache[$k] = $s;
426 * Fetch interwiki prefix data from local cache in constant database
428 * More logic is explained in DefaultSettings
430 * @return string URL of interwiki site
432 public static function getInterwikiCached( $key ) {
433 global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
437 $db=dba_open($wgInterwikiCache,'r','cdb');
438 /* Resolve site name */
439 if ($wgInterwikiScopes>=3 and !$site) {
440 $site = dba_fetch('__sites:' . wfWikiID(), $db);
442 $site = $wgInterwikiFallbackSite;
444 $value = dba_fetch( wfMemcKey( $key ), $db);
445 if ($value=='' and $wgInterwikiScopes>=3) {
447 $value = dba_fetch("_{$site}:{$key}", $db);
449 if ($value=='' and $wgInterwikiScopes>=2) {
451 $value = dba_fetch("__global:{$key}", $db);
460 list($local,$url)=explode(' ',$value,2);
462 $s->iw_local
=(int)$local;
464 Title
::$interwikiCache[wfMemcKey( 'interwiki', $key )] = $s;
468 * Determine whether the object refers to a page within
471 * @return bool TRUE if this is an in-project interwiki link
472 * or a wikilink, FALSE otherwise
474 public function isLocal() {
475 if ( $this->mInterwiki
!= '' ) {
476 # Make sure key is loaded into cache
477 $this->getInterwikiLink( $this->mInterwiki
);
478 $k = wfMemcKey( 'interwiki', $this->mInterwiki
);
479 return (bool)(Title
::$interwikiCache[$k]->iw_local
);
486 * Determine whether the object refers to a page within
487 * this project and is transcludable.
489 * @return bool TRUE if this is transcludable
491 public function isTrans() {
492 if ($this->mInterwiki
== '')
494 # Make sure key is loaded into cache
495 $this->getInterwikiLink( $this->mInterwiki
);
496 $k = wfMemcKey( 'interwiki', $this->mInterwiki
);
497 return (bool)(Title
::$interwikiCache[$k]->iw_trans
);
501 * Escape a text fragment, say from a link, for a URL
503 static function escapeFragmentForURL( $fragment ) {
504 $fragment = str_replace( ' ', '_', $fragment );
505 $fragment = urlencode( Sanitizer
::decodeCharReferences( $fragment ) );
506 $replaceArray = array(
510 return strtr( $fragment, $replaceArray );
513 #----------------------------------------------------------------------------
515 #----------------------------------------------------------------------------
517 /** Simple accessors */
519 * Get the text form (spaces not underscores) of the main part
522 public function getText() { return $this->mTextform
; }
524 * Get the URL-encoded form of the main part
527 public function getPartialURL() { return $this->mUrlform
; }
529 * Get the main part with underscores
532 public function getDBkey() { return $this->mDbkeyform
; }
534 * Get the namespace index, i.e. one of the NS_xxxx constants
537 public function getNamespace() { return $this->mNamespace
; }
539 * Get the namespace text
542 public function getNsText() {
543 global $wgContLang, $wgCanonicalNamespaceNames;
545 if ( '' != $this->mInterwiki
) {
546 // This probably shouldn't even happen. ohh man, oh yuck.
547 // But for interwiki transclusion it sometimes does.
548 // Shit. Shit shit shit.
550 // Use the canonical namespaces if possible to try to
551 // resolve a foreign namespace.
552 if( isset( $wgCanonicalNamespaceNames[$this->mNamespace
] ) ) {
553 return $wgCanonicalNamespaceNames[$this->mNamespace
];
556 return $wgContLang->getNsText( $this->mNamespace
);
559 * Get the namespace text of the subject (rather than talk) page
562 public function getSubjectNsText() {
564 return $wgContLang->getNsText( Namespace::getSubject( $this->mNamespace
) );
568 * Get the namespace text of the talk page
571 public function getTalkNsText() {
573 return( $wgContLang->getNsText( Namespace::getTalk( $this->mNamespace
) ) );
577 * Could this title have a corresponding talk page?
580 public function canTalk() {
581 return( Namespace::canTalk( $this->mNamespace
) );
585 * Get the interwiki prefix (or null string)
588 public function getInterwiki() { return $this->mInterwiki
; }
590 * Get the Title fragment (i.e. the bit after the #) in text form
593 public function getFragment() { return $this->mFragment
; }
595 * Get the fragment in URL form, including the "#" character if there is one
598 public function getFragmentForURL() {
599 if ( $this->mFragment
== '' ) {
602 return '#' . Title
::escapeFragmentForURL( $this->mFragment
);
606 * Get the default namespace index, for when there is no namespace
609 public function getDefaultNamespace() { return $this->mDefaultNamespace
; }
612 * Get title for search index
613 * @return string a stripped-down title string ready for the
616 public function getIndexTitle() {
617 return Title
::indexTitle( $this->mNamespace
, $this->mTextform
);
621 * Get the prefixed database key form
622 * @return string the prefixed title, with underscores and
623 * any interwiki and namespace prefixes
625 public function getPrefixedDBkey() {
626 $s = $this->prefix( $this->mDbkeyform
);
627 $s = str_replace( ' ', '_', $s );
632 * Get the prefixed title with spaces.
633 * This is the form usually used for display
634 * @return string the prefixed title, with spaces
636 public function getPrefixedText() {
637 if ( empty( $this->mPrefixedText
) ) { // FIXME: bad usage of empty() ?
638 $s = $this->prefix( $this->mTextform
);
639 $s = str_replace( '_', ' ', $s );
640 $this->mPrefixedText
= $s;
642 return $this->mPrefixedText
;
646 * Get the prefixed title with spaces, plus any fragment
647 * (part beginning with '#')
648 * @return string the prefixed title, with spaces and
649 * the fragment, including '#'
651 public function getFullText() {
652 $text = $this->getPrefixedText();
653 if( '' != $this->mFragment
) {
654 $text .= '#' . $this->mFragment
;
660 * Get the base name, i.e. the leftmost parts before the /
661 * @return string Base name
663 public function getBaseText() {
664 global $wgNamespacesWithSubpages;
665 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) && $wgNamespacesWithSubpages[ $this->mNamespace
] ) {
666 $parts = explode( '/', $this->getText() );
667 # Don't discard the real title if there's no subpage involved
668 if( count( $parts ) > 1 )
669 unset( $parts[ count( $parts ) - 1 ] );
670 return implode( '/', $parts );
672 return $this->getText();
677 * Get the lowest-level subpage name, i.e. the rightmost part after /
678 * @return string Subpage name
680 public function getSubpageText() {
681 global $wgNamespacesWithSubpages;
682 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) && $wgNamespacesWithSubpages[ $this->mNamespace
] ) {
683 $parts = explode( '/', $this->mTextform
);
684 return( $parts[ count( $parts ) - 1 ] );
686 return( $this->mTextform
);
691 * Get a URL-encoded form of the subpage text
692 * @return string URL-encoded subpage name
694 public function getSubpageUrlForm() {
695 $text = $this->getSubpageText();
696 $text = wfUrlencode( str_replace( ' ', '_', $text ) );
697 $text = str_replace( '%28', '(', str_replace( '%29', ')', $text ) ); # Clean up the URL; per below, this might not be safe
702 * Get a URL-encoded title (not an actual URL) including interwiki
703 * @return string the URL-encoded form
705 public function getPrefixedURL() {
706 $s = $this->prefix( $this->mDbkeyform
);
707 $s = str_replace( ' ', '_', $s );
709 $s = wfUrlencode ( $s ) ;
711 # Cleaning up URL to make it look nice -- is this safe?
712 $s = str_replace( '%28', '(', $s );
713 $s = str_replace( '%29', ')', $s );
719 * Get a real URL referring to this title, with interwiki link and
722 * @param string $query an optional query string, not used
723 * for interwiki links
724 * @param string $variant language variant of url (for sr, zh..)
725 * @return string the URL
727 public function getFullURL( $query = '', $variant = false ) {
728 global $wgContLang, $wgServer, $wgRequest;
730 if ( '' == $this->mInterwiki
) {
731 $url = $this->getLocalUrl( $query, $variant );
733 // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
734 // Correct fix would be to move the prepending elsewhere.
735 if ($wgRequest->getVal('action') != 'render') {
736 $url = $wgServer . $url;
739 $baseUrl = $this->getInterwikiLink( $this->mInterwiki
);
741 $namespace = wfUrlencode( $this->getNsText() );
742 if ( '' != $namespace ) {
743 # Can this actually happen? Interwikis shouldn't be parsed.
744 # Yes! It can in interwiki transclusion. But... it probably shouldn't.
747 $url = str_replace( '$1', $namespace . $this->mUrlform
, $baseUrl );
748 $url = wfAppendQuery( $url, $query );
751 # Finally, add the fragment.
752 $url .= $this->getFragmentForURL();
754 wfRunHooks( 'GetFullURL', array( &$this, &$url, $query ) );
759 * Get a URL with no fragment or server name. If this page is generated
760 * with action=render, $wgServer is prepended.
761 * @param string $query an optional query string; if not specified,
762 * $wgArticlePath will be used.
763 * @param string $variant language variant of url (for sr, zh..)
764 * @return string the URL
766 public function getLocalURL( $query = '', $variant = false ) {
767 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
768 global $wgVariantArticlePath, $wgContLang, $wgUser;
770 // internal links should point to same variant as current page (only anonymous users)
771 if($variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn()){
772 $pref = $wgContLang->getPreferredVariant(false);
773 if($pref != $wgContLang->getCode())
777 if ( $this->isExternal() ) {
778 $url = $this->getFullURL();
780 // This is currently only used for edit section links in the
781 // context of interwiki transclusion. In theory we should
782 // append the query to the end of any existing query string,
783 // but interwiki transclusion is already broken in that case.
787 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
788 if ( $query == '' ) {
789 if($variant!=false && $wgContLang->hasVariants()){
790 if($wgVariantArticlePath==false) {
791 $variantArticlePath = "$wgScript?title=$1&variant=$2"; // default
793 $variantArticlePath = $wgVariantArticlePath;
795 $url = str_replace( '$2', urlencode( $variant ), $variantArticlePath );
796 $url = str_replace( '$1', $dbkey, $url );
799 $url = str_replace( '$1', $dbkey, $wgArticlePath );
802 global $wgActionPaths;
805 if( !empty( $wgActionPaths ) &&
806 preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) )
808 $action = urldecode( $matches[2] );
809 if( isset( $wgActionPaths[$action] ) ) {
810 $query = $matches[1];
811 if( isset( $matches[4] ) ) $query .= $matches[4];
812 $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
813 if( $query != '' ) $url .= '?' . $query;
816 if ( $url === false ) {
817 if ( $query == '-' ) {
820 $url = "{$wgScript}?title={$dbkey}&{$query}";
824 // FIXME: this causes breakage in various places when we
825 // actually expected a local URL and end up with dupe prefixes.
826 if ($wgRequest->getVal('action') == 'render') {
827 $url = $wgServer . $url;
830 wfRunHooks( 'GetLocalURL', array( &$this, &$url, $query ) );
835 * Get an HTML-escaped version of the URL form, suitable for
836 * using in a link, without a server name or fragment
837 * @param string $query an optional query string
838 * @return string the URL
840 public function escapeLocalURL( $query = '' ) {
841 return htmlspecialchars( $this->getLocalURL( $query ) );
845 * Get an HTML-escaped version of the URL form, suitable for
846 * using in a link, including the server name and fragment
848 * @return string the URL
849 * @param string $query an optional query string
851 public function escapeFullURL( $query = '' ) {
852 return htmlspecialchars( $this->getFullURL( $query ) );
856 * Get the URL form for an internal link.
857 * - Used in various Squid-related code, in case we have a different
858 * internal hostname for the server from the exposed one.
860 * @param string $query an optional query string
861 * @param string $variant language variant of url (for sr, zh..)
862 * @return string the URL
864 public function getInternalURL( $query = '', $variant = false ) {
865 global $wgInternalServer;
866 $url = $wgInternalServer . $this->getLocalURL( $query, $variant );
867 wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
872 * Get the edit URL for this Title
873 * @return string the URL, or a null string if this is an
876 public function getEditURL() {
877 if ( '' != $this->mInterwiki
) { return ''; }
878 $s = $this->getLocalURL( 'action=edit' );
884 * Get the HTML-escaped displayable text form.
885 * Used for the title field in <a> tags.
886 * @return string the text, including any prefixes
888 public function getEscapedText() {
889 return htmlspecialchars( $this->getPrefixedText() );
893 * Is this Title interwiki?
896 public function isExternal() { return ( '' != $this->mInterwiki
); }
899 * Is this page "semi-protected" - the *only* protection is autoconfirm?
901 * @param string Action to check (default: edit)
904 public function isSemiProtected( $action = 'edit' ) {
905 if( $this->exists() ) {
906 $restrictions = $this->getRestrictions( $action );
907 if( count( $restrictions ) > 0 ) {
908 foreach( $restrictions as $restriction ) {
909 if( strtolower( $restriction ) != 'autoconfirmed' )
918 # If it doesn't exist, it can't be protected
924 * Does the title correspond to a protected article?
925 * @param string $what the action the page is protected from,
926 * by default checks move and edit
929 public function isProtected( $action = '' ) {
930 global $wgRestrictionLevels;
932 # Special pages have inherent protection
933 if( $this->getNamespace() == NS_SPECIAL
)
936 # Check regular protection levels
937 if( $action == 'edit' ||
$action == '' ) {
938 $r = $this->getRestrictions( 'edit' );
939 foreach( $wgRestrictionLevels as $level ) {
940 if( in_array( $level, $r ) && $level != '' ) {
946 if( $action == 'move' ||
$action == '' ) {
947 $r = $this->getRestrictions( 'move' );
948 foreach( $wgRestrictionLevels as $level ) {
949 if( in_array( $level, $r ) && $level != '' ) {
959 * Is $wgUser is watching this page?
962 public function userIsWatching() {
965 if ( is_null( $this->mWatched
) ) {
966 if ( NS_SPECIAL
== $this->mNamespace ||
!$wgUser->isLoggedIn()) {
967 $this->mWatched
= false;
969 $this->mWatched
= $wgUser->isWatched( $this );
972 return $this->mWatched
;
976 * Can $wgUser perform $action on this page?
977 * This skips potentially expensive cascading permission checks.
979 * Suitable for use for nonessential UI controls in common cases, but
980 * _not_ for functional access control.
982 * May provide false positives, but should never provide a false negative.
984 * @param string $action action that permission needs to be checked for
987 public function quickUserCan( $action ) {
988 return $this->userCan( $action, false );
992 * Can $wgUser perform $action on this page?
993 * @param string $action action that permission needs to be checked for
994 * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
997 public function userCan( $action, $doExpensiveQueries = true ) {
998 $fname = 'Title::userCan';
999 wfProfileIn( $fname );
1001 global $wgUser, $wgNamespaceProtection;
1004 wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) );
1005 if ( $result !== null ) {
1006 wfProfileOut( $fname );
1010 if( NS_SPECIAL
== $this->mNamespace
) {
1011 wfProfileOut( $fname );
1015 if ( array_key_exists( $this->mNamespace
, $wgNamespaceProtection ) ) {
1016 $nsProt = $wgNamespaceProtection[ $this->mNamespace
];
1017 if ( !is_array($nsProt) ) $nsProt = array($nsProt);
1018 foreach( $nsProt as $right ) {
1019 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1020 wfProfileOut( $fname );
1026 if( $this->mDbkeyform
== '_' ) {
1027 # FIXME: Is this necessary? Shouldn't be allowed anyway...
1028 wfProfileOut( $fname );
1032 # protect css/js subpages of user pages
1033 # XXX: this might be better using restrictions
1034 # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
1035 if( $this->isCssJsSubpage()
1036 && !$wgUser->isAllowed('editinterface')
1037 && !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) ) {
1038 wfProfileOut( $fname );
1042 if ( $doExpensiveQueries && !$this->isCssJsSubpage() ) {
1043 # We /could/ use the protection level on the source page, but it's fairly ugly
1044 # as we have to establish a precedence hierarchy for pages included by multiple
1045 # cascade-protected pages. So just restrict it to people with 'protect' permission,
1046 # as they could remove the protection anyway.
1047 list( $cascadingSources, $restrictions ) = $this->getCascadeProtectionSources();
1048 # Cascading protection depends on more than this page...
1049 # Several cascading protected pages may include this page...
1050 # Check each cascading level
1051 # This is only for protection restrictions, not for all actions
1052 if( $cascadingSources > 0 && isset($restrictions[$action]) ) {
1053 foreach( $restrictions[$action] as $right ) {
1054 $right = ( $right == 'sysop' ) ?
'protect' : $right;
1055 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1056 wfProfileOut( $fname );
1063 foreach( $this->getRestrictions($action) as $right ) {
1064 // Backwards compatibility, rewrite sysop -> protect
1065 if ( $right == 'sysop' ) {
1068 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1069 wfProfileOut( $fname );
1074 if( $action == 'move' &&
1075 !( $this->isMovable() && $wgUser->isAllowed( 'move' ) ) ) {
1076 wfProfileOut( $fname );
1080 if( $action == 'create' ) {
1081 if( ( $this->isTalkPage() && !$wgUser->isAllowed( 'createtalk' ) ) ||
1082 ( !$this->isTalkPage() && !$wgUser->isAllowed( 'createpage' ) ) ) {
1083 wfProfileOut( $fname );
1088 wfProfileOut( $fname );
1093 * Can $wgUser edit this page?
1095 * @deprecated use userCan('edit')
1097 public function userCanEdit( $doExpensiveQueries = true ) {
1098 return $this->userCan( 'edit', $doExpensiveQueries );
1102 * Can $wgUser create this page?
1104 * @deprecated use userCan('create')
1106 public function userCanCreate( $doExpensiveQueries = true ) {
1107 return $this->userCan( 'create', $doExpensiveQueries );
1111 * Can $wgUser move this page?
1113 * @deprecated use userCan('move')
1115 public function userCanMove( $doExpensiveQueries = true ) {
1116 return $this->userCan( 'move', $doExpensiveQueries );
1120 * Would anybody with sufficient privileges be able to move this page?
1121 * Some pages just aren't movable.
1125 public function isMovable() {
1126 return Namespace::isMovable( $this->getNamespace() )
1127 && $this->getInterwiki() == '';
1131 * Can $wgUser read this page?
1133 * @todo fold these checks into userCan()
1135 public function userCanRead() {
1139 wfRunHooks( 'userCan', array( &$this, &$wgUser, 'read', &$result ) );
1140 if ( $result !== null ) {
1144 if( $wgUser->isAllowed('read') ) {
1147 global $wgWhitelistRead;
1150 * Always grant access to the login page.
1151 * Even anons need to be able to log in.
1153 if( $this->isSpecial( 'Userlogin' ) ||
$this->isSpecial( 'Resetpass' ) ) {
1157 /** some pages are explicitly allowed */
1158 $name = $this->getPrefixedText();
1159 if( $wgWhitelistRead && in_array( $name, $wgWhitelistRead ) ) {
1163 # Compatibility with old settings
1164 if( $wgWhitelistRead && $this->getNamespace() == NS_MAIN
) {
1165 if( in_array( ':' . $name, $wgWhitelistRead ) ) {
1174 * Is this a talk page of some sort?
1177 public function isTalkPage() {
1178 return Namespace::isTalk( $this->getNamespace() );
1182 * Is this a subpage?
1185 public function isSubpage() {
1186 global $wgNamespacesWithSubpages;
1188 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) ) {
1189 return ( strpos( $this->getText(), '/' ) !== false && $wgNamespacesWithSubpages[ $this->mNamespace
] == true );
1196 * Is this a .css or .js subpage of a user page?
1199 public function isCssJsSubpage() {
1200 return ( NS_USER
== $this->mNamespace
and preg_match("/\\/.*\\.(?:css|js)$/", $this->mTextform
) );
1203 * Is this a *valid* .css or .js subpage of a user page?
1204 * Check that the corresponding skin exists
1206 public function isValidCssJsSubpage() {
1207 if ( $this->isCssJsSubpage() ) {
1208 $skinNames = Skin
::getSkinNames();
1209 return array_key_exists( $this->getSkinFromCssJsSubpage(), $skinNames );
1215 * Trim down a .css or .js subpage title to get the corresponding skin name
1217 public function getSkinFromCssJsSubpage() {
1218 $subpage = explode( '/', $this->mTextform
);
1219 $subpage = $subpage[ count( $subpage ) - 1 ];
1220 return( str_replace( array( '.css', '.js' ), array( '', '' ), $subpage ) );
1223 * Is this a .css subpage of a user page?
1226 public function isCssSubpage() {
1227 return ( NS_USER
== $this->mNamespace
and preg_match("/\\/.*\\.css$/", $this->mTextform
) );
1230 * Is this a .js subpage of a user page?
1233 public function isJsSubpage() {
1234 return ( NS_USER
== $this->mNamespace
and preg_match("/\\/.*\\.js$/", $this->mTextform
) );
1237 * Protect css/js subpages of user pages: can $wgUser edit
1241 * @todo XXX: this might be better using restrictions
1243 public function userCanEditCssJsSubpage() {
1245 return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) );
1249 * Cascading protection: Return true if cascading restrictions apply to this page, false if not.
1251 * @return bool If the page is subject to cascading restrictions.
1253 public function isCascadeProtected() {
1254 list( $sources, $restrictions ) = $this->getCascadeProtectionSources( false );
1255 return ( $sources > 0 );
1259 * Cascading protection: Get the source of any cascading restrictions on this page.
1261 * @param $get_pages bool Whether or not to retrieve the actual pages that the restrictions have come from.
1262 * @return array( mixed title array, restriction array)
1263 * 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.
1264 * The restriction array is an array of each type, each of which contains an array of unique groups
1266 public function getCascadeProtectionSources( $get_pages = true ) {
1267 global $wgEnableCascadingProtection, $wgRestrictionTypes;
1269 # Define our dimension of restrictions types
1270 $pagerestrictions = array();
1271 foreach( $wgRestrictionTypes as $action )
1272 $pagerestrictions[$action] = array();
1274 if (!$wgEnableCascadingProtection)
1275 return array( false, $pagerestrictions );
1277 if ( isset( $this->mCascadeSources
) && $get_pages ) {
1278 return array( $this->mCascadeSources
, $this->mCascadingRestrictions
);
1279 } else if ( isset( $this->mHasCascadingRestrictions
) && !$get_pages ) {
1280 return array( $this->mHasCascadingRestrictions
, $pagerestrictions );
1283 wfProfileIn( __METHOD__
);
1285 $dbr = wfGetDb( DB_SLAVE
);
1287 if ( $this->getNamespace() == NS_IMAGE
) {
1288 $tables = array ('imagelinks', 'page_restrictions');
1289 $where_clauses = array(
1290 'il_to' => $this->getDBkey(),
1292 'pr_cascade' => 1 );
1294 $tables = array ('templatelinks', 'page_restrictions');
1295 $where_clauses = array(
1296 'tl_namespace' => $this->getNamespace(),
1297 'tl_title' => $this->getDBkey(),
1299 'pr_cascade' => 1 );
1303 $cols = array('pr_page', 'page_namespace', 'page_title', 'pr_expiry', 'pr_type', 'pr_level' );
1304 $where_clauses[] = 'page_id=pr_page';
1307 $cols = array( 'pr_expiry' );
1310 $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__
);
1312 $sources = $get_pages ?
array() : false;
1313 $now = wfTimestampNow();
1314 $purgeExpired = false;
1316 while( $row = $dbr->fetchObject( $res ) ) {
1317 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
1318 if( $expiry > $now ) {
1320 $page_id = $row->pr_page
;
1321 $page_ns = $row->page_namespace
;
1322 $page_title = $row->page_title
;
1323 $sources[$page_id] = Title
::makeTitle($page_ns, $page_title);
1324 # Add groups needed for each restriction type if its not already there
1325 # Make sure this restriction type still exists
1326 if ( isset($pagerestrictions[$row->pr_type
]) && !in_array($row->pr_level
, $pagerestrictions[$row->pr_type
]) ) {
1327 $pagerestrictions[$row->pr_type
][]=$row->pr_level
;
1333 // Trigger lazy purge of expired restrictions from the db
1334 $purgeExpired = true;
1337 if( $purgeExpired ) {
1338 Title
::purgeExpiredRestrictions();
1341 wfProfileOut( __METHOD__
);
1344 $this->mCascadeSources
= $sources;
1345 $this->mCascadingRestrictions
= $pagerestrictions;
1347 $this->mHasCascadingRestrictions
= $sources;
1350 return array( $sources, $pagerestrictions );
1353 function areRestrictionsCascading() {
1354 if (!$this->mRestrictionsLoaded
) {
1355 $this->loadRestrictions();
1358 return $this->mCascadeRestriction
;
1362 * Loads a string into mRestrictions array
1363 * @param resource $res restrictions as an SQL result.
1365 private function loadRestrictionsFromRow( $res, $oldFashionedRestrictions = NULL ) {
1366 $dbr = wfGetDb( DB_SLAVE
);
1368 $this->mRestrictions
['edit'] = array();
1369 $this->mRestrictions
['move'] = array();
1371 # Backwards-compatibility: also load the restrictions from the page record (old format).
1373 if ( $oldFashionedRestrictions == NULL ) {
1374 $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleId() ), __METHOD__
);
1377 if ($oldFashionedRestrictions != '') {
1379 foreach( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) {
1380 $temp = explode( '=', trim( $restrict ) );
1381 if(count($temp) == 1) {
1382 // old old format should be treated as edit/move restriction
1383 $this->mRestrictions
["edit"] = explode( ',', trim( $temp[0] ) );
1384 $this->mRestrictions
["move"] = explode( ',', trim( $temp[0] ) );
1386 $this->mRestrictions
[$temp[0]] = explode( ',', trim( $temp[1] ) );
1390 $this->mOldRestrictions
= true;
1391 $this->mCascadeRestriction
= false;
1392 $this->mRestrictionsExpiry
= Block
::decodeExpiry('');
1396 if( $dbr->numRows( $res ) ) {
1397 # Current system - load second to make them override.
1398 $now = wfTimestampNow();
1399 $purgeExpired = false;
1401 while ($row = $dbr->fetchObject( $res ) ) {
1402 # Cycle through all the restrictions.
1404 // This code should be refactored, now that it's being used more generally,
1405 // But I don't really see any harm in leaving it in Block for now -werdna
1406 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
1408 // Only apply the restrictions if they haven't expired!
1409 if ( !$expiry ||
$expiry > $now ) {
1410 $this->mRestrictionsExpiry
= $expiry;
1411 $this->mRestrictions
[$row->pr_type
] = explode( ',', trim( $row->pr_level
) );
1413 $this->mCascadeRestriction |
= $row->pr_cascade
;
1415 // Trigger a lazy purge of expired restrictions
1416 $purgeExpired = true;
1420 if( $purgeExpired ) {
1421 Title
::purgeExpiredRestrictions();
1425 $this->mRestrictionsLoaded
= true;
1428 public function loadRestrictions( $oldFashionedRestrictions = NULL ) {
1429 if( !$this->mRestrictionsLoaded
) {
1430 $dbr = wfGetDB( DB_SLAVE
);
1432 $res = $dbr->select( 'page_restrictions', '*',
1433 array ( 'pr_page' => $this->getArticleId() ), __METHOD__
);
1435 $this->loadRestrictionsFromRow( $res, $oldFashionedRestrictions );
1440 * Purge expired restrictions from the page_restrictions table
1442 static function purgeExpiredRestrictions() {
1443 $dbw = wfGetDB( DB_MASTER
);
1444 $dbw->delete( 'page_restrictions',
1445 array( 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
1450 * Accessor/initialisation for mRestrictions
1452 * @param string $action action that permission needs to be checked for
1453 * @return array the array of groups allowed to edit this article
1455 public function getRestrictions( $action ) {
1456 if( $this->exists() ) {
1457 if( !$this->mRestrictionsLoaded
) {
1458 $this->loadRestrictions();
1460 return isset( $this->mRestrictions
[$action] )
1461 ?
$this->mRestrictions
[$action]
1469 * Is there a version of this page in the deletion archive?
1470 * @return int the number of archived revisions
1472 public function isDeleted() {
1473 $fname = 'Title::isDeleted';
1474 if ( $this->getNamespace() < 0 ) {
1477 $dbr = wfGetDB( DB_SLAVE
);
1478 $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
1479 'ar_title' => $this->getDBkey() ), $fname );
1480 if( $this->getNamespace() == NS_IMAGE
) {
1481 $n +
= $dbr->selectField( 'filearchive', 'COUNT(*)',
1482 array( 'fa_name' => $this->getDBkey() ), $fname );
1489 * Get the article ID for this Title from the link cache,
1490 * adding it if necessary
1491 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select
1493 * @return int the ID
1495 public function getArticleID( $flags = 0 ) {
1496 $linkCache =& LinkCache
::singleton();
1497 if ( $flags & GAID_FOR_UPDATE
) {
1498 $oldUpdate = $linkCache->forUpdate( true );
1499 $this->mArticleID
= $linkCache->addLinkObj( $this );
1500 $linkCache->forUpdate( $oldUpdate );
1502 if ( -1 == $this->mArticleID
) {
1503 $this->mArticleID
= $linkCache->addLinkObj( $this );
1506 return $this->mArticleID
;
1509 public function getLatestRevID() {
1510 if ($this->mLatestID
!== false)
1511 return $this->mLatestID
;
1513 $db = wfGetDB(DB_SLAVE
);
1514 return $this->mLatestID
= $db->selectField( 'revision',
1516 array('rev_page' => $this->getArticleID()),
1517 'Title::getLatestRevID' );
1521 * This clears some fields in this object, and clears any associated
1522 * keys in the "bad links" section of the link cache.
1524 * - This is called from Article::insertNewArticle() to allow
1525 * loading of the new page_id. It's also called from
1526 * Article::doDeleteArticle()
1528 * @param int $newid the new Article ID
1530 public function resetArticleID( $newid ) {
1531 $linkCache =& LinkCache
::singleton();
1532 $linkCache->clearBadLink( $this->getPrefixedDBkey() );
1534 if ( 0 == $newid ) { $this->mArticleID
= -1; }
1535 else { $this->mArticleID
= $newid; }
1536 $this->mRestrictionsLoaded
= false;
1537 $this->mRestrictions
= array();
1541 * Updates page_touched for this page; called from LinksUpdate.php
1542 * @return bool true if the update succeded
1544 public function invalidateCache() {
1545 global $wgUseFileCache;
1547 if ( wfReadOnly() ) {
1551 $dbw = wfGetDB( DB_MASTER
);
1552 $success = $dbw->update( 'page',
1554 'page_touched' => $dbw->timestamp()
1555 ), array( /* WHERE */
1556 'page_namespace' => $this->getNamespace() ,
1557 'page_title' => $this->getDBkey()
1558 ), 'Title::invalidateCache'
1561 if ($wgUseFileCache) {
1562 $cache = new HTMLFileCache($this);
1563 @unlink
($cache->fileCacheName());
1570 * Prefix some arbitrary text with the namespace or interwiki prefix
1573 * @param string $name the text
1574 * @return string the prefixed text
1577 /* private */ function prefix( $name ) {
1579 if ( '' != $this->mInterwiki
) {
1580 $p = $this->mInterwiki
. ':';
1582 if ( 0 != $this->mNamespace
) {
1583 $p .= $this->getNsText() . ':';
1589 * Secure and split - main initialisation function for this object
1591 * Assumes that mDbkeyform has been set, and is urldecoded
1592 * and uses underscores, but not otherwise munged. This function
1593 * removes illegal characters, splits off the interwiki and
1594 * namespace prefixes, sets the other forms, and canonicalizes
1596 * @return bool true on success
1598 private function secureAndSplit() {
1599 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
1602 static $rxTc = false;
1604 # % is needed as well
1605 $rxTc = '/[^' . Title
::legalChars() . ']|%[0-9A-Fa-f]{2}/S';
1608 $this->mInterwiki
= $this->mFragment
= '';
1609 $this->mNamespace
= $this->mDefaultNamespace
; # Usually NS_MAIN
1611 $dbkey = $this->mDbkeyform
;
1613 # Strip Unicode bidi override characters.
1614 # Sometimes they slip into cut-n-pasted page titles, where the
1615 # override chars get included in list displays.
1616 $dbkey = str_replace( "\xE2\x80\x8E", '', $dbkey ); // 200E LEFT-TO-RIGHT MARK
1617 $dbkey = str_replace( "\xE2\x80\x8F", '', $dbkey ); // 200F RIGHT-TO-LEFT MARK
1619 # Clean up whitespace
1621 $dbkey = preg_replace( '/[ _]+/', '_', $dbkey );
1622 $dbkey = trim( $dbkey, '_' );
1624 if ( '' == $dbkey ) {
1628 if( false !== strpos( $dbkey, UTF8_REPLACEMENT
) ) {
1629 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
1633 $this->mDbkeyform
= $dbkey;
1635 # Initial colon indicates main namespace rather than specified default
1636 # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
1637 if ( ':' == $dbkey{0} ) {
1638 $this->mNamespace
= NS_MAIN
;
1639 $dbkey = substr( $dbkey, 1 ); # remove the colon but continue processing
1642 # Namespace or interwiki prefix
1646 if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $dbkey, $m ) ) {
1648 if ( $ns = $wgContLang->getNsIndex( $p )) {
1649 # Ordinary namespace
1651 $this->mNamespace
= $ns;
1652 } elseif( $this->getInterwikiLink( $p ) ) {
1654 # Can't make a local interwiki link to an interwiki link.
1655 # That's just crazy!
1661 $this->mInterwiki
= $wgContLang->lc( $p );
1663 # Redundant interwiki prefix to the local wiki
1664 if ( 0 == strcasecmp( $this->mInterwiki
, $wgLocalInterwiki ) ) {
1665 if( $dbkey == '' ) {
1666 # Can't have an empty self-link
1669 $this->mInterwiki
= '';
1671 # Do another namespace split...
1675 # If there's an initial colon after the interwiki, that also
1676 # resets the default namespace
1677 if ( $dbkey !== '' && $dbkey[0] == ':' ) {
1678 $this->mNamespace
= NS_MAIN
;
1679 $dbkey = substr( $dbkey, 1 );
1682 # If there's no recognized interwiki or namespace,
1683 # then let the colon expression be part of the title.
1688 # We already know that some pages won't be in the database!
1690 if ( '' != $this->mInterwiki || NS_SPECIAL
== $this->mNamespace
) {
1691 $this->mArticleID
= 0;
1693 $fragment = strstr( $dbkey, '#' );
1694 if ( false !== $fragment ) {
1695 $this->setFragment( $fragment );
1696 $dbkey = substr( $dbkey, 0, strlen( $dbkey ) - strlen( $fragment ) );
1697 # remove whitespace again: prevents "Foo_bar_#"
1698 # becoming "Foo_bar_"
1699 $dbkey = preg_replace( '/_*$/', '', $dbkey );
1702 # Reject illegal characters.
1704 if( preg_match( $rxTc, $dbkey ) ) {
1709 * Pages with "/./" or "/../" appearing in the URLs will
1710 * often be unreachable due to the way web browsers deal
1711 * with 'relative' URLs. Forbid them explicitly.
1713 if ( strpos( $dbkey, '.' ) !== false &&
1714 ( $dbkey === '.' ||
$dbkey === '..' ||
1715 strpos( $dbkey, './' ) === 0 ||
1716 strpos( $dbkey, '../' ) === 0 ||
1717 strpos( $dbkey, '/./' ) !== false ||
1718 strpos( $dbkey, '/../' ) !== false ) )
1724 * Magic tilde sequences? Nu-uh!
1726 if( strpos( $dbkey, '~~~' ) !== false ) {
1731 * Limit the size of titles to 255 bytes.
1732 * This is typically the size of the underlying database field.
1733 * We make an exception for special pages, which don't need to be stored
1734 * in the database, and may edge over 255 bytes due to subpage syntax
1735 * for long titles, e.g. [[Special:Block/Long name]]
1737 if ( ( $this->mNamespace
!= NS_SPECIAL
&& strlen( $dbkey ) > 255 ) ||
1738 strlen( $dbkey ) > 512 )
1744 * Normally, all wiki links are forced to have
1745 * an initial capital letter so [[foo]] and [[Foo]]
1746 * point to the same place.
1748 * Don't force it for interwikis, since the other
1749 * site might be case-sensitive.
1751 if( $wgCapitalLinks && $this->mInterwiki
== '') {
1752 $dbkey = $wgContLang->ucfirst( $dbkey );
1756 * Can't make a link to a namespace alone...
1757 * "empty" local links can only be self-links
1758 * with a fragment identifier.
1761 $this->mInterwiki
== '' &&
1762 $this->mNamespace
!= NS_MAIN
) {
1766 // Any remaining initial :s are illegal.
1767 if ( $dbkey !== '' && ':' == $dbkey{0} ) {
1772 $this->mDbkeyform
= $dbkey;
1773 $this->mUrlform
= wfUrlencode( $dbkey );
1775 $this->mTextform
= str_replace( '_', ' ', $dbkey );
1781 * Set the fragment for this title
1782 * This is kind of bad, since except for this rarely-used function, Title objects
1783 * are immutable. The reason this is here is because it's better than setting the
1784 * members directly, which is what Linker::formatComment was doing previously.
1786 * @param string $fragment text
1787 * @todo clarify whether access is supposed to be public (was marked as "kind of public")
1789 public function setFragment( $fragment ) {
1790 $this->mFragment
= str_replace( '_', ' ', substr( $fragment, 1 ) );
1794 * Get a Title object associated with the talk page of this article
1795 * @return Title the object for the talk page
1797 public function getTalkPage() {
1798 return Title
::makeTitle( Namespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
1802 * Get a title object associated with the subject page of this
1805 * @return Title the object for the subject page
1807 public function getSubjectPage() {
1808 return Title
::makeTitle( Namespace::getSubject( $this->getNamespace() ), $this->getDBkey() );
1812 * Get an array of Title objects linking to this Title
1813 * Also stores the IDs in the link cache.
1815 * WARNING: do not use this function on arbitrary user-supplied titles!
1816 * On heavily-used templates it will max out the memory.
1818 * @param string $options may be FOR UPDATE
1819 * @return array the Title objects linking here
1821 public function getLinksTo( $options = '', $table = 'pagelinks', $prefix = 'pl' ) {
1822 $linkCache =& LinkCache
::singleton();
1825 $db = wfGetDB( DB_MASTER
);
1827 $db = wfGetDB( DB_SLAVE
);
1830 $res = $db->select( array( 'page', $table ),
1831 array( 'page_namespace', 'page_title', 'page_id' ),
1833 "{$prefix}_from=page_id",
1834 "{$prefix}_namespace" => $this->getNamespace(),
1835 "{$prefix}_title" => $this->getDbKey() ),
1836 'Title::getLinksTo',
1840 if ( $db->numRows( $res ) ) {
1841 while ( $row = $db->fetchObject( $res ) ) {
1842 if ( $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
) ) {
1843 $linkCache->addGoodLinkObj( $row->page_id
, $titleObj );
1844 $retVal[] = $titleObj;
1848 $db->freeResult( $res );
1853 * Get an array of Title objects using this Title as a template
1854 * Also stores the IDs in the link cache.
1856 * WARNING: do not use this function on arbitrary user-supplied titles!
1857 * On heavily-used templates it will max out the memory.
1859 * @param string $options may be FOR UPDATE
1860 * @return array the Title objects linking here
1862 public function getTemplateLinksTo( $options = '' ) {
1863 return $this->getLinksTo( $options, 'templatelinks', 'tl' );
1867 * Get an array of Title objects referring to non-existent articles linked from this page
1869 * @param string $options may be FOR UPDATE
1870 * @return array the Title objects
1872 public function getBrokenLinksFrom( $options = '' ) {
1874 $db = wfGetDB( DB_MASTER
);
1876 $db = wfGetDB( DB_SLAVE
);
1879 $res = $db->safeQuery(
1880 "SELECT pl_namespace, pl_title
1883 ON pl_namespace=page_namespace
1884 AND pl_title=page_title
1886 AND page_namespace IS NULL
1888 $db->tableName( 'pagelinks' ),
1889 $db->tableName( 'page' ),
1890 $this->getArticleId(),
1894 if ( $db->numRows( $res ) ) {
1895 while ( $row = $db->fetchObject( $res ) ) {
1896 $retVal[] = Title
::makeTitle( $row->pl_namespace
, $row->pl_title
);
1899 $db->freeResult( $res );
1905 * Get a list of URLs to purge from the Squid cache when this
1908 * @return array the URLs
1910 public function getSquidURLs() {
1914 $this->getInternalURL(),
1915 $this->getInternalURL( 'action=history' )
1918 // purge variant urls as well
1919 if($wgContLang->hasVariants()){
1920 $variants = $wgContLang->getVariants();
1921 foreach($variants as $vCode){
1922 if($vCode==$wgContLang->getCode()) continue; // we don't want default variant
1923 $urls[] = $this->getInternalURL('',$vCode);
1930 public function purgeSquid() {
1932 if ( $wgUseSquid ) {
1933 $urls = $this->getSquidURLs();
1934 $u = new SquidUpdate( $urls );
1940 * Move this page without authentication
1941 * @param Title &$nt the new page Title
1943 public function moveNoAuth( &$nt ) {
1944 return $this->moveTo( $nt, false );
1948 * Check whether a given move operation would be valid.
1949 * Returns true if ok, or a message key string for an error message
1950 * if invalid. (Scarrrrry ugly interface this.)
1951 * @param Title &$nt the new title
1952 * @param bool $auth indicates whether $wgUser's permissions
1954 * @return mixed true on success, message name on failure
1956 public function isValidMoveOperation( &$nt, $auth = true ) {
1957 if( !$this or !$nt ) {
1958 return 'badtitletext';
1960 if( $this->equals( $nt ) ) {
1963 if( !$this->isMovable() ||
!$nt->isMovable() ) {
1964 return 'immobile_namespace';
1967 $oldid = $this->getArticleID();
1968 $newid = $nt->getArticleID();
1970 if ( strlen( $nt->getDBkey() ) < 1 ) {
1971 return 'articleexists';
1973 if ( ( '' == $this->getDBkey() ) ||
1975 ( '' == $nt->getDBkey() ) ) {
1976 return 'badarticleerror';
1980 !$this->userCan( 'edit' ) ||
!$nt->userCan( 'edit' ) ||
1981 !$this->userCan( 'move' ) ||
!$nt->userCan( 'move' ) ) ) {
1982 return 'protectedpage';
1985 # The move is allowed only if (1) the target doesn't exist, or
1986 # (2) the target is a redirect to the source, and has no history
1987 # (so we can undo bad moves right after they're done).
1989 if ( 0 != $newid ) { # Target exists; check for validity
1990 if ( ! $this->isValidMoveTarget( $nt ) ) {
1991 return 'articleexists';
1998 * Move a title to a new location
1999 * @param Title &$nt the new title
2000 * @param bool $auth indicates whether $wgUser's permissions
2002 * @return mixed true on success, message name on failure
2004 public function moveTo( &$nt, $auth = true, $reason = '' ) {
2005 $err = $this->isValidMoveOperation( $nt, $auth );
2006 if( is_string( $err ) ) {
2010 $pageid = $this->getArticleID();
2011 if( $nt->exists() ) {
2012 $this->moveOverExistingRedirect( $nt, $reason );
2013 $pageCountChange = 0;
2014 } else { # Target didn't exist, do normal move.
2015 $this->moveToNewTitle( $nt, $reason );
2016 $pageCountChange = 1;
2018 $redirid = $this->getArticleID();
2020 # Fixing category links (those without piped 'alternate' names) to be sorted under the new title
2021 $dbw = wfGetDB( DB_MASTER
);
2022 $categorylinks = $dbw->tableName( 'categorylinks' );
2023 $sql = "UPDATE $categorylinks SET cl_sortkey=" . $dbw->addQuotes( $nt->getPrefixedText() ) .
2024 " WHERE cl_from=" . $dbw->addQuotes( $pageid ) .
2025 " AND cl_sortkey=" . $dbw->addQuotes( $this->getPrefixedText() );
2026 $dbw->query( $sql, 'SpecialMovepage::doSubmit' );
2030 $oldnamespace = $this->getNamespace() & ~
1;
2031 $newnamespace = $nt->getNamespace() & ~
1;
2032 $oldtitle = $this->getDBkey();
2033 $newtitle = $nt->getDBkey();
2035 if( $oldnamespace != $newnamespace ||
$oldtitle != $newtitle ) {
2036 WatchedItem
::duplicateEntries( $this, $nt );
2039 # Update search engine
2040 $u = new SearchUpdate( $pageid, $nt->getPrefixedDBkey() );
2042 $u = new SearchUpdate( $redirid, $this->getPrefixedDBkey(), '' );
2046 if( $this->isContentPage() && !$nt->isContentPage() ) {
2047 # No longer a content page
2048 # Not viewed, edited, removing
2049 $u = new SiteStatsUpdate( 0, 1, -1, $pageCountChange );
2050 } elseif( !$this->isContentPage() && $nt->isContentPage() ) {
2051 # Now a content page
2052 # Not viewed, edited, adding
2053 $u = new SiteStatsUpdate( 0, 1, +
1, $pageCountChange );
2054 } elseif( $pageCountChange ) {
2056 $u = new SiteStatsUpdate( 0, 0, 0, 1 );
2065 wfRunHooks( 'TitleMoveComplete', array( &$this, &$nt, &$wgUser, $pageid, $redirid ) );
2070 * Move page to a title which is at present a redirect to the
2073 * @param Title &$nt the page to move to, which should currently
2076 private function moveOverExistingRedirect( &$nt, $reason = '' ) {
2078 $fname = 'Title::moveOverExistingRedirect';
2079 $comment = wfMsgForContent( '1movedto2_redir', $this->getPrefixedText(), $nt->getPrefixedText() );
2082 $comment .= ": $reason";
2085 $now = wfTimestampNow();
2086 $newid = $nt->getArticleID();
2087 $oldid = $this->getArticleID();
2088 $dbw = wfGetDB( DB_MASTER
);
2089 $linkCache =& LinkCache
::singleton();
2091 # Delete the old redirect. We don't save it to history since
2092 # by definition if we've got here it's rather uninteresting.
2093 # We have to remove it so that the next step doesn't trigger
2094 # a conflict on the unique namespace+title index...
2095 $dbw->delete( 'page', array( 'page_id' => $newid ), $fname );
2097 # Save a null revision in the page's history notifying of the move
2098 $nullRevision = Revision
::newNullRevision( $dbw, $oldid, $comment, true );
2099 $nullRevId = $nullRevision->insertOn( $dbw );
2101 # Change the name of the target page:
2102 $dbw->update( 'page',
2104 'page_touched' => $dbw->timestamp($now),
2105 'page_namespace' => $nt->getNamespace(),
2106 'page_title' => $nt->getDBkey(),
2107 'page_latest' => $nullRevId,
2109 /* WHERE */ array( 'page_id' => $oldid ),
2112 $linkCache->clearLink( $nt->getPrefixedDBkey() );
2114 # Recreate the redirect, this time in the other direction.
2115 $mwRedir = MagicWord
::get( 'redirect' );
2116 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
2117 $redirectArticle = new Article( $this );
2118 $newid = $redirectArticle->insertOn( $dbw );
2119 $redirectRevision = new Revision( array(
2121 'comment' => $comment,
2122 'text' => $redirectText ) );
2123 $redirectRevision->insertOn( $dbw );
2124 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
2125 $linkCache->clearLink( $this->getPrefixedDBkey() );
2128 $log = new LogPage( 'move' );
2129 $log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText() ) );
2131 # Now, we record the link from the redirect to the new title.
2132 # It should have no other outgoing links...
2133 $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), $fname );
2134 $dbw->insert( 'pagelinks',
2136 'pl_from' => $newid,
2137 'pl_namespace' => $nt->getNamespace(),
2138 'pl_title' => $nt->getDbKey() ),
2142 if ( $wgUseSquid ) {
2143 $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
2144 $u = new SquidUpdate( $urls );
2150 * Move page to non-existing title.
2151 * @param Title &$nt the new Title
2153 private function moveToNewTitle( &$nt, $reason = '' ) {
2155 $fname = 'MovePageForm::moveToNewTitle';
2156 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
2158 $comment .= ": $reason";
2161 $newid = $nt->getArticleID();
2162 $oldid = $this->getArticleID();
2163 $dbw = wfGetDB( DB_MASTER
);
2164 $now = $dbw->timestamp();
2165 $linkCache =& LinkCache
::singleton();
2167 # Save a null revision in the page's history notifying of the move
2168 $nullRevision = Revision
::newNullRevision( $dbw, $oldid, $comment, true );
2169 $nullRevId = $nullRevision->insertOn( $dbw );
2172 $dbw->update( 'page',
2174 'page_touched' => $now,
2175 'page_namespace' => $nt->getNamespace(),
2176 'page_title' => $nt->getDBkey(),
2177 'page_latest' => $nullRevId,
2179 /* WHERE */ array( 'page_id' => $oldid ),
2183 $linkCache->clearLink( $nt->getPrefixedDBkey() );
2186 $mwRedir = MagicWord
::get( 'redirect' );
2187 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
2188 $redirectArticle = new Article( $this );
2189 $newid = $redirectArticle->insertOn( $dbw );
2190 $redirectRevision = new Revision( array(
2192 'comment' => $comment,
2193 'text' => $redirectText ) );
2194 $redirectRevision->insertOn( $dbw );
2195 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
2196 $linkCache->clearLink( $this->getPrefixedDBkey() );
2199 $log = new LogPage( 'move' );
2200 $log->addEntry( 'move', $this, $reason, array( 1 => $nt->getPrefixedText()) );
2202 # Purge caches as per article creation
2203 Article
::onArticleCreate( $nt );
2205 # Record the just-created redirect's linking to the page
2206 $dbw->insert( 'pagelinks',
2208 'pl_from' => $newid,
2209 'pl_namespace' => $nt->getNamespace(),
2210 'pl_title' => $nt->getDBkey() ),
2213 # Purge old title from squid
2214 # The new title, and links to the new title, are purged in Article::onArticleCreate()
2215 $this->purgeSquid();
2219 * Checks if $this can be moved to a given Title
2220 * - Selects for update, so don't call it unless you mean business
2222 * @param Title &$nt the new title to check
2224 public function isValidMoveTarget( $nt ) {
2226 $fname = 'Title::isValidMoveTarget';
2227 $dbw = wfGetDB( DB_MASTER
);
2230 $id = $nt->getArticleID();
2231 $obj = $dbw->selectRow( array( 'page', 'revision', 'text'),
2232 array( 'page_is_redirect','old_text','old_flags' ),
2233 array( 'page_id' => $id, 'page_latest=rev_id', 'rev_text_id=old_id' ),
2234 $fname, 'FOR UPDATE' );
2236 if ( !$obj ||
0 == $obj->page_is_redirect
) {
2238 wfDebug( __METHOD__
. ": not a redirect\n" );
2241 $text = Revision
::getRevisionText( $obj );
2243 # Does the redirect point to the source?
2244 # Or is it a broken self-redirect, usually caused by namespace collisions?
2246 if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $text, $m ) ) {
2247 $redirTitle = Title
::newFromText( $m[1] );
2248 if( !is_object( $redirTitle ) ||
2249 ( $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() &&
2250 $redirTitle->getPrefixedDBkey() != $nt->getPrefixedDBkey() ) ) {
2251 wfDebug( __METHOD__
. ": redirect points to other page\n" );
2256 wfDebug( __METHOD__
. ": failsafe\n" );
2260 # Does the article have a history?
2261 $row = $dbw->selectRow( array( 'page', 'revision'),
2263 array( 'page_namespace' => $nt->getNamespace(),
2264 'page_title' => $nt->getDBkey(),
2265 'page_id=rev_page AND page_latest != rev_id'
2266 ), $fname, 'FOR UPDATE'
2269 # Return true if there was no history
2270 return $row === false;
2274 * Get categories to which this Title belongs and return an array of
2275 * categories' names.
2277 * @return array an array of parents in the form:
2278 * $parent => $currentarticle
2280 public function getParentCategories() {
2283 $titlekey = $this->getArticleId();
2284 $dbr = wfGetDB( DB_SLAVE
);
2285 $categorylinks = $dbr->tableName( 'categorylinks' );
2288 $sql = "SELECT * FROM $categorylinks"
2289 ." WHERE cl_from='$titlekey'"
2290 ." AND cl_from <> '0'"
2291 ." ORDER BY cl_sortkey";
2293 $res = $dbr->query ( $sql ) ;
2295 if($dbr->numRows($res) > 0) {
2296 while ( $x = $dbr->fetchObject ( $res ) )
2297 //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
2298 $data[$wgContLang->getNSText ( NS_CATEGORY
).':'.$x->cl_to
] = $this->getFullText();
2299 $dbr->freeResult ( $res ) ;
2307 * Get a tree of parent categories
2308 * @param array $children an array with the children in the keys, to check for circular refs
2311 public function getParentCategoryTree( $children = array() ) {
2312 $parents = $this->getParentCategories();
2314 if($parents != '') {
2315 foreach($parents as $parent => $current) {
2316 if ( array_key_exists( $parent, $children ) ) {
2317 # Circular reference
2318 $stack[$parent] = array();
2320 $nt = Title
::newFromText($parent);
2322 $stack[$parent] = $nt->getParentCategoryTree( $children +
array($parent => 1) );
2334 * Get an associative array for selecting this title from
2339 public function pageCond() {
2340 return array( 'page_namespace' => $this->mNamespace
, 'page_title' => $this->mDbkeyform
);
2344 * Get the revision ID of the previous revision
2346 * @param integer $revision Revision ID. Get the revision that was before this one.
2347 * @return integer $oldrevision|false
2349 public function getPreviousRevisionID( $revision ) {
2350 $dbr = wfGetDB( DB_SLAVE
);
2351 return $dbr->selectField( 'revision', 'rev_id',
2352 'rev_page=' . intval( $this->getArticleId() ) .
2353 ' AND rev_id<' . intval( $revision ) . ' ORDER BY rev_id DESC' );
2357 * Get the revision ID of the next revision
2359 * @param integer $revision Revision ID. Get the revision that was after this one.
2360 * @return integer $oldrevision|false
2362 public function getNextRevisionID( $revision ) {
2363 $dbr = wfGetDB( DB_SLAVE
);
2364 return $dbr->selectField( 'revision', 'rev_id',
2365 'rev_page=' . intval( $this->getArticleId() ) .
2366 ' AND rev_id>' . intval( $revision ) . ' ORDER BY rev_id' );
2370 * Get the number of revisions between the given revision IDs.
2372 * @param integer $old Revision ID.
2373 * @param integer $new Revision ID.
2374 * @return integer Number of revisions between these IDs.
2376 public function countRevisionsBetween( $old, $new ) {
2377 $dbr = wfGetDB( DB_SLAVE
);
2378 return $dbr->selectField( 'revision', 'count(*)',
2379 'rev_page = ' . intval( $this->getArticleId() ) .
2380 ' AND rev_id > ' . intval( $old ) .
2381 ' AND rev_id < ' . intval( $new ) );
2385 * Compare with another title.
2387 * @param Title $title
2390 public function equals( $title ) {
2391 // Note: === is necessary for proper matching of number-like titles.
2392 return $this->getInterwiki() === $title->getInterwiki()
2393 && $this->getNamespace() == $title->getNamespace()
2394 && $this->getDbkey() === $title->getDbkey();
2398 * Check if page exists
2401 public function exists() {
2402 return $this->getArticleId() != 0;
2406 * Should a link should be displayed as a known link, just based on its title?
2408 * Currently, a self-link with a fragment and special pages are in
2409 * this category. Special pages never exist in the database.
2411 public function isAlwaysKnown() {
2412 return $this->isExternal() ||
( 0 == $this->mNamespace
&& "" == $this->mDbkeyform
)
2413 || NS_SPECIAL
== $this->mNamespace
;
2417 * Update page_touched timestamps and send squid purge messages for
2418 * pages linking to this title. May be sent to the job queue depending
2419 * on the number of links. Typically called on create and delete.
2421 public function touchLinks() {
2422 $u = new HTMLCacheUpdate( $this, 'pagelinks' );
2425 if ( $this->getNamespace() == NS_CATEGORY
) {
2426 $u = new HTMLCacheUpdate( $this, 'categorylinks' );
2432 * Get the last touched timestamp
2434 public function getTouched() {
2435 $dbr = wfGetDB( DB_SLAVE
);
2436 $touched = $dbr->selectField( 'page', 'page_touched',
2438 'page_namespace' => $this->getNamespace(),
2439 'page_title' => $this->getDBkey()
2445 public function trackbackURL() {
2446 global $wgTitle, $wgScriptPath, $wgServer;
2448 return "$wgServer$wgScriptPath/trackback.php?article="
2449 . htmlspecialchars(urlencode($wgTitle->getPrefixedDBkey()));
2452 public function trackbackRDF() {
2453 $url = htmlspecialchars($this->getFullURL());
2454 $title = htmlspecialchars($this->getText());
2455 $tburl = $this->trackbackURL();
2458 <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
2459 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
2460 xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">
2463 dc:identifier=\"$url\"
2465 trackback:ping=\"$tburl\" />
2470 * Generate strings used for xml 'id' names in monobook tabs
2473 public function getNamespaceKey() {
2475 switch ($this->getNamespace()) {
2478 return 'nstab-main';
2481 return 'nstab-user';
2483 return 'nstab-media';
2485 return 'nstab-special';
2487 case NS_PROJECT_TALK
:
2488 return 'nstab-project';
2491 return 'nstab-image';
2493 case NS_MEDIAWIKI_TALK
:
2494 return 'nstab-mediawiki';
2496 case NS_TEMPLATE_TALK
:
2497 return 'nstab-template';
2500 return 'nstab-help';
2502 case NS_CATEGORY_TALK
:
2503 return 'nstab-category';
2505 return 'nstab-' . $wgContLang->lc( $this->getSubjectNsText() );
2510 * Returns true if this title resolves to the named special page
2511 * @param string $name The special page name
2513 public function isSpecial( $name ) {
2514 if ( $this->getNamespace() == NS_SPECIAL
) {
2515 list( $thisName, /* $subpage */ ) = SpecialPage
::resolveAliasWithSubpage( $this->getDBkey() );
2516 if ( $name == $thisName ) {
2524 * If the Title refers to a special page alias which is not the local default,
2525 * returns a new Title which points to the local default. Otherwise, returns $this.
2527 public function fixSpecialName() {
2528 if ( $this->getNamespace() == NS_SPECIAL
) {
2529 $canonicalName = SpecialPage
::resolveAlias( $this->mDbkeyform
);
2530 if ( $canonicalName ) {
2531 $localName = SpecialPage
::getLocalNameFor( $canonicalName );
2532 if ( $localName != $this->mDbkeyform
) {
2533 return Title
::makeTitle( NS_SPECIAL
, $localName );
2541 * Is this Title in a namespace which contains content?
2542 * In other words, is this a content page, for the purposes of calculating
2547 public function isContentPage() {
2548 return Namespace::isContent( $this->getNamespace() );