MediaWiki  master
TextContent Class Reference

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

Inheritance diagram for TextContent:
Collaboration diagram for 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. More...
 
 copy ()
 
 diff (Content $that, Language $lang=null)
 Diff this content object with another content object. More...
 
 getNativeData ()
 Returns the text represented by this Content object, as a string. More...
 
 getSize ()
 Returns the text's size in bytes. More...
 
 getText ()
 Returns the text represented by this Content object, as a string. More...
 
 getTextForSearchIndex ()
 Returns the text represented by this Content object, as a string. More...
 
 getTextForSummary ( $maxlength=250)
 
 getWikitextForTransclusion ()
 Returns attempts to convert this content object to wikitext, and then returns the text string. More...
 
 isCountable ( $hasLinks=null)
 Returns true if this content is not a redirect, and $wgArticleCountMethod is "any". More...
 
- Public Member Functions inherited from AbstractContent
 __construct ( $modelId=null)
 
 addSectionHeader ( $header)
 
 equals (Content $that=null)
 Decides whether two Content objects are equal. More...
 
 getContentHandler ()
 
 getDefaultFormat ()
 
 getModel ()
 
 getParserOutput (Title $title, $revId=null, ParserOptions $options=null, $generateHtml=true)
 Returns a ParserOutput object containing information derived from this content. More...
 
 getRedirectChain ()
 
 getRedirectTarget ()
 Subclasses that implement redirects should override this. More...
 
 getSection ( $sectionId)
 
 getSupportedFormats ()
 
 getUltimateRedirectTarget ()
 
 isEmpty ()
 
 isRedirect ()
 
 isSupportedFormat ( $format)
 
 isValid ()
 Subclasses may override this to implement (light weight) validation. More...
 
 matchMagicWord (MagicWord $word)
 This default implementation always returns false. More...
 
 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. More...
 

Static Public Member Functions

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

Protected Attributes

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

Additional Inherited Members

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

Detailed Description

Content object implementation for representing flat text.

TextContent instances are immutable

@newable

Stability: stable
to extend

Definition at line 39 of file TextContent.php.

Constructor & Destructor Documentation

◆ __construct()

TextContent::__construct (   $text,
  $model_id = CONTENT_MODEL_TEXT 
)
Stability: stable
to call
Parameters
string$text
string$model_id
Exceptions
MWException

Reimplemented in JsonContent, JavaScriptContent, and CssContent.

Definition at line 52 of file TextContent.php.

References AbstractContent\$model_id, and wfWarn().

Member Function Documentation

◆ convert()

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

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

@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|bool A content object with the content model $toModel, or false if that conversion is not supported.
Exceptions
MWUnknownContentModelException
See also
Content::convert()

Reimplemented from AbstractContent.

Definition at line 258 of file TextContent.php.

References AbstractContent\getContentHandlerFactory(), and getText().

Referenced by getWikitextForTransclusion().

◆ copy()

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

Implements Content.

Definition at line 74 of file TextContent.php.

Referenced by WikitextContent\replaceSection().

◆ diff()

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 220 of file TextContent.php.

References $lang, AbstractContent\checkModelID(), Content\getModel(), and getText().

◆ getNativeData()

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.

Implements Content.

Definition at line 139 of file TextContent.php.

References getText().

◆ getSize()

TextContent::getSize ( )

Returns the text's size in bytes.

Stability: stable
to override
Returns
int

Implements Content.

Definition at line 101 of file TextContent.php.

References getText().

◆ getText()

TextContent::getText ( )

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

Since
1.33
Note
This method should not be overwritten by subclasses. If a subclass find itself in need to override this method, it should probably not be based on TextContent, but should rather extend AbstractContent instead.
Returns
string The raw text.

Definition at line 153 of file TextContent.php.

References $mText.

Referenced by WikitextContent\addSectionHeader(), convert(), diff(), JsonContent\getData(), MediaWiki\Rest\Handler\UpdateHandler\getDiff(), getNativeData(), CssContent\getRedirectTarget(), JavaScriptContent\getRedirectTarget(), WikitextContent\getRedirectTargetAndText(), WikitextContent\getSection(), getSize(), getTextForSearchIndex(), getTextForSummary(), WikitextContent\matchMagicWord(), and WikitextContent\replaceSection().

◆ getTextForSearchIndex()

TextContent::getTextForSearchIndex ( )

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

Stability: stable
to override
Returns
string The raw text.

Implements Content.

Definition at line 164 of file TextContent.php.

References getText().

◆ getTextForSummary()

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

Implements Content.

Reimplemented in WikitextContent.

Definition at line 85 of file TextContent.php.

References getText().

◆ getWikitextForTransclusion()

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|bool The raw text, or false if the conversion failed.

Implements Content.

Definition at line 178 of file TextContent.php.

References CONTENT_MODEL_WIKITEXT, and convert().

◆ isCountable()

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

Definition at line 118 of file TextContent.php.

References $wgArticleCountMethod, and AbstractContent\isRedirect().

◆ normalizeLineEndings()

static 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 203 of file TextContent.php.

Referenced by Parser\preSaveTransform(), JsonContentHandler\preSaveTransform(), and TextContentHandler\preSaveTransform().

Member Data Documentation

◆ $mText

string TextContent::$mText
protected

Definition at line 44 of file TextContent.php.

Referenced by getText().


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