f93108017b2f8fd9d8e54367119373d16c9c622d
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 );
130 public static function newFromRow( $row ) {
131 return new self( $row );
135 * Load a page revision from a given revision ID number.
136 * Returns null if no such revision can be found.
138 * @param $db DatabaseBase
140 * @return Revision or null
142 public static function loadFromId( $db, $id ) {
143 return Revision
::loadFromConds( $db,
144 array( 'page_id=rev_page',
145 'rev_id' => intval( $id ) ) );
149 * Load either the current, or a specified, revision
150 * that's attached to a given page. If not attached
151 * to that page, will return null.
153 * @param $db DatabaseBase
154 * @param $pageid Integer
156 * @return Revision or null
158 public static function loadFromPageId( $db, $pageid, $id = 0 ) {
159 $conds = array( 'page_id=rev_page','rev_page' => intval( $pageid ), 'page_id'=>intval( $pageid ) );
161 $conds['rev_id'] = intval( $id );
163 $conds[] = 'rev_id=page_latest';
165 return Revision
::loadFromConds( $db, $conds );
169 * Load either the current, or a specified, revision
170 * that's attached to a given page. If not attached
171 * to that page, will return null.
173 * @param $db DatabaseBase
174 * @param $title Title
176 * @return Revision or null
178 public static function loadFromTitle( $db, $title, $id = 0 ) {
180 $matchId = intval( $id );
182 $matchId = 'page_latest';
184 return Revision
::loadFromConds(
186 array( "rev_id=$matchId",
188 'page_namespace' => $title->getNamespace(),
189 'page_title' => $title->getDBkey() ) );
193 * Load the revision for the given title with the given timestamp.
194 * WARNING: Timestamps may in some circumstances not be unique,
195 * so this isn't the best key to use.
197 * @param $db DatabaseBase
198 * @param $title Title
199 * @param $timestamp String
200 * @return Revision or null
202 public static function loadFromTimestamp( $db, $title, $timestamp ) {
203 return Revision
::loadFromConds(
205 array( 'rev_timestamp' => $db->timestamp( $timestamp ),
207 'page_namespace' => $title->getNamespace(),
208 'page_title' => $title->getDBkey() ) );
212 * Given a set of conditions, fetch a revision.
214 * @param $conditions Array
215 * @return Revision or null
217 public static function newFromConds( $conditions ) {
218 $db = wfGetDB( DB_SLAVE
);
219 $row = Revision
::loadFromConds( $db, $conditions );
220 if( is_null( $row ) && wfGetLB()->getServerCount() > 1 ) {
221 $dbw = wfGetDB( DB_MASTER
);
222 $row = Revision
::loadFromConds( $dbw, $conditions );
228 * Given a set of conditions, fetch a revision from
229 * the given database connection.
231 * @param $db DatabaseBase
232 * @param $conditions Array
233 * @return Revision or null
235 private static function loadFromConds( $db, $conditions ) {
236 $res = Revision
::fetchFromConds( $db, $conditions );
238 $row = $res->fetchObject();
241 $ret = new Revision( $row );
250 * Return a wrapper for a series of database rows to
251 * fetch all of a given page's revisions in turn.
252 * Each row can be fed to the constructor to get objects.
254 * @param $title Title
255 * @return ResultWrapper
257 public static function fetchRevision( $title ) {
258 return Revision
::fetchFromConds(
260 array( 'rev_id=page_latest',
261 'page_namespace' => $title->getNamespace(),
262 'page_title' => $title->getDBkey(),
263 'page_id=rev_page' ) );
267 * Given a set of conditions, return a ResultWrapper
268 * which will return matching database rows with the
269 * fields necessary to build Revision objects.
271 * @param $db DatabaseBase
272 * @param $conditions Array
273 * @return ResultWrapper
275 private static function fetchFromConds( $db, $conditions ) {
276 $fields = self
::selectFields();
277 $fields[] = 'page_namespace';
278 $fields[] = 'page_title';
279 $fields[] = 'page_latest';
281 array( 'page', 'revision' ),
285 array( 'LIMIT' => 1 ) );
289 * Return the list of revision fields that should be selected to create
292 public static function selectFields() {
309 * Return the list of text fields that should be selected to read the
312 static function selectTextFields() {
320 * Return the list of page fields that should be selected from page table
322 static function selectPageFields() {
333 * @param $row Mixed: either a database row or an array
336 function __construct( $row ) {
337 if( is_object( $row ) ) {
338 $this->mId
= intval( $row->rev_id
);
339 $this->mPage
= intval( $row->rev_page
);
340 $this->mTextId
= intval( $row->rev_text_id
);
341 $this->mComment
= $row->rev_comment
;
342 $this->mUserText
= $row->rev_user_text
;
343 $this->mUser
= intval( $row->rev_user
);
344 $this->mMinorEdit
= intval( $row->rev_minor_edit
);
345 $this->mTimestamp
= $row->rev_timestamp
;
346 $this->mDeleted
= intval( $row->rev_deleted
);
348 if( !isset( $row->rev_parent_id
) ) {
349 $this->mParentId
= is_null($row->rev_parent_id
) ?
null : 0;
351 $this->mParentId
= intval( $row->rev_parent_id
);
354 if( !isset( $row->rev_len
) ||
is_null( $row->rev_len
) ) {
357 $this->mSize
= intval( $row->rev_len
);
360 if( isset( $row->page_latest
) ) {
361 $this->mCurrent
= ( $row->rev_id
== $row->page_latest
);
362 $this->mTitle
= Title
::newFromRow( $row );
364 $this->mCurrent
= false;
365 $this->mTitle
= null;
368 // Lazy extraction...
370 if( isset( $row->old_text
) ) {
371 $this->mTextRow
= $row;
373 // 'text' table row entry will be lazy-loaded
374 $this->mTextRow
= null;
376 } elseif( is_array( $row ) ) {
377 // Build a new revision to be saved...
380 $this->mId
= isset( $row['id'] ) ?
intval( $row['id'] ) : null;
381 $this->mPage
= isset( $row['page'] ) ?
intval( $row['page'] ) : null;
382 $this->mTextId
= isset( $row['text_id'] ) ?
intval( $row['text_id'] ) : null;
383 $this->mUserText
= isset( $row['user_text'] ) ?
strval( $row['user_text'] ) : $wgUser->getName();
384 $this->mUser
= isset( $row['user'] ) ?
intval( $row['user'] ) : $wgUser->getId();
385 $this->mMinorEdit
= isset( $row['minor_edit'] ) ?
intval( $row['minor_edit'] ) : 0;
386 $this->mTimestamp
= isset( $row['timestamp'] ) ?
strval( $row['timestamp'] ) : wfTimestamp( TS_MW
);
387 $this->mDeleted
= isset( $row['deleted'] ) ?
intval( $row['deleted'] ) : 0;
388 $this->mSize
= isset( $row['len'] ) ?
intval( $row['len'] ) : null;
389 $this->mParentId
= isset( $row['parent_id'] ) ?
intval( $row['parent_id'] ) : null;
391 // Enforce spacing trimming on supplied text
392 $this->mComment
= isset( $row['comment'] ) ?
trim( strval( $row['comment'] ) ) : null;
393 $this->mText
= isset( $row['text'] ) ?
rtrim( strval( $row['text'] ) ) : null;
394 $this->mTextRow
= null;
396 $this->mTitle
= null; # Load on demand if needed
397 $this->mCurrent
= false;
398 # If we still have no len_size, see it we have the text to figure it out
400 $this->mSize
= is_null( $this->mText
) ?
null : strlen( $this->mText
);
402 throw new MWException( 'Revision constructor passed invalid row format.' );
404 $this->mUnpatrolled
= null;
412 public function getId() {
421 public function getTextId() {
422 return $this->mTextId
;
426 * Get parent revision ID (the original previous page revision)
430 public function getParentId() {
431 return $this->mParentId
;
435 * Returns the length of the text in this revision, or null if unknown.
439 public function getSize() {
444 * Returns the title of the page associated with this entry.
448 public function getTitle() {
449 if( isset( $this->mTitle
) ) {
450 return $this->mTitle
;
452 $dbr = wfGetDB( DB_SLAVE
);
453 $row = $dbr->selectRow(
454 array( 'page', 'revision' ),
455 array( 'page_namespace', 'page_title' ),
456 array( 'page_id=rev_page',
457 'rev_id' => $this->mId
),
458 'Revision::getTitle' );
460 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
462 return $this->mTitle
;
466 * Set the title of the revision
468 * @param $title Title
470 public function setTitle( $title ) {
471 $this->mTitle
= $title;
479 public function getPage() {
484 * Fetch revision's user id if it's available to the specified audience.
485 * If the specified audience does not have access to it, zero will be
488 * @param $audience Integer: one of:
489 * Revision::FOR_PUBLIC to be displayed to all users
490 * Revision::FOR_THIS_USER to be displayed to $wgUser
491 * Revision::RAW get the ID regardless of permissions
496 public function getUser( $audience = self
::FOR_PUBLIC
) {
497 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
499 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
507 * Fetch revision's user id without regard for the current user's permissions
511 public function getRawUser() {
516 * Fetch revision's username if it's available to the specified audience.
517 * If the specified audience does not have access to the username, an
518 * empty string will be returned.
520 * @param $audience Integer: one of:
521 * Revision::FOR_PUBLIC to be displayed to all users
522 * Revision::FOR_THIS_USER to be displayed to $wgUser
523 * Revision::RAW get the text regardless of permissions
527 public function getUserText( $audience = self
::FOR_PUBLIC
) {
528 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
530 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
533 return $this->mUserText
;
538 * Fetch revision's username without regard for view restrictions
542 public function getRawUserText() {
543 return $this->mUserText
;
547 * Fetch revision comment if it's available to the specified audience.
548 * If the specified audience does not have access to the comment, an
549 * empty string will be returned.
551 * @param $audience Integer: one of:
552 * Revision::FOR_PUBLIC to be displayed to all users
553 * Revision::FOR_THIS_USER to be displayed to $wgUser
554 * Revision::RAW get the text regardless of permissions
558 function getComment( $audience = self
::FOR_PUBLIC
) {
559 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_COMMENT
) ) {
561 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_COMMENT
) ) {
564 return $this->mComment
;
569 * Fetch revision comment without regard for the current user's permissions
573 public function getRawComment() {
574 return $this->mComment
;
580 public function isMinor() {
581 return (bool)$this->mMinorEdit
;
585 * @return Integer rcid of the unpatrolled row, zero if there isn't one
587 public function isUnpatrolled() {
588 if( $this->mUnpatrolled
!== null ) {
589 return $this->mUnpatrolled
;
591 $dbr = wfGetDB( DB_SLAVE
);
592 $this->mUnpatrolled
= $dbr->selectField( 'recentchanges',
594 array( // Add redundant user,timestamp condition so we can use the existing index
595 'rc_user_text' => $this->getRawUserText(),
596 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
597 'rc_this_oldid' => $this->getId(),
602 return (int)$this->mUnpatrolled
;
606 * @param $field int one of DELETED_* bitfield constants
610 public function isDeleted( $field ) {
611 return ( $this->mDeleted
& $field ) == $field;
615 * Get the deletion bitfield of the revision
619 public function getVisibility() {
620 return (int)$this->mDeleted
;
624 * Fetch revision text if it's available to the specified audience.
625 * If the specified audience does not have the ability to view this
626 * revision, an empty string will be returned.
628 * @param $audience Integer: one of:
629 * Revision::FOR_PUBLIC to be displayed to all users
630 * Revision::FOR_THIS_USER to be displayed to $wgUser
631 * Revision::RAW get the text regardless of permissions
635 public function getText( $audience = self
::FOR_PUBLIC
) {
636 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_TEXT
) ) {
638 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_TEXT
) ) {
641 return $this->getRawText();
646 * Alias for getText(Revision::FOR_THIS_USER)
648 * @deprecated since 1.17
651 public function revText() {
652 wfDeprecated( __METHOD__
);
653 return $this->getText( self
::FOR_THIS_USER
);
657 * Fetch revision text without regard for view restrictions
661 public function getRawText() {
662 if( is_null( $this->mText
) ) {
663 // Revision text is immutable. Load on demand:
664 $this->mText
= $this->loadText();
672 public function getTimestamp() {
673 return wfTimestamp( TS_MW
, $this->mTimestamp
);
679 public function isCurrent() {
680 return $this->mCurrent
;
684 * Get previous revision for this title
686 * @return Revision or null
688 public function getPrevious() {
689 if( $this->getTitle() ) {
690 $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
692 return Revision
::newFromTitle( $this->getTitle(), $prev );
699 * Get next revision for this title
701 * @return Revision or null
703 public function getNext() {
704 if( $this->getTitle() ) {
705 $next = $this->getTitle()->getNextRevisionID( $this->getId() );
707 return Revision
::newFromTitle( $this->getTitle(), $next );
714 * Get previous revision Id for this page_id
715 * This is used to populate rev_parent_id on save
717 * @param $db DatabaseBase
720 private function getPreviousRevisionId( $db ) {
721 if( is_null( $this->mPage
) ) {
724 # Use page_latest if ID is not given
726 $prevId = $db->selectField( 'page', 'page_latest',
727 array( 'page_id' => $this->mPage
),
730 $prevId = $db->selectField( 'revision', 'rev_id',
731 array( 'rev_page' => $this->mPage
, 'rev_id < ' . $this->mId
),
733 array( 'ORDER BY' => 'rev_id DESC' ) );
735 return intval( $prevId );
739 * Get revision text associated with an old or archive row
740 * $row is usually an object from wfFetchRow(), both the flags and the text
741 * field must be included
743 * @param $row Object: the text data
744 * @param $prefix String: table prefix (default 'old_')
745 * @return String: text the text requested or false on failure
747 public static function getRevisionText( $row, $prefix = 'old_' ) {
748 wfProfileIn( __METHOD__
);
751 $textField = $prefix . 'text';
752 $flagsField = $prefix . 'flags';
754 if( isset( $row->$flagsField ) ) {
755 $flags = explode( ',', $row->$flagsField );
760 if( isset( $row->$textField ) ) {
761 $text = $row->$textField;
763 wfProfileOut( __METHOD__
);
767 # Use external methods for external objects, text in table is URL-only then
768 if ( in_array( 'external', $flags ) ) {
770 $parts = explode( '://', $url, 2 );
771 if( count( $parts ) == 1 ||
$parts[1] == '' ) {
772 wfProfileOut( __METHOD__
);
775 $text = ExternalStore
::fetchFromURL( $url );
778 // If the text was fetched without an error, convert it
779 if ( $text !== false ) {
780 if( in_array( 'gzip', $flags ) ) {
781 # Deal with optional compression of archived pages.
782 # This can be done periodically via maintenance/compressOld.php, and
783 # as pages are saved if $wgCompressRevisions is set.
784 $text = gzinflate( $text );
787 if( in_array( 'object', $flags ) ) {
788 # Generic compressed storage
789 $obj = unserialize( $text );
790 if ( !is_object( $obj ) ) {
792 wfProfileOut( __METHOD__
);
795 $text = $obj->getText();
798 global $wgLegacyEncoding;
799 if( $text !== false && $wgLegacyEncoding
800 && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) )
802 # Old revisions kept around in a legacy encoding?
803 # Upconvert on demand.
804 # ("utf8" checked for compatibility with some broken
805 # conversion scripts 2008-12-30)
807 $text = $wgContLang->iconv( $wgLegacyEncoding, 'UTF-8', $text );
810 wfProfileOut( __METHOD__
);
815 * If $wgCompressRevisions is enabled, we will compress data.
816 * The input string is modified in place.
817 * Return value is the flags field: contains 'gzip' if the
818 * data is compressed, and 'utf-8' if we're saving in UTF-8
821 * @param $text Mixed: reference to a text
824 public static function compressRevisionText( &$text ) {
825 global $wgCompressRevisions;
828 # Revisions not marked this way will be converted
829 # on load if $wgLegacyCharset is set in the future.
832 if( $wgCompressRevisions ) {
833 if( function_exists( 'gzdeflate' ) ) {
834 $text = gzdeflate( $text );
837 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
840 return implode( ',', $flags );
844 * Insert a new revision into the database, returning the new revision ID
845 * number on success and dies horribly on failure.
847 * @param $dbw DatabaseBase: (master connection)
850 public function insertOn( $dbw ) {
851 global $wgDefaultExternalStore;
853 wfProfileIn( __METHOD__
);
855 $data = $this->mText
;
856 $flags = Revision
::compressRevisionText( $data );
858 # Write to external storage if required
859 if( $wgDefaultExternalStore ) {
860 // Store and get the URL
861 $data = ExternalStore
::insertToDefault( $data );
863 throw new MWException( "Unable to store text to external storage" );
868 $flags .= 'external';
871 # Record the text (or external storage URL) to the text table
872 if( !isset( $this->mTextId
) ) {
873 $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
874 $dbw->insert( 'text',
878 'old_flags' => $flags,
881 $this->mTextId
= $dbw->insertId();
884 if ( $this->mComment
=== null ) $this->mComment
= "";
886 # Record the edit in revisions
887 $rev_id = isset( $this->mId
)
889 : $dbw->nextSequenceValue( 'revision_rev_id_seq' );
890 $dbw->insert( 'revision',
893 'rev_page' => $this->mPage
,
894 'rev_text_id' => $this->mTextId
,
895 'rev_comment' => $this->mComment
,
896 'rev_minor_edit' => $this->mMinorEdit ?
1 : 0,
897 'rev_user' => $this->mUser
,
898 'rev_user_text' => $this->mUserText
,
899 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp
),
900 'rev_deleted' => $this->mDeleted
,
901 'rev_len' => $this->mSize
,
902 'rev_parent_id' => is_null($this->mParentId
) ?
903 $this->getPreviousRevisionId( $dbw ) : $this->mParentId
907 $this->mId
= !is_null( $rev_id ) ?
$rev_id : $dbw->insertId();
909 wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
911 wfProfileOut( __METHOD__
);
916 * Lazy-load the revision's text.
917 * Currently hardcoded to the 'text' table storage engine.
921 protected function loadText() {
922 wfProfileIn( __METHOD__
);
924 // Caching may be beneficial for massive use of external storage
925 global $wgRevisionCacheExpiry, $wgMemc;
926 $textId = $this->getTextId();
927 $key = wfMemcKey( 'revisiontext', 'textid', $textId );
928 if( $wgRevisionCacheExpiry ) {
929 $text = $wgMemc->get( $key );
930 if( is_string( $text ) ) {
931 wfDebug( __METHOD__
. ": got id $textId from cache\n" );
932 wfProfileOut( __METHOD__
);
937 // If we kept data for lazy extraction, use it now...
938 if ( isset( $this->mTextRow
) ) {
939 $row = $this->mTextRow
;
940 $this->mTextRow
= null;
946 // Text data is immutable; check slaves first.
947 $dbr = wfGetDB( DB_SLAVE
);
948 $row = $dbr->selectRow( 'text',
949 array( 'old_text', 'old_flags' ),
950 array( 'old_id' => $this->getTextId() ),
954 if( !$row && wfGetLB()->getServerCount() > 1 ) {
955 // Possible slave lag!
956 $dbw = wfGetDB( DB_MASTER
);
957 $row = $dbw->selectRow( 'text',
958 array( 'old_text', 'old_flags' ),
959 array( 'old_id' => $this->getTextId() ),
963 $text = self
::getRevisionText( $row );
965 # No negative caching -- negative hits on text rows may be due to corrupted slave servers
966 if( $wgRevisionCacheExpiry && $text !== false ) {
967 $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
970 wfProfileOut( __METHOD__
);
976 * Create a new null-revision for insertion into a page's
977 * history. This will not re-save the text, but simply refer
978 * to the text from the previous version.
980 * Such revisions can for instance identify page rename
981 * operations and other such meta-modifications.
983 * @param $dbw DatabaseBase
984 * @param $pageId Integer: ID number of the page to read from
985 * @param $summary String: revision's summary
986 * @param $minor Boolean: whether the revision should be considered as minor
987 * @return Revision|null on error
989 public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
990 wfProfileIn( __METHOD__
);
992 $current = $dbw->selectRow(
993 array( 'page', 'revision' ),
994 array( 'page_latest', 'rev_text_id', 'rev_len' ),
996 'page_id' => $pageId,
997 'page_latest=rev_id',
1002 $revision = new Revision( array(
1004 'comment' => $summary,
1005 'minor_edit' => $minor,
1006 'text_id' => $current->rev_text_id
,
1007 'parent_id' => $current->page_latest
,
1008 'len' => $current->rev_len
1014 wfProfileOut( __METHOD__
);
1019 * Determine if the current user is allowed to view a particular
1020 * field of this revision, if it's marked as deleted.
1022 * @param $field Integer:one of self::DELETED_TEXT,
1023 * self::DELETED_COMMENT,
1024 * self::DELETED_USER
1027 public function userCan( $field ) {
1028 return self
::userCanBitfield( $this->mDeleted
, $field );
1032 * Determine if the current user is allowed to view a particular
1033 * field of this revision, if it's marked as deleted. This is used
1034 * by various classes to avoid duplication.
1036 * @param $bitfield Integer: current field
1037 * @param $field Integer: one of self::DELETED_TEXT = File::DELETED_FILE,
1038 * self::DELETED_COMMENT = File::DELETED_COMMENT,
1039 * self::DELETED_USER = File::DELETED_USER
1042 public static function userCanBitfield( $bitfield, $field ) {
1043 if( $bitfield & $field ) { // aspect is deleted
1045 if ( $bitfield & self
::DELETED_RESTRICTED
) {
1046 $permission = 'suppressrevision';
1047 } elseif ( $field & self
::DELETED_TEXT
) {
1048 $permission = 'deletedtext';
1050 $permission = 'deletedhistory';
1052 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
1053 return $wgUser->isAllowed( $permission );
1060 * Get rev_timestamp from rev_id, without loading the rest of the row
1062 * @param $title Title
1063 * @param $id Integer
1066 static function getTimestampFromId( $title, $id ) {
1067 $dbr = wfGetDB( DB_SLAVE
);
1068 // Casting fix for DB2
1072 $conds = array( 'rev_id' => $id );
1073 $conds['rev_page'] = $title->getArticleId();
1074 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1075 if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
1076 # Not in slave, try master
1077 $dbw = wfGetDB( DB_MASTER
);
1078 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1080 return wfTimestamp( TS_MW
, $timestamp );
1084 * Get count of revisions per page...not very efficient
1086 * @param $db DatabaseBase
1087 * @param $id Integer: page id
1090 static function countByPageId( $db, $id ) {
1091 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
1092 array( 'rev_page' => $id ), __METHOD__
);
1094 return $row->revCount
;
1100 * Get count of revisions per page...not very efficient
1102 * @param $db DatabaseBase
1103 * @param $title Title
1106 static function countByTitle( $db, $title ) {
1107 $id = $title->getArticleId();
1109 return Revision
::countByPageId( $db, $id );