41 private $redirectTargetAndText =
null;
46 private $preSaveTransformFlags = [];
66 $sect = MediaWikiServices::getInstance()->getParserFactory()->getInstance()
67 ->getSection( $text, $sectionId,
false );
69 if ( $sect ===
false ) {
72 return new static( $sect );
91 if ( $sectionModelId != $myModelId ) {
92 throw new MWException(
"Incompatible content model for section: " .
93 "document uses $myModelId but " .
94 "section uses $sectionModelId." );
97 '@phan-var self $with';
100 $text = $with->getText();
102 if ( strval( $sectionId ) ===
'' ) {
103 return $with; # XXX:
copy first?
106 if ( $sectionId ===
'new' ) {
107 # Inserting a new section
108 $subject = strval( $sectionTitle ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
109 ->plaintextParams( $sectionTitle )->inContentLanguage()->text() .
"\n\n" :
'';
110 $hookRunner = (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) );
111 if ( $hookRunner->onPlaceNewSection( $this, $oldtext, $subject, $text ) ) {
112 $text = strlen( trim( $oldtext ) ) > 0
113 ?
"{$oldtext}\n\n{$subject}{$text}"
114 :
"{$subject}{$text}";
117 # Replacing an existing section; roll out the big guns
118 $text = MediaWikiServices::getInstance()->getParserFactory()->getInstance()
119 ->replaceSection( $oldtext, $sectionId, $text );
122 $newContent =
new static( $text );
136 $text = strval(
$header ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
137 ->plaintextParams(
$header )->inContentLanguage()->text() .
"\n\n" :
'';
140 return new static( $text );
153 if ( $this->redirectTargetAndText !==
null ) {
154 return $this->redirectTargetAndText;
157 $redir = MediaWikiServices::getInstance()->getMagicWordFactory()->get(
'redirect' );
158 $text = ltrim( $this->
getText() );
159 if ( $redir->matchStartAndRemove( $text ) ) {
164 if ( preg_match(
'!^\s*:?\s*\[{2}(.*?)(?:\|.*?)?\]{2}\s*!', $text, $m ) ) {
167 if ( strpos( $m[1],
'%' ) !==
false ) {
169 $m[1] = rawurldecode( ltrim( $m[1],
':' ) );
171 $title = Title::newFromText( $m[1] );
174 $this->redirectTargetAndText = [
null, $this->
getText() ];
175 return $this->redirectTargetAndText;
178 $this->redirectTargetAndText = [ $title, substr( $text, strlen( $m[0] ) ) ];
179 return $this->redirectTargetAndText;
183 $this->redirectTargetAndText = [
null, $this->
getText() ];
184 return $this->redirectTargetAndText;
218 # Remember that redirect pages can have categories, templates, etc.,
219 # so the regex has to be fairly general
220 $newText = preg_replace(
'/ \[ \[ [^\]]* \] \] /x',
222 $this->getText(), 1 );
224 return new static( $newText );
239 $articleCountMethod = MediaWikiServices::getInstance()->getMainConfig()
240 ->get( MainConfigNames::ArticleCountMethod );
246 if ( $articleCountMethod ===
'link' ) {
247 if ( $hasLinks ===
null ) { # not known, find out
251 $title = $context->getTitle();
253 $contentRenderer = MediaWikiServices::getInstance()->getContentRenderer();
255 $po = $contentRenderer->getParserOutput( $this, $title,
null,
null,
false );
256 $links = $po->getLinks();
257 $hasLinks = $links !== [];
271 $truncatedtext = parent::getTextForSummary( $maxlength );
273 # clean up unfinished links
274 # XXX: make this optional? wasn't there in autosummary, but required for
276 $truncatedtext = preg_replace(
'/\[\[([^\]]*)\]?$/',
'$1', $truncatedtext );
278 return $truncatedtext;
300 $this->preSaveTransformFlags = $flags;
309 return $this->preSaveTransformFlags;
const CONTENT_MODEL_WIKITEXT
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
A class containing constants representing the names of configuration variables.
static getMain()
Get the RequestContext object associated with the main request.
Content object implementation for representing flat text.
getText()
Returns the text represented by this Content object, as a string.
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.