MediaWiki
1.28.0
|
Base interface for content objects. More...
Public Member Functions | |
addSectionHeader ($header) | |
Returns a new WikitextContent object with the given section heading prepended, if supported. More... | |
convert ($toModel, $lossy= '') | |
Converts this content object into another content object with the given content model, if that is possible. More... | |
copy () | |
Return a copy of this Content object. More... | |
equals (Content $that=null) | |
Returns true if this Content objects is conceptually equivalent to the given Content object. More... | |
getContentHandler () | |
Convenience method that returns the ContentHandler singleton for handling the content model that this Content object uses. More... | |
getDefaultFormat () | |
Convenience method that returns the default serialization format for the content model that this Content object uses. More... | |
getDeletionUpdates (WikiPage $page, ParserOutput $parserOutput=null) | |
Returns a list of updates to perform when this content is deleted. More... | |
getModel () | |
Returns the ID of the content model used by this Content object. More... | |
getNativeData () | |
Returns native representation of the data. More... | |
getParserOutput (Title $title, $revId=null, ParserOptions $options=null, $generateHtml=true) | |
Parse the Content object and generate a ParserOutput from the result. More... | |
getRedirectChain () | |
Construct the redirect destination from this content and return an array of Titles, or null if this content doesn't represent a redirect. More... | |
getRedirectTarget () | |
Construct the redirect destination from this content and return a Title, or null if this content doesn't represent a redirect. More... | |
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. More... | |
getSection ($sectionId) | |
Returns the section with the given ID. More... | |
getSize () | |
Returns the content's nominal size in "bogo-bytes". More... | |
getSupportedFormats () | |
Convenience method that returns the list of serialization formats supported for the content model that this Content object uses. More... | |
getTextForSearchIndex () | |
getTextForSummary ($maxLength=250) | |
Returns a textual representation of the content suitable for use in edit summaries and log messages. More... | |
getUltimateRedirectTarget () | |
Construct the redirect destination from this content and return the Title, or null if this content doesn't represent a redirect. More... | |
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. More... | |
isEmpty () | |
Returns true if this Content object represents empty content. More... | |
isRedirect () | |
Returns whether this Content represents a redirect. More... | |
isSupportedFormat ($format) | |
Returns true if $format is a supported serialization format for this Content object, false if it isn't. More... | |
isValid () | |
Returns whether the content is valid. More... | |
matchMagicWord (MagicWord $word) | |
Returns true if this Content object matches the given magic word. More... | |
preloadTransform (Title $title, ParserOptions $parserOptions, $params=[]) | |
Returns a Content object with preload transformations applied (or this object if no transformations apply). More... | |
prepareSave (WikiPage $page, $flags, $parentRevId, User $user) | |
Prepare Content for saving. More... | |
preSaveTransform (Title $title, User $user, ParserOptions $parserOptions) | |
Returns a Content object with pre-save transformations applied (or this object if no transformations apply). More... | |
replaceSection ($sectionId, Content $with, $sectionTitle= '') | |
Replaces a section of the content and returns a Content object with the section replaced. More... | |
serialize ($format=null) | |
Convenience method for serializing this Content object. More... | |
updateRedirect (Title $target) | |
If this Content object is a redirect, this method updates the redirect target. More... | |
Base interface for content objects.
Definition at line 34 of file Content.php.
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.
string | $header |
Implemented in AbstractContent, and WikitextContent.
Content::convert | ( | $toModel, | |
$lossy = '' |
|||
) |
Converts this content object into another content object with the given content model, if that is possible.
string | $toModel | The desired content model, use the CONTENT_MODEL_XXX flags. |
string | $lossy | Optional 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. |
Implemented in AbstractContent, and TextContent.
Content::copy | ( | ) |
Return a copy of this Content object.
The following must be true for the object returned:
if $copy = $original->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.
Implemented in RevisionTestModifyableContent, MessageContent, DummyContentForTesting, DummyNonTextContent, and TextContent.
Content::equals | ( | Content | $that = null | ) |
Returns true if this Content objects is conceptually equivalent to the given Content object.
Contract:
Implementations should be careful to make equals() transitive and reflexive:
Implemented in AbstractContent.
Referenced by WikiPage\doModify(), CssContentTest\testEquals(), and TextContentTest\testEquals().
Content::getContentHandler | ( | ) |
Convenience method that returns the ContentHandler singleton for handling the content model that this Content object uses.
Shorthand for ContentHandler::getForContent( $this )
Implemented in AbstractContent.
Referenced by WikiPage\doEditContent(), and WikiPage\prepareContentForEdit().
Content::getDefaultFormat | ( | ) |
Convenience method that returns the default serialization format for the content model that this Content object uses.
Shorthand for $this->getContentHandler()->getDefaultFormat()
Implemented in AbstractContent.
Referenced by ApiStashEdit\getContentHash(), and ApiStashEdit\parseAndStash().
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.
WikiPage | $page | The deleted page |
ParserOutput | $parserOutput | Optional parser output object for efficient access to meta-information about the content object. Provide if you have one handy. |
Implemented in AbstractContent.
Content::getModel | ( | ) |
Returns the ID of the content model used by this Content object.
Corresponds to the CONTENT_MODEL_XXX constants.
Implemented in AbstractContent.
Referenced by TextContent\diff(), WikiPage\doCreate(), WikiPage\doEditContent(), WikiPage\doModify(), ApiStashEdit\getContentHash(), ContentHandler\getForContent(), TextContentHandler\merge3(), and WikitextContent\replaceSection().
Content::getNativeData | ( | ) |
Returns native representation of the data.
Interpretation depends on the data model used, as given by getDataModel().
Implemented in TextContent, MessageContent, DummyContentForTesting, and DummyNonTextContent.
Referenced by TextContent\diff(), AbstractContent\equals(), LinkFilter\matchEntry(), WikitextContent\replaceSection(), and TextContentHandler\serializeContent().
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.
Title | $title | The page title to use as a context for rendering. |
int | $revId | Optional revision ID being rendered. |
ParserOptions | $options | Any parser options. |
bool | $generateHtml | Whether to generate HTML (default: true). If false, the result of calling getText() on the ParserOutput object returned by this method is undefined. |
Implemented in AbstractContent, MessageContent, DummyContentForTesting, and DummyNonTextContent.
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).
Implemented in AbstractContent.
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.
Implemented in AbstractContent, WikitextContent, JavaScriptContent, and CssContent.
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.
Title | $title | The context for determining the necessary updates |
Content | $old | An optional Content object representing the previous content, i.e. the content being replaced by this Content object. |
bool | $recursive | Whether to include recursive updates (default: false). |
ParserOutput | $parserOutput | Optional ParserOutput object. Provide if you have one handy, to avoid re-parsing of the content. |
Implemented in AbstractContent.
Content::getSection | ( | $sectionId | ) |
Returns the section with the given ID.
string | number | $sectionId | Section 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. |
Implemented in AbstractContent, and WikitextContent.
Referenced by ApiParse\getSectionContent().
Content::getSize | ( | ) |
Returns the content's nominal size in "bogo-bytes".
Implemented in MessageContent, TextContent, DummyContentForTesting, and DummyNonTextContent.
Referenced by WikiPage\doCreate(), WikiPage\doModify(), and AbstractContent\isEmpty().
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()
Implemented in AbstractContent.
Content::getTextForSearchIndex | ( | ) |
Test that this actually works
Make sure this also works with LuceneSearch / WikiSearch
Implemented in TextContent, MessageContent, DummyContentForTesting, and DummyNonTextContent.
Content::getTextForSummary | ( | $maxLength = 250 | ) |
Returns a textual representation of the content suitable for use in edit summaries and log messages.
int | $maxLength | Maximum length of the summary text. |
Implemented in WikitextContent, MessageContent, TextContent, DummyContentForTesting, and DummyNonTextContent.
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().
Implemented in AbstractContent.
Content::getWikitextForTransclusion | ( | ) |
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 TextContent, MessageContent, DummyContentForTesting, and DummyNonTextContent.
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).
bool | null | $hasLinks | If it is known whether this content contains links, provide this information here, to avoid redundant parsing to find out. |
Implemented in MessageContent, TextContent, DummyContentForTesting, and DummyNonTextContent.
Content::isEmpty | ( | ) |
Returns true if this Content object represents empty content.
Implemented in AbstractContent.
Content::isRedirect | ( | ) |
Returns whether this Content represents a redirect.
Shorthand for getRedirectTarget() !== null.
Implemented in AbstractContent.
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 )
string | $format | The serialization format to check. |
Implemented in AbstractContent.
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.
Implemented in AbstractContent, and JsonContent.
Content::matchMagicWord | ( | MagicWord | $word | ) |
Returns true if this Content object matches the given magic word.
MagicWord | $word | The magic word to match |
Implemented in AbstractContent, and WikitextContent.
Content::preloadTransform | ( | Title | $title, |
ParserOptions | $parserOptions, | ||
$params = [] |
|||
) |
Returns a Content object with preload transformations applied (or this object if no transformations apply).
Title | $title | |
ParserOptions | $parserOptions | |
array | $params |
Implemented in AbstractContent, and WikitextContent.
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.
WikiPage | $page | The page to be saved. |
int | $flags | Bitfield for use with EDIT_XXX constants, see WikiPage::doEditContent() |
int | $parentRevId | The ID of the current revision |
User | $user |
Implemented in AbstractContent.
Referenced by WikiPage\doCreate(), and WikiPage\doModify().
Content::preSaveTransform | ( | Title | $title, |
User | $user, | ||
ParserOptions | $parserOptions | ||
) |
Returns a Content object with pre-save transformations applied (or this object if no transformations apply).
Title | $title | |
User | $user | |
ParserOptions | $parserOptions |
Implemented in AbstractContent, TextContent, WikitextContent, JsonContent, CssContent, and JavaScriptContent.
Referenced by EditPage\doPreviewParse(), and WikiPage\prepareContentForEdit().
Content::replaceSection | ( | $sectionId, | |
Content | $with, | ||
$sectionTitle = '' |
|||
) |
Replaces a section of the content and returns a Content object with the section replaced.
string | number | null | bool | $sectionId | Section 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 | $with | New content of the section |
string | $sectionTitle | New section's subject, only if $section is 'new' |
Implemented in AbstractContent, and WikitextContent.
Content::serialize | ( | $format = null | ) |
Convenience method for serializing this Content object.
Shorthand for $this->getContentHandler()->serializeContent( $this, $format )
string | $format | The desired serialization format, or null for the default format. |
Implemented in AbstractContent, DummyContentForTesting, and DummyNonTextContent.
Referenced by EditPage\displayViewSourcePage(), DifferenceEngine\generateContentDiffBody(), ApiStashEdit\getContentHash(), DummyNonTextContentHandler\serializeContent(), and DummyContentHandlerForTesting\serializeContent().
Content::updateRedirect | ( | Title | $target | ) |
If this Content object is a redirect, this method updates the redirect target.
Otherwise, it does nothing.
Title | $target | The new redirect target |
Implemented in AbstractContent, WikitextContent, JavaScriptContent, and CssContent.