MediaWiki 1.41.2
AbstractContent Class Reference

Base implementation for content objects. More...

Inherits Content.

Inherited by FallbackContent, MessageContent, and TextContent.

Collaboration diagram for AbstractContent:

Public Member Functions

 __construct ( $modelId=null)
 
 addSectionHeader ( $header)
 
 convert ( $toModel, $lossy='')
 This base implementation calls the hook ConvertContent to enable custom conversions.
 
 equals (Content $that=null)
 Decides whether two Content objects are equal.
 
 getContentHandler ()
 
 getDefaultFormat ()
 
 getModel ()
 
 getNativeData ()
 Returns native representation of the data.
 
 getParserOutput (Title $title, $revId=null, ParserOptions $options=null, $generateHtml=true)
 Returns a ParserOutput object containing information derived from this content.
 
 getRedirectTarget ()
 Subclasses that implement redirects should override this.
 
 getSection ( $sectionId)
 
 getSupportedFormats ()
 
 isEmpty ()
 
 isRedirect ()
 
 isSupportedFormat ( $format)
 
 isValid ()
 Subclasses may override this to implement (light weight) validation.
 
 matchMagicWord (MagicWord $word)
 This default implementation always returns false.
 
 preloadTransform (Title $title, ParserOptions $popts, $params=[])
 
 prepareSave (WikiPage $page, $flags, $parentRevId, User $user)
 
 preSaveTransform (Title $title, User $user, ParserOptions $popts)
 
 replaceSection ( $sectionId, Content $with, $sectionTitle='')
 
 serialize ( $format=null)
 
 updateRedirect (Title $target)
 This default implementation always returns $this.
 
- Public Member Functions inherited from Content
 copy ()
 Return a copy of this Content object.
 
 getSize ()
 Returns the content's nominal size in "bogo-bytes".
 
 getTextForSearchIndex ()
 
 getTextForSummary ( $maxLength=250)
 Returns a textual representation of the content suitable for use in edit summaries and log messages.
 
 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.
 

Protected Member Functions

 checkFormat ( $format)
 
 checkModelID ( $modelId)
 
 equalsInternal (Content $that)
 Checks whether $that is logically equal to this Content object.
 
 fillParserOutput (Title $title, $revId, ParserOptions $options, $generateHtml, ParserOutput &$output)
 Fills the provided ParserOutput with information derived from the content.
 
 getContentHandlerFactory ()
 

Protected Attributes

string $model_id
 Name of the content model this Content object represents.
 

Detailed Description

Base implementation for content objects.

Stability: stable
to extend

Definition at line 48 of file AbstractContent.php.

Constructor & Destructor Documentation

◆ __construct()

AbstractContent::__construct ( $modelId = null)
Stability: stable
to call
Parameters
string | null$modelId
Since
1.21

Reimplemented in WikitextContent.

Definition at line 66 of file AbstractContent.php.

Member Function Documentation

◆ addSectionHeader()

AbstractContent::addSectionHeader ( $header)
Stability: stable
to override
Since
1.21
Parameters
string$header
Returns
Content $this
See also
Content::addSectionHeader

Implements Content.

Reimplemented in WikitextContent.

Definition at line 398 of file AbstractContent.php.

◆ checkFormat()

AbstractContent::checkFormat ( $format)
protected
Since
1.21
Parameters
string$formatThe serialization format to check.
Exceptions
MWExceptionIf the format is not supported by this content handler.

Definition at line 159 of file AbstractContent.php.

◆ checkModelID()

AbstractContent::checkModelID ( $modelId)
protected
Since
1.21
Parameters
string$modelIdThe model to check
Exceptions
MWExceptionIf the provided ID is not the ID of the content model supported by this Content object.

Definition at line 88 of file AbstractContent.php.

Referenced by TextContent\diff().

◆ convert()

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

This base implementation calls the hook ConvertContent to enable custom conversions.

Subclasses may override this to implement conversion for "their" content model.

Stability: stable
to override
Parameters
string$toModel
string$lossy
Returns
Content|false
See also
Content::convert()

Implements Content.

Reimplemented in FallbackContent, and TextContent.

Definition at line 491 of file AbstractContent.php.

◆ equals()

AbstractContent::equals ( Content $that = null)

Decides whether two Content objects are equal.

Two Content objects MUST not be considered equal if they do not share the same content model. Two Content objects that are equal SHOULD have the same serialization.

This default implementation relies on equalsInternal() to determine whether the Content objects are logically equivalent. Subclasses that need to implement a custom equality check should consider overriding equalsInternal(). Subclasses that override equals() itself MUST make sure that the implementation returns false for $that === null, and true for $that === this. It MUST also return false if $that does not have the same content model.

