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
);
114 if ( isset( $row->ar_text
) && !$row->ar_text_id
) {
115 // Pre-1.5 ar_text row
116 $attribs['text'] = self
::getRevisionText( $row, 'ar_' );
117 if ( $attribs['text'] === false ) {
118 throw new MWException( 'Unable to load text from archive row (possibly bug 22624)' );
121 return new self( $attribs );
125 * Load a page revision from a given revision ID number.
126 * Returns null if no such revision can be found.
128 * @param $db DatabaseBase
130 * @return Revision or null
132 public static function loadFromId( $db, $id ) {
133 return Revision
::loadFromConds( $db,
134 array( 'page_id=rev_page',
135 'rev_id' => intval( $id ) ) );
139 * Load either the current, or a specified, revision
140 * that's attached to a given page. If not attached
141 * to that page, will return null.
143 * @param $db DatabaseBase
144 * @param $pageid Integer
146 * @return Revision or null
148 public static function loadFromPageId( $db, $pageid, $id = 0 ) {
149 $conds = array( 'page_id=rev_page','rev_page' => intval( $pageid ), 'page_id'=>intval( $pageid ) );
151 $conds['rev_id'] = intval( $id );
153 $conds[] = 'rev_id=page_latest';
155 return Revision
::loadFromConds( $db, $conds );
159 * Load either the current, or a specified, revision
160 * that's attached to a given page. If not attached
161 * to that page, will return null.
163 * @param $db DatabaseBase
164 * @param $title Title
166 * @return Revision or null
168 public static function loadFromTitle( $db, $title, $id = 0 ) {
170 $matchId = intval( $id );
172 $matchId = 'page_latest';
174 return Revision
::loadFromConds(
176 array( "rev_id=$matchId",
178 'page_namespace' => $title->getNamespace(),
179 'page_title' => $title->getDBkey() ) );
183 * Load the revision for the given title with the given timestamp.
184 * WARNING: Timestamps may in some circumstances not be unique,
185 * so this isn't the best key to use.
187 * @param $db DatabaseBase
188 * @param $title Title
189 * @param $timestamp String
190 * @return Revision or null
192 public static function loadFromTimestamp( $db, $title, $timestamp ) {
193 return Revision
::loadFromConds(
195 array( 'rev_timestamp' => $db->timestamp( $timestamp ),
197 'page_namespace' => $title->getNamespace(),
198 'page_title' => $title->getDBkey() ) );
202 * Given a set of conditions, fetch a revision.
204 * @param $conditions Array
205 * @return Revision or null
207 public static function newFromConds( $conditions ) {
208 $db = wfGetDB( DB_SLAVE
);
209 $row = Revision
::loadFromConds( $db, $conditions );
210 if( is_null( $row ) && wfGetLB()->getServerCount() > 1 ) {
211 $dbw = wfGetDB( DB_MASTER
);
212 $row = Revision
::loadFromConds( $dbw, $conditions );
218 * Given a set of conditions, fetch a revision from
219 * the given database connection.
221 * @param $db DatabaseBase
222 * @param $conditions Array
223 * @return Revision or null
225 private static function loadFromConds( $db, $conditions ) {
226 $res = Revision
::fetchFromConds( $db, $conditions );
228 $row = $res->fetchObject();
231 $ret = new Revision( $row );
240 * Return a wrapper for a series of database rows to
241 * fetch all of a given page's revisions in turn.
242 * Each row can be fed to the constructor to get objects.
244 * @param $title Title
245 * @return ResultWrapper
247 public static function fetchRevision( $title ) {
248 return Revision
::fetchFromConds(
250 array( 'rev_id=page_latest',
251 'page_namespace' => $title->getNamespace(),
252 'page_title' => $title->getDBkey(),
253 'page_id=rev_page' ) );
257 * Given a set of conditions, return a ResultWrapper
258 * which will return matching database rows with the
259 * fields necessary to build Revision objects.
261 * @param $db DatabaseBase
262 * @param $conditions Array
263 * @return ResultWrapper
265 private static function fetchFromConds( $db, $conditions ) {
266 $fields = self
::selectFields();
267 $fields[] = 'page_namespace';
268 $fields[] = 'page_title';
269 $fields[] = 'page_latest';
271 array( 'page', 'revision' ),
275 array( 'LIMIT' => 1 ) );
279 * Return the list of revision fields that should be selected to create
282 public static function selectFields() {
299 * Return the list of text fields that should be selected to read the
302 static function selectTextFields() {
310 * Return the list of page fields that should be selected from page table
312 static function selectPageFields() {
323 * @param $row Mixed: either a database row or an array
326 function __construct( $row ) {
327 if( is_object( $row ) ) {
328 $this->mId
= intval( $row->rev_id
);
329 $this->mPage
= intval( $row->rev_page
);
330 $this->mTextId
= intval( $row->rev_text_id
);
331 $this->mComment
= $row->rev_comment
;
332 $this->mUserText
= $row->rev_user_text
;
333 $this->mUser
= intval( $row->rev_user
);
334 $this->mMinorEdit
= intval( $row->rev_minor_edit
);
335 $this->mTimestamp
= $row->rev_timestamp
;
336 $this->mDeleted
= intval( $row->rev_deleted
);
338 if( !isset( $row->rev_parent_id
) ) {
339 $this->mParentId
= is_null($row->rev_parent_id
) ?
null : 0;
341 $this->mParentId
= intval( $row->rev_parent_id
);
344 if( !isset( $row->rev_len
) ||
is_null( $row->rev_len
) ) {
347 $this->mSize
= intval( $row->rev_len
);
350 if( isset( $row->page_latest
) ) {
351 $this->mCurrent
= ( $row->rev_id
== $row->page_latest
);
352 $this->mTitle
= Title
::newFromRow( $row );
354 $this->mCurrent
= false;
355 $this->mTitle
= null;
358 // Lazy extraction...
360 if( isset( $row->old_text
) ) {
361 $this->mTextRow
= $row;
363 // 'text' table row entry will be lazy-loaded
364 $this->mTextRow
= null;
366 } elseif( is_array( $row ) ) {
367 // Build a new revision to be saved...
370 $this->mId
= isset( $row['id'] ) ?
intval( $row['id'] ) : null;
371 $this->mPage
= isset( $row['page'] ) ?
intval( $row['page'] ) : null;
372 $this->mTextId
= isset( $row['text_id'] ) ?
intval( $row['text_id'] ) : null;
373 $this->mUserText
= isset( $row['user_text'] ) ?
strval( $row['user_text'] ) : $wgUser->getName();
374 $this->mUser
= isset( $row['user'] ) ?
intval( $row['user'] ) : $wgUser->getId();
375 $this->mMinorEdit
= isset( $row['minor_edit'] ) ?
intval( $row['minor_edit'] ) : 0;
376 $this->mTimestamp
= isset( $row['timestamp'] ) ?
strval( $row['timestamp'] ) : wfTimestamp( TS_MW
);
377 $this->mDeleted
= isset( $row['deleted'] ) ?
intval( $row['deleted'] ) : 0;
378 $this->mSize
= isset( $row['len'] ) ?
intval( $row['len'] ) : null;
379 $this->mParentId
= isset( $row['parent_id'] ) ?
intval( $row['parent_id'] ) : null;
381 // Enforce spacing trimming on supplied text
382 $this->mComment
= isset( $row['comment'] ) ?
trim( strval( $row['comment'] ) ) : null;
383 $this->mText
= isset( $row['text'] ) ?
rtrim( strval( $row['text'] ) ) : null;
384 $this->mTextRow
= null;
386 $this->mTitle
= null; # Load on demand if needed
387 $this->mCurrent
= false;
388 # If we still have no len_size, see it we have the text to figure it out
390 $this->mSize
= is_null( $this->mText
) ?
null : strlen( $this->mText
);
392 throw new MWException( 'Revision constructor passed invalid row format.' );
394 $this->mUnpatrolled
= null;
402 public function getId() {
411 public function getTextId() {
412 return $this->mTextId
;
416 * Get parent revision ID (the original previous page revision)
420 public function getParentId() {
421 return $this->mParentId
;
425 * Returns the length of the text in this revision, or null if unknown.
429 public function getSize() {
434 * Returns the title of the page associated with this entry.
438 public function getTitle() {
439 if( isset( $this->mTitle
) ) {
440 return $this->mTitle
;
442 $dbr = wfGetDB( DB_SLAVE
);
443 $row = $dbr->selectRow(
444 array( 'page', 'revision' ),
445 array( 'page_namespace', 'page_title' ),
446 array( 'page_id=rev_page',
447 'rev_id' => $this->mId
),
448 'Revision::getTitle' );
450 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
452 return $this->mTitle
;
456 * Set the title of the revision
458 * @param $title Title
460 public function setTitle( $title ) {
461 $this->mTitle
= $title;
469 public function getPage() {
474 * Fetch revision's user id if it's available to the specified audience.
475 * If the specified audience does not have access to it, zero will be
478 * @param $audience Integer: one of:
479 * Revision::FOR_PUBLIC to be displayed to all users
480 * Revision::FOR_THIS_USER to be displayed to $wgUser
481 * Revision::RAW get the ID regardless of permissions
486 public function getUser( $audience = self
::FOR_PUBLIC
) {
487 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
489 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
497 * Fetch revision's user id without regard for the current user's permissions
501 public function getRawUser() {
506 * Fetch revision's username if it's available to the specified audience.
507 * If the specified audience does not have access to the username, an
508 * empty string will be returned.
510 * @param $audience Integer: one of:
511 * Revision::FOR_PUBLIC to be displayed to all users
512 * Revision::FOR_THIS_USER to be displayed to $wgUser
513 * Revision::RAW get the text regardless of permissions
517 public function getUserText( $audience = self
::FOR_PUBLIC
) {
518 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
520 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
523 return $this->mUserText
;
528 * Fetch revision's username without regard for view restrictions
532 public function getRawUserText() {
533 return $this->mUserText
;
537 * Fetch revision comment if it's available to the specified audience.
538 * If the specified audience does not have access to the comment, an
539 * empty string will be returned.
541 * @param $audience Integer: one of:
542 * Revision::FOR_PUBLIC to be displayed to all users
543 * Revision::FOR_THIS_USER to be displayed to $wgUser
544 * Revision::RAW get the text regardless of permissions
548 function getComment( $audience = self
::FOR_PUBLIC
) {
549 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_COMMENT
) ) {
551 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_COMMENT
) ) {
554 return $this->mComment
;
559 * Fetch revision comment without regard for the current user's permissions
563 public function getRawComment() {
564 return $this->mComment
;
570 public function isMinor() {
571 return (bool)$this->mMinorEdit
;
575 * @return Integer rcid of the unpatrolled row, zero if there isn't one
577 public function isUnpatrolled() {
578 if( $this->mUnpatrolled
!== null ) {
579 return $this->mUnpatrolled
;
581 $dbr = wfGetDB( DB_SLAVE
);
582 $this->mUnpatrolled
= $dbr->selectField( 'recentchanges',
584 array( // Add redundant user,timestamp condition so we can use the existing index
585 'rc_user_text' => $this->getRawUserText(),
586 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
587 'rc_this_oldid' => $this->getId(),
592 return (int)$this->mUnpatrolled
;
596 * @param $field int one of DELETED_* bitfield constants
600 public function isDeleted( $field ) {
601 return ( $this->mDeleted
& $field ) == $field;
605 * Get the deletion bitfield of the revision
609 public function getVisibility() {
610 return (int)$this->mDeleted
;
614 * Fetch revision text if it's available to the specified audience.
615 * If the specified audience does not have the ability to view this
616 * revision, an empty string will be returned.
618 * @param $audience Integer: one of:
619 * Revision::FOR_PUBLIC to be displayed to all users
620 * Revision::FOR_THIS_USER to be displayed to $wgUser
621 * Revision::RAW get the text regardless of permissions
625 public function getText( $audience = self
::FOR_PUBLIC
) {
626 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_TEXT
) ) {
628 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_TEXT
) ) {
631 return $this->getRawText();
636 * Alias for getText(Revision::FOR_THIS_USER)
638 * @deprecated since 1.17
641 public function revText() {
642 wfDeprecated( __METHOD__
);
643 return $this->getText( self
::FOR_THIS_USER
);
647 * Fetch revision text without regard for view restrictions
651 public function getRawText() {
652 if( is_null( $this->mText
) ) {
653 // Revision text is immutable. Load on demand:
654 $this->mText
= $this->loadText();
662 public function getTimestamp() {
663 return wfTimestamp( TS_MW
, $this->mTimestamp
);
669 public function isCurrent() {
670 return $this->mCurrent
;
674 * Get previous revision for this title
676 * @return Revision or null
678 public function getPrevious() {
679 if( $this->getTitle() ) {
680 $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
682 return Revision
::newFromTitle( $this->getTitle(), $prev );
689 * Get next revision for this title
691 * @return Revision or null
693 public function getNext() {
694 if( $this->getTitle() ) {
695 $next = $this->getTitle()->getNextRevisionID( $this->getId() );
697 return Revision
::newFromTitle( $this->getTitle(), $next );
704 * Get previous revision Id for this page_id
705 * This is used to populate rev_parent_id on save
707 * @param $db DatabaseBase
710 private function getPreviousRevisionId( $db ) {
711 if( is_null( $this->mPage
) ) {
714 # Use page_latest if ID is not given
716 $prevId = $db->selectField( 'page', 'page_latest',
717 array( 'page_id' => $this->mPage
),
720 $prevId = $db->selectField( 'revision', 'rev_id',
721 array( 'rev_page' => $this->mPage
, 'rev_id < ' . $this->mId
),
723 array( 'ORDER BY' => 'rev_id DESC' ) );
725 return intval( $prevId );
729 * Get revision text associated with an old or archive row
730 * $row is usually an object from wfFetchRow(), both the flags and the text
731 * field must be included
733 * @param $row Object: the text data
734 * @param $prefix String: table prefix (default 'old_')
735 * @return String: text the text requested or false on failure
737 public static function getRevisionText( $row, $prefix = 'old_' ) {
738 wfProfileIn( __METHOD__
);
741 $textField = $prefix . 'text';
742 $flagsField = $prefix . 'flags';
744 if( isset( $row->$flagsField ) ) {
745 $flags = explode( ',', $row->$flagsField );
750 if( isset( $row->$textField ) ) {
751 $text = $row->$textField;
753 wfProfileOut( __METHOD__
);
757 # Use external methods for external objects, text in table is URL-only then
758 if ( in_array( 'external', $flags ) ) {
760 $parts = explode( '://', $url, 2 );
761 if( count( $parts ) == 1 ||
$parts[1] == '' ) {
762 wfProfileOut( __METHOD__
);
765 $text = ExternalStore
::fetchFromURL( $url );
768 // If the text was fetched without an error, convert it
769 if ( $text !== false ) {
770 if( in_array( 'gzip', $flags ) ) {
771 # Deal with optional compression of archived pages.
772 # This can be done periodically via maintenance/compressOld.php, and
773 # as pages are saved if $wgCompressRevisions is set.
774 $text = gzinflate( $text );
777 if( in_array( 'object', $flags ) ) {
778 # Generic compressed storage
779 $obj = unserialize( $text );
780 if ( !is_object( $obj ) ) {
782 wfProfileOut( __METHOD__
);
785 $text = $obj->getText();
788 global $wgLegacyEncoding;
789 if( $text !== false && $wgLegacyEncoding
790 && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) )
792 # Old revisions kept around in a legacy encoding?
793 # Upconvert on demand.
794 # ("utf8" checked for compatibility with some broken
795 # conversion scripts 2008-12-30)
797 $text = $wgContLang->iconv( $wgLegacyEncoding, 'UTF-8', $text );
800 wfProfileOut( __METHOD__
);
805 * If $wgCompressRevisions is enabled, we will compress data.
806 * The input string is modified in place.
807 * Return value is the flags field: contains 'gzip' if the
808 * data is compressed, and 'utf-8' if we're saving in UTF-8
811 * @param $text Mixed: reference to a text
814 public static function compressRevisionText( &$text ) {
815 global $wgCompressRevisions;
818 # Revisions not marked this way will be converted
819 # on load if $wgLegacyCharset is set in the future.
822 if( $wgCompressRevisions ) {
823 if( function_exists( 'gzdeflate' ) ) {
824 $text = gzdeflate( $text );
827 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
830 return implode( ',', $flags );
834 * Insert a new revision into the database, returning the new revision ID
835 * number on success and dies horribly on failure.
837 * @param $dbw DatabaseBase: (master connection)
840 public function insertOn( $dbw ) {
841 global $wgDefaultExternalStore;
843 wfProfileIn( __METHOD__
);
845 $data = $this->mText
;
846 $flags = Revision
::compressRevisionText( $data );
848 # Write to external storage if required
849 if( $wgDefaultExternalStore ) {
850 // Store and get the URL
851 $data = ExternalStore
::insertToDefault( $data );
853 throw new MWException( "Unable to store text to external storage" );
858 $flags .= 'external';
861 # Record the text (or external storage URL) to the text table
862 if( !isset( $this->mTextId
) ) {
863 $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
864 $dbw->insert( 'text',
868 'old_flags' => $flags,
871 $this->mTextId
= $dbw->insertId();
874 if ( $this->mComment
=== null ) $this->mComment
= "";
876 # Record the edit in revisions
877 $rev_id = isset( $this->mId
)
879 : $dbw->nextSequenceValue( 'revision_rev_id_seq' );
880 $dbw->insert( 'revision',
883 'rev_page' => $this->mPage
,
884 'rev_text_id' => $this->mTextId
,
885 'rev_comment' => $this->mComment
,
886 'rev_minor_edit' => $this->mMinorEdit ?
1 : 0,
887 'rev_user' => $this->mUser
,
888 'rev_user_text' => $this->mUserText
,
889 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp
),
890 'rev_deleted' => $this->mDeleted
,
891 'rev_len' => $this->mSize
,
892 'rev_parent_id' => is_null($this->mParentId
) ?
893 $this->getPreviousRevisionId( $dbw ) : $this->mParentId
897 $this->mId
= !is_null( $rev_id ) ?
$rev_id : $dbw->insertId();
899 wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
901 wfProfileOut( __METHOD__
);
906 * Lazy-load the revision's text.
907 * Currently hardcoded to the 'text' table storage engine.
911 protected function loadText() {
912 wfProfileIn( __METHOD__
);
914 // Caching may be beneficial for massive use of external storage
915 global $wgRevisionCacheExpiry, $wgMemc;
916 $textId = $this->getTextId();
917 $key = wfMemcKey( 'revisiontext', 'textid', $textId );
918 if( $wgRevisionCacheExpiry ) {
919 $text = $wgMemc->get( $key );
920 if( is_string( $text ) ) {
921 wfDebug( __METHOD__
. ": got id $textId from cache\n" );
922 wfProfileOut( __METHOD__
);
927 // If we kept data for lazy extraction, use it now...
928 if ( isset( $this->mTextRow
) ) {
929 $row = $this->mTextRow
;
930 $this->mTextRow
= null;
936 // Text data is immutable; check slaves first.
937 $dbr = wfGetDB( DB_SLAVE
);
938 $row = $dbr->selectRow( 'text',
939 array( 'old_text', 'old_flags' ),
940 array( 'old_id' => $this->getTextId() ),
944 if( !$row && wfGetLB()->getServerCount() > 1 ) {
945 // Possible slave lag!
946 $dbw = wfGetDB( DB_MASTER
);
947 $row = $dbw->selectRow( 'text',
948 array( 'old_text', 'old_flags' ),
949 array( 'old_id' => $this->getTextId() ),
953 $text = self
::getRevisionText( $row );
955 # No negative caching -- negative hits on text rows may be due to corrupted slave servers
956 if( $wgRevisionCacheExpiry && $text !== false ) {
957 $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
960 wfProfileOut( __METHOD__
);
966 * Create a new null-revision for insertion into a page's
967 * history. This will not re-save the text, but simply refer
968 * to the text from the previous version.
970 * Such revisions can for instance identify page rename
971 * operations and other such meta-modifications.
973 * @param $dbw DatabaseBase
974 * @param $pageId Integer: ID number of the page to read from
975 * @param $summary String: revision's summary
976 * @param $minor Boolean: whether the revision should be considered as minor
977 * @return Revision|null on error
979 public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
980 wfProfileIn( __METHOD__
);
982 $current = $dbw->selectRow(
983 array( 'page', 'revision' ),
984 array( 'page_latest', 'rev_text_id', 'rev_len' ),
986 'page_id' => $pageId,
987 'page_latest=rev_id',
992 $revision = new Revision( array(
994 'comment' => $summary,
995 'minor_edit' => $minor,
996 'text_id' => $current->rev_text_id
,
997 'parent_id' => $current->page_latest
,
998 'len' => $current->rev_len
1004 wfProfileOut( __METHOD__
);
1009 * Determine if the current user is allowed to view a particular
1010 * field of this revision, if it's marked as deleted.
1012 * @param $field Integer:one of self::DELETED_TEXT,
1013 * self::DELETED_COMMENT,
1014 * self::DELETED_USER
1017 public function userCan( $field ) {
1018 return self
::userCanBitfield( $this->mDeleted
, $field );
1022 * Determine if the current user is allowed to view a particular
1023 * field of this revision, if it's marked as deleted. This is used
1024 * by various classes to avoid duplication.
1026 * @param $bitfield Integer: current field
1027 * @param $field Integer: one of self::DELETED_TEXT = File::DELETED_FILE,
1028 * self::DELETED_COMMENT = File::DELETED_COMMENT,
1029 * self::DELETED_USER = File::DELETED_USER
1032 public static function userCanBitfield( $bitfield, $field ) {
1033 if( $bitfield & $field ) { // aspect is deleted
1035 if ( $bitfield & self
::DELETED_RESTRICTED
) {
1036 $permission = 'suppressrevision';
1037 } elseif ( $field & self
::DELETED_TEXT
) {
1038 $permission = 'deletedtext';
1040 $permission = 'deletedhistory';
1042 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
1043 return $wgUser->isAllowed( $permission );
1050 * Get rev_timestamp from rev_id, without loading the rest of the row
1052 * @param $title Title
1053 * @param $id Integer
1056 static function getTimestampFromId( $title, $id ) {
1057 $dbr = wfGetDB( DB_SLAVE
);
1058 // Casting fix for DB2
1062 $conds = array( 'rev_id' => $id );
1063 $conds['rev_page'] = $title->getArticleId();
1064 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1065 if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
1066 # Not in slave, try master
1067 $dbw = wfGetDB( DB_MASTER
);
1068 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1070 return wfTimestamp( TS_MW
, $timestamp );
1074 * Get count of revisions per page...not very efficient
1076 * @param $db DatabaseBase
1077 * @param $id Integer: page id
1080 static function countByPageId( $db, $id ) {
1081 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
1082 array( 'rev_page' => $id ), __METHOD__
);
1084 return $row->revCount
;
1090 * Get count of revisions per page...not very efficient
1092 * @param $db DatabaseBase
1093 * @param $title Title
1096 static function countByTitle( $db, $title ) {
1097 $id = $title->getArticleId();
1099 return Revision
::countByPageId( $db, $id );