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'] = $pageId;
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 return Revision
::newFromConds( $conds );
92 * Make a fake revision object from an archive table row. This is queried
93 * for permissions or even inserted (as in Special:Undelete)
94 * @todo FIXME: Should be a subclass for RevisionDelete. [TS]
97 * @param $overrides array
101 public static function newFromArchiveRow( $row, $overrides = array() ) {
102 $attribs = $overrides +
array(
103 'page' => isset( $row->page_id
) ?
$row->page_id
: null,
104 'id' => isset( $row->ar_rev_id
) ?
$row->ar_rev_id
: null,
105 'comment' => $row->ar_comment
,
106 'user' => $row->ar_user
,
107 'user_text' => $row->ar_user_text
,
108 'timestamp' => $row->ar_timestamp
,
109 'minor_edit' => $row->ar_minor_edit
,
110 'text_id' => isset( $row->ar_text_id
) ?
$row->ar_text_id
: null,
111 'deleted' => $row->ar_deleted
,
112 'len' => $row->ar_len
);
113 if ( isset( $row->ar_text
) && !$row->ar_text_id
) {
114 // Pre-1.5 ar_text row
115 $attribs['text'] = self
::getRevisionText( $row, 'ar_' );
116 if ( $attribs['text'] === false ) {
117 throw new MWException( 'Unable to load text from archive row (possibly bug 22624)' );
120 return new self( $attribs );
124 * Load a page revision from a given revision ID number.
125 * Returns null if no such revision can be found.
127 * @param $db DatabaseBase
129 * @return Revision or null
131 public static function loadFromId( $db, $id ) {
132 return Revision
::loadFromConds( $db,
133 array( 'page_id=rev_page',
134 'rev_id' => intval( $id ) ) );
138 * Load either the current, or a specified, revision
139 * that's attached to a given page. If not attached
140 * to that page, will return null.
142 * @param $db DatabaseBase
143 * @param $pageid Integer
145 * @return Revision or null
147 public static function loadFromPageId( $db, $pageid, $id = 0 ) {
148 $conds = array( 'page_id=rev_page','rev_page' => intval( $pageid ), 'page_id'=>intval( $pageid ) );
150 $conds['rev_id'] = intval( $id );
152 $conds[] = 'rev_id=page_latest';
154 return Revision
::loadFromConds( $db, $conds );
158 * Load either the current, or a specified, revision
159 * that's attached to a given page. If not attached
160 * to that page, will return null.
162 * @param $db DatabaseBase
163 * @param $title Title
165 * @return Revision or null
167 public static function loadFromTitle( $db, $title, $id = 0 ) {
169 $matchId = intval( $id );
171 $matchId = 'page_latest';
173 return Revision
::loadFromConds(
175 array( "rev_id=$matchId",
177 'page_namespace' => $title->getNamespace(),
178 'page_title' => $title->getDBkey() ) );
182 * Load the revision for the given title with the given timestamp.
183 * WARNING: Timestamps may in some circumstances not be unique,
184 * so this isn't the best key to use.
186 * @param $db DatabaseBase
187 * @param $title Title
188 * @param $timestamp String
189 * @return Revision or null
191 public static function loadFromTimestamp( $db, $title, $timestamp ) {
192 return Revision
::loadFromConds(
194 array( 'rev_timestamp' => $db->timestamp( $timestamp ),
196 'page_namespace' => $title->getNamespace(),
197 'page_title' => $title->getDBkey() ) );
201 * Given a set of conditions, fetch a revision.
203 * @param $conditions Array
204 * @return Revision or null
206 public static function newFromConds( $conditions ) {
207 $db = wfGetDB( DB_SLAVE
);
208 $row = Revision
::loadFromConds( $db, $conditions );
209 if( is_null( $row ) && wfGetLB()->getServerCount() > 1 ) {
210 $dbw = wfGetDB( DB_MASTER
);
211 $row = Revision
::loadFromConds( $dbw, $conditions );
217 * Given a set of conditions, fetch a revision from
218 * the given database connection.
220 * @param $db DatabaseBase
221 * @param $conditions Array
222 * @return Revision or null
224 private static function loadFromConds( $db, $conditions ) {
225 $res = Revision
::fetchFromConds( $db, $conditions );
227 $row = $res->fetchObject();
230 $ret = new Revision( $row );
239 * Return a wrapper for a series of database rows to
240 * fetch all of a given page's revisions in turn.
241 * Each row can be fed to the constructor to get objects.
243 * @param $title Title
244 * @return ResultWrapper
246 public static function fetchRevision( $title ) {
247 return Revision
::fetchFromConds(
249 array( 'rev_id=page_latest',
250 'page_namespace' => $title->getNamespace(),
251 'page_title' => $title->getDBkey(),
252 'page_id=rev_page' ) );
256 * Given a set of conditions, return a ResultWrapper
257 * which will return matching database rows with the
258 * fields necessary to build Revision objects.
260 * @param $db DatabaseBase
261 * @param $conditions Array
262 * @return ResultWrapper
264 private static function fetchFromConds( $db, $conditions ) {
265 $fields = self
::selectFields();
266 $fields[] = 'page_namespace';
267 $fields[] = 'page_title';
268 $fields[] = 'page_latest';
270 array( 'page', 'revision' ),
274 array( 'LIMIT' => 1 ) );
278 * Return the list of revision fields that should be selected to create
281 public static function selectFields() {
298 * Return the list of text fields that should be selected to read the
301 static function selectTextFields() {
309 * Return the list of page fields that should be selected from page table
311 static function selectPageFields() {
322 * @param $row Mixed: either a database row or an array
325 function __construct( $row ) {
326 if( is_object( $row ) ) {
327 $this->mId
= intval( $row->rev_id
);
328 $this->mPage
= intval( $row->rev_page
);
329 $this->mTextId
= intval( $row->rev_text_id
);
330 $this->mComment
= $row->rev_comment
;
331 $this->mUserText
= $row->rev_user_text
;
332 $this->mUser
= intval( $row->rev_user
);
333 $this->mMinorEdit
= intval( $row->rev_minor_edit
);
334 $this->mTimestamp
= $row->rev_timestamp
;
335 $this->mDeleted
= intval( $row->rev_deleted
);
337 if( !isset( $row->rev_parent_id
) )
338 $this->mParentId
= is_null($row->rev_parent_id
) ?
null : 0;
340 $this->mParentId
= intval( $row->rev_parent_id
);
342 if( !isset( $row->rev_len
) ||
is_null( $row->rev_len
) )
345 $this->mSize
= intval( $row->rev_len
);
347 if( isset( $row->page_latest
) ) {
348 $this->mCurrent
= ( $row->rev_id
== $row->page_latest
);
349 $this->mTitle
= Title
::newFromRow( $row );
351 $this->mCurrent
= false;
352 $this->mTitle
= null;
355 // Lazy extraction...
357 if( isset( $row->old_text
) ) {
358 $this->mTextRow
= $row;
360 // 'text' table row entry will be lazy-loaded
361 $this->mTextRow
= null;
363 } elseif( is_array( $row ) ) {
364 // Build a new revision to be saved...
367 $this->mId
= isset( $row['id'] ) ?
intval( $row['id'] ) : null;
368 $this->mPage
= isset( $row['page'] ) ?
intval( $row['page'] ) : null;
369 $this->mTextId
= isset( $row['text_id'] ) ?
intval( $row['text_id'] ) : null;
370 $this->mUserText
= isset( $row['user_text'] ) ?
strval( $row['user_text'] ) : $wgUser->getName();
371 $this->mUser
= isset( $row['user'] ) ?
intval( $row['user'] ) : $wgUser->getId();
372 $this->mMinorEdit
= isset( $row['minor_edit'] ) ?
intval( $row['minor_edit'] ) : 0;
373 $this->mTimestamp
= isset( $row['timestamp'] ) ?
strval( $row['timestamp'] ) : wfTimestamp( TS_MW
);
374 $this->mDeleted
= isset( $row['deleted'] ) ?
intval( $row['deleted'] ) : 0;
375 $this->mSize
= isset( $row['len'] ) ?
intval( $row['len'] ) : null;
376 $this->mParentId
= isset( $row['parent_id'] ) ?
intval( $row['parent_id'] ) : null;
378 // Enforce spacing trimming on supplied text
379 $this->mComment
= isset( $row['comment'] ) ?
trim( strval( $row['comment'] ) ) : null;
380 $this->mText
= isset( $row['text'] ) ?
rtrim( strval( $row['text'] ) ) : null;
381 $this->mTextRow
= null;
383 $this->mTitle
= null; # Load on demand if needed
384 $this->mCurrent
= false;
385 # If we still have no len_size, see it we have the text to figure it out
387 $this->mSize
= is_null( $this->mText
) ?
null : strlen( $this->mText
);
389 throw new MWException( 'Revision constructor passed invalid row format.' );
391 $this->mUnpatrolled
= null;
399 public function getId() {
408 public function getTextId() {
409 return $this->mTextId
;
413 * Get parent revision ID (the original previous page revision)
417 public function getParentId() {
418 return $this->mParentId
;
422 * Returns the length of the text in this revision, or null if unknown.
426 public function getSize() {
431 * Returns the title of the page associated with this entry.
435 public function getTitle() {
436 if( isset( $this->mTitle
) ) {
437 return $this->mTitle
;
439 $dbr = wfGetDB( DB_SLAVE
);
440 $row = $dbr->selectRow(
441 array( 'page', 'revision' ),
442 array( 'page_namespace', 'page_title' ),
443 array( 'page_id=rev_page',
444 'rev_id' => $this->mId
),
445 'Revision::getTitle' );
447 $this->mTitle
= Title
::makeTitle( $row->page_namespace
,
450 return $this->mTitle
;
454 * Set the title of the revision
456 * @param $title Title
458 public function setTitle( $title ) {
459 $this->mTitle
= $title;
467 public function getPage() {
472 * Fetch revision's user id if it's available to the specified audience.
473 * If the specified audience does not have access to it, zero will be
476 * @param $audience Integer: one of:
477 * Revision::FOR_PUBLIC to be displayed to all users
478 * Revision::FOR_THIS_USER to be displayed to $wgUser
479 * Revision::RAW get the ID regardless of permissions
484 public function getUser( $audience = self
::FOR_PUBLIC
) {
485 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
487 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
495 * Fetch revision's user id without regard for the current user's permissions
499 public function getRawUser() {
504 * Fetch revision's username if it's available to the specified audience.
505 * If the specified audience does not have access to the username, an
506 * empty string will be returned.
508 * @param $audience Integer: one of:
509 * Revision::FOR_PUBLIC to be displayed to all users
510 * Revision::FOR_THIS_USER to be displayed to $wgUser
511 * Revision::RAW get the text regardless of permissions
515 public function getUserText( $audience = self
::FOR_PUBLIC
) {
516 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
518 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
521 return $this->mUserText
;
526 * Fetch revision's username without regard for view restrictions
530 public function getRawUserText() {
531 return $this->mUserText
;
535 * Fetch revision comment if it's available to the specified audience.
536 * If the specified audience does not have access to the comment, an
537 * empty string will be returned.
539 * @param $audience Integer: one of:
540 * Revision::FOR_PUBLIC to be displayed to all users
541 * Revision::FOR_THIS_USER to be displayed to $wgUser
542 * Revision::RAW get the text regardless of permissions
546 function getComment( $audience = self
::FOR_PUBLIC
) {
547 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_COMMENT
) ) {
549 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_COMMENT
) ) {
552 return $this->mComment
;
557 * Fetch revision comment without regard for the current user's permissions
561 public function getRawComment() {
562 return $this->mComment
;
568 public function isMinor() {
569 return (bool)$this->mMinorEdit
;
573 * @return Integer rcid of the unpatrolled row, zero if there isn't one
575 public function isUnpatrolled() {
576 if( $this->mUnpatrolled
!== null ) {
577 return $this->mUnpatrolled
;
579 $dbr = wfGetDB( DB_SLAVE
);
580 $this->mUnpatrolled
= $dbr->selectField( 'recentchanges',
582 array( // Add redundant user,timestamp condition so we can use the existing index
583 'rc_user_text' => $this->getRawUserText(),
584 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
585 'rc_this_oldid' => $this->getId(),
590 return (int)$this->mUnpatrolled
;
594 * int $field one of DELETED_* bitfield constants
598 public function isDeleted( $field ) {
599 return ( $this->mDeleted
& $field ) == $field;
603 * Get the deletion bitfield of the revision
605 public function getVisibility() {
606 return (int)$this->mDeleted
;
610 * Fetch revision text if it's available to the specified audience.
611 * If the specified audience does not have the ability to view this
612 * revision, an empty string will be returned.
614 * @param $audience Integer: one of:
615 * Revision::FOR_PUBLIC to be displayed to all users
616 * Revision::FOR_THIS_USER to be displayed to $wgUser
617 * Revision::RAW get the text regardless of permissions
621 public function getText( $audience = self
::FOR_PUBLIC
) {
622 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_TEXT
) ) {
624 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_TEXT
) ) {
627 return $this->getRawText();
632 * Alias for getText(Revision::FOR_THIS_USER)
634 * @deprecated since 1.17
637 public function revText() {
638 wfDeprecated( __METHOD__
);
639 return $this->getText( self
::FOR_THIS_USER
);
643 * Fetch revision text without regard for view restrictions
647 public function getRawText() {
648 if( is_null( $this->mText
) ) {
649 // Revision text is immutable. Load on demand:
650 $this->mText
= $this->loadText();
658 public function getTimestamp() {
659 return wfTimestamp( TS_MW
, $this->mTimestamp
);
665 public function isCurrent() {
666 return $this->mCurrent
;
670 * Get previous revision for this title
672 * @return Revision or null
674 public function getPrevious() {
675 if( $this->getTitle() ) {
676 $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
678 return Revision
::newFromTitle( $this->getTitle(), $prev );
685 * Get next revision for this title
687 * @return Revision or null
689 public function getNext() {
690 if( $this->getTitle() ) {
691 $next = $this->getTitle()->getNextRevisionID( $this->getId() );
693 return Revision
::newFromTitle( $this->getTitle(), $next );
700 * Get previous revision Id for this page_id
701 * This is used to populate rev_parent_id on save
703 * @param $db DatabaseBase
706 private function getPreviousRevisionId( $db ) {
707 if( is_null( $this->mPage
) ) {
710 # Use page_latest if ID is not given
712 $prevId = $db->selectField( 'page', 'page_latest',
713 array( 'page_id' => $this->mPage
),
716 $prevId = $db->selectField( 'revision', 'rev_id',
717 array( 'rev_page' => $this->mPage
, 'rev_id < ' . $this->mId
),
719 array( 'ORDER BY' => 'rev_id DESC' ) );
721 return intval( $prevId );
725 * Get revision text associated with an old or archive row
726 * $row is usually an object from wfFetchRow(), both the flags and the text
727 * field must be included
729 * @param $row Object: the text data
730 * @param $prefix String: table prefix (default 'old_')
731 * @return String: text the text requested or false on failure
733 public static function getRevisionText( $row, $prefix = 'old_' ) {
734 wfProfileIn( __METHOD__
);
737 $textField = $prefix . 'text';
738 $flagsField = $prefix . 'flags';
740 if( isset( $row->$flagsField ) ) {
741 $flags = explode( ',', $row->$flagsField );
746 if( isset( $row->$textField ) ) {
747 $text = $row->$textField;
749 wfProfileOut( __METHOD__
);
753 # Use external methods for external objects, text in table is URL-only then
754 if ( in_array( 'external', $flags ) ) {
756 @list
(/* $proto */, $path ) = explode( '://', $url, 2 );
758 wfProfileOut( __METHOD__
);
761 $text = ExternalStore
::fetchFromURL( $url );
764 // If the text was fetched without an error, convert it
765 if ( $text !== false ) {
766 if( in_array( 'gzip', $flags ) ) {
767 # Deal with optional compression of archived pages.
768 # This can be done periodically via maintenance/compressOld.php, and
769 # as pages are saved if $wgCompressRevisions is set.
770 $text = gzinflate( $text );
773 if( in_array( 'object', $flags ) ) {
774 # Generic compressed storage
775 $obj = unserialize( $text );
776 if ( !is_object( $obj ) ) {
778 wfProfileOut( __METHOD__
);
781 $text = $obj->getText();
784 global $wgLegacyEncoding;
785 if( $text !== false && $wgLegacyEncoding
786 && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) )
788 # Old revisions kept around in a legacy encoding?
789 # Upconvert on demand.
790 # ("utf8" checked for compatibility with some broken
791 # conversion scripts 2008-12-30)
793 $text = $wgContLang->iconv( $wgLegacyEncoding, 'UTF-8', $text );
796 wfProfileOut( __METHOD__
);
801 * If $wgCompressRevisions is enabled, we will compress data.
802 * The input string is modified in place.
803 * Return value is the flags field: contains 'gzip' if the
804 * data is compressed, and 'utf-8' if we're saving in UTF-8
807 * @param $text Mixed: reference to a text
810 public static function compressRevisionText( &$text ) {
811 global $wgCompressRevisions;
814 # Revisions not marked this way will be converted
815 # on load if $wgLegacyCharset is set in the future.
818 if( $wgCompressRevisions ) {
819 if( function_exists( 'gzdeflate' ) ) {
820 $text = gzdeflate( $text );
823 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
826 return implode( ',', $flags );
830 * Insert a new revision into the database, returning the new revision ID
831 * number on success and dies horribly on failure.
833 * @param $dbw DatabaseBase: (master connection)
836 public function insertOn( $dbw ) {
837 global $wgDefaultExternalStore;
839 wfProfileIn( __METHOD__
);
841 $data = $this->mText
;
842 $flags = Revision
::compressRevisionText( $data );
844 # Write to external storage if required
845 if( $wgDefaultExternalStore ) {
846 // Store and get the URL
847 $data = ExternalStore
::insertToDefault( $data );
849 throw new MWException( "Unable to store text to external storage" );
854 $flags .= 'external';
857 # Record the text (or external storage URL) to the text table
858 if( !isset( $this->mTextId
) ) {
859 $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
860 $dbw->insert( 'text',
864 'old_flags' => $flags,
867 $this->mTextId
= $dbw->insertId();
870 if ( $this->mComment
=== null ) $this->mComment
= "";
872 # Record the edit in revisions
873 $rev_id = isset( $this->mId
)
875 : $dbw->nextSequenceValue( 'revision_rev_id_seq' );
876 $dbw->insert( 'revision',
879 'rev_page' => $this->mPage
,
880 'rev_text_id' => $this->mTextId
,
881 'rev_comment' => $this->mComment
,
882 'rev_minor_edit' => $this->mMinorEdit ?
1 : 0,
883 'rev_user' => $this->mUser
,
884 'rev_user_text' => $this->mUserText
,
885 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp
),
886 'rev_deleted' => $this->mDeleted
,
887 'rev_len' => $this->mSize
,
888 'rev_parent_id' => is_null($this->mParentId
) ?
889 $this->getPreviousRevisionId( $dbw ) : $this->mParentId
893 $this->mId
= !is_null( $rev_id ) ?
$rev_id : $dbw->insertId();
895 wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
897 wfProfileOut( __METHOD__
);
902 * Lazy-load the revision's text.
903 * Currently hardcoded to the 'text' table storage engine.
907 protected function loadText() {
908 wfProfileIn( __METHOD__
);
910 // Caching may be beneficial for massive use of external storage
911 global $wgRevisionCacheExpiry, $wgMemc;
912 $textId = $this->getTextId();
913 $key = wfMemcKey( 'revisiontext', 'textid', $textId );
914 if( $wgRevisionCacheExpiry ) {
915 $text = $wgMemc->get( $key );
916 if( is_string( $text ) ) {
917 wfDebug( __METHOD__
. ": got id $textId from cache\n" );
918 wfProfileOut( __METHOD__
);
923 // If we kept data for lazy extraction, use it now...
924 if ( isset( $this->mTextRow
) ) {
925 $row = $this->mTextRow
;
926 $this->mTextRow
= null;
932 // Text data is immutable; check slaves first.
933 $dbr = wfGetDB( DB_SLAVE
);
934 $row = $dbr->selectRow( 'text',
935 array( 'old_text', 'old_flags' ),
936 array( 'old_id' => $this->getTextId() ),
940 if( !$row && wfGetLB()->getServerCount() > 1 ) {
941 // Possible slave lag!
942 $dbw = wfGetDB( DB_MASTER
);
943 $row = $dbw->selectRow( 'text',
944 array( 'old_text', 'old_flags' ),
945 array( 'old_id' => $this->getTextId() ),
949 $text = self
::getRevisionText( $row );
951 # No negative caching -- negative hits on text rows may be due to corrupted slave servers
952 if( $wgRevisionCacheExpiry && $text !== false ) {
953 $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
956 wfProfileOut( __METHOD__
);
962 * Create a new null-revision for insertion into a page's
963 * history. This will not re-save the text, but simply refer
964 * to the text from the previous version.
966 * Such revisions can for instance identify page rename
967 * operations and other such meta-modifications.
969 * @param $dbw DatabaseBase
970 * @param $pageId Integer: ID number of the page to read from
971 * @param $summary String: revision's summary
972 * @param $minor Boolean: whether the revision should be considered as minor
973 * @return Revision|null on error
975 public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
976 wfProfileIn( __METHOD__
);
978 $current = $dbw->selectRow(
979 array( 'page', 'revision' ),
980 array( 'page_latest', 'rev_text_id', 'rev_len' ),
982 'page_id' => $pageId,
983 'page_latest=rev_id',
988 $revision = new Revision( array(
990 'comment' => $summary,
991 'minor_edit' => $minor,
992 'text_id' => $current->rev_text_id
,
993 'parent_id' => $current->page_latest
,
994 'len' => $current->rev_len
1000 wfProfileOut( __METHOD__
);
1005 * Determine if the current user is allowed to view a particular
1006 * field of this revision, if it's marked as deleted.
1008 * @param $field Integer:one of self::DELETED_TEXT,
1009 * self::DELETED_COMMENT,
1010 * self::DELETED_USER
1013 public function userCan( $field ) {
1014 return self
::userCanBitfield( $this->mDeleted
, $field );
1018 * Determine if the current user is allowed to view a particular
1019 * field of this revision, if it's marked as deleted. This is used
1020 * by various classes to avoid duplication.
1022 * @param $bitfield Integer: current field
1023 * @param $field Integer: one of self::DELETED_TEXT = File::DELETED_FILE,
1024 * self::DELETED_COMMENT = File::DELETED_COMMENT,
1025 * self::DELETED_USER = File::DELETED_USER
1028 public static function userCanBitfield( $bitfield, $field ) {
1029 if( $bitfield & $field ) { // aspect is deleted
1031 if ( $bitfield & self
::DELETED_RESTRICTED
) {
1032 $permission = 'suppressrevision';
1033 } elseif ( $field & self
::DELETED_TEXT
) {
1034 $permission = 'deletedtext';
1036 $permission = 'deletedhistory';
1038 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
1039 return $wgUser->isAllowed( $permission );
1046 * Get rev_timestamp from rev_id, without loading the rest of the row
1048 * @param $title Title
1049 * @param $id Integer
1052 static function getTimestampFromId( $title, $id ) {
1053 $dbr = wfGetDB( DB_SLAVE
);
1054 // Casting fix for DB2
1058 $conds = array( 'rev_id' => $id );
1059 $conds['rev_page'] = $title->getArticleId();
1060 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1061 if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
1062 # Not in slave, try master
1063 $dbw = wfGetDB( DB_MASTER
);
1064 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1066 return wfTimestamp( TS_MW
, $timestamp );
1070 * Get count of revisions per page...not very efficient
1072 * @param $db DatabaseBase
1073 * @param $id Integer: page id
1076 static function countByPageId( $db, $id ) {
1077 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
1078 array( 'rev_page' => $id ), __METHOD__
);
1080 return $row->revCount
;
1086 * Get count of revisions per page...not very efficient
1088 * @param $db DatabaseBase
1089 * @param $title Title
1092 static function countByTitle( $db, $title ) {
1093 $id = $title->getArticleId();
1095 return Revision
::countByPageId( $db, $id );
1102 * Aliases for backwards compatibility with 1.6
1104 define( 'MW_REV_DELETED_TEXT', Revision
::DELETED_TEXT
);
1105 define( 'MW_REV_DELETED_COMMENT', Revision
::DELETED_COMMENT
);
1106 define( 'MW_REV_DELETED_USER', Revision
::DELETED_USER
);
1107 define( 'MW_REV_DELETED_RESTRICTED', Revision
::DELETED_RESTRICTED
);