Merge "Use selectRow when load one ArchivedFile"
[lhc/web/wiklou.git] / includes / diff / DifferenceEngine.php
index 48723a1..f3dc5a3 100644 (file)
@@ -544,8 +544,19 @@ class DifferenceEngine extends ContextSource {
 
                                $parserOutput = $this->getParserOutput( $wikiPage, $this->mNewRev );
 
-                               # WikiPage::getParserOutput() should not return false, but just in case
-                               if( $parserOutput ) {
+                               # Also try to load it as a redirect
+                               $rt = $this->mNewContent->getRedirectTarget();
+
+                               if ( $rt ) {
+                                       $article = Article::newFromTitle( $this->mNewPage, $this->getContext() );
+                                       $out->addHTML( $article->viewRedirect( $rt ) );
+
+                                       # WikiPage::getParserOutput() should not return false, but just in case
+                                       if ( $parserOutput ) {
+                                               # Show categories etc.
+                                               $out->addParserOutputNoText( $parserOutput );
+                                       }
+                               } else if ( $parserOutput ) {
                                        $out->addParserOutput( $parserOutput );
                                }
                        }
@@ -703,17 +714,24 @@ class DifferenceEngine extends ContextSource {
        /**
         * Generate a diff, no caching.
         *
-        * Subclasses may override this to provide a
+        * This implementation uses generateTextDiffBody() to generate a diff based on the default
+        * serialization of the given Content objects. This will fail if $old or $new are not
+        * instances of TextContent.
+        *
+        * Subclasses may override this to provide a different rendering for the diff,
+        * perhaps taking advantage of the content's native form. This is required for all content
+        * models that are not text based.
         *
         * @param $old Content: old content
         * @param $new Content: new content
         *
         * @since 1.21
+        * @throws MWException if $old or $new are not instances of TextContent.
         */
        function generateContentDiffBody( Content $old, Content $new ) {
                if ( !( $old instanceof TextContent ) ) {
                        throw new MWException( "Diff not implemented for " . get_class( $old ) . "; "
-                                                               . "override generateContentDiffBody to fix this." );
+                                       . "override generateContentDiffBody to fix this." );
                }
 
                if ( !( $new instanceof TextContent ) ) {
@@ -735,7 +753,7 @@ class DifferenceEngine extends ContextSource {
         * @deprecated since 1.21, use generateContentDiffBody() instead!
         */
        function generateDiffBody( $otext, $ntext ) {
-               wfDeprecated( __METHOD__, "1.21" );
+               ContentHandler::deprecated( __METHOD__, "1.21" );
 
                return $this->generateTextDiffBody( $otext, $ntext );
        }
@@ -1007,7 +1025,7 @@ class DifferenceEngine extends ContextSource {
         * @deprecated since 1.21, use setContent() instead.
         */
        function setText( $oldText, $newText ) {
-               wfDeprecated( __METHOD__, "1.21" );
+               ContentHandler::deprecated( __METHOD__, "1.21" );
 
                $oldContent = ContentHandler::makeContent( $oldText, $this->getTitle() );
                $newContent = ContentHandler::makeContent( $newText, $this->getTitle() );
@@ -1150,13 +1168,13 @@ class DifferenceEngine extends ContextSource {
                        return false;
                }
                if ( $this->mOldRev ) {
-                       $this->mOldContent = $this->mOldRev->getContent( Revision::FOR_THIS_USER );
+                       $this->mOldContent = $this->mOldRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
                        if ( $this->mOldContent === false ) {
                                return false;
                        }
                }
                if ( $this->mNewRev ) {
-                       $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER );
+                       $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
                        if ( $this->mNewContent === false ) {
                                return false;
                        }
@@ -1178,7 +1196,7 @@ class DifferenceEngine extends ContextSource {
                if ( !$this->loadRevisionData() ) {
                        return false;
                }
-               $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER );
+               $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
                return true;
        }
 }