From: daniel Date: Wed, 23 May 2012 07:09:44 +0000 (+0200) Subject: content diff X-Git-Tag: 1.31.0-rc.0~22097^2^2~160 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=881793f84ed7fe49125f5b7ff192fc26f9fcdadc;p=lhc%2Fweb%2Fwiklou.git content diff --- diff --git a/includes/Content.php b/includes/Content.php index 9463c91c61..c270540b22 100644 --- a/includes/Content.php +++ b/includes/Content.php @@ -214,16 +214,13 @@ abstract class Content { } /** - * Diff the content object with what is currently stored in the database. - * If it is not currently stored, it will be diffed with an empty object. + * Diff this content object with another content object.. * * @since WD.diff * - * @return ContentDiff + * @return DiffResult */ - public function diffToDatabase() { - // TODO - } + public abstract function diff( Content $that ); /** * Returns true if this Content objects is conceptually equivalent to the given Content object. @@ -576,6 +573,38 @@ abstract class TextContent extends Content { protected abstract function getHtml( ); + /** + * Diff this content object with another content object.. + * + * @since WD.diff + * + * @param Content $that the other content object to compare this content object to + * @param Language $lang the language object to use for text segmentation. If not given, $wgContentLang is used. + * + * @return DiffResult a diff representing the changes that would have to be made to this content object + * to make it equal to $that. + */ + public function diff( Content $that, Language $lang = null ) { + global $wgContLang; + + $this->checkModelID( $that->getModel() ); + + #@todo: could implement this in DifferenceEngine and just delegate here? + + if ( !$lang ) $lang = $wgContLang; + + $otext = $this->getNativeData(); + $ntext = $this->getNativeData(); + + # Note: Use native PHP diff, external engines don't give us abstract output + $ota = explode( "\n", $wgContLang->segmentForDiff( $otext ) ); + $nta = explode( "\n", $wgContLang->segmentForDiff( $ntext ) ); + + $diffs = new Diff( $ota, $nta ); + return $diff; + } + + } /** diff --git a/includes/diff/DairikiDiff.php b/includes/diff/DairikiDiff.php index 56cee2e2f6..6c706ba811 100644 --- a/includes/diff/DairikiDiff.php +++ b/includes/diff/DairikiDiff.php @@ -751,9 +751,6 @@ class DiffResult { /** * Get the closing set of lines. * - * This reconstructs the $to_lines parameter passed to the - * constructor. - * * @return array The sequence of strings. */ function closing() {