46 private $preSaveTransformFlags = [];
66 $sect = MediaWikiServices::getInstance()->getParserFactory()->getInstance()
67 ->getSection( $text, $sectionId,
false );
69 if ( $sect ===
false ) {
72 return new static( $sect );
89 if ( $sectionModelId != $myModelId ) {
90 throw new InvalidArgumentException(
"Incompatible content model for section: " .
91 "document uses $myModelId but " .
92 "section uses $sectionModelId." );
95 '@phan-var self $with';
98 $text = $with->getText();
100 if ( strval( $sectionId ) ===
'' ) {
101 return $with; # XXX:
copy first?
104 if ( $sectionId ===
'new' ) {
105 # Inserting a new section
106 $subject = strval( $sectionTitle ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
107 ->plaintextParams( $sectionTitle )->inContentLanguage()->text() .
"\n\n" :
'';
108 $hookRunner = (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) );
109 if ( $hookRunner->onPlaceNewSection( $this, $oldtext, $subject, $text ) ) {
110 $text = strlen( trim( $oldtext ) ) > 0
111 ?
"{$oldtext}\n\n{$subject}{$text}"
112 :
"{$subject}{$text}";
115 # Replacing an existing section; roll out the big guns
116 $text = MediaWikiServices::getInstance()->getParserFactory()->getInstance()
117 ->replaceSection( $oldtext, $sectionId, $text );
120 $newContent =
new static( $text );
134 $text = strval(
$header ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
135 ->plaintextParams(
$header )->inContentLanguage()->text() .
"\n\n" :
'';
138 return new static( $text );
153 [ $target, $content ] = $handler->extractRedirectTargetAndText( $this );
155 return [ Title::castFromLinkTarget( $target ), $content->getText() ];
170 [ $target, ] = $handler->extractRedirectTargetAndText( $this );
172 return Title::castFromLinkTarget( $target );
193 # Remember that redirect pages can have categories, templates, etc.,
194 # so the regex has to be fairly general
195 $newText = preg_replace(
'/ \[ \[ [^\]]* \] \] /x',
197 $this->getText(), 1 );
199 return new static( $newText );
214 $articleCountMethod = MediaWikiServices::getInstance()->getMainConfig()
215 ->get( MainConfigNames::ArticleCountMethod );
221 if ( $articleCountMethod ===
'link' ) {
222 if ( $hasLinks ===
null ) { # not known, find out
225 $context = RequestContext::getMain();
226 $title = $context->getTitle();
228 $contentRenderer = MediaWikiServices::getInstance()->getContentRenderer();
230 $po = $contentRenderer->getParserOutput( $this, $title,
null,
null,
false );
231 $links = $po->getLinks();
232 $hasLinks = $links !== [];
246 $truncatedtext = parent::getTextForSummary( $maxlength );
248 # clean up unfinished links
249 # XXX: make this optional? wasn't there in autosummary, but required for
251 $truncatedtext = preg_replace(
'/\[\[([^\]]*)\]?$/',
'$1', $truncatedtext );
253 return $truncatedtext;
275 $this->preSaveTransformFlags = $flags;
284 return $this->preSaveTransformFlags;
289 '@phan-var WikitextContentHandler $handler';
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.
Group all the pieces relevant to the context of a request into one instance.
A class containing constants representing the names of configuration variables.
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.
updateRedirect(Title $target)
This implementation replaces the first link on the page with the given new target if this Content obj...
setPreSaveTransformFlags(array $flags)
Records flags set by preSaveTransform.
getRedirectTarget()
Implement redirect extraction for wikitext.
getTextForSummary( $maxlength=250)
getPreSaveTransformFlags()
Records flags set by preSaveTransform.
getRedirectTargetAndText()
Extract the redirect target and the remaining text on the page.
addSectionHeader( $header)
Returns a new WikitextContent object with the given section heading prepended.
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...
matchMagicWord(MagicWord $word)
This implementation calls $word->match() on the this TextContent object's text.
replaceSection( $sectionId, Content $with, $sectionTitle='')
Base interface for representing page content.
getModel()
Returns the ID of the content model used by this Content object.