40 private $redirectTargetAndText =
null;
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 if (
Hooks::runner()->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 );
151 if ( $this->redirectTargetAndText !==
null ) {
152 return $this->redirectTargetAndText;
155 $redir = MediaWikiServices::getInstance()->getMagicWordFactory()->get(
'redirect' );
156 $text = ltrim( $this->
getText() );
157 if ( $redir->matchStartAndRemove( $text ) ) {
162 if ( preg_match(
'!^\s*:?\s*\[{2}(.*?)(?:\|.*?)?\]{2}\s*!', $text, $m ) ) {
165 if ( strpos( $m[1],
'%' ) !==
false ) {
167 $m[1] = rawurldecode( ltrim( $m[1],
':' ) );
169 $title = Title::newFromText( $m[1] );
172 $this->redirectTargetAndText = [
null, $this->
getText() ];
173 return $this->redirectTargetAndText;
176 $this->redirectTargetAndText = [
$title, substr( $text, strlen( $m[0] ) ) ];
177 return $this->redirectTargetAndText;
181 $this->redirectTargetAndText = [
null, $this->
getText() ];
182 return $this->redirectTargetAndText;
216 # Remember that redirect pages can have categories, templates, etc.,
217 # so the regex has to be fairly general
218 $newText = preg_replace(
'/ \[ \[ [^\]]* \] \] /x',
220 $this->getText(), 1 );
222 return new static( $newText );
237 $articleCountMethod = MediaWikiServices::getInstance()->getMainConfig()
238 ->get( MainConfigNames::ArticleCountMethod );
244 if ( $articleCountMethod ===
'link' ) {
245 if ( $hasLinks ===
null ) { # not known, find out
249 $title = $context->getTitle();
251 $contentRenderer = MediaWikiServices::getInstance()->getContentRenderer();
253 $po = $contentRenderer->getParserOutput( $this,
$title,
null,
null,
false );
254 $links = $po->getLinks();
255 $hasLinks = !empty( $links );
269 $truncatedtext = parent::getTextForSummary( $maxlength );
271 # clean up unfinished links
272 # XXX: make this optional? wasn't there in autosummary, but required for
274 $truncatedtext = preg_replace(
'/\[\[([^\]]*)\]?$/',
'$1', $truncatedtext );
276 return $truncatedtext;
298 $this->preSaveTransformFlags = $flags;
307 return $this->preSaveTransformFlags;
const CONTENT_MODEL_WIKITEXT
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
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.