MediaWiki REL1_41
SlotDiffRenderer Class Reference

Renders a diff for a single slot (that is, a diff between two content objects). More...

Inherited by DifferenceEngineSlotDiffRenderer, TextSlotDiffRenderer, and UnsupportedSlotDiffRenderer.

Public Member Functions

 addModules (OutputPage $output)
 Add modules needed for correct styling/behavior of the diff.
 
 getDiff (Content $oldContent=null, Content $newContent=null)
 Get a diff between two content objects.
 
 getExtraCacheKeys ()
 Return any extra keys to split the diff cache by.
 
 getTablePrefix (IContextSource $context, Title $newTitle)
 Get the content to add above the main diff table.
 
 localizeDiff (string $diff, array $options=[])
 Localize language-independent text returned by getDiff(), making it suitable for display.
 

Protected Member Functions

 normalizeContents (Content &$oldContent=null, Content &$newContent=null, $allowedClasses=null)
 Helper method to normalize the input of getDiff().
 

Detailed Description

Renders a diff for a single slot (that is, a diff between two content objects).

Callers should obtain instances of this class by invoking ContentHandler::getSlotDiffRenderer on the content handler of the new content object (ie. the one shown on the right side of the diff), or of the old one if the new one does not exist.

The default implementation just does a text diff on the native text representation. Content handler extensions can subclass this to provide a more appropriate diff method by overriding ContentHandler::getSlotDiffRendererInternal. Other extensions that want to interfere with diff generation in some way can use the GetSlotDiffRenderer hook.

Stability: stable
to extend

Definition at line 43 of file SlotDiffRenderer.php.

Member Function Documentation

◆ addModules()

SlotDiffRenderer::addModules ( OutputPage $output)

Add modules needed for correct styling/behavior of the diff.

Stability: stable
to override
Parameters
OutputPage$output

Reimplemented in DifferenceEngineSlotDiffRenderer.

Definition at line 88 of file SlotDiffRenderer.php.

◆ getDiff()

SlotDiffRenderer::getDiff ( Content $oldContent = null,
Content $newContent = null )
abstract

Get a diff between two content objects.

One of them might be null (meaning a slot was created or removed), but both cannot be. $newContent (or if it's null then $oldContent) must have the same content model that was used to obtain this diff renderer.

Parameters
Content | null$oldContent
Content | null$newContent
Returns
string HTML. One or more

tags, or an empty string if the inputs are identical.

Exceptions
IncompatibleDiffTypesException

Reimplemented in DifferenceEngineSlotDiffRenderer, TextSlotDiffRenderer, and UnsupportedSlotDiffRenderer.

◆ getExtraCacheKeys()

SlotDiffRenderer::getExtraCacheKeys ( )

Return any extra keys to split the diff cache by.

Stability: stable
to override
Returns
string[]

Reimplemented in DifferenceEngineSlotDiffRenderer, and TextSlotDiffRenderer.

Definition at line 96 of file SlotDiffRenderer.php.

◆ getTablePrefix()

SlotDiffRenderer::getTablePrefix ( IContextSource $context,
Title $newTitle )

Get the content to add above the main diff table.

Since
1.41
Parameters
IContextSource$context
Title$newTitle
Returns
(string|null)[] An array of HTML fragments to assemble into the prefix area. They will be deduplicated and sorted by key.

Reimplemented in TextSlotDiffRenderer.

Definition at line 79 of file SlotDiffRenderer.php.

◆ localizeDiff()

SlotDiffRenderer::localizeDiff ( string $diff,
array $options = [] )

Localize language-independent text returned by getDiff(), making it suitable for display.

Subclasses overriding this should arrange for injection of a MessageLocalizer.

Parameters
string$diff
array$optionsAssociative array of options:
  • reducedLineNumbers: If true, remove "line 1" but allow other line numbers
Returns
string

Definition at line 66 of file SlotDiffRenderer.php.

◆ normalizeContents()

SlotDiffRenderer::normalizeContents ( Content & $oldContent = null,
Content & $newContent = null,
$allowedClasses = null )
protected

Helper method to normalize the input of getDiff().

Verifies that at least one of $oldContent and $newContent is not null, verifies that they are instances of one of the allowed classes (if provided), and replaces null with empty content.

Parameters
Content | null&$oldContent
Content | null&$newContent
string | array | null$allowedClasses
Exceptions
IncompatibleDiffTypesException

Definition at line 110 of file SlotDiffRenderer.php.

Referenced by DifferenceEngineSlotDiffRenderer\getDiff(), and UnsupportedSlotDiffRenderer\getDiff().


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