r80818 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80817‎ | r80818 | r80819 >
Date:16:07, 23 January 2011
Author:platonides
Status:ok (Comments)
Tags:
Comment:
Replace the repeated prologues to set mOptions, clearState(), setOutputType(), setTitle() with startExternalParse() calls
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -271,13 +271,8 @@
272272 wfProfileIn( __METHOD__ );
273273 wfProfileIn( $fname );
274274
275 - $this->mOptions = $options;
276 - if ( $clearState ) {
277 - $this->clearState();
278 - }
 275+ $this->startExternalParse( $title, $options, self::OT_HTML, $clearState );
279276
280 - $this->setTitle( $title ); # Page title has to be set for the pre-processor
281 -
282277 $oldRevisionId = $this->mRevisionId;
283278 $oldRevisionObject = $this->mRevisionObject;
284279 $oldRevisionTimestamp = $this->mRevisionTimestamp;
@@ -288,7 +283,7 @@
289284 $this->mRevisionTimestamp = null;
290285 $this->mRevisionUser = null;
291286 }
292 - $this->setOutputType( self::OT_HTML );
 287+
293288 wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
294289 # No more strip!
295290 wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
@@ -460,10 +455,7 @@
461456 */
462457 function preprocess( $text, $title, $options, $revid = null ) {
463458 wfProfileIn( __METHOD__ );
464 - $this->mOptions = $options;
465 - $this->clearState();
466 - $this->setOutputType( self::OT_PREPROCESS );
467 - $this->setTitle( $title );
 459+ $this->startExternalParse( $title, $options, self::OT_PREPROCESS, true );
468460 if ( $revid !== null ) {
469461 $this->mRevisionId = $revid;
470462 }
@@ -483,10 +475,7 @@
484476 */
485477 public function getPreloadText( $text, $title, $options ) {
486478 # Parser (re)initialisation
487 - $this->mOptions = $options;
488 - $this->clearState();
489 - $this->setOutputType( self::OT_PLAIN );
490 - $this->setTitle( $title );
 479+ $this->startExternalParse( $title, $options, self::OT_PLAIN, true );
491480
492481 $flags = PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES;
493482 $dom = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION );
@@ -4077,15 +4066,9 @@
40784067 * @return String: the altered wiki markup
40794068 */
40804069 public function preSaveTransform( $text, Title $title, User $user, ParserOptions $options, $clearState = true ) {
4081 - $this->mOptions = $options;
4082 - $this->setTitle( $title );
 4070+ $this->startExternalParse( $title, $options, self::OT_WIKI, $clearState );
40834071 $this->setUser( $user );
4084 - $this->setOutputType( self::OT_WIKI );
40854072
4086 - if ( $clearState ) {
4087 - $this->clearState();
4088 - }
4089 -
40904073 $pairs = array(
40914074 "\r\n" => "\n",
40924075 );
@@ -4911,11 +4894,8 @@
49124895 * for "replace", the whole page with the section replaced.
49134896 */
49144897 private function extractSections( $text, $section, $mode, $newText='' ) {
4915 - global $wgTitle;
4916 - $this->mOptions = new ParserOptions;
4917 - $this->clearState();
4918 - $this->setTitle( $wgTitle ); # not generally used but removes an ugly failure mode
4919 - $this->setOutputType( self::OT_PLAIN );
 4898+ global $wgTitle; # not generally used but removes an ugly failure mode
 4899+ $this->startExternalParse( $wgTitle, new ParserOptions, self::OT_PLAIN, true );
49204900 $outText = '';
49214901 $frame = $this->getPreprocessor()->newFrame();
49224902
@@ -5203,13 +5183,11 @@
52045184 * strip/replaceVariables/unstrip for preprocessor regression testing
52055185 */
52065186 function testSrvus( $text, $title, $options, $outputType = self::OT_HTML ) {
5207 - $this->mOptions = $options;
5208 - $this->clearState();
52095187 if ( !$title instanceof Title ) {
52105188 $title = Title::newFromText( $title );
52115189 }
5212 - $this->mTitle = $title;
5213 - $this->setOutputType( $outputType );
 5190+ $this->startExternalParse( $title, $options, $outputType, true );
 5191+
52145192 $text = $this->replaceVariables( $text );
52155193 $text = $this->mStripState->unstripBoth( $text );
52165194 $text = Sanitizer::removeHTMLtags( $text );

Follow-up revisions

RevisionCommit summaryAuthorDate
r82603Rename startExternalParse() when used for internal usage, per r80818 CR.platonides15:05, 22 February 2011

Comments

#Comment by Tim Starling (talk | contribs)   00:42, 22 February 2011

If you want to do this then you have to rename the function. It's obviously not starting an external parse any more.

#Comment by Platonides (talk | contribs)   15:05, 22 February 2011

Perfect. Done in r82603.

Status & tagging log