30use InvalidArgumentException;
49 private $preSaveTransformFlags = [];
70 ->getSection( $text, $sectionId,
false );
72 if ( $sect ===
false ) {
75 return new static( $sect );
93 if ( $sectionModelId != $myModelId ) {
94 throw new InvalidArgumentException(
"Incompatible content model for section: " .
95 "document uses $myModelId but " .
96 "section uses $sectionModelId." );
99 '@phan-var self $with';
102 $text = $with->getText();
104 if ( strval( $sectionId ) ===
'' ) {
105 return $with; # XXX:
copy first?
108 if ( $sectionId ===
'new' ) {
109 # Inserting a new section
110 $subject = strval( $sectionTitle ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
111 ->plaintextParams( $sectionTitle )->inContentLanguage()->text() .
"\n\n" :
'';
113 if ( $hookRunner->onPlaceNewSection( $this, $oldtext, $subject, $text ) ) {
114 $text = strlen( trim( $oldtext ) ) > 0
115 ?
"{$oldtext}\n\n{$subject}{$text}"
116 :
"{$subject}{$text}";
119 # Replacing an existing section; roll out the big guns
124 $newContent =
new static( $text );
138 $text = strval(
$header ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
139 ->plaintextParams(
$header )->inContentLanguage()->text() .
"\n\n" :
'';
142 return new static( $text );
157 [ $target, $content ] = $handler->extractRedirectTargetAndText( $this );
159 return [ Title::castFromLinkTarget( $target ), $content->getText() ];
174 [ $target, ] = $handler->extractRedirectTargetAndText( $this );
176 return Title::castFromLinkTarget( $target );
197 # Remember that redirect pages can have categories, templates, etc.,
198 # so the regex has to be fairly general
199 $newText = preg_replace(
'/ \[ \[ [^\]]* \] \] /x',
201 $this->getText(), 1 );
203 return new static( $newText );
225 if ( $articleCountMethod ===
'link' ) {
226 if ( $hasLinks ===
null ) { # not known, find out
229 $context = RequestContext::getMain();
230 $title = $context->getTitle();
234 $po = $contentRenderer->getParserOutput( $this, $title,
null,
null,
false );
235 $links = $po->getLinks();
236 $hasLinks = $links !== [];
251 $truncatedtext = parent::getTextForSummary( $maxlength );
253 # clean up unfinished links
254 # XXX: make this optional? wasn't there in autosummary, but required for
256 $truncatedtext = preg_replace(
'/\[\[([^\]]*)\]?$/',
'$1', $truncatedtext );
258 return $truncatedtext;
282 $this->preSaveTransformFlags = $flags;
292 return $this->preSaveTransformFlags;
297 '@phan-var WikitextContentHandler $handler';
304class_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()
Base interface for representing page content.
getModel()
Returns the ID of the content model used by this Content object.
replaceSection( $sectionId, Content $with, $sectionTitle='')
Replaces a section of the content and returns a Content object with the section replaced.