56 if ( $text ===
null || $text ===
false ) {
57 wfWarn(
"TextContent constructed with \$text = " . var_export( $text,
true ) .
"! "
58 .
"This may indicate an error in the caller's scope.", 2 );
63 if ( !is_string( $text ) ) {
64 throw new InvalidArgumentException(
"TextContent expects a string in the constructor." );
76 return $this; # NOTE:
this is ok since
TextContent are immutable.
89 $truncatedtext = MediaWikiServices::getInstance()->getContentLanguage()->
90 truncateForDatabase( preg_replace(
"/[\n\r]/",
' ', $text ), max( 0, $maxlength ) );
92 return $truncatedtext;
105 return strlen( $text );
120 $articleCountMethod = MediaWikiServices::getInstance()->getMainConfig()->get(
121 MainConfigNames::ArticleCountMethod );
127 if ( $articleCountMethod ===
'any' ) {
183 '@phan-var WikitextContent $wikitext';
186 return $wikitext->getText();
206 return str_replace( [
"\r\n",
"\r" ],
"\n", rtrim( $text ) );
225 '@phan-var self $that';
229 $lang = MediaWikiServices::getInstance()->getContentLanguage();
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 =
new Diff( $ota, $nta );
260 public function convert( $toModel, $lossy =
'' ) {
261 $converted = parent::convert( $toModel, $lossy );
263 if ( $converted !==
false ) {
272 $converted = $toHandler->unserializeContent( $text );
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.
A class containing constants representing the names of configuration variables.
Base content handler implementation for flat text contents.
Content object implementation for representing flat text.
isCountable( $hasLinks=null)
Returns true if this content is not a redirect, and $wgArticleCountMethod is "any".
getSize()
Returns the text's size in bytes.
__construct( $text, $model_id=CONTENT_MODEL_TEXT)
getWikitextForTransclusion()
Returns attempts to convert this content object to wikitext, and then returns the text string.
convert( $toModel, $lossy='')
This implementation provides lossless conversion between content models based on TextContent.
getText()
Returns the text represented by this Content object, as a string.
getNativeData()
Returns the text represented by this Content object, as a string.
diff(Content $that, Language $lang=null)
Diff this content object with another content object.
getTextForSearchIndex()
Returns the text represented by this Content object, as a string.
getTextForSummary( $maxlength=250)
static normalizeLineEndings( $text)
Do a "\\r\\n" -> "\\n" and "\\r" -> "\\n" transformation as well as trim trailing whitespace.
Base interface for representing page content.
getModel()
Returns the ID of the content model used by this Content object.