MediaWiki  REL1_22
TextContent Class Reference

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

Inheritance diagram for TextContent:
Collaboration diagram for TextContent:

List of all members.

Public Member Functions

 __construct ($text, $model_id=CONTENT_MODEL_TEXT)
 convert ($toModel, $lossy= '')
 copy ()
 Return a copy of this Content object.
 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.
 getParserOutput (Title $title, $revId=null, ParserOptions $options=null, $generateHtml=true)
 Returns a generic ParserOutput object, wrapping the HTML returned by getHtml().
 getSize ()
 returns the text's size in bytes.
 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.

Protected Member Functions

 getHighlightHtml ()
 Generates a syntax-highlighted version of the content, as HTML.
 getHtml ()
 Generates an HTML version of the content, for display.

Detailed Description

Content object implementation for representing flat text.

TextContent instances are immutable

Definition at line 35 of file TextContent.php.


Constructor & Destructor Documentation

TextContent::__construct ( text,
model_id = CONTENT_MODEL_TEXT 
)

Definition at line 37 of file TextContent.php.

References AbstractContent\$model_id, and wfWarn().


Member Function Documentation

TextContent::convert ( toModel,
lossy = '' 
)
See also:
Content::convert()

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.

Reimplemented from AbstractContent.

Definition at line 269 of file TextContent.php.

References ContentHandler\getForModelID(), and getNativeData().

Referenced by getWikitextForTransclusion().

Return a copy of this Content object.

The following must be true for the object returned:

if $copy = $original->copy()

  • get_class($original) === get_class($copy)
  • $original->getModel() === $copy->getModel()
  • $original->equals( $copy )

If and only if the Content object is immutable, the copy() method can and should return $this. That is, $copy === $original may be true, but only for immutable content objects.

Since:
1.21
Returns:
Content. A copy of this object

Implements Content.

Reimplemented in RevisionTestModifyableContent.

Definition at line 54 of file TextContent.php.

References are, and is.

Referenced by WikitextContent\replaceSection().

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

Diff this content object with another content object.

Since:
1.21diff
Parameters:
$thatContent: The other content object to compare this content object to.
$langLanguage: The language object to use for text segmentation. If not given, $wgContentLang is used.
Returns:
DiffResult: A diff representing the changes that would have to be made to this content object to make it equal to $that.

Definition at line 169 of file TextContent.php.

References $wgContLang, AbstractContent\checkModelID(), Content\getModel(), getNativeData(), and global.

Generates a syntax-highlighted version of the content, as HTML.

Used by the default implementation of getHtml().

Returns:
string an HTML representation of the content's markup

Definition at line 251 of file TextContent.php.

References getNativeData().

Referenced by CssContent\getHtml(), JavaScriptContent\getHtml(), and getHtml().

TextContent::getHtml ( ) [protected]

Generates an HTML version of the content, for display.

Used by getParserOutput() to construct a ParserOutput object.

This default implementation just calls getHighlightHtml(). Content models that have another mapping to HTML (as is the case for markup languages like wikitext) should override this method to generate the appropriate HTML.

Returns:
string An HTML representation of the content

Reimplemented in WikitextContent, JavaScriptContent, and CssContent.

Definition at line 241 of file TextContent.php.

References getHighlightHtml().

Referenced by getParserOutput().

TextContent::getParserOutput ( Title title,
revId = null,
ParserOptions options = null,
generateHtml = true 
)

Returns a generic ParserOutput object, wrapping the HTML returned by getHtml().

Parameters:
$titleTitle Context title for parsing
int | null$revIdRevision ID (for {{REVISIONID}})
$optionsParserOptions|null Parser options
bool$generateHtmlWhether or not to generate HTML
Returns:
ParserOutput representing the HTML form of the text

Implements Content.

Reimplemented in WikitextContent.

Definition at line 202 of file TextContent.php.

References $html, $options, $wgParser, AbstractContent\getContentHandler(), getHtml(), AbstractContent\getModel(), getNativeData(), and global.

returns the text's size in bytes.

Returns:
int The size

Implements Content.

Definition at line 75 of file TextContent.php.

References getNativeData().

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

Returns:
string: the raw text

Implements Content.

Definition at line 118 of file TextContent.php.

References getNativeData().

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

References $wgContLang, getNativeData(), and global.

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|false: the raw text, or null if the conversion failed

Implements Content.

Definition at line 130 of file TextContent.php.

References convert().

TextContent::isCountable ( hasLinks = null)

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

Parameters:
bool$hasLinksif it is known whether this content contains links, provide this information here, to avoid redundant parsing to find out.
Returns:
bool True if the content is countable

Implements Content.

Definition at line 89 of file TextContent.php.

References global, and AbstractContent\isRedirect().

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

Returns a Content object with pre-save transformations applied.

This implementation just trims trailing whitespace.

Parameters:
$titleTitle
$userUser
$poptsParserOptions
Returns:
Content

Reimplemented from AbstractContent.

Reimplemented in WikitextContent, CssContent, and JavaScriptContent.

Definition at line 149 of file TextContent.php.

References getNativeData().


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