MediaWiki REL1_31
Content Interface Reference

Base interface for content objects. More...

Inheritance diagram for Content:

Public Member Functions

 addSectionHeader ( $header)
 Returns a new WikitextContent object with the given section heading prepended, if supported.
 
 convert ( $toModel, $lossy='')
 Converts this content object into another content object with the given content model, if that is possible.
 
 copy ()
 Return a copy of this Content object.
 
 equals (Content $that=null)
 Returns true if this Content objects is conceptually equivalent to the given Content object.
 
 getContentHandler ()
 Convenience method that returns the ContentHandler singleton for handling the content model that this Content object uses.
 
 getDefaultFormat ()
 Convenience method that returns the default serialization format for the content model that this Content object uses.
 
 getDeletionUpdates (WikiPage $page, ParserOutput $parserOutput=null)
 Returns a list of updates to perform when this content is deleted.
 
 getModel ()
 Returns the ID of the content model used by this Content object.
 
 getNativeData ()
 Returns native representation of the data.
 
 getParserOutput (Title $title, $revId=null, ParserOptions $options=null, $generateHtml=true)
 Parse the Content object and generate a ParserOutput from the result.
 
 getRedirectChain ()
 Construct the redirect destination from this content and return an array of Titles, or null if this content doesn't represent a redirect.
 
 getRedirectTarget ()
 Construct the redirect destination from this content and return a Title, or null if this content doesn't represent a redirect.
 
 getSecondaryDataUpdates (Title $title, Content $old=null, $recursive=true, ParserOutput $parserOutput=null)
 Returns a list of DataUpdate objects for recording information about this Content in some secondary data store.
 
 getSection ( $sectionId)
 Returns the section with the given ID.
 
 getSize ()
 Returns the content's nominal size in "bogo-bytes".
 
 getSupportedFormats ()
 Convenience method that returns the list of serialization formats supported for the content model that this Content object uses.
 
 getTextForSearchIndex ()
 
 getTextForSummary ( $maxLength=250)
 Returns a textual representation of the content suitable for use in edit summaries and log messages.
 
 getUltimateRedirectTarget ()
 Construct the redirect destination from this content and return the Title, or null if this content doesn't represent a redirect.
 
 getWikitextForTransclusion ()
 
 isCountable ( $hasLinks=null)
 Returns true if this content is countable as a "real" wiki page, provided that it's also in a countable location (e.g.
 
 isEmpty ()
 Returns true if this Content object represents empty content.
 
 isRedirect ()
 Returns whether this Content represents a redirect.
 
 isSupportedFormat ( $format)
 Returns true if $format is a supported serialization format for this Content object, false if it isn't.
 
 isValid ()
 Returns whether the content is valid.
 
 matchMagicWord (MagicWord $word)
 Returns true if this Content object matches the given magic word.
 
 preloadTransform (Title $title, ParserOptions $parserOptions, $params=[])
 Returns a Content object with preload transformations applied (or this object if no transformations apply).
 
 prepareSave (WikiPage $page, $flags, $parentRevId, User $user)
 Prepare Content for saving.
 
 preSaveTransform (Title $title, User $user, ParserOptions $parserOptions)
 Returns a Content object with pre-save transformations applied (or this object if no transformations apply).
 
 replaceSection ( $sectionId, Content $with, $sectionTitle='')
 Replaces a section of the content and returns a Content object with the section replaced.
 
 serialize ( $format=null)
 Convenience method for serializing this Content object.
 
 updateRedirect (Title $target)
 If this Content object is a redirect, this method updates the redirect target.
 

Detailed Description

Base interface for content objects.

Definition at line 34 of file Content.php.

Member Function Documentation

◆ addSectionHeader()

Content::addSectionHeader ( $header)

Returns a new WikitextContent object with the given section heading prepended, if supported.

The default implementation just returns this Content object unmodified, ignoring the section header.

Since
1.21
Parameters
string$header
Returns
Content

