* @ingroup Content
*/
class WikitextContent extends TextContent {
+ private $redirectTargetAndText = null;
public function __construct( $text ) {
parent::__construct( $text, CONTENT_MODEL_WIKITEXT );
* @see Content::replaceSection()
*/
public function replaceSection( $sectionId, Content $with, $sectionTitle = '' ) {
- wfProfileIn( __METHOD__ );
$myModelId = $this->getModel();
$sectionModelId = $with->getModel();
if ( $sectionModelId != $myModelId ) {
- wfProfileOut( __METHOD__ );
throw new MWException( "Incompatible content model for section: " .
"document uses $myModelId but " .
"section uses $sectionModelId." );
$text = $with->getNativeData();
if ( strval( $sectionId ) === '' ) {
- wfProfileOut( __METHOD__ );
return $with; # XXX: copy first?
}
# Inserting a new section
$subject = $sectionTitle ? wfMessage( 'newsectionheaderdefaultlevel' )
->rawParams( $sectionTitle )->inContentLanguage()->text() . "\n\n" : '';
- if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) {
+ if ( Hooks::run( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) {
$text = strlen( trim( $oldtext ) ) > 0
? "{$oldtext}\n\n{$subject}{$text}"
: "{$subject}{$text}";
$newContent = new static( $text );
- wfProfileOut( __METHOD__ );
-
return $newContent;
}
*/
protected function getRedirectTargetAndText() {
global $wgMaxRedirects;
+
+ if ( $this->redirectTargetAndText !== null ) {
+ return $this->redirectTargetAndText;
+ }
+
if ( $wgMaxRedirects < 1 ) {
// redirects are disabled, so quit early
- return array( null, $this->getNativeData() );
+ $this->redirectTargetAndText = array( null, $this->getNativeData() );
+ return $this->redirectTargetAndText;
}
+
$redir = MagicWord::get( 'redirect' );
$text = ltrim( $this->getNativeData() );
if ( $redir->matchStartAndRemove( $text ) ) {
$title = Title::newFromText( $m[1] );
// If the title is a redirect to bad special pages or is invalid, return null
if ( !$title instanceof Title || !$title->isValidRedirectTarget() ) {
- return array( null, $this->getNativeData() );
+ $this->redirectTargetAndText = array( null, $this->getNativeData() );
+ return $this->redirectTargetAndText;
}
- return array( $title, substr( $text, strlen( $m[0] ) ) );
+ $this->redirectTargetAndText = array( $title, substr( $text, strlen( $m[0] ) ) );
+ return $this->redirectTargetAndText;
}
}
- return array( null, $this->getNativeData() );
+ $this->redirectTargetAndText = array( null, $this->getNativeData() );
+ return $this->redirectTargetAndText;
}
/**