MediaWiki master
MediaWiki\Content\TextContent Class Reference

Content object implementation for representing flat text. More...

Inherits MediaWiki\Content\AbstractContent.

Inherited by MediaWiki\Content\CssContent, MediaWiki\Content\JavaScriptContent, MediaWiki\Content\JsonContent, and MediaWiki\Content\WikitextContent.

Collaboration diagram for MediaWiki\Content\TextContent:

Public Member Functions

 __construct ( $text, $model_id=CONTENT_MODEL_TEXT)
 
 convert ( $toModel, $lossy='')
 This implementation provides lossless conversion between content models based on TextContent.
 
 copy ()
 
 diff (Content $that, Language $lang=null)
 Diff this content object with another content object.
 
 getNativeData ()
 Returns the text represented by this Content object, as a string.
 
 getSize ()
 Returns the text's size in bytes.
 
 getText ()
 Returns the text represented by this Content object, as a string.
 
 getTextForSearchIndex ()
 Returns the text represented by this Content object, as a string.
 
 getTextForSummary ( $maxlength=250)
 
 getWikitextForTransclusion ()
 Returns attempts to convert this content object to wikitext, and then returns the text string.
 
 isCountable ( $hasLinks=null)
 Returns true if this content is not a redirect, and $wgArticleCountMethod is "any".
 
- Public Member Functions inherited from MediaWiki\Content\AbstractContent
 __construct ( $modelId=null)
 
 addSectionHeader ( $header)
 
 equals (Content $that=null)
 Decides whether two Content objects are equal.
 
 getContentHandler ()
 
 getDefaultFormat ()
 
 getModel ()
 
 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.
 

Static Public Member Functions

static normalizeLineEndings ( $text)
 Do a "\\r\\n" -> "\\n" and "\\r" -> "\\n" transformation as well as trim trailing whitespace.
 

Protected Attributes

string $mText
 
- Protected Attributes inherited from MediaWiki\Content\AbstractContent
string $model_id
 Name of the content model this Content object represents.
 

Additional Inherited Members

- Protected Member Functions inherited from MediaWiki\Content\AbstractContent
 checkFormat ( $format)
 
 checkModelID ( $modelId)
 
 equalsInternal (Content $that)
 Checks whether $that is logically equal to this Content object.
 
 getContentHandlerFactory ()
 

Detailed Description

Content object implementation for representing flat text.

TextContent instances are immutable

Stability: newable
Stability: stable
to extend

Definition at line 46 of file TextContent.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Content\TextContent::__construct ( $text,
$model_id = CONTENT_MODEL_TEXT )
Stability: stable
to call
Parameters
string$text
string$model_id

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

Definition at line 58 of file TextContent.php.

References MediaWiki\Content\AbstractContent\$model_id, and wfWarn().

Member Function Documentation

◆ convert()

MediaWiki\Content\TextContent::convert ( $toModel,
$lossy = '' )

This implementation provides lossless conversion between content models based on TextContent.

Stability: stable
to override
Parameters
string$toModelThe desired content model, use the CONTENT_MODEL_XXX flags.
string$lossyFlag, set to "lossy" to allow lossy conversion. If lossy conversion is not allowed, full round-trip conversion is expected to work without losing information.
Returns
Content|false A content object with the content model $toModel, or false if that conversion is not supported.
Exceptions
MWUnknownContentModelException
See also
Content::convert()

Reimplemented from MediaWiki\Content\AbstractContent.

Definition at line 265 of file TextContent.php.

References MediaWiki\Content\AbstractContent\getContentHandlerFactory(), and MediaWiki\Content\TextContent\getText().

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

◆ copy()

MediaWiki\Content\TextContent::copy ( )
Note
Mutable subclasses MUST override this to return a copy!
Returns
Content $this

Implements MediaWiki\Content\Content.

Definition at line 80 of file TextContent.php.

Referenced by MediaWiki\Content\WikitextContent\replaceSection().

◆ diff()