Implemented in AbstractContent, and WikitextContent.

◆ convert()

Content::convert ( $toModel,
$lossy = '' )

Converts this content object into another content object with the given content model, if that is possible.

Parameters
string$toModelThe desired content model, use the CONTENT_MODEL_XXX flags.
string$lossyOptional flag, set to "lossy" to allow lossy conversion. If lossy conversion is not allowed, full round-trip conversion is expected to work without losing information.
Returns
Content|bool A content object with the content model $toModel, or false if that conversion is not supported.

Implemented in AbstractContent, and TextContent.

◆ copy()

Content::copy ( )

Return a copy of this Content object.

The following must be true for the object returned:

if $copy = $original->copy()

  • get_class($original) === get_class($copy)
  • $original->getModel() === $copy->getModel()
  • $original->equals( $copy )

If and only if the Content object is immutable, the copy() method can and should return $this. That is, $copy === $original may be true, but only for immutable content objects.

Since
1.21
Returns
Content A copy of this object

Implemented in MessageContent, TextContent, RevisionTestModifyableContent, DummyContentForTesting, and DummyNonTextContent.

◆ equals()

Content::equals ( Content $that = null)

Returns true if this Content objects is conceptually equivalent to the given Content object.

Contract:

  • Will return false if $that is null.
  • Will return true if $that === $this.
  • Will return false if $that->getModel() != $this->getModel().
  • Will return false if $that->getNativeData() is not equal to $this->getNativeData(), where the meaning of "equal" depends on the actual data model.

Implementations should be careful to make equals() transitive and reflexive:

  • $a->equals( $b ) <=> $b->equals( $a )
  • $a->equals( $b ) && $b->equals( $c ) ==> $a->equals( $c )
Since
1.21
Parameters
Content$thatThe Content object to compare to.
Returns
bool True if this Content object is equal to $that, false otherwise.

Implemented in AbstractContent.

Referenced by WikiPage\doModify().

◆ getContentHandler()

Content::getContentHandler ( )

Convenience method that returns the ContentHandler singleton for handling the content model that this Content object uses.

Shorthand for ContentHandler::getForContent( $this )

Since
1.21
Returns
ContentHandler

Implemented in AbstractContent.

Referenced by MediaWiki\Storage\RevisionStore\checkContentModel(), WikiPage\doEditContent(), and WikiPage\prepareContentForEdit().

◆ getDefaultFormat()

Content::getDefaultFormat ( )

Convenience method that returns the default serialization format for the content model that this Content object uses.

Shorthand for $this->getContentHandler()->getDefaultFormat()

Since
1.21
Returns
string

Implemented in AbstractContent.

Referenced by MediaWiki\Storage\RevisionStore\checkContentModel(), ApiStashEdit\getContentHash(), and ApiStashEdit\parseAndStash().

◆ getDeletionUpdates()

Content::getDeletionUpdates ( WikiPage $page,
ParserOutput $parserOutput = null )

Returns a list of updates to perform when this content is deleted.

The necessary updates may be taken from the Content object, or depend on the current state of the database.

Since
1.21
Parameters
WikiPage$pageThe deleted page
ParserOutput | null$parserOutputOptional parser output object for efficient access to meta-information about the content object. Provide if you have one handy.
Returns
DeferrableUpdate[] A list of DeferrableUpdate instances that will clean up the database after deletion.

Implemented in GadgetDefinitionContent, and AbstractContent.

◆ getModel()

Content::getModel ( )

Returns the ID of the content model used by this Content object.

Corresponds to the CONTENT_MODEL_XXX constants.

Since
1.21
Returns
string The model id

Implemented in AbstractContent.

Referenced by MediaWiki\Storage\RevisionStore\checkContentModel(), WikiPage\doCreate(), WikiPage\doEditContent(), WikiPage\doModify(), ApiStashEdit\getContentHash(), ContentHandler\getForContent(), TextContentHandler\merge3(), MediaWiki\Storage\SlotRecord\newUnsaved(), and onContentGetParserOutput().

