30use InvalidArgumentException;
61 if ( $text ===
null || $text ===
false ) {
62 wfWarn(
"TextContent constructed with \$text = " . var_export( $text,
true ) .
"! "
63 .
"This may indicate an error in the caller's scope.", 2 );
68 if ( !is_string( $text ) ) {
69 throw new InvalidArgumentException(
"TextContent expects a string in the constructor." );
81 return $this; # NOTE:
this is ok since
TextContent are immutable.
95 truncateForDatabase( preg_replace(
"/[\n\r]/",
' ', $text ), max( 0, $maxlength ) );
97 return $truncatedtext;
110 return strlen( $text );
132 if ( $articleCountMethod ===
'any' ) {
188 '@phan-var WikitextContent $wikitext';
191 return $wikitext->getText();
211 return str_replace( [
"\r\n",
"\r" ],
"\n", rtrim( $text ) );
230 '@phan-var self $that';
238 $ntext = $that->getText();
240 # Note: Use native PHP diff, external engines don't give us abstract output
241 $ota = explode(
"\n", $lang->segmentForDiff( $otext ) );
242 $nta = explode(
"\n", $lang->segmentForDiff( $ntext ) );
244 $diff =
new Diff( $ota, $nta );
265 public function convert( $toModel, $lossy =
'' ) {
266 $converted = parent::convert( $toModel, $lossy );
268 if ( $converted !==
false ) {
277 $converted = $toHandler->unserializeContent( $text );
285class_alias( TextContent::class,
'TextContent' );
const CONTENT_MODEL_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.
Exception thrown when an unregistered content model is requested.
Base implementation for content objects.
string $model_id
Name of the content model this Content object represents.
getContentHandlerFactory()
Base content handler implementation for flat text contents.
Content object implementation for representing flat text.
static normalizeLineEndings( $text)
Do a "\\r\\n" -> "\\n" and "\\r" -> "\\n" transformation as well as trim trailing whitespace.
__construct( $text, $model_id=CONTENT_MODEL_TEXT)
getWikitextForTransclusion()
Returns attempts to convert this content object to wikitext, and then returns the text string.
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.
getTextForSummary( $maxlength=250)
getText()
Returns the text represented by this Content object, as a string.
getTextForSearchIndex()
Returns the text represented by this Content object, as a string.
getSize()
Returns the text's size in bytes.
convert( $toModel, $lossy='')
This implementation provides lossless conversion between content models based on TextContent.
isCountable( $hasLinks=null)
Returns true if this content is not a redirect, and $wgArticleCountMethod is "any".
A class containing constants representing the names of configuration variables.
const ArticleCountMethod
Name constant for the ArticleCountMethod setting, for use with Config::get()
Base interface for representing page content.
getModel()
Returns the ID of the content model used by this Content object.