MediaWiki master
MediaWiki\Content\TextContentHandler Class Reference

Base content handler implementation for flat text contents. More...

Inherits MediaWiki\Content\ContentHandler.

Inherited by MediaWiki\Content\CodeContentHandler, and MediaWiki\Content\WikitextContentHandler.

Collaboration diagram for MediaWiki\Content\TextContentHandler:

Public Member Functions

 __construct ( $modelId=CONTENT_MODEL_TEXT, $formats=[CONTENT_FORMAT_TEXT])
 Constructor, initializing the ContentHandler instance with its model ID and a list of supported formats.
 
 getDataForSearchIndex (WikiPage $page, ParserOutput $output, SearchEngine $engine, ?RevisionRecord $revision=null)
 
 getFieldsForSearchIndex (SearchEngine $engine)
 Get fields definition for search index.
 
 makeEmptyContent ()
 Creates an empty TextContent object.
 
 merge3 (Content $oldContent, Content $myContent, Content $yourContent)
 Attempts to merge differences between three versions.
 
 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)
 Returns the content's text as-is.
 
 supportsDirectEditing ()
 
 unserializeContent ( $text, $format=null)
 Unserializes a Content object of the type supported by this ContentHandler.
 
- Public Member Functions inherited from MediaWiki\Content\ContentHandler
 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 by 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.
 
 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 (by 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.
 
 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.
 
 preloadTransform (Content $content, PreloadTransformParams $pltParams)
 Returns a $content object with preload transformations applied (or the same object if no transformations apply).
 
 supportsCategories ()
 Returns true if this content model supports categories.
 
 supportsDirectApiEditing ()
 Whether or not this content model supports direct editing via ApiEditPage.
 
 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.
 
 validateSave (Content $content, ValidationParams $validationParams)
 Validate content for saving it.
 

Protected Member Functions

 fillParserOutput (Content $content, ContentParseParams $cpoParams, ParserOutput &$output)
 Fills the provided ParserOutput object with information derived from the content.
 
 getContentClass ()
 Returns the name of the associated Content class, to be used when creating new objects.
 
- Protected Member Functions inherited from MediaWiki\Content\ContentHandler
 addSearchField (&$fields, SearchEngine $engine, $name, $type)
 Add new field definition to array.
 
 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.
 
 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.
 

Additional Inherited Members

- Static Public Member Functions inherited from MediaWiki\Content\ContentHandler
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 Attributes inherited from MediaWiki\Content\ContentHandler
string $mModelID
 
string[] $mSupportedFormats
 

Detailed Description

Base content handler implementation for flat text contents.

Definition at line 44 of file TextContentHandler.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Content\TextContentHandler::__construct ( $modelId = CONTENT_MODEL_TEXT,
$formats = CONTENT_FORMAT_TEXT ] )

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 from MediaWiki\Content\ContentHandler.

Definition at line 46 of file TextContentHandler.php.

Member Function Documentation

◆ fillParserOutput()

MediaWiki\Content\TextContentHandler::fillParserOutput ( Content $content,
ContentParseParams $cpoParams,
ParserOutput & $output )
protected

Fills the provided ParserOutput object with information derived from the content.

Unless $generateHtml was false, this includes an HTML representation of the content provided by getHtml().

For content models listed in $wgTextModelsToParse, this method will call the MediaWiki wikitext parser on the text to extract any (wikitext) links, magic words, etc., but note that the Table of Contents will not be generated (feature added by T307691, but should be refactored: T313455).

Subclasses may override this to provide custom content processing. For custom HTML generation alone, it is sufficient to override getHtml().

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

Reimplemented from MediaWiki\Content\ContentHandler.

Reimplemented in MediaWiki\Content\CssContentHandler, MediaWiki\Content\JavaScriptContentHandler, MediaWiki\Content\JsonContentHandler, and MediaWiki\Content\WikitextContentHandler.

Definition at line 221 of file TextContentHandler.php.

References MediaWiki\Parser\ParserOutput\clearWrapperDivClass(), MediaWiki\Content\Renderer\ContentParseParams\getGenerateHtml(), MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Content\Content\getModel(), MediaWiki\Content\Renderer\ContentParseParams\getPage(), MediaWiki\Content\Renderer\ContentParseParams\getParserOptions(), MediaWiki\Content\Renderer\ContentParseParams\getRevId(), MediaWiki\Parser\ParserOutput\setRawText(), and MediaWiki\MainConfigNames\TextModelsToParse.

