7 const DELETED_TEXT
= 1;
8 const DELETED_COMMENT
= 2;
9 const DELETED_USER
= 4;
10 const DELETED_RESTRICTED
= 8;
12 const SUPPRESSED_USER
= 12;
13 // Audience options for Revision::getText()
15 const FOR_THIS_USER
= 2;
19 * Load a page revision from a given revision ID number.
20 * Returns null if no such revision can be found.
23 * @return Revision or null
25 public static function newFromId( $id ) {
26 return Revision
::newFromConds(
27 array( 'page_id=rev_page',
28 'rev_id' => intval( $id ) ) );
32 * Load either the current, or a specified, revision
33 * that's attached to a given title. If not attached
34 * to that title, will return null.
37 * @param $id Integer (optional)
38 * @return Revision or null
40 public static function newFromTitle( $title, $id = 0 ) {
42 'page_namespace' => $title->getNamespace(),
43 'page_title' => $title->getDBkey()
46 // Use the specified ID
47 $conds['rev_id'] = $id;
48 } elseif ( wfGetLB()->getServerCount() > 1 ) {
49 // Get the latest revision ID from the master
50 $dbw = wfGetDB( DB_MASTER
);
51 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
52 if ( $latest === false ) {
53 return null; // page does not exist
55 $conds['rev_id'] = $latest;
57 // Use a join to get the latest revision
58 $conds[] = 'rev_id=page_latest';
60 $conds[] = 'page_id=rev_page';
61 return Revision
::newFromConds( $conds );
65 * Load either the current, or a specified, revision
66 * that's attached to a given page ID.
67 * Returns null if no such revision can be found.
69 * @param $revId Integer
70 * @param $pageId Integer (optional)
71 * @return Revision or null
73 public static function newFromPageId( $pageId, $revId = 0 ) {
74 $conds = array( 'page_id' => $pageId );
76 $conds['rev_id'] = $revId;
77 } elseif ( wfGetLB()->getServerCount() > 1 ) {
78 // Get the latest revision ID from the master
79 $dbw = wfGetDB( DB_MASTER
);
80 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
81 if ( $latest === false ) {
82 return null; // page does not exist
84 $conds['rev_id'] = $latest;
86 $conds[] = 'rev_id = page_latest';
88 $conds[] = 'page_id=rev_page';
89 return Revision
::newFromConds( $conds );
93 * Make a fake revision object from an archive table row. This is queried
94 * for permissions or even inserted (as in Special:Undelete)
95 * @todo FIXME: Should be a subclass for RevisionDelete. [TS]
98 * @param $overrides array
102 public static function newFromArchiveRow( $row, $overrides = array() ) {
103 $attribs = $overrides +
array(
104 'page' => isset( $row->ar_page_id
) ?
$row->ar_page_id
: null,
105 'id' => isset( $row->ar_rev_id
) ?
$row->ar_rev_id
: null,
106 'comment' => $row->ar_comment
,
107 'user' => $row->ar_user
,
108 'user_text' => $row->ar_user_text
,
109 'timestamp' => $row->ar_timestamp
,
110 'minor_edit' => $row->ar_minor_edit
,
111 'text_id' => isset( $row->ar_text_id
) ?
$row->ar_text_id
: null,
112 'deleted' => $row->ar_deleted
,
113 'len' => $row->ar_len
115 if ( isset( $row->ar_text
) && !$row->ar_text_id
) {
116 // Pre-1.5 ar_text row
117 $attribs['text'] = self
::getRevisionText( $row, 'ar_' );
118 if ( $attribs['text'] === false ) {
119 throw new MWException( 'Unable to load text from archive row (possibly bug 22624)' );
122 return new self( $attribs );
131 public static function newFromRow( $row ) {
132 return new self( $row );
136 * Load a page revision from a given revision ID number.
137 * Returns null if no such revision can be found.
139 * @param $db DatabaseBase
141 * @return Revision or null
143 public static function loadFromId( $db, $id ) {
144 return Revision
::loadFromConds( $db,
145 array( 'page_id=rev_page',
146 'rev_id' => intval( $id ) ) );
150 * Load either the current, or a specified, revision
151 * that's attached to a given page. If not attached
152 * to that page, will return null.
154 * @param $db DatabaseBase
155 * @param $pageid Integer
157 * @return Revision or null
159 public static function loadFromPageId( $db, $pageid, $id = 0 ) {
160 $conds = array( 'page_id=rev_page','rev_page' => intval( $pageid ), 'page_id'=>intval( $pageid ) );
162 $conds['rev_id'] = intval( $id );
164 $conds[] = 'rev_id=page_latest';
166 return Revision
::loadFromConds( $db, $conds );
170 * Load either the current, or a specified, revision
171 * that's attached to a given page. If not attached
172 * to that page, will return null.
174 * @param $db DatabaseBase
175 * @param $title Title
177 * @return Revision or null
179 public static function loadFromTitle( $db, $title, $id = 0 ) {
181 $matchId = intval( $id );
183 $matchId = 'page_latest';
185 return Revision
::loadFromConds(
187 array( "rev_id=$matchId",
189 'page_namespace' => $title->getNamespace(),
190 'page_title' => $title->getDBkey() ) );
194 * Load the revision for the given title with the given timestamp.
195 * WARNING: Timestamps may in some circumstances not be unique,
196 * so this isn't the best key to use.
198 * @param $db DatabaseBase
199 * @param $title Title
200 * @param $timestamp String
201 * @return Revision or null
203 public static function loadFromTimestamp( $db, $title, $timestamp ) {
204 return Revision
::loadFromConds(
206 array( 'rev_timestamp' => $db->timestamp( $timestamp ),
208 'page_namespace' => $title->getNamespace(),
209 'page_title' => $title->getDBkey() ) );
213 * Given a set of conditions, fetch a revision.
215 * @param $conditions Array
216 * @return Revision or null
218 public static function newFromConds( $conditions ) {
219 $db = wfGetDB( DB_SLAVE
);
220 $row = Revision
::loadFromConds( $db, $conditions );
221 if( is_null( $row ) && wfGetLB()->getServerCount() > 1 ) {
222 $dbw = wfGetDB( DB_MASTER
);
223 $row = Revision
::loadFromConds( $dbw, $conditions );
229 * Given a set of conditions, fetch a revision from
230 * the given database connection.
232 * @param $db DatabaseBase
233 * @param $conditions Array
234 * @return Revision or null
236 private static function loadFromConds( $db, $conditions ) {
237 $res = Revision
::fetchFromConds( $db, $conditions );
239 $row = $res->fetchObject();
242 $ret = new Revision( $row );
251 * Return a wrapper for a series of database rows to
252 * fetch all of a given page's revisions in turn.
253 * Each row can be fed to the constructor to get objects.
255 * @param $title Title
256 * @return ResultWrapper
258 public static function fetchRevision( $title ) {
259 return Revision
::fetchFromConds(
261 array( 'rev_id=page_latest',
262 'page_namespace' => $title->getNamespace(),
263 'page_title' => $title->getDBkey(),
264 'page_id=rev_page' ) );
268 * Given a set of conditions, return a ResultWrapper
269 * which will return matching database rows with the
270 * fields necessary to build Revision objects.
272 * @param $db DatabaseBase
273 * @param $conditions Array
274 * @return ResultWrapper
276 private static function fetchFromConds( $db, $conditions ) {
277 $fields = self
::selectFields();
278 $fields[] = 'page_namespace';
279 $fields[] = 'page_title';
280 $fields[] = 'page_latest';
282 array( 'page', 'revision' ),
286 array( 'LIMIT' => 1 ) );
290 * Return the list of revision fields that should be selected to create
293 public static function selectFields() {
310 * Return the list of text fields that should be selected to read the
313 static function selectTextFields() {
321 * Return the list of page fields that should be selected from page table
323 static function selectPageFields() {
334 * @param $row Mixed: either a database row or an array
337 function __construct( $row ) {
338 if( is_object( $row ) ) {
339 $this->mId
= intval( $row->rev_id
);
340 $this->mPage
= intval( $row->rev_page
);
341 $this->mTextId
= intval( $row->rev_text_id
);
342 $this->mComment
= $row->rev_comment
;
343 $this->mUserText
= $row->rev_user_text
;
344 $this->mUser
= intval( $row->rev_user
);
345 $this->mMinorEdit
= intval( $row->rev_minor_edit
);
346 $this->mTimestamp
= $row->rev_timestamp
;
347 $this->mDeleted
= intval( $row->rev_deleted
);
349 if( !isset( $row->rev_parent_id
) ) {
350 $this->mParentId
= is_null($row->rev_parent_id
) ?
null : 0;
352 $this->mParentId
= intval( $row->rev_parent_id
);
355 if( !isset( $row->rev_len
) ||
is_null( $row->rev_len
) ) {
358 $this->mSize
= intval( $row->rev_len
);
361 if( isset( $row->page_latest
) ) {
362 $this->mCurrent
= ( $row->rev_id
== $row->page_latest
);
363 $this->mTitle
= Title
::newFromRow( $row );
365 $this->mCurrent
= false;
366 $this->mTitle
= null;
369 // Lazy extraction...
371 if( isset( $row->old_text
) ) {
372 $this->mTextRow
= $row;
374 // 'text' table row entry will be lazy-loaded
375 $this->mTextRow
= null;
377 } elseif( is_array( $row ) ) {
378 // Build a new revision to be saved...
381 $this->mId
= isset( $row['id'] ) ?
intval( $row['id'] ) : null;
382 $this->mPage
= isset( $row['page'] ) ?
intval( $row['page'] ) : null;
383 $this->mTextId
= isset( $row['text_id'] ) ?
intval( $row['text_id'] ) : null;
384 $this->mUserText
= isset( $row['user_text'] ) ?
strval( $row['user_text'] ) : $wgUser->getName();
385 $this->mUser
= isset( $row['user'] ) ?
intval( $row['user'] ) : $wgUser->getId();
386 $this->mMinorEdit
= isset( $row['minor_edit'] ) ?
intval( $row['minor_edit'] ) : 0;
387 $this->mTimestamp
= isset( $row['timestamp'] ) ?
strval( $row['timestamp'] ) : wfTimestamp( TS_MW
);
388 $this->mDeleted
= isset( $row['deleted'] ) ?
intval( $row['deleted'] ) : 0;
389 $this->mSize
= isset( $row['len'] ) ?
intval( $row['len'] ) : null;
390 $this->mParentId
= isset( $row['parent_id'] ) ?
intval( $row['parent_id'] ) : null;
392 // Enforce spacing trimming on supplied text
393 $this->mComment
= isset( $row['comment'] ) ?
trim( strval( $row['comment'] ) ) : null;
394 $this->mText
= isset( $row['text'] ) ?
rtrim( strval( $row['text'] ) ) : null;
395 $this->mTextRow
= null;
397 $this->mTitle
= null; # Load on demand if needed
398 $this->mCurrent
= false;
399 # If we still have no len_size, see it we have the text to figure it out
400 if ( !$this->mSize
) {
401 $this->mSize
= is_null( $this->mText
) ?
null : strlen( $this->mText
);
404 throw new MWException( 'Revision constructor passed invalid row format.' );
406 $this->mUnpatrolled
= null;
414 public function getId() {
423 public function getTextId() {
424 return $this->mTextId
;
428 * Get parent revision ID (the original previous page revision)
432 public function getParentId() {
433 return $this->mParentId
;
437 * Returns the length of the text in this revision, or null if unknown.
441 public function getSize() {
446 * Returns the title of the page associated with this entry.
450 public function getTitle() {
451 if( isset( $this->mTitle
) ) {
452 return $this->mTitle
;
454 $dbr = wfGetDB( DB_SLAVE
);
455 $row = $dbr->selectRow(
456 array( 'page', 'revision' ),
457 array( 'page_namespace', 'page_title' ),
458 array( 'page_id=rev_page',
459 'rev_id' => $this->mId
),
460 'Revision::getTitle' );
462 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
464 return $this->mTitle
;
468 * Set the title of the revision
470 * @param $title Title
472 public function setTitle( $title ) {
473 $this->mTitle
= $title;
481 public function getPage() {
486 * Fetch revision's user id if it's available to the specified audience.
487 * If the specified audience does not have access to it, zero will be
490 * @param $audience Integer: 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 ID regardless of permissions
494 * @param $user User object to check for, only if FOR_THIS_USER is passed
495 * to the $audience parameter
498 public function getUser( $audience = self
::FOR_PUBLIC
, User
$user = null ) {
499 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
501 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
, $user ) ) {
509 * Fetch revision's user id without regard for the current user's permissions
513 public function getRawUser() {
518 * Fetch revision's username if it's available to the specified audience.
519 * If the specified audience does not have access to the username, an
520 * empty string will be returned.
522 * @param $audience Integer: one of:
523 * Revision::FOR_PUBLIC to be displayed to all users
524 * Revision::FOR_THIS_USER to be displayed to $wgUser
525 * Revision::RAW get the text regardless of permissions
526 * @param $user User object to check for, only if FOR_THIS_USER is passed
527 * to the $audience parameter
530 public function getUserText( $audience = self
::FOR_PUBLIC
, User
$user = null ) {
531 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
533 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
, $user ) ) {
536 return $this->mUserText
;
541 * Fetch revision's username without regard for view restrictions
545 public function getRawUserText() {
546 return $this->mUserText
;
550 * Fetch revision comment if it's available to the specified audience.
551 * If the specified audience does not have access to the comment, an
552 * empty string will be returned.
554 * @param $audience Integer: one of:
555 * Revision::FOR_PUBLIC to be displayed to all users
556 * Revision::FOR_THIS_USER to be displayed to $wgUser
557 * Revision::RAW get the text regardless of permissions
558 * @param $user User object to check for, only if FOR_THIS_USER is passed
559 * to the $audience parameter
562 function getComment( $audience = self
::FOR_PUBLIC
, User
$user = null ) {
563 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_COMMENT
) ) {
565 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_COMMENT
, $user ) ) {
568 return $this->mComment
;
573 * Fetch revision comment without regard for the current user's permissions
577 public function getRawComment() {
578 return $this->mComment
;
584 public function isMinor() {
585 return (bool)$this->mMinorEdit
;
589 * @return Integer rcid of the unpatrolled row, zero if there isn't one
591 public function isUnpatrolled() {
592 if( $this->mUnpatrolled
!== null ) {
593 return $this->mUnpatrolled
;
595 $dbr = wfGetDB( DB_SLAVE
);
596 $this->mUnpatrolled
= $dbr->selectField( 'recentchanges',
598 array( // Add redundant user,timestamp condition so we can use the existing index
599 'rc_user_text' => $this->getRawUserText(),
600 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
601 'rc_this_oldid' => $this->getId(),
606 return (int)$this->mUnpatrolled
;
610 * @param $field int one of DELETED_* bitfield constants
614 public function isDeleted( $field ) {
615 return ( $this->mDeleted
& $field ) == $field;
619 * Get the deletion bitfield of the revision
623 public function getVisibility() {
624 return (int)$this->mDeleted
;
628 * Fetch revision text if it's available to the specified audience.
629 * If the specified audience does not have the ability to view this
630 * revision, an empty string will be returned.
632 * @param $audience Integer: one of:
633 * Revision::FOR_PUBLIC to be displayed to all users
634 * Revision::FOR_THIS_USER to be displayed to $wgUser
635 * Revision::RAW get the text regardless of permissions
636 * @param $user User object to check for, only if FOR_THIS_USER is passed
637 * to the $audience parameter
640 public function getText( $audience = self
::FOR_PUBLIC
, User
$user = null ) {
641 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_TEXT
) ) {
643 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_TEXT
, $user ) ) {
646 return $this->getRawText();
651 * Alias for getText(Revision::FOR_THIS_USER)
653 * @deprecated since 1.17
656 public function revText() {
657 wfDeprecated( __METHOD__
);
658 return $this->getText( self
::FOR_THIS_USER
);
662 * Fetch revision text without regard for view restrictions
666 public function getRawText() {
667 if( is_null( $this->mText
) ) {
668 // Revision text is immutable. Load on demand:
669 $this->mText
= $this->loadText();
677 public function getTimestamp() {
678 return wfTimestamp( TS_MW
, $this->mTimestamp
);
684 public function isCurrent() {
685 return $this->mCurrent
;
689 * Get previous revision for this title
691 * @return Revision or null
693 public function getPrevious() {
694 if( $this->getTitle() ) {
695 $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
697 return Revision
::newFromTitle( $this->getTitle(), $prev );
704 * Get next revision for this title
706 * @return Revision or null
708 public function getNext() {
709 if( $this->getTitle() ) {
710 $next = $this->getTitle()->getNextRevisionID( $this->getId() );
712 return Revision
::newFromTitle( $this->getTitle(), $next );
719 * Get previous revision Id for this page_id
720 * This is used to populate rev_parent_id on save
722 * @param $db DatabaseBase
725 private function getPreviousRevisionId( $db ) {
726 if( is_null( $this->mPage
) ) {
729 # Use page_latest if ID is not given
731 $prevId = $db->selectField( 'page', 'page_latest',
732 array( 'page_id' => $this->mPage
),
735 $prevId = $db->selectField( 'revision', 'rev_id',
736 array( 'rev_page' => $this->mPage
, 'rev_id < ' . $this->mId
),
738 array( 'ORDER BY' => 'rev_id DESC' ) );
740 return intval( $prevId );
744 * Get revision text associated with an old or archive row
745 * $row is usually an object from wfFetchRow(), both the flags and the text
746 * field must be included
748 * @param $row Object: the text data
749 * @param $prefix String: table prefix (default 'old_')
750 * @return String: text the text requested or false on failure
752 public static function getRevisionText( $row, $prefix = 'old_' ) {
753 wfProfileIn( __METHOD__
);
756 $textField = $prefix . 'text';
757 $flagsField = $prefix . 'flags';
759 if( isset( $row->$flagsField ) ) {
760 $flags = explode( ',', $row->$flagsField );
765 if( isset( $row->$textField ) ) {
766 $text = $row->$textField;
768 wfProfileOut( __METHOD__
);
772 # Use external methods for external objects, text in table is URL-only then
773 if ( in_array( 'external', $flags ) ) {
775 $parts = explode( '://', $url, 2 );
776 if( count( $parts ) == 1 ||
$parts[1] == '' ) {
777 wfProfileOut( __METHOD__
);
780 $text = ExternalStore
::fetchFromURL( $url );
783 // If the text was fetched without an error, convert it
784 if ( $text !== false ) {
785 if( in_array( 'gzip', $flags ) ) {
786 # Deal with optional compression of archived pages.
787 # This can be done periodically via maintenance/compressOld.php, and
788 # as pages are saved if $wgCompressRevisions is set.
789 $text = gzinflate( $text );
792 if( in_array( 'object', $flags ) ) {
793 # Generic compressed storage
794 $obj = unserialize( $text );
795 if ( !is_object( $obj ) ) {
797 wfProfileOut( __METHOD__
);
800 $text = $obj->getText();
803 global $wgLegacyEncoding;
804 if( $text !== false && $wgLegacyEncoding
805 && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) )
807 # Old revisions kept around in a legacy encoding?
808 # Upconvert on demand.
809 # ("utf8" checked for compatibility with some broken
810 # conversion scripts 2008-12-30)
812 $text = $wgContLang->iconv( $wgLegacyEncoding, 'UTF-8', $text );
815 wfProfileOut( __METHOD__
);
820 * If $wgCompressRevisions is enabled, we will compress data.
821 * The input string is modified in place.
822 * Return value is the flags field: contains 'gzip' if the
823 * data is compressed, and 'utf-8' if we're saving in UTF-8
826 * @param $text Mixed: reference to a text
829 public static function compressRevisionText( &$text ) {
830 global $wgCompressRevisions;
833 # Revisions not marked this way will be converted
834 # on load if $wgLegacyCharset is set in the future.
837 if( $wgCompressRevisions ) {
838 if( function_exists( 'gzdeflate' ) ) {
839 $text = gzdeflate( $text );
842 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
845 return implode( ',', $flags );
849 * Insert a new revision into the database, returning the new revision ID
850 * number on success and dies horribly on failure.
852 * @param $dbw DatabaseBase: (master connection)
855 public function insertOn( $dbw ) {
856 global $wgDefaultExternalStore;
858 wfProfileIn( __METHOD__
);
860 $data = $this->mText
;
861 $flags = Revision
::compressRevisionText( $data );
863 # Write to external storage if required
864 if( $wgDefaultExternalStore ) {
865 // Store and get the URL
866 $data = ExternalStore
::insertToDefault( $data );
868 throw new MWException( "Unable to store text to external storage" );
873 $flags .= 'external';
876 # Record the text (or external storage URL) to the text table
877 if( !isset( $this->mTextId
) ) {
878 $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
879 $dbw->insert( 'text',
883 'old_flags' => $flags,
886 $this->mTextId
= $dbw->insertId();
889 if ( $this->mComment
=== null ) $this->mComment
= "";
891 # Record the edit in revisions
892 $rev_id = isset( $this->mId
)
894 : $dbw->nextSequenceValue( 'revision_rev_id_seq' );
895 $dbw->insert( 'revision',
898 'rev_page' => $this->mPage
,
899 'rev_text_id' => $this->mTextId
,
900 'rev_comment' => $this->mComment
,
901 'rev_minor_edit' => $this->mMinorEdit ?
1 : 0,
902 'rev_user' => $this->mUser
,
903 'rev_user_text' => $this->mUserText
,
904 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp
),
905 'rev_deleted' => $this->mDeleted
,
906 'rev_len' => $this->mSize
,
907 'rev_parent_id' => is_null($this->mParentId
) ?
908 $this->getPreviousRevisionId( $dbw ) : $this->mParentId
912 $this->mId
= !is_null( $rev_id ) ?
$rev_id : $dbw->insertId();
914 wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
916 wfProfileOut( __METHOD__
);
921 * Lazy-load the revision's text.
922 * Currently hardcoded to the 'text' table storage engine.
926 protected function loadText() {
927 wfProfileIn( __METHOD__
);
929 // Caching may be beneficial for massive use of external storage
930 global $wgRevisionCacheExpiry, $wgMemc;
931 $textId = $this->getTextId();
932 $key = wfMemcKey( 'revisiontext', 'textid', $textId );
933 if( $wgRevisionCacheExpiry ) {
934 $text = $wgMemc->get( $key );
935 if( is_string( $text ) ) {
936 wfDebug( __METHOD__
. ": got id $textId from cache\n" );
937 wfProfileOut( __METHOD__
);
942 // If we kept data for lazy extraction, use it now...
943 if ( isset( $this->mTextRow
) ) {
944 $row = $this->mTextRow
;
945 $this->mTextRow
= null;
951 // Text data is immutable; check slaves first.
952 $dbr = wfGetDB( DB_SLAVE
);
953 $row = $dbr->selectRow( 'text',
954 array( 'old_text', 'old_flags' ),
955 array( 'old_id' => $this->getTextId() ),
959 if( !$row && wfGetLB()->getServerCount() > 1 ) {
960 // Possible slave lag!
961 $dbw = wfGetDB( DB_MASTER
);
962 $row = $dbw->selectRow( 'text',
963 array( 'old_text', 'old_flags' ),
964 array( 'old_id' => $this->getTextId() ),
968 $text = self
::getRevisionText( $row );
970 # No negative caching -- negative hits on text rows may be due to corrupted slave servers
971 if( $wgRevisionCacheExpiry && $text !== false ) {
972 $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
975 wfProfileOut( __METHOD__
);
981 * Create a new null-revision for insertion into a page's
982 * history. This will not re-save the text, but simply refer
983 * to the text from the previous version.
985 * Such revisions can for instance identify page rename
986 * operations and other such meta-modifications.
988 * @param $dbw DatabaseBase
989 * @param $pageId Integer: ID number of the page to read from
990 * @param $summary String: revision's summary
991 * @param $minor Boolean: whether the revision should be considered as minor
992 * @return Revision|null on error
994 public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
995 wfProfileIn( __METHOD__
);
997 $current = $dbw->selectRow(
998 array( 'page', 'revision' ),
999 array( 'page_latest', 'rev_text_id', 'rev_len' ),
1001 'page_id' => $pageId,
1002 'page_latest=rev_id',
1007 $revision = new Revision( array(
1009 'comment' => $summary,
1010 'minor_edit' => $minor,
1011 'text_id' => $current->rev_text_id
,
1012 'parent_id' => $current->page_latest
,
1013 'len' => $current->rev_len
1019 wfProfileOut( __METHOD__
);
1024 * Determine if the current user is allowed to view a particular
1025 * field of this revision, if it's marked as deleted.
1027 * @param $field Integer:one of self::DELETED_TEXT,
1028 * self::DELETED_COMMENT,
1029 * self::DELETED_USER
1030 * @param $user User object to check, or null to use $wgUser
1033 public function userCan( $field, User
$user = null ) {
1034 return self
::userCanBitfield( $this->mDeleted
, $field, $user );
1038 * Determine if the current user is allowed to view a particular
1039 * field of this revision, if it's marked as deleted. This is used
1040 * by various classes to avoid duplication.
1042 * @param $bitfield Integer: current field
1043 * @param $field Integer: one of self::DELETED_TEXT = File::DELETED_FILE,
1044 * self::DELETED_COMMENT = File::DELETED_COMMENT,
1045 * self::DELETED_USER = File::DELETED_USER
1046 * @param $user User object to check, or null to use $wgUser
1049 public static function userCanBitfield( $bitfield, $field, User
$user = null ) {
1050 if( $bitfield & $field ) { // aspect is deleted
1051 if ( $bitfield & self
::DELETED_RESTRICTED
) {
1052 $permission = 'suppressrevision';
1053 } elseif ( $field & self
::DELETED_TEXT
) {
1054 $permission = 'deletedtext';
1056 $permission = 'deletedhistory';
1058 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
1059 if ( $user === null ) {
1063 return $user->isAllowed( $permission );
1070 * Get rev_timestamp from rev_id, without loading the rest of the row
1072 * @param $title Title
1073 * @param $id Integer
1076 static function getTimestampFromId( $title, $id ) {
1077 $dbr = wfGetDB( DB_SLAVE
);
1078 // Casting fix for DB2
1082 $conds = array( 'rev_id' => $id );
1083 $conds['rev_page'] = $title->getArticleId();
1084 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1085 if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
1086 # Not in slave, try master
1087 $dbw = wfGetDB( DB_MASTER
);
1088 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1090 return wfTimestamp( TS_MW
, $timestamp );
1094 * Get count of revisions per page...not very efficient
1096 * @param $db DatabaseBase
1097 * @param $id Integer: page id
1100 static function countByPageId( $db, $id ) {
1101 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
1102 array( 'rev_page' => $id ), __METHOD__
);
1104 return $row->revCount
;
1110 * Get count of revisions per page...not very efficient
1112 * @param $db DatabaseBase
1113 * @param $title Title
1116 static function countByTitle( $db, $title ) {
1117 $id = $title->getArticleId();
1119 return Revision
::countByPageId( $db, $id );