X-Git-Url: https://git.cyclocoop.org/%28%28?a=blobdiff_plain;f=includes%2Fcontent%2FWikitextContent.php;h=dbe09f91c9b20452bc2858f50d949f43938256eb;hb=a6c17640fc571ebd173e5460bfbda599cf5f5f67;hp=3ab6a6dbea11fb0376c33004f2743bdd49ee0094;hpb=523c6c0e41159c073b6b44dd550878f42cbc847e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/content/WikitextContent.php b/includes/content/WikitextContent.php index 3ab6a6dbea..dbe09f91c9 100644 --- a/includes/content/WikitextContent.php +++ b/includes/content/WikitextContent.php @@ -31,6 +31,7 @@ * @ingroup Content */ class WikitextContent extends TextContent { + private $redirectTargetAndText = null; public function __construct( $text ) { parent::__construct( $text, CONTENT_MODEL_WIKITEXT ); @@ -67,13 +68,11 @@ class WikitextContent extends TextContent { * @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." ); @@ -83,7 +82,6 @@ class WikitextContent extends TextContent { $text = $with->getNativeData(); if ( strval( $sectionId ) === '' ) { - wfProfileOut( __METHOD__ ); return $with; # XXX: copy first? } @@ -92,7 +90,7 @@ class WikitextContent extends TextContent { # 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}"; @@ -106,8 +104,6 @@ class WikitextContent extends TextContent { $newContent = new static( $text ); - wfProfileOut( __METHOD__ ); - return $newContent; } @@ -178,10 +174,17 @@ class WikitextContent extends TextContent { */ 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 ) ) { @@ -199,14 +202,17 @@ class WikitextContent extends TextContent { $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; } /**