MediaWiki master
TextSlotDiffRenderer Class Reference

Renders a slot diff by doing a text diff on the native representation. More...

Inherits SlotDiffRenderer.

Collaboration diagram for TextSlotDiffRenderer:

Public Member Functions

 getContentModel ()
 Get the content model ID that this renderer acts on.
 
 getDiff (Content $oldContent=null, Content $newContent=null)
 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

 
 getExtraCacheKeys ()
 Return any extra keys to split the diff cache by.
Stability: stable
to override
Returns
string[]

 
 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.

 
 getTextDiff (string $oldText, string $newText)
 Diff the text representations of two content objects (or just two pieces of text in general).
 
 localizeDiff ( $diff, $options=[])
 
 setContentModel (string $contentModel)
 
 setEngine ( $type, $executable=null)
 Set which diff engine to use.
 
 setFormat ( $format)
 Set the TextDiffer format.
 
 setHookContainer (HookContainer $hookContainer)
 
 setInlineToggleEnabled ( $enabled=true)
 Set a flag indicating whether the inline toggle switch is shown.
 
 setLanguage (Language $language)
 This has no effect since MW 1.41.
 
 setStatsdDataFactory (IBufferingStatsdDataFactory $statsdDataFactory)
 
 setTextDiffer (TextDiffer $textDiffer)
 
- Public Member Functions inherited from SlotDiffRenderer
 addModules (OutputPage $output)
 Add modules needed for correct styling/behavior of the diff.
 
 localizeDiff (string $diff, array $options=[])
 Localize language-independent text returned by getDiff(), making it suitable for display.
 

Static Public Member Functions

static diff ( $oldText, $newText, $options=[])
 Convenience helper to use getTextDiff without an instance.
 

Public Attributes

const ENGINE_EXTERNAL = 'external'
 Use an external executable.
 
const ENGINE_PHP = 'php'
 Use the PHP diff implementation (DiffEngine).
 
const ENGINE_WIKIDIFF2 = 'wikidiff2'
 Use the wikidiff2 PHP module.
 
const ENGINE_WIKIDIFF2_INLINE = 'wikidiff2inline'
 Use the wikidiff2 PHP module.
 
const INLINE_LEGEND_KEY = '10_mw-diff-inline-legend'
 
const INLINE_SWITCHER_KEY = '60_mw-diff-inline-switch'
 

Protected Member Functions

 getTextDiffInternal ( $oldText, $newText)
 Diff the text representations of two content objects (or just two pieces of text in general).
 
- Protected Member Functions inherited from SlotDiffRenderer
 normalizeContents (Content &$oldContent=null, Content &$newContent=null, $allowedClasses=null)
 Helper method to normalize the input of getDiff().
 

Detailed Description

Renders a slot diff by doing a text diff on the native representation.

If you want to use this without content objects (to call getTextDiff() on some non-content-related texts), obtain an instance with ContentHandler::getForModelID( CONTENT_MODEL_TEXT ) ->getSlotDiffRenderer( RequestContext::getMain() )

Definition at line 48 of file TextSlotDiffRenderer.php.

Member Function Documentation

◆ diff()

static TextSlotDiffRenderer::diff ( $oldText,
$newText,
$options = [] )
static

Convenience helper to use getTextDiff without an instance.

Parameters
string$oldText
string$newText
array$options
Returns
string

Definition at line 96 of file TextSlotDiffRenderer.php.

References CONTENT_MODEL_TEXT.

◆ getContentModel()

TextSlotDiffRenderer::getContentModel ( )

Get the content model ID that this renderer acts on.

Since
1.41
Returns
string

Definition at line 225 of file TextSlotDiffRenderer.php.

◆ getDiff()

TextSlotDiffRenderer::getDiff ( Content $oldContent = null,
Content $newContent = null )

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

Reimplemented from SlotDiffRenderer.

Definition at line 230 of file TextSlotDiffRenderer.php.

◆ getExtraCacheKeys()

TextSlotDiffRenderer::getExtraCacheKeys ( )

Return any extra keys to split the diff cache by.

Stability: stable
to override
Returns
string[]

Reimplemented from SlotDiffRenderer.

Definition at line 85 of file TextSlotDiffRenderer.php.

◆ getTablePrefix()

TextSlotDiffRenderer::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 from SlotDiffRenderer.

Definition at line 246 of file TextSlotDiffRenderer.php.

References MediaWiki\Title\Title\getLocalURL(), MediaWiki\Context\IContextSource\getRequest(), and MessageLocalizer\msg().

