45 private $preSaveTransformFlags = [];
65 $sect = MediaWikiServices::getInstance()->getParserFactory()->getInstance()
66 ->getSection( $text, $sectionId,
false );
68 if ( $sect ===
false ) {
71 return new static( $sect );
90 if ( $sectionModelId != $myModelId ) {
91 throw new MWException(
"Incompatible content model for section: " .
92 "document uses $myModelId but " .
93 "section uses $sectionModelId." );
96 '@phan-var self $with';
99 $text = $with->getText();
101 if ( strval( $sectionId ) ===
'' ) {
102 return $with; # XXX:
copy first?
105 if ( $sectionId ===
'new' ) {
106 # Inserting a new section
107 $subject = strval( $sectionTitle ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
108 ->plaintextParams( $sectionTitle )->inContentLanguage()->text() .
"\n\n" :
'';
109 $hookRunner = (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) );
110 if ( $hookRunner->onPlaceNewSection( $this, $oldtext, $subject, $text ) ) {
111 $text = strlen( trim( $oldtext ) ) > 0
112 ?
"{$oldtext}\n\n{$subject}{$text}"
113 :
"{$subject}{$text}";
116 # Replacing an existing section; roll out the big guns
117 $text = MediaWikiServices::getInstance()->getParserFactory()->getInstance()
118 ->replaceSection( $oldtext, $sectionId, $text );
121 $newContent =
new static( $text );
135 $text = strval(
$header ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
136 ->plaintextParams(
$header )->inContentLanguage()->text() .
"\n\n" :
'';
139 return new static( $text );
154 [ $target,
$content ] = $handler->extractRedirectTargetAndText( $this );
156 return [ Title::castFromLinkTarget( $target ),
$content->getText() ];
171 [ $target, ] = $handler->extractRedirectTargetAndText( $this );
173 return Title::castFromLinkTarget( $target );
194 # Remember that redirect pages can have categories, templates, etc.,
195 # so the regex has to be fairly general
196 $newText = preg_replace(
'/ \[ \[ [^\]]* \] \] /x',
198 $this->getText(), 1 );
200 return new static( $newText );
215 $articleCountMethod = MediaWikiServices::getInstance()->getMainConfig()
216 ->get( MainConfigNames::ArticleCountMethod );
222 if ( $articleCountMethod ===
'link' ) {
223 if ( $hasLinks ===
null ) { # not known, find out
226 $context = RequestContext::getMain();
227 $title = $context->getTitle();
229 $contentRenderer = MediaWikiServices::getInstance()->getContentRenderer();
231 $po = $contentRenderer->getParserOutput( $this, $title,
null,
null,
false );
232 $links = $po->getLinks();
233 $hasLinks = $links !== [];
247 $truncatedtext = parent::getTextForSummary( $maxlength );
249 # clean up unfinished links
250 # XXX: make this optional? wasn't there in autosummary, but required for
252 $truncatedtext = preg_replace(
'/\[\[([^\]]*)\]?$/',
'$1', $truncatedtext );
254 return $truncatedtext;
276 $this->preSaveTransformFlags = $flags;
285 return $this->preSaveTransformFlags;
290 '@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.
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.