00001 <?php
00002
00006 class Revision {
00007 const DELETED_TEXT = 1;
00008 const DELETED_COMMENT = 2;
00009 const DELETED_USER = 4;
00010 const DELETED_RESTRICTED = 8;
00011
00012 const SUPPRESSED_USER = 12;
00013
00014 const FOR_PUBLIC = 1;
00015 const FOR_THIS_USER = 2;
00016 const RAW = 3;
00017
00025 public static function newFromId( $id ) {
00026 return Revision::newFromConds(
00027 array( 'page_id=rev_page',
00028 'rev_id' => intval( $id ) ) );
00029 }
00030
00040 public static function newFromTitle( $title, $id = 0 ) {
00041 $conds = array(
00042 'page_namespace' => $title->getNamespace(),
00043 'page_title' => $title->getDBkey()
00044 );
00045 if ( $id ) {
00046
00047 $conds['rev_id'] = $id;
00048 } elseif ( wfGetLB()->getServerCount() > 1 ) {
00049
00050 $dbw = wfGetDB( DB_MASTER );
00051 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ );
00052 if ( $latest === false ) {
00053
00054 return null;
00055 }
00056 $conds['rev_id'] = $latest;
00057 } else {
00058
00059 $conds[] = 'rev_id=page_latest';
00060 }
00061 $conds[] = 'page_id=rev_page';
00062 return Revision::newFromConds( $conds );
00063 }
00064
00070 public static function newFromArchiveRow( $row, $overrides = array() ) {
00071 $attribs = $overrides + array(
00072 'page' => isset( $row->page_id ) ? $row->page_id : null,
00073 'id' => isset( $row->ar_rev_id ) ? $row->ar_rev_id : null,
00074 'comment' => $row->ar_comment,
00075 'user' => $row->ar_user,
00076 'user_text' => $row->ar_user_text,
00077 'timestamp' => $row->ar_timestamp,
00078 'minor_edit' => $row->ar_minor_edit,
00079 'text_id' => isset( $row->ar_text_id ) ? $row->ar_text_id : null,
00080 'deleted' => $row->ar_deleted,
00081 'len' => $row->ar_len);
00082 if ( isset( $row->ar_text ) && !$row->ar_text_id ) {
00083
00084 $attribs['text'] = self::getRevisionText( $row, 'ar_' );
00085 }
00086 return new self( $attribs );
00087 }
00088
00097 public static function loadFromId( $db, $id ) {
00098 return Revision::loadFromConds( $db,
00099 array( 'page_id=rev_page',
00100 'rev_id' => intval( $id ) ) );
00101 }
00102
00113 public static function loadFromPageId( $db, $pageid, $id = 0 ) {
00114 $conds = array( 'page_id=rev_page','rev_page' => intval( $pageid ), 'page_id'=>intval( $pageid ) );
00115 if( $id ) {
00116 $conds['rev_id'] = intval( $id );
00117 } else {
00118 $conds[] = 'rev_id=page_latest';
00119 }
00120 return Revision::loadFromConds( $db, $conds );
00121 }
00122
00133 public static function loadFromTitle( $db, $title, $id = 0 ) {
00134 if( $id ) {
00135 $matchId = intval( $id );
00136 } else {
00137 $matchId = 'page_latest';
00138 }
00139 return Revision::loadFromConds(
00140 $db,
00141 array( "rev_id=$matchId",
00142 'page_id=rev_page',
00143 'page_namespace' => $title->getNamespace(),
00144 'page_title' => $title->getDBkey() ) );
00145 }
00146
00157 public static function loadFromTimestamp( $db, $title, $timestamp ) {
00158 return Revision::loadFromConds(
00159 $db,
00160 array( 'rev_timestamp' => $db->timestamp( $timestamp ),
00161 'page_id=rev_page',
00162 'page_namespace' => $title->getNamespace(),
00163 'page_title' => $title->getDBkey() ) );
00164 }
00165
00172 public static function newFromConds( $conditions ) {
00173 $db = wfGetDB( DB_SLAVE );
00174 $row = Revision::loadFromConds( $db, $conditions );
00175 if( is_null( $row ) && wfGetLB()->getServerCount() > 1 ) {
00176 $dbw = wfGetDB( DB_MASTER );
00177 $row = Revision::loadFromConds( $dbw, $conditions );
00178 }
00179 return $row;
00180 }
00181
00190 private static function loadFromConds( $db, $conditions ) {
00191 $res = Revision::fetchFromConds( $db, $conditions );
00192 if( $res ) {
00193 $row = $res->fetchObject();
00194 $res->free();
00195 if( $row ) {
00196 $ret = new Revision( $row );
00197 return $ret;
00198 }
00199 }
00200 $ret = null;
00201 return $ret;
00202 }
00203
00212 public static function fetchRevision( $title ) {
00213 return Revision::fetchFromConds(
00214 wfGetDB( DB_SLAVE ),
00215 array( 'rev_id=page_latest',
00216 'page_namespace' => $title->getNamespace(),
00217 'page_title' => $title->getDBkey(),
00218 'page_id=rev_page' ) );
00219 }
00220
00230 private static function fetchFromConds( $db, $conditions ) {
00231 $fields = self::selectFields();
00232 $fields[] = 'page_namespace';
00233 $fields[] = 'page_title';
00234 $fields[] = 'page_latest';
00235 $res = $db->select(
00236 array( 'page', 'revision' ),
00237 $fields,
00238 $conditions,
00239 __METHOD__,
00240 array( 'LIMIT' => 1 ) );
00241 $ret = $db->resultObject( $res );
00242 return $ret;
00243 }
00244
00249 static function selectFields() {
00250 return array(
00251 'rev_id',
00252 'rev_page',
00253 'rev_text_id',
00254 'rev_timestamp',
00255 'rev_comment',
00256 'rev_user_text,'.
00257 'rev_user',
00258 'rev_minor_edit',
00259 'rev_deleted',
00260 'rev_len',
00261 'rev_parent_id'
00262 );
00263 }
00264
00269 static function selectTextFields() {
00270 return array(
00271 'old_text',
00272 'old_flags'
00273 );
00274 }
00275
00279 static function selectPageFields() {
00280 return array(
00281 'page_namespace',
00282 'page_title',
00283 'page_latest'
00284 );
00285 }
00286
00293 function Revision( $row ) {
00294 if( is_object( $row ) ) {
00295 $this->mId = intval( $row->rev_id );
00296 $this->mPage = intval( $row->rev_page );
00297 $this->mTextId = intval( $row->rev_text_id );
00298 $this->mComment = $row->rev_comment;
00299 $this->mUserText = $row->rev_user_text;
00300 $this->mUser = intval( $row->rev_user );
00301 $this->mMinorEdit = intval( $row->rev_minor_edit );
00302 $this->mTimestamp = $row->rev_timestamp;
00303 $this->mDeleted = intval( $row->rev_deleted );
00304
00305 if( !isset( $row->rev_parent_id ) )
00306 $this->mParentId = is_null($row->rev_parent_id) ? null : 0;
00307 else
00308 $this->mParentId = intval( $row->rev_parent_id );
00309
00310 if( !isset( $row->rev_len ) || is_null( $row->rev_len ) )
00311 $this->mSize = null;
00312 else
00313 $this->mSize = intval( $row->rev_len );
00314
00315 if( isset( $row->page_latest ) ) {
00316 $this->mCurrent = ( $row->rev_id == $row->page_latest );
00317 $this->mTitle = Title::makeTitle( $row->page_namespace, $row->page_title );
00318 $this->mTitle->resetArticleID( $this->mPage );
00319 } else {
00320 $this->mCurrent = false;
00321 $this->mTitle = null;
00322 }
00323
00324
00325 $this->mText = null;
00326 if( isset( $row->old_text ) ) {
00327 $this->mTextRow = $row;
00328 } else {
00329
00330 $this->mTextRow = null;
00331 }
00332 } elseif( is_array( $row ) ) {
00333
00334 global $wgUser;
00335
00336 $this->mId = isset( $row['id'] ) ? intval( $row['id'] ) : null;
00337 $this->mPage = isset( $row['page'] ) ? intval( $row['page'] ) : null;
00338 $this->mTextId = isset( $row['text_id'] ) ? intval( $row['text_id'] ) : null;
00339 $this->mUserText = isset( $row['user_text'] ) ? strval( $row['user_text'] ) : $wgUser->getName();
00340 $this->mUser = isset( $row['user'] ) ? intval( $row['user'] ) : $wgUser->getId();
00341 $this->mMinorEdit = isset( $row['minor_edit'] ) ? intval( $row['minor_edit'] ) : 0;
00342 $this->mTimestamp = isset( $row['timestamp'] ) ? strval( $row['timestamp'] ) : wfTimestamp( TS_MW );
00343 $this->mDeleted = isset( $row['deleted'] ) ? intval( $row['deleted'] ) : 0;
00344 $this->mSize = isset( $row['len'] ) ? intval( $row['len'] ) : null;
00345 $this->mParentId = isset( $row['parent_id'] ) ? intval( $row['parent_id'] ) : null;
00346
00347
00348 $this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null;
00349 $this->mText = isset( $row['text'] ) ? rtrim( strval( $row['text'] ) ) : null;
00350 $this->mTextRow = null;
00351
00352 $this->mTitle = null; # Load on demand if needed
00353 $this->mCurrent = false;
00354 # If we still have no len_size, see it we have the text to figure it out
00355 if ( !$this->mSize )
00356 $this->mSize = is_null( $this->mText ) ? null : strlen( $this->mText );
00357 } else {
00358 throw new MWException( 'Revision constructor passed invalid row format.' );
00359 }
00360 $this->mUnpatrolled = null;
00361 }
00362
00368 public function getId() {
00369 return $this->mId;
00370 }
00371
00377 public function getTextId() {
00378 return $this->mTextId;
00379 }
00380
00386 public function getParentId() {
00387 return $this->mParentId;
00388 }
00389
00395 public function getSize() {
00396 return $this->mSize;
00397 }
00398
00404 public function getTitle() {
00405 if( isset( $this->mTitle ) ) {
00406 return $this->mTitle;
00407 }
00408 $dbr = wfGetDB( DB_SLAVE );
00409 $row = $dbr->selectRow(
00410 array( 'page', 'revision' ),
00411 array( 'page_namespace', 'page_title' ),
00412 array( 'page_id=rev_page',
00413 'rev_id' => $this->mId ),
00414 'Revision::getTitle' );
00415 if( $row ) {
00416 $this->mTitle = Title::makeTitle( $row->page_namespace,
00417 $row->page_title );
00418 }
00419 return $this->mTitle;
00420 }
00421
00427 public function setTitle( $title ) {
00428 $this->mTitle = $title;
00429 }
00430
00436 public function getPage() {
00437 return $this->mPage;
00438 }
00439
00453 public function getUser( $audience = self::FOR_PUBLIC ) {
00454 if( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_USER ) ) {
00455 return 0;
00456 } elseif( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_USER ) ) {
00457 return 0;
00458 } else {
00459 return $this->mUser;
00460 }
00461 }
00462
00468 public function getRawUser() {
00469 return $this->mUser;
00470 }
00471
00484 public function getUserText( $audience = self::FOR_PUBLIC ) {
00485 if( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_USER ) ) {
00486 return '';
00487 } elseif( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_USER ) ) {
00488 return '';
00489 } else {
00490 return $this->mUserText;
00491 }
00492 }
00493
00499 public function getRawUserText() {
00500 return $this->mUserText;
00501 }
00502
00515 function getComment( $audience = self::FOR_PUBLIC ) {
00516 if( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_COMMENT ) ) {
00517 return '';
00518 } elseif( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_COMMENT ) ) {
00519 return '';
00520 } else {
00521 return $this->mComment;
00522 }
00523 }
00524
00530 public function getRawComment() {
00531 return $this->mComment;
00532 }
00533
00537 public function isMinor() {
00538 return (bool)$this->mMinorEdit;
00539 }
00540
00544 public function isUnpatrolled() {
00545 if( $this->mUnpatrolled !== null ) {
00546 return $this->mUnpatrolled;
00547 }
00548 $dbr = wfGetDB( DB_SLAVE );
00549 $this->mUnpatrolled = $dbr->selectField( 'recentchanges',
00550 'rc_id',
00551 array(
00552 'rc_user_text' => $this->getRawUserText(),
00553 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
00554 'rc_this_oldid' => $this->getId(),
00555 'rc_patrolled' => 0
00556 ),
00557 __METHOD__
00558 );
00559 return (int)$this->mUnpatrolled;
00560 }
00561
00567 public function isDeleted( $field ) {
00568 return ( $this->mDeleted & $field ) == $field;
00569 }
00570
00574 public function getVisibility() {
00575 return (int)$this->mDeleted;
00576 }
00577
00591 public function getText( $audience = self::FOR_PUBLIC ) {
00592 if( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_TEXT ) ) {
00593 return '';
00594 } elseif( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_TEXT ) ) {
00595 return '';
00596 } else {
00597 return $this->getRawText();
00598 }
00599 }
00600
00606 public function revText() {
00607 return $this->getText( self::FOR_THIS_USER );
00608 }
00609
00615 public function getRawText() {
00616 if( is_null( $this->mText ) ) {
00617
00618 $this->mText = $this->loadText();
00619 }
00620 return $this->mText;
00621 }
00622
00626 public function getTimestamp() {
00627 return wfTimestamp( TS_MW, $this->mTimestamp );
00628 }
00629
00633 public function isCurrent() {
00634 return $this->mCurrent;
00635 }
00636
00642 public function getPrevious() {
00643 if( $this->getTitle() ) {
00644 $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
00645 if( $prev ) {
00646 return Revision::newFromTitle( $this->getTitle(), $prev );
00647 }
00648 }
00649 return null;
00650 }
00651
00657 public function getNext() {
00658 if( $this->getTitle() ) {
00659 $next = $this->getTitle()->getNextRevisionID( $this->getId() );
00660 if ( $next ) {
00661 return Revision::newFromTitle( $this->getTitle(), $next );
00662 }
00663 }
00664 return null;
00665 }
00666
00674 private function getPreviousRevisionId( $db ) {
00675 if( is_null( $this->mPage ) ) {
00676 return 0;
00677 }
00678 # Use page_latest if ID is not given
00679 if( !$this->mId ) {
00680 $prevId = $db->selectField( 'page', 'page_latest',
00681 array( 'page_id' => $this->mPage ),
00682 __METHOD__ );
00683 } else {
00684 $prevId = $db->selectField( 'revision', 'rev_id',
00685 array( 'rev_page' => $this->mPage, 'rev_id < ' . $this->mId ),
00686 __METHOD__,
00687 array( 'ORDER BY' => 'rev_id DESC' ) );
00688 }
00689 return intval( $prevId );
00690 }
00691
00701 public static function getRevisionText( $row, $prefix = 'old_' ) {
00702 wfProfileIn( __METHOD__ );
00703
00704 # Get data
00705 $textField = $prefix . 'text';
00706 $flagsField = $prefix . 'flags';
00707
00708 if( isset( $row->$flagsField ) ) {
00709 $flags = explode( ',', $row->$flagsField );
00710 } else {
00711 $flags = array();
00712 }
00713
00714 if( isset( $row->$textField ) ) {
00715 $text = $row->$textField;
00716 } else {
00717 wfProfileOut( __METHOD__ );
00718 return false;
00719 }
00720
00721 # Use external methods for external objects, text in table is URL-only then
00722 if ( in_array( 'external', $flags ) ) {
00723 $url = $text;
00724 @list(, $path ) = explode( '://', $url, 2 );
00725 if( $path == '' ) {
00726 wfProfileOut( __METHOD__ );
00727 return false;
00728 }
00729 $text = ExternalStore::fetchFromURL( $url );
00730 }
00731
00732
00733 if ( $text !== false ) {
00734 if( in_array( 'gzip', $flags ) ) {
00735 # Deal with optional compression of archived pages.
00736 # This can be done periodically via maintenance/compressOld.php, and
00737 # as pages are saved if $wgCompressRevisions is set.
00738 $text = gzinflate( $text );
00739 }
00740
00741 if( in_array( 'object', $flags ) ) {
00742 # Generic compressed storage
00743 $obj = unserialize( $text );
00744 if ( !is_object( $obj ) ) {
00745
00746 wfProfileOut( __METHOD__ );
00747 return false;
00748 }
00749 $text = $obj->getText();
00750 }
00751
00752 global $wgLegacyEncoding;
00753 if( $text !== false && $wgLegacyEncoding
00754 && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) )
00755 {
00756 # Old revisions kept around in a legacy encoding?
00757 # Upconvert on demand.
00758 # ("utf8" checked for compatibility with some broken
00759 # conversion scripts 2008-12-30)
00760 global $wgInputEncoding, $wgContLang;
00761 $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text );
00762 }
00763 }
00764 wfProfileOut( __METHOD__ );
00765 return $text;
00766 }
00767
00778 public static function compressRevisionText( &$text ) {
00779 global $wgCompressRevisions;
00780 $flags = array();
00781
00782 # Revisions not marked this way will be converted
00783 # on load if $wgLegacyCharset is set in the future.
00784 $flags[] = 'utf-8';
00785
00786 if( $wgCompressRevisions ) {
00787 if( function_exists( 'gzdeflate' ) ) {
00788 $text = gzdeflate( $text );
00789 $flags[] = 'gzip';
00790 } else {
00791 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
00792 }
00793 }
00794 return implode( ',', $flags );
00795 }
00796
00804 public function insertOn( $dbw ) {
00805 global $wgDefaultExternalStore;
00806
00807 wfProfileIn( __METHOD__ );
00808
00809 $data = $this->mText;
00810 $flags = Revision::compressRevisionText( $data );
00811
00812 # Write to external storage if required
00813 if( $wgDefaultExternalStore ) {
00814
00815 $data = ExternalStore::insertToDefault( $data );
00816 if( !$data ) {
00817 throw new MWException( "Unable to store text to external storage" );
00818 }
00819 if( $flags ) {
00820 $flags .= ',';
00821 }
00822 $flags .= 'external';
00823 }
00824
00825 # Record the text (or external storage URL) to the text table
00826 if( !isset( $this->mTextId ) ) {
00827 $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
00828 $dbw->insert( 'text',
00829 array(
00830 'old_id' => $old_id,
00831 'old_text' => $data,
00832 'old_flags' => $flags,
00833 ), __METHOD__
00834 );
00835 $this->mTextId = $dbw->insertId();
00836 }
00837
00838 if ( $this->mComment === null ) $this->mComment = "";
00839
00840 # Record the edit in revisions
00841 $rev_id = isset( $this->mId )
00842 ? $this->mId
00843 : $dbw->nextSequenceValue( 'revision_rev_id_seq' );
00844 $dbw->insert( 'revision',
00845 array(
00846 'rev_id' => $rev_id,
00847 'rev_page' => $this->mPage,
00848 'rev_text_id' => $this->mTextId,
00849 'rev_comment' => $this->mComment,
00850 'rev_minor_edit' => $this->mMinorEdit ? 1 : 0,
00851 'rev_user' => $this->mUser,
00852 'rev_user_text' => $this->mUserText,
00853 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp ),
00854 'rev_deleted' => $this->mDeleted,
00855 'rev_len' => $this->mSize,
00856 'rev_parent_id' => is_null($this->mParentId) ?
00857 $this->getPreviousRevisionId( $dbw ) : $this->mParentId
00858 ), __METHOD__
00859 );
00860
00861 $this->mId = !is_null( $rev_id ) ? $rev_id : $dbw->insertId();
00862
00863 wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
00864
00865 wfProfileOut( __METHOD__ );
00866 return $this->mId;
00867 }
00868
00875 protected function loadText() {
00876 wfProfileIn( __METHOD__ );
00877
00878
00879 global $wgRevisionCacheExpiry, $wgMemc;
00880 $textId = $this->getTextId();
00881 $key = wfMemcKey( 'revisiontext', 'textid', $textId );
00882 if( $wgRevisionCacheExpiry ) {
00883 $text = $wgMemc->get( $key );
00884 if( is_string( $text ) ) {
00885 wfDebug( __METHOD__ . ": got id $textId from cache\n" );
00886 wfProfileOut( __METHOD__ );
00887 return $text;
00888 }
00889 }
00890
00891
00892 if ( isset( $this->mTextRow ) ) {
00893 $row = $this->mTextRow;
00894 $this->mTextRow = null;
00895 } else {
00896 $row = null;
00897 }
00898
00899 if( !$row ) {
00900
00901 $dbr = wfGetDB( DB_SLAVE );
00902 $row = $dbr->selectRow( 'text',
00903 array( 'old_text', 'old_flags' ),
00904 array( 'old_id' => $this->getTextId() ),
00905 __METHOD__ );
00906 }
00907
00908 if( !$row && wfGetLB()->getServerCount() > 1 ) {
00909
00910 $dbw = wfGetDB( DB_MASTER );
00911 $row = $dbw->selectRow( 'text',
00912 array( 'old_text', 'old_flags' ),
00913 array( 'old_id' => $this->getTextId() ),
00914 __METHOD__ );
00915 }
00916
00917 $text = self::getRevisionText( $row );
00918
00919 # No negative caching -- negative hits on text rows may be due to corrupted slave servers
00920 if( $wgRevisionCacheExpiry && $text !== false ) {
00921 $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
00922 }
00923
00924 wfProfileOut( __METHOD__ );
00925
00926 return $text;
00927 }
00928
00943 public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
00944 wfProfileIn( __METHOD__ );
00945
00946 $current = $dbw->selectRow(
00947 array( 'page', 'revision' ),
00948 array( 'page_latest', 'rev_text_id', 'rev_len' ),
00949 array(
00950 'page_id' => $pageId,
00951 'page_latest=rev_id',
00952 ),
00953 __METHOD__ );
00954
00955 if( $current ) {
00956 $revision = new Revision( array(
00957 'page' => $pageId,
00958 'comment' => $summary,
00959 'minor_edit' => $minor,
00960 'text_id' => $current->rev_text_id,
00961 'parent_id' => $current->page_latest,
00962 'len' => $current->rev_len
00963 ) );
00964 } else {
00965 $revision = null;
00966 }
00967
00968 wfProfileOut( __METHOD__ );
00969 return $revision;
00970 }
00971
00981 public function userCan( $field ) {
00982 return self::userCanBitfield( $this->mDeleted, $field );
00983 }
00984
00996 public static function userCanBitfield( $bitfield, $field ) {
00997 if( $bitfield & $field ) {
00998 global $wgUser;
00999 $permission = '';
01000 if ( $bitfield & self::DELETED_RESTRICTED ) {
01001 $permission = 'suppressrevision';
01002 } elseif ( $field & self::DELETED_TEXT ) {
01003 $permission = 'deletedtext';
01004 } else {
01005 $permission = 'deletedhistory';
01006 }
01007 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
01008 return $wgUser->isAllowed( $permission );
01009 } else {
01010 return true;
01011 }
01012 }
01013
01021 static function getTimestampFromId( $title, $id ) {
01022 $dbr = wfGetDB( DB_SLAVE );
01023
01024 if ( $id == '' ) {
01025 $id = 0;
01026 }
01027 $conds = array( 'rev_id' => $id );
01028 $conds['rev_page'] = $title->getArticleId();
01029 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__ );
01030 if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
01031 # Not in slave, try master
01032 $dbw = wfGetDB( DB_MASTER );
01033 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__ );
01034 }
01035 return wfTimestamp( TS_MW, $timestamp );
01036 }
01037
01045 static function countByPageId( $db, $id ) {
01046 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
01047 array( 'rev_page' => $id ), __METHOD__ );
01048 if( $row ) {
01049 return $row->revCount;
01050 }
01051 return 0;
01052 }
01053
01061 static function countByTitle( $db, $title ) {
01062 $id = $title->getArticleId();
01063 if( $id ) {
01064 return Revision::countByPageId( $db, $id );
01065 }
01066 return 0;
01067 }
01068 }
01069
01073 define( 'MW_REV_DELETED_TEXT', Revision::DELETED_TEXT );
01074 define( 'MW_REV_DELETED_COMMENT', Revision::DELETED_COMMENT );
01075 define( 'MW_REV_DELETED_USER', Revision::DELETED_USER );
01076 define( 'MW_REV_DELETED_RESTRICTED', Revision::DELETED_RESTRICTED );