32use InvalidArgumentException;
64 if ( $text ===
null || $text ===
false ) {
65 wfWarn(
"TextContent constructed with \$text = " . var_export( $text,
true ) .
"! "
66 .
"This may indicate an error in the caller's scope.", 2 );
71 if ( !is_string( $text ) ) {
72 throw new InvalidArgumentException(
"TextContent expects a string in the constructor." );
84 return $this; # NOTE:
this is ok since
TextContent are immutable.
98 truncateForDatabase( preg_replace(
"/[\n\r]/",
' ', $text ), max( 0, $maxlength ) );
100 return $truncatedtext;
113 return strlen( $text );
135 if ( $articleCountMethod ===
'any' ) {
191 '@phan-var WikitextContent $wikitext';
194 return $wikitext->getText();
214 return str_replace( [
"\r\n",
"\r" ],
"\n", rtrim( $text ) );
233 '@phan-var self $that';
241 $ntext = $that->getText();
243 # Note: Use native PHP diff, external engines don't give us abstract output
244 $ota = explode(
"\n", $lang->segmentForDiff( $otext ) );
245 $nta = explode(
"\n", $lang->segmentForDiff( $ntext ) );
247 $diff =
new Diff( $ota, $nta );
268 public function convert( $toModel, $lossy =
'' ) {
269 $converted = parent::convert( $toModel, $lossy );
271 if ( $converted !==
false ) {
280 $converted = $toHandler->unserializeContent( $text );
288class_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.
Base implementation for content objects.
getContentHandlerFactory()
string $model_id
Name of the content model this Content object represents.
Base class for language-specific code.
Exception thrown when an unregistered content model is requested.
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()
Content object for wiki text pages.
Base interface for representing page content.
getModel()
Returns the ID of the content model used by this Content object.