38 private $redirectTargetAndText =
null;
43 private $preSaveTransformFlags = [];
63 $sect = MediaWikiServices::getInstance()->getParserFactory()->getInstance()
64 ->getSection( $text, $sectionId,
false );
66 if ( $sect ===
false ) {
69 return new static( $sect );
88 if ( $sectionModelId != $myModelId ) {
89 throw new MWException(
"Incompatible content model for section: " .
90 "document uses $myModelId but " .
91 "section uses $sectionModelId." );
94 '@phan-var self $with';
97 $text = $with->getText();
99 if ( strval( $sectionId ) ===
'' ) {
100 return $with; # XXX:
copy first?
103 if ( $sectionId ===
'new' ) {
104 # Inserting a new section
105 $subject = strval( $sectionTitle ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
106 ->plaintextParams( $sectionTitle )->inContentLanguage()->text() .
"\n\n" :
'';
107 if ( Hooks::runner()->onPlaceNewSection( $this, $oldtext, $subject, $text ) ) {
108 $text = strlen( trim( $oldtext ) ) > 0
109 ?
"{$oldtext}\n\n{$subject}{$text}"
110 :
"{$subject}{$text}";
113 # Replacing an existing section; roll out the big guns
114 $text = MediaWikiServices::getInstance()->getParserFactory()->getInstance()
115 ->replaceSection( $oldtext, $sectionId, $text );
118 $newContent =
new static( $text );
132 $text = strval(
$header ) !==
'' ?
wfMessage(
'newsectionheaderdefaultlevel' )
133 ->plaintextParams(
$header )->inContentLanguage()->text() .
"\n\n" :
'';
136 return new static( $text );
149 if ( $this->redirectTargetAndText !==
null ) {
150 return $this->redirectTargetAndText;
153 $redir = MediaWikiServices::getInstance()->getMagicWordFactory()->get(
'redirect' );
154 $text = ltrim( $this->
getText() );
155 if ( $redir->matchStartAndRemove( $text ) ) {
160 if ( preg_match(
'!^\s*:?\s*\[{2}(.*?)(?:\|.*?)?\]{2}\s*!', $text, $m ) ) {
163 if ( strpos( $m[1],
'%' ) !==
false ) {
165 $m[1] = rawurldecode( ltrim( $m[1],
':' ) );
167 $title = Title::newFromText( $m[1] );
170 $this->redirectTargetAndText = [
null, $this->
getText() ];
171 return $this->redirectTargetAndText;
174 $this->redirectTargetAndText = [
$title, substr( $text, strlen( $m[0] ) ) ];
175 return $this->redirectTargetAndText;
179 $this->redirectTargetAndText = [
null, $this->
getText() ];
180 return $this->redirectTargetAndText;
214 # Remember that redirect pages can have categories, templates, etc.,
215 # so the regex has to be fairly general
216 $newText = preg_replace(
'/ \[ \[ [^\]]* \] \] /x',
218 $this->getText(), 1 );
220 return new static( $newText );
235 $articleCountMethod = MediaWikiServices::getInstance()->getMainConfig()
236 ->get( MainConfigNames::ArticleCountMethod );
242 if ( $articleCountMethod ===
'link' ) {
243 if ( $hasLinks ===
null ) { # not known, find out
246 $context = RequestContext::getMain();
247 $title = $context->getTitle();
249 $contentRenderer = MediaWikiServices::getInstance()->getContentRenderer();
251 $po = $contentRenderer->getParserOutput( $this,
$title,
null,
null,
false );
252 $links = $po->getLinks();
253 $hasLinks = !empty( $links );
267 $truncatedtext = parent::getTextForSummary( $maxlength );
269 # clean up unfinished links
270 # XXX: make this optional? wasn't there in autosummary, but required for
272 $truncatedtext = preg_replace(
'/\[\[([^\]]*)\]?$/',
'$1', $truncatedtext );
274 return $truncatedtext;
296 $this->preSaveTransformFlags = $flags;
305 return $this->preSaveTransformFlags;
const CONTENT_MODEL_WIKITEXT
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
This class encapsulates "magic words" such as "#redirect", NOTOC, etc.
match( $text)
Returns true if the text contains the word.
A class containing constants representing the names of configuration variables.
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.
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 content objects.
getModel()
Returns the ID of the content model used by this Content object.