Go to the documentation of this file.
52 if ( $text ===
null || $text ===
false ) {
53 wfWarn(
"TextContent constructed with \$text = " . var_export( $text,
true ) .
"! "
54 .
"This may indicate an error in the caller's scope.", 2 );
59 if ( !is_string( $text ) ) {
60 throw new MWException(
"TextContent expects a string in the constructor." );
72 return $this; # NOTE:
this is ok since
TextContent are immutable.
78 $truncatedtext = MediaWikiServices::getInstance()->getContentLanguage()->
79 truncateForDatabase( preg_replace(
"/[\n\r]/",
' ', $text ), max( 0, $maxlength ) );
81 return $truncatedtext;
92 return strlen( $text );
111 if ( $wgArticleCountMethod ===
'any' ) {
160 '@phan-var WikitextContent $wikitext';
163 return $wikitext->getText();
183 return str_replace( [
"\r\n",
"\r" ],
"\n", rtrim( $text ) );
202 return ( $text === $pst ) ? $this :
new static( $pst, $this->
getModel() );
220 '@phan-var self $that';
224 $lang = MediaWikiServices::getInstance()->getContentLanguage();
228 $ntext = $that->getText();
230 # Note: Use native PHP diff, external engines don't give us abstract output
231 $ota = explode(
"\n",
$lang->segmentForDiff( $otext ) );
232 $nta = explode(
"\n",
$lang->segmentForDiff( $ntext ) );
234 $diff =
new Diff( $ota, $nta );
261 if ( in_array( $this->
getModel(), $wgTextModelsToParse ) ) {
263 $output = MediaWikiServices::getInstance()->getParser()
264 ->parse( $this->
getText(), $title, $options,
true,
true, $revId );
267 if ( $generateHtml ) {
311 return htmlspecialchars( $this->
getText() );
327 public function convert( $toModel, $lossy =
'' ) {
328 $converted = parent::convert( $toModel, $lossy );
330 if ( $converted !==
false ) {
339 $converted = $toHandler->unserializeContent( $text );
__construct( $text, $model_id=CONTENT_MODEL_TEXT)
Set options of the Parser.
getTextForSearchIndex()
Returns the text represented by this Content object, as a string.
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
getWikitextForTransclusion()
Returns attempts to convert this content object to wikitext, and then returns the text string.
if(!isset( $args[0])) $lang
getHtml()
Generates an HTML version of the content, for display.
const CONTENT_MODEL_WIKITEXT
getText()
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.
getHighlightHtml()
Generates an HTML version of the content, for display.
preSaveTransform(Title $title, User $user, ParserOptions $popts)
Returns a Content object with pre-save transformations applied.
clearWrapperDivClass()
Clears the CSS class to use for the wrapping div, effectively disabling the wrapper div until addWrap...
getSize()
Returns the text's size in bytes.
Base implementation for content objects.
isCountable( $hasLinks=null)
Returns true if this content is not a redirect, and $wgArticleCountMethod is "any".
Base content handler implementation for flat text contents.
Content object implementation for representing flat text.
Base interface for content objects.
$model_id
Name of the content model this Content object represents.
Represents a title within MediaWiki.
getModel()
Returns the ID of the content model used by this Content object.
static normalizeLineEndings( $text)
Do a "\\r\\n" -> "\\n" and "\\r" -> "\\n" transformation as well as trim trailing whitespace.
$wgTextModelsToParse
Determines which types of text are parsed as wikitext.
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
$wgArticleCountMethod
Method used to determine if a page in a content namespace should be counted as a valid article.
diff(Content $that, Language $lang=null)
Diff this content object with another content object.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Internationalisation code.
fillParserOutput(Title $title, $revId, ParserOptions $options, $generateHtml, ParserOutput &$output)
Fills the provided ParserOutput object with information derived from the content.
convert( $toModel, $lossy='')
This implementation provides lossless conversion between content models based on TextContent.
getNativeData()
Returns the text represented by this Content object, as a string.
Class representing a 'diff' between two sequences of strings.