MediaWiki REL1_32
DifferenceEngine Class Reference

DifferenceEngine is responsible for rendering the difference between two revisions as HTML. More...

Inheritance diagram for DifferenceEngine:
Collaboration diagram for DifferenceEngine:

Public Member Functions

 __construct ( $context=null, $old=0, $new=0, $rcid=0, $refreshCache=false, $unhide=false)
 #-
 
 addHeader ( $diff, $otitle, $ntitle, $multi='', $notice='')
 Add the header to a diff body.
 
 deletedIdMarker ( $id)
 Build a wikitext link toward a deleted revision, if viewable.
 
 deletedLink ( $id)
 Look up a special:Undelete link to the given deleted revision id, as a workaround for being unable to load deleted diffs in currently.
 
 generateContentDiffBody (Content $old, Content $new)
 Generate a diff, no caching.
 
 generateTextDiffBody ( $otext, $ntext)
 Generate a diff, no caching.
 
 getDiff ( $otitle, $ntitle, $notice='')
 Get complete diff table, including header.
 
 getDiffBody ()
 Get the diff table body, without header.
 
 getDiffBodyForRole ( $role)
 Get the diff table body for one slot, without header.
 
 getDiffLang ()
 Get the language of the difference engine, defaults to page content language.
 
 getExtraCacheKeys ()
 Implements DifferenceEngineSlotDiffRenderer::getExtraCacheKeys().
 
 getMultiNotice ()
 If there are revisions between the ones being compared, return a note saying so.
 
 getNewid ()
 Get the ID of new revision (right pane) of the diff.
 
 getNewRevision ()
 Get the right side of the diff.
 
 getOldid ()
 Get the ID of old revision (left pane) of the diff.
 
 getOldRevision ()
 Get the left side of the diff.
 
 getRevisionHeader (Revision $rev, $complete='')
 Get a header for a specified revision.
 
 getTitle ()
 
 loadNewText ()
 Load the text of the new revision, not the old one.
 
 loadRevisionData ()
 Load revision metadata for the specified revisions.
 
 loadText ()
 Load the text of the revisions, as well as revision data.
 
 localiseLineNumbers ( $text)
 Replace line numbers with the text in the user's language.
 
 localiseLineNumbersCb ( $matches)
 
 mapDiffPrevNext ( $old, $new)
 Maps a revision pair definition as accepted by DifferenceEngine constructor to a pair of actual integers representing revision ids.
 
 markAsSlotDiffRenderer ()
 Mark this DifferenceEngine as a slot renderer (as opposed to a page renderer).
 
 markPatrolledLink ()
 Build a link to mark a change as patrolled.
 
 renderNewRevision ()
 Show the new revision of the page.
 
 setContent (Content $oldContent, Content $newContent)
 Use specified text instead of loading from the database.
 
 setReducedLineNumbers ( $value=true)
 Set reduced line numbers mode.
 
 setRevisions (RevisionRecord $oldRevision=null, RevisionRecord $newRevision)
 Use specified text instead of loading from the database.
 
 setTextLanguage ( $lang)
 Set the language in which the diff text is written.
 
 showDiff ( $otitle, $ntitle, $notice='')
 Get the diff text, send it to the OutputPage object Returns false if the diff could not be generated, otherwise returns true.
 
 showDiffPage ( $diffOnly=false)
 
 showDiffStyle ()
 Add style sheets for diff display.
 
 wasCacheHit ()
 
- Public Member Functions inherited from ContextSource
 canUseWikiPage ()
 Check whether a WikiPage object can be get with getWikiPage().
 
 exportSession ()
 Export the resolved user IP, HTTP headers, user ID, and session ID.
 
 getConfig ()
 
 getContext ()
 Get the base IContextSource object.
 
 getLanguage ()
 
 getOutput ()
 
 getRequest ()
 
 getSkin ()
 
 getStats ()
 
 getTiming ()
 
 getUser ()
 
 getWikiPage ()
 Get the WikiPage object.
 
 msg ( $key)
 Get a Message object with context set Parameters are the same as wfMessage()
 
 setContext (IContextSource $context)
 

Static Public Member Functions

static getEngine ()
 Process $wgExternalDiffEngine and get a sane, usable engine.
 
static intermediateEditsMsg ( $numEdits, $numUsers, $limit)
 Get a notice about how many intermediate edits and users there are.
 

Public Attributes

 $enableDebugComment = false
 Set this to true to add debug info to the HTML output.
 
const DIFF_VERSION = '1.12'
 Constant to indicate diff cache compatibility.
 

