+ // if they didn't want any output except (probably) the parse tree,
+ // then don't bother actually fully expanding it
+ if ( $prop || $params['prop'] === null ) {
+ $wgParser->startExternalParse( $titleObj, $options, Parser::OT_PREPROCESS );
+ $frame = $wgParser->getPreprocessor()->newFrame();
+ $wikitext = $wgParser->preprocess( $params['text'], $titleObj, $options, $revid, $frame );
+ if ( $params['prop'] === null ) {
+ // the old way
+ ApiResult::setContentValue( $retval, 'wikitext', $wikitext );
+ } else {
+ $p_output = $wgParser->getOutput();
+ if ( isset( $prop['categories'] ) ) {
+ $categories = $p_output->getCategories();
+ if ( $categories ) {
+ $categories_result = [];
+ foreach ( $categories as $category => $sortkey ) {
+ $entry = [];
+ $entry['sortkey'] = $sortkey;
+ ApiResult::setContentValue( $entry, 'category', (string)$category );
+ $categories_result[] = $entry;
+ }
+ ApiResult::setIndexedTagName( $categories_result, 'category' );
+ $retval['categories'] = $categories_result;
+ }
+ }
+ if ( isset( $prop['properties'] ) ) {
+ $properties = $p_output->getProperties();
+ if ( $properties ) {
+ ApiResult::setArrayType( $properties, 'BCkvp', 'name' );
+ ApiResult::setIndexedTagName( $properties, 'property' );
+ $retval['properties'] = $properties;
+ }
+ }
+ if ( isset( $prop['volatile'] ) ) {
+ $retval['volatile'] = $frame->isVolatile();
+ }
+ if ( isset( $prop['ttl'] ) && $frame->getTTL() !== null ) {
+ $retval['ttl'] = $frame->getTTL();
+ }
+ if ( isset( $prop['wikitext'] ) ) {
+ $retval['wikitext'] = $wikitext;
+ }
+ if ( isset( $prop['modules'] ) ) {
+ $retval['modules'] = array_values( array_unique( $p_output->getModules() ) );
+ $retval['modulescripts'] = array_values( array_unique( $p_output->getModuleScripts() ) );
+ $retval['modulestyles'] = array_values( array_unique( $p_output->getModuleStyles() ) );
+ }
+ if ( isset( $prop['jsconfigvars'] ) ) {
+ $retval['jsconfigvars'] =
+ ApiResult::addMetadataToResultVars( $p_output->getJsConfigVars() );
+ }
+ if ( isset( $prop['encodedjsconfigvars'] ) ) {
+ $retval['encodedjsconfigvars'] = FormatJson::encode(
+ $p_output->getJsConfigVars(), false, FormatJson::ALL_OK
+ );
+ $retval[ApiResult::META_SUBELEMENTS][] = 'encodedjsconfigvars';
+ }
+ if ( isset( $prop['modules'] ) &&
+ !isset( $prop['jsconfigvars'] ) && !isset( $prop['encodedjsconfigvars'] ) ) {
+ $this->addWarning( 'apiwarn-moduleswithoutvars' );
+ }
+ }
+ }
+ ApiResult::setSubelementsList( $retval, [ 'wikitext', 'parsetree' ] );
+ $result->addValue( null, $this->getModuleName(), $retval );