◆ getContentClass()

MediaWiki\Content\TextContentHandler::getContentClass ( )
protected

Returns the name of the associated Content class, to be used when creating new objects.

Override expected by subclasses.

Since
1.24
Returns
class-string<TextContent>

Reimplemented in MediaWiki\Content\CodeContentHandler, MediaWiki\Content\CssContentHandler, MediaWiki\Content\JavaScriptContentHandler, MediaWiki\Content\JsonContentHandler, and MediaWiki\Content\WikitextContentHandler.

Definition at line 125 of file TextContentHandler.php.

Referenced by MediaWiki\Content\TextContentHandler\makeEmptyContent(), and MediaWiki\Content\TextContentHandler\unserializeContent().

◆ getDataForSearchIndex()

MediaWiki\Content\TextContentHandler::getDataForSearchIndex ( WikiPage $page,
ParserOutput $output,
SearchEngine $engine,
?RevisionRecord $revision = null )

◆ getFieldsForSearchIndex()

MediaWiki\Content\TextContentHandler::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 from MediaWiki\Content\ContentHandler.

Reimplemented in MediaWiki\Content\FileContentHandler, and MediaWiki\Content\WikitextContentHandler.

Definition at line 167 of file TextContentHandler.php.

References SearchEngine\makeSearchFieldMapping().

◆ makeEmptyContent()

MediaWiki\Content\TextContentHandler::makeEmptyContent ( )

Creates an empty TextContent object.

Since
1.21
Returns
Content A new TextContent object with empty text.

Reimplemented from MediaWiki\Content\ContentHandler.

Reimplemented in MediaWiki\Content\JsonContentHandler.

Definition at line 153 of file TextContentHandler.php.

References MediaWiki\Content\TextContentHandler\getContentClass().

Referenced by MediaWiki\Content\TextContentHandler\merge3().

◆ merge3()

MediaWiki\Content\TextContentHandler::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.

All three Content objects passed as parameters must have the same content model.

This text-based implementation uses wfMerge().

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

Reimplemented from MediaWiki\Content\ContentHandler.

Definition at line 80 of file TextContentHandler.php.

References MediaWiki\Content\ContentHandler\checkModelID(), MediaWiki\Content\Content\equals(), MediaWiki\Content\ContentHandler\getDefaultFormat(), MediaWiki\Content\Content\getModel(), MediaWiki\Content\TextContentHandler\makeEmptyContent(), MediaWiki\Content\TextContentHandler\serializeContent(), MediaWiki\Content\TextContentHandler\unserializeContent(), and wfMerge().

◆ preSaveTransform()

MediaWiki\Content\TextContentHandler::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 from MediaWiki\Content\ContentHandler.

Reimplemented in MediaWiki\Content\CssContentHandler, MediaWiki\Content\JavaScriptContentHandler, MediaWiki\Content\JsonContentHandler, and MediaWiki\Content\WikitextContentHandler.

Definition at line 187 of file TextContentHandler.php.

◆ serializeContent()

MediaWiki\Content\TextContentHandler::serializeContent ( Content $content,
$format = null )

Returns the content's text as-is.

Parameters
Content$content
string | null$formatThe serialization format to check
Returns
mixed

Reimplemented from MediaWiki\Content\ContentHandler.

Reimplemented in MediaWiki\Content\WikitextContentHandler.

Definition at line 58 of file TextContentHandler.php.

References MediaWiki\Content\ContentHandler\checkFormat().

Referenced by MediaWiki\Content\TextContentHandler\merge3().

◆ supportsDirectEditing()

MediaWiki\Content\TextContentHandler::supportsDirectEditing ( )
See also
ContentHandler::supportsDirectEditing
Returns
bool Should return true for TextContent and derivatives.

Reimplemented from MediaWiki\Content\ContentHandler.

Definition at line 163 of file TextContentHandler.php.

◆ unserializeContent()

MediaWiki\Content\TextContentHandler::unserializeContent ( $text,
$format = null )

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

Since
1.21
Parameters
string$textSerialized form of the content
string | null$formatThe format used for serialization
Returns
Content The TextContent object wrapping $text

Reimplemented from MediaWiki\Content\ContentHandler.

Definition at line 139 of file TextContentHandler.php.

References MediaWiki\Content\ContentHandler\checkFormat(), and MediaWiki\Content\TextContentHandler\getContentClass().

Referenced by MediaWiki\Content\TextContentHandler\merge3().


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