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

Revision: 114244
Author:   daniel
Date:     2012-03-20 10:15:10 +0000 (Tue, 20 Mar 2012)
Log Message:
-----------
getUndoContent()

Modified Paths:
--------------
    branches/Wikidata/phase3/includes/Content.php
    branches/Wikidata/phase3/includes/ContentHandler.php
    branches/Wikidata/phase3/includes/WikiPage.php

Modified: branches/Wikidata/phase3/includes/Content.php
===================================================================
--- branches/Wikidata/phase3/includes/Content.php       2012-03-20 10:07:51 UTC 
(rev 114243)
+++ branches/Wikidata/phase3/includes/Content.php       2012-03-20 10:15:10 UTC 
(rev 114244)
@@ -40,6 +40,14 @@
         return $this->getSize() == 0;
     }
 
+    public function equals( Content $that ) {
+        if ( empty( $that ) ) return false;
+        if ( $that === $this ) return true;
+        if ( $that->getModelName() !== $this->getModelName() ) return false;
+
+        return $this->getNativeData() == $that->getNativeData();
+    }
+
     /**
      * Returns true if this content is countable as a "real" wiki page, 
provided
      * that it's also in a countable location (e.g. a current revision in the 
main namespace).
@@ -93,11 +101,10 @@
     # XXX: isCacheable( ) # can/should we do this here?
 
     # TODO: WikiPage::getUndoText( Revision $undo, Revision $undoafter = null )
-    # TODO: WikiPage::getAutosummary( $oldtext, $text, $flags )
 
     # TODO: EditPage::getPreloadedText( $preload ) // $wgParser->getPreloadText
     # TODO: tie into EditPage, make it use Content-objects throughout, make 
edit form aware of content model and format
-    # TODO: tie into WikiPage, make it use Content-objects throughout, 
especially in doEdit(), doDelete(), etc
+    # TODO: tie into WikiPage, make it use Content-objects throughout, 
especially in doEdit(), doDelete(), updateRevisionOn(), etc
     # TODO: make model-aware diff view!
     # TODO: handle ImagePage and CategoryPage
 

Modified: branches/Wikidata/phase3/includes/ContentHandler.php
===================================================================
--- branches/Wikidata/phase3/includes/ContentHandler.php        2012-03-20 
10:07:51 UTC (rev 114243)
+++ branches/Wikidata/phase3/includes/ContentHandler.php        2012-03-20 
10:15:10 UTC (rev 114244)
@@ -380,9 +380,34 @@
         return $reason;
     }
 
+    /**
+     * Get the Content object that needs to be saved in order to undo all 
revisions
+     * between $undo and $undoafter. Revisions must belong to the same page,
+     * must exist and must not be deleted
+     * @param $undo Revision
+     * @param $undoafter Revision Must be an earlier revision than $undo
+     * @return mixed string on success, false on failure
+     */
+    public function getUndoContent( Revision $current, Revision $undo, 
Revision $undoafter ) {
+        $cur_content = $current->getContent();
 
-    #TODO: cover patch/undo just like merge3.
+        if ( empty( $cur_content ) ) {
+            return false; // no page
+        }
 
+        $undo_content = $undo->getContent();
+        $undoafter_content = $undoafter->getContent();
+
+        if ( $cur_content->equals( $undo_content ) ) {
+            # No use doing a merge if it's just a straight revert.
+            return $undoafter_content;
+        }
+
+        $undone_content = $this->merge3( $undo_content, $undoafter_content, 
$cur_content );
+
+        return $undone_content;
+    }
+
     #TODO: how to handle extra message for JS/CSS previews??
     #TODO: Article::showCssOrJsPage ---> specialized classes!
 

Modified: branches/Wikidata/phase3/includes/WikiPage.php
===================================================================
--- branches/Wikidata/phase3/includes/WikiPage.php      2012-03-20 10:07:51 UTC 
(rev 114243)
+++ branches/Wikidata/phase3/includes/WikiPage.php      2012-03-20 10:15:10 UTC 
(rev 114244)
@@ -424,6 +424,11 @@
                return $this->getText( Revision::RAW );
        }
 
+    /**
+     * Get the content of the current revision. No side-effects...
+     *
+     * @return Contet|false The text of the current revision
+     */
     protected function getNativeData() {
         $content = $this->getContent( Revision::RAW );
         if ( !$content ) return null;
@@ -1097,27 +1102,19 @@
         * @param $undo Revision
         * @param $undoafter Revision Must be an earlier revision than $undo
         * @return mixed string on success, false on failure
+     * @deprecated since 1.20: use ContentHandler::getUndoContent() instead.
         */
-       public function getUndoText( Revision $undo, Revision $undoafter = null 
) { #FIXME: move undo logic to ContentHandler
-               $cur_text = $this->getRawText();
-               if ( $cur_text === false ) {
-                       return false; // no page
-               }
-               $undo_text = $undo->getText();
-               $undoafter_text = $undoafter->getText();
+       public function getUndoText( Revision $undo, Revision $undoafter = null 
) { #FIXME: replace usages.
+        $this->loadLastEdit();
 
-               if ( $cur_text == $undo_text ) {
-                       # No use doing a merge if it's just a straight revert.
-                       return $undoafter_text;
-               }
+        if ( $this->mLastRevision ) {
+            $handler = ContentHandler::getForTitle( $this->getTitle() );
+            $undone = $handler->getUndoContent( $this->mLastRevision, $undo, 
$undoafter );
 
-               $undone_text = '';
+            return ContentHandler::getContentText( $undone );
+        }
 
-               if ( !wfMerge( $undo_text, $undoafter_text, $cur_text, 
$undone_text ) ) {
-                       return false;
-               }
-
-               return $undone_text;
+        return false;
        }
 
        /**


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

Reply via email to