r14925 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14924‎ | r14925 | r14926 >
Date:06:31, 23 June 2006
Author:tstarling
Status:old
Tags:
Comment:
s/Revision::MW_REV_DELETED/Revision::DELETED/, and introduced aliases for compatibility with 1.6.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Export.php (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/PageHistory.php (modified) (history)
  • /trunk/phase3/includes/Revision.php (modified) (history)
  • /trunk/phase3/includes/SpecialContributions.php (modified) (history)
  • /trunk/phase3/includes/SpecialRevisiondelete.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -436,7 +436,7 @@
437437
438438 // FIXME: Horrible, horrible! This content-loading interface just plain sucks.
439439 // We should instead work with the Revision object when we need it...
440 - $this->mContent = $revision->userCan( Revision::MW_REV_DELETED_TEXT ) ? $revision->getRawText() : "";
 440+ $this->mContent = $revision->userCan( Revision::DELETED_TEXT ) ? $revision->getRawText() : "";
441441 //$this->mContent = $revision->getText();
442442
443443 $this->mUser = $revision->getUser();
@@ -803,8 +803,8 @@
804804 // FIXME: This would be a nice place to load the 'no such page' text.
805805 } else {
806806 $this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid );
807 - if( $this->mRevision->isDeleted( Revision::MW_REV_DELETED_TEXT ) ) {
808 - if( !$this->mRevision->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
 807+ if( $this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
 808+ if( !$this->mRevision->userCan( Revision::DELETED_TEXT ) ) {
809809 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
810810 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
811811 return;
Index: trunk/phase3/includes/SpecialRevisiondelete.php
@@ -46,10 +46,10 @@
4747
4848 $this->skin = $wgUser->getSkin();
4949 $this->checks = array(
50 - array( 'revdelete-hide-text', 'wpHideText', Revision::MW_REV_DELETED_TEXT ),
51 - array( 'revdelete-hide-comment', 'wpHideComment', Revision::MW_REV_DELETED_COMMENT ),
52 - array( 'revdelete-hide-user', 'wpHideUser', Revision::MW_REV_DELETED_USER ),
53 - array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision::MW_REV_DELETED_RESTRICTED ) );
 50+ array( 'revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT ),
 51+ array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ),
 52+ array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER ),
 53+ array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision::DELETED_RESTRICTED ) );
