MediaWiki  1.33.0
TextSlotDiffRenderer Class Reference

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

Inheritance diagram for TextSlotDiffRenderer:
Collaboration diagram for TextSlotDiffRenderer:

Public Member Functions

 getDiff (Content $oldContent=null, Content $newContent=null)
 @inheritDoc More...
 
 getTextDiff ( $oldText, $newText)
 Diff the text representations of two content objects (or just two pieces of text in general). More...
 
 setEngine ( $type, $executable=null)
 Set which diff engine to use. More...
 
 setLanguage (Language $language)
 
 setStatsdDataFactory (IBufferingStatsdDataFactory $statsdDataFactory)
 
 setWikiDiff2MovedParagraphDetectionCutoff ( $cutoff)
 
- Public Member Functions inherited from SlotDiffRenderer
 addModules (OutputPage $output)
 Add modules needed for correct styling/behavior of the diff. More...
 
 getExtraCacheKeys ()
 Return any extra keys to split the diff cache by. More...
 

Static Public Member Functions

static diff ( $oldText, $newText)
 Convenience helper to use getTextDiff without an instance. More...
 

Public Attributes

const ENGINE_EXTERNAL = 'external'
 Use an external executable. More...
 
const ENGINE_PHP = 'php'
 Use the PHP diff implementation (DiffEngine). More...
 
const ENGINE_WIKIDIFF2 = 'wikidiff2'
 Use the wikidiff2 PHP module. More...
 

Protected Member Functions

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

Private Attributes

string $engine = self::ENGINE_PHP
 One of the ENGINE_* constants. More...
 
string $externalEngine
 Path to an executable to be used as the diff engine. More...
 
Language null $language
 The language this content is in. More...
 
IBufferingStatsdDataFactory null $statsdDataFactory
 
int $wikiDiff2MovedParagraphDetectionCutoff = 0
 Number of paragraph moves the algorithm should attempt to detect. More...
 

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 37 of file TextSlotDiffRenderer.php.

Member Function Documentation

◆ diff()

static TextSlotDiffRenderer::diff (   $oldText,
  $newText 
)
static

Convenience helper to use getTextDiff without an instance.

Parameters
string$oldText
string$newText
Returns
string

Definition at line 74 of file TextSlotDiffRenderer.php.

References CONTENT_MODEL_TEXT, ContentHandler\getForModelID(), and RequestContext\getMain().

◆ getDiff()

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

@inheritDoc

Reimplemented from SlotDiffRenderer.

Definition at line 119 of file TextSlotDiffRenderer.php.

References class, getTextDiff(), and SlotDiffRenderer\normalizeContents().

◆ getTextDiff()

TextSlotDiffRenderer::getTextDiff (   $oldText,
  $newText 
)

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

Parameters
string$oldText
string$newText
Returns
string

Definition at line 134 of file TextSlotDiffRenderer.php.

References $time, getTextDiffInternal(), and use.

Referenced by getDiff().

◆ 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 188 of file TextSlotDiffRenderer.php.

References $externalEngine, language(), wfEscapeWikiText(), and wfTempDir().

Referenced by getTextDiff().

◆ setEngine()

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

Set which diff engine to use.

Parameters
string$typeOne of the ENGINE_* constants.
string | null$executablePath to an external exectable, only when type is ENGINE_EXTERNAL.

Definition at line 103 of file TextSlotDiffRenderer.php.

References $type, ENGINE_EXTERNAL, ENGINE_PHP, and ENGINE_WIKIDIFF2.

◆ setLanguage()

TextSlotDiffRenderer::setLanguage ( Language  $language)

Definition at line 85 of file TextSlotDiffRenderer.php.

References $language, and language().

◆ setStatsdDataFactory()

TextSlotDiffRenderer::setStatsdDataFactory ( IBufferingStatsdDataFactory  $statsdDataFactory)

Definition at line 81 of file TextSlotDiffRenderer.php.

References $statsdDataFactory.

◆ setWikiDiff2MovedParagraphDetectionCutoff()

TextSlotDiffRenderer::setWikiDiff2MovedParagraphDetectionCutoff (   $cutoff)
Parameters
int$cutoff
See also
$wgWikiDiff2MovedParagraphDetectionCutoff

Definition at line 93 of file TextSlotDiffRenderer.php.

Member Data Documentation

◆ $engine

string TextSlotDiffRenderer::$engine = self::ENGINE_PHP
private

One of the ENGINE_* constants.

Definition at line 63 of file TextSlotDiffRenderer.php.

◆ $externalEngine

string TextSlotDiffRenderer::$externalEngine
private

Path to an executable to be used as the diff engine.

Definition at line 66 of file TextSlotDiffRenderer.php.

Referenced by getTextDiffInternal().

◆ $language

Language null TextSlotDiffRenderer::$language
private

The language this content is in.

Definition at line 52 of file TextSlotDiffRenderer.php.

Referenced by setLanguage().

◆ $statsdDataFactory

IBufferingStatsdDataFactory null TextSlotDiffRenderer::$statsdDataFactory
private

Definition at line 49 of file TextSlotDiffRenderer.php.

Referenced by setStatsdDataFactory().

◆ $wikiDiff2MovedParagraphDetectionCutoff

int TextSlotDiffRenderer::$wikiDiff2MovedParagraphDetectionCutoff = 0
private

Number of paragraph moves the algorithm should attempt to detect.

Only used with the wikidiff2 engine.

See also
$wgWikiDiff2MovedParagraphDetectionCutoff

Definition at line 60 of file TextSlotDiffRenderer.php.

◆ ENGINE_EXTERNAL

const TextSlotDiffRenderer::ENGINE_EXTERNAL = 'external'

Use an external executable.

Definition at line 46 of file TextSlotDiffRenderer.php.

Referenced by ContentHandler\getSlotDiffRendererInternal(), and setEngine().

◆ ENGINE_PHP

const TextSlotDiffRenderer::ENGINE_PHP = 'php'

◆ ENGINE_WIKIDIFF2

const TextSlotDiffRenderer::ENGINE_WIKIDIFF2 = 'wikidiff2'

Use the wikidiff2 PHP module.

Definition at line 43 of file TextSlotDiffRenderer.php.

Referenced by ContentHandler\getSlotDiffRendererInternal(), and setEngine().


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