23use InvalidArgumentException;
44 private $preSaveTransformFlags = [];
65 ->getSection( $text, $sectionId,
false );
67 if ( $sect ===
false ) {
70 return new static( $sect );
88 if ( $sectionModelId != $myModelId ) {
89 throw new InvalidArgumentException(
"Incompatible content model for section: " .
90 "document uses $myModelId but " .
91 "section uses $sectionModelId." );
94 '@phan-var self $with';
97 $text = $with->getText();
99 if ( strval( $sectionId ) ===
'' ) {
100 return $with; # XXX:
copy first?
103 if ( $sectionId ===
'new' ) {
104 # Inserting a new section
105 $subject = strval( $sectionTitle ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
106 ->plaintextParams( $sectionTitle )->inContentLanguage()->text() .
"\n\n" :
'';
108 if ( $hookRunner->onPlaceNewSection( $this, $oldtext, $subject, $text ) ) {
109 $text = trim( $oldtext ) !==
''
110 ?
"{$oldtext}\n\n{$subject}{$text}"
111 :
"{$subject}{$text}";
114 # Replacing an existing section; roll out the big guns
119 $newContent =
new static( $text );
133 $text = strval(
$header ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
134 ->plaintextParams(
$header )->inContentLanguage()->text() .
"\n\n" :
'';
137 return new static( $text );
152 [ $target, $content ] = $handler->extractRedirectTargetAndText( $this );
154 return [ Title::castFromLinkTarget( $target ), $content->getText() ];
169 [ $target, ] = $handler->extractRedirectTargetAndText( $this );
171 return Title::castFromLinkTarget( $target );
192 # Remember that redirect pages can have categories, templates, etc.,
193 # so the regex has to be fairly general
194 $newText = preg_replace(
'/ \[ \[ [^\]]* \] \] /x',
196 $this->getText(), 1 );
198 return new static( $newText );
220 if ( $articleCountMethod ===
'link' ) {
221 if ( $hasLinks ===
null ) { # not known, find out
224 $context = RequestContext::getMain();
225 $title = $context->getTitle();
229 $po = $contentRenderer->getParserOutput( $this, $title,
null,
null,
false );
230 $hasLinks = $po->hasLinks();
245 $truncatedtext = parent::getTextForSummary( $maxlength );
247 # clean up unfinished links
248 # XXX: make this optional? wasn't there in autosummary, but required for
250 $truncatedtext = preg_replace(
'/\[\[([^\]]*)\]?$/',
'$1', $truncatedtext );
252 return $truncatedtext;
276 $this->preSaveTransformFlags = $flags;
286 return $this->preSaveTransformFlags;
291 '@phan-var WikitextContentHandler $handler';
298class_alias( WikitextContent::class,
'WikitextContent' );
const CONTENT_MODEL_WIKITEXT
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Content object implementation for representing flat text.
getText()
Returns the text represented by this Content object, as a string.
Content handler for wiki text pages.
Content object for wiki text pages.
setPreSaveTransformFlags(array $flags)
Records flags set by preSaveTransform.
updateRedirect(Title $target)
This implementation replaces the first link on the page with the given new target if this Content obj...
addSectionHeader( $header)
Returns a new WikitextContent object with the given section heading prepended.
replaceSection( $sectionId, Content $with, $sectionTitle='')
isCountable( $hasLinks=null, ?Title $title=null)
Returns true if this content is not a redirect, and this content's text is countable according to the...
getTextForSummary( $maxlength=250)
matchMagicWord(MagicWord $word)
This implementation calls $word->match() on the this TextContent object's text.
getPreSaveTransformFlags()
Records flags set by preSaveTransform.
getRedirectTarget()
Implement redirect extraction for wikitext.
getRedirectTargetAndText()
Extract the redirect target and the remaining text on the page.
Group all the pieces relevant to the context of a request into one instance.
A class containing constants representing the names of configuration variables.
const ArticleCountMethod
Name constant for the ArticleCountMethod setting, for use with Config::get()
Content objects represent page content, e.g.
getModel()
Get the content model ID.
replaceSection( $sectionId, Content $with, $sectionTitle='')
Create a derived Content with the specified section added or replaced.