Protected Member Functions

 debug ( $generator="internal")
 Generate a debug comment indicating diff generating time, server node, and generator backend.
 
 getDiffBodyCacheKey ()
 Returns the cache key for diff body text or content.
 
 getDiffBodyCacheKeyParams ()
 Get the cache key parameters.
 
 getMarkPatrolledLinkInfo ()
 Returns an array of meta data needed to build a "mark as patrolled" link and adds the mediawiki.page.patrol.ajax to the output.
 
 getParserOutput (WikiPage $page, Revision $rev)
 
 getSlotContents ()
 Get the old and new content objects for all slots.
 
 getSlotDiffRenderers ()
 
 getSlotHeader ( $headerText)
 Get a slot header for inclusion in a diff body (as a table row).
 
 revisionDeleteLink ( $rev)
 
 textDiff ( $otext, $ntext)
 Generates diff, to be wrapped internally in a logging/instrumentation.
 

Protected Attributes

bool $isContentOverridden = false
 Was the content overridden via setContent()? If the content was overridden, most internal state (e.g.
 
bool $isSlotDiffRenderer = false
 Temporary hack for B/C while slot diff related methods of DifferenceEngine are being deprecated.
 
bool $mCacheHit = false
 Was the diff fetched from cache?
 
Language $mDiffLang
 
string $mMarkPatrolledLink = null
 Link to action=markpatrolled.
 
int string false null $mNewid
 Revision ID for the new revision.
 
Title null $mNewPage
 Title of $mNewRev or null if the new revision does not exist or does not belong to a page.
 
Revision null $mNewRev
 New revision (right pane).
 
int false null $mOldid
 Revision ID for the old revision.
 
Title null $mOldPage
 Title of $mOldRev or null if the old revision does not exist or does not belong to a page.
 
Revision null false $mOldRev
 Old revision (left pane).
 
bool $mReducedLineNumbers = false
 If true, line X is not displayed when X is 1, for example to increase readability and conserve space with many small diffs.
 
bool $mRefreshCache = false
 Refresh the diff cache.
 
bool $mRevisionsLoaded = false
 Have the revisions been loaded.
 
int $mTextLoaded = 0
 How many text blobs have been loaded, 0, 1 or 2?
 
SlotDiffRenderer[] $slotDiffRenderers = null
 DifferenceEngine classes for the slots, keyed by role name.
 
bool $unhide = false
 Show rev_deleted content if allowed.
 

Private Member Functions

 addLocalisedTitleTooltips ( $text)
 Add title attributes for tooltips on moved paragraph indicators.
 
 addLocalisedTitleTooltipsCb (array $matches)
 
 getDebugString ()
 
 loadRevisionIds ()
 Load revision IDs.
 
 localiseDiff ( $text)
 Localise diff output.
 
 showMissingRevision ()
 

Private Attributes

Content null $mNewContent
 
string[] null $mNewTags
 Change tags of $mNewRev or null if it does not exist / is not saved.
 
Content null $mOldContent
 
string[] null $mOldTags
 Change tags of $mOldRev or null if it does not exist / is not saved.
 
bool $mRevisionsIdsLoaded = false
 Have the revisions IDs been loaded.
 

Detailed Description

DifferenceEngine is responsible for rendering the difference between two revisions as HTML.

This includes interpreting URL parameters, retrieving revision data, checking access permissions, selecting and invoking the diff generator class for the individual slots, doing post-processing on the generated diff, adding the rest of the HTML (such as headers) and writing the whole thing to OutputPage.

DifferenceEngine can be subclassed by extensions, by customizing ContentHandler::createDifferenceEngine; the content handler will be selected based on the content model of the main slot (of the new revision, when the two are different). That might change after PageTypeHandler gets introduced.

In the past, the class was also used for slot-level diff generation, and extensions might still subclass it and add such functionality. When that is the case (sepcifically, when a ContentHandler returns a standard SlotDiffRenderer but a nonstandard DifferenceEngine) DifferenceEngineSlotDiffRenderer will be used to convert the old behavior into the new one.

Todo
This class is huge and poorly defined. It should be split into a controller responsible for interpreting query parameters, retrieving data and checking permissions; and a HTML renderer.

Definition at line 49 of file DifferenceEngine.php.

Constructor & Destructor Documentation

◆ __construct()

DifferenceEngine::__construct ( $context = null,
$old = 0,
$new = 0,
$rcid = 0,
$refreshCache = false,
$unhide = false )

#-

Parameters
IContextSource | null$contextContext to use, anything else will be ignored
int$oldOld ID we want to show and diff with.
string | int$newEither revision ID or 'prev' or 'next'. Default: 0.
int$rcidDeprecated, no longer used!
bool$refreshCacheIf set, refreshes the diff cache
bool$unhideIf set, allow viewing deleted revs

Definition at line 208 of file DifferenceEngine.php.

References ContextSource\$context, $refreshCache, $unhide, deprecatePublicProperty(), ContextSource\setContext(), and wfDebug().

Member Function Documentation

◆ addHeader()

DifferenceEngine::addHeader ( $diff,
$otitle,
$ntitle,
$multi = '',
$notice = '' )

Add the header to a diff body.

Parameters
string$diffDiff body
string$otitleOld revision header
string$ntitleNew revision header
string$multiNotice telling user that there are intermediate revisions between the ones being compared
string$noticeOther notices, e.g. that user is viewing deleted content
Returns
string

Definition at line 1564 of file DifferenceEngine.php.

References $header, getDiffLang(), and ContextSource\getLanguage().

Referenced by getDiff(), and showDiffPage().

◆ addLocalisedTitleTooltips()

DifferenceEngine::addLocalisedTitleTooltips ( $text)
private

Add title attributes for tooltips on moved paragraph indicators.

Parameters
string$text
Returns
string

Definition at line 1408 of file DifferenceEngine.php.

Referenced by localiseDiff().

◆ addLocalisedTitleTooltipsCb()

DifferenceEngine::addLocalisedTitleTooltipsCb ( array $matches)
private
Parameters
array$matches
Returns
string

Definition at line 1420 of file DifferenceEngine.php.

References $matches, and ContextSource\msg().

◆ debug()

DifferenceEngine::debug ( $generator = "internal")
protected

Generate a debug comment indicating diff generating time, server node, and generator backend.

Parameters
string$generator: What diff engine was used
Returns
string

Definition at line 1336 of file DifferenceEngine.php.

References $generator, $wgShowHostnames, wfHostname(), and wfTimestamp().

Referenced by getDebugString().

◆ deletedIdMarker()

DifferenceEngine::deletedIdMarker ( $id)

Build a wikitext link toward a deleted revision, if viewable.

Parameters
int$idRevision ID
Returns
string Wikitext fragment

Definition at line 433 of file DifferenceEngine.php.

References $link, and deletedLink().

Referenced by showMissingRevision().

◆ deletedLink()

DifferenceEngine::deletedLink ( $id)

Look up a special:Undelete link to the given deleted revision id, as a workaround for being unable to load deleted diffs in currently.

Parameters
int$idRevision ID
Returns
string|bool Link HTML or false

Definition at line 400 of file DifferenceEngine.php.

References $dbr, $rev, DB_REPLICA, Revision\getArchiveQueryInfo(), ContextSource\getUser(), Revision\newFromArchiveRow(), and wfGetDB().

Referenced by deletedIdMarker().

◆ generateContentDiffBody()

DifferenceEngine::generateContentDiffBody ( Content $old,
Content $new )

Generate a diff, no caching.

Since
1.21
Parameters
Content$oldOld content
Content$newNew content
Exceptions
ExceptionIf old or new content is not an instance of TextContent.
Returns
bool|string
Deprecated
since 1.32, use a SlotDiffRenderer instead.

Reimplemented in CustomDifferenceEngine.

Definition at line 1232 of file DifferenceEngine.php.

References Content\getContentHandler(), ContextSource\getContext(), and getDebugString().

◆ generateTextDiffBody()

DifferenceEngine::generateTextDiffBody ( $otext,
$ntext )

Generate a diff, no caching.

Parameters
string$otextOld text, must be already segmented
string$ntextNew text, must be already segmented
Exceptions
ExceptionIf content handling for text content is configured in a way that makes maintaining B/C hard.
Returns
bool|string
Deprecated
since 1.32, use a TextSlotDiffRenderer instead.

Definition at line 1260 of file DifferenceEngine.php.

References CONTENT_MODEL_TEXT, ContextSource\getContext(), and getDebugString().

◆ getDebugString()

DifferenceEngine::getDebugString ( )
private

Definition at line 1352 of file DifferenceEngine.php.

References $engine, debug(), and getEngine().

Referenced by generateContentDiffBody(), generateTextDiffBody(), and textDiff().

◆ getDiff()

DifferenceEngine::getDiff ( $otitle,
$ntitle,
$notice = '' )

Get complete diff table, including header.

Parameters
string | bool$otitleHeader for old text or false
string | bool$ntitleHeader for new text or false
string$noticeHTML between diff header and body
Returns
mixed

Definition at line 973 of file DifferenceEngine.php.

References addHeader(), getDiffBody(), getMultiNotice(), and ContextSource\msg().

Referenced by showDiff().

◆ getDiffBody()

DifferenceEngine::getDiffBody ( )

Get the diff table body, without header.

Returns
mixed (string/false)

Definition at line 995 of file DifferenceEngine.php.

References $cache, Revision\DELETED_TEXT, getDiffBodyCacheKey(), getDiffBodyCacheKeyParams(), getSlotContents(), getSlotDiffRenderers(), getSlotHeader(), loadRevisionData(), loadText(), localiseDiff(), and wfIncrStats().

Referenced by getDiff().

◆ getDiffBodyCacheKey()

DifferenceEngine::getDiffBodyCacheKey ( )
protected

Returns the cache key for diff body text or content.

Deprecated
since 1.31, use getDiffBodyCacheKeyParams() instead
Since
1.23
Exceptions
MWException
Returns
string|null

Definition at line 1137 of file DifferenceEngine.php.

Referenced by getDiffBody(), and getExtraCacheKeys().

◆ getDiffBodyCacheKeyParams()

DifferenceEngine::getDiffBodyCacheKeyParams ( )
protected

Get the cache key parameters.

Subclasses can replace the first element in the array to something more specific to the type of diff (e.g. "inline-diff"), or append if the cache should vary on more things. Overriding entirely should be avoided.

Since
1.31
Returns
array
Exceptions
MWException

Reimplemented in CustomDifferenceEngine.

Definition at line 1154 of file DifferenceEngine.php.

References $engine, $params, DIFF_VERSION, ContextSource\getConfig(), getEngine(), and getSlotDiffRenderers().

Referenced by getDiffBody(), and getExtraCacheKeys().

◆ getDiffBodyForRole()

DifferenceEngine::getDiffBodyForRole ( $role)

Get the diff table body for one slot, without header.

Parameters
string$role
Returns
string|false

Definition at line 1091 of file DifferenceEngine.php.

References getSlotContents(), getSlotDiffRenderers(), getSlotHeader(), and localiseDiff().

◆ getDiffLang()

DifferenceEngine::getDiffLang ( )

Get the language of the difference engine, defaults to page content language.

Returns
Language

Definition at line 332 of file DifferenceEngine.php.

References $mDiffLang, and getTitle().

Referenced by addHeader().

◆ getEngine()

static DifferenceEngine::getEngine ( )
static

Process $wgExternalDiffEngine and get a sane, usable engine.

Returns
bool|string 'wikidiff2', path to an executable, or false

Definition at line 1278 of file DifferenceEngine.php.

References $wgExternalDiffEngine, wfDeprecated(), and wfWarn().

Referenced by getDebugString(), getDiffBodyCacheKeyParams(), ContentHandler\getSlotDiffRendererInternal(), and localiseDiff().

◆ getExtraCacheKeys()

DifferenceEngine::getExtraCacheKeys ( )

◆ getMarkPatrolledLinkInfo()

DifferenceEngine::getMarkPatrolledLinkInfo ( )
protected

Returns an array of meta data needed to build a "mark as patrolled" link and adds the mediawiki.page.patrol.ajax to the output.

Returns
array|false An array of meta data for a patrol link (rcid only) or false if no link is needed

Definition at line 755 of file DifferenceEngine.php.

References $wgUseRCPatrol, DB_REPLICA, ContextSource\getOutput(), ContextSource\getUser(), and wfGetDB().

Referenced by markPatrolledLink().

◆ getMultiNotice()

DifferenceEngine::getMultiNotice ( )

If there are revisions between the ones being compared, return a note saying so.

Returns
string

Definition at line 1432 of file DifferenceEngine.php.

References $mNewRev, $mOldRev, $newRev, intermediateEditsMsg(), and Revision\RAW.

Referenced by getDiff(), and showDiffPage().

◆ getNewid()

DifferenceEngine::getNewid ( )

Get the ID of new revision (right pane) of the diff.

0 for the current revision, false if the new revision does not exist, null if it's unsaved. To get a real revision ID instead of 0, call loadRevisionData() first.

Returns
int|false|null

Definition at line 367 of file DifferenceEngine.php.

References $mNewid, and loadRevisionIds().

◆ getNewRevision()

DifferenceEngine::getNewRevision ( )

Get the right side of the diff.

Should not be null but can still happen in the case of load failure.

Returns
RevisionRecord|null

Definition at line 388 of file DifferenceEngine.php.

◆ getOldid()

DifferenceEngine::getOldid ( )

Get the ID of old revision (left pane) of the diff.

0 for the revision previous to getNewid(), false if the old revision does not exist, null if it's unsaved. To get a real revision ID instead of 0, call loadRevisionData() first.

Returns
int|false|null

Definition at line 355 of file DifferenceEngine.php.

References $mOldid, and loadRevisionIds().

◆ getOldRevision()

DifferenceEngine::getOldRevision ( )

Get the left side of the diff.

Could be null when the first revision of the page is diffed to 'prev' (or in the case of load failure).

Returns
RevisionRecord|null

Definition at line 379 of file DifferenceEngine.php.

◆ getParserOutput()

DifferenceEngine::getParserOutput ( WikiPage $page,
Revision $rev )
protected
Parameters
WikiPage$page
Revision$rev
Returns
ParserOutput|bool False if the revision was not found

Definition at line 911 of file DifferenceEngine.php.

References $rev, and ContextSource\getContext().

Referenced by renderNewRevision().

◆ getRevisionHeader()

DifferenceEngine::getRevisionHeader ( Revision $rev,
$complete = '' )

Get a header for a specified revision.

Parameters
Revision$rev
string$complete'complete' to get the header wrapped depending the visibility of the revision and a link to edit the page.
Returns
string HTML fragment

Definition at line 1499 of file DifferenceEngine.php.

References $header, $lang, $rev, Revision\DELETED_TEXT, ContextSource\getLanguage(), ContextSource\getUser(), Revision\isCurrent(), Linker\linkKnown(), and ContextSource\msg().

Referenced by renderNewRevision(), and showDiffPage().

◆ getSlotContents()

DifferenceEngine::getSlotContents ( )
protected

Get the old and new content objects for all slots.

This method does not do any permission checks.

Returns
array [ role => [ 'old' => SlotRecord|null, 'new' => SlotRecord|null ], ... ]

Definition at line 274 of file DifferenceEngine.php.

References $mNewContent, $mOldContent, and loadRevisionData().

Referenced by getDiffBody(), getDiffBodyForRole(), and getSlotDiffRenderers().

◆ getSlotDiffRenderers()

DifferenceEngine::getSlotDiffRenderers ( )
protected
Returns
SlotDiffRenderer[] Diff renderers for each slot, keyed by role name. Includes slots only present in one of the revisions.

Definition at line 239 of file DifferenceEngine.php.

References $content, $slotDiffRenderers, ContextSource\getContext(), getSlotContents(), and loadRevisionData().

Referenced by getDiffBody(), getDiffBodyCacheKeyParams(), getDiffBodyForRole(), and showDiffStyle().

◆ getSlotHeader()

DifferenceEngine::getSlotHeader ( $headerText)
protected

Get a slot header for inclusion in a diff body (as a table row).

Parameters
string$headerTextThe text of the header
Returns
string

Definition at line 1120 of file DifferenceEngine.php.

References ContextSource\getLanguage().

Referenced by getDiffBody(), and getDiffBodyForRole().

◆ getTitle()

DifferenceEngine::getTitle ( )
Since
1.18
Returns
Title|null

Reimplemented from ContextSource.

Definition at line 312 of file DifferenceEngine.php.

References NS_SPECIAL.

Referenced by getDiffLang(), loadRevisionData(), loadRevisionIds(), mapDiffPrevNext(), renderNewRevision(), and showDiffPage().

◆ intermediateEditsMsg()

static DifferenceEngine::intermediateEditsMsg ( $numEdits,
$numUsers,
$limit )
static

Get a notice about how many intermediate edits and users there are.

Parameters
int$numEdits
int$numUsers
int$limit
Returns
string

Definition at line 1477 of file DifferenceEngine.php.

References wfMessage().

Referenced by getMultiNotice().

◆ loadNewText()

DifferenceEngine::loadNewText ( )

Load the text of the new revision, not the old one.

Returns
bool Whether the content of the new revision could be loaded successfully.

Definition at line 1865 of file DifferenceEngine.php.

References Revision\FOR_THIS_USER, ContextSource\getUser(), and loadRevisionData().

Referenced by renderNewRevision().

◆ loadRevisionData()

DifferenceEngine::loadRevisionData ( )

Load revision metadata for the specified revisions.

If newid is 0, then compare the old revision in oldid to the current revision of the current page (as defined by the request context); if oldid is 0, then compare the revision in newid to the immediately previous one.

If oldid is false, leave the corresponding revision object set to false. This can happen with 'diff=prev' pointing to a non-existent revision, and is also used directly by the API.

Returns
bool Whether both revisions were loaded successfully. Setting mOldRev to false counts as successful loading.

Definition at line 1742 of file DifferenceEngine.php.

References $dbr, $rev, DB_REPLICA, getTitle(), loadRevisionIds(), Revision\newFromId(), Revision\newFromTitle(), and wfGetDB().

Referenced by getDiffBody(), getSlotContents(), getSlotDiffRenderers(), loadNewText(), loadText(), and showDiffPage().

◆ loadRevisionIds()

DifferenceEngine::loadRevisionIds ( )
private

Load revision IDs.

Definition at line 1706 of file DifferenceEngine.php.

References $mNewid, $mOldid, getTitle(), list, and mapDiffPrevNext().

Referenced by getNewid(), getOldid(), and loadRevisionData().

◆ loadText()

DifferenceEngine::loadText ( )

Load the text of the revisions, as well as revision data.

When the old revision is missing (mOldRev is false), loading mOldContent is not attempted.

Returns
bool Whether the content of both revisions could be loaded successfully. (When mOldRev is false, that still counts as a success.)

Definition at line 1831 of file DifferenceEngine.php.

References $mOldContent, Revision\FOR_THIS_USER, ContextSource\getUser(), and loadRevisionData().

Referenced by getDiffBody().

◆ localiseDiff()

DifferenceEngine::localiseDiff ( $text)
private

Localise diff output.

Parameters
string$text
Returns
string

Definition at line 1369 of file DifferenceEngine.php.

References addLocalisedTitleTooltips(), getEngine(), and localiseLineNumbers().

Referenced by getDiffBody(), and getDiffBodyForRole().

◆ localiseLineNumbers()

DifferenceEngine::localiseLineNumbers ( $text)

Replace line numbers with the text in the user's language.

Parameters
string$text
Returns
mixed

Definition at line 1386 of file DifferenceEngine.php.

Referenced by localiseDiff().

◆ localiseLineNumbersCb()

DifferenceEngine::localiseLineNumbersCb ( $matches)

Definition at line 1394 of file DifferenceEngine.php.

References $matches, and ContextSource\msg().

◆ mapDiffPrevNext()

DifferenceEngine::mapDiffPrevNext ( $old,
$new )

Maps a revision pair definition as accepted by DifferenceEngine constructor to a pair of actual integers representing revision ids.

Parameters
int$oldRevision id, e.g. from URL parameter 'oldid'
int | string$newRevision id or strings 'next' or 'prev', e.g. from URL parameter 'diff'
Returns
array List of two revision ids, older first, later second. Zero signifies invalid argument passed. false signifies that there is no previous/next revision ($old is the oldest/newest one).

Definition at line 1686 of file DifferenceEngine.php.

References getTitle().

Referenced by loadRevisionIds().

◆ markAsSlotDiffRenderer()

DifferenceEngine::markAsSlotDiffRenderer ( )

Mark this DifferenceEngine as a slot renderer (as opposed to a page renderer).

This is used in legacy mode when the DifferenceEngine is wrapped in a DifferenceEngineSlotDiffRenderer.

Definition at line 265 of file DifferenceEngine.php.

◆ markPatrolledLink()

DifferenceEngine::markPatrolledLink ( )

Build a link to mark a change as patrolled.

Returns empty string if there's either no revision to patrol or the user is not allowed to. Side effect: When the patrol link is build, this method will call OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.

Returns
string HTML or empty string

Definition at line 723 of file DifferenceEngine.php.

References $mMarkPatrolledLink, getMarkPatrolledLinkInfo(), Linker\linkKnown(), and ContextSource\msg().

Referenced by renderNewRevision(), and showDiffPage().

◆ renderNewRevision()

DifferenceEngine::renderNewRevision ( )

Show the new revision of the page.

Note
Not supported after calling setContent().

Definition at line 829 of file DifferenceEngine.php.

References $out, ContextSource\getOutput(), getParserOutput(), getRevisionHeader(), getTitle(), ContextSource\getWikiPage(), loadNewText(), and markPatrolledLink().

Referenced by showDiffPage().

◆ revisionDeleteLink()

DifferenceEngine::revisionDeleteLink ( $rev)
protected
Parameters
Revision$rev
Returns
string

Definition at line 815 of file DifferenceEngine.php.

References $link, $rev, Linker\getRevDeleteLink(), and ContextSource\getUser().

Referenced by showDiffPage().

◆ setContent()

DifferenceEngine::setContent ( Content $oldContent,
Content $newContent )

Use specified text instead of loading from the database.

Parameters
Content$oldContent
Content$newContent
Since
1.21
Deprecated
since 1.32, use setRevisions or ContentHandler::getSlotDiffRenderer.

Definition at line 1620 of file DifferenceEngine.php.

◆ setReducedLineNumbers()

DifferenceEngine::setReducedLineNumbers ( $value = true)

Set reduced line numbers mode.

When set, line X is not displayed when X is 1, for example to increase readability and conserve space with many small diffs.

Parameters
bool$value

Definition at line 323 of file DifferenceEngine.php.

References $value.

◆ setRevisions()

DifferenceEngine::setRevisions ( RevisionRecord $oldRevision = null,
RevisionRecord $newRevision )

Use specified text instead of loading from the database.

Parameters
RevisionRecord | null$oldRevision
RevisionRecord$newRevision

Definition at line 1635 of file DifferenceEngine.php.

References ContextSource\getUser().

◆ setTextLanguage()

DifferenceEngine::setTextLanguage ( $lang)

Set the language in which the diff text is written.

Parameters
Language$lang
Since
1.19

Definition at line 1668 of file DifferenceEngine.php.

References $lang, wfDeprecated(), and wfGetLangObj().

◆ showDiff()

DifferenceEngine::showDiff ( $otitle,
$ntitle,
$notice = '' )

Get the diff text, send it to the OutputPage object Returns false if the diff could not be generated, otherwise returns true.

Parameters
string | bool$otitleHeader for old text or false
string | bool$ntitleHeader for new text or false
string$noticeHTML between diff header and body
Returns
bool

Definition at line 935 of file DifferenceEngine.php.

References getDiff(), ContextSource\getOutput(), showDiffStyle(), and showMissingRevision().

Referenced by showDiffPage().

◆ showDiffPage()

◆ showDiffStyle()

DifferenceEngine::showDiffStyle ( )

Add style sheets for diff display.

Reimplemented in CustomDifferenceEngine.

Definition at line 955 of file DifferenceEngine.php.

References ContextSource\getOutput(), and getSlotDiffRenderers().

Referenced by showDiff(), and showDiffPage().

◆ showMissingRevision()

DifferenceEngine::showMissingRevision ( )
private

◆ textDiff()

DifferenceEngine::textDiff ( $otext,
$ntext )
protected

Generates diff, to be wrapped internally in a logging/instrumentation.

Parameters
string$otextOld text, must be already segmented
string$ntextNew text, must be already segmented
Exceptions
ExceptionIf content handling for text content is configured in a way that makes maintaining B/C hard.
Returns
bool|string
Deprecated
since 1.32, use a TextSlotDiffRenderer instead.

Definition at line 1316 of file DifferenceEngine.php.

References CONTENT_MODEL_TEXT, ContextSource\getContext(), and getDebugString().

◆ wasCacheHit()

DifferenceEngine::wasCacheHit ( )
Returns
bool

Definition at line 344 of file DifferenceEngine.php.

References $mCacheHit.

Member Data Documentation

◆ $enableDebugComment

DifferenceEngine::$enableDebugComment = false

Set this to true to add debug info to the HTML output.

Warning: this may cause RSS readers to spuriously mark articles as "new" (T22601)

Definition at line 171 of file DifferenceEngine.php.

◆ $isContentOverridden

bool DifferenceEngine::$isContentOverridden = false
protected

Was the content overridden via setContent()? If the content was overridden, most internal state (e.g.

mOldid or mOldRev) should be ignored and only mOldContent and mNewContent is reliable. (Note that setRevisions() does not set this flag as in that case all properties are overriden and remain consistent with each other, so no special handling is needed.)

Definition at line 161 of file DifferenceEngine.php.

◆ $isSlotDiffRenderer

bool DifferenceEngine::$isSlotDiffRenderer = false
protected

Temporary hack for B/C while slot diff related methods of DifferenceEngine are being deprecated.

When true, we are inside a DifferenceEngineSlotDiffRenderer and $slotDiffRenderers should not be used.

Definition at line 196 of file DifferenceEngine.php.

◆ $mCacheHit

bool DifferenceEngine::$mCacheHit = false
protected

Was the diff fetched from cache?

Definition at line 164 of file DifferenceEngine.php.

Referenced by wasCacheHit().

◆ $mDiffLang

Language DifferenceEngine::$mDiffLang
protected

Definition at line 142 of file DifferenceEngine.php.

Referenced by getDiffLang().

◆ $mMarkPatrolledLink

string DifferenceEngine::$mMarkPatrolledLink = null
protected

Link to action=markpatrolled.

Definition at line 179 of file DifferenceEngine.php.

Referenced by markPatrolledLink().

◆ $mNewContent

Content null DifferenceEngine::$mNewContent
private
Deprecated
since 1.32, content slots are now handled by the corresponding SlotDiffRenderer. This property is set to the content of the main slot, but not actually used for the main diff.

Definition at line 139 of file DifferenceEngine.php.

Referenced by getSlotContents().

◆ $mNewid

int string false null DifferenceEngine::$mNewid
protected

Revision ID for the new revision.

0 for the last revision of the current page (as defined by the request context), false if the revision does not exist, null if it is unsaved, or an alias such as 'next'.

Definition at line 75 of file DifferenceEngine.php.

Referenced by getNewid(), and loadRevisionIds().

◆ $mNewPage

Title null DifferenceEngine::$mNewPage
protected

Title of $mNewRev or null if the new revision does not exist or does not belong to a page.

Since 1.32 public access is deprecated and the property can be null.

Definition at line 113 of file DifferenceEngine.php.

◆ $mNewRev

Revision null DifferenceEngine::$mNewRev
protected

New revision (right pane).

Note that this might be an unsaved revision (e.g. for edit preview). Null in case of load failure; diff methods will just return an error message in that case, and loadRevisionData() will return false. Also null until lazy-loaded. Ignored completely when isContentOverridden is set. Since 1.32 public access is deprecated.

Definition at line 99 of file DifferenceEngine.php.

Referenced by getMultiNotice().

◆ $mNewTags

string [] null DifferenceEngine::$mNewTags
private

Change tags of $mNewRev or null if it does not exist / is not saved.

Definition at line 125 of file DifferenceEngine.php.

◆ $mOldContent

Content null DifferenceEngine::$mOldContent
private
Deprecated
since 1.32, content slots are now handled by the corresponding SlotDiffRenderer. This property is set to the content of the main slot, but not actually used for the main diff.

Definition at line 132 of file DifferenceEngine.php.

Referenced by getSlotContents(), and loadText().

◆ $mOldid

int false null DifferenceEngine::$mOldid
protected

Revision ID for the old revision.

0 for the revision previous to $mNewid, false if the diff does not have an old revision (e.g. 'oldid=<first revision of page>&diff=prev'), or the revision does not exist, null if the revision is unsaved.

Definition at line 67 of file DifferenceEngine.php.

Referenced by getOldid(), and loadRevisionIds().

◆ $mOldPage

Title null DifferenceEngine::$mOldPage
protected

Title of $mOldRev or null if the old revision does not exist or does not belong to a page.

Since 1.32 public access is deprecated and the property can be null.

Definition at line 106 of file DifferenceEngine.php.

◆ $mOldRev

Revision null false DifferenceEngine::$mOldRev
protected

Old revision (left pane).

Allowed to be an unsaved revision, unlikely that's ever needed though. False when the old revision does not exist; this can happen when using diff=prev on the first revision. Null when the revision should exist but doesn't (e.g. load failure); loadRevisionData() will return false in that case. Also null until lazy-loaded. Ignored completely when isContentOverridden is set. Since 1.32 public access is deprecated.

Definition at line 88 of file DifferenceEngine.php.

Referenced by getMultiNotice().

◆ $mOldTags

string [] null DifferenceEngine::$mOldTags
private

Change tags of $mOldRev or null if it does not exist / is not saved.

Definition at line 119 of file DifferenceEngine.php.

◆ $mReducedLineNumbers

bool DifferenceEngine::$mReducedLineNumbers = false
protected

If true, line X is not displayed when X is 1, for example to increase readability and conserve space with many small diffs.

Definition at line 176 of file DifferenceEngine.php.

◆ $mRefreshCache

bool DifferenceEngine::$mRefreshCache = false
protected

Refresh the diff cache.

Definition at line 185 of file DifferenceEngine.php.

◆ $mRevisionsIdsLoaded

bool DifferenceEngine::$mRevisionsIdsLoaded = false
private

Have the revisions IDs been loaded.

Definition at line 145 of file DifferenceEngine.php.

◆ $mRevisionsLoaded

bool DifferenceEngine::$mRevisionsLoaded = false
protected

Have the revisions been loaded.

Definition at line 148 of file DifferenceEngine.php.

◆ $mTextLoaded

int DifferenceEngine::$mTextLoaded = 0
protected

How many text blobs have been loaded, 0, 1 or 2?

Definition at line 151 of file DifferenceEngine.php.

◆ $slotDiffRenderers

SlotDiffRenderer [] DifferenceEngine::$slotDiffRenderers = null
protected

DifferenceEngine classes for the slots, keyed by role name.

Definition at line 188 of file DifferenceEngine.php.

Referenced by getSlotDiffRenderers().

◆ $unhide

bool DifferenceEngine::$unhide = false
protected

Show rev_deleted content if allowed.

Definition at line 182 of file DifferenceEngine.php.

Referenced by __construct().

◆ DIFF_VERSION

const DifferenceEngine::DIFF_VERSION = '1.12'

Constant to indicate diff cache compatibility.

Bump this when changing the diff formatting in a way that fixes important bugs or such to force cached diff views to clear.

Definition at line 59 of file DifferenceEngine.php.

Referenced by getDiffBodyCacheKeyParams().


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