5454 }
5555
5656 /**
@@ -222,9 +222,9 @@
223223 function updateRecentChanges( $rev, $bitfield ) {
224224 $this->db->update( 'recentchanges',
225225 array(
226 - 'rc_user' => ($bitfield & Revision::MW_REV_DELETED_USER) ? 0 : $rev->getUser(),
227 - 'rc_user_text' => ($bitfield & Revision::MW_REV_DELETED_USER) ? wfMsg( 'rev-deleted-user' ) : $rev->getUserText(),
228 - 'rc_comment' => ($bitfield & Revision::MW_REV_DELETED_COMMENT) ? wfMsg( 'rev-deleted-comment' ) : $rev->getComment() ),
 226+ 'rc_user' => ($bitfield & Revision::DELETED_USER) ? 0 : $rev->getUser(),
 227+ 'rc_user_text' => ($bitfield & Revision::DELETED_USER) ? wfMsg( 'rev-deleted-user' ) : $rev->getUserText(),
 228+ 'rc_comment' => ($bitfield & Revision::DELETED_COMMENT) ? wfMsg( 'rev-deleted-comment' ) : $rev->getComment() ),
229229 array(
230230 'rc_this_oldid' => $rev->getId() ),
231231 'RevisionDeleter::updateRecentChanges' );
Index: trunk/phase3/includes/Linker.php
@@ -833,12 +833,12 @@
834834 * @return string HTML
835835 */
836836 function revUserLink( $rev ) {
837 - if( $rev->userCan( Revision::MW_REV_DELETED_USER ) ) {
 837+ if( $rev->userCan( Revision::DELETED_USER ) ) {
838838 $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() );
839839 } else {
840840 $link = wfMsgHtml( 'rev-deleted-user' );
841841 }
842 - if( $rev->isDeleted( Revision::MW_REV_DELETED_USER ) ) {
 842+ if( $rev->isDeleted( Revision::DELETED_USER ) ) {
843843 return '<span class="history-deleted">' . $link . '</span>';
844844 }
845845 return $link;
@@ -850,14 +850,14 @@
851851 * @return string HTML
852852 */
853853 function revUserTools( $rev ) {
854 - if( $rev->userCan( Revision::MW_REV_DELETED_USER ) ) {
 854+ if( $rev->userCan( Revision::DELETED_USER ) ) {
855855 $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() ) .
856856 ' ' .
857857 $this->userToolLinks( $rev->getRawUser(), $rev->getRawUserText() );
858858 } else {
859859 $link = wfMsgHtml( 'rev-deleted-user' );
860860 }
861 - if( $rev->isDeleted( Revision::MW_REV_DELETED_USER ) ) {
 861+ if( $rev->isDeleted( Revision::DELETED_USER ) ) {
862862 return '<span class="history-deleted">' . $link . '</span>';
863863 }
864864 return $link;
@@ -977,13 +977,13 @@
978978 * @return string HTML
979979 */
980980 function revComment( $rev ) {
981 - if( $rev->userCan( Revision::MW_REV_DELETED_COMMENT ) ) {
 981+ if( $rev->userCan( Revision::DELETED_COMMENT ) ) {
982982 $block = $this->commentBlock( $rev->getRawComment(), $rev->getTitle() );
983983 } else {
984984 $block = " <span class=\"comment\">" .
985985 wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
986986 }
987 - if( $rev->isDeleted( Revision::MW_REV_DELETED_COMMENT ) ) {
 987+ if( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
988988 return " <span class=\"history-deleted\">$block</span>";
989989 }
990990 return $block;
Index: trunk/phase3/includes/SpecialContributions.php
@@ -412,7 +412,7 @@
413413 }
414414
415415 }
416 - if( $rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
 416+ if( $rev->userCan( Revision::DELETED_TEXT ) ) {
417417 $difftext = '(' . $sk->makeKnownLinkObj( $page, $messages['diff'], 'diff=prev&oldid='.$row->rev_id ) . ')';
418418 } else {
419419 $difftext = '(' . $messages['diff'] . ')';
@@ -422,7 +422,7 @@
423423 $comment = $sk->revComment( $rev );
424424 $d = $wgLang->timeanddate( wfTimestamp( TS_MW, $row->rev_timestamp ), true );
425425
426 - if( $rev->isDeleted( Revision::MW_REV_DELETED_TEXT ) ) {
 426+ if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
427427 $d = '<span class="history-deleted">' . $d . '</span>';
428428 }
429429
@@ -433,7 +433,7 @@
434434 }
435435
436436 $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}";
437 - if( $rev->isDeleted( Revision::MW_REV_DELETED_TEXT ) ) {
 437+ if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
438438 $ret .= ' ' . wfMsgHtml( 'deletedrev' );
439439 }
440440 $ret = "<li>$ret</li>\n";
Index: trunk/phase3/includes/Export.php
@@ -395,7 +395,7 @@
396396 $ts = wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
397397 $out .= " " . wfElement( 'timestamp', null, $ts ) . "\n";
398398
399 - if( $row->rev_deleted & Revision::MW_REV_DELETED_USER ) {
 399+ if( $row->rev_deleted & Revision::DELETED_USER ) {
400400 $out .= " " . wfElement( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
401401 } else {
402402 $out .= " <contributor>\n";
@@ -411,13 +411,13 @@
412412 if( $row->rev_minor_edit ) {
413413 $out .= " <minor/>\n";
414414 }
415 - if( $row->rev_deleted & Revision::MW_REV_DELETED_COMMENT ) {
 415+ if( $row->rev_deleted & Revision::DELETED_COMMENT ) {
416416 $out .= " " . wfElement( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
417417 } elseif( $row->rev_comment != '' ) {
418418 $out .= " " . wfElementClean( 'comment', null, strval( $row->rev_comment ) ) . "\n";
419419 }
420420
421 - if( $row->rev_deleted & Revision::MW_REV_DELETED_TEXT ) {
 421+ if( $row->rev_deleted & Revision::DELETED_TEXT ) {
422422 $out .= " " . wfElement( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
423423 } elseif( isset( $row->old_text ) ) {
424424 // Raw text from the database may have invalid chars
Index: trunk/phase3/includes/Revision.php
@@ -12,10 +12,10 @@
1313 * @todo document
1414 */
1515 class Revision {
16 - const MW_REV_DELETED_TEXT = 1;
17 - const MW_REV_DELETED_COMMENT = 2;
18 - const MW_REV_DELETED_USER = 4;
19 - const MW_REV_DELETED_RESTRICTED = 8;
 16+ const DELETED_TEXT = 1;
 17+ const DELETED_COMMENT = 2;
 18+ const DELETED_USER = 4;
 19+ const DELETED_RESTRICTED = 8;
2020
2121 /**
2222 * Load a page revision from a given revision ID number.
@@ -348,7 +348,7 @@
349349 * @return int
350350 */
351351 function getUser() {
352 - if( $this->isDeleted( self::MW_REV_DELETED_USER ) ) {
 352+ if( $this->isDeleted( self::DELETED_USER ) ) {
353353 return 0;
354354 } else {
355355 return $this->mUser;
@@ -368,7 +368,7 @@
369369 * @return string
370370 */
371371 function getUserText() {
372 - if( $this->isDeleted( self::MW_REV_DELETED_USER ) ) {
 372+ if( $this->isDeleted( self::DELETED_USER ) ) {
373373 return "";
374374 } else {
375375 return $this->mUserText;
@@ -388,7 +388,7 @@
389389 * @return string
390390 */
391391 function getComment() {
392 - if( $this->isDeleted( self::MW_REV_DELETED_COMMENT ) ) {
 392+ if( $this->isDeleted( self::DELETED_COMMENT ) ) {
393393 return "";
394394 } else {
395395 return $this->mComment;
@@ -411,7 +411,7 @@
412412 }
413413
414414 /**
415 - * int $field one of MW_REV_DELETED_* bitfield constants
 415+ * int $field one of DELETED_* bitfield constants
416416 * @return bool
417417 */
418418 function isDeleted( $field ) {
@@ -423,7 +423,7 @@
424424 * @return string
425425 */
426426 function getText() {
427 - if( $this->isDeleted( self::MW_REV_DELETED_TEXT ) ) {
 427+ if( $this->isDeleted( self::DELETED_TEXT ) ) {
428428 return "";
429429 } else {
430430 return $this->getRawText();
@@ -734,15 +734,15 @@
735735 /**
736736 * Determine if the current user is allowed to view a particular
737737 * field of this revision, if it's marked as deleted.
738 - * @param int $field one of self::MW_REV_DELETED_TEXT,
739 - * self::MW_REV_DELETED_COMMENT,
740 - * self::MW_REV_DELETED_USER
 738+ * @param int $field one of self::DELETED_TEXT,
 739+ * self::DELETED_COMMENT,
 740+ * self::DELETED_USER
741741 * @return bool
742742 */
743743 function userCan( $field ) {
744744 if( ( $this->mDeleted & $field ) == $field ) {
745745 global $wgUser;
746 - $permission = ( $this->mDeleted & self::MW_REV_DELETED_RESTRICTED ) == self::MW_REV_DELETED_RESTRICTED
 746+ $permission = ( $this->mDeleted & self::DELETED_RESTRICTED ) == self::DELETED_RESTRICTED
747747 ? 'hiderevision'
748748 : 'deleterevision';
749749 wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" );
@@ -752,6 +752,31 @@
753753 }
754754 }
755755
 756+
 757+ /**
 758+ * Get rev_timestamp from rev_id, without loading the rest of the row
 759+ * @param integer $id
 760+ */
 761+ static function getTimestampFromID( $id ) {
 762+ $timestamp = $dbr->selectField( 'revision', 'rev_timestamp',
 763+ array( 'rev_id' => $id ), __METHOD__ );
 764+ if ( $timestamp === false ) {
 765+ # Not in slave, try master
 766+ $dbw =& wfGetDB( DB_MASTER );
 767+ $timestamp = $dbw->selectField( 'revision', 'rev_timestamp',
 768+ array( 'rev_id' => $id ), __METHOD__ );
 769+ }
 770+ return $timestamp;
 771+ }
756772 }
757773
 774+/**
 775+ * Aliases for backwards compatibility with 1.6
 776+ */
 777+define( 'MW_REV_DELETED_TEXT', Revision::DELETED_TEXT );
 778+define( 'MW_REV_DELETED_COMMENT', Revision::DELETED_COMMENT );
 779+define( 'MW_REV_DELETED_USER', Revision::DELETED_USER );
 780+define( 'MW_REV_DELETED_RESTRICTED', Revision::DELETED_RESTRICTED );
 781+
 782+
758783 ?>
Index: trunk/phase3/includes/Title.php
@@ -2152,11 +2152,11 @@
21532153 /**
21542154 * Get the revision ID of the previous revision
21552155 *
2156 - * @param integer $revision Revision ID. Get the revision that was before this one.
 2156+ * @param integer $revId Revision ID. Get the revision that was before this one.
 2157+ * @param string $timestamp The timestamp of the current revision, if known
21572158 * @return interger $oldrevision|false
21582159 */
2159 - function getPreviousRevisionID( $revision ) {
2160 - $dbr =& wfGetDB( DB_SLAVE );
 2160+ function getPreviousRevisionID( $revId, $timestamp = false ) {
21612161 return $dbr->selectField( 'revision', 'rev_id',
21622162 'rev_page=' . intval( $this->getArticleId() ) .
21632163 ' AND rev_id<' . intval( $revision ) . ' ORDER BY rev_id DESC' );
Index: trunk/phase3/includes/PageHistory.php
@@ -263,7 +263,7 @@
264264 if ($notificationtimestamp && ($row->rev_timestamp >= $notificationtimestamp)) {
265265 $s .= ' <span class="updatedmarker">' . wfMsgHtml( 'updatedmarker' ) . '</span>';
266266 }
267 - if( $row->rev_deleted & Revision::MW_REV_DELETED_TEXT ) {
 267+ if( $row->rev_deleted & Revision::DELETED_TEXT ) {
268268 $s .= ' ' . wfMsgHtml( 'deletedrev' );
269269 }
270270 $s .= "</li>\n";
@@ -275,13 +275,13 @@
276276 function revLink( $rev ) {
277277 global $wgLang;
278278 $date = $wgLang->timeanddate( wfTimestamp(TS_MW, $rev->getTimestamp()), true );
279 - if( $rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
 279+ if( $rev->userCan( Revision::DELETED_TEXT ) ) {
280280 $link = $this->mSkin->makeKnownLinkObj(
281281 $this->mTitle, $date, "oldid=" . $rev->getId() );
282282 } else {
283283 $link = $date;
284284 }
285 - if( $rev->isDeleted( Revision::MW_REV_DELETED_TEXT ) ) {
 285+ if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
286286 return '<span class="history-deleted">' . $link . '</span>';
287287 }
288288 return $link;
@@ -290,7 +290,7 @@
291291 /** @todo document */
292292 function curLink( $rev, $latest ) {
293293 $cur = wfMsgExt( 'cur', array( 'escape') );
294 - if( $latest || !$rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
 294+ if( $latest || !$rev->userCan( Revision::DELETED_TEXT ) ) {
295295 return $cur;
296296 } else {
297297 return $this->mSkin->makeKnownLinkObj(
@@ -313,7 +313,7 @@
314314 $last,
315315 "diff=" . $rev->getId() . "&oldid=prev" );
316316 }
317 - } elseif( !$rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
 317+ } elseif( !$rev->userCan( Revision::DELETED_TEXT ) ) {
318318 return $last;
319319 } else {
320320 return $this->mSkin->makeKnownLinkObj(
@@ -337,7 +337,7 @@
338338 # 'title' => wfMsgHtml( 'selectolderversionfordiff' )
339339 );
340340
341 - if( !$rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
 341+ if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
342342 $radio['disabled'] = 'disabled';
343343 }
344344

Status & tagging log