* Follow the TODO comment in TextSlotDiffRenderer ::getTextDiffInternal() by moving the code out to three parallel implementations, namely ExternalTextDiffer, PhpTextDiffer and Wikidiff2TextDiffer. * Add a container/factory class ManifoldTextDiffer to glue them together and collate available formats. * Move the inline legend to Wikidiff2TextDiffer. Not the toggle since the ability to toggle depends on the available format, not the current format. * Update the diff cache keys so that ManifoldTextDiffer can store the engine=>format map it used to generate the diff. * Drop support for the second parameter to TextSlotDiffRenderer ::setEngine(), since nothing used it anymore. * Provide a format batch API, since some engines are able to efficiently generate multiple formats. This might be used by DifferenceEngine in future. Needs risky change notification for the cache key change. Bug: T339184 Depends-On: I8a35b9b8ec1622c9a36d2496bdd24f51bc52c85f Change-Id: I5c506e39162855aff53dd420dd8145156739059c
134 lines
3.4 KiB
PHP
134 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Diff\TextDiffer;
|
|
|
|
use OutputPage;
|
|
|
|
/**
|
|
* An interface for parts of a diff page view which represent changes to text
|
|
*
|
|
* @since 1.41
|
|
*/
|
|
interface TextDiffer {
|
|
/**
|
|
* The HTML returned is an ordinary block
|
|
*/
|
|
public const CONTEXT_PLAIN = 'plain';
|
|
|
|
/**
|
|
* The HTML returned is zero or more table rows
|
|
*/
|
|
public const CONTEXT_ROW = 'row';
|
|
|
|
/**
|
|
* Get a stable unique name to identify this differ in a cache key.
|
|
*/
|
|
public function getName(): string;
|
|
|
|
/**
|
|
* Get the supported format names
|
|
*
|
|
* @return string[]
|
|
*/
|
|
public function getFormats(): array;
|
|
|
|
/**
|
|
* Determine whether we support the specified format
|
|
*
|
|
* @param string $format
|
|
* @return bool
|
|
*/
|
|
public function hasFormat( string $format ): bool;
|
|
|
|
/**
|
|
* Get the context for a given format. Returns one of the CONTEXT_* constants.
|
|
*
|
|
* @param string $format
|
|
* @return string
|
|
*/
|
|
public function getFormatContext( string $format );
|
|
|
|
/**
|
|
* Make the context consistent by adding a colspan=4 wrapper around plain
|
|
* HTML output.
|
|
*
|
|
* @param string $format
|
|
* @param string $diffText
|
|
* @return string
|
|
*/
|
|
public function addRowWrapper( string $format, string $diffText ): string;
|
|
|
|
/**
|
|
* Generate a diff comparing $oldText with $newText.
|
|
* The result must be passed through localize() before being sent to the user.
|
|
*
|
|
* @param string $oldText
|
|
* @param string $newText
|
|
* @param string $format
|
|
* @return string
|
|
*/
|
|
public function render( string $oldText, string $newText, string $format ): string;
|
|
|
|
/**
|
|
* Render a diff in multiple formats.
|
|
* The results must be passed through localize() before being sent to the user.
|
|
*
|
|
* @param string $oldText
|
|
* @param string $newText
|
|
* @param string[] $formats
|
|
* @return array An array with the format in the key and the diff in the value.
|
|
*/
|
|
public function renderBatch( string $oldText, string $newText, array $formats ): array;
|
|
|
|
/**
|
|
* Modify the OutputPage, adding any headers required by the specified format.
|
|
*
|
|
* @param OutputPage $out
|
|
* @param string $format
|
|
* @return void
|
|
*/
|
|
public function addModules( OutputPage $out, string $format ): void;
|
|
|
|
/**
|
|
* Get additional cache keys required by the specified formats.
|
|
*
|
|
* The result should have unique string keys, so that cache keys can be
|
|
* deduplicated.
|
|
*
|
|
* @param string[] $formats
|
|
* @return array<string,string>
|
|
*/
|
|
public function getCacheKeys( array $formats ): array;
|
|
|
|
/**
|
|
* Expand messages in the diff text using the current MessageLocalizer.
|
|
*
|
|
* Perform any other necessary post-cache transformations.
|
|
*
|
|
* @param string $format
|
|
* @param string $diff
|
|
* @param array $options An associative array of options, may contain:
|
|
* - reducedLineNumbers: If true, remove "line 1" but allow other line numbers
|
|
* @return string
|
|
*/
|
|
public function localize( string $format, string $diff, array $options = [] ): string;
|
|
|
|
/**
|
|
* Get table prefixes for the specified format. These are HTML fragments
|
|
* placed above all slot diffs. The key should be a string, used for sorting
|
|
* and deduplication.
|
|
*
|
|
* @param string $format
|
|
* @return array
|
|
*/
|
|
public function getTablePrefixes( string $format ): array;
|
|
|
|
/**
|
|
* Given a format, get a list of formats which can be generated at the same
|
|
* time with minimal additional CPU cost.
|
|
*
|
|
* @param string $format
|
|
* @return string[]
|
|
*/
|
|
public function getPreferredFormatBatch( string $format ): array;
|
|
}
|