Stability: stable
to override
Since
1.21
Parameters
Content | null$that
Returns
bool
See also
Content::equals

Implements Content.

Definition at line 252 of file AbstractContent.php.

Referenced by CssContent\getRedirectTarget(), and JavaScriptContent\getRedirectTarget().

◆ equalsInternal()

AbstractContent::equalsInternal ( Content $that)
protected

Checks whether $that is logically equal to this Content object.

This method can be overwritten by subclasses that need to implement custom equality checks.

This default implementation checks whether the serializations of $this and $that are the same: $this->serialize() === $that->serialize()

Implementors can assume that $that is an instance of the same class as the present Content object, as long as equalsInternal() is only called by the standard implementation of equals().

Note
Do not call this method directly, call equals() instead.
Stability: stable
to override
Parameters
Content$that
Returns
bool

Reimplemented in FallbackContent.

Definition at line 293 of file AbstractContent.php.

References Content\serialize().

◆ fillParserOutput()

AbstractContent::fillParserOutput ( Title $title,
$revId,
ParserOptions $options,
$generateHtml,
ParserOutput & $output )
protected

Fills the provided ParserOutput with information derived from the content.

Unless $generateHtml was false, this includes an HTML representation of the content.

This is called by getParserOutput() after consulting the ContentGetParserOutput hook. Subclasses are expected to override this method (or getParserOutput(), if need be). Subclasses of TextContent should generally override getHtml() instead.

This placeholder implementation always throws an exception.

Since
1.24
Deprecated
since 1.38. Hard-deprecated since 1.38. Use ContentHandler::fillParserOutput instead.
Parameters
Title$titleContext title for parsing
int | null$revIdID of the revision being rendered. See Parser::parse() for the ramifications.
ParserOptions$options
bool$generateHtmlWhether or not to generate HTML
ParserOutput&$outputThe output object to fill (reference).
Exceptions
MWException

Definition at line 596 of file AbstractContent.php.

References wfDeprecated().

◆ getContentHandler()

AbstractContent::getContentHandler ( )

◆ getContentHandlerFactory()

AbstractContent::getContentHandlerFactory ( )
protected
Returns
IContentHandlerFactory

Definition at line 111 of file AbstractContent.php.

Referenced by TextContent\convert(), and getContentHandler().

◆ getDefaultFormat()

AbstractContent::getDefaultFormat ( )
Since
1.21
See also
Content::getDefaultFormat
Returns
string

Implements Content.

Definition at line 121 of file AbstractContent.php.

◆ getModel()

AbstractContent::getModel ( )
Since
1.21
See also
Content::getModel
Returns
string

Implements Content.

Definition at line 76 of file AbstractContent.php.

References $model_id.

Referenced by getContentHandler(), and WikitextContent\replaceSection().

◆ getNativeData()

AbstractContent::getNativeData ( )

Returns native representation of the data.

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

Stability: stable
to override
Since
1.21
Deprecated
since 1.33. Use getText() for TextContent instances. For other content models, use specialized getters. Emitting deprecation warnings since 1.41.
Returns
mixed The native representation of the content. Could be a string, a nested array structure, an object, a binary blob... anything, really.
Exceptions
LogicException
Note
Caller must be aware of content model!

Implements Content.

Reimplemented in FallbackContent, MessageContent, and TextContent.

Definition at line 200 of file AbstractContent.php.

References wfDeprecated().

◆ getParserOutput()

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

Returns a ParserOutput object containing information derived from this content.

Most importantly, unless $generateHtml was false, the return value contains an HTML representation of the content.

Subclasses that want to control the parser output may override this, but it is preferred to override fillParserOutput() instead.

Subclasses that override getParserOutput() itself should take care to call the ContentGetParserOutput hook.

Since
1.24
Deprecated
since 1.38. Hard-deprecated since 1.38. Use ContentRenderer::getParserOutput instead. Extensions defining a content model should override ContentHandler::fillParserOutput.
Parameters
Title$titleContext title for parsing
int | null$revIdRevision ID being rendered
ParserOptions | null$options
bool$generateHtmlWhether or not to generate HTML
Returns
ParserOutput Containing information derived from this content.

Implements Content.

Definition at line 527 of file AbstractContent.php.

References wfDeprecated().

◆ getRedirectTarget()

AbstractContent::getRedirectTarget ( )

Subclasses that implement redirects should override this.

Stability: stable
to override
Since
1.21
Returns
Title|null
See also
Content::getRedirectTarget

Implements Content.

Reimplemented in CssContent, JavaScriptContent, and WikitextContent.

Definition at line 307 of file AbstractContent.php.

◆ getSection()

