MediaWiki master
MediaWiki\Diff\TextDiffer\BaseTextDiffer Class Reference

The base class for specific implementations of TextDiffer, apart from ManifoldTextDiffer. More...

Inherits MediaWiki\Diff\TextDiffer\TextDiffer.

Inherited by MediaWiki\Diff\TextDiffer\ExternalTextDiffer, MediaWiki\Diff\TextDiffer\PhpTextDiffer, and MediaWiki\Diff\TextDiffer\Wikidiff2TextDiffer.

Collaboration diagram for MediaWiki\Diff\TextDiffer\BaseTextDiffer:

Public Member Functions

 addModules (OutputPage $out, string $format)
 Modify the OutputPage, adding any headers required by the specified format.
 
 addRowWrapper (string $format, string $diffText)
 Make the context consistent by adding a colspan=4 wrapper around plain HTML output.
 
 getCacheKeys (array $formats)
 Get additional cache keys required by the specified formats.
 
 getPreferredFormatBatch (string $format)
 Given a format, get a list of formats which can be generated at the same time with minimal additional CPU cost.
 
 getTablePrefixes (string $format)
 Get table prefixes for the specified format.
 
 hasFormat (string $format)
 Determine whether we support the specified format.
 
 localize (string $format, string $diff, array $options=[])
 Expand messages in the diff text using the current MessageLocalizer.
 
 render (string $oldText, string $newText, string $format)
 Generate a diff comparing $oldText with $newText.
 
 renderBatch (string $oldText, string $newText, array $formats)
 Render a diff in multiple formats.
 
 setLocalizer (MessageLocalizer $localizer)
 
- Public Member Functions inherited from MediaWiki\Diff\TextDiffer\TextDiffer
 getFormatContext (string $format)
 Get the context for a given format.
 
 getFormats ()
 Get the supported format names.
 
 getName ()
 Get a stable unique name to identify this differ in a cache key.
 

Protected Member Functions

 doRenderBatch (string $oldText, string $newText, array $formats)
 Subclasses should override this to render diffs in the specified formats.
 
 getLocalizer ()
 Provide a MessageLocalizer, or throw if setLocalizer() has not been called.
 
 localizeLineNumbers ( $text, $reducedLineNumbers)
 Replace a common convention for language-independent line numbers with the text in the language of the current localizer.
 
 validateFormats ( $formats)
 Throw an exception if any of the formats in the array is not supported.
 

Additional Inherited Members

- Public Attributes inherited from MediaWiki\Diff\TextDiffer\TextDiffer
const CONTEXT_PLAIN = 'plain'
 The HTML returned is an ordinary block.
 
const CONTEXT_PRE = 'pre'
 The return value is plain text and should be wrapped in a.
 
const CONTEXT_ROW = 'row'
 The HTML returned is zero or more table rows.
 

Detailed Description

The base class for specific implementations of TextDiffer, apart from ManifoldTextDiffer.

A place for protected utility functions.

Since
1.41

Definition at line 18 of file BaseTextDiffer.php.

Member Function Documentation

◆ addModules()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::addModules ( OutputPage $out,
string $format )

Modify the OutputPage, adding any headers required by the specified format.

Parameters
OutputPage$out
string$format
Returns
void

Implements MediaWiki\Diff\TextDiffer\TextDiffer.

Definition at line 94 of file BaseTextDiffer.php.

◆ addRowWrapper()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::addRowWrapper ( string $format,
string $diffText )

Make the context consistent by adding a colspan=4 wrapper around plain HTML output.

Parameters
string$format
string$diffText
Returns
string

Implements MediaWiki\Diff\TextDiffer\TextDiffer.

Definition at line 44 of file BaseTextDiffer.php.

◆ doRenderBatch()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::doRenderBatch ( string $oldText,
string $newText,
array $formats )
abstractprotected

Subclasses should override this to render diffs in the specified formats.

The $formats array is guaranteed to not be empty and to contain only formats supported by the subclass.

Parameters
string$oldText
string$newText
array$formats
Returns
array

Reimplemented in MediaWiki\Diff\TextDiffer\ExternalTextDiffer, MediaWiki\Diff\TextDiffer\PhpTextDiffer, and MediaWiki\Diff\TextDiffer\Wikidiff2TextDiffer.

