69 $sect = MediaWikiServices::getInstance()->getParser()
70 ->getSection( $text, $sectionId,
false );
72 if ( $sect ===
false ) {
75 return new static( $sect );
93 if ( $sectionModelId != $myModelId ) {
94 throw new MWException(
"Incompatible content model for section: " .
95 "document uses $myModelId but " .
96 "section uses $sectionModelId." );
99 '@phan-var self $with';
102 $text = $with->getText();
104 if ( strval( $sectionId ) ===
'' ) {
105 return $with; # XXX:
copy first?
108 if ( $sectionId ===
'new' ) {
109 # Inserting a new section
110 $subject = strval( $sectionTitle ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
111 ->plaintextParams( $sectionTitle )->inContentLanguage()->text() .
"\n\n" :
'';
112 if ( Hooks::runner()->onPlaceNewSection( $this, $oldtext, $subject, $text ) ) {
113 $text = strlen( trim( $oldtext ) ) > 0
114 ?
"{$oldtext}\n\n{$subject}{$text}"
115 :
"{$subject}{$text}";
118 # Replacing an existing section; roll out the big guns
119 $text = MediaWikiServices::getInstance()->getParser()
123 $newContent =
new static( $text );
137 $text =
wfMessage(
'newsectionheaderdefaultlevel' )
138 ->rawParams(
$header )->inContentLanguage()->text();
142 return new static( $text );
158 $parser = MediaWikiServices::getInstance()->getParser();
159 $pst = $parser->preSaveTransform( $text,
$title, $user, $popts );
161 if ( $text === $pst ) {
165 $ret =
new static( $pst );
167 if ( $parser->getOutput()->getFlag(
'user-signature' ) ) {
168 $ret->hadSignature =
true;
186 $plt = MediaWikiServices::getInstance()->getParser()
187 ->getPreloadText( $text,
$title, $popts, $params );
189 return new static( $plt );
204 if ( $this->redirectTargetAndText !==
null ) {
210 $this->redirectTargetAndText = [
null, $this->
getText() ];
214 $redir = MediaWikiServices::getInstance()->getMagicWordFactory()->get(
'redirect' );
215 $text = ltrim( $this->
getText() );
216 if ( $redir->matchStartAndRemove( $text ) ) {
221 if ( preg_match(
'!^\s*:?\s*\[{2}(.*?)(?:\|.*?)?\]{2}\s*!', $text, $m ) ) {
224 if ( strpos( $m[1],
'%' ) !==
false ) {
226 $m[1] = rawurldecode( ltrim( $m[1],
':' ) );
228 $title = Title::newFromText( $m[1] );
231 $this->redirectTargetAndText = [
null, $this->
getText() ];
235 $this->redirectTargetAndText = [
$title, substr( $text, strlen( $m[0] ) ) ];
240 $this->redirectTargetAndText = [
null, $this->
getText() ];
275 # Remember that redirect pages can have categories, templates, etc.,
276 # so the regex has to be fairly general
277 $newText = preg_replace(
'/ \[ \[ [^\]]* \] \] /x',
279 $this->getText(), 1 );
281 return new static( $newText );
302 if ( $wgArticleCountMethod ===
'link' ) {
303 if ( $hasLinks ===
null ) { # not known, find out
305 $context = RequestContext::getMain();
306 $title = $context->getTitle();
310 $links = $po->getLinks();
311 $hasLinks = !empty( $links );
325 $truncatedtext = parent::getTextForSummary( $maxlength );
327 # clean up unfinished links
328 # XXX: make this optional? wasn't there in autosummary, but required for
330 $truncatedtext = preg_replace(
'/\[\[([^\]]*)\]?$/',
'$1', $truncatedtext );
332 return $truncatedtext;
350 $stackTrace = (
new RuntimeException() )->getTraceAsString();
351 if ( $this->previousParseStackTrace ) {
355 $logger = LoggerFactory::getInstance(
'DuplicateParse' );
357 __METHOD__ .
': Possibly redundant parse!',
359 'title' =>
$title->getPrefixedDBkey(),
362 ParserOptions::allCacheVaryingOptions(),
365 'trace' => $stackTrace,
366 'previous-trace' => $this->previousParseStackTrace,
370 $this->previousParseStackTrace = $stackTrace;
373 $output = MediaWikiServices::getInstance()->getParser()
374 ->parse( $text,
$title, $options,
true,
true, $revId );
380 if ( $generateHtml ) {
383 Article::getRedirectHeaderHtml(
$title->getPageLanguage(), $chain,
false ) .
391 if ( $this->hadSignature ) {
392 $output->
setFlag(
'user-signature' );
401 "getHtml() not implemented for wikitext. "
402 .
"Use getParserOutput()->getText()."
$wgMaxRedirects
Max number of redirects to follow when resolving redirects.
$wgArticleCountMethod
Method used to determine if a page in a content namespace should be counted as a valid article.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
getParserOutput(Title $title, $revId=null, ParserOptions $options=null, $generateHtml=true)
Returns a ParserOutput object containing information derived from this content.
This class encapsulates "magic words" such as "#redirect", NOTOC, etc.
match( $text)
Returns true if the text contains the word.
Set options of the Parser.
optionsHash( $forOptions, $title=null)
Generate a hash string with the values set on these ParserOptions for the keys given in the array.
addLink(Title $title, $id=null)
Record a local or interwiki inline link for saving in future link tables.
getRawText()
Get the cacheable text with <mw:editsection> markers still in it.
addModuleStyles( $modules)
setFlag( $flag)
Attach a flag to the output so that it can be checked later to handle special cases.
Content object implementation for representing flat text.
getText()
Returns the text represented by this Content object, as a string.
Represents a title within MediaWiki.
getFullText()
Get the prefixed title with spaces, plus any fragment (part beginning with '#')
isValidRedirectTarget()
Check if this Title is a valid redirect target.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
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...
getRedirectTarget()
Implement redirect extraction for wikitext.
string null $previousParseStackTrace
Stack trace of the previous parse.
getTextForSummary( $maxlength=250)
preloadTransform(Title $title, ParserOptions $popts, $params=[])
Returns a Content object with preload transformations applied (or this object if no transformations a...
fillParserOutput(Title $title, $revId, ParserOptions $options, $generateHtml, ParserOutput &$output)
Returns a ParserOutput object resulting from parsing the content's text using the global Parser servi...
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.
__construct( $text)
Stable to call.
bool $hadSignature
Tracks if the parser set the user-signature flag when creating this content, which would make it expi...
preSaveTransform(Title $title, User $user, ParserOptions $popts)
Returns a Content object with pre-save transformations applied using Parser::preSaveTransform().
replaceSection( $sectionId, Content $with, $sectionTitle='')
const CONTENT_MODEL_WIKITEXT
Base interface for content objects.
getModel()
Returns the ID of the content model used by this Content object.
replaceSection( $sectionId, Content $with, $sectionTitle='')
Replaces a section of the content and returns a Content object with the section replaced.