Jdlrobson has uploaded a new change for review. https://gerrit.wikimedia.org/r/300106
Change subject: Mobile diffs should use OneColumnDifferenceEngine in core ...................................................................... Mobile diffs should use OneColumnDifferenceEngine in core InlineDifferenceEngine now extends OneColumnDifferenceEngine to allow us time to upstream/move the remaining methods used by MobileDiff Change-Id: I92ef57a1f1b5b293a4e10d53cecf47d8dd546cdc Depends-On: Ib1b7f17d1099e2efb7edac7ba006e9b763135296 Bug: T117279 --- M extension.json D includes/diff/InlineDiffFormatter.php M includes/diff/InlineDifferenceEngine.php 3 files changed, 1 insertion(+), 182 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/06/300106/1 diff --git a/extension.json b/extension.json index da337ca..442cd10 100644 --- a/extension.json +++ b/extension.json @@ -79,7 +79,6 @@ "MobileUI": "includes/MobileUI.php", "ApiMobileView": "includes/api/ApiMobileView.php", "ApiParseExtender": "includes/api/ApiParseExtender.php", - "InlineDiffFormatter": "includes/diff/InlineDiffFormatter.php", "InlineDifferenceEngine": "includes/diff/InlineDifferenceEngine.php", "MobileSiteModule": "includes/modules/MobileSiteModule.php", "MobileUserModule": "includes/modules/MobileUserModule.php", diff --git a/includes/diff/InlineDiffFormatter.php b/includes/diff/InlineDiffFormatter.php deleted file mode 100644 index 86da38a..0000000 --- a/includes/diff/InlineDiffFormatter.php +++ /dev/null @@ -1,135 +0,0 @@ -<?php -/** - * InlineDiffFormatter.php - */ - -use MediaWiki\Diff\WordAccumulator; - -/** - * Extends standard Table-formatted DiffFormatter of core to enable Inline-Diff - * format of MF with only one column. - */ -class InlineDiffFormatter extends TableDiffFormatter { - /** - * Get the header of diff block. Remember: Given line numbers will not be visible, - * it's a one column diff style. - * @param integer $xbeg line number of left side to compare with - * @param integer $xlen Number of trailing lines after the changed line on left side - * @param integer $ybeg right side line number to compare with - * @param integer $ylen Number of trailing lines after the changed line on right side - * @return string - */ - function blockHeader( $xbeg, $xlen, $ybeg, $ylen ) { - return "<div class=\"mw-diff-inline-header\"><!-- LINES $xbeg,$ybeg --></div>\n"; - } - - /** - * Get a div element with a complete new added line as content. - * Complete line will be appear with green background. - * @param array $lines With changed lines - */ - function added( $lines ) { - foreach ( $lines as $line ) { - $this->writeOutput( '<div class="mw-diff-inline-added"><ins>' - . $this->lineOrNbsp( htmlspecialchars( $line ) ) - . "</ins></div>\n" ); - } - } - - /** - * Get a div with a line which is deleted completly. - * This line will be appear with complete red background. - * @param array $lines With deleted lines - */ - function deleted( $lines ) { - foreach ( $lines as $line ) { - $this->writeOutput( '<div class="mw-diff-inline-deleted"><del>' - . $this->lineOrNbsp( htmlspecialchars( $line ) ) - . "</del></div>\n" ); - } - } - - /** - * Get a div with some changed content. - * Line will appear with white and the changed context in - * red (for deleted chars) and green (for added chars) background. - * @param array $lines With edited lines - */ - function context( $lines ) { - foreach ( $lines as $line ) { - $this->writeOutput( "<div class=\"mw-diff-inline-context\">" . - "{$this->contextLine( htmlspecialchars( $line ) )}</div>\n" ); - } - } - - /** - * Convert all spaces to a forced blank. If line is empty creates at least one - * forced space. - * @param string $marker Unused - * @param string $class Unused - * @param string $line Content of the line - * @return string - */ - protected function wrapLine( $marker, $class, $line ) { - // The <div> wrapper is needed for 'overflow: auto' style to scroll properly - $this->escapeWhiteSpace( $this->lineOrNbsp( $line ) ); - - return $line; - } - - /** - * Adds a forced blank to line, if the line is empty. - * @param string $line - * - * @return string - */ - protected function lineOrNbsp( $line ) { - if ( $line === '' ) { - $line = ' '; - } - - return $line; - } - - /** - * Get a div with changed content (not complete added or deleted line) - * @param string[] $orig Old content to compare with - * @param string[] $closing New content to compare with - */ - function changed( $orig, $closing ) { - $this->writeOutput( '<div class="mw-diff-inline-changed">' ); - $diff = new WordLevelDiff( $orig, $closing ); - $edits = $this->inlineWordDiff( $diff ); - - # WordLevelDiff returns already HTML-escaped output. - $this->writeOutput( implode( '', $edits ) ); - - $this->writeOutput( "</div>\n" ); - } - - /** - * Builds the string of deleted and added words from the given diff. - * @param WordLevelDiff $diff - * @return array Array of changed lines - */ - private function inlineWordDiff( $diff ) { - $inline = new WordAccumulator; - $inline->insClass = $inline->delClass = ''; - - foreach ( $diff->edits as $edit ) { - if ( $edit->type == 'copy' ) { - $inline->addWords( $edit->orig ); - } elseif ( $edit->type == 'delete' ) { - $inline->addWords( $edit->orig, 'del' ); - } elseif ( $edit->type == 'add' ) { - $inline->addWords( $edit->closing, 'ins' ); - } else { - $inline->addWords( $edit->orig, 'del' ); - $inline->addWords( $edit->closing, 'ins' ); - } - } - $lines = $inline->getLines(); - - return $lines; - } -} diff --git a/includes/diff/InlineDifferenceEngine.php b/includes/diff/InlineDifferenceEngine.php index 8a43451..e78e6c2 100644 --- a/includes/diff/InlineDifferenceEngine.php +++ b/includes/diff/InlineDifferenceEngine.php @@ -7,7 +7,7 @@ * Extends the basic DifferenceEngine from core to enable inline difference view * using only one column instead of two column diff system. */ -class InlineDifferenceEngine extends DifferenceEngine { +class InlineDifferenceEngine extends OneColumnDifferenceEngine { /** * Checks whether the given Revision was deleted * @todo FIXME: Upstream to DifferenceEngine - refactor showDiffPage @@ -104,51 +104,6 @@ } } return $msg; - } - - /** - * Creates an inline diff - * @param Content $otext Old content - * @param Content $ntext New content - * - * @return string - */ - function generateTextDiffBody( $otext, $ntext ) { - global $wgContLang; - - # First try wikidiff2 - if ( function_exists( 'wikidiff2_inline_diff' ) ) { - $text = wikidiff2_inline_diff( $otext, $ntext, 2 ); - $text .= $this->debug( 'wikidiff2-inline' ); - - return $text; - } - - # Else slow native PHP diff - $ota = explode( "\n", $wgContLang->segmentForDiff( $otext ) ); - $nta = explode( "\n", $wgContLang->segmentForDiff( $ntext ) ); - $diffs = new Diff( $ota, $nta ); - $formatter = new InlineDiffFormatter(); - $difftext = $wgContLang->unsegmentForDiff( $formatter->format( $diffs ) ); - - return $difftext; - } - - /** - * Reimplements getDiffBodyCacheKey from DifferenceEngine - * Returns the cache key for diff body text or content. - * - * @throws Exception when no mOldid and mNewid is set - * @see DifferenceEngine:getDiffBodyCacheKey - * @return string - */ - protected function getDiffBodyCacheKey() { - if ( !$this->mOldid || !$this->mNewid ) { - throw new Exception( 'mOldid and mNewid must be set to get diff cache key.' ); - } - - return wfMemcKey( 'diff', 'inline', MW_DIFF_VERSION, - 'oldid', $this->mOldid, 'newid', $this->mNewid ); } /** -- To view, visit https://gerrit.wikimedia.org/r/300106 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I92ef57a1f1b5b293a4e10d53cecf47d8dd546cdc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits