11 const DELETED_TEXT
= 1;
12 const DELETED_COMMENT
= 2;
13 const DELETED_USER
= 4;
14 const DELETED_RESTRICTED
= 8;
16 const SUPPRESSED_USER
= 12;
17 // Audience options for Revision::getText()
19 const FOR_THIS_USER
= 2;
23 * Load a page revision from a given revision ID number.
24 * Returns null if no such revision can be found.
30 public static function newFromId( $id ) {
31 return Revision
::newFromConds(
32 array( 'page_id=rev_page',
33 'rev_id' => intval( $id ) ) );
37 * Load either the current, or a specified, revision
38 * that's attached to a given title. If not attached
39 * to that title, will return null.
45 public static function newFromTitle( $title, $id = 0 ) {
47 'page_namespace' => $title->getNamespace(),
48 'page_title' => $title->getDBkey()
51 // Use the specified ID
52 $conds['rev_id'] = $id;
53 } elseif ( wfGetLB()->getServerCount() > 1 ) {
54 // Get the latest revision ID from the master
55 $dbw = wfGetDB( DB_MASTER
);
56 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
57 if ( $latest === false ) {
58 // Page does not exist
61 $conds['rev_id'] = $latest;
63 // Use a join to get the latest revision
64 $conds[] = 'rev_id=page_latest';
66 $conds[] = 'page_id=rev_page';
67 return Revision
::newFromConds( $conds );
71 * Make a fake revision object from an archive table row. This is queried
72 * for permissions or even inserted (as in Special:Undelete)
73 * @fixme: should be a subclass for RevisionDelete. [TS]
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_' );
91 return new self( $attribs );
95 * Load a page revision from a given revision ID number.
96 * Returns null if no such revision can be found.
103 public static function loadFromId( $db, $id ) {
104 return Revision
::loadFromConds( $db,
105 array( 'page_id=rev_page',
106 'rev_id' => intval( $id ) ) );
110 * Load either the current, or a specified, revision
111 * that's attached to a given page. If not attached
112 * to that page, will return null.
114 * @param Database $db
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 Database $db
137 * @param Title $title
143 public static function loadFromTitle( $db, $title, $id = 0 ) {
145 $matchId = intval( $id );
147 $matchId = 'page_latest';
149 return Revision
::loadFromConds(
151 array( "rev_id=$matchId",
153 'page_namespace' => $title->getNamespace(),
154 'page_title' => $title->getDBkey() ) );
158 * Load the revision for the given title with the given timestamp.
159 * WARNING: Timestamps may in some circumstances not be unique,
160 * so this isn't the best key to use.
162 * @param Database $db
163 * @param Title $title
164 * @param string $timestamp
169 public static function loadFromTimestamp( $db, $title, $timestamp ) {
170 return Revision
::loadFromConds(
172 array( 'rev_timestamp' => $db->timestamp( $timestamp ),
174 'page_namespace' => $title->getNamespace(),
175 'page_title' => $title->getDBkey() ) );
179 * Given a set of conditions, fetch a revision.
181 * @param array $conditions
186 public static function newFromConds( $conditions ) {
187 $db = wfGetDB( DB_SLAVE
);
188 $row = Revision
::loadFromConds( $db, $conditions );
189 if( is_null( $row ) && wfGetLB()->getServerCount() > 1 ) {
190 $dbw = wfGetDB( DB_MASTER
);
191 $row = Revision
::loadFromConds( $dbw, $conditions );
197 * Given a set of conditions, fetch a revision from
198 * the given database connection.
200 * @param Database $db
201 * @param array $conditions
206 private static function loadFromConds( $db, $conditions ) {
207 $res = Revision
::fetchFromConds( $db, $conditions );
209 $row = $res->fetchObject();
212 $ret = new Revision( $row );
221 * Return a wrapper for a series of database rows to
222 * fetch all of a given page's revisions in turn.
223 * Each row can be fed to the constructor to get objects.
225 * @param Title $title
226 * @return ResultWrapper
230 public static function fetchRevision( $title ) {
231 return Revision
::fetchFromConds(
233 array( 'rev_id=page_latest',
234 'page_namespace' => $title->getNamespace(),
235 'page_title' => $title->getDBkey(),
236 'page_id=rev_page' ) );
240 * Given a set of conditions, return a ResultWrapper
241 * which will return matching database rows with the
242 * fields necessary to build Revision objects.
244 * @param Database $db
245 * @param array $conditions
246 * @return ResultWrapper
250 private static function fetchFromConds( $db, $conditions ) {
251 $fields = self
::selectFields();
252 $fields[] = 'page_namespace';
253 $fields[] = 'page_title';
254 $fields[] = 'page_latest';
256 array( 'page', 'revision' ),
260 array( 'LIMIT' => 1 ) );
261 $ret = $db->resultObject( $res );
266 * Return the list of revision fields that should be selected to create
269 static function selectFields() {
286 * Return the list of text fields that should be selected to read the
289 static function selectTextFields() {
297 * Return the list of page fields that should be selected from page table
299 static function selectPageFields() {
311 function Revision( $row ) {
312 if( is_object( $row ) ) {
313 $this->mId
= intval( $row->rev_id
);
314 $this->mPage
= intval( $row->rev_page
);
315 $this->mTextId
= intval( $row->rev_text_id
);
316 $this->mComment
= $row->rev_comment
;
317 $this->mUserText
= $row->rev_user_text
;
318 $this->mUser
= intval( $row->rev_user
);
319 $this->mMinorEdit
= intval( $row->rev_minor_edit
);
320 $this->mTimestamp
= $row->rev_timestamp
;
321 $this->mDeleted
= intval( $row->rev_deleted
);
323 if( !isset( $row->rev_parent_id
) )
324 $this->mParentId
= is_null($row->rev_parent_id
) ?
null : 0;
326 $this->mParentId
= intval( $row->rev_parent_id
);
328 if( !isset( $row->rev_len
) ||
is_null( $row->rev_len
) )
331 $this->mSize
= intval( $row->rev_len
);
333 if( isset( $row->page_latest
) ) {
334 $this->mCurrent
= ( $row->rev_id
== $row->page_latest
);
335 $this->mTitle
= Title
::makeTitle( $row->page_namespace
, $row->page_title
);
336 $this->mTitle
->resetArticleID( $this->mPage
);
338 $this->mCurrent
= false;
339 $this->mTitle
= null;
342 // Lazy extraction...
344 if( isset( $row->old_text
) ) {
345 $this->mTextRow
= $row;
347 // 'text' table row entry will be lazy-loaded
348 $this->mTextRow
= null;
350 } elseif( is_array( $row ) ) {
351 // Build a new revision to be saved...
354 $this->mId
= isset( $row['id'] ) ?
intval( $row['id'] ) : null;
355 $this->mPage
= isset( $row['page'] ) ?
intval( $row['page'] ) : null;
356 $this->mTextId
= isset( $row['text_id'] ) ?
intval( $row['text_id'] ) : null;
357 $this->mUserText
= isset( $row['user_text'] ) ?
strval( $row['user_text'] ) : $wgUser->getName();
358 $this->mUser
= isset( $row['user'] ) ?
intval( $row['user'] ) : $wgUser->getId();
359 $this->mMinorEdit
= isset( $row['minor_edit'] ) ?
intval( $row['minor_edit'] ) : 0;
360 $this->mTimestamp
= isset( $row['timestamp'] ) ?
strval( $row['timestamp'] ) : wfTimestamp( TS_MW
);
361 $this->mDeleted
= isset( $row['deleted'] ) ?
intval( $row['deleted'] ) : 0;
362 $this->mSize
= isset( $row['len'] ) ?
intval( $row['len'] ) : null;
363 $this->mParentId
= isset( $row['parent_id'] ) ?
intval( $row['parent_id'] ) : null;
365 // Enforce spacing trimming on supplied text
366 $this->mComment
= isset( $row['comment'] ) ?
trim( strval( $row['comment'] ) ) : null;
367 $this->mText
= isset( $row['text'] ) ?
rtrim( strval( $row['text'] ) ) : null;
368 $this->mTextRow
= null;
370 $this->mTitle
= null; # Load on demand if needed
371 $this->mCurrent
= false;
372 # If we still have no len_size, see it we have the text to figure it out
374 $this->mSize
= is_null( $this->mText
) ?
null : strlen( $this->mText
);
376 throw new MWException( 'Revision constructor passed invalid row format.' );
378 $this->mUnpatrolled
= null;
389 public function getId() {
397 public function getTextId() {
398 return $this->mTextId
;
402 * Get parent revision ID (the original previous page revision)
405 public function getParentId() {
406 return $this->mParentId
;
410 * Returns the length of the text in this revision, or null if unknown.
413 public function getSize() {
418 * Returns the title of the page associated with this entry.
421 public function getTitle() {
422 if( isset( $this->mTitle
) ) {
423 return $this->mTitle
;
425 $dbr = wfGetDB( DB_SLAVE
);
426 $row = $dbr->selectRow(
427 array( 'page', 'revision' ),
428 array( 'page_namespace', 'page_title' ),
429 array( 'page_id=rev_page',
430 'rev_id' => $this->mId
),
431 'Revision::getTitle' );
433 $this->mTitle
= Title
::makeTitle( $row->page_namespace
,
436 return $this->mTitle
;
440 * Set the title of the revision
441 * @param Title $title
443 public function setTitle( $title ) {
444 $this->mTitle
= $title;
451 public function getPage() {
456 * Fetch revision's user id if it's available to the specified audience.
457 * If the specified audience does not have access to it, zero will be
460 * @param integer $audience One of:
461 * Revision::FOR_PUBLIC to be displayed to all users
462 * Revision::FOR_THIS_USER to be displayed to $wgUser
463 * Revision::RAW get the ID regardless of permissions
468 public function getUser( $audience = self
::FOR_PUBLIC
) {
469 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
471 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
479 * Fetch revision's user id without regard for the current user's permissions
482 public function getRawUser() {
487 * Fetch revision's username if it's available to the specified audience.
488 * If the specified audience does not have access to the username, an
489 * empty string will be returned.
491 * @param integer $audience One of:
492 * Revision::FOR_PUBLIC to be displayed to all users
493 * Revision::FOR_THIS_USER to be displayed to $wgUser
494 * Revision::RAW get the text regardless of permissions
498 public function getUserText( $audience = self
::FOR_PUBLIC
) {
499 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_USER
) ) {
501 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_USER
) ) {
504 return $this->mUserText
;
509 * Fetch revision's username without regard for view restrictions
512 public function getRawUserText() {
513 return $this->mUserText
;
517 * Fetch revision comment if it's available to the specified audience.
518 * If the specified audience does not have access to the comment, an
519 * empty string will be returned.
521 * @param integer $audience One of:
522 * Revision::FOR_PUBLIC to be displayed to all users
523 * Revision::FOR_THIS_USER to be displayed to $wgUser
524 * Revision::RAW get the text regardless of permissions
528 function getComment( $audience = self
::FOR_PUBLIC
) {
529 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_COMMENT
) ) {
531 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_COMMENT
) ) {
534 return $this->mComment
;
539 * Fetch revision comment without regard for the current user's permissions
542 public function getRawComment() {
543 return $this->mComment
;
549 public function isMinor() {
550 return (bool)$this->mMinorEdit
;
554 * @return int rcid of the unpatrolled row, zero if there isn't one
556 public function isUnpatrolled() {
557 if( $this->mUnpatrolled
!== null ) {
558 return $this->mUnpatrolled
;
560 $dbr = wfGetDB( DB_SLAVE
);
561 $this->mUnpatrolled
= $dbr->selectField( 'recentchanges',
563 array( // Add redundant user,timestamp condition so we can use the existing index
564 'rc_user_text' => $this->getRawUserText(),
565 'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
566 'rc_this_oldid' => $this->getId(),
571 return (int)$this->mUnpatrolled
;
575 * int $field one of DELETED_* bitfield constants
578 public function isDeleted( $field ) {
579 return ( $this->mDeleted
& $field ) == $field;
583 * Get the deletion bitfield of the revision
585 public function getVisibility() {
586 return (int)$this->mDeleted
;
590 * Fetch revision text if it's available to the specified audience.
591 * If the specified audience does not have the ability to view this
592 * revision, an empty string will be returned.
594 * @param integer $audience One of:
595 * Revision::FOR_PUBLIC to be displayed to all users
596 * Revision::FOR_THIS_USER to be displayed to $wgUser
597 * Revision::RAW get the text regardless of permissions
602 public function getText( $audience = self
::FOR_PUBLIC
) {
603 if( $audience == self
::FOR_PUBLIC
&& $this->isDeleted( self
::DELETED_TEXT
) ) {
605 } elseif( $audience == self
::FOR_THIS_USER
&& !$this->userCan( self
::DELETED_TEXT
) ) {
608 return $this->getRawText();
613 * Alias for getText(Revision::FOR_THIS_USER)
615 public function revText() {
616 return $this->getText( self
::FOR_THIS_USER
);
620 * 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
649 public function getPrevious() {
650 if( $this->getTitle() ) {
651 $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
653 return Revision
::newFromTitle( $this->getTitle(), $prev );
662 public function getNext() {
663 if( $this->getTitle() ) {
664 $next = $this->getTitle()->getNextRevisionID( $this->getId() );
666 return Revision
::newFromTitle( $this->getTitle(), $next );
673 * Get previous revision Id for this page_id
674 * This is used to populate rev_parent_id on save
675 * @param Database $db
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 object $row The text data
702 * @param string $prefix table prefix (default 'old_')
703 * @return string $text|false the text requested
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( $wgLegacyEncoding && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) ) {
758 # Old revisions kept around in a legacy encoding?
759 # Upconvert on demand.
760 # ("utf8" checked for compatibility with some broken
761 # conversion scripts 2008-12-30)
762 global $wgInputEncoding, $wgContLang;
763 $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text );
766 wfProfileOut( __METHOD__
);
771 * If $wgCompressRevisions is enabled, we will compress data.
772 * The input string is modified in place.
773 * Return value is the flags field: contains 'gzip' if the
774 * data is compressed, and 'utf-8' if we're saving in UTF-8
777 * @param mixed $text reference to a text
780 public static function compressRevisionText( &$text ) {
781 global $wgCompressRevisions;
784 # Revisions not marked this way will be converted
785 # on load if $wgLegacyCharset is set in the future.
788 if( $wgCompressRevisions ) {
789 if( function_exists( 'gzdeflate' ) ) {
790 $text = gzdeflate( $text );
793 wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
796 return implode( ',', $flags );
800 * Insert a new revision into the database, returning the new revision ID
801 * number on success and dies horribly on failure.
803 * @param Database $dbw
806 public function insertOn( $dbw ) {
807 global $wgDefaultExternalStore;
809 wfProfileIn( __METHOD__
);
811 $data = $this->mText
;
812 $flags = Revision
::compressRevisionText( $data );
814 # Write to external storage if required
815 if( $wgDefaultExternalStore ) {
816 // Store and get the URL
817 $data = ExternalStore
::insertToDefault( $data );
819 throw new MWException( "Unable to store text to external storage" );
824 $flags .= 'external';
827 # Record the text (or external storage URL) to the text table
828 if( !isset( $this->mTextId
) ) {
829 $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
830 $dbw->insert( 'text',
834 'old_flags' => $flags,
837 $this->mTextId
= $dbw->insertId();
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 Database $dbw
938 * @param int $pageId ID number of the page to read from
939 * @param string $summary
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.
975 * @param int $field one of self::DELETED_TEXT,
976 * self::DELETED_COMMENT,
980 public function userCan( $field ) {
981 return self
::userCanBitfield( $this->mDeleted
, $field );
985 * Determine if the current user is allowed to view a particular
986 * field of this revision, if it's marked as deleted. This is used
987 * by various classes to avoid duplication.
988 * @param int $bitfield (current field)
989 * @param int $field one of self::DELETED_TEXT = File::DELETED_FILE,
990 * self::DELETED_COMMENT = File::DELETED_COMMENT,
991 * self::DELETED_USER = File::DELETED_USER
994 public static function userCanBitfield( $bitfield, $field ) {
995 if( $bitfield & $field ) { // aspect is deleted
998 if ( $bitfield & self
::DELETED_RESTRICTED
) {
999 $permission = 'suppressrevision';
1000 } elseif ( $field & self
::DELETED_TEXT
) {
1001 $permission = 'deletedtext';
1003 $permission = 'deletedhistory';
1005 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
1006 return $wgUser->isAllowed( $permission );
1013 * Get rev_timestamp from rev_id, without loading the rest of the row
1014 * @param Title $title
1015 * @param integer $id
1017 static function getTimestampFromId( $title, $id ) {
1018 $dbr = wfGetDB( DB_SLAVE
);
1019 // Casting fix for DB2
1023 $conds = array( 'rev_id' => $id );
1024 $conds['rev_page'] = $title->getArticleId();
1025 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1026 if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
1027 # Not in slave, try master
1028 $dbw = wfGetDB( DB_MASTER
);
1029 $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
1031 return wfTimestamp( TS_MW
, $timestamp );
1035 * Get count of revisions per page...not very efficient
1036 * @param Database $db
1037 * @param int $id, page id
1039 static function countByPageId( $db, $id ) {
1040 $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
1041 array( 'rev_page' => $id ), __METHOD__
);
1043 return $row->revCount
;
1049 * Get count of revisions per page...not very efficient
1050 * @param Database $db
1051 * @param Title $title
1053 static function countByTitle( $db, $title ) {
1054 $id = $title->getArticleId();
1056 return Revision
::countByPageId( $db, $id );
1063 * Aliases for backwards compatibility with 1.6
1065 define( 'MW_REV_DELETED_TEXT', Revision
::DELETED_TEXT
);
1066 define( 'MW_REV_DELETED_COMMENT', Revision
::DELETED_COMMENT
);
1067 define( 'MW_REV_DELETED_USER', Revision
::DELETED_USER
);
1068 define( 'MW_REV_DELETED_RESTRICTED', Revision
::DELETED_RESTRICTED
);