10 require_once( 'normal/UtfNormal.php' );
12 $wgTitleInterwikiCache = array();
13 define ( 'GAID_FOR_UPDATE', 1 );
17 * - Represents a title, which may contain an interwiki designation or namespace
18 * - Can fetch various kinds of data from the database, albeit inefficiently.
24 * All member variables should be considered private
25 * Please use the accessor functions
32 var $mTextform; # Text form (spaces not underscores) of the main part
33 var $mUrlform; # URL-encoded form of the main part
34 var $mDbkeyform; # Main part with underscores
35 var $mNamespace; # Namespace index, i.e. one of the NS_xxxx constants
36 var $mInterwiki; # Interwiki prefix (or null string)
37 var $mFragment; # Title fragment (i.e. the bit after the #)
38 var $mArticleID; # Article ID, fetched from the link cache on demand
39 var $mRestrictions; # Array of groups allowed to edit this article
40 # Only null or "sysop" are supported
41 var $mRestrictionsLoaded; # Boolean for initialisation on demand
42 var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand
43 var $mDefaultNamespace; # Namespace index when there is no namespace
44 # Zero except in {{transclusion}} tags
52 /* private */ function Title() {
53 $this->mInterwiki
= $this->mUrlform
=
54 $this->mTextform
= $this->mDbkeyform
= '';
55 $this->mArticleID
= -1;
56 $this->mNamespace
= 0;
57 $this->mRestrictionsLoaded
= false;
58 $this->mRestrictions
= array();
59 $this->mDefaultNamespace
= 0;
63 * Create a new Title from a prefixed DB key
64 * @param string $key The database key, which has underscores
65 * instead of spaces, possibly including namespace and
67 * @return Title the new object, or NULL on an error
71 /* static */ function newFromDBkey( $key ) {
73 $t->mDbkeyform
= $key;
74 if( $t->secureAndSplit() )
81 * Create a new Title from text, such as what one would
82 * find in a link. Decodes any HTML entities in the text.
84 * @param string $text the link text; spaces, prefixes,
85 * and an initial ':' indicating the main namespace
87 * @param int $defaultNamespace the namespace to use if
88 * none is specified by a prefix
89 * @return Title the new object, or NULL on an error
93 /* static */ function &newFromText( $text, $defaultNamespace = 0 ) {
94 $fname = 'Title::newFromText';
95 wfProfileIn( $fname );
98 * Convert things like é into real text...
100 global $wgInputEncoding;
101 $text = do_html_entity_decode( $text, ENT_COMPAT
, $wgInputEncoding );
104 * Convert things like ā or 〗 into real text...
105 * WARNING: Not friendly to internal links on a latin-1 wiki.
107 $text = wfMungeToUtf8( $text );
109 # What was this for? TS 2004-03-03
110 # $text = urldecode( $text );
113 $t->mDbkeyform
= str_replace( ' ', '_', $text );
114 $t->mDefaultNamespace
= $defaultNamespace;
116 if( $t->secureAndSplit() ) {
117 wfProfileOut( $fname );
120 wfProfileOut( $fname );
126 * Create a new Title from URL-encoded text. Ensures that
127 * the given title's length does not exceed the maximum.
128 * @param string $url the title, as might be taken from a URL
129 * @return Title the new object, or NULL on an error
133 /* static */ function newFromURL( $url ) {
134 global $wgLang, $wgServer;
137 # For compatibility with old buggy URLs. "+" is not valid in titles,
138 # but some URLs used it as a space replacement and they still come
139 # from some external search tools.
140 $s = str_replace( '+', ' ', $url );
142 $t->mDbkeyform
= str_replace( ' ', '_', $s );
143 if( $t->secureAndSplit() ) {
151 * Create a new Title from an article ID
152 * @todo This is inefficiently implemented, the cur row is requested
153 * but not used for anything else
154 * @param int $id the cur_id corresponding to the Title to create
155 * @return Title the new object, or NULL on an error
158 /* static */ function newFromID( $id ) {
159 $fname = 'Title::newFromID';
160 $dbr =& wfGetDB( DB_SLAVE
);
161 $row = $dbr->selectRow( 'cur', array( 'cur_namespace', 'cur_title' ),
162 array( 'cur_id' => $id ), $fname );
163 if ( $row !== false ) {
164 $title = Title
::makeTitle( $row->cur_namespace
, $row->cur_title
);
172 * Create a new Title from a namespace index and a DB key.
173 * It's assumed that $ns and $title are *valid*, for instance when
174 * they came directly from the database or a special page name.
175 * For convenience, spaces are converted to underscores so that
176 * eg user_text fields can be used directly.
178 * @param int $ns the namespace of the article
179 * @param string $title the unprefixed database key form
180 * @return Title the new object
184 /* static */ function &makeTitle( $ns, $title ) {
188 $t->mNamespace
= IntVal( $ns );
189 $t->mDbkeyform
= str_replace( ' ', '_', $title );
190 $t->mArticleID
= ( $ns >= 0 ) ?
-1 : 0;
191 $t->mUrlform
= wfUrlencode( $t->mDbkeyform
);
192 $t->mTextform
= str_replace( '_', ' ', $title );
197 * Create a new Title frrom a namespace index and a DB key.
198 * The parameters will be checked for validity, which is a bit slower
199 * than makeTitle() but safer for user-provided data.
200 * @param int $ns the namespace of the article
201 * @param string $title the database key form
202 * @return Title the new object, or NULL on an error
206 /* static */ function makeTitleSafe( $ns, $title ) {
208 $t->mDbkeyform
= Title
::makeName( $ns, $title );
209 if( $t->secureAndSplit() ) {
217 * Create a new Title for the Main Page
219 * @return Title the new object
222 /* static */ function newMainPage() {
223 return Title
::newFromText( wfMsgForContent( 'mainpage' ) );
227 * Create a new Title for a redirect
228 * @param string $text the redirect title text
229 * @return Title the new object, or NULL if the text is not a
234 /* static */ function newFromRedirect( $text ) {
237 if ( $wgMwRedir->matchStart( $text ) ) {
238 if ( preg_match( '/\\[\\[([^\\]\\|]+)[\\]\\|]/', $text, $m ) ) {
239 # categories are escaped using : for example one can enter:
240 # #REDIRECT [[:Category:Music]]. Need to remove it.
241 if ( substr($m[1],0,1) == ':') {
242 # We don't want to keep the ':'
243 $m[1] = substr( $m[1], 1 );
246 $rt = Title
::newFromText( $m[1] );
247 # Disallow redirects to Special:Userlogout
248 if ( !is_null($rt) && $rt->getNamespace() == NS_SPECIAL
&& preg_match( '/^Userlogout/i', $rt->getText() ) ) {
256 #----------------------------------------------------------------------------
258 #----------------------------------------------------------------------------
261 * Get the prefixed DB key associated with an ID
262 * @param int $id the cur_id of the article
263 * @return Title an object representing the article, or NULL
264 * if no such article was found
268 /* static */ function nameOf( $id ) {
269 $fname = 'Title::nameOf';
270 $dbr =& wfGetDB( DB_SLAVE
);
272 $s = $dbr->selectRow( 'cur', array( 'cur_namespace','cur_title' ), array( 'cur_id' => $id ), $fname );
273 if ( $s === false ) { return NULL; }
275 $n = Title
::makeName( $s->cur_namespace
, $s->cur_title
);
280 * Get a regex character class describing the legal characters in a link
281 * @return string the list of characters, not delimited
285 /* static */ function legalChars() {
286 # Missing characters:
287 # * []|# Needed for link syntax
288 # * % and + are corrupted by Apache when they appear in the path
290 # % seems to work though
292 # The problem with % is that URLs are double-unescaped: once by Apache's
293 # path conversion code, and again by PHP. So %253F, for example, becomes "?".
294 # Our code does not double-escape to compensate for this, indeed double escaping
295 # would break if the double-escaped title was passed in the query string
296 # rather than the path. This is a minor security issue because articles can be
297 # created such that they are hard to view or edit. -- TS
299 # Theoretically 0x80-0x9F of ISO 8859-1 should be disallowed, but
300 # this breaks interlanguage links
302 $set = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF";
307 * Get a string representation of a title suitable for
308 * including in a search index
310 * @param int $ns a namespace index
311 * @param string $title text-form main part
312 * @return string a stripped-down title string ready for the
315 /* static */ function indexTitle( $ns, $title ) {
316 global $wgDBminWordLen, $wgContLang;
317 require_once( 'SearchEngine.php' );
319 $lc = SearchEngine
::legalSearchChars() . '&#;';
320 $t = $wgContLang->stripForSearch( $title );
321 $t = preg_replace( "/[^{$lc}]+/", ' ', $t );
322 $t = strtolower( $t );
325 $t = preg_replace( "/([{$lc}]+)'s( |$)/", "\\1 \\1's ", $t );
326 $t = preg_replace( "/([{$lc}]+)s'( |$)/", "\\1s ", $t );
328 $t = preg_replace( "/\\s+/", ' ', $t );
330 if ( $ns == NS_IMAGE
) {
331 $t = preg_replace( "/ (png|gif|jpg|jpeg|ogg)$/", "", $t );
337 * Make a prefixed DB key from a DB key and a namespace index
338 * @param int $ns numerical representation of the namespace
339 * @param string $title the DB key form the title
340 * @return string the prefixed form of the title
342 /* static */ function makeName( $ns, $title ) {
345 $n = $wgContLang->getNsText( $ns );
346 if ( '' == $n ) { return $title; }
347 else { return $n.':'.$title; }
351 * Returns the URL associated with an interwiki prefix
352 * @param string $key the interwiki prefix (e.g. "MeatBall")
353 * @return the associated URL, containing "$1", which should be
354 * replaced by an article title
358 function getInterwikiLink( $key ) {
359 global $wgMemc, $wgDBname, $wgInterwikiExpiry, $wgTitleInterwikiCache;
360 $fname = 'Title::getInterwikiLink';
362 wfProfileIn( $fname );
364 $k = $wgDBname.':interwiki:'.$key;
365 if( array_key_exists( $k, $wgTitleInterwikiCache ) ) {
366 wfProfileOut( $fname );
367 return $wgTitleInterwikiCache[$k]->iw_url
;
370 $s = $wgMemc->get( $k );
371 # Ignore old keys with no iw_local
372 if( $s && isset( $s->iw_local
) ) {
373 $wgTitleInterwikiCache[$k] = $s;
374 wfProfileOut( $fname );
378 $dbr =& wfGetDB( DB_SLAVE
);
379 $res = $dbr->select( 'interwiki',
380 array( 'iw_url', 'iw_local' ),
381 array( 'iw_prefix' => $key ), $fname );
383 wfProfileOut( $fname );
387 $s = $dbr->fetchObject( $res );
389 # Cache non-existence: create a blank object and save it to memcached
394 $wgMemc->set( $k, $s, $wgInterwikiExpiry );
395 $wgTitleInterwikiCache[$k] = $s;
397 wfProfileOut( $fname );
402 * Determine whether the object refers to a page within
405 * @return bool TRUE if this is an in-project interwiki link
406 * or a wikilink, FALSE otherwise
410 global $wgTitleInterwikiCache, $wgDBname;
412 if ( $this->mInterwiki
!= '' ) {
413 # Make sure key is loaded into cache
414 $this->getInterwikiLink( $this->mInterwiki
);
415 $k = $wgDBname.':interwiki:' . $this->mInterwiki
;
416 return (bool)($wgTitleInterwikiCache[$k]->iw_local
);
423 * Update the cur_touched field for an array of title objects
424 * @todo Inefficient unless the IDs are already loaded into the
426 * @param array $titles an array of Title objects to be touched
427 * @param string $timestamp the timestamp to use instead of the
428 * default current time
432 /* static */ function touchArray( $titles, $timestamp = '' ) {
433 if ( count( $titles ) == 0 ) {
436 $dbw =& wfGetDB( DB_MASTER
);
437 if ( $timestamp == '' ) {
438 $timestamp = $dbw->timestamp();
440 $cur = $dbw->tableName( 'cur' );
441 $sql = "UPDATE $cur SET cur_touched='{$timestamp}' WHERE cur_id IN (";
444 foreach ( $titles as $title ) {
449 $sql .= $title->getArticleID();
453 $dbw->query( $sql, 'Title::touchArray' );
457 #----------------------------------------------------------------------------
459 #----------------------------------------------------------------------------
461 /** Simple accessors */
463 * Get the text form (spaces not underscores) of the main part
467 function getText() { return $this->mTextform
; }
469 * Get the URL-encoded form of the main part
473 function getPartialURL() { return $this->mUrlform
; }
475 * Get the main part with underscores
479 function getDBkey() { return $this->mDbkeyform
; }
481 * Get the namespace index, i.e. one of the NS_xxxx constants
485 function getNamespace() { return $this->mNamespace
; }
487 * Get the interwiki prefix (or null string)
491 function getInterwiki() { return $this->mInterwiki
; }
493 * Get the Title fragment (i.e. the bit after the #)
497 function getFragment() { return $this->mFragment
; }
499 * Get the default namespace index, for when there is no namespace
503 function getDefaultNamespace() { return $this->mDefaultNamespace
; }
506 * Get title for search index
507 * @return string a stripped-down title string ready for the
510 function getIndexTitle() {
511 return Title
::indexTitle( $this->mNamespace
, $this->mTextform
);
515 * Get the prefixed database key form
516 * @return string the prefixed title, with underscores and
517 * any interwiki and namespace prefixes
520 function getPrefixedDBkey() {
521 $s = $this->prefix( $this->mDbkeyform
);
522 $s = str_replace( ' ', '_', $s );
527 * Get the prefixed title with spaces.
528 * This is the form usually used for display
529 * @return string the prefixed title, with spaces
532 function getPrefixedText() {
534 if ( empty( $this->mPrefixedText
) ) {
535 $s = $this->prefix( $this->mTextform
);
536 $s = str_replace( '_', ' ', $s );
537 $this->mPrefixedText
= $s;
539 return $this->mPrefixedText
;
543 * Get the prefixed title with spaces, plus any fragment
544 * (part beginning with '#')
545 * @return string the prefixed title, with spaces and
546 * the fragment, including '#'
549 function getFullText() {
551 $text = $this->getPrefixedText();
552 if( '' != $this->mFragment
) {
553 $text .= '#' . $this->mFragment
;
559 * Get a URL-encoded title (not an actual URL) including interwiki
560 * @return string the URL-encoded form
563 function getPrefixedURL() {
564 $s = $this->prefix( $this->mDbkeyform
);
565 $s = str_replace( ' ', '_', $s );
567 $s = wfUrlencode ( $s ) ;
569 # Cleaning up URL to make it look nice -- is this safe?
570 $s = preg_replace( '/%3[Aa]/', ':', $s );
571 $s = preg_replace( '/%2[Ff]/', '/', $s );
572 $s = str_replace( '%28', '(', $s );
573 $s = str_replace( '%29', ')', $s );
579 * Get a real URL referring to this title, with interwiki link and
582 * @param string $query an optional query string, not used
583 * for interwiki links
584 * @return string the URL
587 function getFullURL( $query = '' ) {
588 global $wgContLang, $wgArticlePath, $wgServer, $wgScript;
590 if ( '' == $this->mInterwiki
) {
592 return $wgServer . $this->getLocalUrl( $query );
594 $baseUrl = $this->getInterwikiLink( $this->mInterwiki
);
595 $namespace = $wgContLang->getNsText( $this->mNamespace
);
596 if ( '' != $namespace ) {
597 # Can this actually happen? Interwikis shouldn't be parsed.
600 $url = str_replace( '$1', $namespace . $this->mUrlform
, $baseUrl );
601 if ( '' != $this->mFragment
) {
602 $url .= '#' . $this->mFragment
;
609 * Get a URL with no fragment or server name
610 * @param string $query an optional query string; if not specified,
611 * $wgArticlePath will be used.
612 * @return string the URL
615 function getLocalURL( $query = '' ) {
616 global $wgLang, $wgArticlePath, $wgScript;
618 if ( $this->isExternal() ) {
619 return $this->getFullURL();
622 $dbkey = wfUrlencode( $this->getPrefixedDBkey() );
623 if ( $query == '' ) {
624 $url = str_replace( '$1', $dbkey, $wgArticlePath );
626 if ( $query == '-' ) {
629 $url = "{$wgScript}?title={$dbkey}&{$query}";
635 * Get an HTML-escaped version of the URL form, suitable for
636 * using in a link, without a server name or fragment
637 * @param string $query an optional query string
638 * @return string the URL
641 function escapeLocalURL( $query = '' ) {
642 return htmlspecialchars( $this->getLocalURL( $query ) );
646 * Get an HTML-escaped version of the URL form, suitable for
647 * using in a link, including the server name and fragment
649 * @return string the URL
650 * @param string $query an optional query string
653 function escapeFullURL( $query = '' ) {
654 return htmlspecialchars( $this->getFullURL( $query ) );
658 * Get the URL form for an internal link.
659 * - Used in various Squid-related code, in case we have a different
660 * internal hostname for the server from the exposed one.
662 * @param string $query an optional query string
663 * @return string the URL
666 function getInternalURL( $query = '' ) {
667 global $wgInternalServer;
668 return $wgInternalServer . $this->getLocalURL( $query );
672 * Get the edit URL for this Title
673 * @return string the URL, or a null string if this is an
677 function getEditURL() {
678 global $wgServer, $wgScript;
680 if ( '' != $this->mInterwiki
) { return ''; }
681 $s = $this->getLocalURL( 'action=edit' );
687 * Get the HTML-escaped displayable text form.
688 * Used for the title field in <a> tags.
689 * @return string the text, including any prefixes
692 function getEscapedText() {
693 return htmlspecialchars( $this->getPrefixedText() );
697 * Is this Title interwiki?
701 function isExternal() { return ( '' != $this->mInterwiki
); }
704 * Does the title correspond to a protected article?
705 * @param string $what the action the page is protected from,
706 * by default checks move and edit
710 function isProtected($action = '') {
711 if ( -1 == $this->mNamespace
) { return true; }
712 if($action == 'edit' ||
$action == '') {
713 $a = $this->getRestrictions("edit");
714 if ( in_array( 'sysop', $a ) ) { return true; }
716 if($action == 'move' ||
$action == '') {
717 $a = $this->getRestrictions("move");
718 if ( in_array( 'sysop', $a ) ) { return true; }
724 * Is $wgUser is watching this page?
728 function userIsWatching() {
731 if ( -1 == $this->mNamespace
) { return false; }
732 if ( 0 == $wgUser->getID() ) { return false; }
734 return $wgUser->isWatched( $this );
738 * Is $wgUser perform $action this page?
739 * @param string $action action that permission needs to be checked for
743 function userCan($action) {
744 $fname = 'Title::userCanEdit';
745 wfProfileIn( $fname );
748 if( NS_SPECIAL
== $this->mNamespace
) {
749 wfProfileOut( $fname );
752 if( NS_MEDIAWIKI
== $this->mNamespace
&&
753 !$wgUser->isAllowed('editinterface') ) {
754 wfProfileOut( $fname );
757 if( $this->mDbkeyform
== '_' ) {
758 # FIXME: Is this necessary? Shouldn't be allowed anyway...
759 wfProfileOut( $fname );
763 # protect global styles and js
764 if ( NS_MEDIAWIKI
== $this->mNamespace
765 && preg_match("/\\.(css|js)$/", $this->mTextform
)
766 && !$wgUser->isAllowed('editinterface') ) {
767 wfProfileOut( $fname );
771 # protect css/js subpages of user pages
772 # XXX: this might be better using restrictions
773 # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working
774 if( NS_USER
== $this->mNamespace
775 && preg_match("/\\.(css|js)$/", $this->mTextform
)
776 && !$wgUser->isAllowed('editinterface')
777 && !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) ) {
778 wfProfileOut( $fname );
782 foreach( $this->getRestrictions($action) as $right ) {
783 if( '' != $right && !$wgUser->isAllowed( $right ) ) {
784 wfProfileOut( $fname );
788 wfProfileOut( $fname );
793 * Can $wgUser edit this page?
797 function userCanEdit() {
798 return $this->userCan('edit');
802 * Can $wgUser move this page?
806 function userCanMove() {
807 return $this->userCan('move');
811 * Can $wgUser read this page?
815 function userCanRead() {
818 if( $wgUser->isAllowed('read') ) {
821 global $wgWhitelistRead;
823 /** If anon users can create an account,
824 they need to reach the login page first! */
825 if( $wgUser->isAllowed( 'createaccount' )
826 && $this->mId
== NS_SPECIAL
827 && $this->getText() == 'Userlogin' ) {
831 /** some pages are explicitly allowed */
832 $name = $this->getPrefixedText();
833 if( in_array( $name, $wgWhitelistRead ) ) {
837 # Compatibility with old settings
838 if( $this->getNamespace() == NS_MAIN
) {
839 if( in_array( ':' . $name, $wgWhitelistRead ) ) {
848 * Is this a .css or .js subpage of a user page?
852 function isCssJsSubpage() {
853 return ( NS_USER
== $this->mNamespace
and preg_match("/\\.(css|js)$/", $this->mTextform
) );
856 * Is this a .css subpage of a user page?
860 function isCssSubpage() {
861 return ( NS_USER
== $this->mNamespace
and preg_match("/\\.css$/", $this->mTextform
) );
864 * Is this a .js subpage of a user page?
868 function isJsSubpage() {
869 return ( NS_USER
== $this->mNamespace
and preg_match("/\\.js$/", $this->mTextform
) );
872 * Protect css/js subpages of user pages: can $wgUser edit
876 * @todo XXX: this might be better using restrictions
879 function userCanEditCssJsSubpage() {
881 return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform
) );
885 * Loads a string into mRestrictions array
886 * @param string $res restrictions in string format
889 function loadRestrictions( $res ) {
890 foreach( explode( ':', trim( $res ) ) as $restrict ) {
891 $temp = explode( '=', trim( $restrict ) );
892 if(count($temp) == 1) {
893 // old format should be treated as edit/move restriction
894 $this->mRestrictions
["edit"] = explode( ',', trim( $temp[0] ) );
895 $this->mRestrictions
["move"] = explode( ',', trim( $temp[0] ) );
897 $this->mRestrictions
[$temp[0]] = explode( ',', trim( $temp[1] ) );
900 $this->mRestrictionsLoaded
= true;
904 * Accessor/initialisation for mRestrictions
905 * @param string $action action that permission needs to be checked for
906 * @return array the array of groups allowed to edit this article
909 function getRestrictions($action) {
910 $id = $this->getArticleID();
911 if ( 0 == $id ) { return array(); }
913 if ( ! $this->mRestrictionsLoaded
) {
914 $dbr =& wfGetDB( DB_SLAVE
);
915 $res = $dbr->selectField( 'cur', 'cur_restrictions', 'cur_id='.$id );
916 $this->loadRestrictions( $res );
918 if( isset( $this->mRestrictions
[$action] ) ) {
919 return $this->mRestrictions
[$action];
925 * Is there a version of this page in the deletion archive?
926 * @return int the number of archived revisions
929 function isDeleted() {
930 $fname = 'Title::isDeleted';
931 $dbr =& wfGetDB( DB_SLAVE
);
932 $n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),
933 'ar_title' => $this->getDBkey() ), $fname );
938 * Get the article ID for this Title from the link cache,
939 * adding it if necessary
940 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select
945 function getArticleID( $flags = 0 ) {
948 if ( $flags & GAID_FOR_UPDATE
) {
949 $oldUpdate = $wgLinkCache->forUpdate( true );
950 $this->mArticleID
= $wgLinkCache->addLinkObj( $this );
951 $wgLinkCache->forUpdate( $oldUpdate );
953 if ( -1 == $this->mArticleID
) {
954 $this->mArticleID
= $wgLinkCache->addLinkObj( $this );
957 return $this->mArticleID
;
961 * This clears some fields in this object, and clears any associated
962 * keys in the "bad links" section of $wgLinkCache.
964 * - This is called from Article::insertNewArticle() to allow
965 * loading of the new cur_id. It's also called from
966 * Article::doDeleteArticle()
968 * @param int $newid the new Article ID
971 function resetArticleID( $newid ) {
973 $wgLinkCache->clearBadLink( $this->getPrefixedDBkey() );
975 if ( 0 == $newid ) { $this->mArticleID
= -1; }
976 else { $this->mArticleID
= $newid; }
977 $this->mRestrictionsLoaded
= false;
978 $this->mRestrictions
= array();
982 * Updates cur_touched for this page; called from LinksUpdate.php
983 * @return bool true if the update succeded
986 function invalidateCache() {
987 $now = wfTimestampNow();
988 $dbw =& wfGetDB( DB_MASTER
);
989 $success = $dbw->update( 'cur',
991 'cur_touched' => $dbw->timestamp()
992 ), array( /* WHERE */
993 'cur_namespace' => $this->getNamespace() ,
994 'cur_title' => $this->getDBkey()
995 ), 'Title::invalidateCache'
1001 * Prefix some arbitrary text with the namespace or interwiki prefix
1004 * @param string $name the text
1005 * @return string the prefixed text
1008 /* private */ function prefix( $name ) {
1012 if ( '' != $this->mInterwiki
) {
1013 $p = $this->mInterwiki
. ':';
1015 if ( 0 != $this->mNamespace
) {
1016 $p .= $wgContLang->getNsText( $this->mNamespace
) . ':';
1022 * Secure and split - main initialisation function for this object
1024 * Assumes that mDbkeyform has been set, and is urldecoded
1025 * and uses underscores, but not otherwise munged. This function
1026 * removes illegal characters, splits off the interwiki and
1027 * namespace prefixes, sets the other forms, and canonicalizes
1029 * @return bool true on success
1032 /* private */ function secureAndSplit() {
1033 global $wgContLang, $wgLocalInterwiki, $wgCapitalLinks;
1034 $fname = 'Title::secureAndSplit';
1035 wfProfileIn( $fname );
1037 static $imgpre = false;
1038 static $rxTc = false;
1041 if ( $imgpre === false ) {
1042 $imgpre = ':' . $wgContLang->getNsText( NS_IMAGE
) . ':';
1043 # % is needed as well
1044 $rxTc = '/[^' . Title
::legalChars() . ']|%[0-9A-Fa-f]{2}/S';
1047 $this->mInterwiki
= $this->mFragment
= '';
1048 $this->mNamespace
= $this->mDefaultNamespace
; # Usually NS_MAIN
1050 # Clean up whitespace
1052 $t = preg_replace( "/[\\s_]+/", '_', $this->mDbkeyform
);
1053 $t = preg_replace( '/^_*(.*?)_*$/', '$1', $t );
1056 wfProfileOut( $fname );
1060 global $wgUseLatin1;
1061 if( !$wgUseLatin1 && false !== strpos( $t, UTF8_REPLACEMENT
) ) {
1062 # Contained illegal UTF-8 sequences or forbidden Unicode chars.
1063 wfProfileOut( $fname );
1067 $this->mDbkeyform
= $t;
1071 if ( 0 == strncasecmp( $imgpre, $t, strlen( $imgpre ) ) ) {
1072 $t = substr( $t, 1 );
1075 # Initial colon indicating main namespace
1076 if ( ':' == $t{0} ) {
1077 $r = substr( $t, 1 );
1078 $this->mNamespace
= NS_MAIN
;
1080 # Namespace or interwiki prefix
1081 if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $t, $m ) ) {
1082 #$p = strtolower( $m[1] );
1084 $lowerNs = strtolower( $p );
1085 if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
1086 # Canonical namespace
1088 $this->mNamespace
= $ns;
1089 } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) {
1090 # Ordinary namespace
1092 $this->mNamespace
= $ns;
1093 } elseif ( $this->getInterwikiLink( $p ) ) {
1096 $this->mInterwiki
= $p;
1098 if ( !preg_match( "/^([A-Za-z0-9_\\x80-\\xff]+):(.*)$/", $t, $m ) ) {
1100 } elseif($this->mInterwiki
!= $wgLocalInterwiki) {
1108 # Redundant interwiki prefix to the local wiki
1109 if ( 0 == strcmp( $this->mInterwiki
, $wgLocalInterwiki ) ) {
1110 $this->mInterwiki
= '';
1112 # We already know that some pages won't be in the database!
1114 if ( '' != $this->mInterwiki ||
-1 == $this->mNamespace
) {
1115 $this->mArticleID
= 0;
1117 $f = strstr( $r, '#' );
1118 if ( false !== $f ) {
1119 $this->mFragment
= substr( $f, 1 );
1120 $r = substr( $r, 0, strlen( $r ) - strlen( $f ) );
1121 # remove whitespace again: prevents "Foo_bar_#"
1122 # becoming "Foo_bar_"
1123 $r = preg_replace( '/_*$/', '', $r );
1126 # Reject illegal characters.
1128 if( preg_match( $rxTc, $r ) ) {
1129 wfProfileOut( $fname );
1134 * Pages with "/./" or "/../" appearing in the URLs will
1135 * often be unreachable due to the way web browsers deal
1136 * with 'relative' URLs. Forbid them explicitly.
1138 if ( strpos( $r, '.' ) !== false &&
1139 ( $r === '.' ||
$r === '..' ||
1140 strpos( $r, './' ) === 0 ||
1141 strpos( $r, '../' ) === 0 ||
1142 strpos( $r, '/./' ) !== false ||
1143 strpos( $r, '/../' ) !== false ) )
1145 wfProfileOut( $fname );
1149 # We shouldn't need to query the DB for the size.
1150 #$maxSize = $dbr->textFieldSize( 'cur', 'cur_title' );
1151 if ( strlen( $r ) > 255 ) {
1156 * Normally, all wiki links are forced to have
1157 * an initial capital letter so [[foo]] and [[Foo]]
1158 * point to the same place.
1160 * Don't force it for interwikis, since the other
1161 * site might be case-sensitive.
1163 if( $wgCapitalLinks && $this->mInterwiki
== '') {
1164 $t = $wgContLang->ucfirst( $r );
1170 $this->mDbkeyform
= $t;
1171 $this->mUrlform
= wfUrlencode( $t );
1173 $this->mTextform
= str_replace( '_', ' ', $t );
1175 wfProfileOut( $fname );
1180 * Get a Title object associated with the talk page of this article
1181 * @return Title the object for the talk page
1184 function getTalkPage() {
1185 return Title
::makeTitle( Namespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
1189 * Get a title object associated with the subject page of this
1192 * @return Title the object for the subject page
1195 function getSubjectPage() {
1196 return Title
::makeTitle( Namespace::getSubject( $this->getNamespace() ), $this->getDBkey() );
1200 * Get an array of Title objects linking to this Title
1201 * - Also stores the IDs in the link cache.
1203 * @param string $options may be FOR UPDATE
1204 * @return array the Title objects linking here
1207 function getLinksTo( $options = '' ) {
1208 global $wgLinkCache;
1209 $id = $this->getArticleID();
1212 $db =& wfGetDB( DB_MASTER
);
1214 $db =& wfGetDB( DB_SLAVE
);
1216 $cur = $db->tableName( 'cur' );
1217 $links = $db->tableName( 'links' );
1219 $sql = "SELECT cur_namespace,cur_title,cur_id FROM $cur,$links WHERE l_from=cur_id AND l_to={$id} $options";
1220 $res = $db->query( $sql, 'Title::getLinksTo' );
1222 if ( $db->numRows( $res ) ) {
1223 while ( $row = $db->fetchObject( $res ) ) {
1224 if ( $titleObj = Title
::makeTitle( $row->cur_namespace
, $row->cur_title
) ) {
1225 $wgLinkCache->addGoodLink( $row->cur_id
, $titleObj->getPrefixedDBkey() );
1226 $retVal[] = $titleObj;
1230 $db->freeResult( $res );
1235 * Get an array of Title objects linking to this non-existent title.
1236 * - Also stores the IDs in the link cache.
1238 * @param string $options may be FOR UPDATE
1239 * @return array the Title objects linking here
1242 function getBrokenLinksTo( $options = '' ) {
1243 global $wgLinkCache;
1246 $db =& wfGetDB( DB_MASTER
);
1248 $db =& wfGetDB( DB_SLAVE
);
1250 $cur = $db->tableName( 'cur' );
1251 $brokenlinks = $db->tableName( 'brokenlinks' );
1252 $encTitle = $db->strencode( $this->getPrefixedDBkey() );
1254 $sql = "SELECT cur_namespace,cur_title,cur_id FROM $brokenlinks,$cur " .
1255 "WHERE bl_from=cur_id AND bl_to='$encTitle' $options";
1256 $res = $db->query( $sql, "Title::getBrokenLinksTo" );
1258 if ( $db->numRows( $res ) ) {
1259 while ( $row = $db->fetchObject( $res ) ) {
1260 $titleObj = Title
::makeTitle( $row->cur_namespace
, $row->cur_title
);
1261 $wgLinkCache->addGoodLink( $row->cur_id
, $titleObj->getPrefixedDBkey() );
1262 $retVal[] = $titleObj;
1265 $db->freeResult( $res );
1270 * Get a list of URLs to purge from the Squid cache when this
1273 * @return array the URLs
1276 function getSquidURLs() {
1278 $this->getInternalURL(),
1279 $this->getInternalURL( 'action=history' )
1284 * Move this page without authentication
1285 * @param Title &$nt the new page Title
1288 function moveNoAuth( &$nt ) {
1289 return $this->moveTo( $nt, false );
1293 * Move a title to a new location
1294 * @param Title &$nt the new title
1295 * @param bool $auth indicates whether $wgUser's permissions
1297 * @return mixed true on success, message name on failure
1300 function moveTo( &$nt, $auth = true ) {
1301 if( !$this or !$nt ) {
1302 return 'badtitletext';
1305 $fname = 'Title::move';
1306 $oldid = $this->getArticleID();
1307 $newid = $nt->getArticleID();
1309 if ( strlen( $nt->getDBkey() ) < 1 ) {
1310 return 'articleexists';
1312 if ( ( ! Namespace::isMovable( $this->getNamespace() ) ) ||
1313 ( '' == $this->getDBkey() ) ||
1314 ( '' != $this->getInterwiki() ) ||
1316 ( ! Namespace::isMovable( $nt->getNamespace() ) ) ||
1317 ( '' == $nt->getDBkey() ) ||
1318 ( '' != $nt->getInterwiki() ) ) {
1319 return 'badarticleerror';
1322 if ( $auth && ( !$this->userCanEdit() ||
!$nt->userCanEdit() ) ) {
1323 return 'protectedpage';
1326 # The move is allowed only if (1) the target doesn't exist, or
1327 # (2) the target is a redirect to the source, and has no history
1328 # (so we can undo bad moves right after they're done).
1330 if ( 0 != $newid ) { # Target exists; check for validity
1331 if ( ! $this->isValidMoveTarget( $nt ) ) {
1332 return 'articleexists';
1334 $this->moveOverExistingRedirect( $nt );
1335 } else { # Target didn't exist, do normal move.
1336 $this->moveToNewTitle( $nt, $newid );
1339 # Fixing category links (those without piped 'alternate' names) to be sorted under the new title
1341 $dbw =& wfGetDB( DB_MASTER
);
1342 $sql = "UPDATE categorylinks SET cl_sortkey=" . $dbw->addQuotes( $nt->getPrefixedText() ) .
1343 " WHERE cl_from=" . $dbw->addQuotes( $this->getArticleID() ) .
1344 " AND cl_sortkey=" . $dbw->addQuotes( $this->getPrefixedText() );
1345 $dbw->query( $sql, 'SpecialMovepage::doSubmit' );
1349 $oldnamespace = $this->getNamespace() & ~
1;
1350 $newnamespace = $nt->getNamespace() & ~
1;
1351 $oldtitle = $this->getDBkey();
1352 $newtitle = $nt->getDBkey();
1354 if( $oldnamespace != $newnamespace ||
$oldtitle != $newtitle ) {
1355 WatchedItem
::duplicateEntries( $this, $nt );
1358 # Update search engine
1359 $u = new SearchUpdate( $oldid, $nt->getPrefixedDBkey() );
1361 $u = new SearchUpdate( $newid, $this->getPrefixedDBkey(), '' );
1368 * Move page to a title which is at present a redirect to the
1371 * @param Title &$nt the page to move to, which should currently
1375 /* private */ function moveOverExistingRedirect( &$nt ) {
1376 global $wgUser, $wgLinkCache, $wgUseSquid, $wgMwRedir;
1377 $fname = 'Title::moveOverExistingRedirect';
1378 $comment = wfMsg( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
1380 $now = wfTimestampNow();
1381 $won = wfInvertTimestamp( $now );
1382 $newid = $nt->getArticleID();
1383 $oldid = $this->getArticleID();
1384 $dbw =& wfGetDB( DB_MASTER
);
1385 $links = $dbw->tableName( 'links' );
1387 # Change the name of the target page:
1388 $dbw->update( 'cur',
1390 'cur_touched' => $dbw->timestamp($now),
1391 'cur_namespace' => $nt->getNamespace(),
1392 'cur_title' => $nt->getDBkey()
1394 /* WHERE */ array( 'cur_id' => $oldid ),
1397 $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
1399 # Repurpose the old redirect. We don't save it to history since
1400 # by definition if we've got here it's rather uninteresting.
1402 $redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
1403 $dbw->update( 'cur',
1405 'cur_touched' => $dbw->timestamp($now),
1406 'cur_timestamp' => $dbw->timestamp($now),
1407 'inverse_timestamp' => $won,
1408 'cur_namespace' => $this->getNamespace(),
1409 'cur_title' => $this->getDBkey(),
1410 'cur_text' => $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n",
1411 'cur_comment' => $comment,
1412 'cur_user' => $wgUser->getID(),
1413 'cur_minor_edit' => 0,
1415 'cur_restrictions' => '',
1416 'cur_user_text' => $wgUser->getName(),
1417 'cur_is_redirect' => 1,
1420 /* WHERE */ array( 'cur_id' => $newid ),
1424 $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
1426 # Fix the redundant names for the past revisions of the target page.
1427 # The redirect should have no old revisions.
1431 'old_namespace' => $nt->getNamespace(),
1432 'old_title' => $nt->getDBkey(),
1435 'old_namespace' => $this->getNamespace(),
1436 'old_title' => $this->getDBkey(),
1441 RecentChange
::notifyMoveOverRedirect( $now, $this, $nt, $wgUser, $comment );
1445 # Load titles and IDs
1446 $linksToOld = $this->getLinksTo( 'FOR UPDATE' );
1447 $linksToNew = $nt->getLinksTo( 'FOR UPDATE' );
1450 $sql = "DELETE FROM $links WHERE l_to=$oldid OR l_to=$newid";
1451 $dbw->query( $sql, $fname );
1454 if ( count( $linksToOld ) ||
count( $linksToNew )) {
1455 $sql = "INSERT INTO $links (l_from,l_to) VALUES ";
1458 # Insert links to old title
1459 foreach ( $linksToOld as $linkTitle ) {
1465 $id = $linkTitle->getArticleID();
1466 $sql .= "($id,$newid)";
1469 # Insert links to new title
1470 foreach ( $linksToNew as $linkTitle ) {
1476 $id = $linkTitle->getArticleID();
1477 $sql .= "($id, $oldid)";
1480 $dbw->query( $sql, DB_MASTER
, $fname );
1483 # Now, we record the link from the redirect to the new title.
1484 # It should have no other outgoing links...
1485 $dbw->delete( 'links', array( 'l_from' => $newid ) );
1486 $dbw->insert( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ) );
1489 LinkCache
::linksccClearLinksTo( $oldid );
1490 LinkCache
::linksccClearLinksTo( $newid );
1493 if ( $wgUseSquid ) {
1494 $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
1495 $u = new SquidUpdate( $urls );
1501 * Move page to non-existing title.
1502 * @param Title &$nt the new Title
1503 * @param int &$newid set to be the new article ID
1506 /* private */ function moveToNewTitle( &$nt, &$newid ) {
1507 global $wgUser, $wgLinkCache, $wgUseSquid;
1508 $fname = 'MovePageForm::moveToNewTitle';
1509 $comment = wfMsg( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
1511 $newid = $nt->getArticleID();
1512 $oldid = $this->getArticleID();
1513 $dbw =& wfGetDB( DB_MASTER
);
1514 $now = $dbw->timestamp();
1515 $won = wfInvertTimestamp( wfTimestamp(TS_MW
,$now) );
1520 $dbw->update( 'cur',
1522 'cur_touched' => $now,
1523 'cur_namespace' => $nt->getNamespace(),
1524 'cur_title' => $nt->getDBkey()
1526 /* WHERE */ array( 'cur_id' => $oldid ),
1530 $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
1533 $dbw->insert( 'cur', array(
1534 'cur_id' => $dbw->nextSequenceValue('cur_cur_id_seq'),
1535 'cur_namespace' => $this->getNamespace(),
1536 'cur_title' => $this->getDBkey(),
1537 'cur_comment' => $comment,
1538 'cur_user' => $wgUser->getID(),
1539 'cur_user_text' => $wgUser->getName(),
1540 'cur_timestamp' => $now,
1541 'inverse_timestamp' => $won,
1542 'cur_touched' => $now,
1543 'cur_is_redirect' => 1,
1544 'cur_random' => $rand,
1546 'cur_text' => "#REDIRECT [[" . $nt->getPrefixedText() . "]]\n" ), $fname
1548 $newid = $dbw->insertId();
1549 $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
1551 # Rename old entries
1555 'old_namespace' => $nt->getNamespace(),
1556 'old_title' => $nt->getDBkey()
1559 'old_namespace' => $this->getNamespace(),
1560 'old_title' => $this->getDBkey()
1565 RecentChange
::notifyMoveToNew( $now, $this, $nt, $wgUser, $comment );
1567 # Purge squid and linkscc as per article creation
1568 Article
::onArticleCreate( $nt );
1570 # Any text links to the old title must be reassigned to the redirect
1571 $dbw->update( 'links', array( 'l_to' => $newid ), array( 'l_to' => $oldid ), $fname );
1572 LinkCache
::linksccClearLinksTo( $oldid );
1574 # Record the just-created redirect's linking to the page
1575 $dbw->insert( 'links', array( 'l_from' => $newid, 'l_to' => $oldid ), $fname );
1577 # Non-existent target may have had broken links to it; these must
1578 # now be removed and made into good links.
1579 $update = new LinksUpdate( $oldid, $nt->getPrefixedDBkey() );
1580 $update->fixBrokenLinks();
1582 # Purge old title from squid
1583 # The new title, and links to the new title, are purged in Article::onArticleCreate()
1584 $titles = $nt->getLinksTo();
1585 if ( $wgUseSquid ) {
1586 $urls = $this->getSquidURLs();
1587 foreach ( $titles as $linkTitle ) {
1588 $urls[] = $linkTitle->getInternalURL();
1590 $u = new SquidUpdate( $urls );
1596 * Checks if $this can be moved to a given Title
1597 * - Selects for update, so don't call it unless you mean business
1599 * @param Title &$nt the new title to check
1602 function isValidMoveTarget( $nt ) {
1603 $fname = 'Title::isValidMoveTarget';
1604 $dbw =& wfGetDB( DB_MASTER
);
1607 $id = $nt->getArticleID();
1608 $obj = $dbw->selectRow( 'cur', array( 'cur_is_redirect','cur_text' ),
1609 array( 'cur_id' => $id ), $fname, 'FOR UPDATE' );
1611 if ( !$obj ||
0 == $obj->cur_is_redirect
) {
1616 # Does the redirect point to the source?
1617 if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $obj->cur_text
, $m ) ) {
1618 $redirTitle = Title
::newFromText( $m[1] );
1619 if( !is_object( $redirTitle ) ||
1620 $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() ) {
1625 # Does the article have a history?
1626 $row = $dbw->selectRow( 'old', array( 'old_id' ),
1628 'old_namespace' => $nt->getNamespace(),
1629 'old_title' => $nt->getDBkey()
1630 ), $fname, 'FOR UPDATE'
1633 # Return true if there was no history
1634 return $row === false;
1638 * Create a redirect; fails if the title already exists; does
1641 * @param Title $dest the destination of the redirect
1642 * @param string $comment the comment string describing the move
1643 * @return bool true on success
1646 function createRedirect( $dest, $comment ) {
1648 if ( $this->getArticleID() ) {
1652 $fname = 'Title::createRedirect';
1653 $dbw =& wfGetDB( DB_MASTER
);
1654 $now = wfTimestampNow();
1655 $won = wfInvertTimestamp( $now );
1656 $seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' );
1658 $dbw->insert( 'cur', array(
1659 'cur_id' => $seqVal,
1660 'cur_namespace' => $this->getNamespace(),
1661 'cur_title' => $this->getDBkey(),
1662 'cur_comment' => $comment,
1663 'cur_user' => $wgUser->getID(),
1664 'cur_user_text' => $wgUser->getName(),
1665 'cur_timestamp' => $now,
1666 'inverse_timestamp' => $won,
1667 'cur_touched' => $now,
1668 'cur_is_redirect' => 1,
1670 'cur_text' => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n"
1672 $newid = $dbw->insertId();
1673 $this->resetArticleID( $newid );
1676 if ( $dest->getArticleID() ) {
1677 $dbw->insert( 'links',
1679 'l_to' => $dest->getArticleID(),
1684 $dbw->insert( 'brokenlinks',
1686 'bl_to' => $dest->getPrefixedDBkey(),
1692 Article
::onArticleCreate( $this );
1697 * Get categories to which this Title belongs and return an array of
1698 * categories' names.
1700 * @return array an array of parents in the form:
1701 * $parent => $currentarticle
1704 function getParentCategories() {
1705 global $wgContLang,$wgUser;
1707 $titlekey = $this->getArticleId();
1708 $sk =& $wgUser->getSkin();
1710 $dbr =& wfGetDB( DB_SLAVE
);
1711 $categorylinks = $dbr->tableName( 'categorylinks' );
1714 $sql = "SELECT * FROM $categorylinks"
1715 ." WHERE cl_from='$titlekey'"
1716 ." AND cl_from <> '0'"
1717 ." ORDER BY cl_sortkey";
1719 $res = $dbr->query ( $sql ) ;
1721 if($dbr->numRows($res) > 0) {
1722 while ( $x = $dbr->fetchObject ( $res ) )
1723 //$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);
1724 $data[$wgContLang->getNSText ( NS_CATEGORY
).':'.$x->cl_to
] = $this->getFullText();
1725 $dbr->freeResult ( $res ) ;
1733 * Get a tree of parent categories
1734 * @param array $children an array with the children in the keys, to check for circular refs
1738 function getParentCategoryTree( $children = array() ) {
1739 $parents = $this->getParentCategories();
1741 if($parents != '') {
1742 foreach($parents as $parent => $current)
1744 if ( array_key_exists( $parent, $children ) ) {
1745 # Circular reference
1746 $stack[$parent] = array();
1748 $nt = Title
::newFromText($parent);
1749 $stack[$parent] = $nt->getParentCategoryTree( $children +
array($parent => 1) );
1760 * Get an associative array for selecting this title from
1766 function curCond() {
1767 return array( 'cur_namespace' => $this->mNamespace
, 'cur_title' => $this->mDbkeyform
);
1771 * Get an associative array for selecting this title from the
1777 function oldCond() {
1778 return array( 'old_namespace' => $this->mNamespace
, 'old_title' => $this->mDbkeyform
);
1782 * Get the revision ID of the previous revision
1784 * @param integer $revision Revision ID. Get the revision that was before this one.
1785 * @return interger $oldrevision|false
1787 function getPreviousRevisionID( $revision ) {
1788 $dbr =& wfGetDB( DB_SLAVE
);
1789 return $dbr->selectField( 'old', 'old_id',
1790 'old_title=' . $dbr->addQuotes( $this->getDBkey() ) .
1791 ' AND old_namespace=' . IntVal( $this->getNamespace() ) .
1792 ' AND old_id<' . IntVal( $revision ) . ' ORDER BY old_id DESC' );
1796 * Get the revision ID of the next revision
1798 * @param integer $revision Revision ID. Get the revision that was after this one.
1799 * @return interger $oldrevision|false
1801 function getNextRevisionID( $revision ) {
1802 $dbr =& wfGetDB( DB_SLAVE
);
1803 return $dbr->selectField( 'old', 'old_id',
1804 'old_title=' . $dbr->addQuotes( $this->getDBkey() ) .
1805 ' AND old_namespace=' . IntVal( $this->getNamespace() ) .
1806 ' AND old_id>' . IntVal( $revision ) . ' ORDER BY old_id' );