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.
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 // Page does not exist
56 $conds['rev_id'] = $latest;
58 // Use a join to get the latest revision
59 $conds[] = 'rev_id=page_latest';
61 $conds[] = 'page_id=rev_page';
62 return Revision
::newFromConds( $conds );
66 * Make a fake revision object from an archive table row. This is queried
67 * for permissions or even inserted (as in Special:Undelete)
68 * @todo FIXME: Should be a subclass for RevisionDelete. [TS]
71 * @param $overrides array
75 public static function newFromArchiveRow( $row, $overrides = array() ) {
76 $attribs = $overrides +
array(
77 'page' => isset( $row->page_id
) ?
$row->page_id
: null,
78 'id' => isset( $row->ar_rev_id
) ?
$row->ar_rev_id
: null,
79 'comment' => $row->ar_comment
,
80 'user' => $row->ar_user
,
81 'user_text' => $row->ar_user_text
,
82 'timestamp' => $row->ar_timestamp
,
83 'minor_edit' => $row->ar_minor_edit
,
84 'text_id' => isset( $row->ar_text_id
) ?
$row->ar_text_id
: null,
85 'deleted' => $row->ar_deleted
,
86 'len' => $row->ar_len
);
87 if ( isset( $row->ar_text
) && !$row->ar_text_id
) {
88 // Pre-1.5 ar_text row
89 $attribs['text'] = self
::getRevisionText( $row, 'ar_' );
90 if ( $attribs['text'] === false ) {
91 throw new MWException( 'Unable to load text from archive row (possibly bug 22624)' );
94 return new self( $attribs );
98 * Load a page revision from a given revision ID number.
99 * Returns null if no such revision can be found.
101 * @param $db DatabaseBase
103 * @return Revision or null
105 public static function loadFromId( $db, $id ) {
106 return Revision
::loadFromConds( $db,
107 array( 'page_id=rev_page',
108 'rev_id' => intval( $id ) ) );
112 * Load either the current, or a specified, revision
113 * that's attached to a given page. If not attached
114 * to that page, will return null.
116 * @param $db DatabaseBase
117 * @param $pageid Integer
119 * @return Revision or null
121 public static function loadFromPageId( $db, $pageid, $id = 0 ) {
122 $conds = array( 'page_id=rev_page','rev_page' => intval( $pageid ), 'page_id'=>intval( $pageid ) );
124 $conds['rev_id'] = intval( $id );
126 $conds[] = 'rev_id=page_latest';
128 return Revision
::loadFromConds( $db, $conds );
132 * Load either the current, or a specified, revision
133 * that's attached to a given page. If not attached
134 * to that page, will return null.
136 * @param $db DatabaseBase
137 * @param $title Title
139 * @return Revision or null
141 public static function loadFromTitle( $db, $title, $id = 0 ) {
143 $matchId = intval( $id );
145 $matchId = 'page_latest';
147 return Revision
::loadFromConds(
149 array( "rev_id=$matchId",
151 'page_namespace' => $title->getNamespace(),
152 'page_title' => $title->getDBkey() ) );
156 * Load the revision for the given title with the given timestamp.
157 * WARNING: Timestamps may in some circumstances not be unique,
158 * so this isn't the best key to use.
160 * @param $db DatabaseBase
161 * @param $title Title
162 * @param $timestamp String
163 * @return Revision or null
165 public static function loadFromTimestamp( $db, $title, $timestamp ) {
166 return Revision
::loadFromConds(
168 array( 'rev_timestamp' => $db->timestamp( $timestamp ),
170 'page_namespace' => $title->getNamespace(),
171 'page_title' => $title->getDBkey() ) );
175 * Given a set of conditions, fetch a revision.
177 * @param $conditions Array
178 * @return Revision or null
180 public static function newFromConds( $conditions ) {
181 $db = wfGetDB( DB_SLAVE
);
182 $row = Revision
::loadFromConds( $db, $conditions );
183 if( is_null( $row ) && wfGetLB()->getServerCount() > 1 ) {
184 $dbw = wfGetDB( DB_MASTER
);
185 $row = Revision
::loadFromConds( $dbw, $conditions );
191 * Given a set of conditions, fetch a revision from
192 * the given database connection.
194 * @param $db DatabaseBase
195 * @param $conditions Array
196 * @return Revision or null
198 private static function loadFromConds( $db, $conditions ) {
199 $res = Revision
::fetchFromConds( $db, $conditions );
201 $row = $res->fetchObject();
204 $ret = new Revision( $row );
213 * Return a wrapper for a series of database rows to
214 * fetch all of a given page's revisions in turn.
215 * Each row can be fed to the constructor to get objects.
217 * @param $title Title
218 * @return ResultWrapper
220 public static function fetchRevision( $title ) {
221 return Revision
::fetchFromConds(
223 array( 'rev_id=page_latest',
224 'page_namespace' => $title->getNamespace(),
225 'page_title' => $title->getDBkey(),
226 'page_id=rev_page' ) );
230 * Given a set of conditions, return a ResultWrapper
231 * which will return matching database rows with the
232 * fields necessary to build Revision objects.
234 * @param $db DatabaseBase
235 * @param $conditions Array
236 * @return ResultWrapper
238 private static function fetchFromConds( $db, $conditions ) {
239 $fields = self
::selectFields();
240 $fields[] = 'page_namespace';
241 $fields[] = 'page_title';
242 $fields[] = 'page_latest';
244 array( 'page', 'revision' ),
248 array( 'LIMIT' => 1 ) );
249 $ret = $db->resultObject( $res );
254 * Return the list of revision fields that should be selected to create
257 public static function selectFields() {
274 * Return the list of text fields that should be selected to read the
277 static function selectTextFields() {
285 * Return the list of page fields that should be selected from page table
287 static function selectPageFields() {
298 * @param $row Mixed: either a database row or an array
301 function __construct( $row ) {
302 if( is_object( $row ) ) {
303 $this->mId
= intval( $row->rev_id
);
304 $this->mPage
= intval( $row->rev_page
);
305 $this->mTextId
= intval( $row->rev_text_id
);
306 $this->mComment
= $row->rev_comment
;
307 $this->mUserText
= $row->rev_user_text
;
308 $this->mUser
= intval( $row->rev_user
);
309 $this->mMinorEdit
= intval( $row->rev_minor_edit
);
310 $this->mTimestamp
= $row->rev_timestamp
;
311 $this->mDeleted
= intval( $row->rev_deleted
);
313 if( !isset( $row->rev_parent_id
) )
314 $this->mParentId
= is_null($row->rev_parent_id
) ?
null : 0;
316 $this->mParentId
= intval( $row->rev_parent_id
);
318 if( !isset( $row->rev_len
) ||
is_null( $row->rev_len
) )
321 $this->mSize
= intval( $row->rev_len
);
323 if( isset( $row->page_latest
) ) {
324 $this->mCurrent
= ( $row->rev_id
== $row->page_latest
);
325 $this->mTitle
= Title
::newFromRow( $row );
327 $this->mCurrent
= false;
328 $this->mTitle
= null;
331 // Lazy extraction...
333 if( isset( $row->old_text
) ) {
334 $this->mTextRow
= $row;
336 // 'text' table row entry will be lazy-loaded
337 $this->mTextRow
= null;
339 } elseif( is_array( $row ) ) {
340 // Build a new revision to be saved...
343 $this->mId
= isset( $row['id'] ) ?
intval( $row['id'] ) : null;
344 $this->mPage
= isset( $row['page'] ) ?
intval( $row['page'] ) : null;
345 $this->mTextId
= isset( $row['text_id'] ) ?
intval( $row['text_id'] ) : null;
346 $this->mUserText
= isset( $row['user_text'] ) ?
strval( $row['user_text'] ) : $wgUser->getName();
347 $this->mUser
= isset( $row['user'] ) ?
intval( $row['user'] ) : $wgUser->getId();
348 $this->mMinorEdit
= isset( $row['minor_edit'] ) ?
intval( $row['minor_edit'] ) : 0;
349 $this->mTimestamp
= isset( $row['timestamp'] ) ?
strval( $row['timestamp'] ) : wfTimestamp( TS_MW
);
350 $this->mDeleted
= isset( $row['deleted'] ) ?
intval( $row['deleted'] ) : 0;
351 $this->mSize
= isset( $row['len'] ) ?
intval( $row['len'] ) : null;
352 $this->mParentId
= isset( $row['parent_id'] ) ?
intval( $row['parent_id'] ) : null;
354 // Enforce spacing trimming on supplied text
355 $this->mComment
= isset( $row['comment'] ) ?
trim( strval( $row['comment'] ) ) : null;
356 $this->mText
= isset( $row['text'] ) ?
rtrim( strval( $row['text'] ) ) : null;
357 $this->mTextRow
= null;
359 $this->mTitle
= null; # Load on demand if needed
360 $this->mCurrent
= false;
361 # If we still have no len_size, see it we have the text to figure it out
363 $this->mSize
= is_null( $this->mText
) ?
null : strlen( $this->mText
);
365 throw new MWException( 'Revision constructor passed invalid row format.' );
367 $this->mUnpatrolled
= null;
375 public function getId() {
384 public function getTextId() {
385 return $this->mTextId
;
389 * Get parent revision ID (the original previous page revision)
393 public function getParentId() {
394 return $this->mParentId
;
398 * Returns the length of the text in this revision, or null if unknown.
402 public function getSize() {
407 * Returns the title of the page associated with this entry.
411 public function getTitle() {
412 if( isset( $this->mTitle
) ) {
413 return $this->mTitle
;
415 $dbr = wfGetDB( DB_SLAVE
);
416 $row = $dbr->selectRow(
417 array( 'page', 'revision' ),
418 array( 'page_namespace', 'page_title' ),
419 array( 'page_id=rev_page',
420 'rev_id' => $this->mId
),
421 'Revision::getTitle' );
423 $this->mTitle
= Title
::makeTitle( $row->page_namespace
,
426 return $this->mTitle
;
430 * Set the title of the revision
432 * @param $title Title
434 public function setTitle( $title ) {
435 $this->mTitle
= $title;
443 public function getPage() {
448 * Fetch revision's user id if it's available to the specified audience.
449 * If the specified audience does not have access to it, zero will be
452 * @param $audience Integer: one of:
453 * Revision::FOR_PUBLIC to be displayed to all users
454 * Revision::FOR_THIS_USER to be displayed to $wgUser
455 * Revision::RAW get the ID regardless of permissions
460 public function getUser( $audience = self
::FOR_PUBLIC
) {
461 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
463 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
471 * Fetch revision's user id without regard for the current user's permissions
475 public function getRawUser() {
480 * Fetch revision's username if it's available to the specified audience.
481 * If the specified audience does not have access to the username, an
482 * empty string will be returned.
484 * @param $audience Integer: one of:
485 * Revision::FOR_PUBLIC to be displayed to all users
486 * Revision::FOR_THIS_USER to be displayed to $wgUser
487 * Revision::RAW get the text regardless of permissions
491 public function getUserText( $audience = self
::FOR_PUBLIC
) {
492 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
494 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
497 return $this->mUserText
;
502 * Fetch revision's username without regard for view restrictions
506 public function getRawUserText() {
507 return $this->mUserText
;
511 * Fetch revision comment if it's available to the specified audience.
512 * If the specified audience does not have access to the comment, an
513 * empty string will be returned.
515 * @param $audience Integer: one of:
516 * Revision::FOR_PUBLIC to be displayed to all users
517 * Revision::FOR_THIS_USER to be displayed to $wgUser
518 * Revision::RAW get the text regardless of permissions
522 function getComment( $audience = self
::FOR_PUBLIC
) {
523 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_COMMENT
) ) {
525 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_COMMENT
) ) {
528 return $this->mComment
;
533 * Fetch revision comment without regard for the current user's permissions
537 public function getRawComment() {
538 return $this->mComment
;
544 public function isMinor() {
545 return (bool)$this->mMinorEdit
;
549 * @return Integer rcid of the unpatrolled row, zero if there isn't one
551 public function isUnpatrolled() {
552 if( $this->mUnpatrolled
!== null ) {
553 return $this->mUnpatrolled
;
555 $dbr = wfGetDB( DB_SLAVE
);
556 $this->mUnpatrolled
= $dbr->selectField( 'recentchanges',
558 array( // Add redundant user,timestamp condition so we can use the existing index
559 'rc_user_text' => $this->getRawUserText(),
560 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
561 'rc_this_oldid' => $this->getId(),
566 return (int)$this->mUnpatrolled
;
570 * int $field one of DELETED_* bitfield constants
574 public function isDeleted( $field ) {
575 return ( $this->mDeleted
& $field ) == $field;
579 * Get the deletion bitfield of the revision
581 public function getVisibility() {
582 return (int)$this->mDeleted
;
586 * Fetch revision text if it's available to the specified audience.
587 * If the specified audience does not have the ability to view this
588 * revision, an empty string will be returned.
590 * @param $audience Integer: one of:
591 * Revision::FOR_PUBLIC to be displayed to all users
592 * Revision::FOR_THIS_USER to be displayed to $wgUser
593 * Revision::RAW get the text regardless of permissions
597 public function getText( $audience = self
::FOR_PUBLIC
) {
598 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_TEXT
) ) {
600 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_TEXT
) ) {
603 return $this->getRawText();
608 * Alias for getText(Revision::FOR_THIS_USER)
610 * @deprecated since 1.17
613 public function revText() {
614 wfDeprecated( __METHOD__
);
615 return $this->getText( self
::FOR_THIS_USER
);
619 * Fetch revision text without regard for view restrictions
623 public function getRawText() {
624 if( is_null( $this->mText
) ) {
625 // Revision text is immutable. Load on demand:
626 $this->mText
= $this->loadText();
634 public function getTimestamp() {
635 return wfTimestamp( TS_MW
, $this->mTimestamp
);
641 public function isCurrent() {
642 return $this->mCurrent
;
646 * Get previous revision for this title
648 * @return Revision or null
650 public function getPrevious() {
651 if( $this->getTitle() ) {
652 $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
654 return Revision
::newFromTitle( $this->getTitle(), $prev );
661 * Get next revision for this title
663 * @return Revision or null
665 public function getNext() {
666 if( $this->getTitle() ) {
667 $next = $this->getTitle()->getNextRevisionID( $this->getId() );
669 return Revision
::newFromTitle( $this->getTitle(), $next );
676 * Get previous revision Id for this page_id
677 * This is used to populate rev_parent_id on save
679 * @param $db DatabaseBase
682 private function getPreviousRevisionId( $db ) {
683 if( is_null( $this->mPage
) ) {
686 # Use page_latest if ID is not given
688 $prevId = $db->selectField( 'page', 'page_latest',
689 array( 'page_id' => $this->mPage
),
692 $prevId = $db->selectField( 'revision', 'rev_id',
693 array( 'rev_page' => $this->mPage
, 'rev_id < ' . $this->mId
),
695 array( 'ORDER BY' => 'rev_id DESC' ) );
697 return intval( $prevId );
701 * Get revision text associated with an old or archive row
702 * $row is usually an object from wfFetchRow(), both the flags and the text
703 * field must be included
705 * @param $row Object: the text data
706 * @param $prefix String: table prefix (default 'old_')
707 * @return String: text the text requested or false on failure
709 public static function getRevisionText( $row, $prefix = 'old_' ) {
710 wfProfileIn( __METHOD__
);
713 $textField = $prefix . 'text';
714 $flagsField = $prefix . 'flags';
716 if( isset( $row->$flagsField ) ) {
717 $flags = explode( ',', $row->$flagsField );
722 if( isset( $row->$textField ) ) {
723 $text = $row->$textField;
725 wfProfileOut( __METHOD__
);
729 # Use external methods for external objects, text in table is URL-only then
730 if ( in_array( 'external', $flags ) ) {
732 @list
(/* $proto */, $path ) = explode( '://', $url, 2 );
734 wfProfileOut( __METHOD__
);
737 $text = ExternalStore
::fetchFromURL( $url );
740 // If the text was fetched without an error, convert it
741 if ( $text !== false ) {
742 if( in_array( 'gzip', $flags ) ) {
743 # Deal with optional compression of archived pages.
744 # This can be done periodically via maintenance/compressOld.php, and
745 # as pages are saved if $wgCompressRevisions is set.
746 $text = gzinflate( $text );
749 if( in_array( 'object', $flags ) ) {
750 # Generic compressed storage
751 $obj = unserialize( $text );
752 if ( !is_object( $obj ) ) {
754 wfProfileOut( __METHOD__
);
757 $text = $obj->getText();
760 global $wgLegacyEncoding;
761 if( $text !== false && $wgLegacyEncoding
762 && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) )
764 # Old revisions kept around in a legacy encoding?
765 # Upconvert on demand.
766 # ("utf8" checked for compatibility with some broken
767 # conversion scripts 2008-12-30)
769 $text = $wgContLang->iconv( $wgLegacyEncoding, 'UTF-8', $text );
772 wfProfileOut( __METHOD__
);
777 * If $wgCompressRevisions is enabled, we will compress data.
778 * The input string is modified in place.
779 * Return value is the flags field: contains 'gzip' if the
780 * data is compressed, and 'utf-8' if we're saving in UTF-8
783 * @param $text Mixed: reference to a text
786 public static function compressRevisionText( &$text ) {
787 global $wgCompressRevisions;
790 # Revisions not marked this way will be converted
791 # on load if $wgLegacyCharset is set in the future.
794 if( $wgCompressRevisions ) {
795 if( function_exists( 'gzdeflate' ) ) {
796 $text = gzdeflate( $text );
799 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
802 return implode( ',', $flags );
806 * Insert a new revision into the database, returning the new revision ID
807 * number on success and dies horribly on failure.
809 * @param $dbw DatabaseBase: (master connection)
812 public function insertOn( $dbw ) {
813 global $wgDefaultExternalStore;
815 wfProfileIn( __METHOD__
);
817 $data = $this->mText
;
818 $flags = Revision
::compressRevisionText( $data );
820 # Write to external storage if required
821 if( $wgDefaultExternalStore ) {
822 // Store and get the URL
823 $data = ExternalStore
::insertToDefault( $data );
825 throw new MWException( "Unable to store text to external storage" );
830 $flags .= 'external';
833 # Record the text (or external storage URL) to the text table
834 if( !isset( $this->mTextId
) ) {
835 $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
836 $dbw->insert( 'text',
840 'old_flags' => $flags,
843 $this->mTextId
= $dbw->insertId();
846 if ( $this->mComment
=== null ) $this->mComment
= "";
848 # Record the edit in revisions
849 $rev_id = isset( $this->mId
)
851 : $dbw->nextSequenceValue( 'revision_rev_id_seq' );
852 $dbw->insert( 'revision',
855 'rev_page' => $this->mPage
,
856 'rev_text_id' => $this->mTextId
,
857 'rev_comment' => $this->mComment
,
858 'rev_minor_edit' => $this->mMinorEdit ?
1 : 0,
859 'rev_user' => $this->mUser
,
860 'rev_user_text' => $this->mUserText
,
861 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp
),
862 'rev_deleted' => $this->mDeleted
,
863 'rev_len' => $this->mSize
,
864 'rev_parent_id' => is_null($this->mParentId
) ?
865 $this->getPreviousRevisionId( $dbw ) : $this->mParentId
869 $this->mId
= !is_null( $rev_id ) ?
$rev_id : $dbw->insertId();
871 wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
873 wfProfileOut( __METHOD__
);
878 * Lazy-load the revision's text.
879 * Currently hardcoded to the 'text' table storage engine.
883 protected function loadText() {
884 wfProfileIn( __METHOD__
);
886 // Caching may be beneficial for massive use of external storage
887 global $wgRevisionCacheExpiry, $wgMemc;
888 $textId = $this->getTextId();
889 $key = wfMemcKey( 'revisiontext', 'textid', $textId );
890 if( $wgRevisionCacheExpiry ) {
891 $text = $wgMemc->get( $key );
892 if( is_string( $text ) ) {
893 wfDebug( __METHOD__
. ": got id $textId from cache\n" );
894 wfProfileOut( __METHOD__
);
899 // If we kept data for lazy extraction, use it now...
900 if ( isset( $this->mTextRow
) ) {
901 $row = $this->mTextRow
;
902 $this->mTextRow
= null;
908 // Text data is immutable; check slaves first.
909 $dbr = wfGetDB( DB_SLAVE
);
910 $row = $dbr->selectRow( 'text',
911 array( 'old_text', 'old_flags' ),
912 array( 'old_id' => $this->getTextId() ),
916 if( !$row && wfGetLB()->getServerCount() > 1 ) {
917 // Possible slave lag!
918 $dbw = wfGetDB( DB_MASTER
);
919 $row = $dbw->selectRow( 'text',
920 array( 'old_text', 'old_flags' ),
921 array( 'old_id' => $this->getTextId() ),
925 $text = self
::getRevisionText( $row );
927 # No negative caching -- negative hits on text rows may be due to corrupted slave servers
928 if( $wgRevisionCacheExpiry && $text !== false ) {
929 $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
932 wfProfileOut( __METHOD__
);
938 * Create a new null-revision for insertion into a page's
939 * history. This will not re-save the text, but simply refer
940 * to the text from the previous version.
942 * Such revisions can for instance identify page rename
943 * operations and other such meta-modifications.
945 * @param $dbw DatabaseBase
946 * @param $pageId Integer: ID number of the page to read from
947 * @param $summary String: revision's summary
948 * @param $minor Boolean: whether the revision should be considered as minor
949 * @return Revision|null on error
951 public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
952 wfProfileIn( __METHOD__
);
954 $current = $dbw->selectRow(
955 array( 'page', 'revision' ),
956 array( 'page_latest', 'rev_text_id', 'rev_len' ),
958 'page_id' => $pageId,
959 'page_latest=rev_id',
964 $revision = new Revision( array(
966 'comment' => $summary,
967 'minor_edit' => $minor,
968 'text_id' => $current->rev_text_id
,
969 'parent_id' => $current->page_latest
,
970 'len' => $current->rev_len
976 wfProfileOut( __METHOD__
);
981 * Determine if the current user is allowed to view a particular
982 * field of this revision, if it's marked as deleted.
984 * @param $field Integer:one of self::DELETED_TEXT,
985 * self::DELETED_COMMENT,
989 public function userCan( $field ) {
990 return self
::userCanBitfield( $this->mDeleted
, $field );
994 * Determine if the current user is allowed to view a particular
995 * field of this revision, if it's marked as deleted. This is used
996 * by various classes to avoid duplication.
998 * @param $bitfield Integer: current field
999 * @param $field Integer: one of self::DELETED_TEXT = File::DELETED_FILE,
1000 * self::DELETED_COMMENT = File::DELETED_COMMENT,
1001 * self::DELETED_USER = File::DELETED_USER
1004 public static function userCanBitfield( $bitfield, $field ) {
1005 if( $bitfield & $field ) { // aspect is deleted
1007 if ( $bitfield & self
::DELETED_RESTRICTED
) {
1008 $permission = 'suppressrevision';
1009 } elseif ( $field & self
::DELETED_TEXT
) {
1010 $permission = 'deletedtext';
1012 $permission = 'deletedhistory';
1014 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
1015 return $wgUser->isAllowed( $permission );
1022 * Get rev_timestamp from rev_id, without loading the rest of the row
1024 * @param $title Title
1025 * @param $id Integer
1028 static function getTimestampFromId( $title, $id ) {
1029 $dbr = wfGetDB( DB_SLAVE
);
1030 // Casting fix for DB2
1034 $conds = array( 'rev_id' => $id );
1035 $conds['rev_page'] = $title->getArticleId();
1036 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1037 if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
1038 # Not in slave, try master
1039 $dbw = wfGetDB( DB_MASTER
);
1040 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1042 return wfTimestamp( TS_MW
, $timestamp );
1046 * Get count of revisions per page...not very efficient
1048 * @param $db DatabaseBase
1049 * @param $id Integer: page id
1052 static function countByPageId( $db, $id ) {
1053 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
1054 array( 'rev_page' => $id ), __METHOD__
);
1056 return $row->revCount
;
1062 * Get count of revisions per page...not very efficient
1064 * @param $db DatabaseBase
1065 * @param $title Title
1068 static function countByTitle( $db, $title ) {
1069 $id = $title->getArticleId();
1071 return Revision
::countByPageId( $db, $id );
1078 * Aliases for backwards compatibility with 1.6
1080 define( 'MW_REV_DELETED_TEXT', Revision
::DELETED_TEXT
);
1081 define( 'MW_REV_DELETED_COMMENT', Revision
::DELETED_COMMENT
);
1082 define( 'MW_REV_DELETED_USER', Revision
::DELETED_USER
);
1083 define( 'MW_REV_DELETED_RESTRICTED', Revision
::DELETED_RESTRICTED
);