MediaWiki\Content\TextContent::diff ( Content $that,
Language $lang = null )

Diff this content object with another content object.

Stability: stable
to override
Since
1.21
Parameters
Content$thatThe other content object to compare this content object to.
Language | null$langThe language object to use for text segmentation. If not given, the content language is used.
Returns
Diff A diff representing the changes that would have to be made to this content object to make it equal to $that.

Definition at line 227 of file TextContent.php.

References MediaWiki\Content\AbstractContent\checkModelID(), MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Content\Content\getModel(), and MediaWiki\Content\TextContent\getText().

◆ getNativeData()

MediaWiki\Content\TextContent::getNativeData ( )

Returns the text represented by this Content object, as a string.

Deprecated
since 1.33 use getText() instead.
Returns
string The raw text. Subclasses may guarantee a specific syntax here.

Reimplemented from MediaWiki\Content\AbstractContent.

Definition at line 146 of file TextContent.php.

References MediaWiki\Content\TextContent\getText().

◆ getSize()

MediaWiki\Content\TextContent::getSize ( )

Returns the text's size in bytes.

Stability: stable
to override
Returns
int

Implements MediaWiki\Content\Content.

Definition at line 107 of file TextContent.php.

References MediaWiki\Content\TextContent\getText().

◆ getText()

MediaWiki\Content\TextContent::getText ( )

◆ getTextForSearchIndex()

MediaWiki\Content\TextContent::getTextForSearchIndex ( )

Returns the text represented by this Content object, as a string.

Stability: stable
to override
Returns
string The raw text.

Implements MediaWiki\Content\Content.

Definition at line 171 of file TextContent.php.

References MediaWiki\Content\TextContent\getText().

◆ getTextForSummary()

MediaWiki\Content\TextContent::getTextForSummary ( $maxlength = 250)
Stability: stable
to override
Parameters
int$maxlength
Returns
string

Implements MediaWiki\Content\Content.

Reimplemented in MediaWiki\Content\WikitextContent.

Definition at line 91 of file TextContent.php.

References MediaWiki\MediaWikiServices\getInstance(), and MediaWiki\Content\TextContent\getText().

◆ getWikitextForTransclusion()

MediaWiki\Content\TextContent::getWikitextForTransclusion ( )

Returns attempts to convert this content object to wikitext, and then returns the text string.

The conversion may be lossy.

Stability: stable
to override
Note
this allows any text-based content to be transcluded as if it was wikitext.
Returns
string|false The raw text, or false if the conversion failed.

Implements MediaWiki\Content\Content.

Definition at line 185 of file TextContent.php.

References CONTENT_MODEL_WIKITEXT, and MediaWiki\Content\TextContent\convert().

◆ isCountable()

MediaWiki\Content\TextContent::isCountable ( $hasLinks = null)

Returns true if this content is not a redirect, and $wgArticleCountMethod is "any".

Stability: stable
to override
Parameters
bool | null$hasLinksIf it is known whether this content contains links, provide this information here, to avoid redundant parsing to find out.
Returns
bool

Implements MediaWiki\Content\Content.

Definition at line 124 of file TextContent.php.

References MediaWiki\MainConfigNames\ArticleCountMethod, MediaWiki\MediaWikiServices\getInstance(), and MediaWiki\Content\AbstractContent\isRedirect().

◆ normalizeLineEndings()

static MediaWiki\Content\TextContent::normalizeLineEndings ( $text)
static

Do a "\\r\\n" -> "\\n" and "\\r" -> "\\n" transformation as well as trim trailing whitespace.

This was formerly part of Parser::preSaveTransform, but for non-wikitext content models they probably still want to normalize line endings without all of the other PST changes.

Since
1.28
Parameters
string$text
Returns
string

Definition at line 210 of file TextContent.php.

Member Data Documentation

◆ $mText

string MediaWiki\Content\TextContent::$mText
protected

Definition at line 51 of file TextContent.php.

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


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