MediaWiki  master
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)
 #- More...
 
 addHeader ( $diff, $otitle, $ntitle, $multi='', $notice='')
 Add the header to a diff body. More...
 
 deletedIdMarker ( $id)
 Build a wikitext link toward a deleted revision, if viewable. More...
 
 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. More...
 
 generateContentDiffBody (Content $old, Content $new)
 Generate a diff, no caching. More...
 
 generateTextDiffBody ( $otext, $ntext)
 Generate a diff, no caching. More...
 
 getDiff ( $otitle, $ntitle, $notice='')
 Get complete diff table, including header. More...
 
 getDiffBody ()
 Get the diff table body, without header. More...
 
 getDiffBodyForRole ( $role)
 Get the diff table body for one slot, without header. More...
 
 getDiffLang ()
 Get the language of the difference engine, defaults to page content language. More...
 
 getExtraCacheKeys ()
 Implements DifferenceEngineSlotDiffRenderer::getExtraCacheKeys(). More...
 
 getMultiNotice ()
 If there are revisions between the ones being compared, return a note saying so. More...
 
 getNewid ()
 Get the ID of new revision (right pane) of the diff. More...
 
 getNewRevision ()
 Get the right side of the diff. More...
 
 getOldid ()
 Get the ID of old revision (left pane) of the diff. More...
 
 getOldRevision ()
 Get the left side of the diff. More...
 
 getPermissionErrors (Authority $performer)
 Get the permission errors associated with the revisions for the current diff. More...
 
 getRevisionHeader (RevisionRecord $rev, $complete='')
 Get a header for a specified revision. More...
 
 getTitle ()
 
Since
1.18
Stability: stable
to override
Returns
Title|null
More...
 
 hasDeletedRevision ()
 Checks whether one of the given Revisions was deleted. More...
 
 hasSuppressedRevision ()
 Checks whether one of the given Revisions was suppressed. More...
 
 isUserAllowedToSeeRevisions (Authority $performer)
 Checks whether the current user has permission for accessing the revisions of the diff. More...
 
 loadNewText ()
 Load the text of the new revision, not the old one. More...
 
 loadRevisionData ()
 Load revision metadata for the specified revisions. More...
 
 loadText ()
 Load the text of the revisions, as well as revision data. More...
 
 localiseLineNumbers ( $text)
 Replace line numbers with the text in the user's language. More...
 
 mapDiffPrevNext ( $old, $new)
 Maps a revision pair definition as accepted by DifferenceEngine constructor to a pair of actual integers representing revision ids. More...
 
 markAsSlotDiffRenderer ()
 Mark this DifferenceEngine as a slot renderer (as opposed to a page renderer). More...
 
 markPatrolledLink ()
 Build a link to mark a change as patrolled. More...
 
 renderNewRevision ()
 Show the new revision of the page. More...
 
 setContent (Content $oldContent, Content $newContent)
 Use specified text instead of loading from the database. More...
 
 setReducedLineNumbers ( $value=true)
 Set reduced line numbers mode. More...
 
 setRevisions (?RevisionRecord $oldRevision, RevisionRecord $newRevision)
 Use specified text instead of loading from the database. More...
 
 setSlotDiffOptions ( $options)
 
 setTextLanguage (Language $lang)
 Set the language in which the diff text is written. More...
 
 shouldBeHiddenFromUser (Authority $performer)
 Checks whether the diff should be hidden from the current user This is based on whether the user is allowed to see it and has specifically asked to see it. More...
 
 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. More...
 
 showDiffPage ( $diffOnly=false)
 
 showDiffStyle ()
 Add style sheets for diff display. More...
 
 wasCacheHit ()
 
- Public Member Functions inherited from ContextSource
 canUseWikiPage ()
 Check whether a WikiPage object can be get with getWikiPage(). More...
 
 exportSession ()
 Export the resolved user IP, HTTP headers, user ID, and session ID. More...
 
 getActionName ()
 Get the action name for the current web request. More...
 
 getAuthority ()
 
 getConfig ()
 
 getContext ()
 Get the base IContextSource object. More...
 
 getCsrfTokenSet ()
 Get a repository to obtain and match CSRF tokens. More...
 
 getLanguage ()
 
 getOutput ()
 
 getRequest ()
 
 getSkin ()
 
 getStats ()
 
 getTiming ()
 
 getUser ()
 
 getWikiPage ()
 Get the WikiPage object. More...
 
 msg ( $key,... $params)
 Get a Message object with context set Parameters are the same as wfMessage() More...
 
 setContext (IContextSource $context)
 

Static Public Member Functions

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

Public Attributes

bool $enableDebugComment = false
 Set this to true to add debug info to the HTML output. More...
 

