59 $this->
getMain()->setCacheMode(
'anon-public-user-private' );
67 $titleProvided =
false;
71 $titleProvided =
true;
74 if ( $params[
'prop'] ===
null ) {
76 [
'apiwarn-deprecation-missingparam',
'prop' ],
'action=expandtemplates&!prop'
80 $prop = array_fill_keys( $params[
'prop'],
true );
83 $titleObj = Title::newFromText(
$title );
84 if ( !$titleObj || $titleObj->isExternal() ) {
89 $revid = $params[
'revid'];
90 if ( $revid !==
null ) {
91 $rev = $this->revisionStore->getRevisionById( $revid );
93 $this->
dieWithError( [
'apierror-nosuchrevid', $revid ] );
95 $pTitleObj = $titleObj;
96 $titleObj = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
97 if ( $titleProvided && !$titleObj->equals( $pTitleObj ) ) {
98 $this->
addWarning( [
'apierror-revwrongpage', $rev->getId(),
106 $options = ParserOptions::newFromContext( $this->
getContext() );
108 if ( $params[
'includecomments'] ) {
109 $options->setRemoveComments(
false );
113 $suppressCache =
false;
115 $options, $titleObj, $params, $this, $reset, $suppressCache );
119 if ( isset( $prop[
'parsetree'] ) || $params[
'generatexml'] ) {
121 $dom = $this->parser->preprocessToDom( $params[
'text'] );
123 if ( is_callable( [ $dom,
'saveXML' ] ) ) {
125 $xml = $dom->saveXML();
128 $xml = $dom->__toString();
130 if ( isset( $prop[
'parsetree'] ) ) {
131 unset( $prop[
'parsetree'] );
132 $retval[
'parsetree'] = $xml;
135 $result->addValue(
null,
'parsetree', $xml );
136 $result->addValue(
null, ApiResult::META_BC_SUBELEMENTS, [
'parsetree' ] );
142 if ( $prop || $params[
'prop'] ===
null ) {
144 $frame = $this->parser->getPreprocessor()->newFrame();
145 $wikitext = $this->parser->preprocess( $params[
'text'], $titleObj, $options, $revid, $frame );
146 if ( $params[
'prop'] ===
null ) {
148 ApiResult::setContentValue( $retval,
'wikitext', $wikitext );
150 $p_output = $this->parser->getOutput();
151 if ( isset( $prop[
'categories'] ) ) {
152 $categories = $p_output->getCategories();
154 $categories_result = [];
155 foreach ( $categories as $category => $sortkey ) {
157 $entry[
'sortkey'] = $sortkey;
158 ApiResult::setContentValue( $entry,
'category', (
string)$category );
159 $categories_result[] = $entry;
161 ApiResult::setIndexedTagName( $categories_result,
'category' );
162 $retval[
'categories'] = $categories_result;
165 if ( isset( $prop[
'properties'] ) ) {
166 $properties = $p_output->getPageProperties();
168 ApiResult::setArrayType( $properties,
'BCkvp',
'name' );
169 ApiResult::setIndexedTagName( $properties,
'property' );
170 $retval[
'properties'] = $properties;
173 if ( isset( $prop[
'volatile'] ) ) {
174 $retval[
'volatile'] = $frame->isVolatile();
176 if ( isset( $prop[
'ttl'] ) && $frame->getTTL() !==
null ) {
177 $retval[
'ttl'] = $frame->getTTL();
179 if ( isset( $prop[
'wikitext'] ) ) {
180 $retval[
'wikitext'] = $wikitext;
182 if ( isset( $prop[
'modules'] ) ) {
183 $retval[
'modules'] = array_values( array_unique( $p_output->getModules() ) );
185 $retval[
'modulescripts'] = [];
186 $retval[
'modulestyles'] = array_values( array_unique( $p_output->getModuleStyles() ) );
188 if ( isset( $prop[
'jsconfigvars'] ) ) {
189 $showStrategyKeys = (bool)( $params[
'showstrategykeys'] );
190 $retval[
'jsconfigvars'] =
191 ApiResult::addMetadataToResultVars( $p_output->getJsConfigVars( $showStrategyKeys ) );
193 if ( isset( $prop[
'encodedjsconfigvars'] ) ) {
194 $retval[
'encodedjsconfigvars'] = FormatJson::encode(
195 $p_output->getJsConfigVars(),
false, FormatJson::ALL_OK
197 $retval[ApiResult::META_SUBELEMENTS][] =
'encodedjsconfigvars';
199 if ( isset( $prop[
'modules'] ) &&
200 !isset( $prop[
'jsconfigvars'] ) && !isset( $prop[
'encodedjsconfigvars'] ) ) {
201 $this->
addWarning(
'apiwarn-moduleswithoutvars' );
205 ApiResult::setSubelementsList( $retval, [
'wikitext',
'parsetree' ] );
213 ParamValidator::PARAM_TYPE =>
'text',
214 ParamValidator::PARAM_REQUIRED =>
true,
217 ParamValidator::PARAM_TYPE =>
'integer',
220 ParamValidator::PARAM_TYPE => [
228 'encodedjsconfigvars',
231 ParamValidator::PARAM_ISMULTI =>
true,
234 'includecomments' =>
false,
235 'showstrategykeys' =>
false,
237 ParamValidator::PARAM_TYPE =>
'boolean',
238 ParamValidator::PARAM_DEPRECATED =>
true,