11 const DELETED_TEXT
= 1;
12 const DELETED_COMMENT
= 2;
13 const DELETED_USER
= 4;
14 const DELETED_RESTRICTED
= 8;
16 const SUPPRESSED_USER
= 12;
17 // Audience options for Revision::getText()
19 const FOR_THIS_USER
= 2;
23 * Load a page revision from a given revision ID number.
24 * Returns null if no such revision can be found.
30 public static function newFromId( $id ) {
31 return Revision
::newFromConds(
32 array( 'page_id=rev_page',
33 'rev_id' => intval( $id ) ) );
37 * Load either the current, or a specified, revision
38 * that's attached to a given title. If not attached
39 * to that title, will return null.
45 public static function newFromTitle( $title, $id = 0 ) {
47 'page_namespace' => $title->getNamespace(),
48 'page_title' => $title->getDBkey()
51 // Use the specified ID
52 $conds['rev_id'] = $id;
53 } elseif ( wfGetLB()->getServerCount() > 1 ) {
54 // Get the latest revision ID from the master
55 $dbw = wfGetDB( DB_MASTER
);
56 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
57 if ( $latest === false ) {
58 // Page does not exist
61 $conds['rev_id'] = $latest;
63 // Use a join to get the latest revision
64 $conds[] = 'rev_id=page_latest';
66 $conds[] = 'page_id=rev_page';
67 return Revision
::newFromConds( $conds );
71 * Make a fake revision object from an archive table row. This is queried
72 * for permissions or even inserted (as in Special:Undelete)
73 * @fixme: should be a subclass for RevisionDelete. [TS]
75 public static function newFromArchiveRow( $row, $overrides = array() ) {
76 $attribs = $overrides +
array(
77 'page' => isset( $row->page_id
) ?
$row->page_id
: null,
78 'id' => isset( $row->ar_rev_id
) ?
$row->ar_rev_id
: null,
79 'comment' => $row->ar_comment
,
80 'user' => $row->ar_user
,
81 'user_text' => $row->ar_user_text
,
82 'timestamp' => $row->ar_timestamp
,
83 'minor_edit' => $row->ar_minor_edit
,
84 'text_id' => isset( $row->ar_text_id
) ?
$row->ar_text_id
: null,
85 'deleted' => $row->ar_deleted
,
86 'len' => $row->ar_len
);
87 if ( isset( $row->ar_text
) && !$row->ar_text_id
) {
88 // Pre-1.5 ar_text row
89 $attribs['text'] = self
::getRevisionText( $row, 'ar_' );
91 return new self( $attribs );
95 * Load a page revision from a given revision ID number.
96 * Returns null if no such revision can be found.
103 public static function loadFromId( $db, $id ) {
104 return Revision
::loadFromConds( $db,
105 array( 'page_id=rev_page',
106 'rev_id' => intval( $id ) ) );
110 * Load either the current, or a specified, revision
111 * that's attached to a given page. If not attached
112 * to that page, will return null.
114 * @param Database $db
121 public static function loadFromPageId( $db, $pageid, $id = 0 ) {
122 $conds=array('page_id=rev_page','rev_page'=>intval( $pageid ), 'page_id'=>intval( $pageid ));
124 $conds['rev_id']=intval($id);
126 $conds[]='rev_id=page_latest';
128 return Revision
::loadFromConds( $db, $conds );
132 * Load either the current, or a specified, revision
133 * that's attached to a given page. If not attached
134 * to that page, will return null.
136 * @param Database $db
137 * @param Title $title
143 public static function loadFromTitle( $db, $title, $id = 0 ) {
145 $matchId = intval( $id );
147 $matchId = 'page_latest';
149 return Revision
::loadFromConds(
151 array( "rev_id=$matchId",
153 'page_namespace' => $title->getNamespace(),
154 'page_title' => $title->getDBkey() ) );
158 * Load the revision for the given title with the given timestamp.
159 * WARNING: Timestamps may in some circumstances not be unique,
160 * so this isn't the best key to use.
162 * @param Database $db
163 * @param Title $title
164 * @param string $timestamp
169 public static function loadFromTimestamp( $db, $title, $timestamp ) {
170 return Revision
::loadFromConds(
172 array( 'rev_timestamp' => $db->timestamp( $timestamp ),
174 'page_namespace' => $title->getNamespace(),
175 'page_title' => $title->getDBkey() ) );
179 * Given a set of conditions, fetch a revision.
181 * @param array $conditions
186 public static function newFromConds( $conditions ) {
187 $db = wfGetDB( DB_SLAVE
);
188 $row = Revision
::loadFromConds( $db, $conditions );
189 if( is_null( $row ) && wfGetLB()->getServerCount() > 1 ) {
190 $dbw = wfGetDB( DB_MASTER
);
191 $row = Revision
::loadFromConds( $dbw, $conditions );
197 * Given a set of conditions, fetch a revision from
198 * the given database connection.
200 * @param Database $db
201 * @param array $conditions
206 private static function loadFromConds( $db, $conditions ) {
207 $res = Revision
::fetchFromConds( $db, $conditions );
209 $row = $res->fetchObject();
212 $ret = new Revision( $row );
221 * Return a wrapper for a series of database rows to
222 * fetch all of a given page's revisions in turn.
223 * Each row can be fed to the constructor to get objects.
225 * @param Title $title
226 * @return ResultWrapper
230 public static function fetchRevision( $title ) {
231 return Revision
::fetchFromConds(
233 array( 'rev_id=page_latest',
234 'page_namespace' => $title->getNamespace(),
235 'page_title' => $title->getDBkey(),
236 'page_id=rev_page' ) );
240 * Given a set of conditions, return a ResultWrapper
241 * which will return matching database rows with the
242 * fields necessary to build Revision objects.
244 * @param Database $db
245 * @param array $conditions
246 * @return ResultWrapper
250 private static function fetchFromConds( $db, $conditions ) {
251 $fields = self
::selectFields();
252 $fields[] = 'page_namespace';
253 $fields[] = 'page_title';
254 $fields[] = 'page_latest';
256 array( 'page', 'revision' ),
260 array( 'LIMIT' => 1 ) );
261 $ret = $db->resultObject( $res );
266 * Return the list of revision fields that should be selected to create
269 static function selectFields() {
286 * Return the list of text fields that should be selected to read the
289 static function selectTextFields() {
296 * Return the list of page fields that should be selected from page table
298 static function selectPageFields() {
310 function Revision( $row ) {
311 if( is_object( $row ) ) {
312 $this->mId
= intval( $row->rev_id
);
313 $this->mPage
= intval( $row->rev_page
);
314 $this->mTextId
= intval( $row->rev_text_id
);
315 $this->mComment
= $row->rev_comment
;
316 $this->mUserText
= $row->rev_user_text
;
317 $this->mUser
= intval( $row->rev_user
);
318 $this->mMinorEdit
= intval( $row->rev_minor_edit
);
319 $this->mTimestamp
= $row->rev_timestamp
;
320 $this->mDeleted
= intval( $row->rev_deleted
);
322 if( !isset( $row->rev_parent_id
) )
323 $this->mParentId
= is_null($row->rev_parent_id
) ?
null : 0;
325 $this->mParentId
= intval( $row->rev_parent_id
);
327 if( !isset( $row->rev_len
) ||
is_null( $row->rev_len
) )
330 $this->mSize
= intval( $row->rev_len
);
332 if( isset( $row->page_latest
) ) {
333 $this->mCurrent
= ( $row->rev_id
== $row->page_latest
);
334 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
335 $this->mTitle
->resetArticleID( $this->mPage
);
337 $this->mCurrent
= false;
338 $this->mTitle
= null;
341 // Lazy extraction...
343 if( isset( $row->old_text
) ) {
344 $this->mTextRow
= $row;
346 // 'text' table row entry will be lazy-loaded
347 $this->mTextRow
= null;
349 } elseif( is_array( $row ) ) {
350 // Build a new revision to be saved...
353 $this->mId
= isset( $row['id'] ) ?
intval( $row['id'] ) : null;
354 $this->mPage
= isset( $row['page'] ) ?
intval( $row['page'] ) : null;
355 $this->mTextId
= isset( $row['text_id'] ) ?
intval( $row['text_id'] ) : null;
356 $this->mUserText
= isset( $row['user_text'] ) ?
strval( $row['user_text'] ) : $wgUser->getName();
357 $this->mUser
= isset( $row['user'] ) ?
intval( $row['user'] ) : $wgUser->getId();
358 $this->mMinorEdit
= isset( $row['minor_edit'] ) ?
intval( $row['minor_edit'] ) : 0;
359 $this->mTimestamp
= isset( $row['timestamp'] ) ?
strval( $row['timestamp'] ) : wfTimestamp( TS_MW
);
360 $this->mDeleted
= isset( $row['deleted'] ) ?
intval( $row['deleted'] ) : 0;
361 $this->mSize
= isset( $row['len'] ) ?
intval( $row['len'] ) : null;
362 $this->mParentId
= isset( $row['parent_id'] ) ?
intval( $row['parent_id'] ) : null;
364 // Enforce spacing trimming on supplied text
365 $this->mComment
= isset( $row['comment'] ) ?
trim( strval( $row['comment'] ) ) : null;
366 $this->mText
= isset( $row['text'] ) ?
rtrim( strval( $row['text'] ) ) : null;
367 $this->mTextRow
= null;
369 $this->mTitle
= null; # Load on demand if needed
370 $this->mCurrent
= false;
371 # If we still have no len_size, see it we have the text to figure it out
373 $this->mSize
= is_null($this->mText
) ?
null : strlen($this->mText
);
375 throw new MWException( 'Revision constructor passed invalid row format.' );
377 $this->mUnpatrolled
= NULL;
388 public function getId() {
396 public function getTextId() {
397 return $this->mTextId
;
401 * Get parent revision ID (the original previous page revision)
404 public function getParentId() {
405 return $this->mParentId
;
409 * Returns the length of the text in this revision, or null if unknown.
412 public function getSize() {
417 * Returns the title of the page associated with this entry.
420 public function getTitle() {
421 if( isset( $this->mTitle
) ) {
422 return $this->mTitle
;
424 $dbr = wfGetDB( DB_SLAVE
);
425 $row = $dbr->selectRow(
426 array( 'page', 'revision' ),
427 array( 'page_namespace', 'page_title' ),
428 array( 'page_id=rev_page',
429 'rev_id' => $this->mId
),
430 'Revision::getTitle' );
432 $this->mTitle
= Title
::makeTitle( $row->page_namespace
,
435 return $this->mTitle
;
439 * Set the title of the revision
440 * @param Title $title
442 public function setTitle( $title ) {
443 $this->mTitle
= $title;
450 public function getPage() {
455 * Fetch revision's user id if it's available to the specified audience.
456 * If the specified audience does not have access to it, zero will be
459 * @param integer $audience One of:
460 * Revision::FOR_PUBLIC to be displayed to all users
461 * Revision::FOR_THIS_USER to be displayed to $wgUser
462 * Revision::RAW get the ID regardless of permissions
467 public function getUser( $audience = self
::FOR_PUBLIC
) {
468 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
470 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
478 * Fetch revision's user id without regard for the current user's permissions
481 public function getRawUser() {
486 * Fetch revision's username if it's available to the specified audience.
487 * If the specified audience does not have access to the username, an
488 * empty string will be returned.
490 * @param integer $audience One of:
491 * Revision::FOR_PUBLIC to be displayed to all users
492 * Revision::FOR_THIS_USER to be displayed to $wgUser
493 * Revision::RAW get the text regardless of permissions
497 public function getUserText( $audience = self
::FOR_PUBLIC
) {
498 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
500 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
503 return $this->mUserText
;
508 * Fetch revision's username without regard for view restrictions
511 public function getRawUserText() {
512 return $this->mUserText
;
516 * Fetch revision comment if it's available to the specified audience.
517 * If the specified audience does not have access to the comment, an
518 * empty string will be returned.
520 * @param integer $audience One of:
521 * Revision::FOR_PUBLIC to be displayed to all users
522 * Revision::FOR_THIS_USER to be displayed to $wgUser
523 * Revision::RAW get the text regardless of permissions
527 function getComment( $audience = self
::FOR_PUBLIC
) {
528 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_COMMENT
) ) {
530 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_COMMENT
) ) {
533 return $this->mComment
;
538 * Fetch revision comment without regard for the current user's permissions
541 public function getRawComment() {
542 return $this->mComment
;
548 public function isMinor() {
549 return (bool)$this->mMinorEdit
;
553 * @return int rcid of the unpatrolled row, zero if there isn't one
555 public function isUnpatrolled() {
556 if( $this->mUnpatrolled
!== NULL ) {
557 return $this->mUnpatrolled
;
559 $dbr = wfGetDB( DB_SLAVE
);
560 $this->mUnpatrolled
= $dbr->selectField( 'recentchanges',
562 array( // Add redundant user,timestamp condition so we can use the existing index
563 'rc_user_text' => $this->getRawUserText(),
564 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
565 'rc_this_oldid' => $this->getId(),
570 return (int)$this->mUnpatrolled
;
574 * int $field one of DELETED_* bitfield constants
577 public function isDeleted( $field ) {
578 return ($this->mDeleted
& $field) == $field;
582 * Get the deletion bitfield of the revision
584 public function getVisibility() {
585 return (int)$this->mDeleted
;
589 * Fetch revision text if it's available to the specified audience.
590 * If the specified audience does not have the ability to view this
591 * revision, an empty string will be returned.
593 * @param integer $audience One of:
594 * Revision::FOR_PUBLIC to be displayed to all users
595 * Revision::FOR_THIS_USER to be displayed to $wgUser
596 * Revision::RAW get the text regardless of permissions
601 public function getText( $audience = self
::FOR_PUBLIC
) {
602 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_TEXT
) ) {
604 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_TEXT
) ) {
607 return $this->getRawText();
612 * Alias for getText(Revision::FOR_THIS_USER)
614 public function revText() {
615 return $this->getText( self
::FOR_THIS_USER
);
619 * Fetch revision text without regard for view restrictions
622 public function getRawText() {
623 if( is_null( $this->mText
) ) {
624 // Revision text is immutable. Load on demand:
625 $this->mText
= $this->loadText();
633 public function getTimestamp() {
634 return wfTimestamp(TS_MW
, $this->mTimestamp
);
640 public function isCurrent() {
641 return $this->mCurrent
;
645 * Get previous revision for this title
648 public function getPrevious() {
649 if( $this->getTitle() ) {
650 $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
652 return Revision
::newFromTitle( $this->getTitle(), $prev );
661 public function getNext() {
662 if( $this->getTitle() ) {
663 $next = $this->getTitle()->getNextRevisionID( $this->getId() );
665 return Revision
::newFromTitle( $this->getTitle(), $next );
672 * Get previous revision Id for this page_id
673 * This is used to populate rev_parent_id on save
674 * @param Database $db
677 private function getPreviousRevisionId( $db ) {
678 if( is_null($this->mPage
) ) {
681 # Use page_latest if ID is not given
683 $prevId = $db->selectField( 'page', 'page_latest',
684 array( 'page_id' => $this->mPage
),
687 $prevId = $db->selectField( 'revision', 'rev_id',
688 array( 'rev_page' => $this->mPage
, 'rev_id < ' . $this->mId
),
690 array( 'ORDER BY' => 'rev_id DESC' ) );
692 return intval($prevId);
696 * Get revision text associated with an old or archive row
697 * $row is usually an object from wfFetchRow(), both the flags and the text
698 * field must be included
700 * @param object $row The text data
701 * @param string $prefix table prefix (default 'old_')
702 * @return string $text|false the text requested
704 public static function getRevisionText( $row, $prefix = 'old_' ) {
705 wfProfileIn( __METHOD__
);
708 $textField = $prefix . 'text';
709 $flagsField = $prefix . 'flags';
711 if( isset( $row->$flagsField ) ) {
712 $flags = explode( ',', $row->$flagsField );
717 if( isset( $row->$textField ) ) {
718 $text = $row->$textField;
720 wfProfileOut( __METHOD__
);
724 # Use external methods for external objects, text in table is URL-only then
725 if ( in_array( 'external', $flags ) ) {
727 @list
(/* $proto */,$path)=explode('://',$url,2);
729 wfProfileOut( __METHOD__
);
732 $text=ExternalStore
::fetchFromURL($url);
735 // If the text was fetched without an error, convert it
736 if ( $text !== false ) {
737 if( in_array( 'gzip', $flags ) ) {
738 # Deal with optional compression of archived pages.
739 # This can be done periodically via maintenance/compressOld.php, and
740 # as pages are saved if $wgCompressRevisions is set.
741 $text = gzinflate( $text );
744 if( in_array( 'object', $flags ) ) {
745 # Generic compressed storage
746 $obj = unserialize( $text );
747 if ( !is_object( $obj ) ) {
749 wfProfileOut( __METHOD__
);
752 $text = $obj->getText();
755 global $wgLegacyEncoding;
756 if( $wgLegacyEncoding && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) ) {
757 # Old revisions kept around in a legacy encoding?
758 # Upconvert on demand.
759 # ("utf8" checked for compatibility with some broken
760 # conversion scripts 2008-12-30)
761 global $wgInputEncoding, $wgContLang;
762 $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text );
765 wfProfileOut( __METHOD__
);
770 * If $wgCompressRevisions is enabled, we will compress data.
771 * The input string is modified in place.
772 * Return value is the flags field: contains 'gzip' if the
773 * data is compressed, and 'utf-8' if we're saving in UTF-8
776 * @param mixed $text reference to a text
779 public static function compressRevisionText( &$text ) {
780 global $wgCompressRevisions;
783 # Revisions not marked this way will be converted
784 # on load if $wgLegacyCharset is set in the future.
787 if( $wgCompressRevisions ) {
788 if( function_exists( 'gzdeflate' ) ) {
789 $text = gzdeflate( $text );
792 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
795 return implode( ',', $flags );
799 * Insert a new revision into the database, returning the new revision ID
800 * number on success and dies horribly on failure.
802 * @param Database $dbw
805 public function insertOn( $dbw ) {
806 global $wgDefaultExternalStore;
808 wfProfileIn( __METHOD__
);
810 $data = $this->mText
;
811 $flags = Revision
::compressRevisionText( $data );
813 # Write to external storage if required
814 if( $wgDefaultExternalStore ) {
815 // Store and get the URL
816 $data = ExternalStore
::insertToDefault( $data );
818 throw new MWException( "Unable to store text to external storage" );
823 $flags .= 'external';
826 # Record the text (or external storage URL) to the text table
827 if( !isset( $this->mTextId
) ) {
828 $old_id = $dbw->nextSequenceValue( 'text_old_id_val' );
829 $dbw->insert( 'text',
833 'old_flags' => $flags,
836 $this->mTextId
= $dbw->insertId();
839 # Record the edit in revisions
840 $rev_id = isset( $this->mId
)
842 : $dbw->nextSequenceValue( 'rev_rev_id_val' );
843 $dbw->insert( 'revision',
846 'rev_page' => $this->mPage
,
847 'rev_text_id' => $this->mTextId
,
848 'rev_comment' => $this->mComment
,
849 'rev_minor_edit' => $this->mMinorEdit ?
1 : 0,
850 'rev_user' => $this->mUser
,
851 'rev_user_text' => $this->mUserText
,
852 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp
),
853 'rev_deleted' => $this->mDeleted
,
854 'rev_len' => $this->mSize
,
855 'rev_parent_id' => is_null($this->mParentId
) ?
856 $this->getPreviousRevisionId( $dbw ) : $this->mParentId
860 $this->mId
= !is_null($rev_id) ?
$rev_id : $dbw->insertId();
862 wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
864 wfProfileOut( __METHOD__
);
869 * Lazy-load the revision's text.
870 * Currently hardcoded to the 'text' table storage engine.
874 protected function loadText() {
875 wfProfileIn( __METHOD__
);
877 // Caching may be beneficial for massive use of external storage
878 global $wgRevisionCacheExpiry, $wgMemc;
879 $textId = $this->getTextId();
880 $key = wfMemcKey( 'revisiontext', 'textid', $textId );
881 if( $wgRevisionCacheExpiry ) {
882 $text = $wgMemc->get( $key );
883 if( is_string( $text ) ) {
884 wfDebug( __METHOD__
. ": got id $textId from cache\n" );
885 wfProfileOut( __METHOD__
);
890 // If we kept data for lazy extraction, use it now...
891 if ( isset( $this->mTextRow
) ) {
892 $row = $this->mTextRow
;
893 $this->mTextRow
= null;
899 // Text data is immutable; check slaves first.
900 $dbr = wfGetDB( DB_SLAVE
);
901 $row = $dbr->selectRow( 'text',
902 array( 'old_text', 'old_flags' ),
903 array( 'old_id' => $this->getTextId() ),
907 if( !$row && wfGetLB()->getServerCount() > 1 ) {
908 // Possible slave lag!
909 $dbw = wfGetDB( DB_MASTER
);
910 $row = $dbw->selectRow( 'text',
911 array( 'old_text', 'old_flags' ),
912 array( 'old_id' => $this->getTextId() ),
916 $text = self
::getRevisionText( $row );
918 # No negative caching -- negative hits on text rows may be due to corrupted slave servers
919 if( $wgRevisionCacheExpiry && $text !== false ) {
920 $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
923 wfProfileOut( __METHOD__
);
929 * Create a new null-revision for insertion into a page's
930 * history. This will not re-save the text, but simply refer
931 * to the text from the previous version.
933 * Such revisions can for instance identify page rename
934 * operations and other such meta-modifications.
936 * @param Database $dbw
937 * @param int $pageId ID number of the page to read from
938 * @param string $summary
940 * @return mixed Revision, or null on error
942 public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
943 wfProfileIn( __METHOD__
);
945 $current = $dbw->selectRow(
946 array( 'page', 'revision' ),
947 array( 'page_latest', 'rev_text_id', 'rev_len' ),
949 'page_id' => $pageId,
950 'page_latest=rev_id',
955 $revision = new Revision( array(
957 'comment' => $summary,
958 'minor_edit' => $minor,
959 'text_id' => $current->rev_text_id
,
960 'parent_id' => $current->page_latest
,
961 'len' => $current->rev_len
967 wfProfileOut( __METHOD__
);
972 * Determine if the current user is allowed to view a particular
973 * field of this revision, if it's marked as deleted.
974 * @param int $field one of self::DELETED_TEXT,
975 * self::DELETED_COMMENT,
979 public function userCan( $field ) {
980 if( ( $this->mDeleted
& $field ) == $field ) {
982 $permission = ( $this->mDeleted
& self
::DELETED_RESTRICTED
) == self
::DELETED_RESTRICTED
985 wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" );
986 return $wgUser->isAllowed( $permission );
994 * Get rev_timestamp from rev_id, without loading the rest of the row
995 * @param Title $title
998 static function getTimestampFromId( $title, $id ) {
999 $dbr = wfGetDB( DB_SLAVE
);
1000 // Casting fix for DB2
1004 $conds = array( 'rev_id' => $id );
1005 $conds['rev_page'] = $title->getArticleId();
1006 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1007 if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
1008 # Not in slave, try master
1009 $dbw = wfGetDB( DB_MASTER
);
1010 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1012 return wfTimestamp( TS_MW
, $timestamp );
1016 * Get count of revisions per page...not very efficient
1017 * @param Database $db
1018 * @param int $id, page id
1020 static function countByPageId( $db, $id ) {
1021 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
1022 array( 'rev_page' => $id ), __METHOD__
);
1024 return $row->revCount
;
1030 * Get count of revisions per page...not very efficient
1031 * @param Database $db
1032 * @param Title $title
1034 static function countByTitle( $db, $title ) {
1035 $id = $title->getArticleId();
1037 return Revision
::countByPageId( $db, $id );
1044 * Aliases for backwards compatibility with 1.6
1046 define( 'MW_REV_DELETED_TEXT', Revision
::DELETED_TEXT
);
1047 define( 'MW_REV_DELETED_COMMENT', Revision
::DELETED_COMMENT
);
1048 define( 'MW_REV_DELETED_USER', Revision
::DELETED_USER
);
1049 define( 'MW_REV_DELETED_RESTRICTED', Revision
::DELETED_RESTRICTED
);