◆ getTextDiff()

TextSlotDiffRenderer::getTextDiff ( string $oldText,
string $newText )

Diff the text representations of two content objects (or just two pieces of text in general).

Parameters
string$oldText
string$newText
Returns
string HTML. One or more

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

Definition at line 292 of file TextSlotDiffRenderer.php.

◆ getTextDiffInternal()

TextSlotDiffRenderer::getTextDiffInternal ( $oldText,
$newText )
protected

Diff the text representations of two content objects (or just two pieces of text in general).

This does the actual diffing, getTextDiff() wraps it with logging and resource limiting.

Parameters
string$oldText
string$newText
Returns
string
Exceptions
Exception

Definition at line 335 of file TextSlotDiffRenderer.php.

◆ localizeDiff()

TextSlotDiffRenderer::localizeDiff ( $diff,
$options = [] )

Definition at line 239 of file TextSlotDiffRenderer.php.

◆ setContentModel()

TextSlotDiffRenderer::setContentModel ( string $contentModel)
Parameters
string$contentModel
Since
1.41

Definition at line 135 of file TextSlotDiffRenderer.php.

◆ setEngine()

TextSlotDiffRenderer::setEngine ( $type,
$executable = null )

Set which diff engine to use.

Parameters
string$typeOne of the ENGINE_* constants.
null$executableMust be null since 1.41. Previously a path to execute.

Definition at line 145 of file TextSlotDiffRenderer.php.

◆ setFormat()

TextSlotDiffRenderer::setFormat ( $format)

Set the TextDiffer format.

Since
1.41
Parameters
string$format

Definition at line 188 of file TextSlotDiffRenderer.php.

◆ setHookContainer()

TextSlotDiffRenderer::setHookContainer ( HookContainer $hookContainer)
Since
1.41
Parameters
HookContainer$hookContainer

Definition at line 127 of file TextSlotDiffRenderer.php.

◆ setInlineToggleEnabled()

TextSlotDiffRenderer::setInlineToggleEnabled ( $enabled = true)

Set a flag indicating whether the inline toggle switch is shown.

Since
1.41
Parameters
bool$enabled

Definition at line 215 of file TextSlotDiffRenderer.php.

◆ setLanguage()

TextSlotDiffRenderer::setLanguage ( Language $language)

This has no effect since MW 1.41.

The language is now injected via setTextDiffer().

Parameters
Language$language
Deprecated
since 1.41

Definition at line 119 of file TextSlotDiffRenderer.php.

References wfDeprecated().

◆ setStatsdDataFactory()

TextSlotDiffRenderer::setStatsdDataFactory ( IBufferingStatsdDataFactory $statsdDataFactory)
Parameters
IBufferingStatsdDataFactory$statsdDataFactory

Definition at line 109 of file TextSlotDiffRenderer.php.

◆ setTextDiffer()

TextSlotDiffRenderer::setTextDiffer ( TextDiffer $textDiffer)
Parameters
TextDiffer$textDiffer

Definition at line 195 of file TextSlotDiffRenderer.php.

Member Data Documentation

◆ ENGINE_EXTERNAL

const TextSlotDiffRenderer::ENGINE_EXTERNAL = 'external'

Use an external executable.

Definition at line 60 of file TextSlotDiffRenderer.php.

◆ ENGINE_PHP

const TextSlotDiffRenderer::ENGINE_PHP = 'php'

Use the PHP diff implementation (DiffEngine).

Definition at line 51 of file TextSlotDiffRenderer.php.

◆ ENGINE_WIKIDIFF2

const TextSlotDiffRenderer::ENGINE_WIKIDIFF2 = 'wikidiff2'

Use the wikidiff2 PHP module.

Definition at line 54 of file TextSlotDiffRenderer.php.

◆ ENGINE_WIKIDIFF2_INLINE

const TextSlotDiffRenderer::ENGINE_WIKIDIFF2_INLINE = 'wikidiff2inline'

Use the wikidiff2 PHP module.

Definition at line 57 of file TextSlotDiffRenderer.php.

◆ INLINE_LEGEND_KEY

const TextSlotDiffRenderer::INLINE_LEGEND_KEY = '10_mw-diff-inline-legend'

Definition at line 62 of file TextSlotDiffRenderer.php.

◆ INLINE_SWITCHER_KEY

const TextSlotDiffRenderer::INLINE_SWITCHER_KEY = '60_mw-diff-inline-switch'

Definition at line 64 of file TextSlotDiffRenderer.php.


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