68 $sect = MediaWikiServices::getInstance()->getParser()
69 ->getSection( $text, $sectionId,
false );
71 if ( $sect ===
false ) {
74 return new static( $sect );
92 if ( $sectionModelId != $myModelId ) {
93 throw new MWException(
"Incompatible content model for section: " .
94 "document uses $myModelId but " .
95 "section uses $sectionModelId." );
98 '@phan-var self $with';
101 $text = $with->getText();
103 if ( strval( $sectionId ) ===
'' ) {
104 return $with; # XXX:
copy first?
107 if ( $sectionId ===
'new' ) {
108 # Inserting a new section
109 $subject = strval( $sectionTitle ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
110 ->plaintextParams( $sectionTitle )->inContentLanguage()->text() .
"\n\n" :
'';
111 if ( Hooks::runner()->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()->getParser()
122 $newContent =
new static( $text );
136 $text =
wfMessage(
'newsectionheaderdefaultlevel' )
137 ->rawParams(
$header )->inContentLanguage()->text();
141 return new static( $text );
156 if ( $this->redirectTargetAndText !==
null ) {
162 $this->redirectTargetAndText = [
null, $this->
getText() ];
166 $redir = MediaWikiServices::getInstance()->getMagicWordFactory()->get(
'redirect' );
167 $text = ltrim( $this->
getText() );
168 if ( $redir->matchStartAndRemove( $text ) ) {
173 if ( preg_match(
'!^\s*:?\s*\[{2}(.*?)(?:\|.*?)?\]{2}\s*!', $text, $m ) ) {
176 if ( strpos( $m[1],
'%' ) !==
false ) {
178 $m[1] = rawurldecode( ltrim( $m[1],
':' ) );
180 $title = Title::newFromText( $m[1] );
183 $this->redirectTargetAndText = [
null, $this->
getText() ];
187 $this->redirectTargetAndText = [
$title, substr( $text, strlen( $m[0] ) ) ];
192 $this->redirectTargetAndText = [
null, $this->
getText() ];
227 # Remember that redirect pages can have categories, templates, etc.,
228 # so the regex has to be fairly general
229 $newText = preg_replace(
'/ \[ \[ [^\]]* \] \] /x',
231 $this->getText(), 1 );
233 return new static( $newText );
254 if ( $wgArticleCountMethod ===
'link' ) {
255 if ( $hasLinks ===
null ) { # not known, find out
258 $context = RequestContext::getMain();
259 $title = $context->getTitle();
263 $links = $po->getLinks();
264 $hasLinks = !empty( $links );
278 $truncatedtext = parent::getTextForSummary( $maxlength );
280 # clean up unfinished links
281 # XXX: make this optional? wasn't there in autosummary, but required for
283 $truncatedtext = preg_replace(
'/\[\[([^\]]*)\]?$/',
'$1', $truncatedtext );
285 return $truncatedtext;
303 $stackTrace = (
new RuntimeException() )->getTraceAsString();
304 if ( $this->previousParseStackTrace ) {
308 $logger = LoggerFactory::getInstance(
'DuplicateParse' );
310 __METHOD__ .
': Possibly redundant parse!',
312 'title' =>
$title->getPrefixedDBkey(),
315 ParserOptions::allCacheVaryingOptions(),
318 'trace' => $stackTrace,
319 'previous-trace' => $this->previousParseStackTrace,
323 $this->previousParseStackTrace = $stackTrace;
326 $output = MediaWikiServices::getInstance()->getParser()
327 ->parse( $text,
$title, $options,
true,
true, $revId );
333 if ( $generateHtml ) {
336 Article::getRedirectHeaderHtml(
$title->getPageLanguage(), $chain,
false ) .
344 if ( in_array(
'user-signature', $this->preSaveTransformFlags ) ) {
345 $output->
setFlag(
'user-signature' );
355 "getHtml() not implemented for wikitext. "
356 .
"Use getParserOutput()->getText()."
379 $this->preSaveTransformFlags = $flags;
$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.
const CONTENT_MODEL_WIKITEXT
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.
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.
string[] $preSaveTransformFlags
flags set by PST
getRedirectTarget()
Implement redirect extraction for wikitext.
string null $previousParseStackTrace
Stack trace of the previous parse.
getTextForSummary( $maxlength=250)
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.
replaceSection( $sectionId, Content $with, $sectionTitle='')
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.