Protected Member Functions

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

Protected Attributes

bool $isContentOverridden = false
 Was the content overridden via setContent()? If the content was overridden, most internal state (e.g. More...
 
bool $isSlotDiffRenderer = false
 Temporary hack for B/C while slot diff related methods of DifferenceEngine are being deprecated. More...
 
LinkRenderer $linkRenderer
 
bool $mCacheHit = false
 Was the diff fetched from cache? More...
 
Language $mDiffLang
 
string $mMarkPatrolledLink = null
 Link to action=markpatrolled. More...
 
int string false null $mNewid
 Revision ID for the new revision. More...
 
Title null $mNewPage
 Title of new revision or null if the new revision does not exist or does not belong to a page. More...
 
int false null $mOldid
 Revision ID for the old revision. More...
 
Title null $mOldPage
 Title of old revision or null if the old revision does not exist or does not belong to a page. More...
 
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. More...
 
bool $mRefreshCache = false
 Refresh the diff cache. More...
 
bool $mRevisionsLoaded = false
 Have the revisions been loaded. More...
 
int $mTextLoaded = 0
 How many text blobs have been loaded, 0, 1 or 2? More...
 
SlotDiffRenderer[] null $slotDiffRenderers = null
 DifferenceEngine classes for the slots, keyed by role name. More...
 
bool $unhide = false
 Show rev_deleted content if allowed. More...
 

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 (specifically, 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 60 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 248 of file DifferenceEngine.php.

References $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 1793 of file DifferenceEngine.php.

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

Referenced by getDiff(), and showDiffPage().

◆ debug()

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

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

Parameters
string$generatorWhat diff engine was used
Returns
string

Definition at line 1538 of file DifferenceEngine.php.

References $generator, ContextSource\getConfig(), wfHostname(), and wfTimestamp().

◆ 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 479 of file DifferenceEngine.php.

References deletedLink().

◆ 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 446 of file DifferenceEngine.php.

References $dbr, $title, DB_REPLICA, ContextSource\getAuthority(), SpecialPage\getTitleFor(), Title\makeTitleSafe(), 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.

Definition at line 1406 of file DifferenceEngine.php.

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

◆ 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 1434 of file DifferenceEngine.php.

References CONTENT_MODEL_TEXT, and ContextSource\getContext().

◆ getDiff()

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

Get complete diff table, including header.

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

Definition at line 1116 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
string|false

Definition at line 1138 of file DifferenceEngine.php.

References $cache, MWDebug\detectDeprecatedOverride(), getDiffBodyCacheKey(), getDiffBodyCacheKeyParams(), getSlotContents(), getSlotDiffRenderers(), getSlotHeader(), loadRevisionData(), and loadText().

Referenced by getDiff().

◆ getDiffBodyCacheKey()

DifferenceEngine::getDiffBodyCacheKey ( )
protected

Returns the cache key for diff body text or content.

Deprecated:
since 1.31, use getDiffBodyCacheKeyParams() instead. Hard deprecated in 1.39.
Since
1.23
Exceptions
MWException
Returns
string|null

Definition at line 1295 of file DifferenceEngine.php.

References wfDeprecated().

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
string[]
Exceptions
MWException

Definition at line 1313 of file DifferenceEngine.php.

References 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 1248 of file DifferenceEngine.php.

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

◆ getDiffLang()

DifferenceEngine::getDiffLang ( )

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

Returns
Language

Definition at line 378 of file DifferenceEngine.php.

References $mDiffLang, and getTitle().

Referenced by addHeader().

◆ getEngine()

static DifferenceEngine::getEngine ( )
static

Process DiffEngine config and get a sensible, usable engine.

Returns
string 'wikidiff2', 'php', or path to an executable
Access: internal
For use by this class and TextSlotDiffRenderer only.

Definition at line 1453 of file DifferenceEngine.php.

References wfDebug(), and wfWarn().

Referenced by getDiffBodyCacheKeyParams(), and ContentHandler\getSlotDiffRendererWithOptions().

◆ getExtraCacheKeys()

DifferenceEngine::getExtraCacheKeys ( )

◆ getMarkPatrolledLinkInfo()

DifferenceEngine::getMarkPatrolledLinkInfo ( )
protected

Returns an array of meta data needed to build a "mark as patrolled" link and adds a JS module 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 893 of file DifferenceEngine.php.

References ContextSource\getAuthority(), ContextSource\getConfig(), ContextSource\getOutput(), ContextSource\getUser(), RecentChange\isInRCLifespan(), RecentChange\newFromConds(), and RecentChange\PRC_UNPATROLLED.

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 1627 of file DifferenceEngine.php.

References intermediateEditsMsg().

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 413 of file DifferenceEngine.php.

References $mNewid.

◆ 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 434 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 401 of file DifferenceEngine.php.

References $mOldid.

◆ 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 425 of file DifferenceEngine.php.

◆ getParserOutput()

DifferenceEngine::getParserOutput ( WikiPage  $page,
RevisionRecord  $revRecord 
)
protected
Parameters
WikiPage$page
RevisionRecord$revRecord
Returns
ParserOutput|false False if the revision was not found

Definition at line 1051 of file DifferenceEngine.php.

References ContextSource\getContext(), MediaWiki\Revision\RevisionRecord\getId(), WikiPage\getParserOutput(), and WikiPage\makeParserOptions().

Referenced by renderNewRevision().

◆ getPermissionErrors()

DifferenceEngine::getPermissionErrors ( Authority  $performer)

Get the permission errors associated with the revisions for the current diff.

Parameters
Authority$performer
Returns
array[] Array of arrays of the arguments to wfMessage to explain permissions problems.

Definition at line 530 of file DifferenceEngine.php.

References MediaWiki\Permissions\Authority\authorizeRead(), and loadRevisionData().

Referenced by showDiffPage().

◆ getRevisionHeader()

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

◆ 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 324 of file DifferenceEngine.php.

References 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 285 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 1277 of file DifferenceEngine.php.

References Html\element(), ContextSource\getLanguage(), and Html\rawElement().

Referenced by getDiffBody(), and getDiffBodyForRole().

◆ getTitle()

DifferenceEngine::getTitle ( )

Since
1.18
Stability: stable
to override
Returns
Title|null

Reimplemented from ContextSource.

Definition at line 358 of file DifferenceEngine.php.

References getTitle(), Title\makeTitle(), and NS_SPECIAL.

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

◆ hasDeletedRevision()

DifferenceEngine::hasDeletedRevision ( )

Checks whether one of the given Revisions was deleted.

Returns
bool

Definition at line 512 of file DifferenceEngine.php.

References loadRevisionData().

Referenced by hasSuppressedRevision(), shouldBeHiddenFromUser(), and showDiffPage().

◆ hasSuppressedRevision()

DifferenceEngine::hasSuppressedRevision ( )

Checks whether one of the given Revisions was suppressed.

Returns
bool

Definition at line 547 of file DifferenceEngine.php.

References hasDeletedRevision().

Referenced by 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 1694 of file DifferenceEngine.php.

References wfMessage().

Referenced by getMultiNotice().

◆ isUserAllowedToSeeRevisions()

DifferenceEngine::isUserAllowedToSeeRevisions ( Authority  $performer)

Checks whether the current user has permission for accessing the revisions of the diff.

Note that this does not check whether the user has permission to view the page, it only checks revdelete permissions.

It is the caller's responsibility to call $this->getUserPermissionErrors or similar checks.

Parameters
Authority$performer
Returns
bool

Definition at line 567 of file DifferenceEngine.php.

References loadRevisionData().

Referenced by shouldBeHiddenFromUser(), and showDiffPage().

◆ 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 2134 of file DifferenceEngine.php.

References ContextSource\getAuthority(), 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 RevisionRecord 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 mOldRevisionRecord to false counts as successful loading.

Definition at line 1990 of file DifferenceEngine.php.

References $dbr, DB_REPLICA, MediaWiki\Revision\RevisionRecord\getId(), getTitle(), Title\newFromLinkTarget(), and wfGetDB().

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

◆ 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 2091 of file DifferenceEngine.php.

References ContextSource\getAuthority(), and loadRevisionData().

Referenced by getDiffBody().

◆ localiseLineNumbers()

DifferenceEngine::localiseLineNumbers (   $text)

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

Parameters
string$text
Returns
string

Definition at line 1590 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 1923 of file DifferenceEngine.php.

◆ 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.

Access: internal
For use by DifferenceEngineSlotDiffRenderer only.

Definition at line 315 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::setPreventClickjacking(true) and load a JS module.

Returns
string HTML or empty string

Definition at line 861 of file DifferenceEngine.php.

References $mMarkPatrolledLink, getMarkPatrolledLinkInfo(), 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 968 of file DifferenceEngine.php.

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

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 1859 of file DifferenceEngine.php.

Referenced by DifferenceEngineSlotDiffRenderer\__construct().

◆ 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 369 of file DifferenceEngine.php.

◆ setRevisions()

DifferenceEngine::setRevisions ( ?RevisionRecord  $oldRevision,
RevisionRecord  $newRevision 
)

Use specified text instead of loading from the database.

Parameters
RevisionRecord | null$oldRevision
RevisionRecord$newRevision

Definition at line 1874 of file DifferenceEngine.php.

References ContextSource\getAuthority(), MediaWiki\Revision\RevisionRecord\getContent(), MediaWiki\Revision\RevisionRecord\getId(), MediaWiki\Revision\RevisionRecord\getPageAsLinkTarget(), and Title\newFromLinkTarget().

◆ setSlotDiffOptions()

DifferenceEngine::setSlotDiffOptions (   $options)
Parameters
array$optionsfor the difference engine. Accepts keys 'diff-type' and 'expand-url'

Definition at line 1389 of file DifferenceEngine.php.

◆ setTextLanguage()

DifferenceEngine::setTextLanguage ( Language  $lang)

Set the language in which the diff text is written.

Parameters
Language$lang
Since
1.19

Definition at line 1907 of file DifferenceEngine.php.

References $lang.

◆ shouldBeHiddenFromUser()

DifferenceEngine::shouldBeHiddenFromUser ( Authority  $performer)

Checks whether the diff should be hidden from the current user This is based on whether the user is allowed to see it and has specifically asked to see it.

Parameters
Authority$performer
Returns
bool

Definition at line 592 of file DifferenceEngine.php.

References hasDeletedRevision(), and isUserAllowedToSeeRevisions().

Referenced by showDiffPage().

◆ 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 | false$otitleHeader for old text or false
string | false$ntitleHeader for new text or false
string$noticeHTML between diff header and body
Returns
bool

Definition at line 1073 of file DifferenceEngine.php.

References Linker\expandLocalLinks(), getDiff(), ContextSource\getOutput(), and showDiffStyle().

Referenced by showDiffPage().

◆ showDiffPage()

◆ showDiffStyle()

DifferenceEngine::showDiffStyle ( )

Add style sheets for diff display.

Definition at line 1094 of file DifferenceEngine.php.

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

Referenced by showDiff(), and showDiffPage().

◆ 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. Hard deprecated since 1.39.

Definition at line 1516 of file DifferenceEngine.php.

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

◆ wasCacheHit()

DifferenceEngine::wasCacheHit ( )
Returns
bool

Definition at line 390 of file DifferenceEngine.php.

References $mCacheHit.

Member Data Documentation

◆ $enableDebugComment

bool 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 181 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 overridden and remain consistent with each other, so no special handling is needed.)

Definition at line 170 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 206 of file DifferenceEngine.php.

◆ $linkRenderer

LinkRenderer DifferenceEngine::$linkRenderer
protected

Definition at line 217 of file DifferenceEngine.php.

◆ $mCacheHit

bool DifferenceEngine::$mCacheHit = false
protected

Was the diff fetched from cache?

Definition at line 173 of file DifferenceEngine.php.

Referenced by wasCacheHit().

◆ $mDiffLang

Language DifferenceEngine::$mDiffLang
protected

Definition at line 151 of file DifferenceEngine.php.

Referenced by getDiffLang().

◆ $mMarkPatrolledLink

string DifferenceEngine::$mMarkPatrolledLink = null
protected

Link to action=markpatrolled.

Definition at line 189 of file DifferenceEngine.php.

Referenced by markPatrolledLink().

◆ $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 86 of file DifferenceEngine.php.

Referenced by getNewid().

◆ $mNewPage

Title null DifferenceEngine::$mNewPage
protected

Title of new revision 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 122 of file DifferenceEngine.php.

◆ $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 78 of file DifferenceEngine.php.

Referenced by getOldid().

◆ $mOldPage

Title null DifferenceEngine::$mOldPage
protected

Title of old revision 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 115 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 186 of file DifferenceEngine.php.

◆ $mRefreshCache

bool DifferenceEngine::$mRefreshCache = false
protected

Refresh the diff cache.

Definition at line 195 of file DifferenceEngine.php.

◆ $mRevisionsLoaded

bool DifferenceEngine::$mRevisionsLoaded = false
protected

Have the revisions been loaded.

Definition at line 157 of file DifferenceEngine.php.

◆ $mTextLoaded

int DifferenceEngine::$mTextLoaded = 0
protected

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

Definition at line 160 of file DifferenceEngine.php.

◆ $slotDiffRenderers

SlotDiffRenderer [] null DifferenceEngine::$slotDiffRenderers = null
protected

DifferenceEngine classes for the slots, keyed by role name.

Definition at line 198 of file DifferenceEngine.php.

Referenced by getSlotDiffRenderers().

◆ $unhide

bool DifferenceEngine::$unhide = false
protected

Show rev_deleted content if allowed.

Definition at line 192 of file DifferenceEngine.php.

Referenced by __construct().


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