9 require_once( 'normal/UtfNormal.php' );
11 $wgTitleInterwikiCache = array();
12 define ( 'GAID_FOR_UPDATE', 1 );
16 * - Represents a title, which may contain an interwiki designation or namespace
17 * - Can fetch various kinds of data from the database, albeit inefficiently.
23 * All member variables should be considered private
24 * Please use the accessor functions
31 var $mTextform; # Text form (spaces not underscores) of the main part
32 var $mUrlform; # URL-encoded form of the main part
33 var $mDbkeyform; # Main part with underscores
34 var $mNamespace; # Namespace index, i.e. one of the NS_xxxx constants
35 var $mInterwiki; # Interwiki prefix (or null string)
36 var $mFragment; # Title fragment (i.e. the bit after the #)
37 var $mArticleID; # Article ID, fetched from the link cache on demand
38 var $mRestrictions; # Array of groups allowed to edit this article
39 # Only null or "sysop" are supported
40 var $mRestrictionsLoaded; # Boolean for initialisation on demand
41 var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
42 var $mDefaultNamespace; # Namespace index when there is no namespace
43 # Zero except in {{transclusion}} tags
51 /* private */ function Title() {
52 $this->mInterwiki
= $this->mUrlform
=
53 $this->mTextform
= $this->mDbkeyform
= '';
54 $this->mArticleID
= -1;
55 $this->mNamespace
= 0;
56 $this->mRestrictionsLoaded
= false;
57 $this->mRestrictions
= array();
58 # Dont change the following, NS_MAIN is hardcoded in several place
60 $this->mDefaultNamespace
= NS_MAIN
;
64 * Create a new Title from a prefixed DB key
65 * @param string $key The database key, which has underscores
66 * instead of spaces, possibly including namespace and
68 * @return Title the new object, or NULL on an error
72 /* static */ function newFromDBkey( $key ) {
74 $t->mDbkeyform
= $key;
75 if( $t->secureAndSplit() )
82 * Create a new Title from text, such as what one would
83 * find in a link. Decodes any HTML entities in the text.
85 * @param string $text the link text; spaces, prefixes,
86 * and an initial ':' indicating the main namespace
88 * @param int $defaultNamespace the namespace to use if
89 * none is specified by a prefix
90 * @return Title the new object, or NULL on an error
94 /* static */ function &newFromText( $text, $defaultNamespace = 0 ) {
95 $fname = 'Title::newFromText';
96 wfProfileIn( $fname );
99 * Wiki pages often contain multiple links to the same page.
100 * Title normalization and parsing can become expensive on
101 * pages with many links, so we can save a little time by
104 * In theory these are value objects and won't get changed...
106 static $titleCache = array();
107 if( $defaultNamespace == 0 && isset( $titleCache[$text] ) ) {
108 wfProfileOut( $fname );
109 return $titleCache[$text];
113 * Convert things like é into real text...
115 global $wgInputEncoding;
116 $filteredText = do_html_entity_decode( $text, ENT_COMPAT
, $wgInputEncoding );
119 * Convert things like ā or 〗 into real text...
120 * WARNING: Not friendly to internal links on a latin-1 wiki.
122 $filteredText = wfMungeToUtf8( $filteredText );
124 # What was this for? TS 2004-03-03
125 # $text = urldecode( $text );
128 $t->mDbkeyform
= str_replace( ' ', '_', $filteredText );
129 $t->mDefaultNamespace
= $defaultNamespace;
131 if( $t->secureAndSplit() ) {
132 if( $defaultNamespace == 0 ) {
133 $titleCache[$text] =& $t;
135 wfProfileOut( $fname );
138 wfProfileOut( $fname );
144 * Create a new Title from URL-encoded text. Ensures that
145 * the given title's length does not exceed the maximum.
146 * @param string $url the title, as might be taken from a URL
147 * @return Title the new object, or NULL on an error
151 /* static */ function newFromURL( $url ) {
152 global $wgLang, $wgServer;
155 # For compatibility with old buggy URLs. "+" is not valid in titles,
156 # but some URLs used it as a space replacement and they still come
157 # from some external search tools.
158 $s = str_replace( '+', ' ', $url );
160 $t->mDbkeyform
= str_replace( ' ', '_', $s );
161 if( $t->secureAndSplit() ) {
169 * Create a new Title from an article ID
170 * @todo This is inefficiently implemented, the page row is requested
171 * but not used for anything else
172 * @param int $id the page_id corresponding to the Title to create
173 * @return Title the new object, or NULL on an error
176 /* static */ function newFromID( $id ) {
177 $fname = 'Title::newFromID';
178 $dbr =& wfGetDB( DB_SLAVE
);
179 $row = $dbr->selectRow( 'page', array( 'page_namespace', 'page_title' ),
180 array( 'page_id' => $id ), $fname );
181 if ( $row !== false ) {
182 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
190 * Create a new Title from a namespace index and a DB key.
191 * It's assumed that $ns and $title are *valid*, for instance when
192 * they came directly from the database or a special page name.
193 * For convenience, spaces are converted to underscores so that
194 * eg user_text fields can be used directly.
196 * @param int $ns the namespace of the article
197 * @param string $title the unprefixed database key form
198 * @return Title the new object
202 /* static */ function &makeTitle( $ns, $title ) {
206 $t->mNamespace
= IntVal( $ns );
207 $t->mDbkeyform
= str_replace( ' ', '_', $title );
208 $t->mArticleID
= ( $ns >= 0 ) ?
-1 : 0;
209 $t->mUrlform
= wfUrlencode( $t->mDbkeyform
);
210 $t->mTextform
= str_replace( '_', ' ', $title );
215 * Create a new Title frrom a namespace index and a DB key.
216 * The parameters will be checked for validity, which is a bit slower
217 * than makeTitle() but safer for user-provided data.
218 * @param int $ns the namespace of the article
219 * @param string $title the database key form
220 * @return Title the new object, or NULL on an error
224 /* static */ function makeTitleSafe( $ns, $title ) {
226 $t->mDbkeyform
= Title
::makeName( $ns, $title );
227 if( $t->secureAndSplit() ) {
235 * Create a new Title for the Main Page
237 * @return Title the new object
240 /* static */ function newMainPage() {
241 return Title
::newFromText( wfMsgForContent( 'mainpage' ) );
245 * Create a new Title for a redirect
246 * @param string $text the redirect title text
247 * @return Title the new object, or NULL if the text is not a
252 /* static */ function newFromRedirect( $text ) {
255 if ( $wgMwRedir->matchStart( $text ) ) {
256 if ( preg_match( '/\\[\\[([^\\]\\|]+)[\\]\\|]/', $text, $m ) ) {
257 # categories are escaped using : for example one can enter:
258 # #REDIRECT [[:Category:Music]]. Need to remove it.
259 if ( substr($m[1],0,1) == ':') {
260 # We don't want to keep the ':'
261 $m[1] = substr( $m[1], 1 );
264 $rt = Title
::newFromText( $m[1] );
265 # Disallow redirects to Special:Userlogout
266 if ( !is_null($rt) && $rt->getNamespace() == NS_SPECIAL
&& preg_match( '/^Userlogout/i', $rt->getText() ) ) {
274 #----------------------------------------------------------------------------
276 #----------------------------------------------------------------------------
279 * Get the prefixed DB key associated with an ID
280 * @param int $id the page_id of the article
281 * @return Title an object representing the article, or NULL
282 * if no such article was found
286 /* static */ function nameOf( $id ) {
287 $fname = 'Title::nameOf';
288 $dbr =& wfGetDB( DB_SLAVE
);
290 $s = $dbr->selectRow( 'page', array( 'page_namespace','page_title' ), array( 'page_id' => $id ), $fname );
291 if ( $s === false ) { return NULL; }
293 $n = Title
::makeName( $s->page_namespace
, $s->page_title
);
298 * Get a regex character class describing the legal characters in a link
299 * @return string the list of characters, not delimited
303 /* static */ function legalChars() {
304 # Missing characters:
305 # * []|# Needed for link syntax
306 # * % and + are corrupted by Apache when they appear in the path
308 # % seems to work though
310 # The problem with % is that URLs are double-unescaped: once by Apache's
311 # path conversion code, and again by PHP. So %253F, for example, becomes "?".
312 # Our code does not double-escape to compensate for this, indeed double escaping
313 # would break if the double-escaped title was passed in the query string
314 # rather than the path. This is a minor security issue because articles can be
315 # created such that they are hard to view or edit. -- TS
317 # Theoretically 0x80-0x9F of ISO 8859-1 should be disallowed, but
318 # this breaks interlanguage links
320 $set = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF";
325 * Get a string representation of a title suitable for
326 * including in a search index
328 * @param int $ns a namespace index
329 * @param string $title text-form main part
330 * @return string a stripped-down title string ready for the
333 /* static */ function indexTitle( $ns, $title ) {
334 global $wgDBminWordLen, $wgContLang;
335 require_once( 'SearchEngine.php' );
337 $lc = SearchEngine
::legalSearchChars() . '&#;';
338 $t = $wgContLang->stripForSearch( $title );
339 $t = preg_replace( "/[^{$lc}]+/", ' ', $t );
340 $t = strtolower( $t );
343 $t = preg_replace( "/([{$lc}]+)'s( |$)/", "\\1 \\1's ", $t );
344 $t = preg_replace( "/([{$lc}]+)s'( |$)/", "\\1s ", $t );
346 $t = preg_replace( "/\\s+/", ' ', $t );
348 if ( $ns == NS_IMAGE
) {
349 $t = preg_replace( "/ (png|gif|jpg|jpeg|ogg)$/", "", $t );
355 * Make a prefixed DB key from a DB key and a namespace index
356 * @param int $ns numerical representation of the namespace
357 * @param string $title the DB key form the title
358 * @return string the prefixed form of the title
360 /* static */ function makeName( $ns, $title ) {
363 $n = $wgContLang->getNsText( $ns );
364 if ( '' == $n ) { return $title; }
365 else { return $n.':'.$title; }
369 * Returns the URL associated with an interwiki prefix
370 * @param string $key the interwiki prefix (e.g. "MeatBall")
371 * @return the associated URL, containing "$1", which should be
372 * replaced by an article title
376 function getInterwikiLink( $key ) {
377 global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgTitleInterwikiCache;
378 $fname = 'Title::getInterwikiLink';
380 wfProfileIn( $fname );
382 $k = $wgDBname.':interwiki:'.$key;
383 if( array_key_exists( $k, $wgTitleInterwikiCache ) ) {
384 wfProfileOut( $fname );
385 return $wgTitleInterwikiCache[$k]->iw_url
;
388 $s = $wgMemc->get( $k );
389 # Ignore old keys with no iw_local
390 if( $s && isset( $s->iw_local
) ) {
391 $wgTitleInterwikiCache[$k] = $s;
392 wfProfileOut( $fname );
396 $dbr =& wfGetDB( DB_SLAVE
);
397 $res = $dbr->select( 'interwiki',
398 array( 'iw_url', 'iw_local' ),
399 array( 'iw_prefix' => $key ), $fname );
401 wfProfileOut( $fname );
405 $s = $dbr->fetchObject( $res );
407 # Cache non-existence: create a blank object and save it to memcached
412 $wgMemc->set( $k, $s, $wgInterwikiExpiry );
413 $wgTitleInterwikiCache[$k] = $s;
415 wfProfileOut( $fname );
420 * Determine whether the object refers to a page within
423 * @return bool TRUE if this is an in-project interwiki link
424 * or a wikilink, FALSE otherwise
428 global $wgTitleInterwikiCache, $wgDBname;
430 if ( $this->mInterwiki
!= '' ) {
431 # Make sure key is loaded into cache
432 $this->getInterwikiLink( $this->mInterwiki
);
433 $k = $wgDBname.':interwiki:' . $this->mInterwiki
;
434 return (bool)($wgTitleInterwikiCache[$k]->iw_local
);
441 * Update the page_touched field for an array of title objects
442 * @todo Inefficient unless the IDs are already loaded into the
444 * @param array $titles an array of Title objects to be touched
445 * @param string $timestamp the timestamp to use instead of the
446 * default current time
450 /* static */ function touchArray( $titles, $timestamp = '' ) {
451 if ( count( $titles ) == 0 ) {
454 $dbw =& wfGetDB( DB_MASTER
);
455 if ( $timestamp == '' ) {
456 $timestamp = $dbw->timestamp();
458 $page = $dbw->tableName( 'page' );
459 $sql = "UPDATE $page SET page_touched='{$timestamp}' WHERE page_id IN (";
462 foreach ( $titles as $title ) {
467 $sql .= $title->getArticleID();
471 $dbw->query( $sql, 'Title::touchArray' );
475 #----------------------------------------------------------------------------
477 #----------------------------------------------------------------------------
479 /** Simple accessors */
481 * Get the text form (spaces not underscores) of the main part
485 function getText() { return $this->mTextform
; }
487 * Get the URL-encoded form of the main part
491 function getPartialURL() { return $this->mUrlform
; }
493 * Get the main part with underscores
497 function getDBkey() { return $this->mDbkeyform
; }
499 * Get the namespace index, i.e. one of the NS_xxxx constants
503 function getNamespace() { return $this->mNamespace
; }
505 * Get the interwiki prefix (or null string)
509 function getInterwiki() { return $this->mInterwiki
; }
511 * Get the Title fragment (i.e. the bit after the #)
515 function getFragment() { return $this->mFragment
; }
517 * Get the default namespace index, for when there is no namespace
521 function getDefaultNamespace() { return $this->mDefaultNamespace
; }
524 * Get title for search index
525 * @return string a stripped-down title string ready for the
528 function getIndexTitle() {
529 return Title
::indexTitle( $this->mNamespace
, $this->mTextform
);
533 * Get the prefixed database key form
534 * @return string the prefixed title, with underscores and
535 * any interwiki and namespace prefixes
538 function getPrefixedDBkey() {
539 $s = $this->prefix( $this->mDbkeyform
);
540 $s = str_replace( ' ', '_', $s );
545 * Get the prefixed title with spaces.
546 * This is the form usually used for display
547 * @return string the prefixed title, with spaces
550 function getPrefixedText() {
552 if ( empty( $this->mPrefixedText
) ) {
553 $s = $this->prefix( $this->mTextform
);
554 $s = str_replace( '_', ' ', $s );
555 $this->mPrefixedText
= $s;
557 return $this->mPrefixedText
;
561 * Get the prefixed title with spaces, plus any fragment
562 * (part beginning with '#')
563 * @return string the prefixed title, with spaces and
564 * the fragment, including '#'
567 function getFullText() {
569 $text = $this->getPrefixedText();
570 if( '' != $this->mFragment
) {
571 $text .= '#' . $this->mFragment
;
577 * Get a URL-encoded title (not an actual URL) including interwiki
578 * @return string the URL-encoded form
581 function getPrefixedURL() {
582 $s = $this->prefix( $this->mDbkeyform
);
583 $s = str_replace( ' ', '_', $s );
585 $s = wfUrlencode ( $s ) ;
587 # Cleaning up URL to make it look nice -- is this safe?
588 $s = str_replace( '%28', '(', $s );
589 $s = str_replace( '%29', ')', $s );
595 * Get a real URL referring to this title, with interwiki link and
598 * @param string $query an optional query string, not used
599 * for interwiki links
600 * @return string the URL
603 function getFullURL( $query = '' ) {
604 global $wgContLang, $wgArticlePath, $wgServer, $wgScript;
606 if ( '' == $this->mInterwiki
) {
608 return $wgServer . $this->getLocalUrl( $query );
610 $baseUrl = $this->getInterwikiLink( $this->mInterwiki
);
611 $namespace = $wgContLang->getNsText( $this->mNamespace
);
612 if ( '' != $namespace ) {
613 # Can this actually happen? Interwikis shouldn't be parsed.
616 $url = str_replace( '$1', $namespace . $this->mUrlform
, $baseUrl );
617 if ( '' != $this->mFragment
) {
618 $url .= '#' . $this->mFragment
;
625 * Get a URL with no fragment or server name
626 * @param string $query an optional query string; if not specified,
627 * $wgArticlePath will be used.
628 * @return string the URL
631 function getLocalURL( $query = '' ) {
632 global $wgLang, $wgArticlePath, $wgScript;
634 if ( $this->isExternal() ) {
635 return $this->getFullURL();
638 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
639 if ( $query == '' ) {
640 $url = str_replace( '$1', $dbkey, $wgArticlePath );
642 if ( $query == '-' ) {
645 $url = "{$wgScript}?title={$dbkey}&{$query}";
651 * Get an HTML-escaped version of the URL form, suitable for
652 * using in a link, without a server name or fragment
653 * @param string $query an optional query string
654 * @return string the URL
657 function escapeLocalURL( $query = '' ) {
658 return htmlspecialchars( $this->getLocalURL( $query ) );
662 * Get an HTML-escaped version of the URL form, suitable for
663 * using in a link, including the server name and fragment
665 * @return string the URL
666 * @param string $query an optional query string
669 function escapeFullURL( $query = '' ) {
670 return htmlspecialchars( $this->getFullURL( $query ) );
674 * Get the URL form for an internal link.
675 * - Used in various Squid-related code, in case we have a different
676 * internal hostname for the server from the exposed one.
678 * @param string $query an optional query string
679 * @return string the URL
682 function getInternalURL( $query = '' ) {
683 global $wgInternalServer;
684 return $wgInternalServer . $this->getLocalURL( $query );
688 * Get the edit URL for this Title
689 * @return string the URL, or a null string if this is an
693 function getEditURL() {
694 global $wgServer, $wgScript;
696 if ( '' != $this->mInterwiki
) { return ''; }
697 $s = $this->getLocalURL( 'action=edit' );
703 * Get the HTML-escaped displayable text form.
704 * Used for the title field in <a> tags.
705 * @return string the text, including any prefixes
708 function getEscapedText() {
709 return htmlspecialchars( $this->getPrefixedText() );
713 * Is this Title interwiki?
717 function isExternal() { return ( '' != $this->mInterwiki
); }
720 * Does the title correspond to a protected article?
721 * @param string $what the action the page is protected from,
722 * by default checks move and edit
726 function isProtected($action = '') {
727 if ( -1 == $this->mNamespace
) { return true; }
728 if($action == 'edit' ||
$action == '') {
729 $a = $this->getRestrictions("edit");
730 if ( in_array( 'sysop', $a ) ) { return true; }
732 if($action == 'move' ||
$action == '') {
733 $a = $this->getRestrictions("move");
734 if ( in_array( 'sysop', $a ) ) { return true; }
740 * Is $wgUser is watching this page?
744 function userIsWatching() {
747 if ( -1 == $this->mNamespace
) { return false; }
748 if ( 0 == $wgUser->getID() ) { return false; }
750 return $wgUser->isWatched( $this );
754 * Is $wgUser perform $action this page?
755 * @param string $action action that permission needs to be checked for
759 function userCan($action) {
760 $fname = 'Title::userCanEdit';
761 wfProfileIn( $fname );
764 if( NS_SPECIAL
== $this->mNamespace
) {
765 wfProfileOut( $fname );
768 if( NS_MEDIAWIKI
== $this->mNamespace
&&
769 !$wgUser->isAllowed('editinterface') ) {
770 wfProfileOut( $fname );
773 if( $this->mDbkeyform
== '_' ) {
774 # FIXME: Is this necessary? Shouldn't be allowed anyway...
775 wfProfileOut( $fname );
779 # protect global styles and js
780 if ( NS_MEDIAWIKI
== $this->mNamespace
781 && preg_match("/\\.(css|js)$/", $this->mTextform
)
782 && !$wgUser->isAllowed('editinterface') ) {
783 wfProfileOut( $fname );
787 # protect css/js subpages of user pages
788 # XXX: this might be better using restrictions
789 # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
790 if( NS_USER
== $this->mNamespace
791 && preg_match("/\\.(css|js)$/", $this->mTextform
)
792 && !$wgUser->isAllowed('editinterface')
793 && !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) ) {
794 wfProfileOut( $fname );
798 foreach( $this->getRestrictions($action) as $right ) {
799 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
800 wfProfileOut( $fname );
804 wfProfileOut( $fname );
809 * Can $wgUser edit this page?
813 function userCanEdit() {
814 return $this->userCan('edit');
818 * Can $wgUser move this page?
822 function userCanMove() {
823 return $this->userCan('move');
827 * Can $wgUser read this page?
831 function userCanRead() {
834 if( $wgUser->isAllowed('read') ) {
837 global $wgWhitelistRead;
839 /** If anon users can create an account,
840 they need to reach the login page first! */
841 if( $wgUser->isAllowed( 'createaccount' )
842 && $this->mId
== NS_SPECIAL
843 && $this->getText() == 'Userlogin' ) {
847 /** some pages are explicitly allowed */
848 $name = $this->getPrefixedText();
849 if( in_array( $name, $wgWhitelistRead ) ) {
853 # Compatibility with old settings
854 if( $this->getNamespace() == NS_MAIN
) {
855 if( in_array( ':' . $name, $wgWhitelistRead ) ) {
864 * Is this a .css or .js subpage of a user page?
868 function isCssJsSubpage() {
869 return ( NS_USER
== $this->mNamespace
and preg_match("/\\.(css|js)$/", $this->mTextform
) );
872 * Is this a .css subpage of a user page?
876 function isCssSubpage() {
877 return ( NS_USER
== $this->mNamespace
and preg_match("/\\.css$/", $this->mTextform
) );
880 * Is this a .js subpage of a user page?
884 function isJsSubpage() {
885 return ( NS_USER
== $this->mNamespace
and preg_match("/\\.js$/", $this->mTextform
) );
888 * Protect css/js subpages of user pages: can $wgUser edit
892 * @todo XXX: this might be better using restrictions
895 function userCanEditCssJsSubpage() {
897 return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) );
901 * Loads a string into mRestrictions array
902 * @param string $res restrictions in string format
905 function loadRestrictions( $res ) {
906 foreach( explode( ':', trim( $res ) ) as $restrict ) {
907 $temp = explode( '=', trim( $restrict ) );
908 if(count($temp) == 1) {
909 // old format should be treated as edit/move restriction
910 $this->mRestrictions
["edit"] = explode( ',', trim( $temp[0] ) );
911 $this->mRestrictions
["move"] = explode( ',', trim( $temp[0] ) );
913 $this->mRestrictions
[$temp[0]] = explode( ',', trim( $temp[1] ) );
916 $this->mRestrictionsLoaded
= true;
920 * Accessor/initialisation for mRestrictions
921 * @param string $action action that permission needs to be checked for
922 * @return array the array of groups allowed to edit this article
925 function getRestrictions($action) {
926 $id = $this->getArticleID();
927 if ( 0 == $id ) { return array(); }
929 if ( ! $this->mRestrictionsLoaded
) {
930 $dbr =& wfGetDB( DB_SLAVE
);
931 $res = $dbr->selectField( 'page', 'page_restrictions', 'page_id='.$id );
932 $this->loadRestrictions( $res );
934 if( isset( $this->mRestrictions
[$action] ) ) {
935 return $this->mRestrictions
[$action];
941 * Is there a version of this page in the deletion archive?
942 * @return int the number of archived revisions
945 function isDeleted() {
946 $fname = 'Title::isDeleted';
947 $dbr =& wfGetDB( DB_SLAVE
);
948 $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
949 'ar_title' => $this->getDBkey() ), $fname );
954 * Get the article ID for this Title from the link cache,
955 * adding it if necessary
956 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select
961 function getArticleID( $flags = 0 ) {
964 if ( $flags & GAID_FOR_UPDATE
) {
965 $oldUpdate = $wgLinkCache->forUpdate( true );
966 $this->mArticleID
= $wgLinkCache->addLinkObj( $this );
967 $wgLinkCache->forUpdate( $oldUpdate );
969 if ( -1 == $this->mArticleID
) {
970 $this->mArticleID
= $wgLinkCache->addLinkObj( $this );
973 return $this->mArticleID
;
977 * This clears some fields in this object, and clears any associated
978 * keys in the "bad links" section of $wgLinkCache.
980 * - This is called from Article::insertNewArticle() to allow
981 * loading of the new page_id. It's also called from
982 * Article::doDeleteArticle()
984 * @param int $newid the new Article ID
987 function resetArticleID( $newid ) {
989 $wgLinkCache->clearBadLink( $this->getPrefixedDBkey() );
991 if ( 0 == $newid ) { $this->mArticleID
= -1; }
992 else { $this->mArticleID
= $newid; }
993 $this->mRestrictionsLoaded
= false;
994 $this->mRestrictions
= array();
998 * Updates page_touched for this page; called from LinksUpdate.php
999 * @return bool true if the update succeded
1002 function invalidateCache() {
1003 $now = wfTimestampNow();
1004 $dbw =& wfGetDB( DB_MASTER
);
1005 $success = $dbw->update( 'page',
1007 'page_touched' => $dbw->timestamp()
1008 ), array( /* WHERE */
1009 'page_namespace' => $this->getNamespace() ,
1010 'page_title' => $this->getDBkey()
1011 ), 'Title::invalidateCache'
1017 * Prefix some arbitrary text with the namespace or interwiki prefix
1020 * @param string $name the text
1021 * @return string the prefixed text
1024 /* private */ function prefix( $name ) {
1028 if ( '' != $this->mInterwiki
) {
1029 $p = $this->mInterwiki
. ':';
1031 if ( 0 != $this->mNamespace
) {
1032 $p .= $wgContLang->getNsText( $this->mNamespace
) . ':';
1038 * Secure and split - main initialisation function for this object
1040 * Assumes that mDbkeyform has been set, and is urldecoded
1041 * and uses underscores, but not otherwise munged. This function
1042 * removes illegal characters, splits off the interwiki and
1043 * namespace prefixes, sets the other forms, and canonicalizes
1045 * @return bool true on success
1048 /* private */ function secureAndSplit() {
1049 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
1050 $fname = 'Title::secureAndSplit';
1051 wfProfileIn( $fname );
1054 static $rxTc = false;
1056 # % is needed as well
1057 $rxTc = '/[^' . Title
::legalChars() . ']|%[0-9A-Fa-f]{2}/S';
1060 $this->mInterwiki
= $this->mFragment
= '';
1061 $this->mNamespace
= $this->mDefaultNamespace
; # Usually NS_MAIN
1063 # Clean up whitespace
1065 $t = preg_replace( '/[\\s_]+/', '_', $this->mDbkeyform
);
1066 $t = trim( $t, '_' );
1069 wfProfileOut( $fname );
1073 global $wgUseLatin1;
1074 if( !$wgUseLatin1 && false !== strpos( $t, UTF8_REPLACEMENT
) ) {
1075 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
1076 wfProfileOut( $fname );
1080 $this->mDbkeyform
= $t;
1082 # Initial colon indicating main namespace
1083 if ( ':' == $t{0} ) {
1084 $r = substr( $t, 1 );
1085 $this->mNamespace
= NS_MAIN
;
1087 # Namespace or interwiki prefix
1090 if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $t, $m ) ) {
1092 $lowerNs = strtolower( $p );
1093 if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
1094 # Canonical namespace
1096 $this->mNamespace
= $ns;
1097 } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) {
1098 # Ordinary namespace
1100 $this->mNamespace
= $ns;
1101 } elseif( $this->getInterwikiLink( $p ) ) {
1103 # Can't make a local interwiki link to an interwiki link.
1104 # That's just crazy!
1105 wfProfileOut( $fname );
1111 $this->mInterwiki
= $p;
1113 # Redundant interwiki prefix to the local wiki
1114 if ( 0 == strcasecmp( $this->mInterwiki
, $wgLocalInterwiki ) ) {
1116 # Can't have an empty self-link
1117 wfProfileOut( $fname );
1120 $this->mInterwiki
= '';
1122 # Do another namespace split...
1126 # If there's no recognized interwiki or namespace,
1127 # then let the colon expression be part of the title.
1134 # We already know that some pages won't be in the database!
1136 if ( '' != $this->mInterwiki ||
-1 == $this->mNamespace
) {
1137 $this->mArticleID
= 0;
1139 $f = strstr( $r, '#' );
1140 if ( false !== $f ) {
1141 $this->mFragment
= substr( $f, 1 );
1142 $r = substr( $r, 0, strlen( $r ) - strlen( $f ) );
1143 # remove whitespace again: prevents "Foo_bar_#"
1144 # becoming "Foo_bar_"
1145 $r = preg_replace( '/_*$/', '', $r );
1148 # Reject illegal characters.
1150 if( preg_match( $rxTc, $r ) ) {
1151 wfProfileOut( $fname );
1156 * Pages with "/./" or "/../" appearing in the URLs will
1157 * often be unreachable due to the way web browsers deal
1158 * with 'relative' URLs. Forbid them explicitly.
1160 if ( strpos( $r, '.' ) !== false &&
1161 ( $r === '.' ||
$r === '..' ||
1162 strpos( $r, './' ) === 0 ||
1163 strpos( $r, '../' ) === 0 ||
1164 strpos( $r, '/./' ) !== false ||
1165 strpos( $r, '/../' ) !== false ) )
1167 wfProfileOut( $fname );
1171 # We shouldn't need to query the DB for the size.
1172 #$maxSize = $dbr->textFieldSize( 'page', 'page_title' );
1173 if ( strlen( $r ) > 255 ) {
1178 * Normally, all wiki links are forced to have
1179 * an initial capital letter so [[foo]] and [[Foo]]
1180 * point to the same place.
1182 * Don't force it for interwikis, since the other
1183 * site might be case-sensitive.
1185 if( $wgCapitalLinks && $this->mInterwiki
== '') {
1186 $t = $wgContLang->ucfirst( $r );
1192 $this->mDbkeyform
= $t;
1193 $this->mUrlform
= wfUrlencode( $t );
1195 $this->mTextform
= str_replace( '_', ' ', $t );
1197 wfProfileOut( $fname );
1202 * Get a Title object associated with the talk page of this article
1203 * @return Title the object for the talk page
1206 function getTalkPage() {
1207 return Title
::makeTitle( Namespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
1211 * Get a title object associated with the subject page of this
1214 * @return Title the object for the subject page
1217 function getSubjectPage() {
1218 return Title
::makeTitle( Namespace::getSubject( $this->getNamespace() ), $this->getDBkey() );
1222 * Get an array of Title objects linking to this Title
1223 * - Also stores the IDs in the link cache.
1225 * @param string $options may be FOR UPDATE
1226 * @return array the Title objects linking here
1229 function getLinksTo( $options = '' ) {
1230 global $wgLinkCache;
1231 $id = $this->getArticleID();
1234 $db =& wfGetDB( DB_MASTER
);
1236 $db =& wfGetDB( DB_SLAVE
);
1238 $page = $db->tableName( 'page' );
1239 $links = $db->tableName( 'links' );
1241 $sql = "SELECT page_namespace,page_title,page_id FROM $page,$links WHERE l_from=page_id AND l_to={$id} $options";
1242 $res = $db->query( $sql, 'Title::getLinksTo' );
1244 if ( $db->numRows( $res ) ) {
1245 while ( $row = $db->fetchObject( $res ) ) {
1246 if ( $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
) ) {
1247 $wgLinkCache->addGoodLink( $row->page_id
, $titleObj->getPrefixedDBkey() );
1248 $retVal[] = $titleObj;
1252 $db->freeResult( $res );
1257 * Get an array of Title objects linking to this non-existent title.
1258 * - Also stores the IDs in the link cache.
1260 * @param string $options may be FOR UPDATE
1261 * @return array the Title objects linking here
1264 function getBrokenLinksTo( $options = '' ) {
1265 global $wgLinkCache;
1268 $db =& wfGetDB( DB_MASTER
);
1270 $db =& wfGetDB( DB_SLAVE
);
1272 $page = $db->tableName( 'page' );
1273 $brokenlinks = $db->tableName( 'brokenlinks' );
1274 $encTitle = $db->strencode( $this->getPrefixedDBkey() );
1276 $sql = "SELECT page_namespace,page_title,page_id FROM $brokenlinks,$page " .
1277 "WHERE bl_from=page_id AND bl_to='$encTitle' $options";
1278 $res = $db->query( $sql, "Title::getBrokenLinksTo" );
1280 if ( $db->numRows( $res ) ) {
1281 while ( $row = $db->fetchObject( $res ) ) {
1282 $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
1283 $wgLinkCache->addGoodLink( $row->page_id
, $titleObj->getPrefixedDBkey() );
1284 $retVal[] = $titleObj;
1287 $db->freeResult( $res );
1292 * Get a list of URLs to purge from the Squid cache when this
1295 * @return array the URLs
1298 function getSquidURLs() {
1300 $this->getInternalURL(),
1301 $this->getInternalURL( 'action=history' )
1306 * Move this page without authentication
1307 * @param Title &$nt the new page Title
1310 function moveNoAuth( &$nt ) {
1311 return $this->moveTo( $nt, false );
1315 * Move a title to a new location
1316 * @param Title &$nt the new title
1317 * @param bool $auth indicates whether $wgUser's permissions
1319 * @return mixed true on success, message name on failure
1322 function moveTo( &$nt, $auth = true ) {
1323 if( !$this or !$nt ) {
1324 return 'badtitletext';
1327 $fname = 'Title::move';
1328 $oldid = $this->getArticleID();
1329 $newid = $nt->getArticleID();
1331 if ( strlen( $nt->getDBkey() ) < 1 ) {
1332 return 'articleexists';
1334 if ( ( ! Namespace::isMovable( $this->getNamespace() ) ) ||
1335 ( '' == $this->getDBkey() ) ||
1336 ( '' != $this->getInterwiki() ) ||
1338 ( ! Namespace::isMovable( $nt->getNamespace() ) ) ||
1339 ( '' == $nt->getDBkey() ) ||
1340 ( '' != $nt->getInterwiki() ) ) {
1341 return 'badarticleerror';
1345 !$this->userCanEdit() ||
!$nt->userCanEdit() ||
1346 !$this->userCanMove() ||
!$nt->userCanMove() ) ) {
1347 return 'protectedpage';
1350 # The move is allowed only if (1) the target doesn't exist, or
1351 # (2) the target is a redirect to the source, and has no history
1352 # (so we can undo bad moves right after they're done).
1354 if ( 0 != $newid ) { # Target exists; check for validity
1355 if ( ! $this->isValidMoveTarget( $nt ) ) {
1356 return 'articleexists';
1358 $this->moveOverExistingRedirect( $nt );
1359 } else { # Target didn't exist, do normal move.
1360 $this->moveToNewTitle( $nt, $newid );
1363 # Fixing category links (those without piped 'alternate' names) to be sorted under the new title
1365 $dbw =& wfGetDB( DB_MASTER
);
1366 $categorylinks = $dbw->tableName( 'categorylinks' );
1367 $sql = "UPDATE $categorylinks SET cl_sortkey=" . $dbw->addQuotes( $nt->getPrefixedText() ) .
1368 " WHERE cl_from=" . $dbw->addQuotes( $this->getArticleID() ) .
1369 " AND cl_sortkey=" . $dbw->addQuotes( $this->getPrefixedText() );
1370 $dbw->query( $sql, 'SpecialMovepage::doSubmit' );
1374 $oldnamespace = $this->getNamespace() & ~
1;
1375 $newnamespace = $nt->getNamespace() & ~
1;
1376 $oldtitle = $this->getDBkey();
1377 $newtitle = $nt->getDBkey();
1379 if( $oldnamespace != $newnamespace ||
$oldtitle != $newtitle ) {
1380 WatchedItem
::duplicateEntries( $this, $nt );
1383 # Update search engine
1384 $u = new SearchUpdate( $oldid, $nt->getPrefixedDBkey() );
1386 $u = new SearchUpdate( $newid, $this->getPrefixedDBkey(), '' );
1393 * Move page to a title which is at present a redirect to the
1396 * @param Title &$nt the page to move to, which should currently
1400 /* private */ function moveOverExistingRedirect( &$nt ) {
1401 global $wgUser, $wgLinkCache, $wgUseSquid, $wgMwRedir;
1402 $fname = 'Title::moveOverExistingRedirect';
1403 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
1405 $now = wfTimestampNow();
1406 $won = wfInvertTimestamp( $now );
1408 $newid = $nt->getArticleID();
1409 $oldid = $this->getArticleID();
1410 $dbw =& wfGetDB( DB_MASTER
);
1411 $links = $dbw->tableName( 'links' );
1413 # Delete the old redirect. We don't save it to history since
1414 # by definition if we've got here it's rather uninteresting.
1415 # We have to remove it so that the next step doesn't trigger
1416 # a conflict on the unique namespace+title index...
1417 $dbw->delete( 'page', array( 'page_id' => $newid ), $fname );
1419 # Change the name of the target page:
1420 $dbw->update( 'page',
1422 'page_touched' => $dbw->timestamp($now),
1423 'page_namespace' => $nt->getNamespace(),
1424 'page_title' => $nt->getDBkey()
1426 /* WHERE */ array( 'page_id' => $oldid ),
1429 $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
1431 # Recreate the redirect, this time in the other direction.
1432 $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
1433 $dbw->insert( 'revision', array(
1434 'rev_id' => $dbw->nextSequenceValue('rev_rev_id_seq'),
1435 'rev_comment' => $comment,
1436 'rev_user' => $wgUser->getID(),
1437 'rev_user_text' => $wgUser->getName(),
1438 'rev_timestamp' => $now,
1439 'inverse_timestamp' => $won ), $fname
1441 $revid = $dbw->insertId();
1442 $dbw->insert( 'text', array(
1445 'old_text' => $redirectText,
1448 $dbw->insert( 'page', array(
1449 'page_id' => $dbw->nextSequenceValue('page_page_id_seq'),
1450 'page_namespace' => $this->getNamespace(),
1451 'page_title' => $this->getDBkey(),
1452 'page_touched' => $now,
1453 'page_is_redirect' => 1,
1454 'page_random' => $rand,
1456 'page_latest' => $revid), $fname
1458 $newid = $dbw->insertId();
1459 $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
1461 RecentChange
::notifyMoveOverRedirect( $now, $this, $nt, $wgUser, $comment );
1465 # Load titles and IDs
1466 $linksToOld = $this->getLinksTo( 'FOR UPDATE' );
1467 $linksToNew = $nt->getLinksTo( 'FOR UPDATE' );
1470 $sql = "DELETE FROM $links WHERE l_to=$oldid OR l_to=$newid";
1471 $dbw->query( $sql, $fname );
1474 if ( count( $linksToOld ) ||
count( $linksToNew )) {
1475 $sql = "INSERT INTO $links (l_from,l_to) VALUES ";
1478 # Insert links to old title
1479 foreach ( $linksToOld as $linkTitle ) {
1485 $id = $linkTitle->getArticleID();
1486 $sql .= "($id,$newid)";
1489 # Insert links to new title
1490 foreach ( $linksToNew as $linkTitle ) {
1496 $id = $linkTitle->getArticleID();
1497 $sql .= "($id, $oldid)";
1500 $dbw->query( $sql, DB_MASTER
, $fname );
1503 # Now, we record the link from the redirect to the new title.
1504 # It should have no other outgoing links...
1505 $dbw->delete( 'links', array( 'l_from' => $newid ) );
1506 $dbw->insert( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ) );
1509 LinkCache
::linksccClearLinksTo( $oldid );
1510 LinkCache
::linksccClearLinksTo( $newid );
1513 if ( $wgUseSquid ) {
1514 $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
1515 $u = new SquidUpdate( $urls );
1521 * Move page to non-existing title.
1522 * @param Title &$nt the new Title
1523 * @param int &$newid set to be the new article ID
1526 /* private */ function moveToNewTitle( &$nt, &$newid ) {
1527 global $wgUser, $wgLinkCache, $wgUseSquid;
1529 $fname = 'MovePageForm::moveToNewTitle';
1530 $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
1532 $newid = $nt->getArticleID();
1533 $oldid = $this->getArticleID();
1534 $dbw =& wfGetDB( DB_MASTER
);
1535 $now = $dbw->timestamp();
1536 $won = wfInvertTimestamp( wfTimestamp(TS_MW
,$now) );
1541 $dbw->update( 'page',
1543 'page_touched' => $now,
1544 'page_namespace' => $nt->getNamespace(),
1545 'page_title' => $nt->getDBkey()
1547 /* WHERE */ array( 'page_id' => $oldid ),
1551 $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
1554 $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
1555 $dbw->insert( 'revision', array(
1556 'rev_id' => $dbw->nextSequenceValue('rev_rev_id_seq'),
1557 'rev_comment' => $comment,
1558 'rev_user' => $wgUser->getID(),
1559 'rev_user_text' => $wgUser->getName(),
1560 'rev_timestamp' => $now,
1561 'inverse_timestamp' => $won ), $fname
1563 $revid = $dbw->insertId();
1564 $dbw->insert( 'text', array(
1567 'old_text' => $redirectText
1570 $dbw->insert( 'page', array(
1571 'page_id' => $dbw->nextSequenceValue('page_page_id_seq'),
1572 'page_namespace' => $this->getNamespace(),
1573 'page_title' => $this->getDBkey(),
1574 'page_touched' => $now,
1575 'page_is_redirect' => 1,
1576 'page_random' => $rand,
1578 'page_latest' => $revid), $fname
1580 $newid = $dbw->insertId();
1581 $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
1584 RecentChange
::notifyMoveToNew( $now, $this, $nt, $wgUser, $comment );
1586 # Purge squid and linkscc as per article creation
1587 Article
::onArticleCreate( $nt );
1589 # Any text links to the old title must be reassigned to the redirect
1590 $dbw->update( 'links', array( 'l_to' => $newid ), array( 'l_to' => $oldid ), $fname );
1591 LinkCache
::linksccClearLinksTo( $oldid );
1593 # Record the just-created redirect's linking to the page
1594 $dbw->insert( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ), $fname );
1596 # Non-existent target may have had broken links to it; these must
1597 # now be removed and made into good links.
1598 $update = new LinksUpdate( $oldid, $nt->getPrefixedDBkey() );
1599 $update->fixBrokenLinks();
1601 # Purge old title from squid
1602 # The new title, and links to the new title, are purged in Article::onArticleCreate()
1603 $titles = $nt->getLinksTo();
1604 if ( $wgUseSquid ) {
1605 $urls = $this->getSquidURLs();
1606 foreach ( $titles as $linkTitle ) {
1607 $urls[] = $linkTitle->getInternalURL();
1609 $u = new SquidUpdate( $urls );
1615 * Checks if $this can be moved to a given Title
1616 * - Selects for update, so don't call it unless you mean business
1618 * @param Title &$nt the new title to check
1621 function isValidMoveTarget( $nt ) {
1623 $fname = 'Title::isValidMoveTarget';
1624 $dbw =& wfGetDB( DB_MASTER
);
1627 $id = $nt->getArticleID();
1628 $obj = $dbw->selectRow( array( 'page', 'text') ,
1629 array( 'page_is_redirect','old_text' ),
1630 array( 'page_id' => $id, 'page_latest=old_id' ),
1631 $fname, 'FOR UPDATE' );
1633 if ( !$obj ||
0 == $obj->page_is_redirect
) {
1638 # Does the redirect point to the source?
1639 if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $obj->old_text
, $m ) ) {
1640 $redirTitle = Title
::newFromText( $m[1] );
1641 if( !is_object( $redirTitle ) ||
1642 $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() ) {
1647 # Does the article have a history?
1648 $row = $dbw->selectRow( array( 'page', 'revision'),
1650 array( 'page_namespace' => $nt->getNamespace(),
1651 'page_title' => $nt->getDBkey(),
1652 'page_id=rev_page AND page_latest != rev_id'
1653 ), $fname, 'FOR UPDATE'
1656 # Return true if there was no history
1657 return $row === false;
1661 * Create a redirect; fails if the title already exists; does
1664 * @param Title $dest the destination of the redirect
1665 * @param string $comment the comment string describing the move
1666 * @return bool true on success
1669 function createRedirect( $dest, $comment ) {
1671 if ( $this->getArticleID() ) {
1675 $fname = 'Title::createRedirect';
1676 $dbw =& wfGetDB( DB_MASTER
);
1677 $now = wfTimestampNow();
1678 $won = wfInvertTimestamp( $now );
1680 $seqVal = $dbw->nextSequenceValue( 'page_page_id_seq' );
1681 $dbw->insert( 'page', array(
1682 'page_id' => $seqVal,
1683 'page_namespace' => $this->getNamespace(),
1684 'page_title' => $this->getDBkey(),
1685 'page_touched' => $now,
1686 'page_is_redirect' => 1,
1688 'page_latest' => NULL,
1690 $newid = $dbw->insertId();
1692 $seqVal = $dbw->nextSequenceValue( 'text_old_id_seq' );
1693 $dbw->insert( 'text', array(
1694 'old_id' => $seqVal,
1696 'old_text' => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n"
1698 $revisionId = $dbw->insertId();
1700 $dbw->insert( 'revision', array(
1701 'rev_id' => $seqVal,
1702 'rev_page' => $newid,
1703 'rev_comment' => $comment,
1704 'rev_user' => $wgUser->getID(),
1705 'rev_user_text' => $wgUser->getName(),
1706 'rev_timestamp' => $now,
1707 'inverse_timestamp' => $won,
1710 $dbw->update( 'page',
1711 /* SET */ array( 'page_latest' => $revisionId ),
1712 /* WHERE */ array( 'page_id' => $newid ),
1714 $this->resetArticleID( $newid );
1717 if ( $dest->getArticleID() ) {
1718 $dbw->insert( 'links',
1720 'l_to' => $dest->getArticleID(),
1725 $dbw->insert( 'brokenlinks',
1727 'bl_to' => $dest->getPrefixedDBkey(),
1733 Article
::onArticleCreate( $this );
1738 * Get categories to which this Title belongs and return an array of
1739 * categories' names.
1741 * @return array an array of parents in the form:
1742 * $parent => $currentarticle
1745 function getParentCategories() {
1746 global $wgContLang,$wgUser;
1748 $titlekey = $this->getArticleId();
1749 $sk =& $wgUser->getSkin();
1751 $dbr =& wfGetDB( DB_SLAVE
);
1752 $categorylinks = $dbr->tableName( 'categorylinks' );
1755 $sql = "SELECT * FROM $categorylinks"
1756 ." WHERE cl_from='$titlekey'"
1757 ." AND cl_from <> '0'"
1758 ." ORDER BY cl_sortkey";
1760 $res = $dbr->query ( $sql ) ;
1762 if($dbr->numRows($res) > 0) {
1763 while ( $x = $dbr->fetchObject ( $res ) )
1764 //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
1765 $data[$wgContLang->getNSText ( NS_CATEGORY
).':'.$x->cl_to
] = $this->getFullText();
1766 $dbr->freeResult ( $res ) ;
1774 * Get a tree of parent categories
1775 * @param array $children an array with the children in the keys, to check for circular refs
1779 function getParentCategoryTree( $children = array() ) {
1780 $parents = $this->getParentCategories();
1782 if($parents != '') {
1783 foreach($parents as $parent => $current)
1785 if ( array_key_exists( $parent, $children ) ) {
1786 # Circular reference
1787 $stack[$parent] = array();
1789 $nt = Title
::newFromText($parent);
1790 $stack[$parent] = $nt->getParentCategoryTree( $children +
array($parent => 1) );
1801 * Get an associative array for selecting this title from
1807 function curCond() {
1808 wfDebugDieBacktrace( 'curCond called' );
1809 return array( 'cur_namespace' => $this->mNamespace
, 'cur_title' => $this->mDbkeyform
);
1813 * Get an associative array for selecting this title from the
1819 function oldCond() {
1820 wfDebugDieBacktrace( 'oldCond called' );
1821 return array( 'old_namespace' => $this->mNamespace
, 'old_title' => $this->mDbkeyform
);
1825 * Get the revision ID of the previous revision
1827 * @param integer $revision Revision ID. Get the revision that was before this one.
1828 * @return interger $oldrevision|false
1830 function getPreviousRevisionID( $revision ) {
1831 $dbr =& wfGetDB( DB_SLAVE
);
1832 return $dbr->selectField( 'revision', 'rev_id',
1833 'rev_page=' . IntVal( $this->getArticleId() ) .
1834 ' AND rev_id<' . IntVal( $revision ) . ' ORDER BY rev_id DESC' );
1838 * Get the revision ID of the next revision
1840 * @param integer $revision Revision ID. Get the revision that was after this one.
1841 * @return interger $oldrevision|false
1843 function getNextRevisionID( $revision ) {
1844 $dbr =& wfGetDB( DB_SLAVE
);
1845 return $dbr->selectField( 'revision', 'rev_id',
1846 'rev_page=' . IntVal( $this->getArticleId() ) .
1847 ' AND rev_id>' . IntVal( $revision ) . ' ORDER BY rev_id' );