◆ getNativeData()

Content::getNativeData ( )

Returns native representation of the data.

Interpretation depends on the data model used, as given by getDataModel().

Since
1.21
Returns
mixed The native representation of the content. Could be a string, a nested array structure, an object, a binary blob... anything, really.
Note
Caller must be aware of content model!

Implemented in MessageContent, TextContent, DummyContentForTesting, and DummyNonTextContent.

Referenced by AbstractContent\equals(), LinkFilter\matchEntry(), and TextContentHandler\serializeContent().

◆ getParserOutput()

Content::getParserOutput ( Title $title,
$revId = null,
ParserOptions $options = null,
$generateHtml = true )

Parse the Content object and generate a ParserOutput from the result.

$result->getText() can be used to obtain the generated HTML. If no HTML is needed, $generateHtml can be set to false; in that case, $result->getText() may return null.

Note
To control which options are used in the cache key for the generated parser output, implementations of this method may call ParserOutput::recordOption() on the output object.
Parameters
Title$titleThe page title to use as a context for rendering.
int$revIdOptional revision ID being rendered.
ParserOptions$optionsAny parser options.
bool$generateHtmlWhether to generate HTML (default: true). If false, the result of calling getText() on the ParserOutput object returned by this method is undefined.
Since
1.21
Returns
ParserOutput

Implemented in AbstractContent, MessageContent, DummyContentForTesting, and DummyNonTextContent.

Referenced by PoolWorkArticleView\doWork().

◆ getRedirectChain()

Content::getRedirectChain ( )

Construct the redirect destination from this content and return an array of Titles, or null if this content doesn't represent a redirect.

The last element in the array is the final destination after all redirects have been resolved (up to $wgMaxRedirects times).

Since
1.21
Returns
Title[]|null List of Titles, with the destination last.

Implemented in AbstractContent.

◆ getRedirectTarget()

Content::getRedirectTarget ( )

Construct the redirect destination from this content and return a Title, or null if this content doesn't represent a redirect.

This will only return the immediate redirect target, useful for the redirect table and other checks that don't need full recursion.

Since
1.21
Returns
Title|null The corresponding Title.

Implemented in AbstractContent, CssContent, JavaScriptContent, and WikitextContent.

◆ getSecondaryDataUpdates()

Content::getSecondaryDataUpdates ( Title $title,
Content $old = null,
$recursive = true,
ParserOutput $parserOutput = null )

Returns a list of DataUpdate objects for recording information about this Content in some secondary data store.

If the optional second argument, $old, is given, the updates may model only the changes that need to be made to replace information about the old content with information about the new content.

This default implementation calls $this->getParserOutput( $content, $title, null, null, false ), and then calls getSecondaryDataUpdates( $title, $recursive ) on the resulting ParserOutput object.

Subclasses may implement this to determine the necessary updates more efficiently, or make use of information about the old content.

Note
Implementations should call the SecondaryDataUpdates hook, like AbstractContent does.
Parameters
Title$titleThe context for determining the necessary updates
Content$oldAn optional Content object representing the previous content, i.e. the content being replaced by this Content object.
bool$recursiveWhether to include recursive updates (default: false).
ParserOutput$parserOutputOptional ParserOutput object. Provide if you have one handy, to avoid re-parsing of the content.
Returns
DataUpdate[] A list of DataUpdate objects for putting information about this content object somewhere.
Since
1.21

Implemented in GadgetDefinitionContent, and AbstractContent.

◆ getSection()

Content::getSection ( $sectionId)

Returns the section with the given ID.

Since
1.21
Parameters
string | int$sectionIdSection identifier as a number or string (e.g. 0, 1 or 'T-1'). The ID "0" retrieves the section before the first heading, "1" the text between the first heading (included) and the second heading (excluded), etc.
Returns
Content|bool|null The section, or false if no such section exist, or null if sections are not supported.

