11 const DELETED_TEXT
= 1;
12 const DELETED_COMMENT
= 2;
13 const DELETED_USER
= 4;
14 const DELETED_RESTRICTED
= 8;
16 // Audience options for Revision::getText()
18 const FOR_THIS_USER
= 2;
22 * Load a page revision from a given revision ID number.
23 * Returns null if no such revision can be found.
29 public static function newFromId( $id ) {
30 return Revision
::newFromConds(
31 array( 'page_id=rev_page',
32 'rev_id' => intval( $id ) ) );
36 * Load either the current, or a specified, revision
37 * that's attached to a given title. If not attached
38 * to that title, will return null.
44 public static function newFromTitle( $title, $id = 0 ) {
46 'page_namespace' => $title->getNamespace(),
47 'page_title' => $title->getDBkey()
50 // Use the specified ID
51 $conds['rev_id'] = $id;
52 } elseif ( wfGetLB()->getServerCount() > 1 ) {
53 // Get the latest revision ID from the master
54 $dbw = wfGetDB( DB_MASTER
);
55 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
56 if ( $latest === false ) {
57 // Page does not exist
60 $conds['rev_id'] = $latest;
62 // Use a join to get the latest revision
63 $conds[] = 'rev_id=page_latest';
65 $conds[] = 'page_id=rev_page';
66 return Revision
::newFromConds( $conds );
70 * Make a fake revision object from an archive table row. This is queried
71 * for permissions or even inserted (as in Special:Undelete)
72 * @fixme: should be a subclass for RevisionDelete. [TS]
74 public static function newFromArchiveRow( $row, $overrides = array() ) {
75 $attribs = $overrides +
array(
76 'page' => isset( $row->page_id
) ?
$row->page_id
: null,
77 'id' => isset( $row->ar_rev_id
) ?
$row->ar_rev_id
: null,
78 'comment' => $row->ar_comment
,
79 'user' => $row->ar_user
,
80 'user_text' => $row->ar_user_text
,
81 'timestamp' => $row->ar_timestamp
,
82 'minor_edit' => $row->ar_minor_edit
,
83 'text_id' => isset( $row->ar_text_id
) ?
$row->ar_text_id
: null,
84 'deleted' => $row->ar_deleted
,
85 'len' => $row->ar_len
);
86 if ( isset( $row->ar_text
) && !$row->ar_text_id
) {
87 // Pre-1.5 ar_text row
88 $attribs['text'] = $row->ar_text
;
90 return new self( $attribs );
94 * Load a page revision from a given revision ID number.
95 * Returns null if no such revision can be found.
102 public static function loadFromId( $db, $id ) {
103 return Revision
::loadFromConds( $db,
104 array( 'page_id=rev_page',
105 'rev_id' => intval( $id ) ) );
109 * Load either the current, or a specified, revision
110 * that's attached to a given page. If not attached
111 * to that page, will return null.
113 * @param Database $db
120 public static function loadFromPageId( $db, $pageid, $id = 0 ) {
121 $conds=array('page_id=rev_page','rev_page'=>intval( $pageid ), 'page_id'=>intval( $pageid ));
123 $conds['rev_id']=intval($id);
125 $conds[]='rev_id=page_latest';
127 return Revision
::loadFromConds( $db, $conds );
131 * Load either the current, or a specified, revision
132 * that's attached to a given page. If not attached
133 * to that page, will return null.
135 * @param Database $db
136 * @param Title $title
142 public static function loadFromTitle( $db, $title, $id = 0 ) {
144 $matchId = intval( $id );
146 $matchId = 'page_latest';
148 return Revision
::loadFromConds(
150 array( "rev_id=$matchId",
152 'page_namespace' => $title->getNamespace(),
153 'page_title' => $title->getDBkey() ) );
157 * Load the revision for the given title with the given timestamp.
158 * WARNING: Timestamps may in some circumstances not be unique,
159 * so this isn't the best key to use.
161 * @param Database $db
162 * @param Title $title
163 * @param string $timestamp
168 public static function loadFromTimestamp( $db, $title, $timestamp ) {
169 return Revision
::loadFromConds(
171 array( 'rev_timestamp' => $db->timestamp( $timestamp ),
173 'page_namespace' => $title->getNamespace(),
174 'page_title' => $title->getDBkey() ) );
178 * Given a set of conditions, fetch a revision.
180 * @param array $conditions
185 private static function newFromConds( $conditions ) {
186 $db = wfGetDB( DB_SLAVE
);
187 $row = Revision
::loadFromConds( $db, $conditions );
188 if( is_null( $row ) && wfGetLB()->getServerCount() > 1 ) {
189 $dbw = wfGetDB( DB_MASTER
);
190 $row = Revision
::loadFromConds( $dbw, $conditions );
196 * Given a set of conditions, fetch a revision from
197 * the given database connection.
199 * @param Database $db
200 * @param array $conditions
205 private static function loadFromConds( $db, $conditions ) {
206 $res = Revision
::fetchFromConds( $db, $conditions );
208 $row = $res->fetchObject();
211 $ret = new Revision( $row );
220 * Return a wrapper for a series of database rows to
221 * fetch all of a given page's revisions in turn.
222 * Each row can be fed to the constructor to get objects.
224 * @param Title $title
225 * @return ResultWrapper
229 public static function fetchAllRevisions( $title ) {
230 return Revision
::fetchFromConds(
232 array( 'page_namespace' => $title->getNamespace(),
233 'page_title' => $title->getDBkey(),
234 'page_id=rev_page' ) );
238 * Return a wrapper for a series of database rows to
239 * fetch all of a given page's revisions in turn.
240 * Each row can be fed to the constructor to get objects.
242 * @param Title $title
243 * @return ResultWrapper
247 public static function fetchRevision( $title ) {
248 return Revision
::fetchFromConds(
250 array( 'rev_id=page_latest',
251 'page_namespace' => $title->getNamespace(),
252 'page_title' => $title->getDBkey(),
253 'page_id=rev_page' ) );
257 * Given a set of conditions, return a ResultWrapper
258 * which will return matching database rows with the
259 * fields necessary to build Revision objects.
261 * @param Database $db
262 * @param array $conditions
263 * @return ResultWrapper
267 private static function fetchFromConds( $db, $conditions ) {
268 $fields = self
::selectFields();
269 $fields[] = 'page_namespace';
270 $fields[] = 'page_title';
271 $fields[] = 'page_latest';
273 array( 'page', 'revision' ),
277 array( 'LIMIT' => 1 ) );
278 $ret = $db->resultObject( $res );
283 * Return the list of revision fields that should be selected to create
286 static function selectFields() {
303 * Return the list of text fields that should be selected to read the
306 static function selectTextFields() {
313 * Return the list of page fields that should be selected from page table
315 static function selectPageFields() {
327 function Revision( $row ) {
328 if( is_object( $row ) ) {
329 $this->mId
= intval( $row->rev_id
);
330 $this->mPage
= intval( $row->rev_page
);
331 $this->mTextId
= intval( $row->rev_text_id
);
332 $this->mComment
= $row->rev_comment
;
333 $this->mUserText
= $row->rev_user_text
;
334 $this->mUser
= intval( $row->rev_user
);
335 $this->mMinorEdit
= intval( $row->rev_minor_edit
);
336 $this->mTimestamp
= $row->rev_timestamp
;
337 $this->mDeleted
= intval( $row->rev_deleted
);
339 if( !isset( $row->rev_parent_id
) )
340 $this->mParentId
= is_null($row->rev_parent_id
) ?
null : 0;
342 $this->mParentId
= intval( $row->rev_parent_id
);
344 if( !isset( $row->rev_len
) ||
is_null( $row->rev_len
) )
347 $this->mSize
= intval( $row->rev_len
);
349 if( isset( $row->page_latest
) ) {
350 $this->mCurrent
= ( $row->rev_id
== $row->page_latest
);
351 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
352 $this->mTitle
->resetArticleID( $this->mPage
);
354 $this->mCurrent
= false;
355 $this->mTitle
= null;
358 // Lazy extraction...
360 if( isset( $row->old_text
) ) {
361 $this->mTextRow
= $row;
363 // 'text' table row entry will be lazy-loaded
364 $this->mTextRow
= null;
366 } elseif( is_array( $row ) ) {
367 // Build a new revision to be saved...
370 $this->mId
= isset( $row['id'] ) ?
intval( $row['id'] ) : null;
371 $this->mPage
= isset( $row['page'] ) ?
intval( $row['page'] ) : null;
372 $this->mTextId
= isset( $row['text_id'] ) ?
intval( $row['text_id'] ) : null;
373 $this->mUserText
= isset( $row['user_text'] ) ?
strval( $row['user_text'] ) : $wgUser->getName();
374 $this->mUser
= isset( $row['user'] ) ?
intval( $row['user'] ) : $wgUser->getId();
375 $this->mMinorEdit
= isset( $row['minor_edit'] ) ?
intval( $row['minor_edit'] ) : 0;
376 $this->mTimestamp
= isset( $row['timestamp'] ) ?
strval( $row['timestamp'] ) : wfTimestamp( TS_MW
);
377 $this->mDeleted
= isset( $row['deleted'] ) ?
intval( $row['deleted'] ) : 0;
378 $this->mSize
= isset( $row['len'] ) ?
intval( $row['len'] ) : null;
379 $this->mParentId
= isset( $row['parent_id'] ) ?
intval( $row['parent_id'] ) : null;
381 // Enforce spacing trimming on supplied text
382 $this->mComment
= isset( $row['comment'] ) ?
trim( strval( $row['comment'] ) ) : null;
383 $this->mText
= isset( $row['text'] ) ?
rtrim( strval( $row['text'] ) ) : null;
384 $this->mTextRow
= null;
386 $this->mTitle
= null; # Load on demand if needed
387 $this->mCurrent
= false;
388 # If we still have no len_size, see it we have the text to figure it out
390 $this->mSize
= is_null($this->mText
) ?
null : strlen($this->mText
);
392 throw new MWException( 'Revision constructor passed invalid row format.' );
394 $this->mUnpatrolled
= NULL;
405 public function getId() {
413 public function getTextId() {
414 return $this->mTextId
;
418 * Get parent revision ID (the original previous page revision)
421 public function getParentId() {
422 return $this->mParentId
;
426 * Returns the length of the text in this revision, or null if unknown.
429 public function getSize() {
434 * Returns the title of the page associated with this entry.
437 public function getTitle() {
438 if( isset( $this->mTitle
) ) {
439 return $this->mTitle
;
441 $dbr = wfGetDB( DB_SLAVE
);
442 $row = $dbr->selectRow(
443 array( 'page', 'revision' ),
444 array( 'page_namespace', 'page_title' ),
445 array( 'page_id=rev_page',
446 'rev_id' => $this->mId
),
447 'Revision::getTitle' );
449 $this->mTitle
= Title
::makeTitle( $row->page_namespace
,
452 return $this->mTitle
;
456 * Set the title of the revision
457 * @param Title $title
459 public function setTitle( $title ) {
460 $this->mTitle
= $title;
467 public function getPage() {
472 * Fetch revision's user id if it's available to the specified audience.
473 * If the specified audience does not have access to it, zero will be
476 * @param integer $audience One of:
477 * Revision::FOR_PUBLIC to be displayed to all users
478 * Revision::FOR_THIS_USER to be displayed to $wgUser
479 * Revision::RAW get the ID regardless of permissions
484 public function getUser( $audience = self
::FOR_PUBLIC
) {
485 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
487 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
495 * Fetch revision's user id without regard for the current user's permissions
498 public function getRawUser() {
503 * Fetch revision's username if it's available to the specified audience.
504 * If the specified audience does not have access to the username, an
505 * empty string will be returned.
507 * @param integer $audience One of:
508 * Revision::FOR_PUBLIC to be displayed to all users
509 * Revision::FOR_THIS_USER to be displayed to $wgUser
510 * Revision::RAW get the text regardless of permissions
514 public function getUserText( $audience = self
::FOR_PUBLIC
) {
515 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
517 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
520 return $this->mUserText
;
525 * Fetch revision's username without regard for view restrictions
528 public function getRawUserText() {
529 return $this->mUserText
;
533 * Fetch revision comment if it's available to the specified audience.
534 * If the specified audience does not have access to the comment, an
535 * empty string will be returned.
537 * @param integer $audience One of:
538 * Revision::FOR_PUBLIC to be displayed to all users
539 * Revision::FOR_THIS_USER to be displayed to $wgUser
540 * Revision::RAW get the text regardless of permissions
544 function getComment( $audience = self
::FOR_PUBLIC
) {
545 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_COMMENT
) ) {
547 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_COMMENT
) ) {
550 return $this->mComment
;
555 * Fetch revision comment without regard for the current user's permissions
558 public function getRawComment() {
559 return $this->mComment
;
565 public function isMinor() {
566 return (bool)$this->mMinorEdit
;
570 * @return int rcid of the unpatrolled row, zero if there isn't one
572 public function isUnpatrolled() {
573 if( $this->mUnpatrolled
!== NULL ) {
574 return $this->mUnpatrolled
;
576 $dbr = wfGetDB( DB_SLAVE
);
577 $this->mUnpatrolled
= $dbr->selectField( 'recentchanges',
579 array( // Add redundant user,timestamp condition so we can use the existing index
580 'rc_user_text' => $this->getRawUserText(),
581 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
582 'rc_this_oldid' => $this->getId(),
587 return (int)$this->mUnpatrolled
;
591 * int $field one of DELETED_* bitfield constants
594 public function isDeleted( $field ) {
595 return ($this->mDeleted
& $field) == $field;
599 * Get the deletion bitfield of the revision
601 public function getVisibility() {
602 return (int)$this->mDeleted
;
606 * Fetch revision text if it's available to the specified audience.
607 * If the specified audience does not have the ability to view this
608 * revision, an empty string will be returned.
610 * @param integer $audience One of:
611 * Revision::FOR_PUBLIC to be displayed to all users
612 * Revision::FOR_THIS_USER to be displayed to $wgUser
613 * Revision::RAW get the text regardless of permissions
618 public function getText( $audience = self
::FOR_PUBLIC
) {
619 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_TEXT
) ) {
621 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_TEXT
) ) {
624 return $this->getRawText();
629 * Alias for getText(Revision::FOR_THIS_USER)
631 public function revText() {
632 return $this->getText( self
::FOR_THIS_USER
);
636 * Fetch revision text without regard for view restrictions
639 public function getRawText() {
640 if( is_null( $this->mText
) ) {
641 // Revision text is immutable. Load on demand:
642 $this->mText
= $this->loadText();
650 public function getTimestamp() {
651 return wfTimestamp(TS_MW
, $this->mTimestamp
);
657 public function isCurrent() {
658 return $this->mCurrent
;
662 * Get previous revision for this title
665 public function getPrevious() {
666 if( $this->getTitle() ) {
667 $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
669 return Revision
::newFromTitle( $this->getTitle(), $prev );
678 public function getNext() {
679 if( $this->getTitle() ) {
680 $next = $this->getTitle()->getNextRevisionID( $this->getId() );
682 return Revision
::newFromTitle( $this->getTitle(), $next );
689 * Get previous revision Id for this page_id
690 * This is used to populate rev_parent_id on save
691 * @param Database $db
694 private function getPreviousRevisionId( $db ) {
695 if( is_null($this->mPage
) ) {
698 # Use page_latest if ID is not given
700 $prevId = $db->selectField( 'page', 'page_latest',
701 array( 'page_id' => $this->mPage
),
704 $prevId = $db->selectField( 'revision', 'rev_id',
705 array( 'rev_page' => $this->mPage
, 'rev_id < ' . $this->mId
),
707 array( 'ORDER BY' => 'rev_id DESC' ) );
709 return intval($prevId);
713 * Get revision text associated with an old or archive row
714 * $row is usually an object from wfFetchRow(), both the flags and the text
715 * field must be included
717 * @param object $row The text data
718 * @param string $prefix table prefix (default 'old_')
719 * @return string $text|false the text requested
721 public static function getRevisionText( $row, $prefix = 'old_' ) {
722 wfProfileIn( __METHOD__
);
725 $textField = $prefix . 'text';
726 $flagsField = $prefix . 'flags';
728 if( isset( $row->$flagsField ) ) {
729 $flags = explode( ',', $row->$flagsField );
734 if( isset( $row->$textField ) ) {
735 $text = $row->$textField;
737 wfProfileOut( __METHOD__
);
741 # Use external methods for external objects, text in table is URL-only then
742 if ( in_array( 'external', $flags ) ) {
744 @list
(/* $proto */,$path)=explode('://',$url,2);
746 wfProfileOut( __METHOD__
);
749 $text=ExternalStore
::fetchFromURL($url);
752 // If the text was fetched without an error, convert it
753 if ( $text !== false ) {
754 if( in_array( 'gzip', $flags ) ) {
755 # Deal with optional compression of archived pages.
756 # This can be done periodically via maintenance/compressOld.php, and
757 # as pages are saved if $wgCompressRevisions is set.
758 $text = gzinflate( $text );
761 if( in_array( 'object', $flags ) ) {
762 # Generic compressed storage
763 $obj = unserialize( $text );
764 if ( !is_object( $obj ) ) {
766 wfProfileOut( __METHOD__
);
769 $text = $obj->getText();
772 global $wgLegacyEncoding;
773 if( $wgLegacyEncoding && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) ) {
774 # Old revisions kept around in a legacy encoding?
775 # Upconvert on demand.
776 # ("utf8" checked for compatibility with some broken
777 # conversion scripts 2008-12-30)
778 global $wgInputEncoding, $wgContLang;
779 $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text );
782 wfProfileOut( __METHOD__
);
787 * If $wgCompressRevisions is enabled, we will compress data.
788 * The input string is modified in place.
789 * Return value is the flags field: contains 'gzip' if the
790 * data is compressed, and 'utf-8' if we're saving in UTF-8
793 * @param mixed $text reference to a text
796 public static function compressRevisionText( &$text ) {
797 global $wgCompressRevisions;
800 # Revisions not marked this way will be converted
801 # on load if $wgLegacyCharset is set in the future.
804 if( $wgCompressRevisions ) {
805 if( function_exists( 'gzdeflate' ) ) {
806 $text = gzdeflate( $text );
809 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
812 return implode( ',', $flags );
816 * Insert a new revision into the database, returning the new revision ID
817 * number on success and dies horribly on failure.
819 * @param Database $dbw
822 public function insertOn( $dbw ) {
823 global $wgDefaultExternalStore;
825 wfProfileIn( __METHOD__
);
827 $data = $this->mText
;
828 $flags = Revision
::compressRevisionText( $data );
830 # Write to external storage if required
831 if( $wgDefaultExternalStore ) {
832 // Store and get the URL
833 $data = ExternalStore
::insertToDefault( $data );
835 throw new MWException( "Unable to store text to external storage" );
840 $flags .= 'external';
843 # Record the text (or external storage URL) to the text table
844 if( !isset( $this->mTextId
) ) {
845 $old_id = $dbw->nextSequenceValue( 'text_old_id_val' );
846 $dbw->insert( 'text',
850 'old_flags' => $flags,
853 $this->mTextId
= $dbw->insertId();
856 # Record the edit in revisions
857 $rev_id = isset( $this->mId
)
859 : $dbw->nextSequenceValue( 'rev_rev_id_val' );
860 $dbw->insert( 'revision',
863 'rev_page' => $this->mPage
,
864 'rev_text_id' => $this->mTextId
,
865 'rev_comment' => $this->mComment
,
866 'rev_minor_edit' => $this->mMinorEdit ?
1 : 0,
867 'rev_user' => $this->mUser
,
868 'rev_user_text' => $this->mUserText
,
869 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp
),
870 'rev_deleted' => $this->mDeleted
,
871 'rev_len' => $this->mSize
,
872 'rev_parent_id' => is_null($this->mParentId
) ?
873 $this->getPreviousRevisionId( $dbw ) : $this->mParentId
877 $this->mId
= !is_null($rev_id) ?
$rev_id : $dbw->insertId();
879 wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
881 wfProfileOut( __METHOD__
);
886 * Lazy-load the revision's text.
887 * Currently hardcoded to the 'text' table storage engine.
891 protected function loadText() {
892 wfProfileIn( __METHOD__
);
894 // Caching may be beneficial for massive use of external storage
895 global $wgRevisionCacheExpiry, $wgMemc;
896 $textId = $this->getTextId();
897 $key = wfMemcKey( 'revisiontext', 'textid', $textId );
898 if( $wgRevisionCacheExpiry ) {
899 $text = $wgMemc->get( $key );
900 if( is_string( $text ) ) {
901 wfDebug( __METHOD__
. ": got id $textId from cache\n" );
902 wfProfileOut( __METHOD__
);
907 // If we kept data for lazy extraction, use it now...
908 if ( isset( $this->mTextRow
) ) {
909 $row = $this->mTextRow
;
910 $this->mTextRow
= null;
916 // Text data is immutable; check slaves first.
917 $dbr = wfGetDB( DB_SLAVE
);
918 $row = $dbr->selectRow( 'text',
919 array( 'old_text', 'old_flags' ),
920 array( 'old_id' => $this->getTextId() ),
924 if( !$row && wfGetLB()->getServerCount() > 1 ) {
925 // Possible slave lag!
926 $dbw = wfGetDB( DB_MASTER
);
927 $row = $dbw->selectRow( 'text',
928 array( 'old_text', 'old_flags' ),
929 array( 'old_id' => $this->getTextId() ),
933 $text = self
::getRevisionText( $row );
935 # No negative caching -- negative hits on text rows may be due to corrupted slave servers
936 if( $wgRevisionCacheExpiry && $text !== false ) {
937 $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
940 wfProfileOut( __METHOD__
);
946 * Create a new null-revision for insertion into a page's
947 * history. This will not re-save the text, but simply refer
948 * to the text from the previous version.
950 * Such revisions can for instance identify page rename
951 * operations and other such meta-modifications.
953 * @param Database $dbw
954 * @param int $pageId ID number of the page to read from
955 * @param string $summary
959 public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
960 wfProfileIn( __METHOD__
);
962 $current = $dbw->selectRow(
963 array( 'page', 'revision' ),
964 array( 'page_latest', 'rev_text_id', 'rev_len' ),
966 'page_id' => $pageId,
967 'page_latest=rev_id',
972 $revision = new Revision( array(
974 'comment' => $summary,
975 'minor_edit' => $minor,
976 'text_id' => $current->rev_text_id
,
977 'parent_id' => $current->page_latest
,
978 'len' => $current->rev_len
984 wfProfileOut( __METHOD__
);
989 * Determine if the current user is allowed to view a particular
990 * field of this revision, if it's marked as deleted.
991 * @param int $field one of self::DELETED_TEXT,
992 * self::DELETED_COMMENT,
996 public function userCan( $field ) {
997 if( ( $this->mDeleted
& $field ) == $field ) {
999 $permission = ( $this->mDeleted
& self
::DELETED_RESTRICTED
) == self
::DELETED_RESTRICTED
1000 ?
'suppressrevision'
1002 wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" );
1003 return $wgUser->isAllowed( $permission );
1011 * Get rev_timestamp from rev_id, without loading the rest of the row
1012 * @param Title $title
1013 * @param integer $id
1015 static function getTimestampFromId( $title, $id ) {
1016 $dbr = wfGetDB( DB_SLAVE
);
1017 // Casting fix for DB2
1021 $conds = array( 'rev_id' => $id );
1022 $conds['rev_page'] = $title->getArticleId();
1023 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1024 if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
1025 # Not in slave, try master
1026 $dbw = wfGetDB( DB_MASTER
);
1027 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1029 return wfTimestamp( TS_MW
, $timestamp );
1033 * Get count of revisions per page...not very efficient
1034 * @param Database $db
1035 * @param int $id, page id
1037 static function countByPageId( $db, $id ) {
1038 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
1039 array( 'rev_page' => $id ), __METHOD__
);
1041 return $row->revCount
;
1047 * Get count of revisions per page...not very efficient
1048 * @param Database $db
1049 * @param Title $title
1051 static function countByTitle( $db, $title ) {
1052 $id = $title->getArticleId();
1054 return Revision
::countByPageId( $db, $id );
1061 * Aliases for backwards compatibility with 1.6
1063 define( 'MW_REV_DELETED_TEXT', Revision
::DELETED_TEXT
);
1064 define( 'MW_REV_DELETED_COMMENT', Revision
::DELETED_COMMENT
);
1065 define( 'MW_REV_DELETED_USER', Revision
::DELETED_USER
);
1066 define( 'MW_REV_DELETED_RESTRICTED', Revision
::DELETED_RESTRICTED
);