Go to the documentation of this file.
63 $sect = MediaWikiServices::getInstance()->getParser()
64 ->getSection( $text, $sectionId,
false );
66 if ( $sect ===
false ) {
69 return new static( $sect );
87 if ( $sectionModelId != $myModelId ) {
88 throw new MWException(
"Incompatible content model for section: " .
89 "document uses $myModelId but " .
90 "section uses $sectionModelId." );
93 '@phan-var self $with';
96 $text = $with->getText();
98 if ( strval( $sectionId ) ===
'' ) {
99 return $with; # XXX:
copy first?
102 if ( $sectionId ===
'new' ) {
103 # Inserting a new section
104 $subject = $sectionTitle ?
wfMessage(
'newsectionheaderdefaultlevel' )
105 ->plaintextParams( $sectionTitle )->inContentLanguage()->text() .
"\n\n" :
'';
106 if (
Hooks::run(
'PlaceNewSection', [ $this, $oldtext, $subject, &$text ] ) ) {
107 $text = strlen( trim( $oldtext ) ) > 0
108 ?
"{$oldtext}\n\n{$subject}{$text}"
109 :
"{$subject}{$text}";
112 # Replacing an existing section; roll out the big guns
113 $text = MediaWikiServices::getInstance()->getParser()
114 ->replaceSection( $oldtext, $sectionId, $text );
117 $newContent =
new static( $text );
131 $text =
wfMessage(
'newsectionheaderdefaultlevel' )
132 ->rawParams(
$header )->inContentLanguage()->text();
136 return new static( $text );
152 $parser = MediaWikiServices::getInstance()->getParser();
153 $pst = $parser->preSaveTransform( $text,
$title, $user, $popts );
155 if ( $text === $pst ) {
159 $ret =
new static( $pst );
161 if ( $parser->getOutput()->getFlag(
'user-signature' ) ) {
162 $ret->hadSignature =
true;
180 $plt = MediaWikiServices::getInstance()->getParser()
181 ->getPreloadText( $text,
$title, $popts, $params );
183 return new static( $plt );
198 if ( $this->redirectTargetAndText !==
null ) {
204 $this->redirectTargetAndText = [
null, $this->
getText() ];
208 $redir = MediaWikiServices::getInstance()->getMagicWordFactory()->get(
'redirect' );
209 $text = ltrim( $this->
getText() );
210 if ( $redir->matchStartAndRemove( $text ) ) {
215 if ( preg_match(
'!^\s*:?\s*\[{2}(.*?)(?:\|.*?)?\]{2}\s*!', $text, $m ) ) {
218 if ( strpos( $m[1],
'%' ) !==
false ) {
220 $m[1] = rawurldecode( ltrim( $m[1],
':' ) );
225 $this->redirectTargetAndText = [
null, $this->
getText() ];
229 $this->redirectTargetAndText = [
$title, substr( $text, strlen( $m[0] ) ) ];
234 $this->redirectTargetAndText = [
null, $this->
getText() ];
269 # Remember that redirect pages can have categories, templates, etc.,
270 # so the regex has to be fairly general
271 $newText = preg_replace(
'/ \[ \[ [^\]]* \] \] /x',
273 $this->getText(), 1 );
275 return new static( $newText );
296 if ( $wgArticleCountMethod ===
'link' ) {
297 if ( $hasLinks ===
null ) { # not known, find out
304 $links = $po->getLinks();
305 $hasLinks = !empty( $links );
319 $truncatedtext = parent::getTextForSummary( $maxlength );
321 # clean up unfinished links
322 # XXX: make this optional? wasn't there in autosummary, but required for
324 $truncatedtext = preg_replace(
'/\[\[([^\]]*)\]?$/',
'$1', $truncatedtext );
326 return $truncatedtext;
344 $stackTrace = (
new RuntimeException() )->getTraceAsString();
345 if ( $this->previousParseStackTrace ) {
349 $logger = LoggerFactory::getInstance(
'DuplicateParse' );
351 __METHOD__ .
': Possibly redundant parse!',
353 'title' =>
$title->getPrefixedDBkey(),
359 'trace' => $stackTrace,
360 'previous-trace' => $this->previousParseStackTrace,
364 $this->previousParseStackTrace = $stackTrace;
367 $output = MediaWikiServices::getInstance()->getParser()
368 ->parse( $text,
$title, $options,
true,
true, $revId );
374 if ( $generateHtml ) {
385 if ( $this->hadSignature ) {
386 $output->
setFlag(
'user-signature' );
395 "getHtml() not implemented for wikitext. "
396 .
"Use getParserOutput()->getText()."
Set options of the Parser.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
getRedirectTarget()
Implement redirect extraction for wikitext.
getParserOutput(Title $title, $revId=null, ParserOptions $options=null, $generateHtml=true)
Returns a ParserOutput object containing information derived from this content.
updateRedirect(Title $target)
This implementation replaces the first link on the page with the given new target if this Content obj...
setFlag( $flag)
Attach a flag to the output so that it can be checked later to handle special cases.
addLink(Title $title, $id=null)
Record a local or interwiki inline link for saving in future link tables.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
getRedirectTargetAndText()
Extract the redirect target and the remaining text on the page.
const CONTENT_MODEL_WIKITEXT
array null $previousParseStackTrace
Stack trace of the previous parse.
getText()
Returns the text represented by this Content object, as a string.
bool $hadSignature
Tracks if the parser set the user-signature flag when creating this content, which would make it expi...
getFullText()
Get the prefixed title with spaces, plus any fragment (part beginning with '#')
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...
addModuleStyles( $modules)
This class encapsulates "magic words" such as "#redirect", NOTOC, etc.
Content object for wiki text pages.
preSaveTransform(Title $title, User $user, ParserOptions $popts)
Returns a Content object with pre-save transformations applied using Parser::preSaveTransform().
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...
matchMagicWord(MagicWord $word)
This implementation calls $word->match() on the this TextContent object's text.
preloadTransform(Title $title, ParserOptions $popts, $params=[])
Returns a Content object with preload transformations applied (or this object if no transformations a...
getTextForSummary( $maxlength=250)
static getMain()
Get the RequestContext object associated with the main request.
Content object implementation for representing flat text.
Base interface for content objects.
Represents a title within MediaWiki.
addSectionHeader( $header)
Returns a new WikitextContent object with the given section heading prepended.
static allCacheVaryingOptions()
Return all option keys that vary the options hash.
getRawText()
Get the cacheable text with <mw:editsection> markers still in it.
getModel()
Returns the ID of the content model used by this Content object.
replaceSection( $sectionId, Content $with, $sectionTitle='')
$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.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
match( $text)
Returns true if the text contains the word.
optionsHash( $forOptions, $title=null)
Generate a hash string with the values set on these ParserOptions for the keys given in the array.
static getRedirectHeaderHtml(Language $lang, $target, $forceKnown=false)
Return the HTML for the top of a redirect page.