Go to the documentation of this file.
36 $this->
getMain()->setCacheMode(
'anon-public-user-private' );
44 $titleProvided =
false;
48 $titleProvided =
true;
51 if ( $params[
'prop'] ===
null ) {
53 [
'apiwarn-deprecation-missingparam',
'prop' ],
'action=expandtemplates&!prop'
57 $prop = array_flip( $params[
'prop'] );
61 if ( !$titleObj || $titleObj->isExternal() ) {
66 $revid = $params[
'revid'];
67 if ( $revid !==
null ) {
68 $rev = MediaWikiServices::getInstance()->getRevisionStore()->getRevisionById( $revid );
70 $this->
dieWithError( [
'apierror-nosuchrevid', $revid ] );
72 $pTitleObj = $titleObj;
74 if ( $titleProvided ) {
75 if ( !$titleObj->equals( $pTitleObj ) ) {
76 $this->
addWarning( [
'apierror-revwrongpage', $rev->getId(),
87 if ( $params[
'includecomments'] ) {
88 $options->setRemoveComments(
false );
92 $suppressCache =
false;
94 [ $options, $titleObj, $params, $this, &$reset, &$suppressCache ] );
98 $parser = MediaWikiServices::getInstance()->getParser();
99 if ( isset( $prop[
'parsetree'] ) || $params[
'generatexml'] ) {
101 $dom = $parser->preprocessToDom( $params[
'text'] );
103 if ( is_callable( [ $dom,
'saveXML' ] ) ) {
105 $xml = $dom->saveXML();
108 $xml = $dom->__toString();
110 if ( isset( $prop[
'parsetree'] ) ) {
111 unset( $prop[
'parsetree'] );
112 $retval[
'parsetree'] = $xml;
115 $result->addValue(
null,
'parsetree', $xml );
122 if ( $prop || $params[
'prop'] ===
null ) {
124 $frame = $parser->getPreprocessor()->newFrame();
125 $wikitext = $parser->preprocess( $params[
'text'], $titleObj, $options, $revid, $frame );
126 if ( $params[
'prop'] ===
null ) {
130 $p_output = $parser->getOutput();
131 if ( isset( $prop[
'categories'] ) ) {
132 $categories = $p_output->getCategories();
134 $categories_result = [];
135 foreach ( $categories as $category => $sortkey ) {
137 $entry[
'sortkey'] = $sortkey;
139 $categories_result[] = $entry;
142 $retval[
'categories'] = $categories_result;
145 if ( isset( $prop[
'properties'] ) ) {
146 $properties = $p_output->getProperties();
150 $retval[
'properties'] = $properties;
153 if ( isset( $prop[
'volatile'] ) ) {
154 $retval[
'volatile'] = $frame->isVolatile();
156 if ( isset( $prop[
'ttl'] ) && $frame->getTTL() !== null ) {
157 $retval[
'ttl'] = $frame->getTTL();
159 if ( isset( $prop[
'wikitext'] ) ) {
160 $retval[
'wikitext'] = $wikitext;
162 if ( isset( $prop[
'modules'] ) ) {
163 $retval[
'modules'] = array_values( array_unique( $p_output->getModules() ) );
165 $retval[
'modulescripts'] = [];
166 $retval[
'modulestyles'] = array_values( array_unique( $p_output->getModuleStyles() ) );
168 if ( isset( $prop[
'jsconfigvars'] ) ) {
169 $retval[
'jsconfigvars'] =
172 if ( isset( $prop[
'encodedjsconfigvars'] ) ) {
178 if ( isset( $prop[
'modules'] ) &&
179 !isset( $prop[
'jsconfigvars'] ) && !isset( $prop[
'encodedjsconfigvars'] ) ) {
180 $this->
addWarning(
'apiwarn-moduleswithoutvars' );
207 'encodedjsconfigvars',
213 'includecomments' =>
false,
223 'action=expandtemplates&text={{Project:Sandbox}}'
224 =>
'apihelp-expandtemplates-example-simple',
229 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Parsing_wikitext#expandtemplates';
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
getContext()
Get the base IContextSource object.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
const PARAM_REQUIRED
(boolean) Is the parameter required?
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
const META_BC_SUBELEMENTS
Key for the 'BC subelements' metadata item.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getResult()
Get the result object.
This abstract class implements many basic API functions, and is the base of all API classes.
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
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.
getHelpUrls()
Return links to more detailed help pages about the module.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
addDeprecation( $msg, $feature, $data=[])
Add a deprecation warning for this module.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
API module that functions as a shortcut to the wikitext preprocessor.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getModuleName()
Get the name of the module being executed by this instance.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
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...
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
static setSubelementsList(array &$arr, $names)
Causes the elements with the specified names to be output as subelements rather than attributes.
getExamplesMessages()
Returns usage examples for this module.