MediaWiki REL1_41
ContentHandler Class Reference

A content handler knows how do deal with a specific type of content on a wiki page. More...

Inherited by FallbackContentHandler, and TextContentHandler.

Public Member Functions

 __construct ( $modelId, $formats)
 Constructor, initializing the ContentHandler instance with its model ID and a list of supported formats.
 
 canBeUsedOn (Title $title)
 Determines whether the content type handled by this ContentHandler can be used for the main slot of the given page.
 
 createDifferenceEngine (IContextSource $context, $old=0, $new=0, $rcid=0, $refreshCache=false, $unhide=false)
 Factory for creating an appropriate DifferenceEngine for this content model.
 
 exportTransform ( $blob, $format=null)
 Applies transformations on export (returns the blob unchanged per default).
 
 fillParserOutputInternal (Content $content, ContentParseParams $cpoParams, ParserOutput &$output)
 A temporary layer to move AbstractContent::fillParserOutput to ContentHandler::fillParserOutput.
 
 generateHTMLOnEdit ()
 Whether an edit on the content should trigger an HTML render and ParserCache entry.
 
 getActionOverrides ()
 Returns overrides for action handlers.
 
 getAutoDeleteReason (Title $title, &$hasHistory=false)
 Auto-generates a deletion reason.
 
 getAutosummary (Content $oldContent=null, Content $newContent=null, $flags=0)
 Return an applicable auto-summary if one exists for the given edit.
 
 getChangeTag (Content $oldContent=null, Content $newContent=null, $flags=0)
 Return an applicable tag if one exists for the given edit or return null.
 
 getDataForSearchIndex (WikiPage $page, ParserOutput $output, SearchEngine $engine, RevisionRecord $revision=null)
 Return fields to be indexed by search engine as representation of this document.
 
 getDefaultFormat ()
 The format used for serialization/deserialization by default by this ContentHandler.
 
 getDeletionUpdates (Title $title, $role)
 Returns a list of DeferrableUpdate objects for removing information about content in some secondary data store.
 
 getFieldsForSearchIndex (SearchEngine $engine)
 Get fields definition for search index.
 
 getModelID ()
 Returns the model id that identifies the content model this ContentHandler can handle.
 
 getPageLanguage (Title $title, Content $content=null)
 Get the language in which the content of the given page is written.
 
 getPageViewLanguage (Title $title, Content $content=null)
 Get the language in which the content of this page is written when viewed by user.
 
 getParserOutput (Content $content, ContentParseParams $cpoParams)
 Returns a ParserOutput object containing information derived from this content.
 
 getParserOutputForIndexing (WikiPage $page, ParserCache $cache=null, RevisionRecord $revision=null)
 Produce page output suitable for indexing.
 
 getSecondaryDataUpdates (Title $title, Content $content, $role, SlotRenderingProvider $slotOutput)
 Returns a list of DeferrableUpdate objects for recording information about the given Content in some secondary data store.
 
 getSlotDiffRenderer (IContextSource $context, array $options=[])
 Get an appropriate SlotDiffRenderer for this content model.
 
 getSupportedFormats ()
 Returns a list of serialization formats supported by the serializeContent() and unserializeContent() methods of this ContentHandler.
 
 getUndoContent (Content $currentContent, Content $undoContent, Content $undoAfterContent, $undoIsLatest=false)
 Get the Content object that needs to be saved in order to undo all changes between $undo and $undoafter.
 
 importTransform ( $blob, $format=null)
 Apply import transformation (per default, returns $blob unchanged).
 
 isParserCacheSupported ()
 Returns true for content models that support caching using the ParserCache mechanism.
 
 isSupportedFormat ( $format)
 Returns true if $format is a serialization format supported by this ContentHandler, and false otherwise.
 
 makeEmptyContent ()
 Creates an empty Content object of the type supported by this ContentHandler.
 
 makeRedirectContent (Title $destination, $text='')
 Creates a new Content object that acts as a redirect to the given page, or null if redirects are not supported by this content model.
 
 merge3 (Content $oldContent, Content $myContent, Content $yourContent)
 Attempts to merge differences between three versions.
 
 preloadTransform (Content $content, PreloadTransformParams $pltParams)
 Returns a $content object with preload transformations applied (or the same object if no transformations apply).
 
 preSaveTransform (Content $content, PreSaveTransformParams $pstParams)
 Returns a $content object with pre-save transformations applied (or the same object if no transformations apply).
 
 serializeContent (Content $content, $format=null)
 Serializes a Content object of the type supported by this ContentHandler.
 
 supportsCategories ()
 Returns true if this content model supports categories.
 
 supportsDirectApiEditing ()
 Whether or not this content model supports direct editing via ApiEditPage.
 
 supportsDirectEditing ()
 Return true if this content model supports direct editing, such as via EditPage.
 
 supportsPreloadContent ()
 If a non-existing page can be created with the contents from another (arbitrary) page being preloaded in the editor, see {.
 
 supportsRedirects ()
 Returns true if this content model supports redirects.
 
 supportsSections ()
 Returns true if this content model supports sections.
 
 unserializeContent ( $blob, $format=null)
 Unserializes a Content object of the type supported by this ContentHandler.
 
 validateSave (Content $content, ValidationParams $validationParams)
 Validate content for saving it.
 

Static Public Member Functions

static getAllContentFormats ()
 
static getContentModels ()
 
static getContentText (Content $content=null)
 Convenience function for getting flat text from a Content object.
 
static getDefaultModelFor (Title $title)
 Returns the name of the default content model to be used for the page with the given title.
 
static getForContent (Content $content)
 Returns the appropriate ContentHandler singleton for the given Content object.
 
static getForModelID ( $modelId)
 Returns the ContentHandler singleton for the given model ID.
 
static getLocalizedName ( $name, Language $lang=null)
 Returns the localized name for a given content model.
 
static makeContent ( $text, Title $title=null, $modelId=null, $format=null)
 Convenience function for creating a Content object from a given textual representation.
 

Protected Member Functions

 addSearchField (&$fields, SearchEngine $engine, $name, $type)
 Add new field definition to array.
 
 callDeprecatedContentGPO (Content $content, ContentParseParams $cpoParams)
 If provided content overrides deprecated Content::getParserOutput, call it and return.
 
 callDeprecatedContentPLT (Content $content, PreloadTransformParams $params)
 If provided content overrides deprecated Content::preloadTransform, call it and return.
 
 callDeprecatedContentPST (Content $content, PreSaveTransformParams $params)
 Provided content overrides deprecated Content::preSaveTransform, call it and return.
 
 checkFormat ( $format)
 Convenient for checking whether a format provided as a parameter is actually supported.
 
 checkModelID ( $model_id)
 
 createTextSlotDiffRenderer (array $options=[])
 Create a TextSlotDiffRenderer and inject dependencies.
 
 fillParserOutput (Content $content, ContentParseParams $cpoParams, ParserOutput &$output)
 Fills the provided ParserOutput with information derived from the content.
 
 getDiffEngineClass ()
 Returns the name of the diff engine to use.
 
 getSlotDiffRendererInternal (IContextSource $context)
 Return the SlotDiffRenderer appropriate for this content handler.
 
 getSlotDiffRendererWithOptions (IContextSource $context, $options=[])
 Return the SlotDiffRenderer appropriate for this content handler.
 
 latestRevision (WikiPage $page)
 Get the latest revision of the given $page, fetching it from the primary if necessary.
 
 shouldCallDeprecatedContentTransformMethod (Content $content, $params)
 Check if we need to provide content overrides deprecated Content method.
 

Protected Attributes

string $mModelID
 
string[] $mSupportedFormats
 

Detailed Description

A content handler knows how do deal with a specific type of content on a wiki page.

Content is stored in the database in a serialized form (using a serialization format a.k.a. MIME type) and is unserialized into its native PHP representation (the content model), which is wrapped in an instance of the appropriate subclass of Content.

ContentHandler instances are stateless singletons that serve, among other things, as a factory for Content objects. Generally, there is one subclass of ContentHandler and one subclass of Content for every type of content model.

Some content types have a flat model, that is, their native representation is the same as their serialized form. Examples would be JavaScript and CSS code. As of now, this also applies to wikitext (MediaWiki's default content type), but wikitext content may be represented by a DOM or AST structure in the future.

Stability: stable
to extend

Definition at line 71 of file ContentHandler.php.

Constructor & Destructor Documentation

◆ __construct()

ContentHandler::__construct ( $modelId,
$formats )

Constructor, initializing the ContentHandler instance with its model ID and a list of supported formats.

Values for the parameters are typically provided as literals by subclass's constructors.

Stability: stable
to call
Parameters
string$modelId(use CONTENT_MODEL_XXX constants).
string[]$formatsList for supported serialization formats (typically as MIME types)

Reimplemented in FallbackContentHandler, and TextContentHandler.

Definition at line 342 of file ContentHandler.php.

Member Function Documentation

◆ addSearchField()

ContentHandler::addSearchField ( & $fields,
SearchEngine $engine,
$name,
$type )
protected

Add new field definition to array.

Parameters
SearchIndexField[]&$fields
SearchEngine$engine
string$name
string$type
Returns
SearchIndexField[] new field defs
Since
1.28

Definition at line 1372 of file ContentHandler.php.

References SearchEngine\makeSearchFieldMapping().

◆ callDeprecatedContentGPO()

ContentHandler::callDeprecatedContentGPO ( Content $content,
ContentParseParams $cpoParams )
protected

If provided content overrides deprecated Content::getParserOutput, call it and return.

Access: internal
only core ContentHandler implementations need to call this.
Parameters
Content$content
ContentParseParams$cpoParams
Returns
ParserOutput

Definition at line 1908 of file ContentHandler.php.

References $content, MediaWiki\Content\Renderer\ContentParseParams\getGenerateHtml(), MediaWiki\Content\Renderer\ContentParseParams\getPage(), MediaWiki\Content\Renderer\ContentParseParams\getParserOptions(), and MediaWiki\Content\Renderer\ContentParseParams\getRevId().

◆ callDeprecatedContentPLT()

ContentHandler::callDeprecatedContentPLT ( Content $content,
PreloadTransformParams $params )
protected

If provided content overrides deprecated Content::preloadTransform, call it and return.

Access: internal
only core ContentHandler implementations need to call this.
Parameters
Content$content
PreloadTransformParams$params
Returns
Content

Definition at line 1887 of file ContentHandler.php.

◆ callDeprecatedContentPST()

ContentHandler::callDeprecatedContentPST ( Content $content,
PreSaveTransformParams $params )
protected

Provided content overrides deprecated Content::preSaveTransform, call it and return.

Access: internal
only core ContentHandler implementations need to call this.
Parameters
Content$content
PreSaveTransformParams$params
Returns
Content

Definition at line 1864 of file ContentHandler.php.

Referenced by CssContentHandler\preSaveTransform(), JavaScriptContentHandler\preSaveTransform(), and TextContentHandler\preSaveTransform().

◆ canBeUsedOn()

ContentHandler::canBeUsedOn ( Title $title)

Determines whether the content type handled by this ContentHandler can be used for the main slot of the given page.

This default implementation always returns true. Subclasses may override this to restrict the use of this content model to specific locations, typically based on the namespace or some other aspect of the title, such as a special suffix (e.g. ".svg" for SVG content).

Note
this calls the ContentHandlerCanBeUsedOn hook which may be used to override which content model can be used where.
Stability: stable
to override
See also
SlotRoleHandler::isAllowedModel
Parameters
Title$titleThe page's title.
Returns
bool True if content of this kind can be used on the given page, false otherwise.

Definition at line 815 of file ContentHandler.php.

◆ checkFormat()

ContentHandler::checkFormat ( $format)
protected

Convenient for checking whether a format provided as a parameter is actually supported.

Parameters
string$formatThe serialization format to check
Exceptions
MWExceptionIf the format is not supported by this content handler.

Definition at line 527 of file ContentHandler.php.

References getModelID(), and isSupportedFormat().

Referenced by TextContentHandler\serializeContent(), and TextContentHandler\unserializeContent().

◆ checkModelID()

ContentHandler::checkModelID ( $model_id)
protected
Since
1.21
Parameters
string$model_idThe model to check
Exceptions
MWExceptionIf the model ID is not the ID of the content model supported by this ContentHandler.

Definition at line 460 of file ContentHandler.php.

Referenced by TextContentHandler\merge3().

◆ createDifferenceEngine()

ContentHandler::createDifferenceEngine ( IContextSource $context,
$old = 0,
$new = 0,
$rcid = 0,
$refreshCache = false,
$unhide = false )

Factory for creating an appropriate DifferenceEngine for this content model.

Since 1.32, this is only used for page-level diffs; to diff two content objects, use getSlotDiffRenderer.

The DifferenceEngine subclass to use is selected in getDiffEngineClass(). The GetDifferenceEngine hook will receive the DifferenceEngine object and can replace or wrap it. (Note that in older versions of MediaWiki the hook documentation instructed extensions to return false from the hook; you should not rely on always being able to decorate the DifferenceEngine instance from the hook. If the owner of the content type wants to decorate the instance, overriding this method is a safer approach.)

Todo
This is page-level functionality so it should not belong to ContentHandler. Move it to a better place once one exists (e.g. PageTypeHandler).
Since
1.21
Parameters
IContextSource$contextContext to use, anything else will be ignored.
int$oldRevision ID we want to show and diff with.
int | string$newEither a revision ID or one of the strings 'cur', 'prev' or 'next'.
int$rcidFIXME: Deprecated, no longer used. Defaults to 0.
bool$refreshCacheIf set, refreshes the diff cache. Defaults to false.
bool$unhideIf set, allow viewing deleted revs. Defaults to false.
Returns
DifferenceEngine

Definition at line 586 of file ContentHandler.php.

References getDiffEngineClass().

Referenced by getSlotDiffRenderer().

◆ createTextSlotDiffRenderer()

ContentHandler::createTextSlotDiffRenderer ( array $options = [])
finalprotected

Create a TextSlotDiffRenderer and inject dependencies.

Since
1.41
Parameters
array$optionsSee getSlotDiffRenderer()
Returns
TextSlotDiffRenderer

Definition at line 672 of file ContentHandler.php.

References getModelID().

Referenced by getSlotDiffRendererWithOptions().

◆ exportTransform()

ContentHandler::exportTransform ( $blob,
$format = null )

Applies transformations on export (returns the blob unchanged per default).

Subclasses may override this to perform transformations such as conversion of legacy formats or filtering of internal meta-data.

Stability: stable
to override
Parameters
string$blobThe blob to be exported
string | null$formatThe blob's serialization format
Returns
string

Definition at line 373 of file ContentHandler.php.

◆ fillParserOutput()

ContentHandler::fillParserOutput ( Content $content,
ContentParseParams $cpoParams,
ParserOutput & $output )
protected

Fills the provided ParserOutput with information derived from the content.

Unless $cpoParams->getGenerateHtml() was false, this includes an HTML representation of the content.

If $cpoParams->getGenerateHtml() is false, and you chose not to generate html, the ParserOutput must have a text of null. If the text of the ParserOutput object is anything other than null (even if ''), it is assumed that you don't support not generating html, and that it is safe to reuse the parser output for calls expecting that html was generated.

Subclasses are expected to override this method.

This placeholder implementation always throws an exception.

Stability: stable
to override
Since
1.38
Parameters
Content$content
ContentParseParams$cpoParams
ParserOutput&$outputThe output object to fill (reference).
Exceptions
MWException

Reimplemented in CssContentHandler, FallbackContentHandler, JavaScriptContentHandler, TextContentHandler, JsonContentHandler, and WikitextContentHandler.

Definition at line 1824 of file ContentHandler.php.

◆ fillParserOutputInternal()

ContentHandler::fillParserOutputInternal ( Content $content,
ContentParseParams $cpoParams,
ParserOutput & $output )

A temporary layer to move AbstractContent::fillParserOutput to ContentHandler::fillParserOutput.

Access: internal
only core AbstractContent::fillParserOutput implementations need to call this.
Since
1.38
Parameters
Content$content
ContentParseParams$cpoParams
ParserOutput&$outputThe output object to fill (reference).

Definition at line 1792 of file ContentHandler.php.

References $content.

◆ generateHTMLOnEdit()

ContentHandler::generateHTMLOnEdit ( )

Whether an edit on the content should trigger an HTML render and ParserCache entry.

Stability: stable
to override
Since
1.37
Returns
bool true if edit should trigger an HTML render false otherwise

Definition at line 1304 of file ContentHandler.php.

◆ getActionOverrides()

ContentHandler::getActionOverrides ( )

Returns overrides for action handlers.

Classes listed here will be used instead of the default one when (and only when) $wgActions[$action] === true. This allows subclasses to override the default action handlers.

Stability: stable
to override
Since
1.21
Returns
array<string,class-string|callable|false|Action|array> An array mapping action names (typically "view", "edit", "history" etc.) to a specification according to {
See also
ActionFactory::getActionSpec}. Can be the full qualified class name of an Action class, a callable taking ( Article $article, IContextSource $context ) as parameters and returning an Action object, false to disable an action, an actual Action object, or an ObjectFactory specification array (can have 'class', 'services', etc.). An empty array in this default implementation.
Action::factory

Definition at line 555 of file ContentHandler.php.

◆ getAllContentFormats()

static ContentHandler::getAllContentFormats ( )
static
Returns
string[]
Exceptions
MWException
MWUnknownContentModelException
Deprecated
since 1.35, use ContentHandlerFactory::getAllContentFormats
See also
ContentHandlerFactory::getAllContentFormats

Definition at line 315 of file ContentHandler.php.

◆ getAutoDeleteReason()

ContentHandler::getAutoDeleteReason ( Title $title,
& $hasHistory = false )

Auto-generates a deletion reason.

Stability: stable
to override
Since
1.21
Parameters
Title$titleThe page's title
bool&$hasHistoryWhether the page has a history
Returns
string|false String containing deletion reason or empty string, or boolean false if no revision occurred

Definition at line 1069 of file ContentHandler.php.

References $content, DB_REPLICA, MediaWiki\Title\Title\getArticleID(), wfDeprecated(), wfGetDB(), and wfMessage().

◆ getAutosummary()

ContentHandler::getAutosummary ( Content $oldContent = null,
Content $newContent = null,
$flags = 0 )

Return an applicable auto-summary if one exists for the given edit.

Stability: stable
to override
Since
1.21
Parameters
Content | null$oldContentThe previous text of the page.
Content | null$newContentThe submitted text of the page.
int$flagsBit mask: a bit mask of flags submitted for the edit.
Returns
string An appropriate auto-summary, or an empty string.

Definition at line 944 of file ContentHandler.php.

References wfMessage().

◆ getChangeTag()

ContentHandler::getChangeTag ( Content $oldContent = null,
Content $newContent = null,
$flags = 0 )

Return an applicable tag if one exists for the given edit or return null.

Stability: stable
to override
Since
1.31
Parameters
Content | null$oldContentThe previous text of the page.
Content | null$newContentThe submitted text of the page.
int$flagsBit mask: a bit mask of flags submitted for the edit.
Returns
string|null An appropriate tag, or null.

Definition at line 1032 of file ContentHandler.php.

References ChangeTags\getSoftwareTags().

◆ getContentModels()

static ContentHandler::getContentModels ( )
static
Deprecated
since 1.35, use ContentHandlerFactory::getContentModels
See also
ContentHandlerFactory::getContentModels
Returns
string[]
Exceptions
MWException
MWUnknownContentModelException

Definition at line 303 of file ContentHandler.php.

◆ getContentText()

static ContentHandler::getContentText ( Content $content = null)
static

Convenience function for getting flat text from a Content object.

This should only be used in the context of backwards compatibility with code that is not yet able to handle Content objects!

If $content is null, this method returns the empty string.

If $content is an instance of TextContent, this method returns the flat text as returned by $content->getText().

If $content is not a TextContent object, the behavior of this method depends on the global $wgContentHandlerTextFallback:

  • If $wgContentHandlerTextFallback is 'fail' and $content is not a TextContent object, an MWException is thrown.
  • If $wgContentHandlerTextFallback is 'serialize' and $content is not a TextContent object, $content->serialize() is called to get a string form of the content.
  • If $wgContentHandlerTextFallback is 'ignore' and $content is not a TextContent object, this method returns null.
  • otherwise, the behavior is undefined.
Since
1.21
Deprecated
since 1.37, use Content::getText() for TextContent instances instead
Parameters
Content | null$content
Exceptions
MWExceptionIf the content is not an instance of TextContent and wgContentHandlerTextFallback was set to 'fail'.
Returns
string|null Textual form of the content, if available.

Definition at line 106 of file ContentHandler.php.

References $content, and wfDebugLog().

◆ getDataForSearchIndex()

ContentHandler::getDataForSearchIndex ( WikiPage $page,
ParserOutput $output,
SearchEngine $engine,
RevisionRecord $revision = null )

Return fields to be indexed by search engine as representation of this document.

Overriding class should call parent function or take care of calling the SearchDataForIndex hook.

The $output must be the result of a call to getParserOutputForIndexing() on the same content handler. That method may return ParserOutput without HTML; this base implementation does not rely on the HTML being present, so it is safe to call even by subclasses that override getParserOutputForIndexing() to skip HTML generation. On the other hand, since the default implementation of getParserOutputForIndexing() does generate HTML, subclasses are free to rely on the HTML here if they do not override getParserOutputForIndexing().

Stability: stable
to override
Parameters
WikiPage$pagePage to index
ParserOutput$output
SearchEngine$engineSearch engine for which we are indexing
RevisionRecord | null$revisionRevision content to fetch if provided or use the latest revision from WikiPage::getRevisionRecord() if not
Returns
array Map of name=>value for fields, an empty array is returned if the latest revision cannot be retrieved.
Since
1.28

Definition at line 1403 of file ContentHandler.php.

References $content, WikiPage\getId(), and WikiPage\getRevisionRecord().

◆ getDefaultFormat()

ContentHandler::getDefaultFormat ( )

The format used for serialization/deserialization by default by this ContentHandler.

This default implementation will return the first element of the array of formats that was passed to the constructor.

Stability: stable
to override
Since
1.21
Returns
string The name of the default serialization format as a MIME type

Definition at line 494 of file ContentHandler.php.

Referenced by TextContentHandler\merge3().

◆ getDefaultModelFor()

static ContentHandler::getDefaultModelFor ( Title $title)
static

Returns the name of the default content model to be used for the page with the given title.

Note: There should rarely be need to call this method directly. To determine the actual content model for a given page, use Title::getContentModel().

Which model is to be used by default for the page is determined based on several factors:

  • The global setting $wgNamespaceContentModels specifies a content model per namespace.
  • The hook ContentHandlerDefaultModelFor may be used to override the page's default model.
  • Pages in NS_MEDIAWIKI and NS_USER default to the CSS or JavaScript model if they end in .js or .css, respectively.
  • Pages in NS_MEDIAWIKI default to the wikitext model otherwise.
  • The hook TitleIsCssOrJsPage may be used to force a page to use the CSS or JavaScript model. This is a compatibility feature. The ContentHandlerDefaultModelFor hook should be used instead if possible.
  • The hook TitleIsWikitextPage may be used to force a page to use the wikitext model. This is a compatibility feature. The ContentHandlerDefaultModelFor hook should be used instead if possible.

If none of the above applies, the wikitext model is used.

Since
1.21
Deprecated
since 1.33, use SlotRoleHandler::getDefaultModel() together with SlotRoleRegistry::getRoleHandler().
Parameters
Title$title
Returns
string Default model name for the page given by $title

Definition at line 207 of file ContentHandler.php.

◆ getDeletionUpdates()

ContentHandler::getDeletionUpdates ( Title $title,
$role )

Returns a list of DeferrableUpdate objects for removing information about content in some secondary data store.

This is used when a page is deleted, and also when a slot is removed from a page.

Application logic should not call this method directly. Instead, it should call WikiPage::getSecondaryDataUpdates().

Note
Implementations must not return a LinksDeletionUpdate instance. Instead, a LinksDeletionUpdate is created by the calling code in WikiPage. This is in contrast to the old getDeletionUpdates method defined by AbstractContent, which returned a LinksUpdate.
Implementations should not rely on the page's current content, but rather the current state of the secondary data store.
Stability: stable
to override
Parameters
Title$titleThe title of the page to supply the updates for
string$roleThe role (slot) in which the content is being used. Which updates are performed should generally not depend on the role the content has, but the DeferrableUpdates themselves may need to know the role, to track to which slot the data refers, and to avoid overwriting data of the same kind from another slot.
Returns
DeferrableUpdate[] A list of DeferrableUpdate objects for putting information about this content object somewhere. The default implementation returns an empty array.
Since
1.32

Definition at line 1579 of file ContentHandler.php.

◆ getDiffEngineClass()

ContentHandler::getDiffEngineClass ( )
protected

Returns the name of the diff engine to use.

Stability: stable
to override
Since
1.21
Returns
class-string<DifferenceEngine>

Definition at line 831 of file ContentHandler.php.

Referenced by createDifferenceEngine().

◆ getFieldsForSearchIndex()

ContentHandler::getFieldsForSearchIndex ( SearchEngine $engine)

Get fields definition for search index.

Todo
Expose title, redirect, namespace, text, source_text, text_bytes field mappings here. (see T142670 and T143409)
Stability: stable
to override
Parameters
SearchEngine$engine
Returns
SearchIndexField[] List of fields this content handler can provide.
Since
1.28

Reimplemented in FileContentHandler, TextContentHandler, and WikitextContentHandler.

Definition at line 1331 of file ContentHandler.php.

References SearchEngine\makeSearchFieldMapping().

◆ getForContent()

static ContentHandler::getForContent ( Content $content)
static

Returns the appropriate ContentHandler singleton for the given Content object.

Deprecated
since 1.35, instead use ContentHandlerFactory::getContentHandler( $content->getModel() ).
Since
1.21
Parameters
Content$content
Returns
ContentHandler
Exceptions
MWException
MWUnknownContentModelException

Definition at line 228 of file ContentHandler.php.

References $content.

◆ getForModelID()

static ContentHandler::getForModelID ( $modelId)
static

Returns the ContentHandler singleton for the given model ID.

Use the CONTENT_MODEL_XXX constants to identify the desired content model.

ContentHandler singletons are taken from the global $wgContentHandlers array. Keys in that array are model names, the values are either ContentHandler singleton objects, or strings specifying the appropriate subclass of ContentHandler.

If a class name is encountered when looking up the singleton for a given model name, the class is instantiated and the class name is replaced by the resulting singleton in $wgContentHandlers.

If no ContentHandler is defined for the desired $modelId, the ContentHandler may be provided by the ContentHandlerForModelID hook. If no ContentHandler can be determined, an MWException is raised.

Since
1.21
Deprecated
since 1.35, use ContentHandlerFactory::getContentHandler
See also
ContentHandlerFactory::getContentHandler()
Parameters
string$modelIdThe ID of the content model for which to get a handler. Use CONTENT_MODEL_XXX constants.
Exceptions
MWExceptionFor internal errors and problems in the configuration.
MWUnknownContentModelExceptionIf no handler is known for the model ID.
Returns
ContentHandler The ContentHandler singleton for handling the model given by the ID.

Definition at line 263 of file ContentHandler.php.

◆ getLocalizedName()

static ContentHandler::getLocalizedName ( $name,
Language $lang = null )
static

Returns the localized name for a given content model.

Model names are localized using system messages. Message keys have the form content-model-$name, where $name is getContentModelName( $id ).

Parameters
string$nameThe content model ID, as given by a CONTENT_MODEL_XXX constant or returned by Content::getModel() or SlotRecord::getModel().
Language | null$langThe language to parse the message in (since 1.26)
Exceptions
MWExceptionIf the model ID isn't known.
Returns
string The content model's localized name.

Definition at line 282 of file ContentHandler.php.

References wfMessage().

◆ getModelID()

ContentHandler::getModelID ( )

Returns the model id that identifies the content model this ContentHandler can handle.

Use with the CONTENT_MODEL_XXX constants.

Since
1.21
Returns
string The model ID

Definition at line 448 of file ContentHandler.php.

Referenced by checkFormat(), createTextSlotDiffRenderer(), getSlotDiffRenderer(), and FallbackContentHandler\unserializeContent().

◆ getPageLanguage()

ContentHandler::getPageLanguage ( Title $title,
Content $content = null )

Get the language in which the content of the given page is written.

This default implementation just returns the content language (except for pages in the MediaWiki namespace)

Note that the page's language is not cacheable, since it may in some cases depend on user settings.

Also note that the page language may or may not depend on the actual content of the page, that is, this method may load the content in order to determine the language.

Stability: stable
to override
Since
1.21
Parameters
Title$titleThe page to determine the language for.
Content | null$contentThe page's content, if you have it handy, to avoid reloading it.
Returns
Language

Reimplemented in CodeContentHandler.

Definition at line 734 of file ContentHandler.php.

References $wgLang, MediaWiki\Title\Title\getText(), MediaWiki\Title\Title\inNamespace(), and NS_MEDIAWIKI.

Referenced by TextContentHandler\getDataForSearchIndex().

◆ getPageViewLanguage()

ContentHandler::getPageViewLanguage ( Title $title,
Content $content = null )

Get the language in which the content of this page is written when viewed by user.

Defaults to $this->getPageLanguage(), but if the user specified a preferred variant, the variant will be used.

This default implementation just returns $this->getPageLanguage( $title, $content ) unless the user specified a preferred variant.

Note that the pages view language is not cacheable, since it depends on user settings.

Also note that the page language may or may not depend on the actual content of the page, that is, this method may load the content in order to determine the language.

Stability: stable
to override
Since
1.21
Parameters
Title$titleThe page to determine the language for.
Content | null$contentThe page's content, if you have it handy, to avoid reloading it.
Returns
Language The page's language for viewing

Reimplemented in CodeContentHandler.

Definition at line 779 of file ContentHandler.php.

References $content, MediaWiki\Title\Title\getNamespace(), and NS_MEDIAWIKI.

◆ getParserOutput()

ContentHandler::getParserOutput ( Content $content,
ContentParseParams $cpoParams )

Returns a ParserOutput object containing information derived from this content.

Most importantly, unless $cpoParams->getGenerateHtml was false, the return value contains an HTML representation of the content.

Subclasses that want to control the parser output may override fillParserOutput() instead.

Since
1.38
Parameters
Content$content
ContentParseParams$cpoParams
Returns
ParserOutput Containing information derived from this content.

Definition at line 1719 of file ContentHandler.php.

References $content, MediaWiki\Content\Renderer\ContentParseParams\getGenerateHtml(), MediaWiki\Content\Renderer\ContentParseParams\getPage(), MediaWiki\Content\Renderer\ContentParseParams\getParserOptions(), and MediaWiki\Content\Renderer\ContentParseParams\getRevId().

◆ getParserOutputForIndexing()

ContentHandler::getParserOutputForIndexing ( WikiPage $page,
ParserCache $cache = null,
RevisionRecord $revision = null )

Produce page output suitable for indexing.

Typically used with getDataForSearchIndex().

Specific content handlers may override it if they need different content handling.

The default implementation returns output with HTML, but callers should not rely on this, and subclasses may override this method and skip HTML generation if it is not needed for indexing. (In that case, they should not attempt to store the output in the $cache.)

Stability: stable
to override
Parameters
WikiPage$page
ParserCache | null$cachedeprecated since 1.38 and won't have any effect
RevisionRecord | null$revision
Returns
ParserOutput|null null when the ParserOutput cannot be obtained
See also
ParserOutputAccess::getParserOutput() for failure modes

Definition at line 1465 of file ContentHandler.php.

References WikiPage\makeParserOptions().

◆ getSecondaryDataUpdates()

ContentHandler::getSecondaryDataUpdates ( Title $title,
Content $content,
$role,
SlotRenderingProvider $slotOutput )

Returns a list of DeferrableUpdate objects for recording information about the given Content in some secondary data store.

Application logic should not call this method directly. Instead, it should call DerivedPageDataUpdater::getSecondaryDataUpdates().

Note
Implementations must not return a LinksUpdate instance. Instead, a LinksUpdate is created by the calling code in DerivedPageDataUpdater, on the combined ParserOutput of all slots, not for each slot individually. This is in contrast to the old getSecondaryDataUpdates method defined by AbstractContent, which returned a LinksUpdate.
Implementations should not call $content->getParserOutput, they should call $slotOutput->getSlotRendering( $role, false ) instead if they need to access a ParserOutput of $content. This allows existing ParserOutput objects to be re-used, while avoiding creating a ParserOutput when none is needed.
Stability: stable
to override
Parameters
Title$titleThe title of the page to supply the updates for
Content$contentThe content to generate data updates for.
string$roleThe role (slot) in which the content is being used. Which updates are performed should generally not depend on the role the content has, but the DeferrableUpdates themselves may need to know the role, to track to which slot the data refers, and to avoid overwriting data of the same kind from another slot.
SlotRenderingProvider$slotOutputA provider that can be used to gain access to a ParserOutput of $content by calling $slotOutput->getSlotParserOutput( $role, false ).
Returns
DeferrableUpdate[] A list of DeferrableUpdate objects for putting information about this content object somewhere. The default implementation returns an empty array.
Since
1.32

Definition at line 1540 of file ContentHandler.php.

◆ getSlotDiffRenderer()

ContentHandler::getSlotDiffRenderer ( IContextSource $context,
array $options = [] )
final

Get an appropriate SlotDiffRenderer for this content model.

Stability: stable
to override
Since
1.32
Parameters
IContextSource$context
array$optionsAn associative array of options passed to the SlotDiffRenderer:
  • diff-type: (string) The text diff format
  • contentLanguage: (string) The language code of the content language, to be passed to the TextDiffer constructor. This is ignored if a TextDiffer object is provided.
  • textDiffer: (TextDiffer) A TextDiffer object to use for text comparison.
Returns
SlotDiffRenderer

Definition at line 613 of file ContentHandler.php.

References createDifferenceEngine(), getModelID(), and getSlotDiffRendererWithOptions().

◆ getSlotDiffRendererInternal()

ContentHandler::getSlotDiffRendererInternal ( IContextSource $context)
protected

Return the SlotDiffRenderer appropriate for this content handler.

Deprecated
since 1.35; use getSlotDiffRendererWithOptions instead Emitting deprecation warnings since 1.41.
Parameters
IContextSource$context
Returns
SlotDiffRenderer|null

Reimplemented in FallbackContentHandler.

Definition at line 640 of file ContentHandler.php.

Referenced by getSlotDiffRendererWithOptions().

◆ getSlotDiffRendererWithOptions()

ContentHandler::getSlotDiffRendererWithOptions ( IContextSource $context,
$options = [] )
protected

Return the SlotDiffRenderer appropriate for this content handler.

Stability: stable
to override
Parameters
IContextSource$context
array$optionsSee getSlotDiffRenderer()
Returns
SlotDiffRenderer

Definition at line 653 of file ContentHandler.php.

References createTextSlotDiffRenderer(), getSlotDiffRendererInternal(), and wfDeprecated().

Referenced by getSlotDiffRenderer().

◆ getSupportedFormats()

ContentHandler::getSupportedFormats ( )

Returns a list of serialization formats supported by the serializeContent() and unserializeContent() methods of this ContentHandler.

Stability: stable
to override
Since
1.21
Returns
string[] List of serialization formats as MIME type like strings

Definition at line 478 of file ContentHandler.php.

◆ getUndoContent()

ContentHandler::getUndoContent ( Content $currentContent,
Content $undoContent,
Content $undoAfterContent,
$undoIsLatest = false )

Get the Content object that needs to be saved in order to undo all changes between $undo and $undoafter.

Stability: stable
to override
Since
1.21
1.32 accepts Content objects for all parameters instead of Revision objects. Passing Revision objects is deprecated.
1.37 only accepts Content objects
Parameters
Content$currentContentThe current text
Content$undoContentThe content of the revision to undo
Content$undoAfterContentMust be from an earlier revision than $undo
bool$undoIsLatestSet true if $undo is from the current revision (since 1.32)
Returns
Content|false Content on success, false on failure

Definition at line 1182 of file ContentHandler.php.

References Content\equals(), and Content\getModel().

◆ importTransform()

ContentHandler::importTransform ( $blob,
$format = null )

Apply import transformation (per default, returns $blob unchanged).

This gives subclasses an opportunity to transform data blobs on import.

Stability: stable
to override
Since
1.24
Parameters
string$blob
string | null$format
Returns
string

Definition at line 403 of file ContentHandler.php.

◆ isParserCacheSupported()

ContentHandler::isParserCacheSupported ( )

Returns true for content models that support caching using the ParserCache mechanism.

See WikiPage::shouldCheckParserCache().

Stability: stable
to override
Since
1.21
Returns
bool Always false.

Reimplemented in WikitextContentHandler.

Definition at line 1223 of file ContentHandler.php.

◆ isSupportedFormat()

ContentHandler::isSupportedFormat ( $format)

Returns true if $format is a serialization format supported by this ContentHandler, and false otherwise.

Note that if $format is null, this method always returns true, because null means "use the default format".

Stability: stable
to override
Since
1.21
Parameters
string$formatThe serialization format to check
Returns
bool

Definition at line 512 of file ContentHandler.php.

Referenced by checkFormat().

◆ latestRevision()

ContentHandler::latestRevision ( WikiPage $page)
protected

Get the latest revision of the given $page, fetching it from the primary if necessary.

Parameters
WikiPage$page
Returns
RevisionRecord
Since
1.36 (previously private)

Definition at line 1491 of file ContentHandler.php.

References WikiPage\getRevisionRecord(), WikiPage\getTitle(), and WikiPage\loadPageData().

◆ makeContent()

static ContentHandler::makeContent ( $text,
Title $title = null,
$modelId = null,
$format = null )
static

Convenience function for creating a Content object from a given textual representation.

$text will be deserialized into a Content object of the model specified by $modelId (or, if that is not given, $title->getContentModel()) using the given format.

Since
1.21
Parameters
string$textThe textual representation, will be unserialized to create the Content object
Title | null$titleThe title of the page this text belongs to. Required if $modelId is not provided.
string | null$modelIdThe model to deserialize to. If not provided, $title->getContentModel() is used.
string | null$formatThe format to use for deserialization. If not given, the model's default format is used.
Exceptions
MWContentSerializationException
MWUnknownContentModelException
Returns
Content A Content object representing the text.

Definition at line 157 of file ContentHandler.php.

◆ makeEmptyContent()

ContentHandler::makeEmptyContent ( )
abstract

Creates an empty Content object of the type supported by this ContentHandler.

Stability: stable
to override
Since
1.21
Returns
Content

Reimplemented in FallbackContentHandler, JsonContentHandler, and TextContentHandler.

◆ makeRedirectContent()

ContentHandler::makeRedirectContent ( Title $destination,
$text = '' )

Creates a new Content object that acts as a redirect to the given page, or null if redirects are not supported by this content model.

This default implementation always returns null. Subclasses supporting redirects must override this method.

Note that subclasses that override this method to return a Content object should also override supportsRedirects() to return true.

Stability: stable
to override
Since
1.21
Parameters
Title$destinationThe page to redirect to.
string$textText to include in the redirect, if possible.
Returns
Content|null Always null.

Reimplemented in CssContentHandler, JavaScriptContentHandler, and WikitextContentHandler.

Definition at line 436 of file ContentHandler.php.

◆ merge3()

ContentHandler::merge3 ( Content $oldContent,
Content $myContent,
Content $yourContent )

Attempts to merge differences between three versions.

Returns a new Content object for a clean merge and false for failure or a conflict.

This default implementation always returns false.

Stability: stable
to override
Since
1.21
Parameters
Content$oldContentThe page's previous content.
Content$myContentOne of the page's conflicting contents.
Content$yourContentOne of the page's conflicting contents.
Returns
Content|false Always false.

Reimplemented in TextContentHandler.

Definition at line 850 of file ContentHandler.php.

◆ preloadTransform()

ContentHandler::preloadTransform ( Content $content,
PreloadTransformParams $pltParams )

Returns a $content object with preload transformations applied (or the same object if no transformations apply).

Note
Not stable to call other then from ContentHandler hierarchy. Callers need to use ContentTransformer::preLoadTransform.
Stability: stable
to override
Since
1.37
Parameters
Content$content
PreloadTransformParams$pltParams
Returns
Content

Reimplemented in WikitextContentHandler.

Definition at line 1630 of file ContentHandler.php.

References $content.

◆ preSaveTransform()

ContentHandler::preSaveTransform ( Content $content,
PreSaveTransformParams $pstParams )

Returns a $content object with pre-save transformations applied (or the same object if no transformations apply).

Note
Not stable to call other then from ContentHandler hierarchy. Callers need to use ContentTransformer::preSaveTransform.
Stability: stable
to override
Since
1.37
Parameters
Content$content
PreSaveTransformParams$pstParams
Returns
Content

Reimplemented in CssContentHandler, JavaScriptContentHandler, JsonContentHandler, TextContentHandler, and WikitextContentHandler.

Definition at line 1597 of file ContentHandler.php.

References $content.

◆ serializeContent()

ContentHandler::serializeContent ( Content $content,
$format = null )
abstract

Serializes a Content object of the type supported by this ContentHandler.

Stability: stable
to override
Since
1.21
Parameters
Content$contentThe Content object to serialize
string | null$formatThe desired serialization format
Returns
string Serialized form of the content

Reimplemented in FallbackContentHandler, TextContentHandler, and WikitextContentHandler.

◆ shouldCallDeprecatedContentTransformMethod()

ContentHandler::shouldCallDeprecatedContentTransformMethod ( Content $content,
$params )
protected

Check if we need to provide content overrides deprecated Content method.

Access: internal
only core ContentHandler implementations need to call this.
Parameters
Content$content
PreSaveTransformParams | PreloadTransformParams$params
Returns
bool

Definition at line 1841 of file ContentHandler.php.

Referenced by CssContentHandler\preSaveTransform(), JavaScriptContentHandler\preSaveTransform(), and TextContentHandler\preSaveTransform().

◆ supportsCategories()

ContentHandler::supportsCategories ( )

Returns true if this content model supports categories.

The default implementation returns true.

Stability: stable
to override
Returns
bool Always true.

Definition at line 1250 of file ContentHandler.php.

◆ supportsDirectApiEditing()

ContentHandler::supportsDirectApiEditing ( )

Whether or not this content model supports direct editing via ApiEditPage.

Stability: stable
to override
Returns
bool Default is false, and true for TextContent and derivatives.

Definition at line 1315 of file ContentHandler.php.

◆ supportsDirectEditing()

ContentHandler::supportsDirectEditing ( )

Return true if this content model supports direct editing, such as via EditPage.

This should return true for TextContent and its derivatives, and return false for structured data content.

Stability: stable
to override
Returns
bool Default is false.

Reimplemented in FallbackContentHandler, and TextContentHandler.

Definition at line 1278 of file ContentHandler.php.

◆ supportsPreloadContent()

ContentHandler::supportsPreloadContent ( )

If a non-existing page can be created with the contents from another (arbitrary) page being preloaded in the editor, see {.

See also
EditPage::getContentObject}. Only makes sense together with {
supportsDirectEditing}.
Stability: stable
to override
Since
1.39
Returns
bool

Reimplemented in JsonContentHandler, and WikitextContentHandler.

Definition at line 1292 of file ContentHandler.php.

◆ supportsRedirects()

ContentHandler::supportsRedirects ( )

Returns true if this content model supports redirects.

This default implementation returns false.

Content models that return true here should also implement ContentHandler::makeRedirectContent to return a Content object.

Stability: stable
to override
Returns
bool Always false.

Reimplemented in CssContentHandler, JavaScriptContentHandler, and WikitextContentHandler.

Definition at line 1265 of file ContentHandler.php.

◆ supportsSections()

ContentHandler::supportsSections ( )

Returns true if this content model supports sections.

This default implementation returns false.

Content models that return true here should also implement Content::getSection, Content::replaceSection, etc. to handle sections.

Stability: stable
to override
Returns
bool Always false.

Reimplemented in WikitextContentHandler.

Definition at line 1238 of file ContentHandler.php.

◆ unserializeContent()

ContentHandler::unserializeContent ( $blob,
$format = null )
abstract

Unserializes a Content object of the type supported by this ContentHandler.

Stability: stable
to override
Since
1.21
Parameters
string$blobSerialized form of the content
string | null$formatThe format used for serialization
Returns
Content The Content object created by deserializing $blob
Exceptions
MWContentSerializationException

Reimplemented in FallbackContentHandler, and TextContentHandler.

◆ validateSave()

ContentHandler::validateSave ( Content $content,
ValidationParams $validationParams )

Validate content for saving it.

This may be used to check the content's consistency with global state. This function should NOT write any information to the database.

Note that this method will usually be called inside the same transaction bracket that will be used to save the new revision, so the revision passed in is probably unsaved (has no id) and might belong to unsaved page.

Since
1.38
Stability: stable
to override
Parameters
Content$content
ValidationParams$validationParams
Returns
StatusValue A status object indicating if content can be saved in the given revision.

Reimplemented in JsonContentHandler.

Definition at line 1667 of file ContentHandler.php.

References $content, MediaWiki\Content\ValidationParams\getFlags(), MediaWiki\Content\ValidationParams\getPageIdentity(), and MediaWiki\Content\ValidationParams\getParentRevisionId().

Member Data Documentation

◆ $mModelID

string ContentHandler::$mModelID
protected

Definition at line 324 of file ContentHandler.php.

◆ $mSupportedFormats

string [] ContentHandler::$mSupportedFormats
protected

Definition at line 329 of file ContentHandler.php.


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