s/Revision::MW_REV_DELETED/Revision::DELETED/, and introduced aliases for compatibili...
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 23 Jun 2006 06:31:46 +0000 (06:31 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 23 Jun 2006 06:31:46 +0000 (06:31 +0000)
includes/Article.php
includes/Export.php
includes/Linker.php
includes/PageHistory.php
includes/Revision.php
includes/SpecialContributions.php
includes/SpecialRevisiondelete.php
includes/Title.php

index b58dda3..402bced 100644 (file)
@@ -436,7 +436,7 @@ class Article {
 
                // FIXME: Horrible, horrible! This content-loading interface just plain sucks.
                // We should instead work with the Revision object when we need it...
-               $this->mContent = $revision->userCan( Revision::MW_REV_DELETED_TEXT ) ? $revision->getRawText() : "";
+               $this->mContent = $revision->userCan( Revision::DELETED_TEXT ) ? $revision->getRawText() : "";
                //$this->mContent   = $revision->getText();
 
                $this->mUser      = $revision->getUser();
@@ -803,8 +803,8 @@ class Article {
                                        // FIXME: This would be a nice place to load the 'no such page' text.
                                } else {
                                        $this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid );
-                                       if( $this->mRevision->isDeleted( Revision::MW_REV_DELETED_TEXT ) ) {
-                                               if( !$this->mRevision->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
+                                       if( $this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
+                                               if( !$this->mRevision->userCan( Revision::DELETED_TEXT ) ) {
                                                        $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
                                                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
                                                        return;
index 88a83d9..da92694 100644 (file)
@@ -395,7 +395,7 @@ class XmlDumpWriter {
                $ts = wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
                $out .= "      " . wfElement( 'timestamp', null, $ts ) . "\n";
 
-               if( $row->rev_deleted & Revision::MW_REV_DELETED_USER ) {
+               if( $row->rev_deleted & Revision::DELETED_USER ) {
                        $out .= "      " . wfElement( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
                } else {
                        $out .= "      <contributor>\n";
@@ -411,13 +411,13 @@ class XmlDumpWriter {
                if( $row->rev_minor_edit ) {
                        $out .=  "      <minor/>\n";
                }
-               if( $row->rev_deleted & Revision::MW_REV_DELETED_COMMENT ) {
+               if( $row->rev_deleted & Revision::DELETED_COMMENT ) {
                        $out .= "      " . wfElement( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
                } elseif( $row->rev_comment != '' ) {
                        $out .= "      " . wfElementClean( 'comment', null, strval( $row->rev_comment ) ) . "\n";
                }
 
-               if( $row->rev_deleted & Revision::MW_REV_DELETED_TEXT ) {
+               if( $row->rev_deleted & Revision::DELETED_TEXT ) {
                        $out .= "      " . wfElement( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
                } elseif( isset( $row->old_text ) ) {
                        // Raw text from the database may have invalid chars
index 416a940..86b1ec6 100644 (file)
@@ -833,12 +833,12 @@ class Linker {
         * @return string HTML
         */
        function revUserLink( $rev ) {
-               if( $rev->userCan( Revision::MW_REV_DELETED_USER ) ) {
+               if( $rev->userCan( Revision::DELETED_USER ) ) {
                        $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() );
                } else {
                        $link = wfMsgHtml( 'rev-deleted-user' );
                }
-               if( $rev->isDeleted( Revision::MW_REV_DELETED_USER ) ) {
+               if( $rev->isDeleted( Revision::DELETED_USER ) ) {
                        return '<span class="history-deleted">' . $link . '</span>';
                }
                return $link;
@@ -850,14 +850,14 @@ class Linker {
         * @return string HTML
         */
        function revUserTools( $rev ) {
-               if( $rev->userCan( Revision::MW_REV_DELETED_USER ) ) {
+               if( $rev->userCan( Revision::DELETED_USER ) ) {
                        $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() ) .
                                ' ' .
                                $this->userToolLinks( $rev->getRawUser(), $rev->getRawUserText() );
                } else {
                        $link = wfMsgHtml( 'rev-deleted-user' );
                }
-               if( $rev->isDeleted( Revision::MW_REV_DELETED_USER ) ) {
+               if( $rev->isDeleted( Revision::DELETED_USER ) ) {
                        return '<span class="history-deleted">' . $link . '</span>';
                }
                return $link;
@@ -977,13 +977,13 @@ class Linker {
         * @return string HTML
         */
        function revComment( $rev ) {
-               if( $rev->userCan( Revision::MW_REV_DELETED_COMMENT ) ) {
+               if( $rev->userCan( Revision::DELETED_COMMENT ) ) {
                        $block = $this->commentBlock( $rev->getRawComment(), $rev->getTitle() );
                } else {
                        $block = " <span class=\"comment\">" .
                                wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
                }
-               if( $rev->isDeleted( Revision::MW_REV_DELETED_COMMENT ) ) {
+               if( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
                        return " <span class=\"history-deleted\">$block</span>";
                }
                return $block;
index 0dbf356..8b72a0a 100644 (file)
@@ -263,7 +263,7 @@ class PageHistory {
                if ($notificationtimestamp && ($row->rev_timestamp >= $notificationtimestamp)) {
                        $s .= ' <span class="updatedmarker">' .  wfMsgHtml( 'updatedmarker' ) . '</span>';
                }
-               if( $row->rev_deleted & Revision::MW_REV_DELETED_TEXT ) {
+               if( $row->rev_deleted & Revision::DELETED_TEXT ) {
                        $s .= ' ' . wfMsgHtml( 'deletedrev' );
                }
                $s .= "</li>\n";
@@ -275,13 +275,13 @@ class PageHistory {
        function revLink( $rev ) {
                global $wgLang;
                $date = $wgLang->timeanddate( wfTimestamp(TS_MW, $rev->getTimestamp()), true );
-               if( $rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
+               if( $rev->userCan( Revision::DELETED_TEXT ) ) {
                        $link = $this->mSkin->makeKnownLinkObj(
                                $this->mTitle, $date, "oldid=" . $rev->getId() );
                } else {
                        $link = $date;
                }
-               if( $rev->isDeleted( Revision::MW_REV_DELETED_TEXT ) ) {
+               if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
                        return '<span class="history-deleted">' . $link . '</span>';
                }
                return $link;
@@ -290,7 +290,7 @@ class PageHistory {
        /** @todo document */
        function curLink( $rev, $latest ) {
                $cur = wfMsgExt( 'cur', array( 'escape') );
-               if( $latest || !$rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
+               if( $latest || !$rev->userCan( Revision::DELETED_TEXT ) ) {
                        return $cur;
                } else {
                        return $this->mSkin->makeKnownLinkObj(
@@ -313,7 +313,7 @@ class PageHistory {
                                        $last,
                                        "diff=" . $rev->getId() . "&oldid=prev" );
                        }
-               } elseif( !$rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
+               } elseif( !$rev->userCan( Revision::DELETED_TEXT ) ) {
                        return $last;
                } else {
                        return $this->mSkin->makeKnownLinkObj(
@@ -337,7 +337,7 @@ class PageHistory {
 #                              'title' => wfMsgHtml( 'selectolderversionfordiff' )
                        );
 
-                       if( !$rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
+                       if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
                                $radio['disabled'] = 'disabled';
                        }
 
index 7ee0ffa..3139f24 100644 (file)
@@ -12,10 +12,10 @@ require_once( 'Database.php' );
  * @todo document
  */
 class Revision {
-       const MW_REV_DELETED_TEXT       = 1;
-       const MW_REV_DELETED_COMMENT    = 2;
-       const MW_REV_DELETED_USER       = 4;
-       const MW_REV_DELETED_RESTRICTED = 8;
+       const DELETED_TEXT      = 1;
+       const DELETED_COMMENT   = 2;
+       const DELETED_USER      = 4;
+       const DELETED_RESTRICTED = 8;
        
        /**
         * Load a page revision from a given revision ID number.
@@ -348,7 +348,7 @@ class Revision {
         * @return int
         */
        function getUser() {
-               if( $this->isDeleted( self::MW_REV_DELETED_USER ) ) {
+               if( $this->isDeleted( self::DELETED_USER ) ) {
                        return 0;
                } else {
                        return $this->mUser;
@@ -368,7 +368,7 @@ class Revision {
         * @return string
         */
        function getUserText() {
-               if( $this->isDeleted( self::MW_REV_DELETED_USER ) ) {
+               if( $this->isDeleted( self::DELETED_USER ) ) {
                        return "";
                } else {
                        return $this->mUserText;
@@ -388,7 +388,7 @@ class Revision {
         * @return string
         */
        function getComment() {
-               if( $this->isDeleted( self::MW_REV_DELETED_COMMENT ) ) {
+               if( $this->isDeleted( self::DELETED_COMMENT ) ) {
                        return "";
                } else {
                        return $this->mComment;
@@ -411,7 +411,7 @@ class Revision {
        }
 
        /**
-        * int $field one of MW_REV_DELETED_* bitfield constants
+        * int $field one of DELETED_* bitfield constants
         * @return bool
         */
        function isDeleted( $field ) {
@@ -423,7 +423,7 @@ class Revision {
         * @return string
         */
        function getText() {
-               if( $this->isDeleted( self::MW_REV_DELETED_TEXT ) ) {
+               if( $this->isDeleted( self::DELETED_TEXT ) ) {
                        return "";
                } else {
                        return $this->getRawText();
@@ -734,15 +734,15 @@ class Revision {
        /**
         * Determine if the current user is allowed to view a particular
         * field of this revision, if it's marked as deleted.
-        * @param int $field one of self::MW_REV_DELETED_TEXT,
-        *                          self::MW_REV_DELETED_COMMENT,
-        *                          self::MW_REV_DELETED_USER
+        * @param int $field one of self::DELETED_TEXT,
+        *                          self::DELETED_COMMENT,
+        *                          self::DELETED_USER
         * @return bool
         */
        function userCan( $field ) {
                if( ( $this->mDeleted & $field ) == $field ) {
                        global $wgUser;
-                       $permission = ( $this->mDeleted & self::MW_REV_DELETED_RESTRICTED ) == self::MW_REV_DELETED_RESTRICTED
+                       $permission = ( $this->mDeleted & self::DELETED_RESTRICTED ) == self::DELETED_RESTRICTED
                                ? 'hiderevision'
                                : 'deleterevision';
                        wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" );
@@ -752,6 +752,31 @@ class Revision {
                }
        }
 
+
+       /**
+        * Get rev_timestamp from rev_id, without loading the rest of the row
+        * @param integer $id
+        */
+       static function getTimestampFromID( $id ) {
+               $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', 
+                       array( 'rev_id' => $id ), __METHOD__ );
+               if ( $timestamp === false ) {
+                       # Not in slave, try master
+                       $dbw =& wfGetDB( DB_MASTER );
+                       $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', 
+                               array( 'rev_id' => $id ), __METHOD__ );
+               }
+               return $timestamp;
+       }
 }
 
+/**
+ * Aliases for backwards compatibility with 1.6
+ */
+define( 'MW_REV_DELETED_TEXT', Revision::DELETED_TEXT );
+define( 'MW_REV_DELETED_COMMENT', Revision::DELETED_COMMENT );
+define( 'MW_REV_DELETED_USER', Revision::DELETED_USER );
+define( 'MW_REV_DELETED_RESTRICTED', Revision::DELETED_RESTRICTED );
+
+
 ?>
index c35909e..8fe1f66 100644 (file)
@@ -412,7 +412,7 @@ function ucListEdit( $sk, $row ) {
                }
 
        }
-       if( $rev->userCan( Revision::MW_REV_DELETED_TEXT ) ) {
+       if( $rev->userCan( Revision::DELETED_TEXT ) ) {
                $difftext = '(' . $sk->makeKnownLinkObj( $page, $messages['diff'], 'diff=prev&oldid='.$row->rev_id ) . ')';
        } else {
                $difftext = '(' . $messages['diff'] . ')';
@@ -422,7 +422,7 @@ function ucListEdit( $sk, $row ) {
        $comment = $sk->revComment( $rev );
        $d = $wgLang->timeanddate( wfTimestamp( TS_MW, $row->rev_timestamp ), true );
        
-       if( $rev->isDeleted( Revision::MW_REV_DELETED_TEXT ) ) {
+       if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
                $d = '<span class="history-deleted">' . $d . '</span>';
        }
 
@@ -433,7 +433,7 @@ function ucListEdit( $sk, $row ) {
        }
 
        $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link} {$comment} {$topmarktext}";
-       if( $rev->isDeleted( Revision::MW_REV_DELETED_TEXT ) ) {
+       if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
                $ret .= ' ' . wfMsgHtml( 'deletedrev' );
        }
        $ret = "<li>$ret</li>\n";
index f14e07b..7fa8bbb 100644 (file)
@@ -46,10 +46,10 @@ class RevisionDeleteForm {
                
                $this->skin = $wgUser->getSkin();
                $this->checks = array(
-                       array( 'revdelete-hide-text', 'wpHideText', Revision::MW_REV_DELETED_TEXT ),
-                       array( 'revdelete-hide-comment', 'wpHideComment', Revision::MW_REV_DELETED_COMMENT ),
-                       array( 'revdelete-hide-user', 'wpHideUser', Revision::MW_REV_DELETED_USER ),
-                       array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision::MW_REV_DELETED_RESTRICTED ) );
+                       array( 'revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT ),
+                       array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ),
+                       array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER ),
+                       array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision::DELETED_RESTRICTED ) );
        }
        
        /**
@@ -222,9 +222,9 @@ class RevisionDeleter {
        function updateRecentChanges( $rev, $bitfield ) {
                $this->db->update( 'recentchanges',
                        array(
-                               'rc_user' => ($bitfield & Revision::MW_REV_DELETED_USER) ? 0 : $rev->getUser(),
-                               'rc_user_text' => ($bitfield & Revision::MW_REV_DELETED_USER) ? wfMsg( 'rev-deleted-user' ) : $rev->getUserText(),
-                               'rc_comment' => ($bitfield & Revision::MW_REV_DELETED_COMMENT) ? wfMsg( 'rev-deleted-comment' ) : $rev->getComment() ),
+                               'rc_user' => ($bitfield & Revision::DELETED_USER) ? 0 : $rev->getUser(),
+                               'rc_user_text' => ($bitfield & Revision::DELETED_USER) ? wfMsg( 'rev-deleted-user' ) : $rev->getUserText(),
+                               'rc_comment' => ($bitfield & Revision::DELETED_COMMENT) ? wfMsg( 'rev-deleted-comment' ) : $rev->getComment() ),
                        array(
                                'rc_this_oldid' => $rev->getId() ),
                        'RevisionDeleter::updateRecentChanges' );
index 6c29bc6..ed46c4a 100644 (file)
@@ -2152,11 +2152,11 @@ class Title {
        /**
         * Get the revision ID of the previous revision
         *
-        * @param integer $revision  Revision ID. Get the revision that was before this one.
+        * @param integer $revId  Revision ID. Get the revision that was before this one.
+        * @param string $timestamp The timestamp of the current revision, if known
         * @return interger $oldrevision|false
         */
-       function getPreviousRevisionID( $revision ) {
-               $dbr =& wfGetDB( DB_SLAVE );
+       function getPreviousRevisionID( $revId, $timestamp = false ) {
                return $dbr->selectField( 'revision', 'rev_id',
                        'rev_page=' . intval( $this->getArticleId() ) .
                        ' AND rev_id<' . intval( $revision ) . ' ORDER BY rev_id DESC' );