MediaWiki master
MediaWiki\Content\AbstractContent Class Reference

Base implementation for content objects. More...

Inherits MediaWiki\Content\Content.

Inherited by MediaWiki\Content\FallbackContent, and MediaWiki\Content\TextContent.

Collaboration diagram for MediaWiki\Content\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.
 
 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.
 
 replaceSection ( $sectionId, Content $with, $sectionTitle='')
 
 serialize ( $format=null)
 
 updateRedirect (Title $target)
 This default implementation always returns $this.
 
- Public Member Functions inherited from MediaWiki\Content\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.
 
 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 45 of file AbstractContent.php.

Constructor & Destructor Documentation

◆ __construct()

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

Reimplemented in MediaWiki\Content\WikitextContent.

Definition at line 63 of file AbstractContent.php.

Member Function Documentation

◆ addSectionHeader()

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

Implements MediaWiki\Content\Content.

Reimplemented in MediaWiki\Content\WikitextContent.

Definition at line 373 of file AbstractContent.php.

◆ checkFormat()

MediaWiki\Content\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 156 of file AbstractContent.php.

◆ checkModelID()

MediaWiki\Content\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 85 of file AbstractContent.php.

Referenced by MediaWiki\Content\TextContent\diff().

◆ convert()

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

Reimplemented in MediaWiki\Content\FallbackContent, and MediaWiki\Content\TextContent.

Definition at line 407 of file AbstractContent.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ equals()

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

Definition at line 249 of file AbstractContent.php.

Referenced by MediaWiki\Content\CssContent\getRedirectTarget().

◆ equalsInternal()

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

Definition at line 290 of file AbstractContent.php.

References MediaWiki\Content\Content\serialize().

◆ getContentHandler()

◆ getContentHandlerFactory()

MediaWiki\Content\AbstractContent::getContentHandlerFactory ( )
protected
Returns
IContentHandlerFactory

Definition at line 108 of file AbstractContent.php.

Referenced by MediaWiki\Content\TextContent\convert(), and MediaWiki\Content\AbstractContent\getContentHandler().

◆ getDefaultFormat()

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

Implements MediaWiki\Content\Content.

Definition at line 118 of file AbstractContent.php.

◆ getModel()

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

Implements MediaWiki\Content\Content.

Definition at line 73 of file AbstractContent.php.

References MediaWiki\Content\AbstractContent\$model_id.

Referenced by MediaWiki\Content\AbstractContent\getContentHandler(), and MediaWiki\Content\WikitextContent\replaceSection().

◆ getNativeData()

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

Reimplemented in MediaWiki\Content\FallbackContent, and MediaWiki\Content\TextContent.

Definition at line 197 of file AbstractContent.php.

References wfDeprecated().

◆ getRedirectTarget()

MediaWiki\Content\AbstractContent::getRedirectTarget ( )

Subclasses that implement redirects should override this.

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

Implements MediaWiki\Content\Content.

Reimplemented in MediaWiki\Content\CssContent, MediaWiki\Content\JavaScriptContent, and MediaWiki\Content\WikitextContent.

Definition at line 304 of file AbstractContent.php.

◆ getSection()

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

Implements MediaWiki\Content\Content.

Reimplemented in MediaWiki\Content\WikitextContent.

Definition at line 345 of file AbstractContent.php.

◆ getSupportedFormats()

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

Implements MediaWiki\Content\Content.

Definition at line 128 of file AbstractContent.php.

◆ isEmpty()

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

Implements MediaWiki\Content\Content.

Definition at line 210 of file AbstractContent.php.

◆ isRedirect()

◆ isSupportedFormat()

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

Implements MediaWiki\Content\Content.

Definition at line 141 of file AbstractContent.php.

◆ isValid()

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

Reimplemented in MediaWiki\Content\JsonContent.

Definition at line 224 of file AbstractContent.php.

◆ matchMagicWord()

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

Reimplemented in MediaWiki\Content\WikitextContent.

Definition at line 390 of file AbstractContent.php.

◆ replaceSection()

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

Reimplemented in MediaWiki\Content\WikitextContent.

Definition at line 360 of file AbstractContent.php.

◆ serialize()

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

Implements MediaWiki\Content\Content.

Reimplemented in MediaWiki\Content\FallbackContent.

Definition at line 175 of file AbstractContent.php.

◆ updateRedirect()

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

Reimplemented in MediaWiki\Content\CssContent, MediaWiki\Content\JavaScriptContent, and MediaWiki\Content\WikitextContent.

Definition at line 332 of file AbstractContent.php.

Member Data Documentation

◆ $model_id

string MediaWiki\Content\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 54 of file AbstractContent.php.

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


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