MediaWiki REL1_34
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.
 
 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)
 Returns a textual representation of the content suitable for use in edit summaries and log messages.
 
 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".
 
 preSaveTransform (Title $title, User $user, ParserOptions $popts)
 Returns a Content object with pre-save transformations applied.
 
- Public Member Functions inherited from AbstractContent
 __construct ( $modelId=null)
 
 addSectionHeader ( $header)
 
 equals (Content $that=null)
 Decides whether two Content objects are equal.
 
 getContentHandler ()
 
 getDefaultFormat ()
 
 getDeletionUpdates (WikiPage $page, ParserOutput $parserOutput=null)
 
 getModel ()
 
 getParserOutput (Title $title, $revId=null, ParserOptions $options=null, $generateHtml=true)
 Returns a ParserOutput object containing information derived from this content.
 
 getRedirectChain ()
 
 getRedirectTarget ()
 Subclasses that implement redirects should override this.
 
 getSecondaryDataUpdates (Title $title, Content $old=null, $recursive=true, ParserOutput $parserOutput=null)
 Returns a list of DataUpdate objects for recording information about this Content in some secondary data store.
 
 getSection ( $sectionId)
 
 getSupportedFormats ()
 
 getUltimateRedirectTarget ()
 
 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)
 
 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 Member Functions

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

Protected Attributes

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

Detailed Description

Content object implementation for representing flat text.

TextContent instances are immutable

Definition at line 37 of file TextContent.php.

Constructor & Destructor Documentation

◆ __construct()

TextContent::__construct ( $text,
$model_id = CONTENT_MODEL_TEXT )
Parameters
string$text
string$model_id
Exceptions
MWException

Reimplemented in CssContent, JavaScriptContent, and JsonContent.

Definition at line 49 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.

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.
See also
Content::convert()

Reimplemented from AbstractContent.

Definition at line 327 of file TextContent.php.

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

Referenced by WikitextContent\replaceSection().

◆ diff()

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

Diff this content object with another content object.

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

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

◆ fillParserOutput()

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

Fills the provided ParserOutput object with information derived from the content.

Unless $generateHtml was false, this includes an HTML representation of the content provided by getHtml().

For content models listed in $wgTextModelsToParse, this method will call the MediaWiki wikitext parser on the text to extract any (wikitext) links, magic words, etc.

Subclasses may override this to provide custom content processing. For custom HTML generation alone, it is sufficient to override getHtml().

Parameters
Title$titleContext title for parsing
int$revIdRevision ID (for {{REVISIONID}})
ParserOptions$options
bool$generateHtmlWhether or not to generate HTML
ParserOutput&$outputThe output object to fill (reference).

Reimplemented from AbstractContent.

Reimplemented in GadgetDefinitionContent, ScribuntoContent, JsonContent, and WikitextContent.

Definition at line 256 of file TextContent.php.

References $wgTextModelsToParse, ParserOutput\clearWrapperDivClass(), getHtml(), AbstractContent\getModel(), getText(), and ParserOutput\setText().

◆ getHighlightHtml()

TextContent::getHighlightHtml ( )
protected

Generates an HTML version of the content, for display.

This default implementation returns an HTML-escaped version of the raw text content.

Note
The functionality of this method should really be implemented in getHtml(), and subclasses should override getHtml() if needed. getHighlightHtml() is kept around for backward compatibility with extensions that already override it.
Deprecated
since 1.24. Use getHtml() instead. In particular, subclasses overriding getHighlightHtml() should override getHtml() instead.
Returns
string An HTML representation of the content

Definition at line 310 of file TextContent.php.

References getText().

Referenced by getHtml().

◆ getHtml()

TextContent::getHtml ( )
protected

Generates an HTML version of the content, for display.

Used by fillParserOutput() to provide HTML for the ParserOutput object.

Subclasses may override this to provide a custom HTML rendering. If further information is to be derived from the content (such as categories), the fillParserOutput() method can be overridden instead.

For backwards-compatibility, this default implementation just calls getHighlightHtml().

Returns
string An HTML representation of the content

Reimplemented in CssContent, JavaScriptContent, and WikitextContent.

Definition at line 290 of file TextContent.php.

References getHighlightHtml().

Referenced by fillParserOutput().

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

References getText().

◆ getSize()

TextContent::getSize ( )

Returns the text's size in bytes.

Returns
int

Implements Content.

Definition at line 89 of file TextContent.php.

References getText().

◆ getText()

◆ getTextForSearchIndex()

TextContent::getTextForSearchIndex ( )

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

Returns
string The raw text.

Implements Content.

Definition at line 145 of file TextContent.php.

References getText().

◆ getTextForSummary()

TextContent::getTextForSummary ( $maxLength = 250)

Returns a textual representation of the content suitable for use in edit summaries and log messages.

Since
1.21
Parameters
int$maxLengthMaximum length of the summary text.
Returns
string The summary text.

Implements Content.

Reimplemented in WikitextContent.

Definition at line 75 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.

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 157 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".

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

Referenced by Parser\preSaveTransform(), JsonContent\preSaveTransform(), and preSaveTransform().

◆ preSaveTransform()

TextContent::preSaveTransform ( Title $title,
User $user,
ParserOptions $popts )

Returns a Content object with pre-save transformations applied.

At a minimum, subclasses should make sure to call TextContent::normalizeLineEndings() either directly or part of Parser::preSaveTransform().

Parameters
Title$title
User$user
ParserOptions$popts
Returns
Content

Reimplemented from AbstractContent.

Reimplemented in CssContent, JavaScriptContent, JsonContent, and WikitextContent.

Definition at line 198 of file TextContent.php.

References AbstractContent\getModel(), getText(), and normalizeLineEndings().

Member Data Documentation

◆ $mText

string TextContent::$mText
protected

Definition at line 42 of file TextContent.php.

Referenced by getText().


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