60 $this->
getMain()->setCacheMode(
'anon-public-user-private' );
68 $titleProvided =
false;
72 $titleProvided =
true;
75 if ( $params[
'prop'] ===
null ) {
77 [
'apiwarn-deprecation-missingparam',
'prop' ],
'action=expandtemplates&!prop'
81 $prop = array_fill_keys( $params[
'prop'],
true );
84 $titleObj = Title::newFromText(
$title );
85 if ( !$titleObj || $titleObj->isExternal() ) {
90 $revid = $params[
'revid'];
91 if ( $revid !==
null ) {
92 $rev = $this->revisionStore->getRevisionById( $revid );
94 $this->
dieWithError( [
'apierror-nosuchrevid', $revid ] );
96 $pTitleObj = $titleObj;
97 $titleObj = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
98 if ( $titleProvided && !$titleObj->equals( $pTitleObj ) ) {
99 $this->
addWarning( [
'apierror-revwrongpage', $rev->getId(),
107 $options = ParserOptions::newFromContext( $this->
getContext() );
109 if ( $params[
'includecomments'] ) {
110 $options->setRemoveComments(
false );
114 $suppressCache =
false;
116 $options, $titleObj, $params, $this, $reset, $suppressCache );
120 if ( isset( $prop[
'parsetree'] ) || $params[
'generatexml'] ) {
122 $dom = $this->parser->preprocessToDom( $params[
'text'] );
124 if ( is_callable( [ $dom,
'saveXML' ] ) ) {
126 $xml = $dom->saveXML();
129 $xml = $dom->__toString();
131 if ( isset( $prop[
'parsetree'] ) ) {
132 unset( $prop[
'parsetree'] );
133 $retval[
'parsetree'] = $xml;
136 $result->addValue(
null,
'parsetree', $xml );
137 $result->addValue(
null, ApiResult::META_BC_SUBELEMENTS, [
'parsetree' ] );
143 if ( $prop || $params[
'prop'] ===
null ) {
145 $frame = $this->parser->getPreprocessor()->newFrame();
146 $wikitext = $this->parser->preprocess( $params[
'text'], $titleObj, $options, $revid, $frame );
147 if ( $params[
'prop'] ===
null ) {
149 ApiResult::setContentValue( $retval,
'wikitext', $wikitext );
151 $p_output = $this->parser->getOutput();
152 if ( isset( $prop[
'categories'] ) ) {
153 $categories = $p_output->getCategories();
155 $categories_result = [];
156 foreach ( $categories as $category => $sortkey ) {
158 $entry[
'sortkey'] = $sortkey;
159 ApiResult::setContentValue( $entry,
'category', (
string)$category );
160 $categories_result[] = $entry;
162 ApiResult::setIndexedTagName( $categories_result,
'category' );
163 $retval[
'categories'] = $categories_result;
166 if ( isset( $prop[
'properties'] ) ) {
167 $properties = $p_output->getPageProperties();
169 ApiResult::setArrayType( $properties,
'BCkvp',
'name' );
170 ApiResult::setIndexedTagName( $properties,
'property' );
171 $retval[
'properties'] = $properties;
174 if ( isset( $prop[
'volatile'] ) ) {
175 $retval[
'volatile'] = $frame->isVolatile();
177 if ( isset( $prop[
'ttl'] ) && $frame->getTTL() !==
null ) {
178 $retval[
'ttl'] = $frame->getTTL();
180 if ( isset( $prop[
'wikitext'] ) ) {
181 $retval[
'wikitext'] = $wikitext;
183 if ( isset( $prop[
'modules'] ) ) {
184 $retval[
'modules'] = array_values( array_unique( $p_output->getModules() ) );
186 $retval[
'modulescripts'] = [];
187 $retval[
'modulestyles'] = array_values( array_unique( $p_output->getModuleStyles() ) );
189 if ( isset( $prop[
'jsconfigvars'] ) ) {
190 $showStrategyKeys = (bool)( $params[
'showstrategykeys'] );
191 $retval[
'jsconfigvars'] =
192 ApiResult::addMetadataToResultVars( $p_output->getJsConfigVars( $showStrategyKeys ) );
194 if ( isset( $prop[
'encodedjsconfigvars'] ) ) {
195 $retval[
'encodedjsconfigvars'] = FormatJson::encode(
196 $p_output->getJsConfigVars(),
false, FormatJson::ALL_OK
198 $retval[ApiResult::META_SUBELEMENTS][] =
'encodedjsconfigvars';
200 if ( isset( $prop[
'modules'] ) &&
201 !isset( $prop[
'jsconfigvars'] ) && !isset( $prop[
'encodedjsconfigvars'] ) ) {
202 $this->
addWarning(
'apiwarn-moduleswithoutvars' );
206 ApiResult::setSubelementsList( $retval, [
'wikitext',
'parsetree' ] );
214 ParamValidator::PARAM_TYPE =>
'text',
215 ParamValidator::PARAM_REQUIRED =>
true,
218 ParamValidator::PARAM_TYPE =>
'integer',
221 ParamValidator::PARAM_TYPE => [
229 'encodedjsconfigvars',
232 ParamValidator::PARAM_ISMULTI =>
true,
235 'includecomments' =>
false,
236 'showstrategykeys' =>
false,
238 ParamValidator::PARAM_TYPE =>
'boolean',
239 ParamValidator::PARAM_DEPRECATED =>
true,