Moved 'get previous/next revision' code from DifferenceEngine to Title'
authorJens Frank <jeluf@users.mediawiki.org>
Sat, 2 Oct 2004 19:49:54 +0000 (19:49 +0000)
committerJens Frank <jeluf@users.mediawiki.org>
Sat, 2 Oct 2004 19:49:54 +0000 (19:49 +0000)
includes/DifferenceEngine.php
includes/Title.php

index 198c9b3..9276d0f 100644 (file)
@@ -25,11 +25,13 @@ class DifferenceEngine {
                        # Get previous one from DB.
                        #
                        $this->mNewid = intval($old);
-                       $dbr =& wfGetDB( DB_SLAVE );
-                       $this->mOldid = $dbr->selectField( 'old', 'old_id',
-                               "old_title='" . $wgTitle->getDBkey() . "'" .
-                               ' AND old_namespace=' . $wgTitle->getNamespace() .
-                               " AND old_id<{$this->mNewid} ORDER BY old_id DESC" );
+
+                       $this->mOldid = $wgTitle->getPreviousRevisionID( $this->mNewid );
+                       #$dbr =& wfGetDB( DB_SLAVE );
+                       #$this->mOldid = $dbr->selectField( 'old', 'old_id',
+                               #"old_title='" . $wgTitle->getDBkey() . "'" .
+                               #' AND old_namespace=' . $wgTitle->getNamespace() .
+                               #" AND old_id<{$this->mNewid} ORDER BY old_id DESC" );
 
                } elseif ( 'next' == $new ) {
 
@@ -37,11 +39,12 @@ class DifferenceEngine {
                        # Get previous one from DB.
                        #
                        $this->mOldid = intval($old);
-                       $dbr =& wfGetDB( DB_SLAVE );
-                       $this->mNewid = $dbr->selectField( 'old', 'old_id',
-                               "old_title='" . $wgTitle->getDBkey() . "'" .
-                               ' AND old_namespace=' . $wgTitle->getNamespace() .
-                               " AND old_id>{$this->mOldid} ORDER BY old_id " );
+                       $this->mNewid = $wgTitle->getNextRevisionID( $this->mOldid );
+                       #$dbr =& wfGetDB( DB_SLAVE );
+                       #$this->mNewid = $dbr->selectField( 'old', 'old_id',
+                       #       "old_title='" . $wgTitle->getDBkey() . "'" .
+                       #       ' AND old_namespace=' . $wgTitle->getNamespace() .
+                       #       " AND old_id>{$this->mOldid} ORDER BY old_id " );
                        if ( false === $this->mNewid ) {
                                # if no result, NewId points to the newest old revision. The only newer
                                # revision is cur, which is "0".
index 94da807..4adec43 100644 (file)
@@ -1698,5 +1698,34 @@ class Title {
        function oldCond() {
                return array( 'old_namespace' => $this->mNamespace, 'old_title' => $this->mDbkeyform );
        }
+
+       /**
+        * Get the revision ID of the previous revision
+        *
+        * @param integer $revision  Revision ID. Get the revision that was before this one.
+        * @return interger $oldrevision|false
+        */
+       function getPreviousRevisionID( $revision ) {
+               $dbr =& wfGetDB( DB_SLAVE );
+               return $dbr->selectField( 'old', 'old_id',
+                       "old_title='" . $this->getDBkey() . "'" .
+                       ' AND old_namespace=' . $this->getNamespace() .
+                       " AND old_id<{$revision} ORDER BY old_id DESC" );
+       }
+
+       /**
+        * Get the revision ID of the next revision
+        *
+        * @param integer $revision  Revision ID. Get the revision that was after this one.
+        * @return interger $oldrevision|false
+        */
+       function getNextRevisionID( $revision ) {
+               $dbr =& wfGetDB( DB_SLAVE );
+               return $dbr->selectField( 'old', 'old_id',
+                       "old_title='" . $this->getDBkey() . "'" .
+                       ' AND old_namespace=' . $this->getNamespace() .
+                       " AND old_id>{$revision} ORDER BY old_id" );
+       }
+
 }
 ?>