8 require_once( dirname(__FILE__
) . '/normal/UtfNormal.php' );
10 define ( 'GAID_FOR_UPDATE', 1 );
12 # Title::newFromTitle maintains a cache to avoid
13 # expensive re-normalization of commonly used titles.
14 # On a batch operation this can become a memory leak
15 # if not bounded. After hitting this many titles,
17 define( 'MW_TITLECACHE_MAX', 1000 );
19 # Constants for pr_cascade bitfield
20 define( 'CASCADE', 1 );
24 * - Represents a title, which may contain an interwiki designation or namespace
25 * - Can fetch various kinds of data from the database, albeit inefficiently.
30 * Static cache variables
32 static private $titleCache=array();
33 static private $interwikiCache=array();
37 * All member variables should be considered private
38 * Please use the accessor functions
45 var $mTextform; # Text form (spaces not underscores) of the main part
46 var $mUrlform; # URL-encoded form of the main part
47 var $mDbkeyform; # Main part with underscores
48 var $mNamespace; # Namespace index, i.e. one of the NS_xxxx constants
49 var $mInterwiki; # Interwiki prefix (or null string)
50 var $mFragment; # Title fragment (i.e. the bit after the #)
51 var $mArticleID; # Article ID, fetched from the link cache on demand
52 var $mLatestID; # ID of most recent revision
53 var $mRestrictions; # Array of groups allowed to edit this article
54 var $mCascadeRestriction; # Cascade restrictions on this page to included templates and images?
55 var $mRestrictionsExpiry; # When do the restrictions on this page expire?
56 var $mHasCascadingRestrictions; # Are cascading restrictions in effect on this page?
57 var $mCascadeRestrictionSources;# Where are the cascading restrictions coming from on this page?
58 var $mRestrictionsLoaded; # Boolean for initialisation on demand
59 var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
60 var $mDefaultNamespace; # Namespace index when there is no namespace
61 # Zero except in {{transclusion}} tags
62 var $mWatched; # Is $wgUser watching this page? NULL if unfilled, accessed through userIsWatching()
70 /* private */ function __construct() {
71 $this->mInterwiki
= $this->mUrlform
=
72 $this->mTextform
= $this->mDbkeyform
= '';
73 $this->mArticleID
= -1;
74 $this->mNamespace
= NS_MAIN
;
75 $this->mRestrictionsLoaded
= false;
76 $this->mRestrictions
= array();
77 # Dont change the following, NS_MAIN is hardcoded in several place
79 $this->mDefaultNamespace
= NS_MAIN
;
80 $this->mWatched
= NULL;
81 $this->mLatestID
= false;
82 $this->mOldRestrictions
= false;
86 * Create a new Title from a prefixed DB key
87 * @param string $key The database key, which has underscores
88 * instead of spaces, possibly including namespace and
90 * @return Title the new object, or NULL on an error
94 /* 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
116 public static function newFromText( $text, $defaultNamespace = NS_MAIN
) {
117 if( is_object( $text ) ) {
118 throw new MWException( 'Title::newFromText given an object' );
122 * Wiki pages often contain multiple links to the same page.
123 * Title normalization and parsing can become expensive on
124 * pages with many links, so we can save a little time by
127 * In theory these are value objects and won't get changed...
129 if( $defaultNamespace == NS_MAIN
&& isset( Title
::$titleCache[$text] ) ) {
130 return Title
::$titleCache[$text];
134 * Convert things like é ā or 〗 into real text...
136 $filteredText = Sanitizer
::decodeCharReferences( $text );
139 $t->mDbkeyform
= str_replace( ' ', '_', $filteredText );
140 $t->mDefaultNamespace
= $defaultNamespace;
142 static $cachedcount = 0 ;
143 if( $t->secureAndSplit() ) {
144 if( $defaultNamespace == NS_MAIN
) {
145 if( $cachedcount >= MW_TITLECACHE_MAX
) {
146 # Avoid memory leaks on mass operations...
147 Title
::$titleCache = array();
151 Title
::$titleCache[$text] =& $t;
161 * Create a new Title from URL-encoded text. Ensures that
162 * the given title's length does not exceed the maximum.
163 * @param string $url the title, as might be taken from a URL
164 * @return Title the new object, or NULL on an error
168 public static function newFromURL( $url ) {
169 global $wgLegalTitleChars;
172 # For compatibility with old buggy URLs. "+" is usually not valid in titles,
173 # but some URLs used it as a space replacement and they still come
174 # from some external search tools.
175 if ( strpos( $wgLegalTitleChars, '+' ) === false ) {
176 $url = str_replace( '+', ' ', $url );
179 $t->mDbkeyform
= str_replace( ' ', '_', $url );
180 if( $t->secureAndSplit() ) {
188 * Create a new Title from an article ID
190 * @todo This is inefficiently implemented, the page row is requested
191 * but not used for anything else
193 * @param int $id the page_id corresponding to the Title to create
194 * @return Title the new object, or NULL on an error
198 public static function newFromID( $id ) {
199 $fname = 'Title::newFromID';
200 $dbr = wfGetDB( DB_SLAVE
);
201 $row = $dbr->selectRow( 'page', array( 'page_namespace', 'page_title' ),
202 array( 'page_id' => $id ), $fname );
203 if ( $row !== false ) {
204 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
212 * Make an array of titles from an array of IDs
214 function newFromIDs( $ids ) {
215 $dbr = wfGetDB( DB_SLAVE
);
216 $res = $dbr->select( 'page', array( 'page_namespace', 'page_title' ),
217 'page_id IN (' . $dbr->makeList( $ids ) . ')', __METHOD__
);
220 while ( $row = $dbr->fetchObject( $res ) ) {
221 $titles[] = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
227 * Create a new Title from a namespace index and a DB key.
228 * It's assumed that $ns and $title are *valid*, for instance when
229 * they came directly from the database or a special page name.
230 * For convenience, spaces are converted to underscores so that
231 * eg user_text fields can be used directly.
233 * @param int $ns the namespace of the article
234 * @param string $title the unprefixed database key form
235 * @return Title the new object
239 public static function &makeTitle( $ns, $title ) {
243 $t->mNamespace
= intval( $ns );
244 $t->mDbkeyform
= str_replace( ' ', '_', $title );
245 $t->mArticleID
= ( $ns >= 0 ) ?
-1 : 0;
246 $t->mUrlform
= wfUrlencode( $t->mDbkeyform
);
247 $t->mTextform
= str_replace( '_', ' ', $title );
252 * Create a new Title from a namespace index and a DB key.
253 * The parameters will be checked for validity, which is a bit slower
254 * than makeTitle() but safer for user-provided data.
256 * @param int $ns the namespace of the article
257 * @param string $title the database key form
258 * @return Title the new object, or NULL on an error
262 public static function makeTitleSafe( $ns, $title ) {
264 $t->mDbkeyform
= Title
::makeName( $ns, $title );
265 if( $t->secureAndSplit() ) {
273 * Create a new Title for the Main Page
276 * @return Title the new object
279 public static function newMainPage() {
280 return Title
::newFromText( wfMsgForContent( 'mainpage' ) );
284 * Create a new Title for a redirect
285 * @param string $text the redirect title text
286 * @return Title the new object, or NULL if the text is not a
289 public static function newFromRedirect( $text ) {
290 $mwRedir = MagicWord
::get( 'redirect' );
292 if ( $mwRedir->matchStart( $text ) ) {
294 if ( preg_match( '/\[{2}(.*?)(?:\||\]{2})/', $text, $m ) ) {
295 # categories are escaped using : for example one can enter:
296 # #REDIRECT [[:Category:Music]]. Need to remove it.
297 if ( substr($m[1],0,1) == ':') {
298 # We don't want to keep the ':'
299 $m[1] = substr( $m[1], 1 );
302 $rt = Title
::newFromText( $m[1] );
303 # Disallow redirects to Special:Userlogout
304 if ( !is_null($rt) && $rt->isSpecial( 'Userlogout' ) ) {
312 #----------------------------------------------------------------------------
314 #----------------------------------------------------------------------------
317 * Get the prefixed DB key associated with an ID
318 * @param int $id the page_id of the article
319 * @return Title an object representing the article, or NULL
320 * if no such article was found
324 function nameOf( $id ) {
325 $fname = 'Title::nameOf';
326 $dbr = wfGetDB( DB_SLAVE
);
328 $s = $dbr->selectRow( 'page', array( 'page_namespace','page_title' ), array( 'page_id' => $id ), $fname );
329 if ( $s === false ) { return NULL; }
331 $n = Title
::makeName( $s->page_namespace
, $s->page_title
);
336 * Get a regex character class describing the legal characters in a link
337 * @return string the list of characters, not delimited
341 public static function legalChars() {
342 global $wgLegalTitleChars;
343 return $wgLegalTitleChars;
347 * Get a string representation of a title suitable for
348 * including in a search index
350 * @param int $ns a namespace index
351 * @param string $title text-form main part
352 * @return string a stripped-down title string ready for the
355 public static function indexTitle( $ns, $title ) {
358 $lc = SearchEngine
::legalSearchChars() . '&#;';
359 $t = $wgContLang->stripForSearch( $title );
360 $t = preg_replace( "/[^{$lc}]+/", ' ', $t );
361 $t = $wgContLang->lc( $t );
364 $t = preg_replace( "/([{$lc}]+)'s( |$)/", "\\1 \\1's ", $t );
365 $t = preg_replace( "/([{$lc}]+)s'( |$)/", "\\1s ", $t );
367 $t = preg_replace( "/\\s+/", ' ', $t );
369 if ( $ns == NS_IMAGE
) {
370 $t = preg_replace( "/ (png|gif|jpg|jpeg|ogg)$/", "", $t );
376 * Make a prefixed DB key from a DB key and a namespace index
377 * @param int $ns numerical representation of the namespace
378 * @param string $title the DB key form the title
379 * @return string the prefixed form of the title
381 public static function makeName( $ns, $title ) {
384 $n = $wgContLang->getNsText( $ns );
385 return $n == '' ?
$title : "$n:$title";
389 * Returns the URL associated with an interwiki prefix
390 * @param string $key the interwiki prefix (e.g. "MeatBall")
391 * @return the associated URL, containing "$1", which should be
392 * replaced by an article title
396 function getInterwikiLink( $key ) {
397 global $wgMemc, $wgInterwikiExpiry;
398 global $wgInterwikiCache, $wgContLang;
399 $fname = 'Title::getInterwikiLink';
401 $key = $wgContLang->lc( $key );
403 $k = wfMemcKey( 'interwiki', $key );
404 if( array_key_exists( $k, Title
::$interwikiCache ) ) {
405 return Title
::$interwikiCache[$k]->iw_url
;
408 if ($wgInterwikiCache) {
409 return Title
::getInterwikiCached( $key );
412 $s = $wgMemc->get( $k );
413 # Ignore old keys with no iw_local
414 if( $s && isset( $s->iw_local
) && isset($s->iw_trans
)) {
415 Title
::$interwikiCache[$k] = $s;
419 $dbr = wfGetDB( DB_SLAVE
);
420 $res = $dbr->select( 'interwiki',
421 array( 'iw_url', 'iw_local', 'iw_trans' ),
422 array( 'iw_prefix' => $key ), $fname );
427 $s = $dbr->fetchObject( $res );
429 # Cache non-existence: create a blank object and save it to memcached
435 $wgMemc->set( $k, $s, $wgInterwikiExpiry );
436 Title
::$interwikiCache[$k] = $s;
442 * Fetch interwiki prefix data from local cache in constant database
444 * More logic is explained in DefaultSettings
446 * @return string URL of interwiki site
449 function getInterwikiCached( $key ) {
450 global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
454 $db=dba_open($wgInterwikiCache,'r','cdb');
455 /* Resolve site name */
456 if ($wgInterwikiScopes>=3 and !$site) {
457 $site = dba_fetch('__sites:' . wfWikiID(), $db);
459 $site = $wgInterwikiFallbackSite;
461 $value = dba_fetch( wfMemcKey( $key ), $db);
462 if ($value=='' and $wgInterwikiScopes>=3) {
464 $value = dba_fetch("_{$site}:{$key}", $db);
466 if ($value=='' and $wgInterwikiScopes>=2) {
468 $value = dba_fetch("__global:{$key}", $db);
477 list($local,$url)=explode(' ',$value,2);
479 $s->iw_local
=(int)$local;
481 Title
::$interwikiCache[wfMemcKey( 'interwiki', $key )] = $s;
485 * Determine whether the object refers to a page within
488 * @return bool TRUE if this is an in-project interwiki link
489 * or a wikilink, FALSE otherwise
493 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_local
);
504 * Determine whether the object refers to a page within
505 * this project and is transcludable.
507 * @return bool TRUE if this is transcludable
511 if ($this->mInterwiki
== '')
513 # Make sure key is loaded into cache
514 $this->getInterwikiLink( $this->mInterwiki
);
515 $k = wfMemcKey( 'interwiki', $this->mInterwiki
);
516 return (bool)(Title
::$interwikiCache[$k]->iw_trans
);
520 * Update the page_touched field for an array of title objects
521 * @todo Inefficient unless the IDs are already loaded into the
523 * @param array $titles an array of Title objects to be touched
524 * @param string $timestamp the timestamp to use instead of the
525 * default current time
529 function touchArray( $titles, $timestamp = '' ) {
531 if ( count( $titles ) == 0 ) {
534 $dbw = wfGetDB( DB_MASTER
);
535 if ( $timestamp == '' ) {
536 $timestamp = $dbw->timestamp();
539 $page = $dbw->tableName( 'page' );
540 $sql = "UPDATE $page SET page_touched='{$timestamp}' WHERE page_id IN (";
543 foreach ( $titles as $title ) {
544 if ( $wgUseFileCache ) {
545 $cm = new HTMLFileCache($title);
546 @unlink($cm->fileCacheName());
553 $sql .= $title->getArticleID();
557 $dbw->query( $sql, 'Title::touchArray' );
560 // hack hack hack -- brion 2005-07-11. this was unfriendly to db.
561 // do them in small chunks:
562 $fname = 'Title::touchArray';
563 foreach( $titles as $title ) {
564 $dbw->update( 'page',
565 array( 'page_touched' => $timestamp ),
567 'page_namespace' => $title->getNamespace(),
568 'page_title' => $title->getDBkey() ),
574 * Escape a text fragment, say from a link, for a URL
576 static function escapeFragmentForURL( $fragment ) {
577 $fragment = str_replace( ' ', '_', $fragment );
578 $fragment = urlencode( Sanitizer
::decodeCharReferences( $fragment ) );
579 $replaceArray = array(
583 return strtr( $fragment, $replaceArray );
586 #----------------------------------------------------------------------------
588 #----------------------------------------------------------------------------
590 /** Simple accessors */
592 * Get the text form (spaces not underscores) of the main part
596 function getText() { return $this->mTextform
; }
598 * Get the URL-encoded form of the main part
602 function getPartialURL() { return $this->mUrlform
; }
604 * Get the main part with underscores
608 function getDBkey() { return $this->mDbkeyform
; }
610 * Get the namespace index, i.e. one of the NS_xxxx constants
614 function getNamespace() { return $this->mNamespace
; }
616 * Get the namespace text
620 function getNsText() {
621 global $wgContLang, $wgCanonicalNamespaceNames;
623 if ( '' != $this->mInterwiki
) {
624 // This probably shouldn't even happen. ohh man, oh yuck.
625 // But for interwiki transclusion it sometimes does.
626 // Shit. Shit shit shit.
628 // Use the canonical namespaces if possible to try to
629 // resolve a foreign namespace.
630 if( isset( $wgCanonicalNamespaceNames[$this->mNamespace
] ) ) {
631 return $wgCanonicalNamespaceNames[$this->mNamespace
];
634 return $wgContLang->getNsText( $this->mNamespace
);
637 * Get the namespace text of the subject (rather than talk) page
641 function getSubjectNsText() {
643 return $wgContLang->getNsText( Namespace::getSubject( $this->mNamespace
) );
647 * Get the namespace text of the talk page
650 function getTalkNsText() {
652 return( $wgContLang->getNsText( Namespace::getTalk( $this->mNamespace
) ) );
656 * Could this title have a corresponding talk page?
660 return( Namespace::canTalk( $this->mNamespace
) );
664 * Get the interwiki prefix (or null string)
668 function getInterwiki() { return $this->mInterwiki
; }
670 * Get the Title fragment (i.e. the bit after the #) in text form
674 function getFragment() { return $this->mFragment
; }
676 * Get the fragment in URL form, including the "#" character if there is one
681 function getFragmentForURL() {
682 if ( $this->mFragment
== '' ) {
685 return '#' . Title
::escapeFragmentForURL( $this->mFragment
);
689 * Get the default namespace index, for when there is no namespace
693 function getDefaultNamespace() { return $this->mDefaultNamespace
; }
696 * Get title for search index
697 * @return string a stripped-down title string ready for the
700 function getIndexTitle() {
701 return Title
::indexTitle( $this->mNamespace
, $this->mTextform
);
705 * Get the prefixed database key form
706 * @return string the prefixed title, with underscores and
707 * any interwiki and namespace prefixes
710 function getPrefixedDBkey() {
711 $s = $this->prefix( $this->mDbkeyform
);
712 $s = str_replace( ' ', '_', $s );
717 * Get the prefixed title with spaces.
718 * This is the form usually used for display
719 * @return string the prefixed title, with spaces
722 function getPrefixedText() {
723 if ( empty( $this->mPrefixedText
) ) { // FIXME: bad usage of empty() ?
724 $s = $this->prefix( $this->mTextform
);
725 $s = str_replace( '_', ' ', $s );
726 $this->mPrefixedText
= $s;
728 return $this->mPrefixedText
;
732 * Get the prefixed title with spaces, plus any fragment
733 * (part beginning with '#')
734 * @return string the prefixed title, with spaces and
735 * the fragment, including '#'
738 function getFullText() {
739 $text = $this->getPrefixedText();
740 if( '' != $this->mFragment
) {
741 $text .= '#' . $this->mFragment
;
747 * Get the base name, i.e. the leftmost parts before the /
748 * @return string Base name
750 function getBaseText() {
751 global $wgNamespacesWithSubpages;
752 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) && $wgNamespacesWithSubpages[ $this->mNamespace
] ) {
753 $parts = explode( '/', $this->getText() );
754 # Don't discard the real title if there's no subpage involved
755 if( count( $parts ) > 1 )
756 unset( $parts[ count( $parts ) - 1 ] );
757 return implode( '/', $parts );
759 return $this->getText();
764 * Get the lowest-level subpage name, i.e. the rightmost part after /
765 * @return string Subpage name
767 function getSubpageText() {
768 global $wgNamespacesWithSubpages;
769 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) && $wgNamespacesWithSubpages[ $this->mNamespace
] ) {
770 $parts = explode( '/', $this->mTextform
);
771 return( $parts[ count( $parts ) - 1 ] );
773 return( $this->mTextform
);
778 * Get a URL-encoded form of the subpage text
779 * @return string URL-encoded subpage name
781 function getSubpageUrlForm() {
782 $text = $this->getSubpageText();
783 $text = wfUrlencode( str_replace( ' ', '_', $text ) );
784 $text = str_replace( '%28', '(', str_replace( '%29', ')', $text ) ); # Clean up the URL; per below, this might not be safe
789 * Get a URL-encoded title (not an actual URL) including interwiki
790 * @return string the URL-encoded form
793 function getPrefixedURL() {
794 $s = $this->prefix( $this->mDbkeyform
);
795 $s = str_replace( ' ', '_', $s );
797 $s = wfUrlencode ( $s ) ;
799 # Cleaning up URL to make it look nice -- is this safe?
800 $s = str_replace( '%28', '(', $s );
801 $s = str_replace( '%29', ')', $s );
807 * Get a real URL referring to this title, with interwiki link and
810 * @param string $query an optional query string, not used
811 * for interwiki links
812 * @param string $variant language variant of url (for sr, zh..)
813 * @return string the URL
816 function getFullURL( $query = '', $variant = false ) {
817 global $wgContLang, $wgServer, $wgRequest;
819 if ( '' == $this->mInterwiki
) {
820 $url = $this->getLocalUrl( $query, $variant );
822 // Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)
823 // Correct fix would be to move the prepending elsewhere.
824 if ($wgRequest->getVal('action') != 'render') {
825 $url = $wgServer . $url;
828 $baseUrl = $this->getInterwikiLink( $this->mInterwiki
);
830 $namespace = wfUrlencode( $this->getNsText() );
831 if ( '' != $namespace ) {
832 # Can this actually happen? Interwikis shouldn't be parsed.
833 # Yes! It can in interwiki transclusion. But... it probably shouldn't.
836 $url = str_replace( '$1', $namespace . $this->mUrlform
, $baseUrl );
837 $url = wfAppendQuery( $url, $query );
840 # Finally, add the fragment.
841 $url .= $this->getFragmentForURL();
843 wfRunHooks( 'GetFullURL', array( &$this, &$url, $query ) );
848 * Get a URL with no fragment or server name. If this page is generated
849 * with action=render, $wgServer is prepended.
850 * @param string $query an optional query string; if not specified,
851 * $wgArticlePath will be used.
852 * @param string $variant language variant of url (for sr, zh..)
853 * @return string the URL
856 function getLocalURL( $query = '', $variant = false ) {
857 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
858 global $wgVariantArticlePath, $wgContLang, $wgUser;
860 // internal links should point to same variant as current page (only anonymous users)
861 if($variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn()){
862 $pref = $wgContLang->getPreferredVariant(false);
863 if($pref != $wgContLang->getCode())
867 if ( $this->isExternal() ) {
868 $url = $this->getFullURL();
870 // This is currently only used for edit section links in the
871 // context of interwiki transclusion. In theory we should
872 // append the query to the end of any existing query string,
873 // but interwiki transclusion is already broken in that case.
877 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
878 if ( $query == '' ) {
879 if($variant!=false && $wgContLang->hasVariants()){
880 if($wgVariantArticlePath==false)
881 $variantArticlePath = "$wgScript?title=$1&variant=$2"; // default
883 $variantArticlePath = $wgVariantArticlePath;
885 $url = str_replace( '$2', urlencode( $variant ), $variantArticlePath );
886 $url = str_replace( '$1', $dbkey, $url );
890 $url = str_replace( '$1', $dbkey, $wgArticlePath );
892 global $wgActionPaths;
895 if( !empty( $wgActionPaths ) &&
896 preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) )
898 $action = urldecode( $matches[2] );
899 if( isset( $wgActionPaths[$action] ) ) {
900 $query = $matches[1];
901 if( isset( $matches[4] ) ) $query .= $matches[4];
902 $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
903 if( $query != '' ) $url .= '?' . $query;
906 if ( $url === false ) {
907 if ( $query == '-' ) {
910 $url = "{$wgScript}?title={$dbkey}&{$query}";
914 // FIXME: this causes breakage in various places when we
915 // actually expected a local URL and end up with dupe prefixes.
916 if ($wgRequest->getVal('action') == 'render') {
917 $url = $wgServer . $url;
920 wfRunHooks( 'GetLocalURL', array( &$this, &$url, $query ) );
925 * Get an HTML-escaped version of the URL form, suitable for
926 * using in a link, without a server name or fragment
927 * @param string $query an optional query string
928 * @return string the URL
931 function escapeLocalURL( $query = '' ) {
932 return htmlspecialchars( $this->getLocalURL( $query ) );
936 * Get an HTML-escaped version of the URL form, suitable for
937 * using in a link, including the server name and fragment
939 * @return string the URL
940 * @param string $query an optional query string
943 function escapeFullURL( $query = '' ) {
944 return htmlspecialchars( $this->getFullURL( $query ) );
948 * Get the URL form for an internal link.
949 * - Used in various Squid-related code, in case we have a different
950 * internal hostname for the server from the exposed one.
952 * @param string $query an optional query string
953 * @param string $variant language variant of url (for sr, zh..)
954 * @return string the URL
957 function getInternalURL( $query = '', $variant = false ) {
958 global $wgInternalServer;
959 $url = $wgInternalServer . $this->getLocalURL( $query, $variant );
960 wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
965 * Get the edit URL for this Title
966 * @return string the URL, or a null string if this is an
970 function getEditURL() {
971 if ( '' != $this->mInterwiki
) { return ''; }
972 $s = $this->getLocalURL( 'action=edit' );
978 * Get the HTML-escaped displayable text form.
979 * Used for the title field in <a> tags.
980 * @return string the text, including any prefixes
983 function getEscapedText() {
984 return htmlspecialchars( $this->getPrefixedText() );
988 * Is this Title interwiki?
992 function isExternal() { return ( '' != $this->mInterwiki
); }
995 * Is this page "semi-protected" - the *only* protection is autoconfirm?
997 * @param string Action to check (default: edit)
1000 function isSemiProtected( $action = 'edit' ) {
1001 if( $this->exists() ) {
1002 $restrictions = $this->getRestrictions( $action );
1003 if( count( $restrictions ) > 0 ) {
1004 foreach( $restrictions as $restriction ) {
1005 if( strtolower( $restriction ) != 'autoconfirmed' )
1014 # If it doesn't exist, it can't be protected
1020 * Does the title correspond to a protected article?
1021 * @param string $what the action the page is protected from,
1022 * by default checks move and edit
1026 function isProtected( $action = '' ) {
1027 global $wgRestrictionLevels;
1029 # Special pages have inherent protection
1030 if( $this->getNamespace() == NS_SPECIAL
)
1033 # Check regular protection levels
1034 if( $action == 'edit' ||
$action == '' ) {
1035 $r = $this->getRestrictions( 'edit' );
1036 foreach( $wgRestrictionLevels as $level ) {
1037 if( in_array( $level, $r ) && $level != '' ) {
1043 if( $action == 'move' ||
$action == '' ) {
1044 $r = $this->getRestrictions( 'move' );
1045 foreach( $wgRestrictionLevels as $level ) {
1046 if( in_array( $level, $r ) && $level != '' ) {
1056 * Is $wgUser is watching this page?
1060 function userIsWatching() {
1063 if ( is_null( $this->mWatched
) ) {
1064 if ( NS_SPECIAL
== $this->mNamespace ||
!$wgUser->isLoggedIn()) {
1065 $this->mWatched
= false;
1067 $this->mWatched
= $wgUser->isWatched( $this );
1070 return $this->mWatched
;
1074 * Can $wgUser perform $action on this page?
1075 * This skips potentially expensive cascading permission checks.
1077 * Suitable for use for nonessential UI controls in common cases, but
1078 * _not_ for functional access control.
1080 * May provide false positives, but should never provide a false negative.
1082 * @param string $action action that permission needs to be checked for
1085 public function quickUserCan( $action ) {
1086 return $this->userCan( $action, false );
1090 * Can $wgUser perform $action on this page?
1091 * @param string $action action that permission needs to be checked for
1092 * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
1095 public function userCan( $action, $doExpensiveQueries = true ) {
1096 $fname = 'Title::userCan';
1097 wfProfileIn( $fname );
1099 global $wgUser, $wgNamespaceProtection;
1102 wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) );
1103 if ( $result !== null ) {
1104 wfProfileOut( $fname );
1108 if( NS_SPECIAL
== $this->mNamespace
) {
1109 wfProfileOut( $fname );
1113 if ( array_key_exists( $this->mNamespace
, $wgNamespaceProtection ) ) {
1114 $nsProt = $wgNamespaceProtection[ $this->mNamespace
];
1115 if ( !is_array($nsProt) ) $nsProt = array($nsProt);
1116 foreach( $nsProt as $right ) {
1117 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1118 wfProfileOut( $fname );
1124 if( $this->mDbkeyform
== '_' ) {
1125 # FIXME: Is this necessary? Shouldn't be allowed anyway...
1126 wfProfileOut( $fname );
1130 # protect css/js subpages of user pages
1131 # XXX: this might be better using restrictions
1132 # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
1133 if( $this->isCssJsSubpage()
1134 && !$wgUser->isAllowed('editinterface')
1135 && !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) ) {
1136 wfProfileOut( $fname );
1140 if ( $doExpensiveQueries && !$this->isCssJsSubpage() ) {
1141 # We /could/ use the protection level on the source page, but it's fairly ugly
1142 # as we have to establish a precedence hierarchy for pages included by multiple
1143 # cascade-protected pages. So just restrict it to people with 'protect' permission,
1144 # as they could remove the protection anyway.
1145 list( $cascadingSources, $restrictions ) = $this->getCascadeProtectionSources();
1146 # Cascading protection depends on more than this page...
1147 # Several cascading protected pages may include this page...
1148 # Check each cascading level
1149 # This is only for protection restrictions, not for all actions
1150 if( $cascadingSources > 0 && isset($restrictions[$action]) ) {
1151 foreach( $restrictions[$action] as $right ) {
1152 $right = ( $right == 'sysop' ) ?
'protect' : $right;
1153 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1154 wfProfileOut( $fname );
1161 foreach( $this->getRestrictions($action) as $right ) {
1162 // Backwards compatibility, rewrite sysop -> protect
1163 if ( $right == 'sysop' ) {
1166 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
1167 wfProfileOut( $fname );
1172 if( $action == 'move' &&
1173 !( $this->isMovable() && $wgUser->isAllowed( 'move' ) ) ) {
1174 wfProfileOut( $fname );
1178 if( $action == 'create' ) {
1179 if( ( $this->isTalkPage() && !$wgUser->isAllowed( 'createtalk' ) ) ||
1180 ( !$this->isTalkPage() && !$wgUser->isAllowed( 'createpage' ) ) ) {
1181 wfProfileOut( $fname );
1186 wfProfileOut( $fname );
1191 * Can $wgUser edit this page?
1193 * @deprecated use userCan('edit')
1195 public function userCanEdit( $doExpensiveQueries = true ) {
1196 return $this->userCan( 'edit', $doExpensiveQueries );
1200 * Can $wgUser create this page?
1202 * @deprecated use userCan('create')
1204 public function userCanCreate( $doExpensiveQueries = true ) {
1205 return $this->userCan( 'create', $doExpensiveQueries );
1209 * Can $wgUser move this page?
1211 * @deprecated use userCan('move')
1213 public function userCanMove( $doExpensiveQueries = true ) {
1214 return $this->userCan( 'move', $doExpensiveQueries );
1218 * Would anybody with sufficient privileges be able to move this page?
1219 * Some pages just aren't movable.
1224 function isMovable() {
1225 return Namespace::isMovable( $this->getNamespace() )
1226 && $this->getInterwiki() == '';
1230 * Can $wgUser read this page?
1232 * @todo fold these checks into userCan()
1234 public function userCanRead() {
1238 wfRunHooks( 'userCan', array( &$this, &$wgUser, 'read', &$result ) );
1239 if ( $result !== null ) {
1243 if( $wgUser->isAllowed('read') ) {
1246 global $wgWhitelistRead;
1249 * Always grant access to the login page.
1250 * Even anons need to be able to log in.
1252 if( $this->isSpecial( 'Userlogin' ) ||
$this->isSpecial( 'Resetpass' ) ) {
1256 /** some pages are explicitly allowed */
1257 $name = $this->getPrefixedText();
1258 if( $wgWhitelistRead && in_array( $name, $wgWhitelistRead ) ) {
1262 # Compatibility with old settings
1263 if( $wgWhitelistRead && $this->getNamespace() == NS_MAIN
) {
1264 if( in_array( ':' . $name, $wgWhitelistRead ) ) {
1273 * Is this a talk page of some sort?
1277 function isTalkPage() {
1278 return Namespace::isTalk( $this->getNamespace() );
1282 * Is this a subpage?
1286 function isSubpage() {
1287 global $wgNamespacesWithSubpages;
1289 if( isset( $wgNamespacesWithSubpages[ $this->mNamespace
] ) ) {
1290 return ( strpos( $this->getText(), '/' ) !== false && $wgNamespacesWithSubpages[ $this->mNamespace
] == true );
1297 * Is this a .css or .js subpage of a user page?
1301 function isCssJsSubpage() {
1302 return ( NS_USER
== $this->mNamespace
and preg_match("/\\/.*\\.(css|js)$/", $this->mTextform
) );
1305 * Is this a *valid* .css or .js subpage of a user page?
1306 * Check that the corresponding skin exists
1308 function isValidCssJsSubpage() {
1309 if ( $this->isCssJsSubpage() ) {
1310 $skinNames = Skin
::getSkinNames();
1311 return array_key_exists( $this->getSkinFromCssJsSubpage(), $skinNames );
1317 * Trim down a .css or .js subpage title to get the corresponding skin name
1319 function getSkinFromCssJsSubpage() {
1320 $subpage = explode( '/', $this->mTextform
);
1321 $subpage = $subpage[ count( $subpage ) - 1 ];
1322 return( str_replace( array( '.css', '.js' ), array( '', '' ), $subpage ) );
1325 * Is this a .css subpage of a user page?
1329 function isCssSubpage() {
1330 return ( NS_USER
== $this->mNamespace
and preg_match("/\\/.*\\.css$/", $this->mTextform
) );
1333 * Is this a .js subpage of a user page?
1337 function isJsSubpage() {
1338 return ( NS_USER
== $this->mNamespace
and preg_match("/\\/.*\\.js$/", $this->mTextform
) );
1341 * Protect css/js subpages of user pages: can $wgUser edit
1345 * @todo XXX: this might be better using restrictions
1348 function userCanEditCssJsSubpage() {
1350 return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) );
1354 * Cascading protection: Return true if cascading restrictions apply to this page, false if not.
1356 * @return bool If the page is subject to cascading restrictions.
1359 function isCascadeProtected() {
1360 list( $sources, $restrictions ) = $this->getCascadeProtectionSources( false );
1361 return ( $sources > 0 );
1365 * Cascading protection: Get the source of any cascading restrictions on this page.
1367 * @param $get_pages bool Whether or not to retrieve the actual pages that the restrictions have come from.
1368 * @return array( mixed title array, restriction array)
1369 * 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.
1370 * The restriction array is an array of each type, each of which contains an array of unique groups
1373 function getCascadeProtectionSources( $get_pages = true ) {
1374 global $wgEnableCascadingProtection, $wgRestrictionTypes;
1376 # Define our dimension of restrictions types
1377 $pagerestrictions = array();
1378 foreach( $wgRestrictionTypes as $action )
1379 $pagerestrictions[$action] = array();
1381 if (!$wgEnableCascadingProtection)
1382 return array( false, $pagerestrictions );
1384 if ( isset( $this->mCascadeSources
) && $get_pages ) {
1385 return array( $this->mCascadeSources
, $this->mCascadingRestrictions
);
1386 } else if ( isset( $this->mHasCascadingRestrictions
) && !$get_pages ) {
1387 return array( $this->mHasCascadingRestrictions
, $pagerestrictions );
1390 wfProfileIn( __METHOD__
);
1392 $dbr = wfGetDb( DB_SLAVE
);
1394 if ( $this->getNamespace() == NS_IMAGE
) {
1395 $tables = array ('imagelinks', 'page_restrictions');
1396 $where_clauses = array(
1397 'il_to' => $this->getDBkey(),
1399 'pr_cascade' => 1 );
1401 $tables = array ('templatelinks', 'page_restrictions');
1402 $where_clauses = array(
1403 'tl_namespace' => $this->getNamespace(),
1404 'tl_title' => $this->getDBkey(),
1406 'pr_cascade' => 1 );
1410 $cols = array('pr_page', 'page_namespace', 'page_title', 'pr_expiry', 'pr_type', 'pr_level' );
1411 $where_clauses[] = 'page_id=pr_page';
1414 $cols = array( 'pr_expiry' );
1417 $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__
);
1419 $sources = $get_pages ?
array() : false;
1420 $now = wfTimestampNow();
1421 $purgeExpired = false;
1423 while( $row = $dbr->fetchObject( $res ) ) {
1424 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
1425 if( $expiry > $now ) {
1427 $page_id = $row->pr_page
;
1428 $page_ns = $row->page_namespace
;
1429 $page_title = $row->page_title
;
1430 $sources[$page_id] = Title
::makeTitle($page_ns, $page_title);
1431 # Add groups needed for each restriction type if its not already there
1432 # Make sure this restriction type still exists
1433 if ( isset($pagerestrictions[$row->pr_type
]) && !in_array($row->pr_level
, $pagerestrictions[$row->pr_type
]) ) {
1434 $pagerestrictions[$row->pr_type
][]=$row->pr_level
;
1440 // Trigger lazy purge of expired restrictions from the db
1441 $purgeExpired = true;
1444 if( $purgeExpired ) {
1445 Title
::purgeExpiredRestrictions();
1448 wfProfileOut( __METHOD__
);
1451 $this->mCascadeSources
= $sources;
1452 $this->mCascadingRestrictions
= $pagerestrictions;
1454 $this->mHasCascadingRestrictions
= $sources;
1457 return array( $sources, $pagerestrictions );
1460 function areRestrictionsCascading() {
1461 if (!$this->mRestrictionsLoaded
) {
1462 $this->loadRestrictions();
1465 return $this->mCascadeRestriction
;
1469 * Loads a string into mRestrictions array
1470 * @param resource $res restrictions as an SQL result.
1473 function loadRestrictionsFromRow( $res, $oldFashionedRestrictions = NULL ) {
1474 $dbr = wfGetDb( DB_SLAVE
);
1476 $this->mRestrictions
['edit'] = array();
1477 $this->mRestrictions
['move'] = array();
1479 # Backwards-compatibility: also load the restrictions from the page record (old format).
1481 if ( $oldFashionedRestrictions == NULL ) {
1482 $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleId() ), __METHOD__
);
1485 if ($oldFashionedRestrictions != '') {
1487 foreach( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) {
1488 $temp = explode( '=', trim( $restrict ) );
1489 if(count($temp) == 1) {
1490 // old old format should be treated as edit/move restriction
1491 $this->mRestrictions
["edit"] = explode( ',', trim( $temp[0] ) );
1492 $this->mRestrictions
["move"] = explode( ',', trim( $temp[0] ) );
1494 $this->mRestrictions
[$temp[0]] = explode( ',', trim( $temp[1] ) );
1498 $this->mOldRestrictions
= true;
1499 $this->mCascadeRestriction
= false;
1500 $this->mRestrictionsExpiry
= Block
::decodeExpiry('');
1504 if( $dbr->numRows( $res ) ) {
1505 # Current system - load second to make them override.
1506 $now = wfTimestampNow();
1507 $purgeExpired = false;
1509 while ($row = $dbr->fetchObject( $res ) ) {
1510 # Cycle through all the restrictions.
1512 // This code should be refactored, now that it's being used more generally,
1513 // But I don't really see any harm in leaving it in Block for now -werdna
1514 $expiry = Block
::decodeExpiry( $row->pr_expiry
);
1516 // Only apply the restrictions if they haven't expired!
1517 if ( !$expiry ||
$expiry > $now ) {
1518 $this->mRestrictionsExpiry
= $expiry;
1519 $this->mRestrictions
[$row->pr_type
] = explode( ',', trim( $row->pr_level
) );
1521 $this->mCascadeRestriction |
= $row->pr_cascade
;
1523 // Trigger a lazy purge of expired restrictions
1524 $purgeExpired = true;
1528 if( $purgeExpired ) {
1529 Title
::purgeExpiredRestrictions();
1533 $this->mRestrictionsLoaded
= true;
1536 function loadRestrictions( $oldFashionedRestrictions = NULL ) {
1537 if( !$this->mRestrictionsLoaded
) {
1538 $dbr = wfGetDB( DB_SLAVE
);
1540 $res = $dbr->select( 'page_restrictions', '*',
1541 array ( 'pr_page' => $this->getArticleId() ), __METHOD__
);
1543 $this->loadRestrictionsFromRow( $res, $oldFashionedRestrictions );
1548 * Purge expired restrictions from the page_restrictions table
1550 static function purgeExpiredRestrictions() {
1551 $dbw = wfGetDB( DB_MASTER
);
1552 $dbw->delete( 'page_restrictions',
1553 array( 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
1558 * Accessor/initialisation for mRestrictions
1561 * @param string $action action that permission needs to be checked for
1562 * @return array the array of groups allowed to edit this article
1564 function getRestrictions( $action ) {
1565 if( $this->exists() ) {
1566 if( !$this->mRestrictionsLoaded
) {
1567 $this->loadRestrictions();
1569 return isset( $this->mRestrictions
[$action] )
1570 ?
$this->mRestrictions
[$action]
1578 * Is there a version of this page in the deletion archive?
1579 * @return int the number of archived revisions
1582 function isDeleted() {
1583 $fname = 'Title::isDeleted';
1584 if ( $this->getNamespace() < 0 ) {
1587 $dbr = wfGetDB( DB_SLAVE
);
1588 $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
1589 'ar_title' => $this->getDBkey() ), $fname );
1590 if( $this->getNamespace() == NS_IMAGE
) {
1591 $n +
= $dbr->selectField( 'filearchive', 'COUNT(*)',
1592 array( 'fa_name' => $this->getDBkey() ), $fname );
1599 * Get the article ID for this Title from the link cache,
1600 * adding it if necessary
1601 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select
1603 * @return int the ID
1605 public function getArticleID( $flags = 0 ) {
1606 $linkCache =& LinkCache
::singleton();
1607 if ( $flags & GAID_FOR_UPDATE
) {
1608 $oldUpdate = $linkCache->forUpdate( true );
1609 $this->mArticleID
= $linkCache->addLinkObj( $this );
1610 $linkCache->forUpdate( $oldUpdate );
1612 if ( -1 == $this->mArticleID
) {
1613 $this->mArticleID
= $linkCache->addLinkObj( $this );
1616 return $this->mArticleID
;
1619 function getLatestRevID() {
1620 if ($this->mLatestID
!== false)
1621 return $this->mLatestID
;
1623 $db = wfGetDB(DB_SLAVE
);
1624 return $this->mLatestID
= $db->selectField( 'revision',
1626 array('rev_page' => $this->getArticleID()),
1627 'Title::getLatestRevID' );
1631 * This clears some fields in this object, and clears any associated
1632 * keys in the "bad links" section of the link cache.
1634 * - This is called from Article::insertNewArticle() to allow
1635 * loading of the new page_id. It's also called from
1636 * Article::doDeleteArticle()
1638 * @param int $newid the new Article ID
1641 function resetArticleID( $newid ) {
1642 $linkCache =& LinkCache
::singleton();
1643 $linkCache->clearBadLink( $this->getPrefixedDBkey() );
1645 if ( 0 == $newid ) { $this->mArticleID
= -1; }
1646 else { $this->mArticleID
= $newid; }
1647 $this->mRestrictionsLoaded
= false;
1648 $this->mRestrictions
= array();
1652 * Updates page_touched for this page; called from LinksUpdate.php
1653 * @return bool true if the update succeded
1656 function invalidateCache() {
1657 global $wgUseFileCache;
1659 if ( wfReadOnly() ) {
1663 $dbw = wfGetDB( DB_MASTER
);
1664 $success = $dbw->update( 'page',
1666 'page_touched' => $dbw->timestamp()
1667 ), array( /* WHERE */
1668 'page_namespace' => $this->getNamespace() ,
1669 'page_title' => $this->getDBkey()
1670 ), 'Title::invalidateCache'
1673 if ($wgUseFileCache) {
1674 $cache = new HTMLFileCache($this);
1675 @unlink
($cache->fileCacheName());
1682 * Prefix some arbitrary text with the namespace or interwiki prefix
1685 * @param string $name the text
1686 * @return string the prefixed text
1689 /* private */ function prefix( $name ) {
1691 if ( '' != $this->mInterwiki
) {
1692 $p = $this->mInterwiki
. ':';
1694 if ( 0 != $this->mNamespace
) {
1695 $p .= $this->getNsText() . ':';
1701 * Secure and split - main initialisation function for this object
1703 * Assumes that mDbkeyform has been set, and is urldecoded
1704 * and uses underscores, but not otherwise munged. This function
1705 * removes illegal characters, splits off the interwiki and
1706 * namespace prefixes, sets the other forms, and canonicalizes
1708 * @return bool true on success
1711 /* private */ function secureAndSplit() {
1712 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
1715 static $rxTc = false;
1717 # % is needed as well
1718 $rxTc = '/[^' . Title
::legalChars() . ']|%[0-9A-Fa-f]{2}/S';
1721 $this->mInterwiki
= $this->mFragment
= '';
1722 $this->mNamespace
= $this->mDefaultNamespace
; # Usually NS_MAIN
1724 $dbkey = $this->mDbkeyform
;
1726 # Strip Unicode bidi override characters.
1727 # Sometimes they slip into cut-n-pasted page titles, where the
1728 # override chars get included in list displays.
1729 $dbkey = str_replace( "\xE2\x80\x8E", '', $dbkey ); // 200E LEFT-TO-RIGHT MARK
1730 $dbkey = str_replace( "\xE2\x80\x8F", '', $dbkey ); // 200F RIGHT-TO-LEFT MARK
1732 # Clean up whitespace
1734 $dbkey = preg_replace( '/[ _]+/', '_', $dbkey );
1735 $dbkey = trim( $dbkey, '_' );
1737 if ( '' == $dbkey ) {
1741 if( false !== strpos( $dbkey, UTF8_REPLACEMENT
) ) {
1742 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
1746 $this->mDbkeyform
= $dbkey;
1748 # Initial colon indicates main namespace rather than specified default
1749 # but should not create invalid {ns,title} pairs such as {0,Project:Foo}
1750 if ( ':' == $dbkey{0} ) {
1751 $this->mNamespace
= NS_MAIN
;
1752 $dbkey = substr( $dbkey, 1 ); # remove the colon but continue processing
1755 # Namespace or interwiki prefix
1759 if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $dbkey, $m ) ) {
1761 $lowerNs = $wgContLang->lc( $p );
1762 if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
1763 # Canonical namespace
1765 $this->mNamespace
= $ns;
1766 } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) {
1767 # Ordinary namespace
1769 $this->mNamespace
= $ns;
1770 } elseif( $this->getInterwikiLink( $p ) ) {
1772 # Can't make a local interwiki link to an interwiki link.
1773 # That's just crazy!
1779 $this->mInterwiki
= $wgContLang->lc( $p );
1781 # Redundant interwiki prefix to the local wiki
1782 if ( 0 == strcasecmp( $this->mInterwiki
, $wgLocalInterwiki ) ) {
1783 if( $dbkey == '' ) {
1784 # Can't have an empty self-link
1787 $this->mInterwiki
= '';
1789 # Do another namespace split...
1793 # If there's an initial colon after the interwiki, that also
1794 # resets the default namespace
1795 if ( $dbkey !== '' && $dbkey[0] == ':' ) {
1796 $this->mNamespace
= NS_MAIN
;
1797 $dbkey = substr( $dbkey, 1 );
1800 # If there's no recognized interwiki or namespace,
1801 # then let the colon expression be part of the title.
1806 # We already know that some pages won't be in the database!
1808 if ( '' != $this->mInterwiki || NS_SPECIAL
== $this->mNamespace
) {
1809 $this->mArticleID
= 0;
1811 $fragment = strstr( $dbkey, '#' );
1812 if ( false !== $fragment ) {
1813 $this->setFragment( $fragment );
1814 $dbkey = substr( $dbkey, 0, strlen( $dbkey ) - strlen( $fragment ) );
1815 # remove whitespace again: prevents "Foo_bar_#"
1816 # becoming "Foo_bar_"
1817 $dbkey = preg_replace( '/_*$/', '', $dbkey );
1820 # Reject illegal characters.
1822 if( preg_match( $rxTc, $dbkey ) ) {
1827 * Pages with "/./" or "/../" appearing in the URLs will
1828 * often be unreachable due to the way web browsers deal
1829 * with 'relative' URLs. Forbid them explicitly.
1831 if ( strpos( $dbkey, '.' ) !== false &&
1832 ( $dbkey === '.' ||
$dbkey === '..' ||
1833 strpos( $dbkey, './' ) === 0 ||
1834 strpos( $dbkey, '../' ) === 0 ||
1835 strpos( $dbkey, '/./' ) !== false ||
1836 strpos( $dbkey, '/../' ) !== false ) )
1842 * Magic tilde sequences? Nu-uh!
1844 if( strpos( $dbkey, '~~~' ) !== false ) {
1849 * Limit the size of titles to 255 bytes.
1850 * This is typically the size of the underlying database field.
1851 * We make an exception for special pages, which don't need to be stored
1852 * in the database, and may edge over 255 bytes due to subpage syntax
1853 * for long titles, e.g. [[Special:Block/Long name]]
1855 if ( ( $this->mNamespace
!= NS_SPECIAL
&& strlen( $dbkey ) > 255 ) ||
1856 strlen( $dbkey ) > 512 )
1862 * Normally, all wiki links are forced to have
1863 * an initial capital letter so [[foo]] and [[Foo]]
1864 * point to the same place.
1866 * Don't force it for interwikis, since the other
1867 * site might be case-sensitive.
1869 if( $wgCapitalLinks && $this->mInterwiki
== '') {
1870 $dbkey = $wgContLang->ucfirst( $dbkey );
1874 * Can't make a link to a namespace alone...
1875 * "empty" local links can only be self-links
1876 * with a fragment identifier.
1879 $this->mInterwiki
== '' &&
1880 $this->mNamespace
!= NS_MAIN
) {
1884 // Any remaining initial :s are illegal.
1885 if ( $dbkey !== '' && ':' == $dbkey{0} ) {
1890 $this->mDbkeyform
= $dbkey;
1891 $this->mUrlform
= wfUrlencode( $dbkey );
1893 $this->mTextform
= str_replace( '_', ' ', $dbkey );
1899 * Set the fragment for this title
1900 * This is kind of bad, since except for this rarely-used function, Title objects
1901 * are immutable. The reason this is here is because it's better than setting the
1902 * members directly, which is what Linker::formatComment was doing previously.
1904 * @param string $fragment text
1906 * @todo clarify whether access is supposed to be public (was marked as "kind of public")
1908 function setFragment( $fragment ) {
1909 $this->mFragment
= str_replace( '_', ' ', substr( $fragment, 1 ) );
1913 * Get a Title object associated with the talk page of this article
1914 * @return Title the object for the talk page
1917 function getTalkPage() {
1918 return Title
::makeTitle( Namespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
1922 * Get a title object associated with the subject page of this
1925 * @return Title the object for the subject page
1928 function getSubjectPage() {
1929 return Title
::makeTitle( Namespace::getSubject( $this->getNamespace() ), $this->getDBkey() );
1933 * Get an array of Title objects linking to this Title
1934 * Also stores the IDs in the link cache.
1936 * WARNING: do not use this function on arbitrary user-supplied titles!
1937 * On heavily-used templates it will max out the memory.
1939 * @param string $options may be FOR UPDATE
1940 * @return array the Title objects linking here
1943 function getLinksTo( $options = '', $table = 'pagelinks', $prefix = 'pl' ) {
1944 $linkCache =& LinkCache
::singleton();
1947 $db = wfGetDB( DB_MASTER
);
1949 $db = wfGetDB( DB_SLAVE
);
1952 $res = $db->select( array( 'page', $table ),
1953 array( 'page_namespace', 'page_title', 'page_id' ),
1955 "{$prefix}_from=page_id",
1956 "{$prefix}_namespace" => $this->getNamespace(),
1957 "{$prefix}_title" => $this->getDbKey() ),
1958 'Title::getLinksTo',
1962 if ( $db->numRows( $res ) ) {
1963 while ( $row = $db->fetchObject( $res ) ) {
1964 if ( $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
) ) {
1965 $linkCache->addGoodLinkObj( $row->page_id
, $titleObj );
1966 $retVal[] = $titleObj;
1970 $db->freeResult( $res );
1975 * Get an array of Title objects using this Title as a template
1976 * Also stores the IDs in the link cache.
1978 * WARNING: do not use this function on arbitrary user-supplied titles!
1979 * On heavily-used templates it will max out the memory.
1981 * @param string $options may be FOR UPDATE
1982 * @return array the Title objects linking here
1985 function getTemplateLinksTo( $options = '' ) {
1986 return $this->getLinksTo( $options, 'templatelinks', 'tl' );
1990 * Get an array of Title objects referring to non-existent articles linked from this page
1992 * @param string $options may be FOR UPDATE
1993 * @return array the Title objects
1996 function getBrokenLinksFrom( $options = '' ) {
1998 $db = wfGetDB( DB_MASTER
);
2000 $db = wfGetDB( DB_SLAVE
);
2003 $res = $db->safeQuery(
2004 "SELECT pl_namespace, pl_title
2007 ON pl_namespace=page_namespace
2008 AND pl_title=page_title
2010 AND page_namespace IS NULL
2012 $db->tableName( 'pagelinks' ),
2013 $db->tableName( 'page' ),
2014 $this->getArticleId(),
2018 if ( $db->numRows( $res ) ) {
2019 while ( $row = $db->fetchObject( $res ) ) {
2020 $retVal[] = Title
::makeTitle( $row->pl_namespace
, $row->pl_title
);
2023 $db->freeResult( $res );
2029 * Get a list of URLs to purge from the Squid cache when this
2032 * @return array the URLs
2035 function getSquidURLs() {
2039 $this->getInternalURL(),
2040 $this->getInternalURL( 'action=history' )
2043 // purge variant urls as well
2044 if($wgContLang->hasVariants()){
2045 $variants = $wgContLang->getVariants();
2046 foreach($variants as $vCode){
2047 if($vCode==$wgContLang->getCode()) continue; // we don't want default variant
2048 $urls[] = $this->getInternalURL('',$vCode);
2055 function purgeSquid() {
2057 if ( $wgUseSquid ) {
2058 $urls = $this->getSquidURLs();
2059 $u = new SquidUpdate( $urls );
2065 * Move this page without authentication
2066 * @param Title &$nt the new page Title
2069 function moveNoAuth( &$nt ) {
2070 return $this->moveTo( $nt, false );
2074 * Check whether a given move operation would be valid.
2075 * Returns true if ok, or a message key string for an error message
2076 * if invalid. (Scarrrrry ugly interface this.)
2077 * @param Title &$nt the new title
2078 * @param bool $auth indicates whether $wgUser's permissions
2080 * @return mixed true on success, message name on failure
2083 function isValidMoveOperation( &$nt, $auth = true ) {
2084 if( !$this or !$nt ) {
2085 return 'badtitletext';
2087 if( $this->equals( $nt ) ) {
2090 if( !$this->isMovable() ||
!$nt->isMovable() ) {
2091 return 'immobile_namespace';
2094 $oldid = $this->getArticleID();
2095 $newid = $nt->getArticleID();
2097 if ( strlen( $nt->getDBkey() ) < 1 ) {
2098 return 'articleexists';
2100 if ( ( '' == $this->getDBkey() ) ||
2102 ( '' == $nt->getDBkey() ) ) {
2103 return 'badarticleerror';
2107 !$this->userCan( 'edit' ) ||
!$nt->userCan( 'edit' ) ||
2108 !$this->userCan( 'move' ) ||
!$nt->userCan( 'move' ) ) ) {
2109 return 'protectedpage';
2112 # The move is allowed only if (1) the target doesn't exist, or
2113 # (2) the target is a redirect to the source, and has no history
2114 # (so we can undo bad moves right after they're done).
2116 if ( 0 != $newid ) { # Target exists; check for validity
2117 if ( ! $this->isValidMoveTarget( $nt ) ) {
2118 return 'articleexists';
2125 * Move a title to a new location
2126 * @param Title &$nt the new title
2127 * @param bool $auth indicates whether $wgUser's permissions
2129 * @return mixed true on success, message name on failure
2132 function moveTo( &$nt, $auth = true, $reason = '' ) {
2133 $err = $this->isValidMoveOperation( $nt, $auth );
2134 if( is_string( $err ) ) {
2138 $pageid = $this->getArticleID();
2139 if( $nt->exists() ) {
2140 $this->moveOverExistingRedirect( $nt, $reason );
2141 $pageCountChange = 0;
2142 } else { # Target didn't exist, do normal move.
2143 $this->moveToNewTitle( $nt, $reason );
2144 $pageCountChange = 1;
2146 $redirid = $this->getArticleID();
2148 # Fixing category links (those without piped 'alternate' names) to be sorted under the new title
2149 $dbw = wfGetDB( DB_MASTER
);
2150 $categorylinks = $dbw->tableName( 'categorylinks' );
2151 $sql = "UPDATE $categorylinks SET cl_sortkey=" . $dbw->addQuotes( $nt->getPrefixedText() ) .
2152 " WHERE cl_from=" . $dbw->addQuotes( $pageid ) .
2153 " AND cl_sortkey=" . $dbw->addQuotes( $this->getPrefixedText() );
2154 $dbw->query( $sql, 'SpecialMovepage::doSubmit' );
2158 $oldnamespace = $this->getNamespace() & ~
1;
2159 $newnamespace = $nt->getNamespace() & ~
1;
2160 $oldtitle = $this->getDBkey();
2161 $newtitle = $nt->getDBkey();
2163 if( $oldnamespace != $newnamespace ||
$oldtitle != $newtitle ) {
2164 WatchedItem
::duplicateEntries( $this, $nt );
2167 # Update search engine
2168 $u = new SearchUpdate( $pageid, $nt->getPrefixedDBkey() );
2170 $u = new SearchUpdate( $redirid, $this->getPrefixedDBkey(), '' );
2174 if( $this->isContentPage() && !$nt->isContentPage() ) {
2175 # No longer a content page
2176 # Not viewed, edited, removing
2177 $u = new SiteStatsUpdate( 0, 1, -1, $pageCountChange );
2178 } elseif( !$this->isContentPage() && $nt->isContentPage() ) {
2179 # Now a content page
2180 # Not viewed, edited, adding
2181 $u = new SiteStatsUpdate( 0, 1, +
1, $pageCountChange );
2182 } elseif( $pageCountChange ) {
2184 $u = new SiteStatsUpdate( 0, 0, 0, 1 );
2193 wfRunHooks( 'TitleMoveComplete', array( &$this, &$nt, &$wgUser, $pageid, $redirid ) );
2198 * Move page to a title which is at present a redirect to the
2201 * @param Title &$nt the page to move to, which should currently
2205 function moveOverExistingRedirect( &$nt, $reason = '' ) {
2207 $fname = 'Title::moveOverExistingRedirect';
2208 $comment = wfMsgForContent( '1movedto2_redir', $this->getPrefixedText(), $nt->getPrefixedText() );
2211 $comment .= ": $reason";
2214 $now = wfTimestampNow();
2215 $newid = $nt->getArticleID();
2216 $oldid = $this->getArticleID();
2217 $dbw = wfGetDB( DB_MASTER
);
2218 $linkCache =& LinkCache
::singleton();
2220 # Delete the old redirect. We don't save it to history since
2221 # by definition if we've got here it's rather uninteresting.
2222 # We have to remove it so that the next step doesn't trigger
2223 # a conflict on the unique namespace+title index...
2224 $dbw->delete( 'page', array( 'page_id' => $newid ), $fname );
2226 # Save a null revision in the page's history notifying of the move
2227 $nullRevision = Revision
::newNullRevision( $dbw, $oldid, $comment, true );
2228 $nullRevId = $nullRevision->insertOn( $dbw );
2230 # Change the name of the target page:
2231 $dbw->update( 'page',
2233 'page_touched' => $dbw->timestamp($now),
2234 'page_namespace' => $nt->getNamespace(),
2235 'page_title' => $nt->getDBkey(),
2236 'page_latest' => $nullRevId,
2238 /* WHERE */ array( 'page_id' => $oldid ),
2241 $linkCache->clearLink( $nt->getPrefixedDBkey() );
2243 # Recreate the redirect, this time in the other direction.
2244 $mwRedir = MagicWord
::get( 'redirect' );
2245 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
2246 $redirectArticle = new Article( $this );
2247 $newid = $redirectArticle->insertOn( $dbw );
2248 $redirectRevision = new Revision( array(
2250 'comment' => $comment,
2251 'text' => $redirectText ) );
2252 $redirectRevision->insertOn( $dbw );
2253 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
2254 $linkCache->clearLink( $this->getPrefixedDBkey() );
2257 $log = new LogPage( 'move' );
2258 $log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText() ) );
2260 # Now, we record the link from the redirect to the new title.
2261 # It should have no other outgoing links...
2262 $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), $fname );
2263 $dbw->insert( 'pagelinks',
2265 'pl_from' => $newid,
2266 'pl_namespace' => $nt->getNamespace(),
2267 'pl_title' => $nt->getDbKey() ),
2271 if ( $wgUseSquid ) {
2272 $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
2273 $u = new SquidUpdate( $urls );
2279 * Move page to non-existing title.
2280 * @param Title &$nt the new Title
2283 function moveToNewTitle( &$nt, $reason = '' ) {
2285 $fname = 'MovePageForm::moveToNewTitle';
2286 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
2288 $comment .= ": $reason";
2291 $newid = $nt->getArticleID();
2292 $oldid = $this->getArticleID();
2293 $dbw = wfGetDB( DB_MASTER
);
2294 $now = $dbw->timestamp();
2295 $linkCache =& LinkCache
::singleton();
2297 # Save a null revision in the page's history notifying of the move
2298 $nullRevision = Revision
::newNullRevision( $dbw, $oldid, $comment, true );
2299 $nullRevId = $nullRevision->insertOn( $dbw );
2302 $dbw->update( 'page',
2304 'page_touched' => $now,
2305 'page_namespace' => $nt->getNamespace(),
2306 'page_title' => $nt->getDBkey(),
2307 'page_latest' => $nullRevId,
2309 /* WHERE */ array( 'page_id' => $oldid ),
2313 $linkCache->clearLink( $nt->getPrefixedDBkey() );
2316 $mwRedir = MagicWord
::get( 'redirect' );
2317 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
2318 $redirectArticle = new Article( $this );
2319 $newid = $redirectArticle->insertOn( $dbw );
2320 $redirectRevision = new Revision( array(
2322 'comment' => $comment,
2323 'text' => $redirectText ) );
2324 $redirectRevision->insertOn( $dbw );
2325 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
2326 $linkCache->clearLink( $this->getPrefixedDBkey() );
2329 $log = new LogPage( 'move' );
2330 $log->addEntry( 'move', $this, $reason, array( 1 => $nt->getPrefixedText()) );
2332 # Purge caches as per article creation
2333 Article
::onArticleCreate( $nt );
2335 # Record the just-created redirect's linking to the page
2336 $dbw->insert( 'pagelinks',
2338 'pl_from' => $newid,
2339 'pl_namespace' => $nt->getNamespace(),
2340 'pl_title' => $nt->getDBkey() ),
2343 # Purge old title from squid
2344 # The new title, and links to the new title, are purged in Article::onArticleCreate()
2345 $this->purgeSquid();
2349 * Checks if $this can be moved to a given Title
2350 * - Selects for update, so don't call it unless you mean business
2352 * @param Title &$nt the new title to check
2355 function isValidMoveTarget( $nt ) {
2357 $fname = 'Title::isValidMoveTarget';
2358 $dbw = wfGetDB( DB_MASTER
);
2361 $id = $nt->getArticleID();
2362 $obj = $dbw->selectRow( array( 'page', 'revision', 'text'),
2363 array( 'page_is_redirect','old_text','old_flags' ),
2364 array( 'page_id' => $id, 'page_latest=rev_id', 'rev_text_id=old_id' ),
2365 $fname, 'FOR UPDATE' );
2367 if ( !$obj ||
0 == $obj->page_is_redirect
) {
2369 wfDebug( __METHOD__
. ": not a redirect\n" );
2372 $text = Revision
::getRevisionText( $obj );
2374 # Does the redirect point to the source?
2375 # Or is it a broken self-redirect, usually caused by namespace collisions?
2377 if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $text, $m ) ) {
2378 $redirTitle = Title
::newFromText( $m[1] );
2379 if( !is_object( $redirTitle ) ||
2380 ( $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() &&
2381 $redirTitle->getPrefixedDBkey() != $nt->getPrefixedDBkey() ) ) {
2382 wfDebug( __METHOD__
. ": redirect points to other page\n" );
2387 wfDebug( __METHOD__
. ": failsafe\n" );
2391 # Does the article have a history?
2392 $row = $dbw->selectRow( array( 'page', 'revision'),
2394 array( 'page_namespace' => $nt->getNamespace(),
2395 'page_title' => $nt->getDBkey(),
2396 'page_id=rev_page AND page_latest != rev_id'
2397 ), $fname, 'FOR UPDATE'
2400 # Return true if there was no history
2401 return $row === false;
2405 * Get categories to which this Title belongs and return an array of
2406 * categories' names.
2408 * @return array an array of parents in the form:
2409 * $parent => $currentarticle
2412 function getParentCategories() {
2415 $titlekey = $this->getArticleId();
2416 $dbr = wfGetDB( DB_SLAVE
);
2417 $categorylinks = $dbr->tableName( 'categorylinks' );
2420 $sql = "SELECT * FROM $categorylinks"
2421 ." WHERE cl_from='$titlekey'"
2422 ." AND cl_from <> '0'"
2423 ." ORDER BY cl_sortkey";
2425 $res = $dbr->query ( $sql ) ;
2427 if($dbr->numRows($res) > 0) {
2428 while ( $x = $dbr->fetchObject ( $res ) )
2429 //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
2430 $data[$wgContLang->getNSText ( NS_CATEGORY
).':'.$x->cl_to
] = $this->getFullText();
2431 $dbr->freeResult ( $res ) ;
2439 * Get a tree of parent categories
2440 * @param array $children an array with the children in the keys, to check for circular refs
2444 function getParentCategoryTree( $children = array() ) {
2445 $parents = $this->getParentCategories();
2447 if($parents != '') {
2448 foreach($parents as $parent => $current) {
2449 if ( array_key_exists( $parent, $children ) ) {
2450 # Circular reference
2451 $stack[$parent] = array();
2453 $nt = Title
::newFromText($parent);
2455 $stack[$parent] = $nt->getParentCategoryTree( $children +
array($parent => 1) );
2467 * Get an associative array for selecting this title from
2473 function pageCond() {
2474 return array( 'page_namespace' => $this->mNamespace
, 'page_title' => $this->mDbkeyform
);
2478 * Get the revision ID of the previous revision
2480 * @param integer $revision Revision ID. Get the revision that was before this one.
2481 * @return integer $oldrevision|false
2483 function getPreviousRevisionID( $revision ) {
2484 $dbr = wfGetDB( DB_SLAVE
);
2485 return $dbr->selectField( 'revision', 'rev_id',
2486 'rev_page=' . intval( $this->getArticleId() ) .
2487 ' AND rev_id<' . intval( $revision ) . ' ORDER BY rev_id DESC' );
2491 * Get the revision ID of the next revision
2493 * @param integer $revision Revision ID. Get the revision that was after this one.
2494 * @return integer $oldrevision|false
2496 function getNextRevisionID( $revision ) {
2497 $dbr = wfGetDB( DB_SLAVE
);
2498 return $dbr->selectField( 'revision', 'rev_id',
2499 'rev_page=' . intval( $this->getArticleId() ) .
2500 ' AND rev_id>' . intval( $revision ) . ' ORDER BY rev_id' );
2504 * Get the number of revisions between the given revision IDs.
2506 * @param integer $old Revision ID.
2507 * @param integer $new Revision ID.
2508 * @return integer Number of revisions between these IDs.
2510 function countRevisionsBetween( $old, $new ) {
2511 $dbr = wfGetDB( DB_SLAVE
);
2512 return $dbr->selectField( 'revision', 'count(*)',
2513 'rev_page = ' . intval( $this->getArticleId() ) .
2514 ' AND rev_id > ' . intval( $old ) .
2515 ' AND rev_id < ' . intval( $new ) );
2519 * Compare with another title.
2521 * @param Title $title
2524 function equals( $title ) {
2525 // Note: === is necessary for proper matching of number-like titles.
2526 return $this->getInterwiki() === $title->getInterwiki()
2527 && $this->getNamespace() == $title->getNamespace()
2528 && $this->getDbkey() === $title->getDbkey();
2532 * Check if page exists
2536 return $this->getArticleId() != 0;
2540 * Should a link should be displayed as a known link, just based on its title?
2542 * Currently, a self-link with a fragment and special pages are in
2543 * this category. Special pages never exist in the database.
2545 function isAlwaysKnown() {
2546 return $this->isExternal() ||
( 0 == $this->mNamespace
&& "" == $this->mDbkeyform
)
2547 || NS_SPECIAL
== $this->mNamespace
;
2551 * Update page_touched timestamps and send squid purge messages for
2552 * pages linking to this title. May be sent to the job queue depending
2553 * on the number of links. Typically called on create and delete.
2555 function touchLinks() {
2556 $u = new HTMLCacheUpdate( $this, 'pagelinks' );
2559 if ( $this->getNamespace() == NS_CATEGORY
) {
2560 $u = new HTMLCacheUpdate( $this, 'categorylinks' );
2566 * Get the last touched timestamp
2568 function getTouched() {
2569 $dbr = wfGetDB( DB_SLAVE
);
2570 $touched = $dbr->selectField( 'page', 'page_touched',
2572 'page_namespace' => $this->getNamespace(),
2573 'page_title' => $this->getDBkey()
2580 * Get a cached value from a global cache that is invalidated when this page changes
2581 * @param string $key the key
2582 * @param callback $callback A callback function which generates the value on cache miss
2584 * @deprecated use DependencyWrapper
2586 function getRelatedCache( $memc, $key, $expiry, $callback, $params = array() ) {
2587 return DependencyWrapper
::getValueFromCache( $memc, $key, $expiry, $callback,
2588 $params, new TitleDependency( $this ) );
2591 function trackbackURL() {
2592 global $wgTitle, $wgScriptPath, $wgServer;
2594 return "$wgServer$wgScriptPath/trackback.php?article="
2595 . htmlspecialchars(urlencode($wgTitle->getPrefixedDBkey()));
2598 function trackbackRDF() {
2599 $url = htmlspecialchars($this->getFullURL());
2600 $title = htmlspecialchars($this->getText());
2601 $tburl = $this->trackbackURL();
2604 <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
2605 xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
2606 xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">
2609 dc:identifier=\"$url\"
2611 trackback:ping=\"$tburl\" />
2616 * Generate strings used for xml 'id' names in monobook tabs
2619 function getNamespaceKey() {
2621 switch ($this->getNamespace()) {
2624 return 'nstab-main';
2627 return 'nstab-user';
2629 return 'nstab-media';
2631 return 'nstab-special';
2633 case NS_PROJECT_TALK
:
2634 return 'nstab-project';
2637 return 'nstab-image';
2639 case NS_MEDIAWIKI_TALK
:
2640 return 'nstab-mediawiki';
2642 case NS_TEMPLATE_TALK
:
2643 return 'nstab-template';
2646 return 'nstab-help';
2648 case NS_CATEGORY_TALK
:
2649 return 'nstab-category';
2651 return 'nstab-' . $wgContLang->lc( $this->getSubjectNsText() );
2656 * Returns true if this title resolves to the named special page
2657 * @param string $name The special page name
2660 function isSpecial( $name ) {
2661 if ( $this->getNamespace() == NS_SPECIAL
) {
2662 list( $thisName, /* $subpage */ ) = SpecialPage
::resolveAliasWithSubpage( $this->getDBkey() );
2663 if ( $name == $thisName ) {
2671 * If the Title refers to a special page alias which is not the local default,
2672 * returns a new Title which points to the local default. Otherwise, returns $this.
2674 function fixSpecialName() {
2675 if ( $this->getNamespace() == NS_SPECIAL
) {
2676 $canonicalName = SpecialPage
::resolveAlias( $this->mDbkeyform
);
2677 if ( $canonicalName ) {
2678 $localName = SpecialPage
::getLocalNameFor( $canonicalName );
2679 if ( $localName != $this->mDbkeyform
) {
2680 return Title
::makeTitle( NS_SPECIAL
, $localName );
2688 * Is this Title in a namespace which contains content?
2689 * In other words, is this a content page, for the purposes of calculating
2694 public function isContentPage() {
2695 return Namespace::isContent( $this->getNamespace() );