From d80b32d1986aff2ab3c0859abd97ef321742da0f Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Thu, 19 Mar 2015 22:20:53 +0100 Subject: [PATCH] ApiParse: Fix parse of new section title Mirror how EditPage transforms a new sectiontitle to be gray, have the arrow etc... Bug: T84877 Change-Id: If4d8fd11386c87a5b6d51b6afbeae737b3a829a5 --- includes/api/ApiParse.php | 42 +++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 20592ca290..6a87dce34f 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -228,12 +228,11 @@ class ApiParse extends ApiBase { $result_array['wikitext'] = array(); ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) ); } - if ( !is_null( $params['summary'] ) ) { + if ( !is_null( $params['summary'] ) || + ( !is_null( $params['sectiontitle'] ) && $this->section === 'new' ) + ) { $result_array['parsedsummary'] = array(); - ApiResult::setContent( - $result_array['parsedsummary'], - Linker::formatComment( $params['summary'], $titleObj ) - ); + ApiResult::setContent( $result_array['parsedsummary'], $this->formatSummary( $titleObj, $params ) ); } $result->addValue( null, $this->getModuleName(), $result_array ); @@ -270,12 +269,11 @@ class ApiParse extends ApiBase { ApiResult::setContent( $result_array['text'], $p_result->getText() ); } - if ( !is_null( $params['summary'] ) ) { + if ( !is_null( $params['summary'] ) || + ( !is_null( $params['sectiontitle'] ) && $this->section === 'new' ) + ) { $result_array['parsedsummary'] = array(); - ApiResult::setContent( - $result_array['parsedsummary'], - Linker::formatComment( $params['summary'], $titleObj ) - ); + ApiResult::setContent( $result_array['parsedsummary'], $this->formatSummary( $titleObj, $params ) ); } if ( isset( $prop['langlinks'] ) ) { @@ -499,6 +497,30 @@ class ApiParse extends ApiBase { return $section; } + /** + * This mimicks the behavior of EditPage in formatting a summary + * + * @param Title $title of the page being parsed + * @param Array $params the API parameters of the request + * @return Content|bool + */ + private function formatSummary( $title, $params ) { + global $wgParser; + $summary = !is_null( $params['summary'] ) ? $params['summary'] : ''; + $sectionTitle = !is_null( $params['sectiontitle'] ) ? $params['sectiontitle'] : ''; + + if ( $this->section === 'new' && ( $sectionTitle === '' || $summary === '' ) ) { + if( $sectionTitle !== '' ) { + $summary = $params['sectiontitle']; + } + if ( $summary !== '' ) { + $summary = wfMessage( 'newsectionsummary' )->rawParams( $wgParser->stripSectionName( $summary ) ) + ->inContentLanguage()->text(); + } + } + return Linker::formatComment( $summary, $title, $this->section === 'new' ); + } + private function formatLangLinks( $links ) { $result = array(); foreach ( $links as $link ) { -- 2.20.1