Implemented in AbstractContent, and WikitextContent.

◆ getSize()

Content::getSize ( )

Returns the content's nominal size in "bogo-bytes".

Returns
int

Implemented in MessageContent, TextContent, DummyContentForTesting, and DummyNonTextContent.

Referenced by WikiPage\doCreate(), WikiPage\doModify(), and AbstractContent\isEmpty().

◆ getSupportedFormats()

Content::getSupportedFormats ( )

Convenience method that returns the list of serialization formats supported for the content model that this Content object uses.

Shorthand for $this->getContentHandler()->getSupportedFormats()

Since
1.21
Returns
string[] List of supported serialization formats

Implemented in AbstractContent.

◆ getTextForSearchIndex()

Content::getTextForSearchIndex ( )
Since
1.21
Returns
string A string representing the content in a way useful for building a full text search index. If no useful representation exists, this method returns an empty string.
Todo

Test that this actually works

Make sure this also works with LuceneSearch / WikiSearch

Implemented in MessageContent, TextContent, DummyContentForTesting, and DummyNonTextContent.

◆ getTextForSummary()

Content::getTextForSummary ( $maxLength = 250)

Returns a textual representation of the content suitable for use in edit summaries and log messages.

Since
1.21
Parameters
int$maxLengthMaximum length of the summary text.
Returns
string The summary text.

Implemented in MessageContent, TextContent, WikitextContent, DummyContentForTesting, and DummyNonTextContent.

◆ getUltimateRedirectTarget()

Content::getUltimateRedirectTarget ( )

Construct the redirect destination from this content and return the Title, or null if this content doesn't represent a redirect.

This will recurse down $wgMaxRedirects times or until a non-redirect target is hit in order to provide (hopefully) the Title of the final destination instead of another redirect.

There is usually no need to override the default behavior, subclasses that want to implement redirects should override getRedirectTarget().

Since
1.21
Returns
Title|null

Implemented in AbstractContent.

◆ getWikitextForTransclusion()

Content::getWikitextForTransclusion ( )
Since
1.21
Returns
string|bool The wikitext to include when another page includes this content, or false if the content is not includable in a wikitext page.
Todo

Allow native handling, bypassing wikitext representation, like for includable special pages.

Allow transclusion into other content models than Wikitext!

Used in WikiPage and MessageCache to get message text. Not so nice. What should we use instead?!

Implemented in MessageContent, TextContent, DummyContentForTesting, and DummyNonTextContent.

◆ isCountable()

Content::isCountable ( $hasLinks = null)

Returns true if this content is countable as a "real" wiki page, provided that it's also in a countable location (e.g.

a current revision in the main namespace).

Since
1.21
Parameters
bool | null$hasLinksIf it is known whether this content contains links, provide this information here, to avoid redundant parsing to find out.
Returns
bool

Implemented in MessageContent, TextContent, DummyContentForTesting, and DummyNonTextContent.

◆ isEmpty()

Content::isEmpty ( )

Returns true if this Content object represents empty content.

Since
1.21
Returns
bool Whether this Content object is empty

Implemented in AbstractContent.

◆ isRedirect()

Content::isRedirect ( )

Returns whether this Content represents a redirect.

Shorthand for getRedirectTarget() !== null.

Since
1.21
Returns
bool

Implemented in AbstractContent.

◆ isSupportedFormat()

Content::isSupportedFormat ( $format)

Returns true if $format is a supported serialization format for this Content object, false if it isn't.

Note that this should always return true if $format is null, because null stands for the default serialization.

Shorthand for $this->getContentHandler()->isSupportedFormat( $format )

Since
1.21
Parameters
string$formatThe serialization format to check.
Returns
bool Whether the format is supported

Implemented in AbstractContent.

◆ isValid()

Content::isValid ( )

Returns whether the content is valid.