AbstractContent::getSection ( $sectionId)
Stability: stable
to override
Since
1.21
Parameters
string | int$sectionId
Returns
null
See also
Content::getSection

Implements Content.

Reimplemented in WikitextContent.

Definition at line 348 of file AbstractContent.php.

◆ getSupportedFormats()

AbstractContent::getSupportedFormats ( )
Since
1.21
See also
Content::getSupportedFormats
Returns
string[]

Implements Content.

Definition at line 131 of file AbstractContent.php.

◆ isEmpty()

AbstractContent::isEmpty ( )
Stability: stable
to override
Since
1.21
Returns
bool
See also
Content::isEmpty

Implements Content.

Definition at line 213 of file AbstractContent.php.

◆ isRedirect()

AbstractContent::isRedirect ( )

◆ isSupportedFormat()

AbstractContent::isSupportedFormat ( $format)
Since
1.21
Parameters
string$format
Returns
bool
See also
Content::isSupportedFormat

Implements Content.

Definition at line 144 of file AbstractContent.php.

◆ isValid()

AbstractContent::isValid ( )

Subclasses may override this to implement (light weight) validation.

Stability: stable
to override
Since
1.21
Returns
bool Always true.
See also
Content::isValid

Implements Content.

Reimplemented in JsonContent.

Definition at line 227 of file AbstractContent.php.

◆ matchMagicWord()

AbstractContent::matchMagicWord ( MagicWord $word)

This default implementation always returns false.

Subclasses may override this to supply matching logic.

Stability: stable
to override
Since
1.21
Parameters
MagicWord$word
Returns
bool Always false.
See also
Content::matchMagicWord

Implements Content.

Reimplemented in WikitextContent.

Definition at line 474 of file AbstractContent.php.

◆ preloadTransform()

AbstractContent::preloadTransform ( Title $title,
ParserOptions $popts,
$params = [] )
Since
1.21
Deprecated
since 1.37. Hard-deprecated since 1.37. Use ContentTransformer::preloadTransform instead. Extensions defining a content model should override ContentHandler::preloadTransform.
Parameters
Title$title
ParserOptions$popts
array$params
Returns
Content $this
See also
Content::preloadTransform

Implements Content.

Definition at line 413 of file AbstractContent.php.

References wfDeprecated().

◆ prepareSave()

AbstractContent::prepareSave ( WikiPage $page,
$flags,
$parentRevId,
User $user )
Since
1.21
Deprecated
since 1.38. Hard-deprecated since 1.38. Use ContentHandler::validateSave instead.
Parameters
WikiPage$page
int$flags
int$parentRevId
User$user
Returns
Status
See also
Content::prepareSave

Implements Content.

Definition at line 435 of file AbstractContent.php.

References wfDeprecated().

◆ preSaveTransform()

AbstractContent::preSaveTransform ( Title $title,
User $user,
ParserOptions $popts )
Since
1.21
Deprecated
since 1.37. Hard-deprecated since 1.37. Use ContentTransformer::preSaveTransform instead. Extensions defining a content model should override ContentHandler::preSaveTransform.
Parameters
Title$title
User$user
ParserOptions$popts
Returns
Content $this
See also
Content::preSaveTransform

Implements Content.

Definition at line 380 of file AbstractContent.php.

References wfDeprecated().

◆ replaceSection()

AbstractContent::replaceSection ( $sectionId,
Content $with,
$sectionTitle = '' )
Stability: stable
to override
Since
1.21
Parameters
string | int | null | false$sectionId
Content$with
string$sectionTitle
Returns
null
See also
Content::replaceSection

Implements Content.

Reimplemented in WikitextContent.

Definition at line 363 of file AbstractContent.php.

◆ serialize()

AbstractContent::serialize ( $format = null)
Stability: stable
to override
Since
1.21
Parameters
string | null$format
Returns
string
See also
Content::serialize

Implements Content.

Reimplemented in FallbackContent.

Definition at line 178 of file AbstractContent.php.

◆ updateRedirect()

AbstractContent::updateRedirect ( Title $target)

This default implementation always returns $this.

Subclasses that implement redirects should override this.

Stability: stable
to override
Since
1.21
Parameters
Title$target
Returns
Content $this
See also
Content::updateRedirect

Implements Content.

Reimplemented in CssContent, JavaScriptContent, and WikitextContent.

Definition at line 335 of file AbstractContent.php.

Member Data Documentation

◆ $model_id

string AbstractContent::$model_id
protected

Name of the content model this Content object represents.

Use with CONTENT_MODEL_XXX constants

Since
1.21

Definition at line 57 of file AbstractContent.php.

Referenced by FallbackContent\__construct(), TextContent\__construct(), and getModel().


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