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]
70 public static function newFromArchiveRow( $row, $overrides = array() ) {
71 $attribs = $overrides +
array(
72 'page' => isset( $row->page_id
) ?
$row->page_id
: null,
73 'id' => isset( $row->ar_rev_id
) ?
$row->ar_rev_id
: null,
74 'comment' => $row->ar_comment
,
75 'user' => $row->ar_user
,
76 'user_text' => $row->ar_user_text
,
77 'timestamp' => $row->ar_timestamp
,
78 'minor_edit' => $row->ar_minor_edit
,
79 'text_id' => isset( $row->ar_text_id
) ?
$row->ar_text_id
: null,
80 'deleted' => $row->ar_deleted
,
81 'len' => $row->ar_len
);
82 if ( isset( $row->ar_text
) && !$row->ar_text_id
) {
83 // Pre-1.5 ar_text row
84 $attribs['text'] = self
::getRevisionText( $row, 'ar_' );
85 if ( $attribs['text'] === false ) {
86 throw new MWException( 'Unable to load text from archive row (possibly bug 22624)' );
89 return new self( $attribs );
93 * Load a page revision from a given revision ID number.
94 * Returns null if no such revision can be found.
96 * @param $db DatabaseBase
98 * @return Revision or null
100 public static function loadFromId( $db, $id ) {
101 return Revision
::loadFromConds( $db,
102 array( 'page_id=rev_page',
103 'rev_id' => intval( $id ) ) );
107 * Load either the current, or a specified, revision
108 * that's attached to a given page. If not attached
109 * to that page, will return null.
111 * @param $db DatabaseBase
112 * @param $pageid Integer
114 * @return Revision or null
116 public static function loadFromPageId( $db, $pageid, $id = 0 ) {
117 $conds = array( 'page_id=rev_page','rev_page' => intval( $pageid ), 'page_id'=>intval( $pageid ) );
119 $conds['rev_id'] = intval( $id );
121 $conds[] = 'rev_id=page_latest';
123 return Revision
::loadFromConds( $db, $conds );
127 * Load either the current, or a specified, revision
128 * that's attached to a given page. If not attached
129 * to that page, will return null.
131 * @param $db DatabaseBase
132 * @param $title Title
134 * @return Revision or null
136 public static function loadFromTitle( $db, $title, $id = 0 ) {
138 $matchId = intval( $id );
140 $matchId = 'page_latest';
142 return Revision
::loadFromConds(
144 array( "rev_id=$matchId",
146 'page_namespace' => $title->getNamespace(),
147 'page_title' => $title->getDBkey() ) );
151 * Load the revision for the given title with the given timestamp.
152 * WARNING: Timestamps may in some circumstances not be unique,
153 * so this isn't the best key to use.
155 * @param $db DatabaseBase
156 * @param $title Title
157 * @param $timestamp String
158 * @return Revision or null
160 public static function loadFromTimestamp( $db, $title, $timestamp ) {
161 return Revision
::loadFromConds(
163 array( 'rev_timestamp' => $db->timestamp( $timestamp ),
165 'page_namespace' => $title->getNamespace(),
166 'page_title' => $title->getDBkey() ) );
170 * Given a set of conditions, fetch a revision.
172 * @param $conditions Array
173 * @return Revision or null
175 public static function newFromConds( $conditions ) {
176 $db = wfGetDB( DB_SLAVE
);
177 $row = Revision
::loadFromConds( $db, $conditions );
178 if( is_null( $row ) && wfGetLB()->getServerCount() > 1 ) {
179 $dbw = wfGetDB( DB_MASTER
);
180 $row = Revision
::loadFromConds( $dbw, $conditions );
186 * Given a set of conditions, fetch a revision from
187 * the given database connection.
189 * @param $db Database
190 * @param $conditions Array
191 * @return Revision or null
193 private static function loadFromConds( $db, $conditions ) {
194 $res = Revision
::fetchFromConds( $db, $conditions );
196 $row = $res->fetchObject();
199 $ret = new Revision( $row );
208 * Return a wrapper for a series of database rows to
209 * fetch all of a given page's revisions in turn.
210 * Each row can be fed to the constructor to get objects.
212 * @param $title Title
213 * @return ResultWrapper
215 public static function fetchRevision( $title ) {
216 return Revision
::fetchFromConds(
218 array( 'rev_id=page_latest',
219 'page_namespace' => $title->getNamespace(),
220 'page_title' => $title->getDBkey(),
221 'page_id=rev_page' ) );
225 * Given a set of conditions, return a ResultWrapper
226 * which will return matching database rows with the
227 * fields necessary to build Revision objects.
229 * @param $db Database
230 * @param $conditions Array
231 * @return ResultWrapper
233 private static function fetchFromConds( $db, $conditions ) {
234 $fields = self
::selectFields();
235 $fields[] = 'page_namespace';
236 $fields[] = 'page_title';
237 $fields[] = 'page_latest';
239 array( 'page', 'revision' ),
243 array( 'LIMIT' => 1 ) );
244 $ret = $db->resultObject( $res );
249 * Return the list of revision fields that should be selected to create
252 public static function selectFields() {
269 * Return the list of text fields that should be selected to read the
272 static function selectTextFields() {
280 * Return the list of page fields that should be selected from page table
282 static function selectPageFields() {
293 * @param $row Mixed: either a database row or an array
296 function __construct( $row ) {
297 if( is_object( $row ) ) {
298 $this->mId
= intval( $row->rev_id
);
299 $this->mPage
= intval( $row->rev_page
);
300 $this->mTextId
= intval( $row->rev_text_id
);
301 $this->mComment
= $row->rev_comment
;
302 $this->mUserText
= $row->rev_user_text
;
303 $this->mUser
= intval( $row->rev_user
);
304 $this->mMinorEdit
= intval( $row->rev_minor_edit
);
305 $this->mTimestamp
= $row->rev_timestamp
;
306 $this->mDeleted
= intval( $row->rev_deleted
);
308 if( !isset( $row->rev_parent_id
) )
309 $this->mParentId
= is_null($row->rev_parent_id
) ?
null : 0;
311 $this->mParentId
= intval( $row->rev_parent_id
);
313 if( !isset( $row->rev_len
) ||
is_null( $row->rev_len
) )
316 $this->mSize
= intval( $row->rev_len
);
318 if( isset( $row->page_latest
) ) {
319 $this->mCurrent
= ( $row->rev_id
== $row->page_latest
);
320 $this->mTitle
= Title
::newFromRow( $row );
322 $this->mCurrent
= false;
323 $this->mTitle
= null;
326 // Lazy extraction...
328 if( isset( $row->old_text
) ) {
329 $this->mTextRow
= $row;
331 // 'text' table row entry will be lazy-loaded
332 $this->mTextRow
= null;
334 } elseif( is_array( $row ) ) {
335 // Build a new revision to be saved...
338 $this->mId
= isset( $row['id'] ) ?
intval( $row['id'] ) : null;
339 $this->mPage
= isset( $row['page'] ) ?
intval( $row['page'] ) : null;
340 $this->mTextId
= isset( $row['text_id'] ) ?
intval( $row['text_id'] ) : null;
341 $this->mUserText
= isset( $row['user_text'] ) ?
strval( $row['user_text'] ) : $wgUser->getName();
342 $this->mUser
= isset( $row['user'] ) ?
intval( $row['user'] ) : $wgUser->getId();
343 $this->mMinorEdit
= isset( $row['minor_edit'] ) ?
intval( $row['minor_edit'] ) : 0;
344 $this->mTimestamp
= isset( $row['timestamp'] ) ?
strval( $row['timestamp'] ) : wfTimestamp( TS_MW
);
345 $this->mDeleted
= isset( $row['deleted'] ) ?
intval( $row['deleted'] ) : 0;
346 $this->mSize
= isset( $row['len'] ) ?
intval( $row['len'] ) : null;
347 $this->mParentId
= isset( $row['parent_id'] ) ?
intval( $row['parent_id'] ) : null;
349 // Enforce spacing trimming on supplied text
350 $this->mComment
= isset( $row['comment'] ) ?
trim( strval( $row['comment'] ) ) : null;
351 $this->mText
= isset( $row['text'] ) ?
rtrim( strval( $row['text'] ) ) : null;
352 $this->mTextRow
= null;
354 $this->mTitle
= null; # Load on demand if needed
355 $this->mCurrent
= false;
356 # If we still have no len_size, see it we have the text to figure it out
358 $this->mSize
= is_null( $this->mText
) ?
null : strlen( $this->mText
);
360 throw new MWException( 'Revision constructor passed invalid row format.' );
362 $this->mUnpatrolled
= null;
370 public function getId() {
379 public function getTextId() {
380 return $this->mTextId
;
384 * Get parent revision ID (the original previous page revision)
388 public function getParentId() {
389 return $this->mParentId
;
393 * Returns the length of the text in this revision, or null if unknown.
397 public function getSize() {
402 * Returns the title of the page associated with this entry.
406 public function getTitle() {
407 if( isset( $this->mTitle
) ) {
408 return $this->mTitle
;
410 $dbr = wfGetDB( DB_SLAVE
);
411 $row = $dbr->selectRow(
412 array( 'page', 'revision' ),
413 array( 'page_namespace', 'page_title' ),
414 array( 'page_id=rev_page',
415 'rev_id' => $this->mId
),
416 'Revision::getTitle' );
418 $this->mTitle
= Title
::makeTitle( $row->page_namespace
,
421 return $this->mTitle
;
425 * Set the title of the revision
427 * @param $title Title
429 public function setTitle( $title ) {
430 $this->mTitle
= $title;
438 public function getPage() {
443 * Fetch revision's user id if it's available to the specified audience.
444 * If the specified audience does not have access to it, zero will be
447 * @param $audience Integer: one of:
448 * Revision::FOR_PUBLIC to be displayed to all users
449 * Revision::FOR_THIS_USER to be displayed to $wgUser
450 * Revision::RAW get the ID regardless of permissions
455 public function getUser( $audience = self
::FOR_PUBLIC
) {
456 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
458 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
466 * Fetch revision's user id without regard for the current user's permissions
470 public function getRawUser() {
475 * Fetch revision's username if it's available to the specified audience.
476 * If the specified audience does not have access to the username, an
477 * empty string will be returned.
479 * @param $audience Integer: one of:
480 * Revision::FOR_PUBLIC to be displayed to all users
481 * Revision::FOR_THIS_USER to be displayed to $wgUser
482 * Revision::RAW get the text regardless of permissions
486 public function getUserText( $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
) ) {
492 return $this->mUserText
;
497 * Fetch revision's username without regard for view restrictions
501 public function getRawUserText() {
502 return $this->mUserText
;
506 * Fetch revision comment if it's available to the specified audience.
507 * If the specified audience does not have access to the comment, 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 function getComment( $audience = self
::FOR_PUBLIC
) {
518 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_COMMENT
) ) {
520 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_COMMENT
) ) {
523 return $this->mComment
;
528 * Fetch revision comment without regard for the current user's permissions
532 public function getRawComment() {
533 return $this->mComment
;
539 public function isMinor() {
540 return (bool)$this->mMinorEdit
;
544 * @return Integer rcid of the unpatrolled row, zero if there isn't one
546 public function isUnpatrolled() {
547 if( $this->mUnpatrolled
!== null ) {
548 return $this->mUnpatrolled
;
550 $dbr = wfGetDB( DB_SLAVE
);
551 $this->mUnpatrolled
= $dbr->selectField( 'recentchanges',
553 array( // Add redundant user,timestamp condition so we can use the existing index
554 'rc_user_text' => $this->getRawUserText(),
555 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
556 'rc_this_oldid' => $this->getId(),
561 return (int)$this->mUnpatrolled
;
565 * int $field one of DELETED_* bitfield constants
569 public function isDeleted( $field ) {
570 return ( $this->mDeleted
& $field ) == $field;
574 * Get the deletion bitfield of the revision
576 public function getVisibility() {
577 return (int)$this->mDeleted
;
581 * Fetch revision text if it's available to the specified audience.
582 * If the specified audience does not have the ability to view this
583 * revision, an empty string will be returned.
585 * @param $audience Integer: one of:
586 * Revision::FOR_PUBLIC to be displayed to all users
587 * Revision::FOR_THIS_USER to be displayed to $wgUser
588 * Revision::RAW get the text regardless of permissions
593 public function getText( $audience = self
::FOR_PUBLIC
) {
594 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_TEXT
) ) {
596 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_TEXT
) ) {
599 return $this->getRawText();
604 * Alias for getText(Revision::FOR_THIS_USER)
609 public function revText() {
611 return $this->getText( self
::FOR_THIS_USER
);
615 * Fetch revision text without regard for view restrictions
619 public function getRawText() {
620 if( is_null( $this->mText
) ) {
621 // Revision text is immutable. Load on demand:
622 $this->mText
= $this->loadText();
630 public function getTimestamp() {
631 return wfTimestamp( TS_MW
, $this->mTimestamp
);
637 public function isCurrent() {
638 return $this->mCurrent
;
642 * Get previous revision for this title
644 * @return Revision or null
646 public function getPrevious() {
647 if( $this->getTitle() ) {
648 $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
650 return Revision
::newFromTitle( $this->getTitle(), $prev );
657 * Get next revision for this title
659 * @return Revision or null
661 public function getNext() {
662 if( $this->getTitle() ) {
663 $next = $this->getTitle()->getNextRevisionID( $this->getId() );
665 return Revision
::newFromTitle( $this->getTitle(), $next );
672 * Get previous revision Id for this page_id
673 * This is used to populate rev_parent_id on save
675 * @param $db DatabaseBase
678 private function getPreviousRevisionId( $db ) {
679 if( is_null( $this->mPage
) ) {
682 # Use page_latest if ID is not given
684 $prevId = $db->selectField( 'page', 'page_latest',
685 array( 'page_id' => $this->mPage
),
688 $prevId = $db->selectField( 'revision', 'rev_id',
689 array( 'rev_page' => $this->mPage
, 'rev_id < ' . $this->mId
),
691 array( 'ORDER BY' => 'rev_id DESC' ) );
693 return intval( $prevId );
697 * Get revision text associated with an old or archive row
698 * $row is usually an object from wfFetchRow(), both the flags and the text
699 * field must be included
701 * @param $row Object: the text data
702 * @param $prefix String: table prefix (default 'old_')
703 * @return String: text the text requested or false on failure
705 public static function getRevisionText( $row, $prefix = 'old_' ) {
706 wfProfileIn( __METHOD__
);
709 $textField = $prefix . 'text';
710 $flagsField = $prefix . 'flags';
712 if( isset( $row->$flagsField ) ) {
713 $flags = explode( ',', $row->$flagsField );
718 if( isset( $row->$textField ) ) {
719 $text = $row->$textField;
721 wfProfileOut( __METHOD__
);
725 # Use external methods for external objects, text in table is URL-only then
726 if ( in_array( 'external', $flags ) ) {
728 @list
(/* $proto */, $path ) = explode( '://', $url, 2 );
730 wfProfileOut( __METHOD__
);
733 $text = ExternalStore
::fetchFromURL( $url );
736 // If the text was fetched without an error, convert it
737 if ( $text !== false ) {
738 if( in_array( 'gzip', $flags ) ) {
739 # Deal with optional compression of archived pages.
740 # This can be done periodically via maintenance/compressOld.php, and
741 # as pages are saved if $wgCompressRevisions is set.
742 $text = gzinflate( $text );
745 if( in_array( 'object', $flags ) ) {
746 # Generic compressed storage
747 $obj = unserialize( $text );
748 if ( !is_object( $obj ) ) {
750 wfProfileOut( __METHOD__
);
753 $text = $obj->getText();
756 global $wgLegacyEncoding;
757 if( $text !== false && $wgLegacyEncoding
758 && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) )
760 # Old revisions kept around in a legacy encoding?
761 # Upconvert on demand.
762 # ("utf8" checked for compatibility with some broken
763 # conversion scripts 2008-12-30)
764 global $wgInputEncoding, $wgContLang;
765 $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text );
768 wfProfileOut( __METHOD__
);
773 * If $wgCompressRevisions is enabled, we will compress data.
774 * The input string is modified in place.
775 * Return value is the flags field: contains 'gzip' if the
776 * data is compressed, and 'utf-8' if we're saving in UTF-8
779 * @param $text Mixed: reference to a text
782 public static function compressRevisionText( &$text ) {
783 global $wgCompressRevisions;
786 # Revisions not marked this way will be converted
787 # on load if $wgLegacyCharset is set in the future.
790 if( $wgCompressRevisions ) {
791 if( function_exists( 'gzdeflate' ) ) {
792 $text = gzdeflate( $text );
795 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
798 return implode( ',', $flags );
802 * Insert a new revision into the database, returning the new revision ID
803 * number on success and dies horribly on failure.
805 * @param $dbw DatabaseBase: (master connection)
808 public function insertOn( $dbw ) {
809 global $wgDefaultExternalStore;
811 wfProfileIn( __METHOD__
);
813 $data = $this->mText
;
814 $flags = Revision
::compressRevisionText( $data );
816 # Write to external storage if required
817 if( $wgDefaultExternalStore ) {
818 // Store and get the URL
819 $data = ExternalStore
::insertToDefault( $data );
821 throw new MWException( "Unable to store text to external storage" );
826 $flags .= 'external';
829 # Record the text (or external storage URL) to the text table
830 if( !isset( $this->mTextId
) ) {
831 $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
832 $dbw->insert( 'text',
836 'old_flags' => $flags,
839 $this->mTextId
= $dbw->insertId();
842 if ( $this->mComment
=== null ) $this->mComment
= "";
844 # Record the edit in revisions
845 $rev_id = isset( $this->mId
)
847 : $dbw->nextSequenceValue( 'revision_rev_id_seq' );
848 $dbw->insert( 'revision',
851 'rev_page' => $this->mPage
,
852 'rev_text_id' => $this->mTextId
,
853 'rev_comment' => $this->mComment
,
854 'rev_minor_edit' => $this->mMinorEdit ?
1 : 0,
855 'rev_user' => $this->mUser
,
856 'rev_user_text' => $this->mUserText
,
857 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp
),
858 'rev_deleted' => $this->mDeleted
,
859 'rev_len' => $this->mSize
,
860 'rev_parent_id' => is_null($this->mParentId
) ?
861 $this->getPreviousRevisionId( $dbw ) : $this->mParentId
865 $this->mId
= !is_null( $rev_id ) ?
$rev_id : $dbw->insertId();
867 wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
869 wfProfileOut( __METHOD__
);
874 * Lazy-load the revision's text.
875 * Currently hardcoded to the 'text' table storage engine.
879 protected function loadText() {
880 wfProfileIn( __METHOD__
);
882 // Caching may be beneficial for massive use of external storage
883 global $wgRevisionCacheExpiry, $wgMemc;
884 $textId = $this->getTextId();
885 $key = wfMemcKey( 'revisiontext', 'textid', $textId );
886 if( $wgRevisionCacheExpiry ) {
887 $text = $wgMemc->get( $key );
888 if( is_string( $text ) ) {
889 wfDebug( __METHOD__
. ": got id $textId from cache\n" );
890 wfProfileOut( __METHOD__
);
895 // If we kept data for lazy extraction, use it now...
896 if ( isset( $this->mTextRow
) ) {
897 $row = $this->mTextRow
;
898 $this->mTextRow
= null;
904 // Text data is immutable; check slaves first.
905 $dbr = wfGetDB( DB_SLAVE
);
906 $row = $dbr->selectRow( 'text',
907 array( 'old_text', 'old_flags' ),
908 array( 'old_id' => $this->getTextId() ),
912 if( !$row && wfGetLB()->getServerCount() > 1 ) {
913 // Possible slave lag!
914 $dbw = wfGetDB( DB_MASTER
);
915 $row = $dbw->selectRow( 'text',
916 array( 'old_text', 'old_flags' ),
917 array( 'old_id' => $this->getTextId() ),
921 $text = self
::getRevisionText( $row );
923 # No negative caching -- negative hits on text rows may be due to corrupted slave servers
924 if( $wgRevisionCacheExpiry && $text !== false ) {
925 $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
928 wfProfileOut( __METHOD__
);
934 * Create a new null-revision for insertion into a page's
935 * history. This will not re-save the text, but simply refer
936 * to the text from the previous version.
938 * Such revisions can for instance identify page rename
939 * operations and other such meta-modifications.
941 * @param $dbw DatabaseBase
942 * @param $pageId Integer: ID number of the page to read from
943 * @param $summary String: revision's summary
944 * @param $minor Boolean: whether the revision should be considered as minor
945 * @return Mixed: Revision, or null on error
947 public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
948 wfProfileIn( __METHOD__
);
950 $current = $dbw->selectRow(
951 array( 'page', 'revision' ),
952 array( 'page_latest', 'rev_text_id', 'rev_len' ),
954 'page_id' => $pageId,
955 'page_latest=rev_id',
960 $revision = new Revision( array(
962 'comment' => $summary,
963 'minor_edit' => $minor,
964 'text_id' => $current->rev_text_id
,
965 'parent_id' => $current->page_latest
,
966 'len' => $current->rev_len
972 wfProfileOut( __METHOD__
);
977 * Determine if the current user is allowed to view a particular
978 * field of this revision, if it's marked as deleted.
980 * @param $field Integer:one of self::DELETED_TEXT,
981 * self::DELETED_COMMENT,
985 public function userCan( $field ) {
986 return self
::userCanBitfield( $this->mDeleted
, $field );
990 * Determine if the current user is allowed to view a particular
991 * field of this revision, if it's marked as deleted. This is used
992 * by various classes to avoid duplication.
994 * @param $bitfield Integer: current field
995 * @param $field Integer: one of self::DELETED_TEXT = File::DELETED_FILE,
996 * self::DELETED_COMMENT = File::DELETED_COMMENT,
997 * self::DELETED_USER = File::DELETED_USER
1000 public static function userCanBitfield( $bitfield, $field ) {
1001 if( $bitfield & $field ) { // aspect is deleted
1003 if ( $bitfield & self
::DELETED_RESTRICTED
) {
1004 $permission = 'suppressrevision';
1005 } elseif ( $field & self
::DELETED_TEXT
) {
1006 $permission = 'deletedtext';
1008 $permission = 'deletedhistory';
1010 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
1011 return $wgUser->isAllowed( $permission );
1018 * Get rev_timestamp from rev_id, without loading the rest of the row
1020 * @param $title Title
1021 * @param $id Integer
1024 static function getTimestampFromId( $title, $id ) {
1025 $dbr = wfGetDB( DB_SLAVE
);
1026 // Casting fix for DB2
1030 $conds = array( 'rev_id' => $id );
1031 $conds['rev_page'] = $title->getArticleId();
1032 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1033 if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
1034 # Not in slave, try master
1035 $dbw = wfGetDB( DB_MASTER
);
1036 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1038 return wfTimestamp( TS_MW
, $timestamp );
1042 * Get count of revisions per page...not very efficient
1044 * @param $db DatabaseBase
1045 * @param $id Integer: page id
1048 static function countByPageId( $db, $id ) {
1049 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
1050 array( 'rev_page' => $id ), __METHOD__
);
1052 return $row->revCount
;
1058 * Get count of revisions per page...not very efficient
1060 * @param $db DatabaseBase
1061 * @param $title Title
1064 static function countByTitle( $db, $title ) {
1065 $id = $title->getArticleId();
1067 return Revision
::countByPageId( $db, $id );
1074 * Aliases for backwards compatibility with 1.6
1076 define( 'MW_REV_DELETED_TEXT', Revision
::DELETED_TEXT
);
1077 define( 'MW_REV_DELETED_COMMENT', Revision
::DELETED_COMMENT
);
1078 define( 'MW_REV_DELETED_USER', Revision
::DELETED_USER
);
1079 define( 'MW_REV_DELETED_RESTRICTED', Revision
::DELETED_RESTRICTED
);