From d7a61d72231861755f0ccdaf80d7b4388cebd5df Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Thu, 6 Jun 2013 20:04:40 +0400 Subject: [PATCH] action=parse now can parse in preview mode Bug: 49239 Change-Id: Iacfea0219ef21dc91d669f51140ec129c2f41f76 --- RELEASE-NOTES-1.22 | 1 + includes/api/ApiParse.php | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 5339514d05..07763d95e6 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -158,6 +158,7 @@ production. * prop=info now adds the content model and page language of the title. * New upload log entries will now contain information on the relavent image (sha1 and timestamp). +* (bug 49239) action=parse now can parse in preview mode. === Languages updated in 1.22=== diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index bde1d99574..800af25afe 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -94,8 +94,7 @@ class ApiParse extends ApiBase { $titleObj = $rev->getTitle(); $wgTitle = $titleObj; $pageObj = WikiPage::factory( $titleObj ); - $popts = $pageObj->makeParserOptions( $this->getContext() ); - $popts->enableLimitReport( !$params['disablepp'] ); + $popts = $this->makeParserOptions( $pageObj, $params ); // If for some reason the "oldid" is actually the current revision, it may be cached if ( $rev->isCurrent() ) { @@ -152,8 +151,7 @@ class ApiParse extends ApiBase { $oldid = $pageObj->getLatest(); } - $popts = $pageObj->makeParserOptions( $this->getContext() ); - $popts->enableLimitReport( !$params['disablepp'] ); + $popts = $this->makeParserOptions( $pageObj, $params ); // Potentially cached $p_result = $this->getParsedContent( $pageObj, $popts, $pageid, @@ -170,8 +168,7 @@ class ApiParse extends ApiBase { $wgTitle = $titleObj; $pageObj = WikiPage::factory( $titleObj ); - $popts = $pageObj->makeParserOptions( $this->getContext() ); - $popts->enableLimitReport( !$params['disablepp'] ); + $popts = $this->makeParserOptions( $pageObj, $params ); if ( is_null( $text ) ) { $this->dieUsage( 'The text parameter should be passed with the title parameter. Should you be using the "page" parameter instead?', 'params' ); @@ -359,6 +356,26 @@ class ApiParse extends ApiBase { } } + /** + * Constructs a ParserOptions object + * + * @param WikiPage $pageObj + * @param array $params + * + * @return ParserOptions + */ + protected function makeParserOptions( WikiPage $pageObj, array $params ) { + wfProfileIn( __METHOD__ ); + + $popts = $pageObj->makeParserOptions( $this->getContext() ); + $popts->enableLimitReport( !$params['disablepp'] ); + $popts->setIsPreview( $params['preview'] ); + $popts->setIsSectionPreview( $params['preview'] && $this->section !== false ); + + wfProfileOut( __METHOD__ ); + return $popts; + } + /** * @param $page WikiPage * @param $popts ParserOptions @@ -594,6 +611,7 @@ class ApiParse extends ApiBase { 'section' => null, 'disablepp' => false, 'generatexml' => false, + 'preview' => false, 'contentformat' => array( ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(), ), @@ -649,6 +667,7 @@ class ApiParse extends ApiBase { 'section' => 'Only retrieve the content of this section number', 'disablepp' => 'Disable the PP Report from the parser output', 'generatexml' => 'Generate XML parse tree (requires prop=wikitext)', + 'preview' => 'Parse in preview mode', 'contentformat' => 'Content serialization format used for the input text', 'contentmodel' => 'Content model of the new content', ); -- 2.20.1