MediaWiki master
MediaWiki\Content\AbstractContent Class Reference

Base class for all 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)
 
 getContentHandler ()
 
 getDefaultFormat ()
 
 getModel ()
 
 getNativeData ()
 
 getRedirectTarget ()
 Subclasses that implement redirects should override this.
 
 getSection ( $sectionId)
 
 getSupportedFormats ()
 
 isEmpty ()
 
 isRedirect ()
 
 isSupportedFormat ( $format)
 
 isValid ()
 
 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 ()
 Create a copy of this Content object.
 
 getSize ()
 Get the content's nominal size in "bogo-bytes".
 
 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.
 

Protected Member Functions

 checkFormat ( $format)
 Helper for subclasses.
 
 checkModelID ( $modelId)
 Helper for subclasses.
 
 equalsInternal (Content $that)
 Helper for AbstractContent::equals.
 
 getContentHandlerFactory ()
 

Protected Attributes

string $model_id
 

Detailed Description

Base class for all Content objects.

Refer to Content for more information.

Stability: stable
to extend
Since
1.21

Definition at line 38 of file AbstractContent.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Content\AbstractContent::__construct ( $modelId = null)
Stability: stable
to call
Since
1.21
Parameters
string | null$modelIdOne of the CONTENT_MODEL_XXX constants.

Reimplemented in MediaWiki\Content\WikitextContent.

Definition at line 50 of file AbstractContent.php.

Member Function Documentation

◆ addSectionHeader()

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

Implements MediaWiki\Content\Content.

Reimplemented in MediaWiki\Content\WikitextContent.

Definition at line 302 of file AbstractContent.php.

◆ checkFormat()

MediaWiki\Content\AbstractContent::checkFormat ( $format)
protected

Helper for subclasses.

Since
1.21
Parameters
string$formatThe serialization format to check.
Exceptions
MWExceptionIf the format is not supported by this Content object

Definition at line 130 of file AbstractContent.php.

◆ checkModelID()

MediaWiki\Content\AbstractContent::checkModelID ( $modelId)
protected

Helper for subclasses.

Since
1.21
Parameters
string$modelIdThe model to check
Exceptions
MWExceptionIf the provided model ID differs from this Content object

Definition at line 70 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
See also
Content::convert()
Parameters
string$toModel
string$lossy
Returns
Content|false

Implements MediaWiki\Content\Content.

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

Definition at line 330 of file AbstractContent.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ equals()

MediaWiki\Content\AbstractContent::equals ( ?Content $that = null)
See also
Content::equals
Stability: stable
to override
Since
1.21
Parameters
Content | null$that
Returns
bool

Implements MediaWiki\Content\Content.

Definition at line 190 of file AbstractContent.php.

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

◆ equalsInternal()

MediaWiki\Content\AbstractContent::equalsInternal ( Content $that)
protected

Helper for AbstractContent::equals.

Note
Do not call this method directly, call Content::equals() instead.

This method can be overwritten by subclasses that only need to implement custom equality checks, with the rest of the Content::equals contract taken care of by AbstractContent::equals.

This default implementation compares Content::serialize of each object.

If you override this method, you can safely assume that $that is an instance of the same class as the current Content object. This is ensured by AbstractContent::equals.

See also
Content::equals
Stability: stable
to override
Parameters
Content$that
Returns
bool

Reimplemented in MediaWiki\Content\FallbackContent.

Definition at line 230 of file AbstractContent.php.

References MediaWiki\Content\Content\serialize().

◆ getContentHandler()

◆ getContentHandlerFactory()

MediaWiki\Content\AbstractContent::getContentHandlerFactory ( )
protected

◆ getDefaultFormat()

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

Implements MediaWiki\Content\Content.

Definition at line 96 of file AbstractContent.php.

◆ getModel()

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

Implements MediaWiki\Content\Content.

Definition at line 59 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 ( )
See also
Content::getNativeData
Stability: stable
to override
Deprecated
since 1.33 Use TextContent::getText() instead. For other content models, use specialized getters.
Since
1.21
Returns
mixed

Implements MediaWiki\Content\Content.

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

Definition at line 158 of file AbstractContent.php.

References wfDeprecated().

◆ getRedirectTarget()

MediaWiki\Content\AbstractContent::getRedirectTarget ( )

Subclasses that implement redirects should override this.

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

Implements MediaWiki\Content\Content.

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

Definition at line 242 of file AbstractContent.php.

◆ getSection()

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

Implements MediaWiki\Content\Content.

Reimplemented in MediaWiki\Content\WikitextContent.

Definition at line 277 of file AbstractContent.php.

◆ getSupportedFormats()

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

Implements MediaWiki\Content\Content.

Definition at line 105 of file AbstractContent.php.

◆ isEmpty()

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

Implements MediaWiki\Content\Content.

Definition at line 169 of file AbstractContent.php.

◆ isRedirect()

◆ isSupportedFormat()

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

Implements MediaWiki\Content\Content.

Definition at line 115 of file AbstractContent.php.

◆ isValid()

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

Implements MediaWiki\Content\Content.

Reimplemented in MediaWiki\Content\JsonContent.

Definition at line 179 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
See also
Content::matchMagicWord
Since
1.21
Parameters
MagicWord$word
Returns
bool

Implements MediaWiki\Content\Content.

Reimplemented in MediaWiki\Content\WikitextContent.

Definition at line 316 of file AbstractContent.php.

◆ replaceSection()

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

Implements MediaWiki\Content\Content.

Reimplemented in MediaWiki\Content\WikitextContent.

Definition at line 291 of file AbstractContent.php.

◆ serialize()

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

Implements MediaWiki\Content\Content.

Reimplemented in MediaWiki\Content\FallbackContent.

Definition at line 146 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
See also
Content::updateRedirect
Since
1.21
Parameters
Title$target
Returns
Content $this

Implements MediaWiki\Content\Content.

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

Definition at line 266 of file AbstractContent.php.

Member Data Documentation

◆ $model_id

string MediaWiki\Content\AbstractContent::$model_id
protected

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