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
401 $this->mSize
= is_null( $this->mText
) ?
null : strlen( $this->mText
);
403 throw new MWException( 'Revision constructor passed invalid row format.' );
405 $this->mUnpatrolled
= null;
413 public function getId() {
422 public function getTextId() {
423 return $this->mTextId
;
427 * Get parent revision ID (the original previous page revision)
431 public function getParentId() {
432 return $this->mParentId
;
436 * Returns the length of the text in this revision, or null if unknown.
440 public function getSize() {
445 * Returns the title of the page associated with this entry.
449 public function getTitle() {
450 if( isset( $this->mTitle
) ) {
451 return $this->mTitle
;
453 $dbr = wfGetDB( DB_SLAVE
);
454 $row = $dbr->selectRow(
455 array( 'page', 'revision' ),
456 array( 'page_namespace', 'page_title' ),
457 array( 'page_id=rev_page',
458 'rev_id' => $this->mId
),
459 'Revision::getTitle' );
461 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
463 return $this->mTitle
;
467 * Set the title of the revision
469 * @param $title Title
471 public function setTitle( $title ) {
472 $this->mTitle
= $title;
480 public function getPage() {
485 * Fetch revision's user id if it's available to the specified audience.
486 * If the specified audience does not have access to it, zero will be
489 * @param $audience Integer: one of:
490 * Revision::FOR_PUBLIC to be displayed to all users
491 * Revision::FOR_THIS_USER to be displayed to $wgUser
492 * Revision::RAW get the ID regardless of permissions
497 public function getUser( $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
) ) {
508 * Fetch revision's user id without regard for the current user's permissions
512 public function getRawUser() {
517 * Fetch revision's username if it's available to the specified audience.
518 * If the specified audience does not have access to the username, an
519 * empty string will be returned.
521 * @param $audience Integer: one of:
522 * Revision::FOR_PUBLIC to be displayed to all users
523 * Revision::FOR_THIS_USER to be displayed to $wgUser
524 * Revision::RAW get the text regardless of permissions
528 public function getUserText( $audience = self
::FOR_PUBLIC
) {
529 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
531 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
534 return $this->mUserText
;
539 * Fetch revision's username without regard for view restrictions
543 public function getRawUserText() {
544 return $this->mUserText
;
548 * Fetch revision comment if it's available to the specified audience.
549 * If the specified audience does not have access to the comment, an
550 * empty string will be returned.
552 * @param $audience Integer: one of:
553 * Revision::FOR_PUBLIC to be displayed to all users
554 * Revision::FOR_THIS_USER to be displayed to $wgUser
555 * Revision::RAW get the text regardless of permissions
559 function getComment( $audience = self
::FOR_PUBLIC
) {
560 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_COMMENT
) ) {
562 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_COMMENT
) ) {
565 return $this->mComment
;
570 * Fetch revision comment without regard for the current user's permissions
574 public function getRawComment() {
575 return $this->mComment
;
581 public function isMinor() {
582 return (bool)$this->mMinorEdit
;
586 * @return Integer rcid of the unpatrolled row, zero if there isn't one
588 public function isUnpatrolled() {
589 if( $this->mUnpatrolled
!== null ) {
590 return $this->mUnpatrolled
;
592 $dbr = wfGetDB( DB_SLAVE
);
593 $this->mUnpatrolled
= $dbr->selectField( 'recentchanges',
595 array( // Add redundant user,timestamp condition so we can use the existing index
596 'rc_user_text' => $this->getRawUserText(),
597 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
598 'rc_this_oldid' => $this->getId(),
603 return (int)$this->mUnpatrolled
;
607 * @param $field int one of DELETED_* bitfield constants
611 public function isDeleted( $field ) {
612 return ( $this->mDeleted
& $field ) == $field;
616 * Get the deletion bitfield of the revision
620 public function getVisibility() {
621 return (int)$this->mDeleted
;
625 * Fetch revision text if it's available to the specified audience.
626 * If the specified audience does not have the ability to view this
627 * revision, an empty string will be returned.
629 * @param $audience Integer: one of:
630 * Revision::FOR_PUBLIC to be displayed to all users
631 * Revision::FOR_THIS_USER to be displayed to $wgUser
632 * Revision::RAW get the text regardless of permissions
636 public function getText( $audience = self
::FOR_PUBLIC
) {
637 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_TEXT
) ) {
639 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_TEXT
) ) {
642 return $this->getRawText();
647 * Alias for getText(Revision::FOR_THIS_USER)
649 * @deprecated since 1.17
652 public function revText() {
653 wfDeprecated( __METHOD__
);
654 return $this->getText( self
::FOR_THIS_USER
);
658 * Fetch revision text without regard for view restrictions
662 public function getRawText() {
663 if( is_null( $this->mText
) ) {
664 // Revision text is immutable. Load on demand:
665 $this->mText
= $this->loadText();
673 public function getTimestamp() {
674 return wfTimestamp( TS_MW
, $this->mTimestamp
);
680 public function isCurrent() {
681 return $this->mCurrent
;
685 * Get previous revision for this title
687 * @return Revision or null
689 public function getPrevious() {
690 if( $this->getTitle() ) {
691 $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
693 return Revision
::newFromTitle( $this->getTitle(), $prev );
700 * Get next revision for this title
702 * @return Revision or null
704 public function getNext() {
705 if( $this->getTitle() ) {
706 $next = $this->getTitle()->getNextRevisionID( $this->getId() );
708 return Revision
::newFromTitle( $this->getTitle(), $next );
715 * Get previous revision Id for this page_id
716 * This is used to populate rev_parent_id on save
718 * @param $db DatabaseBase
721 private function getPreviousRevisionId( $db ) {
722 if( is_null( $this->mPage
) ) {
725 # Use page_latest if ID is not given
727 $prevId = $db->selectField( 'page', 'page_latest',
728 array( 'page_id' => $this->mPage
),
731 $prevId = $db->selectField( 'revision', 'rev_id',
732 array( 'rev_page' => $this->mPage
, 'rev_id < ' . $this->mId
),
734 array( 'ORDER BY' => 'rev_id DESC' ) );
736 return intval( $prevId );
740 * Get revision text associated with an old or archive row
741 * $row is usually an object from wfFetchRow(), both the flags and the text
742 * field must be included
744 * @param $row Object: the text data
745 * @param $prefix String: table prefix (default 'old_')
746 * @return String: text the text requested or false on failure
748 public static function getRevisionText( $row, $prefix = 'old_' ) {
749 wfProfileIn( __METHOD__
);
752 $textField = $prefix . 'text';
753 $flagsField = $prefix . 'flags';
755 if( isset( $row->$flagsField ) ) {
756 $flags = explode( ',', $row->$flagsField );
761 if( isset( $row->$textField ) ) {
762 $text = $row->$textField;
764 wfProfileOut( __METHOD__
);
768 # Use external methods for external objects, text in table is URL-only then
769 if ( in_array( 'external', $flags ) ) {
771 $parts = explode( '://', $url, 2 );
772 if( count( $parts ) == 1 ||
$parts[1] == '' ) {
773 wfProfileOut( __METHOD__
);
776 $text = ExternalStore
::fetchFromURL( $url );
779 // If the text was fetched without an error, convert it
780 if ( $text !== false ) {
781 if( in_array( 'gzip', $flags ) ) {
782 # Deal with optional compression of archived pages.
783 # This can be done periodically via maintenance/compressOld.php, and
784 # as pages are saved if $wgCompressRevisions is set.
785 $text = gzinflate( $text );
788 if( in_array( 'object', $flags ) ) {
789 # Generic compressed storage
790 $obj = unserialize( $text );
791 if ( !is_object( $obj ) ) {
793 wfProfileOut( __METHOD__
);
796 $text = $obj->getText();
799 global $wgLegacyEncoding;
800 if( $text !== false && $wgLegacyEncoding
801 && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) )
803 # Old revisions kept around in a legacy encoding?
804 # Upconvert on demand.
805 # ("utf8" checked for compatibility with some broken
806 # conversion scripts 2008-12-30)
808 $text = $wgContLang->iconv( $wgLegacyEncoding, 'UTF-8', $text );
811 wfProfileOut( __METHOD__
);
816 * If $wgCompressRevisions is enabled, we will compress data.
817 * The input string is modified in place.
818 * Return value is the flags field: contains 'gzip' if the
819 * data is compressed, and 'utf-8' if we're saving in UTF-8
822 * @param $text Mixed: reference to a text
825 public static function compressRevisionText( &$text ) {
826 global $wgCompressRevisions;
829 # Revisions not marked this way will be converted
830 # on load if $wgLegacyCharset is set in the future.
833 if( $wgCompressRevisions ) {
834 if( function_exists( 'gzdeflate' ) ) {
835 $text = gzdeflate( $text );
838 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
841 return implode( ',', $flags );
845 * Insert a new revision into the database, returning the new revision ID
846 * number on success and dies horribly on failure.
848 * @param $dbw DatabaseBase: (master connection)
851 public function insertOn( $dbw ) {
852 global $wgDefaultExternalStore;
854 wfProfileIn( __METHOD__
);
856 $data = $this->mText
;
857 $flags = Revision
::compressRevisionText( $data );
859 # Write to external storage if required
860 if( $wgDefaultExternalStore ) {
861 // Store and get the URL
862 $data = ExternalStore
::insertToDefault( $data );
864 throw new MWException( "Unable to store text to external storage" );
869 $flags .= 'external';
872 # Record the text (or external storage URL) to the text table
873 if( !isset( $this->mTextId
) ) {
874 $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
875 $dbw->insert( 'text',
879 'old_flags' => $flags,
882 $this->mTextId
= $dbw->insertId();
885 if ( $this->mComment
=== null ) $this->mComment
= "";
887 # Record the edit in revisions
888 $rev_id = isset( $this->mId
)
890 : $dbw->nextSequenceValue( 'revision_rev_id_seq' );
891 $dbw->insert( 'revision',
894 'rev_page' => $this->mPage
,
895 'rev_text_id' => $this->mTextId
,
896 'rev_comment' => $this->mComment
,
897 'rev_minor_edit' => $this->mMinorEdit ?
1 : 0,
898 'rev_user' => $this->mUser
,
899 'rev_user_text' => $this->mUserText
,
900 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp
),
901 'rev_deleted' => $this->mDeleted
,
902 'rev_len' => $this->mSize
,
903 'rev_parent_id' => is_null($this->mParentId
) ?
904 $this->getPreviousRevisionId( $dbw ) : $this->mParentId
908 $this->mId
= !is_null( $rev_id ) ?
$rev_id : $dbw->insertId();
910 wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
912 wfProfileOut( __METHOD__
);
917 * Lazy-load the revision's text.
918 * Currently hardcoded to the 'text' table storage engine.
922 protected function loadText() {
923 wfProfileIn( __METHOD__
);
925 // Caching may be beneficial for massive use of external storage
926 global $wgRevisionCacheExpiry, $wgMemc;
927 $textId = $this->getTextId();
928 $key = wfMemcKey( 'revisiontext', 'textid', $textId );
929 if( $wgRevisionCacheExpiry ) {
930 $text = $wgMemc->get( $key );
931 if( is_string( $text ) ) {
932 wfDebug( __METHOD__
. ": got id $textId from cache\n" );
933 wfProfileOut( __METHOD__
);
938 // If we kept data for lazy extraction, use it now...
939 if ( isset( $this->mTextRow
) ) {
940 $row = $this->mTextRow
;
941 $this->mTextRow
= null;
947 // Text data is immutable; check slaves first.
948 $dbr = wfGetDB( DB_SLAVE
);
949 $row = $dbr->selectRow( 'text',
950 array( 'old_text', 'old_flags' ),
951 array( 'old_id' => $this->getTextId() ),
955 if( !$row && wfGetLB()->getServerCount() > 1 ) {
956 // Possible slave lag!
957 $dbw = wfGetDB( DB_MASTER
);
958 $row = $dbw->selectRow( 'text',
959 array( 'old_text', 'old_flags' ),
960 array( 'old_id' => $this->getTextId() ),
964 $text = self
::getRevisionText( $row );
966 # No negative caching -- negative hits on text rows may be due to corrupted slave servers
967 if( $wgRevisionCacheExpiry && $text !== false ) {
968 $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
971 wfProfileOut( __METHOD__
);
977 * Create a new null-revision for insertion into a page's
978 * history. This will not re-save the text, but simply refer
979 * to the text from the previous version.
981 * Such revisions can for instance identify page rename
982 * operations and other such meta-modifications.
984 * @param $dbw DatabaseBase
985 * @param $pageId Integer: ID number of the page to read from
986 * @param $summary String: revision's summary
987 * @param $minor Boolean: whether the revision should be considered as minor
988 * @return Revision|null on error
990 public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
991 wfProfileIn( __METHOD__
);
993 $current = $dbw->selectRow(
994 array( 'page', 'revision' ),
995 array( 'page_latest', 'rev_text_id', 'rev_len' ),
997 'page_id' => $pageId,
998 'page_latest=rev_id',
1003 $revision = new Revision( array(
1005 'comment' => $summary,
1006 'minor_edit' => $minor,
1007 'text_id' => $current->rev_text_id
,
1008 'parent_id' => $current->page_latest
,
1009 'len' => $current->rev_len
1015 wfProfileOut( __METHOD__
);
1020 * Determine if the current user is allowed to view a particular
1021 * field of this revision, if it's marked as deleted.
1023 * @param $field Integer:one of self::DELETED_TEXT,
1024 * self::DELETED_COMMENT,
1025 * self::DELETED_USER
1028 public function userCan( $field ) {
1029 return self
::userCanBitfield( $this->mDeleted
, $field );
1033 * Determine if the current user is allowed to view a particular
1034 * field of this revision, if it's marked as deleted. This is used
1035 * by various classes to avoid duplication.
1037 * @param $bitfield Integer: current field
1038 * @param $field Integer: one of self::DELETED_TEXT = File::DELETED_FILE,
1039 * self::DELETED_COMMENT = File::DELETED_COMMENT,
1040 * self::DELETED_USER = File::DELETED_USER
1043 public static function userCanBitfield( $bitfield, $field ) {
1044 if( $bitfield & $field ) { // aspect is deleted
1046 if ( $bitfield & self
::DELETED_RESTRICTED
) {
1047 $permission = 'suppressrevision';
1048 } elseif ( $field & self
::DELETED_TEXT
) {
1049 $permission = 'deletedtext';
1051 $permission = 'deletedhistory';
1053 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
1054 return $wgUser->isAllowed( $permission );
1061 * Get rev_timestamp from rev_id, without loading the rest of the row
1063 * @param $title Title
1064 * @param $id Integer
1067 static function getTimestampFromId( $title, $id ) {
1068 $dbr = wfGetDB( DB_SLAVE
);
1069 // Casting fix for DB2
1073 $conds = array( 'rev_id' => $id );
1074 $conds['rev_page'] = $title->getArticleId();
1075 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1076 if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
1077 # Not in slave, try master
1078 $dbw = wfGetDB( DB_MASTER
);
1079 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1081 return wfTimestamp( TS_MW
, $timestamp );
1085 * Get count of revisions per page...not very efficient
1087 * @param $db DatabaseBase
1088 * @param $id Integer: page id
1091 static function countByPageId( $db, $id ) {
1092 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
1093 array( 'rev_page' => $id ), __METHOD__
);
1095 return $row->revCount
;
1101 * Get count of revisions per page...not very efficient
1103 * @param $db DatabaseBase
1104 * @param $title Title
1107 static function countByTitle( $db, $title ) {
1108 $id = $title->getArticleId();
1110 return Revision
::countByPageId( $db, $id );