9 require_once( 'normal/UtfNormal.php' );
11 $wgTitleInterwikiCache = array();
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 );
23 * - Represents a title, which may contain an interwiki designation or namespace
24 * - Can fetch various kinds of data from the database, albeit inefficiently.
30 * All member variables should be considered private
31 * Please use the accessor functions
38 var $mTextform; # Text form (spaces not underscores) of the main part
39 var $mUrlform; # URL-encoded form of the main part
40 var $mDbkeyform; # Main part with underscores
41 var $mNamespace; # Namespace index, i.e. one of the NS_xxxx constants
42 var $mInterwiki; # Interwiki prefix (or null string)
43 var $mFragment; # Title fragment (i.e. the bit after the #)
44 var $mArticleID; # Article ID, fetched from the link cache on demand
45 var $mRestrictions; # Array of groups allowed to edit this article
46 # Only null or "sysop" are supported
47 var $mRestrictionsLoaded; # Boolean for initialisation on demand
48 var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
49 var $mDefaultNamespace; # Namespace index when there is no namespace
50 # Zero except in {{transclusion}} tags
58 /* private */ function Title() {
59 $this->mInterwiki
= $this->mUrlform
=
60 $this->mTextform
= $this->mDbkeyform
= '';
61 $this->mArticleID
= -1;
62 $this->mNamespace
= NS_MAIN
;
63 $this->mRestrictionsLoaded
= false;
64 $this->mRestrictions
= array();
65 # Dont change the following, NS_MAIN is hardcoded in several place
67 $this->mDefaultNamespace
= NS_MAIN
;
71 * Create a new Title from a prefixed DB key
72 * @param string $key The database key, which has underscores
73 * instead of spaces, possibly including namespace and
75 * @return Title the new object, or NULL on an error
79 /* static */ function newFromDBkey( $key ) {
81 $t->mDbkeyform
= $key;
82 if( $t->secureAndSplit() )
89 * Create a new Title from text, such as what one would
90 * find in a link. Decodes any HTML entities in the text.
92 * @param string $text the link text; spaces, prefixes,
93 * and an initial ':' indicating the main namespace
95 * @param int $defaultNamespace the namespace to use if
96 * none is specified by a prefix
97 * @return Title the new object, or NULL on an error
101 function &newFromText( $text, $defaultNamespace = NS_MAIN
) {
102 $fname = 'Title::newFromText';
103 wfProfileIn( $fname );
105 if( is_object( $text ) ) {
106 wfDebugDieBacktrace( 'Title::newFromText given an object' );
110 * Wiki pages often contain multiple links to the same page.
111 * Title normalization and parsing can become expensive on
112 * pages with many links, so we can save a little time by
115 * In theory these are value objects and won't get changed...
117 static $titleCache = array();
118 if( $defaultNamespace == NS_MAIN
&& isset( $titleCache[$text] ) ) {
119 wfProfileOut( $fname );
120 return $titleCache[$text];
124 * Convert things like é into real text...
126 global $wgInputEncoding;
127 $filteredText = do_html_entity_decode( $text, ENT_COMPAT
, $wgInputEncoding );
130 * Convert things like ā or 〗 into real text...
131 * WARNING: Not friendly to internal links on a latin-1 wiki.
133 $filteredText = wfMungeToUtf8( $filteredText );
135 # What was this for? TS 2004-03-03
136 # $text = urldecode( $text );
139 $t->mDbkeyform
= str_replace( ' ', '_', $filteredText );
140 $t->mDefaultNamespace
= $defaultNamespace;
142 if( $t->secureAndSplit() ) {
143 if( $defaultNamespace == NS_MAIN
) {
144 if( count( $titleCache ) >= MW_TITLECACHE_MAX
) {
145 # Avoid memory leaks on mass operations...
146 $titleCache = array();
148 $titleCache[$text] =& $t;
150 wfProfileOut( $fname );
153 wfProfileOut( $fname );
159 * Create a new Title from URL-encoded text. Ensures that
160 * the given title's length does not exceed the maximum.
161 * @param string $url the title, as might be taken from a URL
162 * @return Title the new object, or NULL on an error
166 /* static */ function newFromURL( $url ) {
167 global $wgLang, $wgServer;
170 # For compatibility with old buggy URLs. "+" is not valid in titles,
171 # but some URLs used it as a space replacement and they still come
172 # from some external search tools.
173 $s = str_replace( '+', ' ', $url );
175 $t->mDbkeyform
= str_replace( ' ', '_', $s );
176 if( $t->secureAndSplit() ) {
184 * Create a new Title from an article ID
185 * @todo This is inefficiently implemented, the page row is requested
186 * but not used for anything else
187 * @param int $id the page_id corresponding to the Title to create
188 * @return Title the new object, or NULL on an error
191 /* static */ function newFromID( $id ) {
192 $fname = 'Title::newFromID';
193 $dbr =& wfGetDB( DB_SLAVE
);
194 $row = $dbr->selectRow( 'page', array( 'page_namespace', 'page_title' ),
195 array( 'page_id' => $id ), $fname );
196 if ( $row !== false ) {
197 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
205 * Create a new Title from a namespace index and a DB key.
206 * It's assumed that $ns and $title are *valid*, for instance when
207 * they came directly from the database or a special page name.
208 * For convenience, spaces are converted to underscores so that
209 * eg user_text fields can be used directly.
211 * @param int $ns the namespace of the article
212 * @param string $title the unprefixed database key form
213 * @return Title the new object
217 /* static */ function &makeTitle( $ns, $title ) {
221 $t->mNamespace
= IntVal( $ns );
222 $t->mDbkeyform
= str_replace( ' ', '_', $title );
223 $t->mArticleID
= ( $ns >= 0 ) ?
-1 : 0;
224 $t->mUrlform
= wfUrlencode( $t->mDbkeyform
);
225 $t->mTextform
= str_replace( '_', ' ', $title );
230 * Create a new Title frrom a namespace index and a DB key.
231 * The parameters will be checked for validity, which is a bit slower
232 * than makeTitle() but safer for user-provided data.
233 * @param int $ns the namespace of the article
234 * @param string $title the database key form
235 * @return Title the new object, or NULL on an error
239 /* static */ function makeTitleSafe( $ns, $title ) {
241 $t->mDbkeyform
= Title
::makeName( $ns, $title );
242 if( $t->secureAndSplit() ) {
250 * Create a new Title for the Main Page
252 * @return Title the new object
255 /* static */ function newMainPage() {
256 return Title
::newFromText( wfMsgForContent( 'mainpage' ) );
260 * Create a new Title for a redirect
261 * @param string $text the redirect title text
262 * @return Title the new object, or NULL if the text is not a
267 /* static */ function newFromRedirect( $text ) {
270 if ( $wgMwRedir->matchStart( $text ) ) {
271 if ( preg_match( '/\\[\\[([^\\]\\|]+)[\\]\\|]/', $text, $m ) ) {
272 # categories are escaped using : for example one can enter:
273 # #REDIRECT [[:Category:Music]]. Need to remove it.
274 if ( substr($m[1],0,1) == ':') {
275 # We don't want to keep the ':'
276 $m[1] = substr( $m[1], 1 );
279 $rt = Title
::newFromText( $m[1] );
280 # Disallow redirects to Special:Userlogout
281 if ( !is_null($rt) && $rt->getNamespace() == NS_SPECIAL
&& preg_match( '/^Userlogout/i', $rt->getText() ) ) {
289 #----------------------------------------------------------------------------
291 #----------------------------------------------------------------------------
294 * Get the prefixed DB key associated with an ID
295 * @param int $id the page_id of the article
296 * @return Title an object representing the article, or NULL
297 * if no such article was found
301 /* static */ function nameOf( $id ) {
302 $fname = 'Title::nameOf';
303 $dbr =& wfGetDB( DB_SLAVE
);
305 $s = $dbr->selectRow( 'page', array( 'page_namespace','page_title' ), array( 'page_id' => $id ), $fname );
306 if ( $s === false ) { return NULL; }
308 $n = Title
::makeName( $s->page_namespace
, $s->page_title
);
313 * Get a regex character class describing the legal characters in a link
314 * @return string the list of characters, not delimited
318 /* static */ function legalChars() {
319 # Missing characters:
320 # * []|# Needed for link syntax
321 # * % and + are corrupted by Apache when they appear in the path
323 # % seems to work though
325 # The problem with % is that URLs are double-unescaped: once by Apache's
326 # path conversion code, and again by PHP. So %253F, for example, becomes "?".
327 # Our code does not double-escape to compensate for this, indeed double escaping
328 # would break if the double-escaped title was passed in the query string
329 # rather than the path. This is a minor security issue because articles can be
330 # created such that they are hard to view or edit. -- TS
332 # Theoretically 0x80-0x9F of ISO 8859-1 should be disallowed, but
333 # this breaks interlanguage links
335 $set = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF";
340 * Get a string representation of a title suitable for
341 * including in a search index
343 * @param int $ns a namespace index
344 * @param string $title text-form main part
345 * @return string a stripped-down title string ready for the
348 /* static */ function indexTitle( $ns, $title ) {
349 global $wgDBminWordLen, $wgContLang;
350 require_once( 'SearchEngine.php' );
352 $lc = SearchEngine
::legalSearchChars() . '&#;';
353 $t = $wgContLang->stripForSearch( $title );
354 $t = preg_replace( "/[^{$lc}]+/", ' ', $t );
355 $t = strtolower( $t );
358 $t = preg_replace( "/([{$lc}]+)'s( |$)/", "\\1 \\1's ", $t );
359 $t = preg_replace( "/([{$lc}]+)s'( |$)/", "\\1s ", $t );
361 $t = preg_replace( "/\\s+/", ' ', $t );
363 if ( $ns == NS_IMAGE
) {
364 $t = preg_replace( "/ (png|gif|jpg|jpeg|ogg)$/", "", $t );
370 * Make a prefixed DB key from a DB key and a namespace index
371 * @param int $ns numerical representation of the namespace
372 * @param string $title the DB key form the title
373 * @return string the prefixed form of the title
375 /* static */ function makeName( $ns, $title ) {
378 $n = $wgContLang->getNsText( $ns );
379 if ( '' == $n ) { return $title; }
380 else { return $n.':'.$title; }
384 * Returns the URL associated with an interwiki prefix
385 * @param string $key the interwiki prefix (e.g. "MeatBall")
386 * @return the associated URL, containing "$1", which should be
387 * replaced by an article title
391 function getInterwikiLink( $key ) {
392 global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgTitleInterwikiCache;
393 $fname = 'Title::getInterwikiLink';
395 wfProfileIn( $fname );
397 $k = $wgDBname.':interwiki:'.$key;
398 if( array_key_exists( $k, $wgTitleInterwikiCache ) ) {
399 wfProfileOut( $fname );
400 return $wgTitleInterwikiCache[$k]->iw_url
;
403 $s = $wgMemc->get( $k );
404 # Ignore old keys with no iw_local
405 if( $s && isset( $s->iw_local
) ) {
406 $wgTitleInterwikiCache[$k] = $s;
407 wfProfileOut( $fname );
411 $dbr =& wfGetDB( DB_SLAVE
);
412 $res = $dbr->select( 'interwiki',
413 array( 'iw_url', 'iw_local' ),
414 array( 'iw_prefix' => $key ), $fname );
416 wfProfileOut( $fname );
420 $s = $dbr->fetchObject( $res );
422 # Cache non-existence: create a blank object and save it to memcached
427 $wgMemc->set( $k, $s, $wgInterwikiExpiry );
428 $wgTitleInterwikiCache[$k] = $s;
430 wfProfileOut( $fname );
435 * Determine whether the object refers to a page within
438 * @return bool TRUE if this is an in-project interwiki link
439 * or a wikilink, FALSE otherwise
443 global $wgTitleInterwikiCache, $wgDBname;
445 if ( $this->mInterwiki
!= '' ) {
446 # Make sure key is loaded into cache
447 $this->getInterwikiLink( $this->mInterwiki
);
448 $k = $wgDBname.':interwiki:' . $this->mInterwiki
;
449 return (bool)($wgTitleInterwikiCache[$k]->iw_local
);
456 * Update the page_touched field for an array of title objects
457 * @todo Inefficient unless the IDs are already loaded into the
459 * @param array $titles an array of Title objects to be touched
460 * @param string $timestamp the timestamp to use instead of the
461 * default current time
465 /* static */ function touchArray( $titles, $timestamp = '' ) {
466 if ( count( $titles ) == 0 ) {
469 $dbw =& wfGetDB( DB_MASTER
);
470 if ( $timestamp == '' ) {
471 $timestamp = $dbw->timestamp();
473 $page = $dbw->tableName( 'page' );
474 $sql = "UPDATE $page SET page_touched='{$timestamp}' WHERE page_id IN (";
477 foreach ( $titles as $title ) {
482 $sql .= $title->getArticleID();
486 $dbw->query( $sql, 'Title::touchArray' );
490 #----------------------------------------------------------------------------
492 #----------------------------------------------------------------------------
494 /** Simple accessors */
496 * Get the text form (spaces not underscores) of the main part
500 function getText() { return $this->mTextform
; }
502 * Get the URL-encoded form of the main part
506 function getPartialURL() { return $this->mUrlform
; }
508 * Get the main part with underscores
512 function getDBkey() { return $this->mDbkeyform
; }
514 * Get the namespace index, i.e. one of the NS_xxxx constants
518 function getNamespace() { return $this->mNamespace
; }
520 * Get the interwiki prefix (or null string)
524 function getInterwiki() { return $this->mInterwiki
; }
526 * Get the Title fragment (i.e. the bit after the #)
530 function getFragment() { return $this->mFragment
; }
532 * Get the default namespace index, for when there is no namespace
536 function getDefaultNamespace() { return $this->mDefaultNamespace
; }
539 * Get title for search index
540 * @return string a stripped-down title string ready for the
543 function getIndexTitle() {
544 return Title
::indexTitle( $this->mNamespace
, $this->mTextform
);
548 * Get the prefixed database key form
549 * @return string the prefixed title, with underscores and
550 * any interwiki and namespace prefixes
553 function getPrefixedDBkey() {
554 $s = $this->prefix( $this->mDbkeyform
);
555 $s = str_replace( ' ', '_', $s );
560 * Get the prefixed title with spaces.
561 * This is the form usually used for display
562 * @return string the prefixed title, with spaces
565 function getPrefixedText() {
567 if ( empty( $this->mPrefixedText
) ) {
568 $s = $this->prefix( $this->mTextform
);
569 $s = str_replace( '_', ' ', $s );
570 $this->mPrefixedText
= $s;
572 return $this->mPrefixedText
;
576 * Get the prefixed title with spaces, plus any fragment
577 * (part beginning with '#')
578 * @return string the prefixed title, with spaces and
579 * the fragment, including '#'
582 function getFullText() {
584 $text = $this->getPrefixedText();
585 if( '' != $this->mFragment
) {
586 $text .= '#' . $this->mFragment
;
592 * Get a URL-encoded title (not an actual URL) including interwiki
593 * @return string the URL-encoded form
596 function getPrefixedURL() {
597 $s = $this->prefix( $this->mDbkeyform
);
598 $s = str_replace( ' ', '_', $s );
600 $s = wfUrlencode ( $s ) ;
602 # Cleaning up URL to make it look nice -- is this safe?
603 $s = str_replace( '%28', '(', $s );
604 $s = str_replace( '%29', ')', $s );
610 * Get a real URL referring to this title, with interwiki link and
613 * @param string $query an optional query string, not used
614 * for interwiki links
615 * @return string the URL
618 function getFullURL( $query = '' ) {
619 global $wgContLang, $wgArticlePath, $wgServer, $wgScript;
621 if ( '' == $this->mInterwiki
) {
623 return $wgServer . $this->getLocalUrl( $query );
625 $baseUrl = $this->getInterwikiLink( $this->mInterwiki
);
626 $namespace = $wgContLang->getNsText( $this->mNamespace
);
627 if ( '' != $namespace ) {
628 # Can this actually happen? Interwikis shouldn't be parsed.
631 $url = str_replace( '$1', $namespace . $this->mUrlform
, $baseUrl );
633 if( false === strpos( $url, '?' ) ) {
640 if ( '' != $this->mFragment
) {
641 $url .= '#' . $this->mFragment
;
648 * Get a URL with no fragment or server name
649 * @param string $query an optional query string; if not specified,
650 * $wgArticlePath will be used.
651 * @return string the URL
654 function getLocalURL( $query = '' ) {
655 global $wgLang, $wgArticlePath, $wgScript;
657 if ( $this->isExternal() ) {
658 return $this->getFullURL();
661 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
662 if ( $query == '' ) {
663 $url = str_replace( '$1', $dbkey, $wgArticlePath );
665 if( preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) ) {
666 global $wgActionPaths;
667 $action = urldecode( $matches[2] );
668 if( isset( $wgActionPaths[$action] ) ) {
669 $query = $matches[1];
670 if( isset( $matches[4] ) ) $query .= $matches[4];
671 $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
672 if( $query != '' ) $url .= '?' . $query;
676 if ( $query == '-' ) {
679 $url = "{$wgScript}?title={$dbkey}&{$query}";
685 * Get an HTML-escaped version of the URL form, suitable for
686 * using in a link, without a server name or fragment
687 * @param string $query an optional query string
688 * @return string the URL
691 function escapeLocalURL( $query = '' ) {
692 return htmlspecialchars( $this->getLocalURL( $query ) );
696 * Get an HTML-escaped version of the URL form, suitable for
697 * using in a link, including the server name and fragment
699 * @return string the URL
700 * @param string $query an optional query string
703 function escapeFullURL( $query = '' ) {
704 return htmlspecialchars( $this->getFullURL( $query ) );
708 * Get the URL form for an internal link.
709 * - Used in various Squid-related code, in case we have a different
710 * internal hostname for the server from the exposed one.
712 * @param string $query an optional query string
713 * @return string the URL
716 function getInternalURL( $query = '' ) {
717 global $wgInternalServer;
718 return $wgInternalServer . $this->getLocalURL( $query );
722 * Get the edit URL for this Title
723 * @return string the URL, or a null string if this is an
727 function getEditURL() {
728 global $wgServer, $wgScript;
730 if ( '' != $this->mInterwiki
) { return ''; }
731 $s = $this->getLocalURL( 'action=edit' );
737 * Get the HTML-escaped displayable text form.
738 * Used for the title field in <a> tags.
739 * @return string the text, including any prefixes
742 function getEscapedText() {
743 return htmlspecialchars( $this->getPrefixedText() );
747 * Is this Title interwiki?
751 function isExternal() { return ( '' != $this->mInterwiki
); }
754 * Does the title correspond to a protected article?
755 * @param string $what the action the page is protected from,
756 * by default checks move and edit
760 function isProtected($action = '') {
761 if ( -1 == $this->mNamespace
) { return true; }
762 if($action == 'edit' ||
$action == '') {
763 $a = $this->getRestrictions("edit");
764 if ( in_array( 'sysop', $a ) ) { return true; }
766 if($action == 'move' ||
$action == '') {
767 $a = $this->getRestrictions("move");
768 if ( in_array( 'sysop', $a ) ) { return true; }
774 * Is $wgUser is watching this page?
778 function userIsWatching() {
781 if ( -1 == $this->mNamespace
) { return false; }
782 if ( 0 == $wgUser->getID() ) { return false; }
784 return $wgUser->isWatched( $this );
788 * Is $wgUser perform $action this page?
789 * @param string $action action that permission needs to be checked for
793 function userCan($action) {
794 $fname = 'Title::userCanEdit';
795 wfProfileIn( $fname );
798 if( NS_SPECIAL
== $this->mNamespace
) {
799 wfProfileOut( $fname );
802 if( NS_MEDIAWIKI
== $this->mNamespace
&&
803 !$wgUser->isAllowed('editinterface') ) {
804 wfProfileOut( $fname );
807 if( $this->mDbkeyform
== '_' ) {
808 # FIXME: Is this necessary? Shouldn't be allowed anyway...
809 wfProfileOut( $fname );
813 # protect global styles and js
814 if ( NS_MEDIAWIKI
== $this->mNamespace
815 && preg_match("/\\.(css|js)$/", $this->mTextform
)
816 && !$wgUser->isAllowed('editinterface') ) {
817 wfProfileOut( $fname );
821 # protect css/js subpages of user pages
822 # XXX: this might be better using restrictions
823 # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
824 if( NS_USER
== $this->mNamespace
825 && preg_match("/\\.(css|js)$/", $this->mTextform
)
826 && !$wgUser->isAllowed('editinterface')
827 && !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) ) {
828 wfProfileOut( $fname );
832 foreach( $this->getRestrictions($action) as $right ) {
833 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
834 wfProfileOut( $fname );
838 wfProfileOut( $fname );
843 * Can $wgUser edit this page?
847 function userCanEdit() {
848 return $this->userCan('edit');
852 * Can $wgUser move this page?
856 function userCanMove() {
857 return $this->userCan('move');
861 * Can $wgUser read this page?
865 function userCanRead() {
868 if( $wgUser->isAllowed('read') ) {
871 global $wgWhitelistRead;
873 /** If anon users can create an account,
874 they need to reach the login page first! */
875 if( $wgUser->isAllowed( 'createaccount' )
876 && $this->mId
== NS_SPECIAL
877 && $this->getText() == 'Userlogin' ) {
881 /** some pages are explicitly allowed */
882 $name = $this->getPrefixedText();
883 if( in_array( $name, $wgWhitelistRead ) ) {
887 # Compatibility with old settings
888 if( $this->getNamespace() == NS_MAIN
) {
889 if( in_array( ':' . $name, $wgWhitelistRead ) ) {
898 * Is this a talk page of some sort?
902 function isTalkPage() {
903 return Namespace::isTalk( $this->getNamespace() );
907 * Is this a .css or .js subpage of a user page?
911 function isCssJsSubpage() {
912 return ( NS_USER
== $this->mNamespace
and preg_match("/\\.(css|js)$/", $this->mTextform
) );
915 * Is this a .css subpage of a user page?
919 function isCssSubpage() {
920 return ( NS_USER
== $this->mNamespace
and preg_match("/\\.css$/", $this->mTextform
) );
923 * Is this a .js subpage of a user page?
927 function isJsSubpage() {
928 return ( NS_USER
== $this->mNamespace
and preg_match("/\\.js$/", $this->mTextform
) );
931 * Protect css/js subpages of user pages: can $wgUser edit
935 * @todo XXX: this might be better using restrictions
938 function userCanEditCssJsSubpage() {
940 return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) );
944 * Loads a string into mRestrictions array
945 * @param string $res restrictions in string format
948 function loadRestrictions( $res ) {
949 foreach( explode( ':', trim( $res ) ) as $restrict ) {
950 $temp = explode( '=', trim( $restrict ) );
951 if(count($temp) == 1) {
952 // old format should be treated as edit/move restriction
953 $this->mRestrictions
["edit"] = explode( ',', trim( $temp[0] ) );
954 $this->mRestrictions
["move"] = explode( ',', trim( $temp[0] ) );
956 $this->mRestrictions
[$temp[0]] = explode( ',', trim( $temp[1] ) );
959 $this->mRestrictionsLoaded
= true;
963 * Accessor/initialisation for mRestrictions
964 * @param string $action action that permission needs to be checked for
965 * @return array the array of groups allowed to edit this article
968 function getRestrictions($action) {
969 $id = $this->getArticleID();
970 if ( 0 == $id ) { return array(); }
972 if ( ! $this->mRestrictionsLoaded
) {
973 $dbr =& wfGetDB( DB_SLAVE
);
974 $res = $dbr->selectField( 'page', 'page_restrictions', 'page_id='.$id );
975 $this->loadRestrictions( $res );
977 if( isset( $this->mRestrictions
[$action] ) ) {
978 return $this->mRestrictions
[$action];
984 * Is there a version of this page in the deletion archive?
985 * @return int the number of archived revisions
988 function isDeleted() {
989 $fname = 'Title::isDeleted';
990 $dbr =& wfGetDB( DB_SLAVE
);
991 $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
992 'ar_title' => $this->getDBkey() ), $fname );
997 * Get the article ID for this Title from the link cache,
998 * adding it if necessary
999 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select
1001 * @return int the ID
1004 function getArticleID( $flags = 0 ) {
1005 global $wgLinkCache;
1007 if ( $flags & GAID_FOR_UPDATE
) {
1008 $oldUpdate = $wgLinkCache->forUpdate( true );
1009 $this->mArticleID
= $wgLinkCache->addLinkObj( $this );
1010 $wgLinkCache->forUpdate( $oldUpdate );
1012 if ( -1 == $this->mArticleID
) {
1013 $this->mArticleID
= $wgLinkCache->addLinkObj( $this );
1016 return $this->mArticleID
;
1020 * This clears some fields in this object, and clears any associated
1021 * keys in the "bad links" section of $wgLinkCache.
1023 * - This is called from Article::insertNewArticle() to allow
1024 * loading of the new page_id. It's also called from
1025 * Article::doDeleteArticle()
1027 * @param int $newid the new Article ID
1030 function resetArticleID( $newid ) {
1031 global $wgLinkCache;
1032 $wgLinkCache->clearBadLink( $this->getPrefixedDBkey() );
1034 if ( 0 == $newid ) { $this->mArticleID
= -1; }
1035 else { $this->mArticleID
= $newid; }
1036 $this->mRestrictionsLoaded
= false;
1037 $this->mRestrictions
= array();
1041 * Updates page_touched for this page; called from LinksUpdate.php
1042 * @return bool true if the update succeded
1045 function invalidateCache() {
1046 $now = wfTimestampNow();
1047 $dbw =& wfGetDB( DB_MASTER
);
1048 $success = $dbw->update( 'page',
1050 'page_touched' => $dbw->timestamp()
1051 ), array( /* WHERE */
1052 'page_namespace' => $this->getNamespace() ,
1053 'page_title' => $this->getDBkey()
1054 ), 'Title::invalidateCache'
1060 * Prefix some arbitrary text with the namespace or interwiki prefix
1063 * @param string $name the text
1064 * @return string the prefixed text
1067 /* private */ function prefix( $name ) {
1071 if ( '' != $this->mInterwiki
) {
1072 $p = $this->mInterwiki
. ':';
1074 if ( 0 != $this->mNamespace
) {
1075 $p .= $wgContLang->getNsText( $this->mNamespace
) . ':';
1081 * Secure and split - main initialisation function for this object
1083 * Assumes that mDbkeyform has been set, and is urldecoded
1084 * and uses underscores, but not otherwise munged. This function
1085 * removes illegal characters, splits off the interwiki and
1086 * namespace prefixes, sets the other forms, and canonicalizes
1088 * @return bool true on success
1091 /* private */ function secureAndSplit() {
1092 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
1093 $fname = 'Title::secureAndSplit';
1094 wfProfileIn( $fname );
1097 static $rxTc = false;
1099 # % is needed as well
1100 $rxTc = '/[^' . Title
::legalChars() . ']|%[0-9A-Fa-f]{2}/S';
1103 $this->mInterwiki
= $this->mFragment
= '';
1104 $this->mNamespace
= $this->mDefaultNamespace
; # Usually NS_MAIN
1106 # Clean up whitespace
1108 $t = preg_replace( '/[ _]+/', '_', $this->mDbkeyform
);
1109 $t = trim( $t, '_' );
1112 wfProfileOut( $fname );
1116 if( false !== strpos( $t, UTF8_REPLACEMENT
) ) {
1117 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
1118 wfProfileOut( $fname );
1122 $this->mDbkeyform
= $t;
1124 # Initial colon indicating main namespace
1125 if ( ':' == $t{0} ) {
1126 $r = substr( $t, 1 );
1127 $this->mNamespace
= NS_MAIN
;
1129 # Namespace or interwiki prefix
1132 if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $t, $m ) ) {
1134 $lowerNs = strtolower( $p );
1135 if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
1136 # Canonical namespace
1138 $this->mNamespace
= $ns;
1139 } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) {
1140 # Ordinary namespace
1142 $this->mNamespace
= $ns;
1143 } elseif( $this->getInterwikiLink( $p ) ) {
1145 # Can't make a local interwiki link to an interwiki link.
1146 # That's just crazy!
1147 wfProfileOut( $fname );
1153 $this->mInterwiki
= $p;
1155 # Redundant interwiki prefix to the local wiki
1156 if ( 0 == strcasecmp( $this->mInterwiki
, $wgLocalInterwiki ) ) {
1158 # Can't have an empty self-link
1159 wfProfileOut( $fname );
1162 $this->mInterwiki
= '';
1164 # Do another namespace split...
1168 # If there's no recognized interwiki or namespace,
1169 # then let the colon expression be part of the title.
1176 # We already know that some pages won't be in the database!
1178 if ( '' != $this->mInterwiki ||
-1 == $this->mNamespace
) {
1179 $this->mArticleID
= 0;
1181 $f = strstr( $r, '#' );
1182 if ( false !== $f ) {
1183 $this->mFragment
= substr( $f, 1 );
1184 $r = substr( $r, 0, strlen( $r ) - strlen( $f ) );
1185 # remove whitespace again: prevents "Foo_bar_#"
1186 # becoming "Foo_bar_"
1187 $r = preg_replace( '/_*$/', '', $r );
1190 # Reject illegal characters.
1192 if( preg_match( $rxTc, $r ) ) {
1193 wfProfileOut( $fname );
1198 * Pages with "/./" or "/../" appearing in the URLs will
1199 * often be unreachable due to the way web browsers deal
1200 * with 'relative' URLs. Forbid them explicitly.
1202 if ( strpos( $r, '.' ) !== false &&
1203 ( $r === '.' ||
$r === '..' ||
1204 strpos( $r, './' ) === 0 ||
1205 strpos( $r, '../' ) === 0 ||
1206 strpos( $r, '/./' ) !== false ||
1207 strpos( $r, '/../' ) !== false ) )
1209 wfProfileOut( $fname );
1213 # We shouldn't need to query the DB for the size.
1214 #$maxSize = $dbr->textFieldSize( 'page', 'page_title' );
1215 if ( strlen( $r ) > 255 ) {
1216 wfProfileOut( $fname );
1221 * Normally, all wiki links are forced to have
1222 * an initial capital letter so [[foo]] and [[Foo]]
1223 * point to the same place.
1225 * Don't force it for interwikis, since the other
1226 * site might be case-sensitive.
1228 if( $wgCapitalLinks && $this->mInterwiki
== '') {
1229 $t = $wgContLang->ucfirst( $r );
1235 * Can't make a link to a namespace alone...
1236 * "empty" local links can only be self-links
1237 * with a fragment identifier.
1240 $this->mInterwiki
== '' &&
1241 $this->mNamespace
!= NS_MAIN
) {
1242 wfProfileOut( $fname );
1247 $this->mDbkeyform
= $t;
1248 $this->mUrlform
= wfUrlencode( $t );
1250 $this->mTextform
= str_replace( '_', ' ', $t );
1252 wfProfileOut( $fname );
1257 * Get a Title object associated with the talk page of this article
1258 * @return Title the object for the talk page
1261 function getTalkPage() {
1262 return Title
::makeTitle( Namespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
1266 * Get a title object associated with the subject page of this
1269 * @return Title the object for the subject page
1272 function getSubjectPage() {
1273 return Title
::makeTitle( Namespace::getSubject( $this->getNamespace() ), $this->getDBkey() );
1277 * Get an array of Title objects linking to this Title
1278 * - Also stores the IDs in the link cache.
1280 * @param string $options may be FOR UPDATE
1281 * @return array the Title objects linking here
1284 function getLinksTo( $options = '' ) {
1285 global $wgLinkCache;
1286 $id = $this->getArticleID();
1289 $db =& wfGetDB( DB_MASTER
);
1291 $db =& wfGetDB( DB_SLAVE
);
1293 $page = $db->tableName( 'page' );
1294 $links = $db->tableName( 'links' );
1296 $sql = "SELECT page_namespace,page_title,page_id FROM $page,$links WHERE l_from=page_id AND l_to={$id} $options";
1297 $res = $db->query( $sql, 'Title::getLinksTo' );
1299 if ( $db->numRows( $res ) ) {
1300 while ( $row = $db->fetchObject( $res ) ) {
1301 if ( $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
) ) {
1302 $wgLinkCache->addGoodLink( $row->page_id
, $titleObj->getPrefixedDBkey() );
1303 $retVal[] = $titleObj;
1307 $db->freeResult( $res );
1312 * Get an array of Title objects linking to this non-existent title.
1313 * - Also stores the IDs in the link cache.
1315 * @param string $options may be FOR UPDATE
1316 * @return array the Title objects linking here
1319 function getBrokenLinksTo( $options = '' ) {
1320 global $wgLinkCache;
1323 $db =& wfGetDB( DB_MASTER
);
1325 $db =& wfGetDB( DB_SLAVE
);
1327 $page = $db->tableName( 'page' );
1328 $brokenlinks = $db->tableName( 'brokenlinks' );
1329 $encTitle = $db->strencode( $this->getPrefixedDBkey() );
1331 $sql = "SELECT page_namespace,page_title,page_id FROM $brokenlinks,$page " .
1332 "WHERE bl_from=page_id AND bl_to='$encTitle' $options";
1333 $res = $db->query( $sql, "Title::getBrokenLinksTo" );
1335 if ( $db->numRows( $res ) ) {
1336 while ( $row = $db->fetchObject( $res ) ) {
1337 $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
1338 $wgLinkCache->addGoodLink( $row->page_id
, $titleObj->getPrefixedDBkey() );
1339 $retVal[] = $titleObj;
1342 $db->freeResult( $res );
1347 * Get a list of URLs to purge from the Squid cache when this
1350 * @return array the URLs
1353 function getSquidURLs() {
1355 $this->getInternalURL(),
1356 $this->getInternalURL( 'action=history' )
1361 * Move this page without authentication
1362 * @param Title &$nt the new page Title
1365 function moveNoAuth( &$nt ) {
1366 return $this->moveTo( $nt, false );
1370 * Move a title to a new location
1371 * @param Title &$nt the new title
1372 * @param bool $auth indicates whether $wgUser's permissions
1374 * @return mixed true on success, message name on failure
1377 function moveTo( &$nt, $auth = true ) {
1379 if( !$this or !$nt ) {
1380 return 'badtitletext';
1383 $fname = 'Title::move';
1384 $oldid = $this->getArticleID();
1385 $newid = $nt->getArticleID();
1387 if ( strlen( $nt->getDBkey() ) < 1 ) {
1388 return 'articleexists';
1390 if ( ( ! Namespace::isMovable( $this->getNamespace() ) ) ||
1391 ( '' == $this->getDBkey() ) ||
1392 ( '' != $this->getInterwiki() ) ||
1394 ( ! Namespace::isMovable( $nt->getNamespace() ) ) ||
1395 ( '' == $nt->getDBkey() ) ||
1396 ( '' != $nt->getInterwiki() ) ) {
1397 return 'badarticleerror';
1401 !$this->userCanEdit() ||
!$nt->userCanEdit() ||
1402 !$this->userCanMove() ||
!$nt->userCanMove() ) ) {
1403 return 'protectedpage';
1406 # The move is allowed only if (1) the target doesn't exist, or
1407 # (2) the target is a redirect to the source, and has no history
1408 # (so we can undo bad moves right after they're done).
1410 if ( 0 != $newid ) { # Target exists; check for validity
1411 if ( ! $this->isValidMoveTarget( $nt ) ) {
1412 return 'articleexists';
1414 $this->moveOverExistingRedirect( $nt );
1415 } else { # Target didn't exist, do normal move.
1416 $this->moveToNewTitle( $nt, $newid );
1419 # Fixing category links (those without piped 'alternate' names) to be sorted under the new title
1421 $dbw =& wfGetDB( DB_MASTER
);
1422 $categorylinks = $dbw->tableName( 'categorylinks' );
1423 $sql = "UPDATE $categorylinks SET cl_sortkey=" . $dbw->addQuotes( $nt->getPrefixedText() ) .
1424 " WHERE cl_from=" . $dbw->addQuotes( $this->getArticleID() ) .
1425 " AND cl_sortkey=" . $dbw->addQuotes( $this->getPrefixedText() );
1426 $dbw->query( $sql, 'SpecialMovepage::doSubmit' );
1430 $oldnamespace = $this->getNamespace() & ~
1;
1431 $newnamespace = $nt->getNamespace() & ~
1;
1432 $oldtitle = $this->getDBkey();
1433 $newtitle = $nt->getDBkey();
1435 if( $oldnamespace != $newnamespace ||
$oldtitle != $newtitle ) {
1436 WatchedItem
::duplicateEntries( $this, $nt );
1439 # Update search engine
1440 $u = new SearchUpdate( $oldid, $nt->getPrefixedDBkey() );
1442 $u = new SearchUpdate( $newid, $this->getPrefixedDBkey(), '' );
1445 wfRunHooks( 'TitleMoveComplete', array(&$this, &$nt, &$wgUser, $oldid, $newid) );
1450 * Move page to a title which is at present a redirect to the
1453 * @param Title &$nt the page to move to, which should currently
1457 /* private */ function moveOverExistingRedirect( &$nt ) {
1458 global $wgUser, $wgLinkCache, $wgUseSquid, $wgMwRedir;
1459 $fname = 'Title::moveOverExistingRedirect';
1460 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
1462 $now = wfTimestampNow();
1464 $newid = $nt->getArticleID();
1465 $oldid = $this->getArticleID();
1466 $dbw =& wfGetDB( DB_MASTER
);
1467 $links = $dbw->tableName( 'links' );
1469 # Delete the old redirect. We don't save it to history since
1470 # by definition if we've got here it's rather uninteresting.
1471 # We have to remove it so that the next step doesn't trigger
1472 # a conflict on the unique namespace+title index...
1473 $dbw->delete( 'page', array( 'page_id' => $newid ), $fname );
1475 # Change the name of the target page:
1476 $dbw->update( 'page',
1478 'page_touched' => $dbw->timestamp($now),
1479 'page_namespace' => $nt->getNamespace(),
1480 'page_title' => $nt->getDBkey()
1482 /* WHERE */ array( 'page_id' => $oldid ),
1485 $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
1487 # Recreate the redirect, this time in the other direction.
1488 $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
1489 $redirectArticle = new Article( $this );
1490 $newid = $redirectArticle->insertOn( $dbw );
1491 $redirectRevision = new Revision( array(
1493 'comment' => $comment,
1494 'text' => $redirectText ) );
1495 $revid = $redirectRevision->insertOn( $dbw );
1496 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
1497 $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
1500 // Replaced by a log entry
1501 // RecentChange::notifyMoveOverRedirect( $now, $this, $nt, $wgUser, $comment );
1504 $log = new LogPage( 'move' );
1505 $log->addEntry( 'move_redir', $this, '', array(1 => $nt->getText()) );
1509 # Load titles and IDs
1510 $linksToOld = $this->getLinksTo( 'FOR UPDATE' );
1511 $linksToNew = $nt->getLinksTo( 'FOR UPDATE' );
1514 $sql = "DELETE FROM $links WHERE l_to=$oldid OR l_to=$newid";
1515 $dbw->query( $sql, $fname );
1518 if ( count( $linksToOld ) ||
count( $linksToNew )) {
1519 $sql = "INSERT INTO $links (l_from,l_to) VALUES ";
1522 # Insert links to old title
1523 foreach ( $linksToOld as $linkTitle ) {
1529 $id = $linkTitle->getArticleID();
1530 $sql .= "($id,$newid)";
1533 # Insert links to new title
1534 foreach ( $linksToNew as $linkTitle ) {
1540 $id = $linkTitle->getArticleID();
1541 $sql .= "($id, $oldid)";
1544 $dbw->query( $sql, DB_MASTER
, $fname );
1547 # Now, we record the link from the redirect to the new title.
1548 # It should have no other outgoing links...
1549 $dbw->delete( 'links', array( 'l_from' => $newid ) );
1550 $dbw->insert( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ) );
1553 LinkCache
::linksccClearLinksTo( $oldid );
1554 LinkCache
::linksccClearLinksTo( $newid );
1557 if ( $wgUseSquid ) {
1558 $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
1559 $u = new SquidUpdate( $urls );
1565 * Move page to non-existing title.
1566 * @param Title &$nt the new Title
1567 * @param int &$newid set to be the new article ID
1570 /* private */ function moveToNewTitle( &$nt, &$newid ) {
1571 global $wgUser, $wgLinkCache, $wgUseSquid;
1573 $fname = 'MovePageForm::moveToNewTitle';
1574 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
1576 $newid = $nt->getArticleID();
1577 $oldid = $this->getArticleID();
1578 $dbw =& wfGetDB( DB_MASTER
);
1579 $now = $dbw->timestamp();
1584 $dbw->update( 'page',
1586 'page_touched' => $now,
1587 'page_namespace' => $nt->getNamespace(),
1588 'page_title' => $nt->getDBkey()
1590 /* WHERE */ array( 'page_id' => $oldid ),
1594 $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
1597 $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
1598 $redirectArticle = new Article( $this );
1599 $newid = $redirectArticle->insertOn( $dbw );
1600 $redirectRevision = new Revision( array(
1602 'comment' => $comment,
1603 'text' => $redirectText ) );
1604 $revid = $redirectRevision->insertOn( $dbw );
1605 $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
1606 $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
1609 // Replaced by a log entry
1610 // RecentChange::notifyMoveToNew( $now, $this, $nt, $wgUser, $comment );
1613 $log = new LogPage( 'move' );
1614 $log->addEntry( 'move', $this, '', array(1 => $nt->getText()) );
1616 # Purge squid and linkscc as per article creation
1617 Article
::onArticleCreate( $nt );
1619 # Any text links to the old title must be reassigned to the redirect
1620 $dbw->update( 'links', array( 'l_to' => $newid ), array( 'l_to' => $oldid ), $fname );
1621 LinkCache
::linksccClearLinksTo( $oldid );
1623 # Record the just-created redirect's linking to the page
1624 $dbw->insert( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ), $fname );
1626 # Non-existent target may have had broken links to it; these must
1627 # now be removed and made into good links.
1628 $update = new LinksUpdate( $oldid, $nt->getPrefixedDBkey() );
1629 $update->fixBrokenLinks();
1631 # Purge old title from squid
1632 # The new title, and links to the new title, are purged in Article::onArticleCreate()
1633 $titles = $nt->getLinksTo();
1634 if ( $wgUseSquid ) {
1635 $urls = $this->getSquidURLs();
1636 foreach ( $titles as $linkTitle ) {
1637 $urls[] = $linkTitle->getInternalURL();
1639 $u = new SquidUpdate( $urls );
1645 * Checks if $this can be moved to a given Title
1646 * - Selects for update, so don't call it unless you mean business
1648 * @param Title &$nt the new title to check
1651 function isValidMoveTarget( $nt ) {
1653 $fname = 'Title::isValidMoveTarget';
1654 $dbw =& wfGetDB( DB_MASTER
);
1657 $id = $nt->getArticleID();
1658 $obj = $dbw->selectRow( array( 'page', 'text') ,
1659 array( 'page_is_redirect','old_text' ),
1660 array( 'page_id' => $id, 'page_latest=old_id' ),
1661 $fname, 'FOR UPDATE' );
1663 if ( !$obj ||
0 == $obj->page_is_redirect
) {
1668 # Does the redirect point to the source?
1669 if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $obj->old_text
, $m ) ) {
1670 $redirTitle = Title
::newFromText( $m[1] );
1671 if( !is_object( $redirTitle ) ||
1672 $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() ) {
1677 # Does the article have a history?
1678 $row = $dbw->selectRow( array( 'page', 'revision'),
1680 array( 'page_namespace' => $nt->getNamespace(),
1681 'page_title' => $nt->getDBkey(),
1682 'page_id=rev_page AND page_latest != rev_id'
1683 ), $fname, 'FOR UPDATE'
1686 # Return true if there was no history
1687 return $row === false;
1691 * Create a redirect; fails if the title already exists; does
1694 * @param Title $dest the destination of the redirect
1695 * @param string $comment the comment string describing the move
1696 * @return bool true on success
1699 function createRedirect( $dest, $comment ) {
1701 if ( $this->getArticleID() ) {
1705 $fname = 'Title::createRedirect';
1706 $dbw =& wfGetDB( DB_MASTER
);
1708 $article = new Article( $this );
1709 $newid = $article->insertOn( $dbw );
1710 $revision = new Revision( array(
1712 'comment' => $comment,
1713 'text' => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n",
1715 $revisionId = $revision->insertOn( $dbw );
1716 $article->updateRevisionOn( $dbw, $revision, 0 );
1719 if ( $dest->getArticleID() ) {
1720 $dbw->insert( 'links',
1722 'l_to' => $dest->getArticleID(),
1727 $dbw->insert( 'brokenlinks',
1729 'bl_to' => $dest->getPrefixedDBkey(),
1735 Article
::onArticleCreate( $this );
1740 * Get categories to which this Title belongs and return an array of
1741 * categories' names.
1743 * @return array an array of parents in the form:
1744 * $parent => $currentarticle
1747 function getParentCategories() {
1748 global $wgContLang,$wgUser;
1750 $titlekey = $this->getArticleId();
1751 $sk =& $wgUser->getSkin();
1753 $dbr =& wfGetDB( DB_SLAVE
);
1754 $categorylinks = $dbr->tableName( 'categorylinks' );
1757 $sql = "SELECT * FROM $categorylinks"
1758 ." WHERE cl_from='$titlekey'"
1759 ." AND cl_from <> '0'"
1760 ." ORDER BY cl_sortkey";
1762 $res = $dbr->query ( $sql ) ;
1764 if($dbr->numRows($res) > 0) {
1765 while ( $x = $dbr->fetchObject ( $res ) )
1766 //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
1767 $data[$wgContLang->getNSText ( NS_CATEGORY
).':'.$x->cl_to
] = $this->getFullText();
1768 $dbr->freeResult ( $res ) ;
1776 * Get a tree of parent categories
1777 * @param array $children an array with the children in the keys, to check for circular refs
1781 function getParentCategoryTree( $children = array() ) {
1782 $parents = $this->getParentCategories();
1784 if($parents != '') {
1785 foreach($parents as $parent => $current)
1787 if ( array_key_exists( $parent, $children ) ) {
1788 # Circular reference
1789 $stack[$parent] = array();
1791 $nt = Title
::newFromText($parent);
1792 $stack[$parent] = $nt->getParentCategoryTree( $children +
array($parent => 1) );
1803 * Get an associative array for selecting this title from
1809 function curCond() {
1810 wfDebugDieBacktrace( 'curCond called' );
1811 return array( 'cur_namespace' => $this->mNamespace
, 'cur_title' => $this->mDbkeyform
);
1815 * Get an associative array for selecting this title from the
1821 function oldCond() {
1822 wfDebugDieBacktrace( 'oldCond called' );
1823 return array( 'old_namespace' => $this->mNamespace
, 'old_title' => $this->mDbkeyform
);
1827 * Get the revision ID of the previous revision
1829 * @param integer $revision Revision ID. Get the revision that was before this one.
1830 * @return interger $oldrevision|false
1832 function getPreviousRevisionID( $revision ) {
1833 $dbr =& wfGetDB( DB_SLAVE
);
1834 return $dbr->selectField( 'revision', 'rev_id',
1835 'rev_page=' . IntVal( $this->getArticleId() ) .
1836 ' AND rev_id<' . IntVal( $revision ) . ' ORDER BY rev_id DESC' );
1840 * Get the revision ID of the next revision
1842 * @param integer $revision Revision ID. Get the revision that was after this one.
1843 * @return interger $oldrevision|false
1845 function getNextRevisionID( $revision ) {
1846 $dbr =& wfGetDB( DB_SLAVE
);
1847 return $dbr->selectField( 'revision', 'rev_id',
1848 'rev_page=' . IntVal( $this->getArticleId() ) .
1849 ' AND rev_id>' . IntVal( $revision ) . ' ORDER BY rev_id' );
1853 * Compare with another title.
1855 * @param Title $title
1858 function equals( &$title ) {
1859 return $this->getInterwiki() == $title->getInterwiki()
1860 && $this->getNamespace() == $title->getNamespace()
1861 && $this->getDbkey() == $title->getDbkey();