34 $this->
getMain()->setCacheMode(
'anon-public-user-private' );
41 if ( $title ===
null ) {
42 $titleProvided =
false;
46 $titleProvided =
true;
49 if (
$params[
'prop'] ===
null ) {
51 'apiwarn-deprecation-expandtemplates-prop',
'action=expandtemplates&!prop'
55 $prop = array_flip(
$params[
'prop'] );
58 $titleObj = Title::newFromText( $title );
59 if ( !$titleObj || $titleObj->isExternal() ) {
65 if ( $revid !==
null ) {
66 $rev = Revision::newFromId( $revid );
68 $this->
dieWithError( [
'apierror-nosuchrevid', $revid ] );
70 $pTitleObj = $titleObj;
71 $titleObj =
$rev->getTitle();
72 if ( $titleProvided ) {
73 if ( !$titleObj->equals( $pTitleObj ) ) {
80 $titleProvided =
true;
90 if (
$params[
'includecomments'] ) {
91 $options->setRemoveComments(
false );
95 $suppressCache =
false;
96 Hooks::run(
'ApiMakeParserOptions',
101 if ( isset( $prop[
'parsetree'] ) ||
$params[
'generatexml'] ) {
104 if ( is_callable( [ $dom,
'saveXML' ] ) ) {
105 $xml = $dom->saveXML();
107 $xml = $dom->__toString();
109 if ( isset( $prop[
'parsetree'] ) ) {
110 unset( $prop[
'parsetree'] );
114 $result->addValue(
null,
'parsetree', $xml );
121 if ( $prop ||
$params[
'prop'] ===
null ) {
123 $frame =
$wgParser->getPreprocessor()->newFrame();
125 if (
$params[
'prop'] ===
null ) {
130 if ( isset( $prop[
'categories'] ) ) {
131 $categories = $p_output->getCategories();
133 $categories_result = [];
134 foreach ( $categories as $category => $sortkey ) {
136 $entry[
'sortkey'] = $sortkey;
138 $categories_result[] = $entry;
141 $retval[
'categories'] = $categories_result;
144 if ( isset( $prop[
'properties'] ) ) {
145 $properties = $p_output->getProperties();
149 $retval[
'properties'] = $properties;
152 if ( isset( $prop[
'volatile'] ) ) {
153 $retval[
'volatile'] = $frame->isVolatile();
155 if ( isset( $prop[
'ttl'] ) && $frame->getTTL() !==
null ) {
156 $retval[
'ttl'] = $frame->getTTL();
158 if ( isset( $prop[
'wikitext'] ) ) {
159 $retval[
'wikitext'] = $wikitext;
161 if ( isset( $prop[
'modules'] ) ) {
162 $retval[
'modules'] = array_values( array_unique( $p_output->getModules() ) );
163 $retval[
'modulescripts'] = array_values( array_unique( $p_output->getModuleScripts() ) );
164 $retval[
'modulestyles'] = array_values( array_unique( $p_output->getModuleStyles() ) );
166 if ( isset( $prop[
'jsconfigvars'] ) ) {
170 if ( isset( $prop[
'encodedjsconfigvars'] ) ) {
171 $retval[
'encodedjsconfigvars'] = FormatJson::encode(
172 $p_output->getJsConfigVars(),
false, FormatJson::ALL_OK
176 if ( isset( $prop[
'modules'] ) &&
177 !isset( $prop[
'jsconfigvars'] ) && !isset( $prop[
'encodedjsconfigvars'] ) ) {
178 $this->
addWarning(
'apiwarn-moduleswithoutvars' );
205 'encodedjsconfigvars',
211 'includecomments' =>
false,
221 'action=expandtemplates&text={{Project:Sandbox}}'
222 =>
'apihelp-expandtemplates-example-simple',
227 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.
const PARAM_REQUIRED
(boolean) Is the parameter required?
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
getMain()
Get the main module.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
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.
getResult()
Get the result object.
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
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.
API module that functions as a shortcut to the wikitext preprocessor.
getExamplesMessages()
Returns usage examples for this module.
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.
getHelpUrls()
Return links to more detailed help pages about the module.
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.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev