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 $mUserCaseDBKey; # DB key with the initial letter in the case specified by the user
51 var $mNamespace; # Namespace index, i.e. one of the NS_xxxx constants
52 var $mInterwiki; # Interwiki prefix (or null string)
53 var $mFragment; # Title fragment (i.e. the bit after the #)
54 var $mArticleID; # Article ID, fetched from the link cache on demand
55 var $mLatestID; # ID of most recent revision
56 var $mRestrictions; # Array of groups allowed to edit this article
57 var $mCascadeRestriction; # Cascade restrictions on this page to included templates and images?
58 var $mRestrictionsExpiry; # When do the restrictions on this page expire?
59 var $mHasCascadingRestrictions; # Are cascading restrictions in effect on this page?
60 var $mCascadeRestrictionSources;# Where are the cascading restrictions coming from on this page?
61 var $mRestrictionsLoaded; # Boolean for initialisation on demand
62 var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
63 var $mDefaultNamespace; # Namespace index when there is no namespace
64 # Zero except in {{transclusion}} tags
65 var $mWatched; # Is $wgUser watching this page? NULL if unfilled, accessed through userIsWatching()
73 /* private */ function __construct() {
74 $this->mInterwiki
= $this->mUrlform
=
75 $this->mTextform
= $this->mDbkeyform
= '';
76 $this->mArticleID
= -1;
77 $this->mNamespace
= NS_MAIN
;
78 $this->mRestrictionsLoaded
= false;
79 $this->mRestrictions
= array();
80 # Dont change the following, NS_MAIN is hardcoded in several place
82 $this->mDefaultNamespace
= NS_MAIN
;
83 $this->mWatched
= NULL;
84 $this->mLatestID
= false;
85 $this->mOldRestrictions
= false;
89 * Create a new Title from a prefixed DB key
90 * @param string $key The database key, which has underscores
91 * instead of spaces, possibly including namespace and
93 * @return Title the new object, or NULL on an error
95 public 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
115 public static function newFromText( $text, $defaultNamespace = NS_MAIN
) {
116 if( is_object( $text ) ) {
117 throw new MWException( 'Title::newFromText given an object' );
121 * Wiki pages often contain multiple links to the same page.
122 * Title normalization and parsing can become expensive on
123 * pages with many links, so we can save a little time by
126 * In theory these are value objects and won't get changed...
128 if( $defaultNamespace == NS_MAIN
&& isset( Title
::$titleCache[$text] ) ) {
129 return Title
::$titleCache[$text];
133 * Convert things like é ā or 〗 into real text...
135 $filteredText = Sanitizer
::decodeCharReferences( $text );
138 $t->mDbkeyform
= str_replace( ' ', '_', $filteredText );
139 $t->mDefaultNamespace
= $defaultNamespace;
141 static $cachedcount = 0 ;
142 if( $t->secureAndSplit() ) {
143 if( $defaultNamespace == NS_MAIN
) {
144 if( $cachedcount >= MW_TITLECACHE_MAX
) {
145 # Avoid memory leaks on mass operations...
146 Title
::$titleCache = array();
150 Title
::$titleCache[$text] =& $t;
160 * Create a new Title from URL-encoded text. Ensures that
161 * the given title's length does not exceed the maximum.
162 * @param string $url the title, as might be taken from a URL
163 * @return Title the new object, or NULL on an error
165 public static function newFromURL( $url ) {
166 global $wgLegalTitleChars;
169 # For compatibility with old buggy URLs. "+" is usually not valid in titles,
170 # but some URLs used it as a space replacement and they still come
171 # from some external search tools.
172 if ( strpos( $wgLegalTitleChars, '+' ) === false ) {
173 $url = str_replace( '+', ' ', $url );
176 $t->mDbkeyform
= str_replace( ' ', '_', $url );
177 if( $t->secureAndSplit() ) {
185 * Create a new Title from an article ID
187 * @todo This is inefficiently implemented, the page row is requested
188 * but not used for anything else
190 * @param int $id the page_id corresponding to the Title to create
191 * @return Title the new object, or NULL on an error
193 public static function newFromID( $id ) {
194 $fname = 'Title::newFromID';
195 $dbr = wfGetDB( DB_SLAVE
);
196 $row = $dbr->selectRow( 'page', array( 'page_namespace', 'page_title' ),
197 array( 'page_id' => $id ), $fname );
198 if ( $row !== false ) {
199 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
207 * Make an array of titles from an array of IDs
209 public static function newFromIDs( $ids ) {
210 $dbr = wfGetDB( DB_SLAVE
);
211 $res = $dbr->select( 'page', array( 'page_namespace', 'page_title' ),
212 'page_id IN (' . $dbr->makeList( $ids ) . ')', __METHOD__
);
215 while ( $row = $dbr->fetchObject( $res ) ) {
216 $titles[] = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
222 * Create a new Title from a namespace index and a DB key.
223 * It's assumed that $ns and $title are *valid*, for instance when
224 * they came directly from the database or a special page name.
225 * For convenience, spaces are converted to underscores so that
226 * eg user_text fields can be used directly.
228 * @param int $ns the namespace of the article
229 * @param string $title the unprefixed database key form
230 * @return Title the new object
232 public static function &makeTitle( $ns, $title ) {
236 $t->mNamespace
= $ns = intval( $ns );
237 $t->mDbkeyform
= str_replace( ' ', '_', $title );
238 $t->mArticleID
= ( $ns >= 0 ) ?
-1 : 0;
239 $t->mUrlform
= wfUrlencode( $t->mDbkeyform
);
240 $t->mTextform
= str_replace( '_', ' ', $title );
245 * Create a new Title from a namespace index and a DB key.
246 * The parameters will be checked for validity, which is a bit slower
247 * than makeTitle() but safer for user-provided data.
249 * @param int $ns the namespace of the article
250 * @param string $title the database key form
251 * @return Title the new object, or NULL on an error
253 public static function makeTitleSafe( $ns, $title ) {
255 $t->mDbkeyform
= Title
::makeName( $ns, $title );
256 if( $t->secureAndSplit() ) {
264 * Create a new Title for the Main Page
265 * @return Title the new object
267 public static function newMainPage() {
268 return Title
::newFromText( wfMsgForContent( 'mainpage' ) );
272 * Create a new Title for a redirect
273 * @param string $text the redirect title text
274 * @return Title the new object, or NULL if the text is not a
277 public static function newFromRedirect( $text ) {
278 $mwRedir = MagicWord
::get( 'redirect' );
280 if ( $mwRedir->matchStart( $text ) ) {
282 if ( preg_match( '/\[{2}(.*?)(?:\||\]{2})/', $text, $m ) ) {
283 # categories are escaped using : for example one can enter:
284 # #REDIRECT [[:Category:Music]]. Need to remove it.
285 if ( substr($m[1],0,1) == ':') {
286 # We don't want to keep the ':'
287 $m[1] = substr( $m[1], 1 );
290 $rt = Title
::newFromText( $m[1] );
291 # Disallow redirects to Special:Userlogout
292 if ( !is_null($rt) && $rt->isSpecial( 'Userlogout' ) ) {
300 #----------------------------------------------------------------------------
302 #----------------------------------------------------------------------------
305 * Get the prefixed DB key associated with an ID
306 * @param int $id the page_id of the article
307 * @return Title an object representing the article, or NULL
308 * if no such article was found
312 function nameOf( $id ) {
313 $fname = 'Title::nameOf';
314 $dbr = wfGetDB( DB_SLAVE
);
316 $s = $dbr->selectRow( 'page', array( 'page_namespace','page_title' ), array( 'page_id' => $id ), $fname );
317 if ( $s === false ) { return NULL; }
319 $n = Title
::makeName( $s->page_namespace
, $s->page_title
);
324 * Get a regex character class describing the legal characters in a link
325 * @return string the list of characters, not delimited
327 public static function legalChars() {
328 global $wgLegalTitleChars;
329 return $wgLegalTitleChars;
333 * Get a string representation of a title suitable for
334 * including in a search index
336 * @param int $ns a namespace index
337 * @param string $title text-form main part
338 * @return string a stripped-down title string ready for the
341 public static function indexTitle( $ns, $title ) {
344 $lc = SearchEngine
::legalSearchChars() . '&#;';
345 $t = $wgContLang->stripForSearch( $title );
346 $t = preg_replace( "/[^{$lc}]+/", ' ', $t );
347 $t = $wgContLang->lc( $t );
350 $t = preg_replace( "/([{$lc}]+)'s( |$)/", "\\1 \\1's ", $t );
351 $t = preg_replace( "/([{$lc}]+)s'( |$)/", "\\1s ", $t );
353 $t = preg_replace( "/\\s+/", ' ', $t );
355 if ( $ns == NS_IMAGE
) {
356 $t = preg_replace( "/ (png|gif|jpg|jpeg|ogg)$/", "", $t );
362 * Make a prefixed DB key from a DB key and a namespace index
363 * @param int $ns numerical representation of the namespace
364 * @param string $title the DB key form the title
365 * @return string the prefixed form of the title
367 public static function makeName( $ns, $title ) {
370 $n = $wgContLang->getNsText( $ns );
371 return $n == '' ?
$title : "$n:$title";
375 * Returns the URL associated with an interwiki prefix
376 * @param string $key the interwiki prefix (e.g. "MeatBall")
377 * @return the associated URL, containing "$1", which should be
378 * replaced by an article title
381 public function getInterwikiLink( $key ) {
382 global $wgMemc, $wgInterwikiExpiry;
383 global $wgInterwikiCache, $wgContLang;
384 $fname = 'Title::getInterwikiLink';
386 $key = $wgContLang->lc( $key );
388 $k = wfMemcKey( 'interwiki', $key );
389 if( array_key_exists( $k, Title
::$interwikiCache ) ) {
390 return Title
::$interwikiCache[$k]->iw_url
;
393 if ($wgInterwikiCache) {
394 return Title
::getInterwikiCached( $key );
397 $s = $wgMemc->get( $k );
398 # Ignore old keys with no iw_local
399 if( $s && isset( $s->iw_local
) && isset($s->iw_trans
)) {
400 Title
::$interwikiCache[$k] = $s;
404 $dbr = wfGetDB( DB_SLAVE
);
405 $res = $dbr->select( 'interwiki',
406 array( 'iw_url', 'iw_local', 'iw_trans' ),
407 array( 'iw_prefix' => $key ), $fname );
412 $s = $dbr->fetchObject( $res );
414 # Cache non-existence: create a blank object and save it to memcached
420 $wgMemc->set( $k, $s, $wgInterwikiExpiry );
421 Title
::$interwikiCache[$k] = $s;
427 * Fetch interwiki prefix data from local cache in constant database
429 * More logic is explained in DefaultSettings
431 * @return string URL of interwiki site
433 public static function getInterwikiCached( $key ) {
434 global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
438 $db=dba_open($wgInterwikiCache,'r','cdb');
439 /* Resolve site name */
440 if ($wgInterwikiScopes>=3 and !$site) {
441 $site = dba_fetch('__sites:' . wfWikiID(), $db);
443 $site = $wgInterwikiFallbackSite;
445 $value = dba_fetch( wfMemcKey( $key ), $db);
446 if ($value=='' and $wgInterwikiScopes>=3) {
448 $value = dba_fetch("_{$site}:{$key}", $db);
450 if ($value=='' and $wgInterwikiScopes>=2) {
452 $value = dba_fetch("__global:{$key}", $db);
461 list($local,$url)=explode(' ',$value,2);
463 $s->iw_local
=(int)$local;
465 Title
::$interwikiCache[wfMemcKey( 'interwiki', $key )] = $s;
469 * Determine whether the object refers to a page within
472 * @return bool TRUE if this is an in-project interwiki link
473 * or a wikilink, FALSE otherwise
475 public function isLocal() {
476 if ( $this->mInterwiki
!= '' ) {
477 # Make sure key is loaded into cache
478 $this->getInterwikiLink( $this->mInterwiki
);
479 $k = wfMemcKey( 'interwiki', $this->mInterwiki
);
480 return (bool)(Title
::$interwikiCache[$k]->iw_local
);
487 * Determine whether the object refers to a page within
488 * this project and is transcludable.
490 * @return bool TRUE if this is transcludable
492 public function isTrans() {
493 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_trans
);
502 * Escape a text fragment, say from a link, for a URL
504 static function escapeFragmentForURL( $fragment ) {
505 $fragment = str_replace( ' ', '_', $fragment );
506 $fragment = urlencode( Sanitizer
::decodeCharReferences( $fragment ) );
507 $replaceArray = array(
511 return strtr( $fragment, $replaceArray );
514 #----------------------------------------------------------------------------
516 #----------------------------------------------------------------------------
518 /** Simple accessors */
520 * Get the text form (spaces not underscores) of the main part
523 public function getText() { return $this->mTextform
; }
525 * Get the URL-encoded form of the main part
528 public function getPartialURL() { return $this->mUrlform
; }
530 * Get the main part with underscores
533 public function getDBkey() { return $this->mDbkeyform
; }
535 * Get the namespace index, i.e. one of the NS_xxxx constants
538 public function getNamespace() { return $this->mNamespace
; }
540 * Get the namespace text
543 public function getNsText() {
544 global $wgContLang, $wgCanonicalNamespaceNames;
546 if ( '' != $this->mInterwiki
) {
547 // This probably shouldn't even happen. ohh man, oh yuck.
548 // But for interwiki transclusion it sometimes does.
549 // Shit. Shit shit shit.
551 // Use the canonical namespaces if possible to try to
552 // resolve a foreign namespace.
553 if( isset( $wgCanonicalNamespaceNames[$this->mNamespace
] ) ) {
554 return $wgCanonicalNamespaceNames[$this->mNamespace
];
557 return $wgContLang->getNsText( $this->mNamespace
);
560 * Get the DB key with the initial letter case as specified by the user
562 function getUserCaseDBKey() {
563 return $this->mUserCaseDBKey
;
566 * Get the namespace text of the subject (rather than talk) page
569 public function getSubjectNsText() {
571 return $wgContLang->getNsText( Namespace::getSubject( $this->mNamespace
) );
575 * Get the namespace text of the talk page
578 public function getTalkNsText() {
580 return( $wgContLang->getNsText( Namespace::getTalk( $this->mNamespace
) ) );
584 * Could this title have a corresponding talk page?
587 public function canTalk() {
588 return( Namespace::canTalk( $this->mNamespace
) );
592 * Get the interwiki prefix (or null string)
595 public function getInterwiki() { return $this->mInterwiki
; }
597 * Get the Title fragment (i.e. the bit after the #) in text form
600 public function getFragment() { return $this->mFragment
; }
602 * Get the fragment in URL form, including the "#" character if there is one
605 public function getFragmentForURL() {
606 if ( $this->mFragment
== '' ) {
609 return '#' . Title
::escapeFragmentForURL( $this->mFragment
);
613 * Get the default namespace index, for when there is no namespace
616 public function getDefaultNamespace() { return $this->mDefaultNamespace
; }
619 * Get title for search index
620 * @return string a stripped-down title string ready for the
623 public function getIndexTitle() {
624 return Title
::indexTitle( $this->mNamespace
, $this->mTextform
);
628 * Get the prefixed database key form
629 * @return string the prefixed title, with underscores and
630 * any interwiki and namespace prefixes
632 public function getPrefixedDBkey() {
633 $s = $this->prefix( $this->mDbkeyform
);
634 $s = str_replace( ' ', '_', $s );
639 * Get the prefixed title with spaces.
640 * This is the form usually used for display
641 * @return string the prefixed title, with spaces
643 public function getPrefixedText() {
644 if ( empty( $this->mPrefixedText
) ) { // FIXME: bad usage of empty() ?
645 $s = $this->prefix( $this->mTextform
);
646 $s = str_replace( '_', ' ', $s );
647 $this->mPrefixedText
= $s;
649 return $this->mPrefixedText
;
653 * Get the prefixed title with spaces, plus any fragment
654 * (part beginning with '#')
655 * @return string the prefixed title, with spaces and
656 * the fragment, including '#'
658 public function getFullText() {
659 $text = $this->getPrefixedText();
660 if( '' != $this->mFragment
) {
661 $text .= '#' . $this->mFragment
;
667 * Get the base name, i.e. the leftmost parts before the /
668 * @return string Base name
670 public function getBaseText() {
671 global $wgNamespacesWithSubpages;
672 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) && $wgNamespacesWithSubpages[ $this->mNamespace
] ) {
673 $parts = explode( '/', $this->getText() );
674 # Don't discard the real title if there's no subpage involved
675 if( count( $parts ) > 1 )
676 unset( $parts[ count( $parts ) - 1 ] );
677 return implode( '/', $parts );
679 return $this->getText();
684 * Get the lowest-level subpage name, i.e. the rightmost part after /
685 * @return string Subpage name
687 public function getSubpageText() {
688 global $wgNamespacesWithSubpages;
689 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) && $wgNamespacesWithSubpages[ $this->mNamespace
] ) {
690 $parts = explode( '/', $this->mTextform
);
691 return( $parts[ count( $parts ) - 1 ] );
693 return( $this->mTextform
);
698 * Get a URL-encoded form of the subpage text
699 * @return string URL-encoded subpage name
701 public function getSubpageUrlForm() {
702 $text = $this->getSubpageText();
703 $text = wfUrlencode( str_replace( ' ', '_', $text ) );
704 $text = str_replace( '%28', '(', str_replace( '%29', ')', $text ) ); # Clean up the URL; per below, this might not be safe
709 * Get a URL-encoded title (not an actual URL) including interwiki
710 * @return string the URL-encoded form
712 public function getPrefixedURL() {
713 $s = $this->prefix( $this->mDbkeyform
);
714 $s = str_replace( ' ', '_', $s );
716 $s = wfUrlencode ( $s ) ;
718 # Cleaning up URL to make it look nice -- is this safe?
719 $s = str_replace( '%28', '(', $s );
720 $s = str_replace( '%29', ')', $s );
726 * Get a real URL referring to this title, with interwiki link and
729 * @param string $query an optional query string, not used
730 * for interwiki links
731 * @param string $variant language variant of url (for sr, zh..)
732 * @return string the URL
734 public function getFullURL( $query = '', $variant = false ) {
735 global $wgContLang, $wgServer, $wgRequest;
737 if ( '' == $this->mInterwiki
) {
738 $url = $this->getLocalUrl( $query, $variant );
740 // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
741 // Correct fix would be to move the prepending elsewhere.
742 if ($wgRequest->getVal('action') != 'render') {
743 $url = $wgServer . $url;
746 $baseUrl = $this->getInterwikiLink( $this->mInterwiki
);
748 $namespace = wfUrlencode( $this->getNsText() );
749 if ( '' != $namespace ) {
750 # Can this actually happen? Interwikis shouldn't be parsed.
751 # Yes! It can in interwiki transclusion. But... it probably shouldn't.
754 $url = str_replace( '$1', $namespace . $this->mUrlform
, $baseUrl );
755 $url = wfAppendQuery( $url, $query );
758 # Finally, add the fragment.
759 $url .= $this->getFragmentForURL();
761 wfRunHooks( 'GetFullURL', array( &$this, &$url, $query ) );
766 * Get a URL with no fragment or server name. If this page is generated
767 * with action=render, $wgServer is prepended.
768 * @param string $query an optional query string; if not specified,
769 * $wgArticlePath will be used.
770 * @param string $variant language variant of url (for sr, zh..)
771 * @return string the URL
773 public function getLocalURL( $query = '', $variant = false ) {
774 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
775 global $wgVariantArticlePath, $wgContLang, $wgUser;
777 // internal links should point to same variant as current page (only anonymous users)
778 if($variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn()){
779 $pref = $wgContLang->getPreferredVariant(false);
780 if($pref != $wgContLang->getCode())
784 if ( $this->isExternal() ) {
785 $url = $this->getFullURL();
787 // This is currently only used for edit section links in the
788 // context of interwiki transclusion. In theory we should
789 // append the query to the end of any existing query string,
790 // but interwiki transclusion is already broken in that case.
794 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
795 if ( $query == '' ) {
796 if($variant!=false && $wgContLang->hasVariants()){
797 if($wgVariantArticlePath==false) {
798 $variantArticlePath = "$wgScript?title=$1&variant=$2"; // default
800 $variantArticlePath = $wgVariantArticlePath;
802 $url = str_replace( '$2', urlencode( $variant ), $variantArticlePath );
803 $url = str_replace( '$1', $dbkey, $url );
806 $url = str_replace( '$1', $dbkey, $wgArticlePath );
809 global $wgActionPaths;
812 if( !empty( $wgActionPaths ) &&
813 preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) )
815 $action = urldecode( $matches[2] );
816 if( isset( $wgActionPaths[$action] ) ) {
817 $query = $matches[1];
818 if( isset( $matches[4] ) ) $query .= $matches[4];
819 $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
820 if( $query != '' ) $url .= '?' . $query;
823 if ( $url === false ) {
824 if ( $query == '-' ) {
827 $url = "{$wgScript}?title={$dbkey}&{$query}";
831 // FIXME: this causes breakage in various places when we
832 // actually expected a local URL and end up with dupe prefixes.
833 if ($wgRequest->getVal('action') == 'render') {
834 $url = $wgServer . $url;
837 wfRunHooks( 'GetLocalURL', array( &$this, &$url, $query ) );
842 * Get an HTML-escaped version of the URL form, suitable for
843 * using in a link, without a server name or fragment
844 * @param string $query an optional query string
845 * @return string the URL
847 public function escapeLocalURL( $query = '' ) {
848 return htmlspecialchars( $this->getLocalURL( $query ) );
852 * Get an HTML-escaped version of the URL form, suitable for
853 * using in a link, including the server name and fragment
855 * @return string the URL
856 * @param string $query an optional query string
858 public function escapeFullURL( $query = '' ) {
859 return htmlspecialchars( $this->getFullURL( $query ) );
863 * Get the URL form for an internal link.
864 * - Used in various Squid-related code, in case we have a different
865 * internal hostname for the server from the exposed one.
867 * @param string $query an optional query string
868 * @param string $variant language variant of url (for sr, zh..)
869 * @return string the URL
871 public function getInternalURL( $query = '', $variant = false ) {
872 global $wgInternalServer;
873 $url = $wgInternalServer . $this->getLocalURL( $query, $variant );
874 wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
879 * Get the edit URL for this Title
880 * @return string the URL, or a null string if this is an
883 public function getEditURL() {
884 if ( '' != $this->mInterwiki
) { return ''; }
885 $s = $this->getLocalURL( 'action=edit' );
891 * Get the HTML-escaped displayable text form.
892 * Used for the title field in <a> tags.
893 * @return string the text, including any prefixes
895 public function getEscapedText() {
896 return htmlspecialchars( $this->getPrefixedText() );
900 * Is this Title interwiki?
903 public function isExternal() { return ( '' != $this->mInterwiki
); }
906 * Is this page "semi-protected" - the *only* protection is autoconfirm?
908 * @param string Action to check (default: edit)
911 public function isSemiProtected( $action = 'edit' ) {
912 if( $this->exists() ) {
913 $restrictions = $this->getRestrictions( $action );
914 if( count( $restrictions ) > 0 ) {
915 foreach( $restrictions as $restriction ) {
916 if( strtolower( $restriction ) != 'autoconfirmed' )
925 # If it doesn't exist, it can't be protected
931 * Does the title correspond to a protected article?
932 * @param string $what the action the page is protected from,
933 * by default checks move and edit
936 public function isProtected( $action = '' ) {
937 global $wgRestrictionLevels;
939 # Special pages have inherent protection
940 if( $this->getNamespace() == NS_SPECIAL
)
943 # Check regular protection levels
944 if( $action == 'edit' ||
$action == '' ) {
945 $r = $this->getRestrictions( 'edit' );
946 foreach( $wgRestrictionLevels as $level ) {
947 if( in_array( $level, $r ) && $level != '' ) {
953 if( $action == 'move' ||
$action == '' ) {
954 $r = $this->getRestrictions( 'move' );
955 foreach( $wgRestrictionLevels as $level ) {
956 if( in_array( $level, $r ) && $level != '' ) {
966 * Is $wgUser is watching this page?
969 public function userIsWatching() {
972 if ( is_null( $this->mWatched
) ) {
973 if ( NS_SPECIAL
== $this->mNamespace ||
!$wgUser->isLoggedIn()) {
974 $this->mWatched
= false;
976 $this->mWatched
= $wgUser->isWatched( $this );
979 return $this->mWatched
;
983 * Can $wgUser perform $action on this page?
984 * This skips potentially expensive cascading permission checks.
986 * Suitable for use for nonessential UI controls in common cases, but
987 * _not_ for functional access control.
989 * May provide false positives, but should never provide a false negative.
991 * @param string $action action that permission needs to be checked for
994 public function quickUserCan( $action ) {
995 return $this->userCan( $action, false );
999 * Determines if $wgUser is unable to edit this page because it has been protected
1000 * by $wgNamespaceProtection.
1004 public function isNamespaceProtected() {
1005 global $wgNamespaceProtection, $wgUser;
1006 if( isset( $wgNamespaceProtection[ $this->mNamespace
] ) ) {
1007 foreach( (array)$wgNamespaceProtection[ $this->mNamespace
] as $right ) {
1008 if( $right != '' && !$wgUser->isAllowed( $right ) )
1016 * Can $wgUser perform $action on this page?
1017 * @param string $action action that permission needs to be checked for
1018 * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
1021 public function userCan( $action, $doExpensiveQueries = true ) {
1022 $fname = 'Title::userCan';
1023 wfProfileIn( $fname );
1028 wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) );
1029 if ( $result !== null ) {
1030 wfProfileOut( $fname );
1034 if( NS_SPECIAL
== $this->mNamespace
) {
1035 wfProfileOut( $fname );
1039 if ( $this->isNamespaceProtected() ) {
1040 wfProfileOut( $fname );
1044 if( $this->mDbkeyform
== '_' ) {
1045 # FIXME: Is this necessary? Shouldn't be allowed anyway...
1046 wfProfileOut( $fname );
1050 # protect css/js subpages of user pages
1051 # XXX: this might be better using restrictions
1052 # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
1053 if( $this->isCssJsSubpage()
1054 && !$wgUser->isAllowed('editinterface')
1055 && !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) ) {
1056 wfProfileOut( $fname );
1060 if ( $doExpensiveQueries && !$this->isCssJsSubpage() ) {
1061 # We /could/ use the protection level on the source page, but it's fairly ugly
1062 # as we have to establish a precedence hierarchy for pages included by multiple
1063 # cascade-protected pages. So just restrict it to people with 'protect' permission,
1064 # as they could remove the protection anyway.
1065 list( $cascadingSources, $restrictions ) = $this->getCascadeProtectionSources();
1066 # Cascading protection depends on more than this page...
1067 # Several cascading protected pages may include this page...
1068 # Check each cascading level
1069 # This is only for protection restrictions, not for all actions
1070 if( $cascadingSources > 0 && isset($restrictions[$action]) ) {
1071 foreach( $restrictions[$action] as $right ) {
1072 $right = ( $right == 'sysop' ) ?
'protect' : $right;
1073 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1074 wfProfileOut( $fname );
1081 foreach( $this->getRestrictions($action) as $right ) {
1082 // Backwards compatibility, rewrite sysop -> protect
1083 if ( $right == 'sysop' ) {
1086 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1087 wfProfileOut( $fname );
1092 if( $action == 'move' &&
1093 !( $this->isMovable() && $wgUser->isAllowed( 'move' ) ) ) {
1094 wfProfileOut( $fname );
1098 if( $action == 'create' ) {
1099 if( ( $this->isTalkPage() && !$wgUser->isAllowed( 'createtalk' ) ) ||
1100 ( !$this->isTalkPage() && !$wgUser->isAllowed( 'createpage' ) ) ) {
1101 wfProfileOut( $fname );
1106 if( $action == 'edit' && !$wgUser->isAllowed( 'edit' ) ) {
1107 wfProfileOut( $fname );
1111 wfProfileOut( $fname );
1116 * Can $wgUser edit this page?
1118 * @deprecated use userCan('edit')
1120 public function userCanEdit( $doExpensiveQueries = true ) {
1121 return $this->userCan( 'edit', $doExpensiveQueries );
1125 * Can $wgUser create this page?
1127 * @deprecated use userCan('create')
1129 public function userCanCreate( $doExpensiveQueries = true ) {
1130 return $this->userCan( 'create', $doExpensiveQueries );
1134 * Can $wgUser move this page?
1136 * @deprecated use userCan('move')
1138 public function userCanMove( $doExpensiveQueries = true ) {
1139 return $this->userCan( 'move', $doExpensiveQueries );
1143 * Would anybody with sufficient privileges be able to move this page?
1144 * Some pages just aren't movable.
1148 public function isMovable() {
1149 return Namespace::isMovable( $this->getNamespace() )
1150 && $this->getInterwiki() == '';
1154 * Can $wgUser read this page?
1156 * @todo fold these checks into userCan()
1158 public function userCanRead() {
1162 wfRunHooks( 'userCan', array( &$this, &$wgUser, 'read', &$result ) );
1163 if ( $result !== null ) {
1167 if( $wgUser->isAllowed( 'read' ) ) {
1170 global $wgWhitelistRead;
1173 * Always grant access to the login page.
1174 * Even anons need to be able to log in.
1176 if( $this->isSpecial( 'Userlogin' ) ||
$this->isSpecial( 'Resetpass' ) ) {
1181 * Check for explicit whitelisting
1183 $name = $this->getPrefixedText();
1184 if( $wgWhitelistRead && in_array( $name, $wgWhitelistRead, true ) )
1188 * Old settings might have the title prefixed with
1189 * a colon for main-namespace pages
1191 if( $wgWhitelistRead && $this->getNamespace() == NS_MAIN
) {
1192 if( in_array( ':' . $name, $wgWhitelistRead ) )
1197 * If it's a special page, ditch the subpage bit
1200 if( $this->getNamespace() == NS_SPECIAL
) {
1201 $name = $this->getText();
1202 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $name );
1203 $pure = SpecialPage
::getTitleFor( $name )->getPrefixedText();
1204 if( in_array( $pure, $wgWhitelistRead, true ) )
1213 * Is this a talk page of some sort?
1216 public function isTalkPage() {
1217 return Namespace::isTalk( $this->getNamespace() );
1221 * Is this a subpage?
1224 public function isSubpage() {
1225 global $wgNamespacesWithSubpages;
1227 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) ) {
1228 return ( strpos( $this->getText(), '/' ) !== false && $wgNamespacesWithSubpages[ $this->mNamespace
] == true );
1235 * Could this page contain custom CSS or JavaScript, based
1240 public function isCssOrJsPage() {
1241 return $this->mNamespace
== NS_MEDIAWIKI
1242 && preg_match( '!\.(?:css|js)$!u', $this->mTextform
) > 0;
1246 * Is this a .css or .js subpage of a user page?
1249 public function isCssJsSubpage() {
1250 return ( NS_USER
== $this->mNamespace
and preg_match("/\\/.*\\.(?:css|js)$/", $this->mTextform
) );
1253 * Is this a *valid* .css or .js subpage of a user page?
1254 * Check that the corresponding skin exists
1256 public function isValidCssJsSubpage() {
1257 if ( $this->isCssJsSubpage() ) {
1258 $skinNames = Skin
::getSkinNames();
1259 return array_key_exists( $this->getSkinFromCssJsSubpage(), $skinNames );
1265 * Trim down a .css or .js subpage title to get the corresponding skin name
1267 public function getSkinFromCssJsSubpage() {
1268 $subpage = explode( '/', $this->mTextform
);
1269 $subpage = $subpage[ count( $subpage ) - 1 ];
1270 return( str_replace( array( '.css', '.js' ), array( '', '' ), $subpage ) );
1273 * Is this a .css subpage of a user page?
1276 public function isCssSubpage() {
1277 return ( NS_USER
== $this->mNamespace
and preg_match("/\\/.*\\.css$/", $this->mTextform
) );
1280 * Is this a .js subpage of a user page?
1283 public function isJsSubpage() {
1284 return ( NS_USER
== $this->mNamespace
and preg_match("/\\/.*\\.js$/", $this->mTextform
) );
1287 * Protect css/js subpages of user pages: can $wgUser edit
1291 * @todo XXX: this might be better using restrictions
1293 public function userCanEditCssJsSubpage() {
1295 return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) );
1299 * Cascading protection: Return true if cascading restrictions apply to this page, false if not.
1301 * @return bool If the page is subject to cascading restrictions.
1303 public function isCascadeProtected() {
1304 list( $sources, $restrictions ) = $this->getCascadeProtectionSources( false );
1305 return ( $sources > 0 );
1309 * Cascading protection: Get the source of any cascading restrictions on this page.
1311 * @param $get_pages bool Whether or not to retrieve the actual pages that the restrictions have come from.
1312 * @return array( mixed title array, restriction array)
1313 * 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.
1314 * The restriction array is an array of each type, each of which contains an array of unique groups
1316 public function getCascadeProtectionSources( $get_pages = true ) {
1317 global $wgEnableCascadingProtection, $wgRestrictionTypes;
1319 # Define our dimension of restrictions types
1320 $pagerestrictions = array();
1321 foreach( $wgRestrictionTypes as $action )
1322 $pagerestrictions[$action] = array();
1324 if (!$wgEnableCascadingProtection)
1325 return array( false, $pagerestrictions );
1327 if ( isset( $this->mCascadeSources
) && $get_pages ) {
1328 return array( $this->mCascadeSources
, $this->mCascadingRestrictions
);
1329 } else if ( isset( $this->mHasCascadingRestrictions
) && !$get_pages ) {
1330 return array( $this->mHasCascadingRestrictions
, $pagerestrictions );
1333 wfProfileIn( __METHOD__
);
1335 $dbr = wfGetDb( DB_SLAVE
);
1337 if ( $this->getNamespace() == NS_IMAGE
) {
1338 $tables = array ('imagelinks', 'page_restrictions');
1339 $where_clauses = array(
1340 'il_to' => $this->getDBkey(),
1342 'pr_cascade' => 1 );
1344 $tables = array ('templatelinks', 'page_restrictions');
1345 $where_clauses = array(
1346 'tl_namespace' => $this->getNamespace(),
1347 'tl_title' => $this->getDBkey(),
1349 'pr_cascade' => 1 );
1353 $cols = array('pr_page', 'page_namespace', 'page_title', 'pr_expiry', 'pr_type', 'pr_level' );
1354 $where_clauses[] = 'page_id=pr_page';
1357 $cols = array( 'pr_expiry' );
1360 $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__
);
1362 $sources = $get_pages ?
array() : false;
1363 $now = wfTimestampNow();
1364 $purgeExpired = false;
1366 while( $row = $dbr->fetchObject( $res ) ) {
1367 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
1368 if( $expiry > $now ) {
1370 $page_id = $row->pr_page
;
1371 $page_ns = $row->page_namespace
;
1372 $page_title = $row->page_title
;
1373 $sources[$page_id] = Title
::makeTitle($page_ns, $page_title);
1374 # Add groups needed for each restriction type if its not already there
1375 # Make sure this restriction type still exists
1376 if ( isset($pagerestrictions[$row->pr_type
]) && !in_array($row->pr_level
, $pagerestrictions[$row->pr_type
]) ) {
1377 $pagerestrictions[$row->pr_type
][]=$row->pr_level
;
1383 // Trigger lazy purge of expired restrictions from the db
1384 $purgeExpired = true;
1387 if( $purgeExpired ) {
1388 Title
::purgeExpiredRestrictions();
1391 wfProfileOut( __METHOD__
);
1394 $this->mCascadeSources
= $sources;
1395 $this->mCascadingRestrictions
= $pagerestrictions;
1397 $this->mHasCascadingRestrictions
= $sources;
1400 return array( $sources, $pagerestrictions );
1403 function areRestrictionsCascading() {
1404 if (!$this->mRestrictionsLoaded
) {
1405 $this->loadRestrictions();
1408 return $this->mCascadeRestriction
;
1412 * Loads a string into mRestrictions array
1413 * @param resource $res restrictions as an SQL result.
1415 private function loadRestrictionsFromRow( $res, $oldFashionedRestrictions = NULL ) {
1416 $dbr = wfGetDb( DB_SLAVE
);
1418 $this->mRestrictions
['edit'] = array();
1419 $this->mRestrictions
['move'] = array();
1421 # Backwards-compatibility: also load the restrictions from the page record (old format).
1423 if ( $oldFashionedRestrictions == NULL ) {
1424 $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleId() ), __METHOD__
);
1427 if ($oldFashionedRestrictions != '') {
1429 foreach( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) {
1430 $temp = explode( '=', trim( $restrict ) );
1431 if(count($temp) == 1) {
1432 // old old format should be treated as edit/move restriction
1433 $this->mRestrictions
["edit"] = explode( ',', trim( $temp[0] ) );
1434 $this->mRestrictions
["move"] = explode( ',', trim( $temp[0] ) );
1436 $this->mRestrictions
[$temp[0]] = explode( ',', trim( $temp[1] ) );
1440 $this->mOldRestrictions
= true;
1441 $this->mCascadeRestriction
= false;
1442 $this->mRestrictionsExpiry
= Block
::decodeExpiry('');
1446 if( $dbr->numRows( $res ) ) {
1447 # Current system - load second to make them override.
1448 $now = wfTimestampNow();
1449 $purgeExpired = false;
1451 while ($row = $dbr->fetchObject( $res ) ) {
1452 # Cycle through all the restrictions.
1454 // This code should be refactored, now that it's being used more generally,
1455 // But I don't really see any harm in leaving it in Block for now -werdna
1456 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
1458 // Only apply the restrictions if they haven't expired!
1459 if ( !$expiry ||
$expiry > $now ) {
1460 $this->mRestrictionsExpiry
= $expiry;
1461 $this->mRestrictions
[$row->pr_type
] = explode( ',', trim( $row->pr_level
) );
1463 $this->mCascadeRestriction |
= $row->pr_cascade
;
1465 // Trigger a lazy purge of expired restrictions
1466 $purgeExpired = true;
1470 if( $purgeExpired ) {
1471 Title
::purgeExpiredRestrictions();
1475 $this->mRestrictionsLoaded
= true;
1478 public function loadRestrictions( $oldFashionedRestrictions = NULL ) {
1479 if( !$this->mRestrictionsLoaded
) {
1480 $dbr = wfGetDB( DB_SLAVE
);
1482 $res = $dbr->select( 'page_restrictions', '*',
1483 array ( 'pr_page' => $this->getArticleId() ), __METHOD__
);
1485 $this->loadRestrictionsFromRow( $res, $oldFashionedRestrictions );
1490 * Purge expired restrictions from the page_restrictions table
1492 static function purgeExpiredRestrictions() {
1493 $dbw = wfGetDB( DB_MASTER
);
1494 $dbw->delete( 'page_restrictions',
1495 array( 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
1500 * 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 public 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
1522 public function isDeleted() {
1523 $fname = 'Title::isDeleted';
1524 if ( $this->getNamespace() < 0 ) {
1527 $dbr = wfGetDB( DB_SLAVE
);
1528 $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
1529 'ar_title' => $this->getDBkey() ), $fname );
1530 if( $this->getNamespace() == NS_IMAGE
) {
1531 $n +
= $dbr->selectField( 'filearchive', 'COUNT(*)',
1532 array( 'fa_name' => $this->getDBkey() ), $fname );
1539 * Get the article ID for this Title from the link cache,
1540 * adding it if necessary
1541 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select
1543 * @return int the ID
1545 public function getArticleID( $flags = 0 ) {
1546 $linkCache =& LinkCache
::singleton();
1547 if ( $flags & GAID_FOR_UPDATE
) {
1548 $oldUpdate = $linkCache->forUpdate( true );
1549 $this->mArticleID
= $linkCache->addLinkObj( $this );
1550 $linkCache->forUpdate( $oldUpdate );
1552 if ( -1 == $this->mArticleID
) {
1553 $this->mArticleID
= $linkCache->addLinkObj( $this );
1556 return $this->mArticleID
;
1559 public function getLatestRevID() {
1560 if ($this->mLatestID
!== false)
1561 return $this->mLatestID
;
1563 $db = wfGetDB(DB_SLAVE
);
1564 return $this->mLatestID
= $db->selectField( 'revision',
1566 array('rev_page' => $this->getArticleID()),
1567 'Title::getLatestRevID' );
1571 * This clears some fields in this object, and clears any associated
1572 * keys in the "bad links" section of the link cache.
1574 * - This is called from Article::insertNewArticle() to allow
1575 * loading of the new page_id. It's also called from
1576 * Article::doDeleteArticle()
1578 * @param int $newid the new Article ID
1580 public function resetArticleID( $newid ) {
1581 $linkCache =& LinkCache
::singleton();
1582 $linkCache->clearBadLink( $this->getPrefixedDBkey() );
1584 if ( 0 == $newid ) { $this->mArticleID
= -1; }
1585 else { $this->mArticleID
= $newid; }
1586 $this->mRestrictionsLoaded
= false;
1587 $this->mRestrictions
= array();
1591 * Updates page_touched for this page; called from LinksUpdate.php
1592 * @return bool true if the update succeded
1594 public function invalidateCache() {
1595 global $wgUseFileCache;
1597 if ( wfReadOnly() ) {
1601 $dbw = wfGetDB( DB_MASTER
);
1602 $success = $dbw->update( 'page',
1604 'page_touched' => $dbw->timestamp()
1605 ), array( /* WHERE */
1606 'page_namespace' => $this->getNamespace() ,
1607 'page_title' => $this->getDBkey()
1608 ), 'Title::invalidateCache'
1611 if ($wgUseFileCache) {
1612 $cache = new HTMLFileCache($this);
1613 @unlink
($cache->fileCacheName());
1620 * Prefix some arbitrary text with the namespace or interwiki prefix
1623 * @param string $name the text
1624 * @return string the prefixed text
1627 /* private */ function prefix( $name ) {
1629 if ( '' != $this->mInterwiki
) {
1630 $p = $this->mInterwiki
. ':';
1632 if ( 0 != $this->mNamespace
) {
1633 $p .= $this->getNsText() . ':';
1639 * Secure and split - main initialisation function for this object
1641 * Assumes that mDbkeyform has been set, and is urldecoded
1642 * and uses underscores, but not otherwise munged. This function
1643 * removes illegal characters, splits off the interwiki and
1644 * namespace prefixes, sets the other forms, and canonicalizes
1646 * @return bool true on success
1648 private function secureAndSplit() {
1649 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
1652 static $rxTc = false;
1654 # % is needed as well
1655 $rxTc = '/[^' . Title
::legalChars() . ']|%[0-9A-Fa-f]{2}/S';
1658 $this->mInterwiki
= $this->mFragment
= '';
1659 $this->mNamespace
= $this->mDefaultNamespace
; # Usually NS_MAIN
1661 $dbkey = $this->mDbkeyform
;
1663 # Strip Unicode bidi override characters.
1664 # Sometimes they slip into cut-n-pasted page titles, where the
1665 # override chars get included in list displays.
1666 $dbkey = str_replace( "\xE2\x80\x8E", '', $dbkey ); // 200E LEFT-TO-RIGHT MARK
1667 $dbkey = str_replace( "\xE2\x80\x8F", '', $dbkey ); // 200F RIGHT-TO-LEFT MARK
1669 # Clean up whitespace
1671 $dbkey = preg_replace( '/[ _]+/', '_', $dbkey );
1672 $dbkey = trim( $dbkey, '_' );
1674 if ( '' == $dbkey ) {
1678 if( false !== strpos( $dbkey, UTF8_REPLACEMENT
) ) {
1679 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
1683 $this->mDbkeyform
= $dbkey;
1685 # Initial colon indicates main namespace rather than specified default
1686 # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
1687 if ( ':' == $dbkey{0} ) {
1688 $this->mNamespace
= NS_MAIN
;
1689 $dbkey = substr( $dbkey, 1 ); # remove the colon but continue processing
1690 $dbkey = trim( $dbkey, '_' ); # remove any subsequent whitespace
1693 # Namespace or interwiki prefix
1697 if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $dbkey, $m ) ) {
1699 if ( $ns = $wgContLang->getNsIndex( $p )) {
1700 # Ordinary namespace
1702 $this->mNamespace
= $ns;
1703 } elseif( $this->getInterwikiLink( $p ) ) {
1705 # Can't make a local interwiki link to an interwiki link.
1706 # That's just crazy!
1712 $this->mInterwiki
= $wgContLang->lc( $p );
1714 # Redundant interwiki prefix to the local wiki
1715 if ( 0 == strcasecmp( $this->mInterwiki
, $wgLocalInterwiki ) ) {
1716 if( $dbkey == '' ) {
1717 # Can't have an empty self-link
1720 $this->mInterwiki
= '';
1722 # Do another namespace split...
1726 # If there's an initial colon after the interwiki, that also
1727 # resets the default namespace
1728 if ( $dbkey !== '' && $dbkey[0] == ':' ) {
1729 $this->mNamespace
= NS_MAIN
;
1730 $dbkey = substr( $dbkey, 1 );
1733 # If there's no recognized interwiki or namespace,
1734 # then let the colon expression be part of the title.
1739 # We already know that some pages won't be in the database!
1741 if ( '' != $this->mInterwiki || NS_SPECIAL
== $this->mNamespace
) {
1742 $this->mArticleID
= 0;
1744 $fragment = strstr( $dbkey, '#' );
1745 if ( false !== $fragment ) {
1746 $this->setFragment( $fragment );
1747 $dbkey = substr( $dbkey, 0, strlen( $dbkey ) - strlen( $fragment ) );
1748 # remove whitespace again: prevents "Foo_bar_#"
1749 # becoming "Foo_bar_"
1750 $dbkey = preg_replace( '/_*$/', '', $dbkey );
1753 # Reject illegal characters.
1755 if( preg_match( $rxTc, $dbkey ) ) {
1760 * Pages with "/./" or "/../" appearing in the URLs will
1761 * often be unreachable due to the way web browsers deal
1762 * with 'relative' URLs. Forbid them explicitly.
1764 if ( strpos( $dbkey, '.' ) !== false &&
1765 ( $dbkey === '.' ||
$dbkey === '..' ||
1766 strpos( $dbkey, './' ) === 0 ||
1767 strpos( $dbkey, '../' ) === 0 ||
1768 strpos( $dbkey, '/./' ) !== false ||
1769 strpos( $dbkey, '/../' ) !== false ) )
1775 * Magic tilde sequences? Nu-uh!
1777 if( strpos( $dbkey, '~~~' ) !== false ) {
1782 * Limit the size of titles to 255 bytes.
1783 * This is typically the size of the underlying database field.
1784 * We make an exception for special pages, which don't need to be stored
1785 * in the database, and may edge over 255 bytes due to subpage syntax
1786 * for long titles, e.g. [[Special:Block/Long name]]
1788 if ( ( $this->mNamespace
!= NS_SPECIAL
&& strlen( $dbkey ) > 255 ) ||
1789 strlen( $dbkey ) > 512 )
1795 * Normally, all wiki links are forced to have
1796 * an initial capital letter so [[foo]] and [[Foo]]
1797 * point to the same place.
1799 * Don't force it for interwikis, since the other
1800 * site might be case-sensitive.
1802 $this->mUserCaseDBKey
= $dbkey;
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 * @todo clarify whether access is supposed to be public (was marked as "kind of public")
1841 public 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
1849 public function getTalkPage() {
1850 return Title
::makeTitle( Namespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
1854 * Get a title object associated with the subject page of this
1857 * @return Title the object for the subject page
1859 public function getSubjectPage() {
1860 return Title
::makeTitle( Namespace::getSubject( $this->getNamespace() ), $this->getDBkey() );
1864 * Get an array of Title objects linking to this Title
1865 * Also stores the IDs in the link cache.
1867 * WARNING: do not use this function on arbitrary user-supplied titles!
1868 * On heavily-used templates it will max out the memory.
1870 * @param string $options may be FOR UPDATE
1871 * @return array the Title objects linking here
1873 public function getLinksTo( $options = '', $table = 'pagelinks', $prefix = 'pl' ) {
1874 $linkCache =& LinkCache
::singleton();
1877 $db = wfGetDB( DB_MASTER
);
1879 $db = wfGetDB( DB_SLAVE
);
1882 $res = $db->select( array( 'page', $table ),
1883 array( 'page_namespace', 'page_title', 'page_id' ),
1885 "{$prefix}_from=page_id",
1886 "{$prefix}_namespace" => $this->getNamespace(),
1887 "{$prefix}_title" => $this->getDbKey() ),
1888 'Title::getLinksTo',
1892 if ( $db->numRows( $res ) ) {
1893 while ( $row = $db->fetchObject( $res ) ) {
1894 if ( $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
) ) {
1895 $linkCache->addGoodLinkObj( $row->page_id
, $titleObj );
1896 $retVal[] = $titleObj;
1900 $db->freeResult( $res );
1905 * Get an array of Title objects using this Title as a template
1906 * Also stores the IDs in the link cache.
1908 * WARNING: do not use this function on arbitrary user-supplied titles!
1909 * On heavily-used templates it will max out the memory.
1911 * @param string $options may be FOR UPDATE
1912 * @return array the Title objects linking here
1914 public function getTemplateLinksTo( $options = '' ) {
1915 return $this->getLinksTo( $options, 'templatelinks', 'tl' );
1919 * Get an array of Title objects referring to non-existent articles linked from this page
1921 * @param string $options may be FOR UPDATE
1922 * @return array the Title objects
1924 public function getBrokenLinksFrom( $options = '' ) {
1926 $db = wfGetDB( DB_MASTER
);
1928 $db = wfGetDB( DB_SLAVE
);
1931 $res = $db->safeQuery(
1932 "SELECT pl_namespace, pl_title
1935 ON pl_namespace=page_namespace
1936 AND pl_title=page_title
1938 AND page_namespace IS NULL
1940 $db->tableName( 'pagelinks' ),
1941 $db->tableName( 'page' ),
1942 $this->getArticleId(),
1946 if ( $db->numRows( $res ) ) {
1947 while ( $row = $db->fetchObject( $res ) ) {
1948 $retVal[] = Title
::makeTitle( $row->pl_namespace
, $row->pl_title
);
1951 $db->freeResult( $res );
1957 * Get a list of URLs to purge from the Squid cache when this
1960 * @return array the URLs
1962 public function getSquidURLs() {
1966 $this->getInternalURL(),
1967 $this->getInternalURL( 'action=history' )
1970 // purge variant urls as well
1971 if($wgContLang->hasVariants()){
1972 $variants = $wgContLang->getVariants();
1973 foreach($variants as $vCode){
1974 if($vCode==$wgContLang->getCode()) continue; // we don't want default variant
1975 $urls[] = $this->getInternalURL('',$vCode);
1982 public function purgeSquid() {
1984 if ( $wgUseSquid ) {
1985 $urls = $this->getSquidURLs();
1986 $u = new SquidUpdate( $urls );
1992 * Move this page without authentication
1993 * @param Title &$nt the new page Title
1995 public function moveNoAuth( &$nt ) {
1996 return $this->moveTo( $nt, false );
2000 * Check whether a given move operation would be valid.
2001 * Returns true if ok, or a message key string for an error message
2002 * if invalid. (Scarrrrry ugly interface this.)
2003 * @param Title &$nt the new title
2004 * @param bool $auth indicates whether $wgUser's permissions
2006 * @return mixed true on success, message name on failure
2008 public function isValidMoveOperation( &$nt, $auth = true ) {
2009 if( !$this or !$nt ) {
2010 return 'badtitletext';
2012 if( $this->equals( $nt ) ) {
2015 if( !$this->isMovable() ||
!$nt->isMovable() ) {
2016 return 'immobile_namespace';
2019 $oldid = $this->getArticleID();
2020 $newid = $nt->getArticleID();
2022 if ( strlen( $nt->getDBkey() ) < 1 ) {
2023 return 'articleexists';
2025 if ( ( '' == $this->getDBkey() ) ||
2027 ( '' == $nt->getDBkey() ) ) {
2028 return 'badarticleerror';
2032 !$this->userCan( 'edit' ) ||
!$nt->userCan( 'edit' ) ||
2033 !$this->userCan( 'move' ) ||
!$nt->userCan( 'move' ) ) ) {
2034 return 'protectedpage';
2037 # The move is allowed only if (1) the target doesn't exist, or
2038 # (2) the target is a redirect to the source, and has no history
2039 # (so we can undo bad moves right after they're done).
2041 if ( 0 != $newid ) { # Target exists; check for validity
2042 if ( ! $this->isValidMoveTarget( $nt ) ) {
2043 return 'articleexists';
2050 * Move a title to a new location
2051 * @param Title &$nt the new title
2052 * @param bool $auth indicates whether $wgUser's permissions
2054 * @return mixed true on success, message name on failure
2056 public function moveTo( &$nt, $auth = true, $reason = '' ) {
2057 $err = $this->isValidMoveOperation( $nt, $auth );
2058 if( is_string( $err ) ) {
2062 $pageid = $this->getArticleID();
2063 if( $nt->exists() ) {
2064 $this->moveOverExistingRedirect( $nt, $reason );
2065 $pageCountChange = 0;
2066 } else { # Target didn't exist, do normal move.
2067 $this->moveToNewTitle( $nt, $reason );
2068 $pageCountChange = 1;
2070 $redirid = $this->getArticleID();
2072 # Fixing category links (those without piped 'alternate' names) to be sorted under the new title
2073 $dbw = wfGetDB( DB_MASTER
);
2074 $categorylinks = $dbw->tableName( 'categorylinks' );
2075 $sql = "UPDATE $categorylinks SET cl_sortkey=" . $dbw->addQuotes( $nt->getPrefixedText() ) .
2076 " WHERE cl_from=" . $dbw->addQuotes( $pageid ) .
2077 " AND cl_sortkey=" . $dbw->addQuotes( $this->getPrefixedText() );
2078 $dbw->query( $sql, 'SpecialMovepage::doSubmit' );
2082 $oldnamespace = $this->getNamespace() & ~
1;
2083 $newnamespace = $nt->getNamespace() & ~
1;
2084 $oldtitle = $this->getDBkey();
2085 $newtitle = $nt->getDBkey();
2087 if( $oldnamespace != $newnamespace ||
$oldtitle != $newtitle ) {
2088 WatchedItem
::duplicateEntries( $this, $nt );
2091 # Update search engine
2092 $u = new SearchUpdate( $pageid, $nt->getPrefixedDBkey() );
2094 $u = new SearchUpdate( $redirid, $this->getPrefixedDBkey(), '' );
2098 if( $this->isContentPage() && !$nt->isContentPage() ) {
2099 # No longer a content page
2100 # Not viewed, edited, removing
2101 $u = new SiteStatsUpdate( 0, 1, -1, $pageCountChange );
2102 } elseif( !$this->isContentPage() && $nt->isContentPage() ) {
2103 # Now a content page
2104 # Not viewed, edited, adding
2105 $u = new SiteStatsUpdate( 0, 1, +
1, $pageCountChange );
2106 } elseif( $pageCountChange ) {
2108 $u = new SiteStatsUpdate( 0, 0, 0, 1 );
2117 wfRunHooks( 'TitleMoveComplete', array( &$this, &$nt, &$wgUser, $pageid, $redirid ) );
2122 * Move page to a title which is at present a redirect to the
2125 * @param Title &$nt the page to move to, which should currently
2128 private function moveOverExistingRedirect( &$nt, $reason = '' ) {
2130 $fname = 'Title::moveOverExistingRedirect';
2131 $comment = wfMsgForContent( '1movedto2_redir', $this->getPrefixedText(), $nt->getPrefixedText() );
2134 $comment .= ": $reason";
2137 $now = wfTimestampNow();
2138 $newid = $nt->getArticleID();
2139 $oldid = $this->getArticleID();
2140 $dbw = wfGetDB( DB_MASTER
);
2141 $linkCache =& LinkCache
::singleton();
2143 # Delete the old redirect. We don't save it to history since
2144 # by definition if we've got here it's rather uninteresting.
2145 # We have to remove it so that the next step doesn't trigger
2146 # a conflict on the unique namespace+title index...
2147 $dbw->delete( 'page', array( 'page_id' => $newid ), $fname );
2149 # Save a null revision in the page's history notifying of the move
2150 $nullRevision = Revision
::newNullRevision( $dbw, $oldid, $comment, true );
2151 $nullRevId = $nullRevision->insertOn( $dbw );
2153 # Change the name of the target page:
2154 $dbw->update( 'page',
2156 'page_touched' => $dbw->timestamp($now),
2157 'page_namespace' => $nt->getNamespace(),
2158 'page_title' => $nt->getDBkey(),
2159 'page_latest' => $nullRevId,
2161 /* WHERE */ array( 'page_id' => $oldid ),
2164 $linkCache->clearLink( $nt->getPrefixedDBkey() );
2166 # Recreate the redirect, this time in the other direction.
2167 $mwRedir = MagicWord
::get( 'redirect' );
2168 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
2169 $redirectArticle = new Article( $this );
2170 $newid = $redirectArticle->insertOn( $dbw );
2171 $redirectRevision = new Revision( array(
2173 'comment' => $comment,
2174 'text' => $redirectText ) );
2175 $redirectRevision->insertOn( $dbw );
2176 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
2177 $linkCache->clearLink( $this->getPrefixedDBkey() );
2180 $log = new LogPage( 'move' );
2181 $log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText() ) );
2183 # Now, we record the link from the redirect to the new title.
2184 # It should have no other outgoing links...
2185 $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), $fname );
2186 $dbw->insert( 'pagelinks',
2188 'pl_from' => $newid,
2189 'pl_namespace' => $nt->getNamespace(),
2190 'pl_title' => $nt->getDbKey() ),
2194 if ( $wgUseSquid ) {
2195 $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
2196 $u = new SquidUpdate( $urls );
2202 * Move page to non-existing title.
2203 * @param Title &$nt the new Title
2205 private function moveToNewTitle( &$nt, $reason = '' ) {
2207 $fname = 'MovePageForm::moveToNewTitle';
2208 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
2210 $comment .= ": $reason";
2213 $newid = $nt->getArticleID();
2214 $oldid = $this->getArticleID();
2215 $dbw = wfGetDB( DB_MASTER
);
2216 $now = $dbw->timestamp();
2217 $linkCache =& LinkCache
::singleton();
2219 # Save a null revision in the page's history notifying of the move
2220 $nullRevision = Revision
::newNullRevision( $dbw, $oldid, $comment, true );
2221 $nullRevId = $nullRevision->insertOn( $dbw );
2224 $dbw->update( 'page',
2226 'page_touched' => $now,
2227 'page_namespace' => $nt->getNamespace(),
2228 'page_title' => $nt->getDBkey(),
2229 'page_latest' => $nullRevId,
2231 /* WHERE */ array( 'page_id' => $oldid ),
2235 $linkCache->clearLink( $nt->getPrefixedDBkey() );
2238 $mwRedir = MagicWord
::get( 'redirect' );
2239 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
2240 $redirectArticle = new Article( $this );
2241 $newid = $redirectArticle->insertOn( $dbw );
2242 $redirectRevision = new Revision( array(
2244 'comment' => $comment,
2245 'text' => $redirectText ) );
2246 $redirectRevision->insertOn( $dbw );
2247 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
2248 $linkCache->clearLink( $this->getPrefixedDBkey() );
2251 $log = new LogPage( 'move' );
2252 $log->addEntry( 'move', $this, $reason, array( 1 => $nt->getPrefixedText()) );
2254 # Purge caches as per article creation
2255 Article
::onArticleCreate( $nt );
2257 # Record the just-created redirect's linking to the page
2258 $dbw->insert( 'pagelinks',
2260 'pl_from' => $newid,
2261 'pl_namespace' => $nt->getNamespace(),
2262 'pl_title' => $nt->getDBkey() ),
2265 # Purge old title from squid
2266 # The new title, and links to the new title, are purged in Article::onArticleCreate()
2267 $this->purgeSquid();
2271 * Checks if $this can be moved to a given Title
2272 * - Selects for update, so don't call it unless you mean business
2274 * @param Title &$nt the new title to check
2276 public function isValidMoveTarget( $nt ) {
2278 $fname = 'Title::isValidMoveTarget';
2279 $dbw = wfGetDB( DB_MASTER
);
2282 $id = $nt->getArticleID();
2283 $obj = $dbw->selectRow( array( 'page', 'revision', 'text'),
2284 array( 'page_is_redirect','old_text','old_flags' ),
2285 array( 'page_id' => $id, 'page_latest=rev_id', 'rev_text_id=old_id' ),
2286 $fname, 'FOR UPDATE' );
2288 if ( !$obj ||
0 == $obj->page_is_redirect
) {
2290 wfDebug( __METHOD__
. ": not a redirect\n" );
2293 $text = Revision
::getRevisionText( $obj );
2295 # Does the redirect point to the source?
2296 # Or is it a broken self-redirect, usually caused by namespace collisions?
2298 if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $text, $m ) ) {
2299 $redirTitle = Title
::newFromText( $m[1] );
2300 if( !is_object( $redirTitle ) ||
2301 ( $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() &&
2302 $redirTitle->getPrefixedDBkey() != $nt->getPrefixedDBkey() ) ) {
2303 wfDebug( __METHOD__
. ": redirect points to other page\n" );
2308 wfDebug( __METHOD__
. ": failsafe\n" );
2312 # Does the article have a history?
2313 $row = $dbw->selectRow( array( 'page', 'revision'),
2315 array( 'page_namespace' => $nt->getNamespace(),
2316 'page_title' => $nt->getDBkey(),
2317 'page_id=rev_page AND page_latest != rev_id'
2318 ), $fname, 'FOR UPDATE'
2321 # Return true if there was no history
2322 return $row === false;
2326 * Can this title be added to a user's watchlist?
2330 public function isWatchable() {
2331 return !$this->isExternal()
2332 && Namespace::isWatchable( $this->getNamespace() );
2336 * Get categories to which this Title belongs and return an array of
2337 * categories' names.
2339 * @return array an array of parents in the form:
2340 * $parent => $currentarticle
2342 public function getParentCategories() {
2345 $titlekey = $this->getArticleId();
2346 $dbr = wfGetDB( DB_SLAVE
);
2347 $categorylinks = $dbr->tableName( 'categorylinks' );
2350 $sql = "SELECT * FROM $categorylinks"
2351 ." WHERE cl_from='$titlekey'"
2352 ." AND cl_from <> '0'"
2353 ." ORDER BY cl_sortkey";
2355 $res = $dbr->query ( $sql ) ;
2357 if($dbr->numRows($res) > 0) {
2358 while ( $x = $dbr->fetchObject ( $res ) )
2359 //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
2360 $data[$wgContLang->getNSText ( NS_CATEGORY
).':'.$x->cl_to
] = $this->getFullText();
2361 $dbr->freeResult ( $res ) ;
2369 * Get a tree of parent categories
2370 * @param array $children an array with the children in the keys, to check for circular refs
2373 public function getParentCategoryTree( $children = array() ) {
2374 $parents = $this->getParentCategories();
2376 if($parents != '') {
2377 foreach($parents as $parent => $current) {
2378 if ( array_key_exists( $parent, $children ) ) {
2379 # Circular reference
2380 $stack[$parent] = array();
2382 $nt = Title
::newFromText($parent);
2384 $stack[$parent] = $nt->getParentCategoryTree( $children +
array($parent => 1) );
2396 * Get an associative array for selecting this title from
2401 public function pageCond() {
2402 return array( 'page_namespace' => $this->mNamespace
, 'page_title' => $this->mDbkeyform
);
2406 * Get the revision ID of the previous revision
2408 * @param integer $revision Revision ID. Get the revision that was before this one.
2409 * @return integer $oldrevision|false
2411 public function getPreviousRevisionID( $revision ) {
2412 $dbr = wfGetDB( DB_SLAVE
);
2413 return $dbr->selectField( 'revision', 'rev_id',
2414 'rev_page=' . intval( $this->getArticleId() ) .
2415 ' AND rev_id<' . intval( $revision ) . ' ORDER BY rev_id DESC' );
2419 * Get the revision ID of the next revision
2421 * @param integer $revision Revision ID. Get the revision that was after this one.
2422 * @return integer $oldrevision|false
2424 public function getNextRevisionID( $revision ) {
2425 $dbr = wfGetDB( DB_SLAVE
);
2426 return $dbr->selectField( 'revision', 'rev_id',
2427 'rev_page=' . intval( $this->getArticleId() ) .
2428 ' AND rev_id>' . intval( $revision ) . ' ORDER BY rev_id' );
2432 * Get the number of revisions between the given revision IDs.
2434 * @param integer $old Revision ID.
2435 * @param integer $new Revision ID.
2436 * @return integer Number of revisions between these IDs.
2438 public function countRevisionsBetween( $old, $new ) {
2439 $dbr = wfGetDB( DB_SLAVE
);
2440 return $dbr->selectField( 'revision', 'count(*)',
2441 'rev_page = ' . intval( $this->getArticleId() ) .
2442 ' AND rev_id > ' . intval( $old ) .
2443 ' AND rev_id < ' . intval( $new ) );
2447 * Compare with another title.
2449 * @param Title $title
2452 public function equals( $title ) {
2453 // Note: === is necessary for proper matching of number-like titles.
2454 return $this->getInterwiki() === $title->getInterwiki()
2455 && $this->getNamespace() == $title->getNamespace()
2456 && $this->getDbkey() === $title->getDbkey();
2460 * Return a string representation of this title
2464 public function __toString() {
2465 return $this->getPrefixedText();
2469 * Check if page exists
2472 public function exists() {
2473 return $this->getArticleId() != 0;
2477 * Should a link should be displayed as a known link, just based on its title?
2479 * Currently, a self-link with a fragment and special pages are in
2480 * this category. System messages that have defined default values are also
2483 public function isAlwaysKnown() {
2484 return ( $this->isExternal() ||
2485 ( 0 == $this->mNamespace
&& "" == $this->mDbkeyform
) ||
2486 ( NS_MEDIAWIKI
== $this->mNamespace
&& wfMsgWeirdKey( $this->mDbkeyform
) ) );
2490 * Update page_touched timestamps and send squid purge messages for
2491 * pages linking to this title. May be sent to the job queue depending
2492 * on the number of links. Typically called on create and delete.
2494 public function touchLinks() {
2495 $u = new HTMLCacheUpdate( $this, 'pagelinks' );
2498 if ( $this->getNamespace() == NS_CATEGORY
) {
2499 $u = new HTMLCacheUpdate( $this, 'categorylinks' );
2505 * Get the last touched timestamp
2507 public function getTouched() {
2508 $dbr = wfGetDB( DB_SLAVE
);
2509 $touched = $dbr->selectField( 'page', 'page_touched',
2511 'page_namespace' => $this->getNamespace(),
2512 'page_title' => $this->getDBkey()
2518 public function trackbackURL() {
2519 global $wgTitle, $wgScriptPath, $wgServer;
2521 return "$wgServer$wgScriptPath/trackback.php?article="
2522 . htmlspecialchars(urlencode($wgTitle->getPrefixedDBkey()));
2525 public function trackbackRDF() {
2526 $url = htmlspecialchars($this->getFullURL());
2527 $title = htmlspecialchars($this->getText());
2528 $tburl = $this->trackbackURL();
2531 <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
2532 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
2533 xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">
2536 dc:identifier=\"$url\"
2538 trackback:ping=\"$tburl\" />
2543 * Generate strings used for xml 'id' names in monobook tabs
2546 public function getNamespaceKey() {
2548 switch ($this->getNamespace()) {
2551 return 'nstab-main';
2554 return 'nstab-user';
2556 return 'nstab-media';
2558 return 'nstab-special';
2560 case NS_PROJECT_TALK
:
2561 return 'nstab-project';
2564 return 'nstab-image';
2566 case NS_MEDIAWIKI_TALK
:
2567 return 'nstab-mediawiki';
2569 case NS_TEMPLATE_TALK
:
2570 return 'nstab-template';
2573 return 'nstab-help';
2575 case NS_CATEGORY_TALK
:
2576 return 'nstab-category';
2578 return 'nstab-' . $wgContLang->lc( $this->getSubjectNsText() );
2583 * Returns true if this title resolves to the named special page
2584 * @param string $name The special page name
2586 public function isSpecial( $name ) {
2587 if ( $this->getNamespace() == NS_SPECIAL
) {
2588 list( $thisName, /* $subpage */ ) = SpecialPage
::resolveAliasWithSubpage( $this->getDBkey() );
2589 if ( $name == $thisName ) {
2597 * If the Title refers to a special page alias which is not the local default,
2598 * returns a new Title which points to the local default. Otherwise, returns $this.
2600 public function fixSpecialName() {
2601 if ( $this->getNamespace() == NS_SPECIAL
) {
2602 $canonicalName = SpecialPage
::resolveAlias( $this->mDbkeyform
);
2603 if ( $canonicalName ) {
2604 $localName = SpecialPage
::getLocalNameFor( $canonicalName );
2605 if ( $localName != $this->mDbkeyform
) {
2606 return Title
::makeTitle( NS_SPECIAL
, $localName );
2614 * Is this Title in a namespace which contains content?
2615 * In other words, is this a content page, for the purposes of calculating
2620 public function isContentPage() {
2621 return Namespace::isContent( $this->getNamespace() );