23use InvalidArgumentException;
56if ( $text ===
null || $text ===
false ) {
57wfWarn(
"TextContent constructed with \$text = " . var_export( $text,
true ) .
"! " 58 .
"This may indicate an error in the caller's scope.", 2 );
63if ( !is_string( $text ) ) {
64thrownew InvalidArgumentException(
"TextContent expects a string in the constructor." );
76return $this; # NOTE:
this is ok since
TextContent are immutable.
90 truncateForDatabase( preg_replace(
"/[\n\r]/",
' ', $text ), max( 0, $maxlength ) );
105return strlen( $text );
127if ( $articleCountMethod ===
'any' ) {
183'@phan-var WikitextContent $wikitext';
186return $wikitext->getText();
206return str_replace( [
"\r\n",
"\r" ],
"\n", rtrim( $text ) );
225'@phan-var self $that';
226// @todo could implement this in DifferenceEngine and just delegate here? 233 $ntext = $that->getText();
235 # Note: Use native PHP diff, external engines don't give us abstract output 236 $ota = explode(
"\n", $lang->segmentForDiff( $otext ) );
237 $nta = explode(
"\n", $lang->segmentForDiff( $ntext ) );
239 $diff =
newDiff( $ota, $nta );
260publicfunctionconvert( $toModel, $lossy =
'' ) {
261 $converted = parent::convert( $toModel, $lossy );
263if ( $converted !==
false ) {
270// NOTE: ignore content serialization format - it's just text anyway. 272 $converted = $toHandler->unserializeContent( $text );
280class_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 class for all Content objects.
checkModelID( $modelId)
Helper for subclasses.
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".
Exception thrown when an unregistered content model is requested.
Base class for language-specific code.
A class containing constants representing the names of configuration variables.
const ArticleCountMethod
Name constant for the ArticleCountMethod setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Class representing a 'diff' between two sequences of strings.
Content objects represent page content, e.g.
getModel()
Get the content model ID.