This is intended for local validity checks, not considering global consistency.

Content needs to be valid before it can be saved.

This default implementation always returns true.

Since
1.21
Returns
bool

Implemented in GadgetDefinitionContent, AbstractContent, and JsonContent.

Referenced by MediaWiki\Storage\RevisionStore\checkContentModel().

◆ matchMagicWord()

Content::matchMagicWord ( MagicWord $word)

Returns true if this Content object matches the given magic word.

Since
1.21
Parameters
MagicWord$wordThe magic word to match
Returns
bool Whether this Content object matches the given magic word.

Implemented in AbstractContent, and WikitextContent.

◆ preloadTransform()

Content::preloadTransform ( Title $title,
ParserOptions $parserOptions,
$params = [] )

Returns a Content object with preload transformations applied (or this object if no transformations apply).

Since
1.21
Parameters
Title$title
ParserOptions$parserOptions
array$params
Returns
Content

Implemented in AbstractContent, and WikitextContent.

◆ prepareSave()

Content::prepareSave ( WikiPage $page,
$flags,
$parentRevId,
User $user )

Prepare Content for saving.

Called before Content is saved by WikiPage::doEditContent() and in similar places.

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.

Note that this method is called before any update to the page table is performed. This means that $page may not yet know a page ID.

Since
1.21
Parameters
WikiPage$pageThe page to be saved.
int$flagsBitfield for use with EDIT_XXX constants, see WikiPage::doEditContent()
int$parentRevIdThe ID of the current revision
User$user
Returns
Status A status object indicating whether the content was successfully prepared for saving. If the returned status indicates an error, a rollback will be performed and the transaction aborted.
See also
WikiPage::doEditContent()

Implemented in AbstractContent.

Referenced by WikiPage\doCreate(), and WikiPage\doModify().

◆ preSaveTransform()

Content::preSaveTransform ( Title $title,
User $user,
ParserOptions $parserOptions )

Returns a Content object with pre-save transformations applied (or this object if no transformations apply).

Since
1.21
Parameters
Title$title
User$user
ParserOptions$parserOptions
Returns
Content

Implemented in AbstractContent, CssContent, JavaScriptContent, JsonContent, TextContent, and WikitextContent.

Referenced by EditPage\doPreviewParse(), and WikiPage\prepareContentForEdit().

◆ replaceSection()

Content::replaceSection ( $sectionId,
Content $with,
$sectionTitle = '' )

Replaces a section of the content and returns a Content object with the section replaced.

Since
1.21
Parameters
string | int | null | bool$sectionIdSection identifier as a number or string (e.g. 0, 1 or 'T-1'), null/false or an empty string for the whole page or 'new' for a new section.
Content$withNew content of the section
string$sectionTitleNew section's subject, only if $section is 'new'
Returns
string|null Complete article text, or null if error

Implemented in AbstractContent, and WikitextContent.

◆ serialize()

Content::serialize ( $format = null)

Convenience method for serializing this Content object.

Shorthand for $this->getContentHandler()->serializeContent( $this, $format )

Since
1.21
Parameters
string$formatThe desired serialization format, or null for the default format.
Returns
string Serialized form of this Content object.

Implemented in AbstractContent, DummyContentForTesting, and DummyNonTextContent.

Referenced by EditPage\displayViewSourcePage(), DifferenceEngine\generateContentDiffBody(), ApiStashEdit\getContentHash(), DummyContentHandlerForTesting\serializeContent(), and DummyNonTextContentHandler\serializeContent().

◆ updateRedirect()

Content::updateRedirect ( Title $target)

If this Content object is a redirect, this method updates the redirect target.

Otherwise, it does nothing.

Since
1.21
Parameters
Title$targetThe new redirect target
Returns
Content A new Content object with the updated redirect (or $this if this Content object isn't a redirect)

Implemented in AbstractContent, CssContent, JavaScriptContent, and WikitextContent.


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