◆ getCacheKeys()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::getCacheKeys ( array $formats)

Get additional cache keys required by the specified formats.

The result should have unique string keys, so that cache keys can be deduplicated.

Parameters
string[]$formats
Returns
array<string,string>

Implements MediaWiki\Diff\TextDiffer\TextDiffer.

Reimplemented in MediaWiki\Diff\TextDiffer\Wikidiff2TextDiffer.

Definition at line 97 of file BaseTextDiffer.php.

◆ getLocalizer()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::getLocalizer ( )
protected

Provide a MessageLocalizer, or throw if setLocalizer() has not been called.

Returns
MessageLocalizer

Definition at line 36 of file BaseTextDiffer.php.

◆ getPreferredFormatBatch()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::getPreferredFormatBatch ( string $format)

Given a format, get a list of formats which can be generated at the same time with minimal additional CPU cost.

Parameters
string$format
Returns
string[]

Implements MediaWiki\Diff\TextDiffer\TextDiffer.

Reimplemented in MediaWiki\Diff\TextDiffer\Wikidiff2TextDiffer.

Definition at line 109 of file BaseTextDiffer.php.

◆ getTablePrefixes()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::getTablePrefixes ( string $format)

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.

Parameters
string$format
Returns
array

Implements MediaWiki\Diff\TextDiffer\TextDiffer.

Reimplemented in MediaWiki\Diff\TextDiffer\Wikidiff2TextDiffer.

Definition at line 105 of file BaseTextDiffer.php.

◆ hasFormat()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::hasFormat ( string $format)

Determine whether we support the specified format.

Parameters
string$format
Returns
bool

Implements MediaWiki\Diff\TextDiffer\TextDiffer.

Definition at line 40 of file BaseTextDiffer.php.

◆ localize()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::localize ( string $format,
string $diff,
array $options = [] )

Expand messages in the diff text using the current MessageLocalizer.

Perform any other necessary post-cache transformations.

Parameters
string$format
string$diff
array$optionsAn associative array of options, may contain:
  • reducedLineNumbers: If true, remove "line 1" but allow other line numbers
Returns
string

Implements MediaWiki\Diff\TextDiffer\TextDiffer.

Reimplemented in MediaWiki\Diff\TextDiffer\PhpTextDiffer, and MediaWiki\Diff\TextDiffer\Wikidiff2TextDiffer.

Definition at line 101 of file BaseTextDiffer.php.

◆ localizeLineNumbers()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::localizeLineNumbers ( $text,
$reducedLineNumbers )
protected

Replace a common convention for language-independent line numbers with the text in the language of the current localizer.

Parameters
string$text
bool$reducedLineNumbers
Returns
string

Definition at line 122 of file BaseTextDiffer.php.

References $matches.

◆ render()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::render ( string $oldText,
string $newText,
string $format )

Generate a diff comparing $oldText with $newText.

The result must be passed through localize() before being sent to the user.

Parameters
string$oldText
string$newText
string$format
Returns
string

Implements MediaWiki\Diff\TextDiffer\TextDiffer.

Definition at line 69 of file BaseTextDiffer.php.

◆ renderBatch()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::renderBatch ( string $oldText,
string $newText,
array $formats )

Render a diff in multiple formats.

The results must be passed through localize() before being sent to the user.

Parameters
string$oldText
string$newText
string[]$formats
Returns
array An array with the format in the key and the diff in the value.

Implements MediaWiki\Diff\TextDiffer\TextDiffer.

Definition at line 74 of file BaseTextDiffer.php.

◆ setLocalizer()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::setLocalizer ( MessageLocalizer $localizer)
Parameters
MessageLocalizer$localizer

Definition at line 25 of file BaseTextDiffer.php.

◆ validateFormats()

MediaWiki\Diff\TextDiffer\BaseTextDiffer::validateFormats ( $formats)
protected

Throw an exception if any of the formats in the array is not supported.

Parameters
string[]$formats

Definition at line 62 of file BaseTextDiffer.php.


The documentation for this class was generated from the following file: