https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114519

Revision: 114519
Author:   daniel
Date:     2012-03-27 14:07:42 +0000 (Tue, 27 Mar 2012)
Log Message:
-----------
prepare DifferenceEngine for subclassing

Modified Paths:
--------------
    branches/Wikidata/phase3/includes/diff/DifferenceEngine.php

Modified: branches/Wikidata/phase3/includes/diff/DifferenceEngine.php
===================================================================
--- branches/Wikidata/phase3/includes/diff/DifferenceEngine.php 2012-03-27 
14:03:35 UTC (rev 114518)
+++ branches/Wikidata/phase3/includes/diff/DifferenceEngine.php 2012-03-27 
14:07:42 UTC (rev 114519)
@@ -23,7 +23,7 @@
         * @private
         */
        var $mOldid, $mNewid;
-       var $mOldtext, $mNewtext;
+       var $mOldContent, $mNewContent;
        protected $mDiffLang;
 
        /**
@@ -67,7 +67,7 @@
         * @param $refreshCache boolean If set, refreshes the diff cache
         * @param $unhide boolean If set, allow viewing deleted revs
         */
-       function __construct( $context = null, $old = 0, $new = 0, $rcid = 0,  
# FIXME: use Contenthandler::getDifferenceEngine everywhere!
+       function __construct( $context = null, $old = 0, $new = 0, $rcid = 0,
                $refreshCache = false, $unhide = false )
        {
                if ( $context instanceof IContextSource ) {
@@ -486,11 +486,11 @@
                        $out->setRevisionTimestamp( 
$this->mNewRev->getTimestamp() );
                        $out->setArticleFlag( true );
 
-                       if ( $this->mNewPage->isCssJsSubpage() || 
$this->mNewPage->isCssOrJsPage() ) {
+                       if ( $this->mNewPage->isCssJsSubpage() || 
$this->mNewPage->isCssOrJsPage() ) { #FIXME: don't do this, use the content 
handler instead!!
                                // Stolen from Article::view --AG 2007-10-11
                                // Give hooks a chance to customise the output
                                // @TODO: standardize this crap into one 
function
-                               if ( wfRunHooks( 'ShowRawCssJs', array( 
$this->mNewtext, $this->mNewPage, $out ) ) ) {
+                               if ( wfRunHooks( 'ShowRawCssJs', array( 
$this->mNewtext, $this->mNewPage, $out ) ) ) { #FIXME: what to do with this 
hook??
                                        // Wrap the whole lot in a <pre> and 
don't parse
                                        $m = array();
                                        preg_match( '!\.(css|js)$!u', 
$this->mNewPage->getText(), $m );
@@ -498,7 +498,7 @@
                                        $out->addHTML( htmlspecialchars( 
$this->mNewtext ) );
                                        $out->addHTML( "\n</pre>\n" );
                                }
-                       } elseif ( !wfRunHooks( 'ArticleViewCustom', array( 
$this->mNewtext, $this->mNewPage, $out ) ) ) {
+                       } elseif ( !wfRunHooks( 'ArticleViewCustom', array( 
$this->mNewtext, $this->mNewPage, $out ) ) ) { #FIXME: what do we pass here
                                // Handled by extension
                        } else {
                                // Normal page
@@ -630,8 +630,10 @@
                        return false;
                }
 
-               $difftext = $this->generateDiffBody( $this->mOldtext, 
$this->mNewtext );
+        #TODO: make sure both Content objects have the same content model. 
What do we do if they don't?
 
+               $difftext = $this->generateContentDiffBody( $this->mOldContent, 
$this->mNewContent );
+
                // Save to cache for 7 days
                if ( !wfRunHooks( 'AbortDiffCache', array( &$this ) ) ) {
                        wfIncrStats( 'diff_uncacheable' );
@@ -667,13 +669,47 @@
                }
        }
 
+    /**
+     * Generate a diff, no caching.
+     *
+     * Subclasses may override this to provide a
+     *
+     * @param $old Content: old content
+     * @param $new Content: new content
+     */
+    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?
+
+        $otext = $old->serialize();
+        $ntext = $new->serialize();
+
+        #XXX: text should be "already segmented". what does that mean?
+        return $this->generateTextDiffBody( $otext, $ntext );
+    }
+
+    /**
+     * Generate a diff, no caching
+     *
+     * @param $otext String: old text, must be already segmented
+     * @param $ntext String: new text, must be already segmented
+     * @deprecated since 1.20, use generateContentDiffBody() instead!
+     */
+    function generateDiffBody( $otext, $ntext ) {
+        wfDeprecated( __METHOD__, "1.20" );
+
+        return $this->generateTextDiffBody( $otext, $ntext );
+    }
+
        /**
         * Generate a diff, no caching
         *
+     * @todo move this to TextDifferenceEngine, make DifferenceEngine 
abstract. At some point.
+     *
         * @param $otext String: old text, must be already segmented
         * @param $ntext String: new text, must be already segmented
         */
-       function generateDiffBody( $otext, $ntext ) {
+       function generateTextDiffBody( $otext, $ntext ) {
                global $wgExternalDiffEngine, $wgContLang;
 
                wfProfileIn( __METHOD__ );
@@ -927,31 +963,25 @@
         * Use specified text instead of loading from the database
      * @deprecated since 1.20
         */
-       function setText( $oldText, $newText ) {
+       function setText( $oldText, $newText ) { #FIXME: no longer use this, 
use setContent()!
         wfDeprecated( __METHOD__, "1.20" );
-        $this->setText_internal( $oldText, $newText );
+
+        $oldContent = ContentHandler::makeContent( $oldText, $this->getTitle() 
);
+        $newContent = ContentHandler::makeContent( $newText, $this->getTitle() 
);
+
+        $this->setContent( $oldContent, $newContent );
     }
 
     /**
-     * @private
      * Use specified text instead of loading from the database
-     */
-    private function setText_internal( $oldText, $newText ) {
-               $this->mOldtext = $oldText;
-               $this->mNewtext = $newText;
-               $this->mTextLoaded = 2;
-               $this->mRevisionsLoaded = true;
-       }
-
-    /**
-     * Use specified text instead of loading from the database
      * @since 1.20
      */
-    function setContent( Content $oldContent, Content $newContent, $format = 
null ) { #FIXME: use this!
-        $oldText = $oldContent->serialize( $format );
-        $newText = $newContent->serialize( $format );
+    function setContent( Content $oldContent, Content $newContent ) {
+        $this->mOldContent = $oldContent;
+        $this->mNewContent = $newContent;
 
-        return $this->setText_internal( $oldText, $newText );
+        $this->mTextLoaded = 2;
+        $this->mRevisionsLoaded = true;
     }
 
        /**
@@ -1077,14 +1107,14 @@
                        return false;
                }
                if ( $this->mOldRev ) {
-                       $this->mOldtext = $this->mOldRev->getText( 
Revision::FOR_THIS_USER );
-                       if ( $this->mOldtext === false ) {
+                       $this->mOldContent = $this->mOldRev->getContent( 
Revision::FOR_THIS_USER );
+                       if ( $this->mOldContent === false ) {
                                return false;
                        }
                }
                if ( $this->mNewRev ) {
-                       $this->mNewtext = $this->mNewRev->getText( 
Revision::FOR_THIS_USER );
-                       if ( $this->mNewtext === false ) {
+                       $this->mNewContent = $this->mNewRev->getContent( 
Revision::FOR_THIS_USER );
+                       if ( $this->mNewContent === false ) {
                                return false;
                        }
                }
@@ -1105,7 +1135,7 @@
                if ( !$this->loadRevisionData() ) {
                        return false;
                }
-               $this->mNewtext = $this->mNewRev->getText( 
Revision::FOR_THIS_USER );
+               $this->mNewContent = $this->mNewRev->getContent( 
Revision::FOR_THIS_USER );
                return true;
        }
 }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to