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_' );
86 return new self( $attribs );
90 * Load a page revision from a given revision ID number.
91 * Returns null if no such revision can be found.
93 * @param $db DatabaseBase
95 * @return Revision or null
97 public static function loadFromId( $db, $id ) {
98 return Revision
::loadFromConds( $db,
99 array( 'page_id=rev_page',
100 'rev_id' => intval( $id ) ) );
104 * Load either the current, or a specified, revision
105 * that's attached to a given page. If not attached
106 * to that page, will return null.
108 * @param $db DatabaseBase
109 * @param $pageid Integer
111 * @return Revision or null
113 public static function loadFromPageId( $db, $pageid, $id = 0 ) {
114 $conds = array( 'page_id=rev_page','rev_page' => intval( $pageid ), 'page_id'=>intval( $pageid ) );
116 $conds['rev_id'] = intval( $id );
118 $conds[] = 'rev_id=page_latest';
120 return Revision
::loadFromConds( $db, $conds );
124 * Load either the current, or a specified, revision
125 * that's attached to a given page. If not attached
126 * to that page, will return null.
128 * @param $db DatabaseBase
129 * @param $title Title
131 * @return Revision or null
133 public static function loadFromTitle( $db, $title, $id = 0 ) {
135 $matchId = intval( $id );
137 $matchId = 'page_latest';
139 return Revision
::loadFromConds(
141 array( "rev_id=$matchId",
143 'page_namespace' => $title->getNamespace(),
144 'page_title' => $title->getDBkey() ) );
148 * Load the revision for the given title with the given timestamp.
149 * WARNING: Timestamps may in some circumstances not be unique,
150 * so this isn't the best key to use.
152 * @param $db Database
153 * @param $title Title
154 * @param $timestamp String
155 * @return Revision or null
157 public static function loadFromTimestamp( $db, $title, $timestamp ) {
158 return Revision
::loadFromConds(
160 array( 'rev_timestamp' => $db->timestamp( $timestamp ),
162 'page_namespace' => $title->getNamespace(),
163 'page_title' => $title->getDBkey() ) );
167 * Given a set of conditions, fetch a revision.
169 * @param $conditions Array
170 * @return Revision or null
172 public static function newFromConds( $conditions ) {
173 $db = wfGetDB( DB_SLAVE
);
174 $row = Revision
::loadFromConds( $db, $conditions );
175 if( is_null( $row ) && wfGetLB()->getServerCount() > 1 ) {
176 $dbw = wfGetDB( DB_MASTER
);
177 $row = Revision
::loadFromConds( $dbw, $conditions );
183 * Given a set of conditions, fetch a revision from
184 * the given database connection.
186 * @param $db Database
187 * @param $conditions Array
188 * @return Revision or null
190 private static function loadFromConds( $db, $conditions ) {
191 $res = Revision
::fetchFromConds( $db, $conditions );
193 $row = $res->fetchObject();
196 $ret = new Revision( $row );
205 * Return a wrapper for a series of database rows to
206 * fetch all of a given page's revisions in turn.
207 * Each row can be fed to the constructor to get objects.
209 * @param $title Title
210 * @return ResultWrapper
212 public static function fetchRevision( $title ) {
213 return Revision
::fetchFromConds(
215 array( 'rev_id=page_latest',
216 'page_namespace' => $title->getNamespace(),
217 'page_title' => $title->getDBkey(),
218 'page_id=rev_page' ) );
222 * Given a set of conditions, return a ResultWrapper
223 * which will return matching database rows with the
224 * fields necessary to build Revision objects.
226 * @param $db Database
227 * @param $conditions Array
228 * @return ResultWrapper
230 private static function fetchFromConds( $db, $conditions ) {
231 $fields = self
::selectFields();
232 $fields[] = 'page_namespace';
233 $fields[] = 'page_title';
234 $fields[] = 'page_latest';
236 array( 'page', 'revision' ),
240 array( 'LIMIT' => 1 ) );
241 $ret = $db->resultObject( $res );
246 * Return the list of revision fields that should be selected to create
249 static function selectFields() {
266 * Return the list of text fields that should be selected to read the
269 static function selectTextFields() {
277 * Return the list of page fields that should be selected from page table
279 static function selectPageFields() {
290 * @param $row Mixed: either a database row or an array
293 function __construct( $row ) {
294 if( is_object( $row ) ) {
295 $this->mId
= intval( $row->rev_id
);
296 $this->mPage
= intval( $row->rev_page
);
297 $this->mTextId
= intval( $row->rev_text_id
);
298 $this->mComment
= $row->rev_comment
;
299 $this->mUserText
= $row->rev_user_text
;
300 $this->mUser
= intval( $row->rev_user
);
301 $this->mMinorEdit
= intval( $row->rev_minor_edit
);
302 $this->mTimestamp
= $row->rev_timestamp
;
303 $this->mDeleted
= intval( $row->rev_deleted
);
305 if( !isset( $row->rev_parent_id
) )
306 $this->mParentId
= is_null($row->rev_parent_id
) ?
null : 0;
308 $this->mParentId
= intval( $row->rev_parent_id
);
310 if( !isset( $row->rev_len
) ||
is_null( $row->rev_len
) )
313 $this->mSize
= intval( $row->rev_len
);
315 if( isset( $row->page_latest
) ) {
316 $this->mCurrent
= ( $row->rev_id
== $row->page_latest
);
317 $this->mTitle
= Title
::newFromRow( $row );
319 $this->mCurrent
= false;
320 $this->mTitle
= null;
323 // Lazy extraction...
325 if( isset( $row->old_text
) ) {
326 $this->mTextRow
= $row;
328 // 'text' table row entry will be lazy-loaded
329 $this->mTextRow
= null;
331 } elseif( is_array( $row ) ) {
332 // Build a new revision to be saved...
335 $this->mId
= isset( $row['id'] ) ?
intval( $row['id'] ) : null;
336 $this->mPage
= isset( $row['page'] ) ?
intval( $row['page'] ) : null;
337 $this->mTextId
= isset( $row['text_id'] ) ?
intval( $row['text_id'] ) : null;
338 $this->mUserText
= isset( $row['user_text'] ) ?
strval( $row['user_text'] ) : $wgUser->getName();
339 $this->mUser
= isset( $row['user'] ) ?
intval( $row['user'] ) : $wgUser->getId();
340 $this->mMinorEdit
= isset( $row['minor_edit'] ) ?
intval( $row['minor_edit'] ) : 0;
341 $this->mTimestamp
= isset( $row['timestamp'] ) ?
strval( $row['timestamp'] ) : wfTimestamp( TS_MW
);
342 $this->mDeleted
= isset( $row['deleted'] ) ?
intval( $row['deleted'] ) : 0;
343 $this->mSize
= isset( $row['len'] ) ?
intval( $row['len'] ) : null;
344 $this->mParentId
= isset( $row['parent_id'] ) ?
intval( $row['parent_id'] ) : null;
346 // Enforce spacing trimming on supplied text
347 $this->mComment
= isset( $row['comment'] ) ?
trim( strval( $row['comment'] ) ) : null;
348 $this->mText
= isset( $row['text'] ) ?
rtrim( strval( $row['text'] ) ) : null;
349 $this->mTextRow
= null;
351 $this->mTitle
= null; # Load on demand if needed
352 $this->mCurrent
= false;
353 # If we still have no len_size, see it we have the text to figure it out
355 $this->mSize
= is_null( $this->mText
) ?
null : strlen( $this->mText
);
357 throw new MWException( 'Revision constructor passed invalid row format.' );
359 $this->mUnpatrolled
= null;
367 public function getId() {
376 public function getTextId() {
377 return $this->mTextId
;
381 * Get parent revision ID (the original previous page revision)
385 public function getParentId() {
386 return $this->mParentId
;
390 * Returns the length of the text in this revision, or null if unknown.
394 public function getSize() {
399 * Returns the title of the page associated with this entry.
403 public function getTitle() {
404 if( isset( $this->mTitle
) ) {
405 return $this->mTitle
;
407 $dbr = wfGetDB( DB_SLAVE
);
408 $row = $dbr->selectRow(
409 array( 'page', 'revision' ),
410 array( 'page_namespace', 'page_title' ),
411 array( 'page_id=rev_page',
412 'rev_id' => $this->mId
),
413 'Revision::getTitle' );
415 $this->mTitle
= Title
::makeTitle( $row->page_namespace
,
418 return $this->mTitle
;
422 * Set the title of the revision
424 * @param $title Title
426 public function setTitle( $title ) {
427 $this->mTitle
= $title;
435 public function getPage() {
440 * Fetch revision's user id if it's available to the specified audience.
441 * If the specified audience does not have access to it, zero will be
444 * @param $audience Integer: one of:
445 * Revision::FOR_PUBLIC to be displayed to all users
446 * Revision::FOR_THIS_USER to be displayed to $wgUser
447 * Revision::RAW get the ID regardless of permissions
452 public function getUser( $audience = self
::FOR_PUBLIC
) {
453 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
455 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
463 * Fetch revision's user id without regard for the current user's permissions
467 public function getRawUser() {
472 * Fetch revision's username if it's available to the specified audience.
473 * If the specified audience does not have access to the username, an
474 * empty string will be returned.
476 * @param $audience Integer: one of:
477 * Revision::FOR_PUBLIC to be displayed to all users
478 * Revision::FOR_THIS_USER to be displayed to $wgUser
479 * Revision::RAW get the text regardless of permissions
483 public function getUserText( $audience = self
::FOR_PUBLIC
) {
484 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
486 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
489 return $this->mUserText
;
494 * Fetch revision's username without regard for view restrictions
498 public function getRawUserText() {
499 return $this->mUserText
;
503 * Fetch revision comment if it's available to the specified audience.
504 * If the specified audience does not have access to the comment, an
505 * empty string will be returned.
507 * @param $audience Integer: one of:
508 * Revision::FOR_PUBLIC to be displayed to all users
509 * Revision::FOR_THIS_USER to be displayed to $wgUser
510 * Revision::RAW get the text regardless of permissions
514 function getComment( $audience = self
::FOR_PUBLIC
) {
515 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_COMMENT
) ) {
517 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_COMMENT
) ) {
520 return $this->mComment
;
525 * Fetch revision comment without regard for the current user's permissions
529 public function getRawComment() {
530 return $this->mComment
;
536 public function isMinor() {
537 return (bool)$this->mMinorEdit
;
541 * @return Integer rcid of the unpatrolled row, zero if there isn't one
543 public function isUnpatrolled() {
544 if( $this->mUnpatrolled
!== null ) {
545 return $this->mUnpatrolled
;
547 $dbr = wfGetDB( DB_SLAVE
);
548 $this->mUnpatrolled
= $dbr->selectField( 'recentchanges',
550 array( // Add redundant user,timestamp condition so we can use the existing index
551 'rc_user_text' => $this->getRawUserText(),
552 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
553 'rc_this_oldid' => $this->getId(),
558 return (int)$this->mUnpatrolled
;
562 * int $field one of DELETED_* bitfield constants
566 public function isDeleted( $field ) {
567 return ( $this->mDeleted
& $field ) == $field;
571 * Get the deletion bitfield of the revision
573 public function getVisibility() {
574 return (int)$this->mDeleted
;
578 * Fetch revision text if it's available to the specified audience.
579 * If the specified audience does not have the ability to view this
580 * revision, an empty string will be returned.
582 * @param $audience Integer: one of:
583 * Revision::FOR_PUBLIC to be displayed to all users
584 * Revision::FOR_THIS_USER to be displayed to $wgUser
585 * Revision::RAW get the text regardless of permissions
590 public function getText( $audience = self
::FOR_PUBLIC
) {
591 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_TEXT
) ) {
593 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_TEXT
) ) {
596 return $this->getRawText();
601 * Alias for getText(Revision::FOR_THIS_USER)
606 public function revText() {
607 return $this->getText( self
::FOR_THIS_USER
);
611 * Fetch revision text without regard for view restrictions
615 public function getRawText() {
616 if( is_null( $this->mText
) ) {
617 // Revision text is immutable. Load on demand:
618 $this->mText
= $this->loadText();
626 public function getTimestamp() {
627 return wfTimestamp( TS_MW
, $this->mTimestamp
);
633 public function isCurrent() {
634 return $this->mCurrent
;
638 * Get previous revision for this title
640 * @return Revision or null
642 public function getPrevious() {
643 if( $this->getTitle() ) {
644 $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
646 return Revision
::newFromTitle( $this->getTitle(), $prev );
653 * Get next revision for this title
655 * @return Revision or null
657 public function getNext() {
658 if( $this->getTitle() ) {
659 $next = $this->getTitle()->getNextRevisionID( $this->getId() );
661 return Revision
::newFromTitle( $this->getTitle(), $next );
668 * Get previous revision Id for this page_id
669 * This is used to populate rev_parent_id on save
671 * @param $db DatabaseBase
674 private function getPreviousRevisionId( $db ) {
675 if( is_null( $this->mPage
) ) {
678 # Use page_latest if ID is not given
680 $prevId = $db->selectField( 'page', 'page_latest',
681 array( 'page_id' => $this->mPage
),
684 $prevId = $db->selectField( 'revision', 'rev_id',
685 array( 'rev_page' => $this->mPage
, 'rev_id < ' . $this->mId
),
687 array( 'ORDER BY' => 'rev_id DESC' ) );
689 return intval( $prevId );
693 * Get revision text associated with an old or archive row
694 * $row is usually an object from wfFetchRow(), both the flags and the text
695 * field must be included
697 * @param $row Object: the text data
698 * @param $prefix String: table prefix (default 'old_')
699 * @return String: text the text requested or false on failure
701 public static function getRevisionText( $row, $prefix = 'old_' ) {
702 wfProfileIn( __METHOD__
);
705 $textField = $prefix . 'text';
706 $flagsField = $prefix . 'flags';
708 if( isset( $row->$flagsField ) ) {
709 $flags = explode( ',', $row->$flagsField );
714 if( isset( $row->$textField ) ) {
715 $text = $row->$textField;
717 wfProfileOut( __METHOD__
);
721 # Use external methods for external objects, text in table is URL-only then
722 if ( in_array( 'external', $flags ) ) {
724 @list
(/* $proto */, $path ) = explode( '://', $url, 2 );
726 wfProfileOut( __METHOD__
);
729 $text = ExternalStore
::fetchFromURL( $url );
732 // If the text was fetched without an error, convert it
733 if ( $text !== false ) {
734 if( in_array( 'gzip', $flags ) ) {
735 # Deal with optional compression of archived pages.
736 # This can be done periodically via maintenance/compressOld.php, and
737 # as pages are saved if $wgCompressRevisions is set.
738 $text = gzinflate( $text );
741 if( in_array( 'object', $flags ) ) {
742 # Generic compressed storage
743 $obj = unserialize( $text );
744 if ( !is_object( $obj ) ) {
746 wfProfileOut( __METHOD__
);
749 $text = $obj->getText();
752 global $wgLegacyEncoding;
753 if( $text !== false && $wgLegacyEncoding
754 && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) )
756 # Old revisions kept around in a legacy encoding?
757 # Upconvert on demand.
758 # ("utf8" checked for compatibility with some broken
759 # conversion scripts 2008-12-30)
760 global $wgInputEncoding, $wgContLang;
761 $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text );
764 wfProfileOut( __METHOD__
);
769 * If $wgCompressRevisions is enabled, we will compress data.
770 * The input string is modified in place.
771 * Return value is the flags field: contains 'gzip' if the
772 * data is compressed, and 'utf-8' if we're saving in UTF-8
775 * @param $text Mixed: reference to a text
778 public static function compressRevisionText( &$text ) {
779 global $wgCompressRevisions;
782 # Revisions not marked this way will be converted
783 # on load if $wgLegacyCharset is set in the future.
786 if( $wgCompressRevisions ) {
787 if( function_exists( 'gzdeflate' ) ) {
788 $text = gzdeflate( $text );
791 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
794 return implode( ',', $flags );
798 * Insert a new revision into the database, returning the new revision ID
799 * number on success and dies horribly on failure.
801 * @param $dbw DatabaseBase: (master connection)
804 public function insertOn( $dbw ) {
805 global $wgDefaultExternalStore;
807 wfProfileIn( __METHOD__
);
809 $data = $this->mText
;
810 $flags = Revision
::compressRevisionText( $data );
812 # Write to external storage if required
813 if( $wgDefaultExternalStore ) {
814 // Store and get the URL
815 $data = ExternalStore
::insertToDefault( $data );
817 throw new MWException( "Unable to store text to external storage" );
822 $flags .= 'external';
825 # Record the text (or external storage URL) to the text table
826 if( !isset( $this->mTextId
) ) {
827 $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
828 $dbw->insert( 'text',
832 'old_flags' => $flags,
835 $this->mTextId
= $dbw->insertId();
838 if ( $this->mComment
=== null ) $this->mComment
= "";
840 # Record the edit in revisions
841 $rev_id = isset( $this->mId
)
843 : $dbw->nextSequenceValue( 'revision_rev_id_seq' );
844 $dbw->insert( 'revision',
847 'rev_page' => $this->mPage
,
848 'rev_text_id' => $this->mTextId
,
849 'rev_comment' => $this->mComment
,
850 'rev_minor_edit' => $this->mMinorEdit ?
1 : 0,
851 'rev_user' => $this->mUser
,
852 'rev_user_text' => $this->mUserText
,
853 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp
),
854 'rev_deleted' => $this->mDeleted
,
855 'rev_len' => $this->mSize
,
856 'rev_parent_id' => is_null($this->mParentId
) ?
857 $this->getPreviousRevisionId( $dbw ) : $this->mParentId
861 $this->mId
= !is_null( $rev_id ) ?
$rev_id : $dbw->insertId();
863 wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
865 wfProfileOut( __METHOD__
);
870 * Lazy-load the revision's text.
871 * Currently hardcoded to the 'text' table storage engine.
875 protected function loadText() {
876 wfProfileIn( __METHOD__
);
878 // Caching may be beneficial for massive use of external storage
879 global $wgRevisionCacheExpiry, $wgMemc;
880 $textId = $this->getTextId();
881 $key = wfMemcKey( 'revisiontext', 'textid', $textId );
882 if( $wgRevisionCacheExpiry ) {
883 $text = $wgMemc->get( $key );
884 if( is_string( $text ) ) {
885 wfDebug( __METHOD__
. ": got id $textId from cache\n" );
886 wfProfileOut( __METHOD__
);
891 // If we kept data for lazy extraction, use it now...
892 if ( isset( $this->mTextRow
) ) {
893 $row = $this->mTextRow
;
894 $this->mTextRow
= null;
900 // Text data is immutable; check slaves first.
901 $dbr = wfGetDB( DB_SLAVE
);
902 $row = $dbr->selectRow( 'text',
903 array( 'old_text', 'old_flags' ),
904 array( 'old_id' => $this->getTextId() ),
908 if( !$row && wfGetLB()->getServerCount() > 1 ) {
909 // Possible slave lag!
910 $dbw = wfGetDB( DB_MASTER
);
911 $row = $dbw->selectRow( 'text',
912 array( 'old_text', 'old_flags' ),
913 array( 'old_id' => $this->getTextId() ),
917 $text = self
::getRevisionText( $row );
919 # No negative caching -- negative hits on text rows may be due to corrupted slave servers
920 if( $wgRevisionCacheExpiry && $text !== false ) {
921 $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
924 wfProfileOut( __METHOD__
);
930 * Create a new null-revision for insertion into a page's
931 * history. This will not re-save the text, but simply refer
932 * to the text from the previous version.
934 * Such revisions can for instance identify page rename
935 * operations and other such meta-modifications.
937 * @param $dbw DatabaseBase
938 * @param $pageId Integer: ID number of the page to read from
939 * @param $summary String: revision's summary
940 * @param $minor Boolean: whether the revision should be considered as minor
941 * @return Mixed: Revision, or null on error
943 public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
944 wfProfileIn( __METHOD__
);
946 $current = $dbw->selectRow(
947 array( 'page', 'revision' ),
948 array( 'page_latest', 'rev_text_id', 'rev_len' ),
950 'page_id' => $pageId,
951 'page_latest=rev_id',
956 $revision = new Revision( array(
958 'comment' => $summary,
959 'minor_edit' => $minor,
960 'text_id' => $current->rev_text_id
,
961 'parent_id' => $current->page_latest
,
962 'len' => $current->rev_len
968 wfProfileOut( __METHOD__
);
973 * Determine if the current user is allowed to view a particular
974 * field of this revision, if it's marked as deleted.
976 * @param $field Integer:one of self::DELETED_TEXT,
977 * self::DELETED_COMMENT,
981 public function userCan( $field ) {
982 return self
::userCanBitfield( $this->mDeleted
, $field );
986 * Determine if the current user is allowed to view a particular
987 * field of this revision, if it's marked as deleted. This is used
988 * by various classes to avoid duplication.
990 * @param $bitfield Integer: current field
991 * @param $field Integer: one of self::DELETED_TEXT = File::DELETED_FILE,
992 * self::DELETED_COMMENT = File::DELETED_COMMENT,
993 * self::DELETED_USER = File::DELETED_USER
996 public static function userCanBitfield( $bitfield, $field ) {
997 if( $bitfield & $field ) { // aspect is deleted
999 if ( $bitfield & self
::DELETED_RESTRICTED
) {
1000 $permission = 'suppressrevision';
1001 } elseif ( $field & self
::DELETED_TEXT
) {
1002 $permission = 'deletedtext';
1004 $permission = 'deletedhistory';
1006 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
1007 return $wgUser->isAllowed( $permission );
1014 * Get rev_timestamp from rev_id, without loading the rest of the row
1016 * @param $title Title
1017 * @param $id Integer
1020 static function getTimestampFromId( $title, $id ) {
1021 $dbr = wfGetDB( DB_SLAVE
);
1022 // Casting fix for DB2
1026 $conds = array( 'rev_id' => $id );
1027 $conds['rev_page'] = $title->getArticleId();
1028 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1029 if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
1030 # Not in slave, try master
1031 $dbw = wfGetDB( DB_MASTER
);
1032 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1034 return wfTimestamp( TS_MW
, $timestamp );
1038 * Get count of revisions per page...not very efficient
1040 * @param $db DatabaseBase
1041 * @param $id Integer: page id
1044 static function countByPageId( $db, $id ) {
1045 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
1046 array( 'rev_page' => $id ), __METHOD__
);
1048 return $row->revCount
;
1054 * Get count of revisions per page...not very efficient
1056 * @param $db DatabaseBase
1057 * @param $title Title
1060 static function countByTitle( $db, $title ) {
1061 $id = $title->getArticleId();
1063 return Revision
::countByPageId( $db, $id );
1070 * Aliases for backwards compatibility with 1.6
1072 define( 'MW_REV_DELETED_TEXT', Revision
::DELETED_TEXT
);
1073 define( 'MW_REV_DELETED_COMMENT', Revision
::DELETED_COMMENT
);
1074 define( 'MW_REV_DELETED_USER', Revision
::DELETED_USER
);
1075 define( 'MW_REV_DELETED_RESTRICTED', Revision
::DELETED_RESTRICTED
);