MediaWiki master
|
Content objects represent page content, e.g. More...
Inherited by MediaWiki\Content\AbstractContent.
Public Member Functions | |
addSectionHeader ( $header) | |
Create a derived WikitextContent with a prepended section heading, or return $this. | |
convert ( $toModel, $lossy='') | |
Converts this content object into another content object with the given content model, if that is possible. | |
copy () | |
Create a copy of this Content object. | |
equals (?Content $that=null) | |
Whether this Content object is conceptually equivalent to another one. | |
getContentHandler () | |
Convenience method that returns the ContentHandler singleton for handling the content model that this Content object uses. | |
getDefaultFormat () | |
Get the default serialization format. | |
getModel () | |
Get the content model ID. | |
getNativeData () | |
Get native representation of the data. | |
getRedirectTarget () | |
Get the redirect destination or null if this content doesn't represent a redirect. | |
getSection ( $sectionId) | |
Create a derived Content for the portion of text in the specified section. | |
getSize () | |
Get the content's nominal size in "bogo-bytes". | |
getSupportedFormats () | |
Get the list of supported serialization formats. | |
getTextForSearchIndex () | |
getTextForSummary ( $maxLength=250) | |
Get a textual representation of the content, suitable for use in edit summaries and log messages. | |
getWikitextForTransclusion () | |
isCountable ( $hasLinks=null) | |
Whether this content may count towards a "real" wiki page. | |
isEmpty () | |
Whether this Content object is considered empty. | |
isRedirect () | |
Whether this Content represents a redirect. | |
isSupportedFormat ( $format) | |
Whether a given format is a supported serialization format for this Content. | |
isValid () | |
Whether the content is valid. | |
matchMagicWord (MagicWord $word) | |
Returns true if this Content object matches the given magic word. | |
replaceSection ( $sectionId, Content $with, $sectionTitle='') | |
Create a derived Content with the specified section added or replaced. | |
serialize ( $format=null) | |
Serialize this Content object. | |
updateRedirect (Title $target) | |
Create a derived Content with a replaced redirect destination. | |
Content objects represent page content, e.g.
the text shown on a page.
Content objects must have no knowledge of what page they belong to, or how they relate to pages in general. This information belongs in page and revision records instead, flowing down to the content, instead of up in the other direction.
NOTE: This interface must NOT be implemented directly by extensions as it may grow in backwards incompatible ways. Extend the AbstractContent class instead.
Definition at line 42 of file Content.php.
MediaWiki\Content\Content::addSectionHeader | ( | $header | ) |
Create a derived WikitextContent with a prepended section heading, or return $this.
If the content model does not support section headings, the same Content object is returned unmodified. The default AbstractContent implementation returns $this unmodified, ignoring the section header.
string | $header |
Implemented in MediaWiki\Content\AbstractContent, and MediaWiki\Content\WikitextContent.
MediaWiki\Content\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 MediaWiki\Content\AbstractContent, MediaWiki\Content\FallbackContent, and MediaWiki\Content\TextContent.
MediaWiki\Content\Content::copy | ( | ) |
Create a copy of this Content object.
The following must be true for the returned object, given $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 fully immutable value objects.
Implemented in MediaWiki\Content\FallbackContent, and MediaWiki\Content\TextContent.
MediaWiki\Content\Content::equals | ( | ?Content | $that = null | ) |
Whether this Content object is conceptually equivalent to another one.
Contract:
$that === $this
.$that->getModel() !== $this->getModel()
.get_class( $that ) !== get_class( $this )
.$that->getModel() == $this->getModel()
and the contents are considered semantically equivalent according to the data model defined by $this->getModel()
.Two Content objects that are equal SHOULD have the same serialization.
Implementations should be careful to make equals() transitive and reflexive:
This default AbstractContent::equals implementation fulfills the above and relies on Contenet::serialize() (via AbstractContent::equalsInternal) to determine whether Content objects are logically equivalent. Subclasses that only need to implement a custom equality check should consider overriding AbstractContent::equalsInternal().
Content | null | $that | The Content object to compare to. |
Implemented in MediaWiki\Content\AbstractContent.
Referenced by MediaWiki\Content\ContentHandler\getUndoContent(), and MediaWiki\Content\TextContentHandler\merge3().
MediaWiki\Content\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 MediaWiki\Content\AbstractContent, and MediaWiki\Content\WikitextContent.
Referenced by DifferenceEngine\generateContentDiffBody().
MediaWiki\Content\Content::getDefaultFormat | ( | ) |
Get the default serialization format.
Convenience method as shorthand for $this->getContentHandler()->getDefaultFormat()
.
Implemented in MediaWiki\Content\AbstractContent.
Referenced by WikiRevision\setContent().
MediaWiki\Content\Content::getModel | ( | ) |
Get the content model ID.
Implemented in MediaWiki\Content\AbstractContent.
Referenced by MediaWiki\Content\TextContent\diff(), MediaWiki\Content\CssContentHandler\fillParserOutput(), MediaWiki\Content\FallbackContentHandler\fillParserOutput(), MediaWiki\Content\JavaScriptContentHandler\fillParserOutput(), MediaWiki\Content\TextContentHandler\fillParserOutput(), MediaWiki\Content\ContentHandler\getForContent(), MediaWiki\Content\ContentHandler\getUndoContent(), MediaWiki\Content\TextContentHandler\merge3(), MediaWiki\Revision\SlotRecord\newUnsaved(), MediaWiki\Content\WikitextContent\replaceSection(), and WikiRevision\setContent().
MediaWiki\Content\Content::getNativeData | ( | ) |
Get native representation of the data.
Implemented in MediaWiki\Content\AbstractContent, MediaWiki\Content\FallbackContent, and MediaWiki\Content\TextContent.
MediaWiki\Content\Content::getRedirectTarget | ( | ) |
Get the redirect destination or null if this content doesn't represent a redirect.
Implemented in MediaWiki\Content\AbstractContent, MediaWiki\Content\CssContent, MediaWiki\Content\JavaScriptContent, and MediaWiki\Content\WikitextContent.
Referenced by MediaWiki\Content\ContentHandler\getParserOutput().
MediaWiki\Content\Content::getSection | ( | $sectionId | ) |
Create a derived Content for the portion of text in the specified section.
string | int | $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 MediaWiki\Content\AbstractContent, and MediaWiki\Content\WikitextContent.
MediaWiki\Content\Content::getSize | ( | ) |
Get the content's nominal size in "bogo-bytes".
Implemented in MediaWiki\Content\FallbackContent, and MediaWiki\Content\TextContent.
MediaWiki\Content\Content::getSupportedFormats | ( | ) |
Get the list of supported serialization formats.
Shorthand for $this->getContentHandler()->getSupportedFormats()
.
Implemented in MediaWiki\Content\AbstractContent.
MediaWiki\Content\Content::getTextForSearchIndex | ( | ) |
Implemented in MediaWiki\Content\FallbackContent, and MediaWiki\Content\TextContent.
MediaWiki\Content\Content::getTextForSummary | ( | $maxLength = 250 | ) |
Get a textual representation of the content, suitable for use in edit summaries and log messages.
int | $maxLength | Maximum length of the summary text, in bytes. Usually implemented using Language::truncateForDatabase() . |
Implemented in MediaWiki\Content\FallbackContent, MediaWiki\Content\TextContent, and MediaWiki\Content\WikitextContent.
MediaWiki\Content\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 MediaWiki\Content\FallbackContent, and MediaWiki\Content\TextContent.
MediaWiki\Content\Content::isCountable | ( | $hasLinks = null | ) |
Whether this content may count towards a "real" wiki page.
The only factor not taken into account here is the content location (i.e. whether the content belongs to a current revision, of an existant page, in a "content" 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 MediaWiki\Content\FallbackContent, and MediaWiki\Content\TextContent.
MediaWiki\Content\Content::isEmpty | ( | ) |
Whether this Content object is considered empty.
Implemented in MediaWiki\Content\AbstractContent.
MediaWiki\Content\Content::isRedirect | ( | ) |
Whether this Content represents a redirect.
Shorthand for getRedirectTarget() !== null.
Implemented in MediaWiki\Content\AbstractContent.
MediaWiki\Content\Content::isSupportedFormat | ( | $format | ) |
Whether a given format is a supported serialization format for this Content.
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 MediaWiki\Content\AbstractContent.
MediaWiki\Content\Content::isValid | ( | ) |
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.
The default AbstractContent implementation always returns true.
Implemented in MediaWiki\Content\AbstractContent, and MediaWiki\Content\JsonContent.
Referenced by MediaWiki\Content\JsonContentHandler\fillParserOutput(), MediaWiki\Parser\ParserObserver\notifyParse(), and MediaWiki\Content\ContentHandler\validateSave().
MediaWiki\Content\Content::matchMagicWord | ( | MagicWord | $word | ) |
Returns true if this Content object matches the given magic word.
MagicWord | $word | The magic word to match |
Implemented in MediaWiki\Content\AbstractContent, and MediaWiki\Content\WikitextContent.
MediaWiki\Content\Content::replaceSection | ( | $sectionId, | |
Content | $with, | ||
$sectionTitle = '' ) |
Create a derived Content with the specified section added or replaced.
string | int | null | false | $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 MediaWiki\Content\AbstractContent, and MediaWiki\Content\WikitextContent.
Referenced by MediaWiki\Content\WikitextContent\replaceSection().
MediaWiki\Content\Content::serialize | ( | $format = null | ) |
Serialize this Content object.
Shorthand for $this->getContentHandler()->serializeContent( $this, $format )
string | null | $format | The desired serialization format, or null for the default format. |
Implemented in MediaWiki\Content\AbstractContent, and MediaWiki\Content\FallbackContent.
Referenced by MediaWiki\Content\AbstractContent\equalsInternal(), MediaWiki\Parser\ParserObserver\notifyParse(), and WikiRevision\setContent().
MediaWiki\Content\Content::updateRedirect | ( | Title | $target | ) |
Create a derived Content with a replaced redirect destination.
If the content is not already a redirect, this method returns the same object unchanged. If the content can contain other information besides a redirect (e.g. WikitextContent::updateRedirect) then that information is preserved. Otherwise it is effectively the same as creating a new content object via ContentHandler::makeRedirectContent.
Title | $target | The new redirect target |
Implemented in MediaWiki\Content\AbstractContent, MediaWiki\Content\CssContent, MediaWiki\Content\JavaScriptContent, and MediaWiki\Content\WikitextContent.