merge latest master into Wikidata branch
[lhc/web/wiklou.git] / includes / diff / DifferenceEngine.php
index 3a624a8..233e593 100644 (file)
@@ -223,7 +223,11 @@ class DifferenceEngine extends ContextSource {
                # If external diffs are enabled both globally and for the user,
                # we'll use the application/x-external-editor interface to call
                # an external diff tool like kompare, kdiff3, etc.
-               if ( ExternalEdit::useExternalEngine( $this->getContext(), 'diff' ) ) { #FIXME: how to handle this for non-text content?
+               if ( ExternalEdit::useExternalEngine( $this->getContext(), 'diff' ) ) {
+                       //TODO: come up with a good solution for non-text content here.
+                       //      at least, the content format needs to be passed to the client somehow.
+                       //      Currently, action=raw will just fail for non-text content.
+
                        $urls = array(
                                'File' => array( 'Extension' => 'wiki', 'URL' =>
                                        # This should be mOldPage, but it may not be set, see below.
@@ -518,7 +522,7 @@ class DifferenceEngine extends ContextSource {
                                if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
                                        // NOTE: deprecated hook, B/C only
                                        // use the content object's own rendering
-                                       $po = $this->mContentObject->getParserOutput();
+                                       $po = $this->mNewRev->getContent()->getParserOutput( $this->mNewRev->getTitle(), $this->mNewRev->getId() );
                                        $out->addHTML( $po->getText() );
                                }
                        } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
@@ -553,9 +557,7 @@ class DifferenceEngine extends ContextSource {
        }
 
        protected function getParserOutput( WikiPage $page, Revision $rev ) {
-               $parserOptions = ParserOptions::newFromContext( $this->getContext() );
-               $parserOptions->enableLimitReport();
-               $parserOptions->setTidy( true );
+               $parserOptions = $page->makeParserOptions( $this->getContext() );
 
                if ( !$rev->isCurrent() || !$rev->getTitle()->quickUserCan( "edit" ) ) {
                        $parserOptions->setEditSection( false );
@@ -706,16 +708,22 @@ class DifferenceEngine extends ContextSource {
         * @param $old Content: old content
         * @param $new Content: new content
         *
-        * @since 1.WD
+        * @since 1.21
         */
        function generateContentDiffBody( Content $old, Content $new ) {
-               #XXX: generate a warning if $old or $new are not instances of TextContent?
-               #XXX: fail if $old and $new don't have the same content model? or what?
+               if ( !( $old instanceof TextContent ) ) {
+                       throw new MWException( "Diff not implemented for " . get_class( $old ) . "; "
+                                                               . "override generateContentDiffBody to fix this." );
+               }
+
+               if ( !( $new instanceof TextContent ) ) {
+                       throw new MWException( "Diff not implemented for " . get_class( $new ) . "; "
+                               . "override generateContentDiffBody to fix this." );
+               }
 
                $otext = $old->serialize();
                $ntext = $new->serialize();
 
-               #XXX: text should be "already segmented". what does that mean?
                return $this->generateTextDiffBody( $otext, $ntext );
        }
 
@@ -724,10 +732,10 @@ class DifferenceEngine extends ContextSource {
         *
         * @param $otext String: old text, must be already segmented
         * @param $ntext String: new text, must be already segmented
-        * @deprecated since 1.WD, use generateContentDiffBody() instead!
+        * @deprecated since 1.21, use generateContentDiffBody() instead!
         */
        function generateDiffBody( $otext, $ntext ) {
-               wfDeprecated( __METHOD__, "1.WD" );
+               wfDeprecated( __METHOD__, "1.21" );
 
                return $this->generateTextDiffBody( $otext, $ntext );
        }
@@ -960,7 +968,7 @@ class DifferenceEngine extends ContextSource {
 
                if ( !$diff && !$otitle ) {
                        $header .= "
-                       <tr valign='top'>
+                       <tr style='vertical-align: top;'>
                        <td class='diff-ntitle'>{$ntitle}</td>
                        </tr>";
                        $multiColspan = 1;
@@ -978,17 +986,17 @@ class DifferenceEngine extends ContextSource {
                                $multiColspan = 2;
                        }
                        $header .= "
-                       <tr valign='top'>
+                       <tr style='vertical-align: top;'>
                        <td colspan='$colspan' class='diff-otitle'>{$otitle}</td>
                        <td colspan='$colspan' class='diff-ntitle'>{$ntitle}</td>
                        </tr>";
                }
 
                if ( $multi != '' ) {
-                       $header .= "<tr><td colspan='{$multiColspan}' align='center' class='diff-multi'>{$multi}</td></tr>";
+                       $header .= "<tr><td colspan='{$multiColspan}' style='text-align: center;' class='diff-multi'>{$multi}</td></tr>";
                }
                if ( $notice != '' ) {
-                       $header .= "<tr><td colspan='{$multiColspan}' align='center'>{$notice}</td></tr>";
+                       $header .= "<tr><td colspan='{$multiColspan}' style='text-align: center;'>{$notice}</td></tr>";
                }
 
                return $header . $diff . "</table>";
@@ -996,10 +1004,10 @@ class DifferenceEngine extends ContextSource {
 
        /**
         * Use specified text instead of loading from the database
-        * @deprecated since 1.WD
+        * @deprecated since 1.21, use setContent() instead.
         */
-       function setText( $oldText, $newText ) { #FIXME: no longer use this, use setContent()!
-               wfDeprecated( __METHOD__, "1.WD" );
+       function setText( $oldText, $newText ) {
+               wfDeprecated( __METHOD__, "1.21" );
 
                $oldContent = ContentHandler::makeContent( $oldText, $this->getTitle() );
                $newContent = ContentHandler::makeContent( $newText, $this->getTitle() );
@@ -1009,7 +1017,7 @@ class DifferenceEngine extends ContextSource {
 
        /**
         * Use specified text instead of loading from the database
-        * @since 1.WD
+        * @since 1.21
         */
        function setContent( Content $oldContent, Content $newContent ) {
                $this->mOldContent = $oldContent;
@@ -1142,13 +1150,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;
                        }
@@ -1170,7 +1178,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;
        }
 }