Merge "Adding description how to use Special:Redirect"
[lhc/web/wiklou.git] / includes / diff / DifferenceEngine.php
index 0c9086b..ea74164 100644 (file)
@@ -695,24 +695,6 @@ class DifferenceEngine extends ContextSource {
                return $difftext;
        }
 
-       /**
-        * Make sure the proper modules are loaded before we try to
-        * make the diff
-        */
-       private function initDiffEngines() {
-               global $wgExternalDiffEngine;
-               if ( $wgExternalDiffEngine == 'wikidiff' && !function_exists( 'wikidiff_do_diff' ) ) {
-                       wfProfileIn( __METHOD__ . '-php_wikidiff.so' );
-                       wfDl( 'php_wikidiff' );
-                       wfProfileOut( __METHOD__ . '-php_wikidiff.so' );
-               }
-               elseif ( $wgExternalDiffEngine == 'wikidiff2' && !function_exists( 'wikidiff2_do_diff' ) ) {
-                       wfProfileIn( __METHOD__ . '-php_wikidiff2.so' );
-                       wfDl( 'wikidiff2' );
-                       wfProfileOut( __METHOD__ . '-php_wikidiff2.so' );
-               }
-       }
-
        /**
         * Generate a diff, no caching.
         *
@@ -779,8 +761,6 @@ class DifferenceEngine extends ContextSource {
                $otext = str_replace( "\r\n", "\n", $otext );
                $ntext = str_replace( "\r\n", "\n", $ntext );
 
-               $this->initDiffEngines();
-
                if ( $wgExternalDiffEngine == 'wikidiff' && function_exists( 'wikidiff_do_diff' ) ) {
                        # For historical reasons, external diff engine expects
                        # input text to be HTML-escaped already
@@ -1061,6 +1041,33 @@ class DifferenceEngine extends ContextSource {
                $this->mDiffLang = wfGetLangObj( $lang );
        }
 
+       /**
+        * Maps a revision pair definition as accepted by DifferenceEngine constructor
+        * to a pair of actual integers representing revision ids.
+        *
+        * @param int $old Revision id, e.g. from URL parameter 'oldid'
+        * @param int|string $new Revision id or strings 'next' or 'prev', e.g. from URL parameter 'diff'
+        * @return array Array of two revision ids, older first, later second.
+        *     Zero signifies invalid argument passed.
+        *     false signifies that there is no previous/next revision ($old is the oldest/newest one).
+        */
+       public function mapDiffPrevNext( $old, $new ) {
+               if ( $new === 'prev' ) {
+                       // Show diff between revision $old and the previous one. Get previous one from DB.
+                       $newid = intval( $old );
+                       $oldid = $this->getTitle()->getPreviousRevisionID( $newid );
+               } elseif ( $new === 'next' ) {
+                       // Show diff between revision $old and the next one. Get next one from DB.
+                       $oldid = intval( $old );
+                       $newid = $this->getTitle()->getNextRevisionID( $oldid );
+               } else {
+                       $oldid = intval( $old );
+                       $newid = intval( $new );
+               }
+
+               return array( $oldid, $newid );
+       }
+
        /**
         * Load revision IDs
         */
@@ -1074,26 +1081,14 @@ class DifferenceEngine extends ContextSource {
                $old = $this->mOldid;
                $new = $this->mNewid;
 
-               if ( $new === 'prev' ) {
-                       # Show diff between revision $old and the previous one.
-                       # Get previous one from DB.
-                       $this->mNewid = intval( $old );
-                       $this->mOldid = $this->getTitle()->getPreviousRevisionID( $this->mNewid );
-               } elseif ( $new === 'next' ) {
-                       # Show diff between revision $old and the next one.
-                       # Get next one from DB.
-                       $this->mOldid = intval( $old );
-                       $this->mNewid = $this->getTitle()->getNextRevisionID( $this->mOldid );
-                       if ( $this->mNewid === false ) {
-                               # if no result, NewId points to the newest old revision. The only newer
-                               # revision is cur, which is "0".
-                               $this->mNewid = 0;
-                       }
-               } else {
-                       $this->mOldid = intval( $old );
-                       $this->mNewid = intval( $new );
-                       wfRunHooks( 'NewDifferenceEngine', array( $this->getTitle(), &$this->mOldid, &$this->mNewid, $old, $new ) );
+               list( $this->mOldid, $this->mNewid ) = self::mapDiffPrevNext( $old, $new );
+               if ( $new === 'next' && $this->mNewid === false ) {
+                       # if no result, NewId points to the newest old revision. The only newer
+                       # revision is cur, which is "0".
+                       $this->mNewid = 0;
                }
+
+               wfRunHooks( 'NewDifferenceEngine', array( $this->getTitle(), &$this->mOldid, &$this->mNewid, $old, $new ) );
        }
 
        /**