9use InvalidArgumentException;
30 private $preSaveTransformFlags = [];
51 ->getSection( $text, $sectionId,
false );
53 if ( $sect ===
false ) {
56 return new static( $sect );
74 if ( $sectionModelId != $myModelId ) {
75 throw new InvalidArgumentException(
"Incompatible content model for section: " .
76 "document uses $myModelId but " .
77 "section uses $sectionModelId." );
80 '@phan-var self $with';
83 $text = $with->getText();
85 if ( strval( $sectionId ) ===
'' ) {
86 return $with; # XXX:
copy first?
89 if ( $sectionId ===
'new' ) {
90 # Inserting a new section
91 $subject = strval( $sectionTitle ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
92 ->plaintextParams( $sectionTitle )->inContentLanguage()->text() .
"\n\n" :
'';
94 if ( $hookRunner->onPlaceNewSection( $this, $oldtext, $subject, $text ) ) {
95 $text = trim( $oldtext ) !==
''
96 ?
"{$oldtext}\n\n{$subject}{$text}"
97 :
"{$subject}{$text}";
100 # Replacing an existing section; roll out the big guns
105 $newContent =
new static( $text );
119 $text = strval( $header ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
120 ->plaintextParams( $header )->inContentLanguage()->text() .
"\n\n" :
'';
123 return new static( $text );
138 [ $target, $content ] = $handler->extractRedirectTargetAndText( $this );
140 return [ Title::castFromLinkTarget( $target ), $content->getText() ];
155 [ $target, ] = $handler->extractRedirectTargetAndText( $this );
157 return Title::castFromLinkTarget( $target );
178 # Remember that redirect pages can have categories, templates, etc.,
179 # so the regex has to be fairly general
180 $newText = preg_replace(
'/ \[ \[ [^\]]* \] \] /x',
182 $this->getText(), 1 );
184 return new static( $newText );
206 if ( $articleCountMethod ===
'link' ) {
207 if ( $hasLinks ===
null ) { # not known, find out
210 $context = RequestContext::getMain();
211 $title = $context->getTitle();
215 $po = $contentRenderer->getParserOutput( $this, $title,
null,
null,
false );
216 $hasLinks = $po->hasLinks();
231 $truncatedtext = parent::getTextForSummary( $maxlength );
233 # clean up unfinished links
234 # XXX: make this optional? wasn't there in autosummary, but required for
236 $truncatedtext = preg_replace(
'/\[\[([^\]]*)\]?$/',
'$1', $truncatedtext );
238 return $truncatedtext;
262 $this->preSaveTransformFlags = $flags;
272 return $this->preSaveTransformFlags;
277 '@phan-var WikitextContentHandler $handler';
284class_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.