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 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() {
610 return $this->getText( self
::FOR_THIS_USER
);
614 * Fetch revision text without regard for view restrictions
618 public function getRawText() {
619 if( is_null( $this->mText
) ) {
620 // Revision text is immutable. Load on demand:
621 $this->mText
= $this->loadText();
629 public function getTimestamp() {
630 return wfTimestamp( TS_MW
, $this->mTimestamp
);
636 public function isCurrent() {
637 return $this->mCurrent
;
641 * Get previous revision for this title
643 * @return Revision or null
645 public function getPrevious() {
646 if( $this->getTitle() ) {
647 $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
649 return Revision
::newFromTitle( $this->getTitle(), $prev );
656 * Get next revision for this title
658 * @return Revision or null
660 public function getNext() {
661 if( $this->getTitle() ) {
662 $next = $this->getTitle()->getNextRevisionID( $this->getId() );
664 return Revision
::newFromTitle( $this->getTitle(), $next );
671 * Get previous revision Id for this page_id
672 * This is used to populate rev_parent_id on save
674 * @param $db DatabaseBase
677 private function getPreviousRevisionId( $db ) {
678 if( is_null( $this->mPage
) ) {
681 # Use page_latest if ID is not given
683 $prevId = $db->selectField( 'page', 'page_latest',
684 array( 'page_id' => $this->mPage
),
687 $prevId = $db->selectField( 'revision', 'rev_id',
688 array( 'rev_page' => $this->mPage
, 'rev_id < ' . $this->mId
),
690 array( 'ORDER BY' => 'rev_id DESC' ) );
692 return intval( $prevId );
696 * Get revision text associated with an old or archive row
697 * $row is usually an object from wfFetchRow(), both the flags and the text
698 * field must be included
700 * @param $row Object: the text data
701 * @param $prefix String: table prefix (default 'old_')
702 * @return String: text the text requested or false on failure
704 public static function getRevisionText( $row, $prefix = 'old_' ) {
705 wfProfileIn( __METHOD__
);
708 $textField = $prefix . 'text';
709 $flagsField = $prefix . 'flags';
711 if( isset( $row->$flagsField ) ) {
712 $flags = explode( ',', $row->$flagsField );
717 if( isset( $row->$textField ) ) {
718 $text = $row->$textField;
720 wfProfileOut( __METHOD__
);
724 # Use external methods for external objects, text in table is URL-only then
725 if ( in_array( 'external', $flags ) ) {
727 @list
(/* $proto */, $path ) = explode( '://', $url, 2 );
729 wfProfileOut( __METHOD__
);
732 $text = ExternalStore
::fetchFromURL( $url );
735 // If the text was fetched without an error, convert it
736 if ( $text !== false ) {
737 if( in_array( 'gzip', $flags ) ) {
738 # Deal with optional compression of archived pages.
739 # This can be done periodically via maintenance/compressOld.php, and
740 # as pages are saved if $wgCompressRevisions is set.
741 $text = gzinflate( $text );
744 if( in_array( 'object', $flags ) ) {
745 # Generic compressed storage
746 $obj = unserialize( $text );
747 if ( !is_object( $obj ) ) {
749 wfProfileOut( __METHOD__
);
752 $text = $obj->getText();
755 global $wgLegacyEncoding;
756 if( $text !== false && $wgLegacyEncoding
757 && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) )
759 # Old revisions kept around in a legacy encoding?
760 # Upconvert on demand.
761 # ("utf8" checked for compatibility with some broken
762 # conversion scripts 2008-12-30)
763 global $wgInputEncoding, $wgContLang;
764 $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text );
767 wfProfileOut( __METHOD__
);
772 * If $wgCompressRevisions is enabled, we will compress data.
773 * The input string is modified in place.
774 * Return value is the flags field: contains 'gzip' if the
775 * data is compressed, and 'utf-8' if we're saving in UTF-8
778 * @param $text Mixed: reference to a text
781 public static function compressRevisionText( &$text ) {
782 global $wgCompressRevisions;
785 # Revisions not marked this way will be converted
786 # on load if $wgLegacyCharset is set in the future.
789 if( $wgCompressRevisions ) {
790 if( function_exists( 'gzdeflate' ) ) {
791 $text = gzdeflate( $text );
794 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
797 return implode( ',', $flags );
801 * Insert a new revision into the database, returning the new revision ID
802 * number on success and dies horribly on failure.
804 * @param $dbw DatabaseBase: (master connection)
807 public function insertOn( $dbw ) {
808 global $wgDefaultExternalStore;
810 wfProfileIn( __METHOD__
);
812 $data = $this->mText
;
813 $flags = Revision
::compressRevisionText( $data );
815 # Write to external storage if required
816 if( $wgDefaultExternalStore ) {
817 // Store and get the URL
818 $data = ExternalStore
::insertToDefault( $data );
820 throw new MWException( "Unable to store text to external storage" );
825 $flags .= 'external';
828 # Record the text (or external storage URL) to the text table
829 if( !isset( $this->mTextId
) ) {
830 $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
831 $dbw->insert( 'text',
835 'old_flags' => $flags,
838 $this->mTextId
= $dbw->insertId();
841 if ( $this->mComment
=== null ) $this->mComment
= "";
843 # Record the edit in revisions
844 $rev_id = isset( $this->mId
)
846 : $dbw->nextSequenceValue( 'revision_rev_id_seq' );
847 $dbw->insert( 'revision',
850 'rev_page' => $this->mPage
,
851 'rev_text_id' => $this->mTextId
,
852 'rev_comment' => $this->mComment
,
853 'rev_minor_edit' => $this->mMinorEdit ?
1 : 0,
854 'rev_user' => $this->mUser
,
855 'rev_user_text' => $this->mUserText
,
856 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp
),
857 'rev_deleted' => $this->mDeleted
,
858 'rev_len' => $this->mSize
,
859 'rev_parent_id' => is_null($this->mParentId
) ?
860 $this->getPreviousRevisionId( $dbw ) : $this->mParentId
864 $this->mId
= !is_null( $rev_id ) ?
$rev_id : $dbw->insertId();
866 wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
868 wfProfileOut( __METHOD__
);
873 * Lazy-load the revision's text.
874 * Currently hardcoded to the 'text' table storage engine.
878 protected function loadText() {
879 wfProfileIn( __METHOD__
);
881 // Caching may be beneficial for massive use of external storage
882 global $wgRevisionCacheExpiry, $wgMemc;
883 $textId = $this->getTextId();
884 $key = wfMemcKey( 'revisiontext', 'textid', $textId );
885 if( $wgRevisionCacheExpiry ) {
886 $text = $wgMemc->get( $key );
887 if( is_string( $text ) ) {
888 wfDebug( __METHOD__
. ": got id $textId from cache\n" );
889 wfProfileOut( __METHOD__
);
894 // If we kept data for lazy extraction, use it now...
895 if ( isset( $this->mTextRow
) ) {
896 $row = $this->mTextRow
;
897 $this->mTextRow
= null;
903 // Text data is immutable; check slaves first.
904 $dbr = wfGetDB( DB_SLAVE
);
905 $row = $dbr->selectRow( 'text',
906 array( 'old_text', 'old_flags' ),
907 array( 'old_id' => $this->getTextId() ),
911 if( !$row && wfGetLB()->getServerCount() > 1 ) {
912 // Possible slave lag!
913 $dbw = wfGetDB( DB_MASTER
);
914 $row = $dbw->selectRow( 'text',
915 array( 'old_text', 'old_flags' ),
916 array( 'old_id' => $this->getTextId() ),
920 $text = self
::getRevisionText( $row );
922 # No negative caching -- negative hits on text rows may be due to corrupted slave servers
923 if( $wgRevisionCacheExpiry && $text !== false ) {
924 $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
927 wfProfileOut( __METHOD__
);
933 * Create a new null-revision for insertion into a page's
934 * history. This will not re-save the text, but simply refer
935 * to the text from the previous version.
937 * Such revisions can for instance identify page rename
938 * operations and other such meta-modifications.
940 * @param $dbw DatabaseBase
941 * @param $pageId Integer: ID number of the page to read from
942 * @param $summary String: revision's summary
943 * @param $minor Boolean: whether the revision should be considered as minor
944 * @return Mixed: Revision, or null on error
946 public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
947 wfProfileIn( __METHOD__
);
949 $current = $dbw->selectRow(
950 array( 'page', 'revision' ),
951 array( 'page_latest', 'rev_text_id', 'rev_len' ),
953 'page_id' => $pageId,
954 'page_latest=rev_id',
959 $revision = new Revision( array(
961 'comment' => $summary,
962 'minor_edit' => $minor,
963 'text_id' => $current->rev_text_id
,
964 'parent_id' => $current->page_latest
,
965 'len' => $current->rev_len
971 wfProfileOut( __METHOD__
);
976 * Determine if the current user is allowed to view a particular
977 * field of this revision, if it's marked as deleted.
979 * @param $field Integer:one of self::DELETED_TEXT,
980 * self::DELETED_COMMENT,
984 public function userCan( $field ) {
985 return self
::userCanBitfield( $this->mDeleted
, $field );
989 * Determine if the current user is allowed to view a particular
990 * field of this revision, if it's marked as deleted. This is used
991 * by various classes to avoid duplication.
993 * @param $bitfield Integer: current field
994 * @param $field Integer: one of self::DELETED_TEXT = File::DELETED_FILE,
995 * self::DELETED_COMMENT = File::DELETED_COMMENT,
996 * self::DELETED_USER = File::DELETED_USER
999 public static function userCanBitfield( $bitfield, $field ) {
1000 if( $bitfield & $field ) { // aspect is deleted
1002 if ( $bitfield & self
::DELETED_RESTRICTED
) {
1003 $permission = 'suppressrevision';
1004 } elseif ( $field & self
::DELETED_TEXT
) {
1005 $permission = 'deletedtext';
1007 $permission = 'deletedhistory';
1009 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
1010 return $wgUser->isAllowed( $permission );
1017 * Get rev_timestamp from rev_id, without loading the rest of the row
1019 * @param $title Title
1020 * @param $id Integer
1023 static function getTimestampFromId( $title, $id ) {
1024 $dbr = wfGetDB( DB_SLAVE
);
1025 // Casting fix for DB2
1029 $conds = array( 'rev_id' => $id );
1030 $conds['rev_page'] = $title->getArticleId();
1031 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1032 if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
1033 # Not in slave, try master
1034 $dbw = wfGetDB( DB_MASTER
);
1035 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1037 return wfTimestamp( TS_MW
, $timestamp );
1041 * Get count of revisions per page...not very efficient
1043 * @param $db DatabaseBase
1044 * @param $id Integer: page id
1047 static function countByPageId( $db, $id ) {
1048 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
1049 array( 'rev_page' => $id ), __METHOD__
);
1051 return $row->revCount
;
1057 * Get count of revisions per page...not very efficient
1059 * @param $db DatabaseBase
1060 * @param $title Title
1063 static function countByTitle( $db, $title ) {
1064 $id = $title->getArticleId();
1066 return Revision
::countByPageId( $db, $id );
1073 * Aliases for backwards compatibility with 1.6
1075 define( 'MW_REV_DELETED_TEXT', Revision
::DELETED_TEXT
);
1076 define( 'MW_REV_DELETED_COMMENT', Revision
::DELETED_COMMENT
);
1077 define( 'MW_REV_DELETED_USER', Revision
::DELETED_USER
);
1078 define( 'MW_REV_DELETED_RESTRICTED', Revision
::DELETED_RESTRICTED
);