52 parent::__construct( $main, $action );
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 );
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;
97 if ( $titleProvided ) {
98 if ( !$titleObj->equals( $pTitleObj ) ) {
99 $this->
addWarning( [
'apierror-revwrongpage', $rev->getId(),
110 if ( $params[
'includecomments'] ) {
111 $options->setRemoveComments(
false );
115 $suppressCache =
false;
117 $options, $titleObj, $params, $this, $reset, $suppressCache );
121 if ( isset( $prop[
'parsetree'] ) || $params[
'generatexml'] ) {
123 $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 );
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 ) {
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;
160 $categories_result[] = $entry;
163 $retval[
'categories'] = $categories_result;
166 if ( isset( $prop[
'properties'] ) ) {
167 $properties = $p_output->getPageProperties();
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'] =
194 if ( isset( $prop[
'encodedjsconfigvars'] ) ) {
200 if ( isset( $prop[
'modules'] ) &&
201 !isset( $prop[
'jsconfigvars'] ) && !isset( $prop[
'encodedjsconfigvars'] ) ) {
202 $this->
addWarning(
'apiwarn-moduleswithoutvars' );
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,
246 'action=expandtemplates&text={{Project:Sandbox}}'
247 =>
'apihelp-expandtemplates-example-simple',
252 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Parsing_wikitext#expandtemplates';
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
This abstract class implements many basic API functions, and is the base of all API classes.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
getMain()
Get the main module.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
addDeprecation( $msg, $feature, $data=[])
Add a deprecation warning for this module.
requireMaxOneParameter( $params,... $required)
Die if more than one of a certain set of parameters is set and not false.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
getModuleName()
Get the name of the module being executed by this instance.
getHookRunner()
Get an ApiHookRunner for running core API hooks.
API module that functions as a shortcut to the wikitext preprocessor.
getExamplesMessages()
Returns usage examples for this module.
RevisionStore $revisionStore
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
__construct(ApiMain $main, $action, RevisionStore $revisionStore, Parser $parser)
getHelpUrls()
Return links to more detailed help pages about the module.
This is the main API class, used for both external and internal processing.
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
static addMetadataToResultVars( $vars, $forceHash=true)
Add the correct metadata to an array of vars we want to export through the API.
const META_SUBELEMENTS
Key for the 'subelements' metadata item.
static setSubelementsList(array &$arr, $names)
Causes the elements with the specified names to be output as subelements rather than attributes.
const META_BC_SUBELEMENTS
Key for the 'BC subelements' metadata item.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
getContext()
Get the base IContextSource object.
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.