MediaWiki master
|
This is the main API class, used for both external and internal processing. More...
Inherits MediaWiki\Api\ApiBase.
Public Member Functions | ||||||||||
__construct ( $context=null, $enableWrite=false, $internal=null) | ||||||||||
Constructs an instance of ApiMain that utilizes the module and format specified by $request. | ||||||||||
canApiHighLimits () | ||||||||||
Check whether the current user is allowed to use high limits. | ||||||||||
createPrinterByName ( $format) | ||||||||||
Create an instance of an output formatter by its name. | ||||||||||
execute () | ||||||||||
Execute api request. | ||||||||||
getAllowedParams () | ||||||||||
See ApiBase for description. | ||||||||||
getCacheMode () | ||||||||||
getCheck ( $name) | ||||||||||
Get a boolean request value, and register the fact that the parameter was used, for logging. | ||||||||||
getContinuationManager () | ||||||||||
getErrorFormatter () | ||||||||||
Get the ApiErrorFormatter object associated with current request. | ||||||||||
getModule () | ||||||||||
Get the API module object. | ||||||||||
getModuleManager () | ||||||||||
Overrides to return this instance's module manager. | ||||||||||
getParamValidator () | ||||||||||
Get the parameter validator. | ||||||||||
getPrinter () | ||||||||||
Get the result formatter object. | ||||||||||
getResult () | ||||||||||
Get the ApiResult object associated with current request. | ||||||||||
getUpload ( $name) | ||||||||||
Get a request upload, and register the fact that it was used, for logging. | ||||||||||
getUserAgent () | ||||||||||
Fetches the user agent used for this request. | ||||||||||
getVal ( $name, $default=null) | ||||||||||
Get a request value, and register the fact that it was used, for logging. | ||||||||||
isInternalMode () | ||||||||||
Return true if the API was started by other PHP code using MediaWiki\Request\FauxRequest. | ||||||||||
isReadMode () | ||||||||||
lacksSameOriginSecurity () | ||||||||||
Get the security flag for the current request. | ||||||||||
markParamsSensitive ( $params) | ||||||||||
Mark parameters as sensitive. | ||||||||||
markParamsUsed ( $params) | ||||||||||
Mark parameters as used. | ||||||||||
modifyHelp (array &$help, array $options, array &$tocData) | ||||||||||
Called from ApiHelp before the pieces are joined together and returned.This exists mainly for ApiMain to add the Permissions and Credits sections. Other modules probably don't need it.
| ||||||||||
setCacheControl ( $directives) | ||||||||||
Set directives (key/value pairs) for the Cache-Control header. | ||||||||||
setCacheMaxAge ( $maxage) | ||||||||||
Set how long the response should be cached. | ||||||||||
setCacheMode ( $mode) | ||||||||||
Set the type of caching headers which will be sent. | ||||||||||
setContinuationManager (?ApiContinuationManager $manager=null) | ||||||||||
Public Member Functions inherited from MediaWiki\Api\ApiBase | ||||||||||
__construct (ApiMain $mainModule, string $moduleName, string $modulePrefix='') | ||||||||||
getCustomPrinter () | ||||||||||
If the module may only be used with a certain format module, it should override this method to return an instance of that formatter. | ||||||||||
getHelpUrls () | ||||||||||
Return links to more detailed help pages about the module. | ||||||||||
shouldCheckMaxlag () | ||||||||||
Indicates if this module needs maxlag to be checked. | ||||||||||
isWriteMode () | ||||||||||
Indicates whether this module requires write access to the wiki. | ||||||||||
mustBePosted () | ||||||||||
Indicates whether this module must be called with a POST request. | ||||||||||
isDeprecated () | ||||||||||
Indicates whether this module is deprecated. | ||||||||||
isInternal () | ||||||||||
Indicates whether this module is considered to be "internal". | ||||||||||
needsToken () | ||||||||||
Returns the token type this module requires in order to execute. | ||||||||||
getConditionalRequestData ( $condition) | ||||||||||
Returns data for HTTP conditional request mechanisms. | ||||||||||
getModuleName () | ||||||||||
Get the name of the module being executed by this instance. | ||||||||||
getModulePrefix () | ||||||||||
Get parameter prefix (usually two letters or an empty string). | ||||||||||
getMain () | ||||||||||
Get the main module. | ||||||||||
isMain () | ||||||||||
Returns true if this module is the main module ($this === $this->mMainModule), false otherwise. | ||||||||||
getParent () | ||||||||||
Get the parent of this module. | ||||||||||
getModulePath () | ||||||||||
Get the path to this module. | ||||||||||
getModuleFromPath ( $path) | ||||||||||
Get a module from its module path. | ||||||||||
dynamicParameterDocumentation () | ||||||||||
Indicate if the module supports dynamically-determined parameters that cannot be included in self::getAllowedParams(). | ||||||||||
encodeParamName ( $paramName) | ||||||||||
This method mangles parameter name based on the prefix supplied to the constructor. | ||||||||||
extractRequestParams ( $options=[]) | ||||||||||
Using getAllowedParams(), this function makes an array of the values provided by the user, with the key being the name of the variable, and value - validated value from user or default. | ||||||||||
requireOnlyOneParameter ( $params,... $required) | ||||||||||
Die if 0 or more than one of a certain set of parameters is set and not false. | ||||||||||
requireMaxOneParameter ( $params,... $required) | ||||||||||
Dies if more than one parameter from a certain set of parameters are set and not false. | ||||||||||
requireAtLeastOneParameter ( $params,... $required) | ||||||||||
Die if 0 of a certain set of parameters is set and not false. | ||||||||||
requirePostedParameters ( $params, $prefix='prefix') | ||||||||||
Die if any of the specified parameters were found in the query part of the URL rather than the HTTP post body contents. | ||||||||||
getTitleOrPageId ( $params, $load=false) | ||||||||||
Attempts to load a WikiPage object from a title or pageid parameter, if possible. | ||||||||||
getTitleFromTitleOrPageId ( $params) | ||||||||||
Get a Title object from a title or pageid param, if it is possible. | ||||||||||
handleParamNormalization ( $paramName, $value, $rawValue) | ||||||||||
Handle when a parameter was Unicode-normalized. | ||||||||||
validateToken ( $token, array $params) | ||||||||||
Validate the supplied token. | ||||||||||
getWatchlistUser ( $params) | ||||||||||
Gets the user for whom to get the watchlist. | ||||||||||
errorArrayToStatus (array $errors, ?Authority $performer=null) | ||||||||||
Turn an array of messages into a Status. | ||||||||||
addBlockInfoToStatus (StatusValue $status, ?Authority $user=null) | ||||||||||
Add block info to block messages in a Status. | ||||||||||
addWarning ( $msg, $code=null, $data=null) | ||||||||||
Add a warning for this module. | ||||||||||
addDeprecation ( $msg, $feature, $data=[]) | ||||||||||
Add a deprecation warning for this module. | ||||||||||
addError ( $msg, $code=null, $data=null) | ||||||||||
Add an error for this module without aborting. | ||||||||||
addMessagesFromStatus (StatusValue $status, $types=[ 'warning', 'error'], array $filter=[]) | ||||||||||
Add warnings and/or errors from a Status. | ||||||||||
dieWithError ( $msg, $code=null, $data=null, $httpCode=0) | ||||||||||
Abort execution with an error. | ||||||||||
dieWithException (Throwable $exception, array $options=[]) | ||||||||||
Abort execution with an error derived from a throwable. | ||||||||||
dieBlocked (Block $block) | ||||||||||
Throw an ApiUsageException, which will (if uncaught) call the main module's error handler and die with an error message including block info. | ||||||||||
dieStatus (StatusValue $status) | ||||||||||
Throw an ApiUsageException based on the Status object. | ||||||||||
dieReadOnly () | ||||||||||
Helper function for readonly errors. | ||||||||||
checkUserRightsAny ( $rights) | ||||||||||
Helper function for permission-denied errors. | ||||||||||
checkTitleUserPermissions (PageIdentity $pageIdentity, $actions, array $options=[]) | ||||||||||
Helper function for permission-denied errors. | ||||||||||
dieWithErrorOrDebug ( $msg, $code=null, $data=null, $httpCode=null) | ||||||||||
Will only set a warning instead of failing if the global $wgDebugAPI is set to true. | ||||||||||
logFeatureUsage ( $feature) | ||||||||||
Write logging information for API features to a debug log, for usage analysis. | ||||||||||
getFinalSummary () | ||||||||||
Get the final module summary. | ||||||||||
getFinalDescription () | ||||||||||
Get the final module description, after hooks have had a chance to tweak it as needed. | ||||||||||
getFinalParams ( $flags=0) | ||||||||||
Get the final list of parameters, after hooks have had a chance to tweak it as needed. | ||||||||||
getFinalParamDescription () | ||||||||||
Get final parameter descriptions, after hooks have had a chance to tweak it as needed. | ||||||||||
Public Member Functions inherited from MediaWiki\Context\ContextSource | ||||||||||
canUseWikiPage () | ||||||||||
Check whether a WikiPage object can be get with getWikiPage(). | ||||||||||
exportSession () | ||||||||||
Export the resolved user IP, HTTP headers, user ID, and session ID. | ||||||||||
getActionName () | ||||||||||
Get the action name for the current web request. | ||||||||||
getAuthority () | ||||||||||
getConfig () | ||||||||||
getContext () | ||||||||||
Get the base IContextSource object. | ||||||||||
getCsrfTokenSet () | ||||||||||
Get a repository to obtain and match CSRF tokens. | ||||||||||
getLanguage () | ||||||||||
getLanguageCode () | ||||||||||
getOutput () | ||||||||||
getRequest () | ||||||||||
getSkin () | ||||||||||
getTiming () | ||||||||||
getTitle () | ||||||||||
getUser () | ||||||||||
getWikiPage () | ||||||||||
Get the WikiPage object. | ||||||||||
msg ( $key,... $params) | ||||||||||
Get a Message object with context set Parameters are the same as wfMessage() | ||||||||||
setContext (IContextSource $context) | ||||||||||
Static Public Member Functions | |
static | handleApiBeforeMainException (Throwable $e) |
Handle a throwable from the ApiBeforeMain hook. | |
Static Public Member Functions inherited from MediaWiki\Api\ApiBase | |
static | makeMessage ( $msg, IContextSource $context, ?array $params=null) |
Create a Message from a string or array. | |
static | clearCacheForTest () |
Reset static caches of database state. | |
Protected Member Functions | |
addRequestedFields ( $force=[]) | |
Add requested fields to the result. | |
checkAsserts ( $params) | |
Check asserts of the user's rights. | |
checkConditionalRequestHeaders ( $module) | |
Check selected RFC 7232 precondition headers. | |
checkExecutePermissions ( $module) | |
Check for sufficient permissions to execute. | |
checkMaxLag ( $module, $params) | |
Check the max lag if necessary. | |
checkReadOnly ( $module) | |
Check if the DB is read-only for this user. | |
encodeRequestLogValue ( $s) | |
Encode a value in a format suitable for a space-separated log line. | |
errorMessagesFromException (Throwable $e, $type='error') | |
Create an error message for the given throwable. | |
executeAction () | |
Execute the actual module, without any error handling. | |
executeActionWithErrorHandling () | |
Execute an action, and in case of an error, erase whatever partial results have been accumulated, and replace it with an error message and a help screen. | |
getExamplesMessages () | |
Returns usage examples for this module.Return value has query strings as keys, with values being either strings (message key), arrays (message key + parameter), or Message objects.Do not call this base class implementation when overriding this method.
| |
getParamsUsed () | |
Get the request parameters used in the course of the preceding execute() request. | |
getSensitiveParams () | |
Get the request parameters that should be considered sensitive. | |
handleCORS () | |
Check the &origin= query parameter against the Origin: HTTP header and respond appropriately. | |
handleException (Throwable $e) | |
Handle a throwable as an API response. | |
logRequest ( $time, ?Throwable $e=null) | |
Log the preceding request. | |
printResult ( $httpCode=0) | |
Print results using the current printer. | |
reportUnusedParams () | |
Report unused parameters, so the client gets a hint in case it gave us parameters we don't know, for example in case of spelling mistakes or a missing 'g' prefix for generators. | |
sendCacheHeaders ( $isError) | |
Send caching headers. | |
setRequestExpectations (ApiBase $module) | |
Set database connection, query, and write expectations given this module request. | |
setupExecuteAction () | |
Set up for the execution. | |
setupExternalResponse ( $module, $params) | |
Check POST for external response and setup result printer. | |
setupModule () | |
Set up the module for response. | |
substituteResultWithError (Throwable $e) | |
Replace the result data with the information about a throwable. | |
Protected Member Functions inherited from MediaWiki\Api\ApiBase | |
getWebUITokenSalt (array $params) | |
Fetch the salt used in the Web UI corresponding to this module. | |
getDB () | |
Gets a default replica DB connection object. | |
getPermissionManager () | |
Obtain a PermissionManager instance that subclasses may use in their authorization checks. | |
getHookContainer () | |
Get a HookContainer, for running extension hooks or for hook metadata. | |
getHookRunner () | |
Get an ApiHookRunner for running core API hooks. | |
getParameter ( $paramName, $parseLimit=true) | |
Get a value for the given parameter. | |
getParameterFromSettings ( $name, $settings, $parseLimit) | |
Using the settings, determine the value for the given parameter. | |
useTransactionalTimeLimit () | |
Call wfTransactionalTimeLimit() if this request was POSTed. | |
filterIDs ( $fields, array $ids) | |
Filter out-of-range values from a list of positive integer IDs. | |
parseContinueParamOrDie (string $continue, array $types) | |
Parse the 'continue' parameter in the usual format and validate the types of each part, or die with the 'badcontinue' error if the format, types, or the number of parts is wrong. | |
dieContinueUsageIf ( $condition) | |
Die with the 'badcontinue' error. | |
getSummaryMessage () | |
Return the summary message. | |
getExtendedDescription () | |
Return the extended help text message. | |
getHelpFlags () | |
Generates the list of flags for the help screen and for action=paraminfo. | |
getModuleSourceInfo () | |
Returns information about the source of this module, if known. | |
Static Protected Member Functions | |
static | matchRequestedHeaders ( $requestedHeaders, $allowedHeaders) |
Attempt to validate the value of Access-Control-Request-Headers against a list of headers that we allow the follow up request to send. | |
Static Protected Member Functions inherited from MediaWiki\Api\ApiBase | |
static | dieDebug ( $method, $message) |
Internal code errors should be reported with this method. | |
Additional Inherited Members | |
Public Attributes inherited from MediaWiki\Api\ApiBase | |
const | PARAM_RANGE_ENFORCE = 'api-param-range-enforce' |
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE | |
const | PARAM_DFLT = ParamValidator::PARAM_DEFAULT |
const | PARAM_ISMULTI = ParamValidator::PARAM_ISMULTI |
const | PARAM_TYPE = ParamValidator::PARAM_TYPE |
const | PARAM_MAX = IntegerDef::PARAM_MAX |
const | PARAM_MAX2 = IntegerDef::PARAM_MAX2 |
const | PARAM_MIN = IntegerDef::PARAM_MIN |
const | PARAM_ALLOW_DUPLICATES = ParamValidator::PARAM_ALLOW_DUPLICATES |
const | PARAM_DEPRECATED = ParamValidator::PARAM_DEPRECATED |
const | PARAM_REQUIRED = ParamValidator::PARAM_REQUIRED |
const | PARAM_SUBMODULE_MAP = SubmoduleDef::PARAM_SUBMODULE_MAP |
const | PARAM_SUBMODULE_PARAM_PREFIX = SubmoduleDef::PARAM_SUBMODULE_PARAM_PREFIX |
const | PARAM_ALL = ParamValidator::PARAM_ALL |
const | PARAM_EXTRA_NAMESPACES = NamespaceDef::PARAM_EXTRA_NAMESPACES |
const | PARAM_SENSITIVE = ParamValidator::PARAM_SENSITIVE |
const | PARAM_DEPRECATED_VALUES = EnumDef::PARAM_DEPRECATED_VALUES |
const | PARAM_ISMULTI_LIMIT1 = ParamValidator::PARAM_ISMULTI_LIMIT1 |
const | PARAM_ISMULTI_LIMIT2 = ParamValidator::PARAM_ISMULTI_LIMIT2 |
const | PARAM_MAX_BYTES = StringDef::PARAM_MAX_BYTES |
const | PARAM_MAX_CHARS = StringDef::PARAM_MAX_CHARS |
const | PARAM_HELP_MSG = 'api-param-help-msg' |
(string|array|Message) Specify an alternative i18n documentation message for this parameter. | |
const | PARAM_HELP_MSG_APPEND = 'api-param-help-msg-append' |
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this parameter. | |
const | PARAM_HELP_MSG_INFO = 'api-param-help-msg-info' |
(array) Specify additional information tags for the parameter. | |
const | PARAM_VALUE_LINKS = 'api-param-value-links' |
Deprecated and unused. | |
const | PARAM_HELP_MSG_PER_VALUE = 'api-param-help-msg-per-value' |
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI, this is an array mapping parameter values to help messages. | |
const | PARAM_TEMPLATE_VARS = 'param-template-vars' |
(array) Indicate that this is a templated parameter, and specify replacements. | |
const | ALL_DEFAULT_STRING = '*' |
(string|array|Message) Specify an alternative i18n documentation message for this parameter. | |
const | LIMIT_BIG1 = 500 |
Fast query, standard limit. | |
const | LIMIT_BIG2 = 5000 |
Fast query, apihighlimits limit. | |
const | LIMIT_SML1 = 50 |
Slow query, standard limit. | |
const | LIMIT_SML2 = 500 |
Slow query, apihighlimits limit. | |
const | GET_VALUES_FOR_HELP = 1 |
getAllowedParams() flag: When this is set, the result could take longer to generate, but should be more thorough. | |
This is the main API class, used for both external and internal processing.
When executed, it will create the requested formatter object, instantiate and execute an object associated with the needed action, and use formatter to print results. In case of an exception, an error message will be printed using the same formatter.
To use API from another application, run it using MediaWiki\Request\FauxRequest object, in which case any internal exceptions will not be handled but passed up to the caller. After successful execution, use getResult() for the resulting data.
Definition at line 78 of file ApiMain.php.
MediaWiki\Api\ApiMain::__construct | ( | $context = null, | |
$enableWrite = false, | |||
$internal = null ) |
Constructs an instance of ApiMain that utilizes the module and format specified by $request.
IContextSource | WebRequest | null | $context | If this is an instance of MediaWiki\Request\FauxRequest, errors are thrown and no printing occurs |
bool | $enableWrite | Should be set to true if the api may modify data |
bool | null | $internal | Whether the API request is an internal faux request. If null or not given, the request is assumed to be internal if $context contains a FauxRequest. |
Definition at line 590 of file ApiMain.php.
References $wgLang, MediaWiki\MainConfigNames\APIFormatModules, MediaWiki\MainConfigNames\APIMaxResultSize, MediaWiki\MainConfigNames\APIModules, MediaWiki\Context\ContextSource\getConfig(), MediaWiki\Api\ApiMain\getErrorFormatter(), MediaWiki\Api\ApiBase\getHookRunner(), MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Context\ContextSource\getLanguage(), MediaWiki\Api\getRequest(), MediaWiki\Api\ApiMain\lacksSameOriginSecurity(), MediaWiki\Context\ContextSource\setContext(), MediaWiki\StubObject\StubGlobalUser\setUser(), and wfDebug().
|
protected |
Add requested fields to the result.
string[] | $force | Which fields to force even if not requested. Accepted values are:
|
Definition at line 1489 of file ApiMain.php.
References MediaWiki\Api\ApiResult\NO_SIZE_CHECK, MediaWiki\MainConfigNames\ShowHostnames, wfHostname(), and wfTimestamp().
MediaWiki\Api\ApiMain::canApiHighLimits | ( | ) |
Check whether the current user is allowed to use high limits.
Definition at line 2453 of file ApiMain.php.
References MediaWiki\Api\getAuthority().
|
protected |
Check asserts of the user's rights.
array | $params |
Definition at line 1859 of file ApiMain.php.
References $params, MediaWiki\Api\getAuthority(), MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Api\getUser(), and wfEscapeWikiText().
|
protected |
Check selected RFC 7232 precondition headers.
RFC 7232 envisions a particular model where you send your request to "a resource", and for write requests that you can read "the resource" by changing the method to GET. When the API receives a GET request, it works out even though "the resource" from RFC 7232's perspective might be many resources from MediaWiki's perspective. But it totally fails for a POST, since what HTTP sees as "the resource" is probably just "/api.php" with all the interesting bits in the body.
Therefore, we only support RFC 7232 precondition headers for GET (and HEAD). That means we don't need to bother with If-Match and If-Unmodified-Since since they only apply to modification requests.
And since we don't support Range, If-Range is ignored too.
ApiBase | $module | Api module being used |
Definition at line 1672 of file ApiMain.php.
References MediaWiki\MainConfigNames\CacheEpoch, MediaWiki\MainConfigNames\CdnMaxAge, MediaWiki\Api\getRequest(), MediaWiki\Api\getUser(), MediaWiki\MainConfigNames\UseCdn, wfResetOutputBuffers(), and wfTimestamp().
|
protected |
Check for sufficient permissions to execute.
ApiBase | $module | An Api module |
Definition at line 1774 of file ApiMain.php.
References MediaWiki\Api\getRequest(), and MediaWiki\Api\getUser().
|
protected |
Check the max lag if necessary.
ApiBase | $module | Api module being used |
array | $params | Array an array containing the request parameters. |
Definition at line 1626 of file ApiMain.php.
References $params, MediaWiki\Api\getRequest(), and MediaWiki\MainConfigNames\ShowHostnames.
|
protected |
Check if the DB is read-only for this user.
ApiBase | $module | An Api module |
Definition at line 1804 of file ApiMain.php.
References MediaWiki\MediaWikiServices\getInstance().
MediaWiki\Api\ApiMain::createPrinterByName | ( | $format | ) |
Create an instance of an output formatter by its name.
string | $format |
Definition at line 895 of file ApiMain.php.
References wfEscapeWikiText().
Referenced by MediaWiki\Api\ApiFormatRaw\__construct().
|
protected |
Encode a value in a format suitable for a space-separated log line.
string | $s |
Definition at line 2100 of file ApiMain.php.
|
protected |
Create an error message for the given throwable.
If an ApiUsageException, errors/warnings will be extracted from the embedded StatusValue.
Any other throwable will be returned with a generic code and wrapper text around the throwable's (presumably English) message as a single error (no warnings).
Throwable | $e | |
string | $type | 'error' or 'warning' |
Definition at line 1369 of file ApiMain.php.
References $params, MediaWiki\Api\ApiMessage\create(), MediaWiki\Message\Message\newFromSpecifier(), and wfEscapeWikiText().
MediaWiki\Api\ApiMain::execute | ( | ) |
Execute api request.
Any errors will be handled if the API was called by the remote client.
Reimplemented from MediaWiki\Api\ApiBase.
Definition at line 910 of file ApiMain.php.
Referenced by MediaWiki\Rest\Handler\ActionModuleBasedHandler\execute().
|
protected |
Execute the actual module, without any error handling.
Definition at line 1946 of file ApiMain.php.
References $params, MediaWiki\Debug\MWDebug\appendDebugInfoToApiResult(), MediaWiki\Api\getContext(), MW_ENTRY_POINT, and MediaWiki\Profiler\ProfilingContext\singleton().
|
protected |
Execute an action, and in case of an error, erase whatever partial results have been accumulated, and replace it with an error message and a help screen.
Definition at line 922 of file ApiMain.php.
References MediaWiki\Api\getContext(), and MediaWiki\Api\getRequest().
MediaWiki\Api\ApiMain::getAllowedParams | ( | ) |
See ApiBase for description.
Reimplemented from MediaWiki\Api\ApiBase.
Definition at line 2254 of file ApiMain.php.
References MediaWiki\Api\ApiBase\PARAM_HELP_MSG_PER_VALUE.
MediaWiki\Api\ApiMain::getCacheMode | ( | ) |
Definition at line 870 of file ApiMain.php.
MediaWiki\Api\ApiMain::getCheck | ( | $name | ) |
Get a boolean request value, and register the fact that the parameter was used, for logging.
string | $name |
Definition at line 2178 of file ApiMain.php.
References MediaWiki\Api\getRequest().
MediaWiki\Api\ApiMain::getContinuationManager | ( | ) |
Reimplemented from MediaWiki\Api\ApiBase.
Definition at line 759 of file ApiMain.php.
MediaWiki\Api\ApiMain::getErrorFormatter | ( | ) |
Get the ApiErrorFormatter object associated with current request.
Reimplemented from MediaWiki\Api\ApiBase.
Definition at line 752 of file ApiMain.php.
Referenced by MediaWiki\Api\ApiMain\__construct().
|
protected |
Returns usage examples for this module.Return value has query strings as keys, with values being either strings (message key), arrays (message key + parameter), or Message objects.Do not call this base class implementation when overriding this method.
Reimplemented from MediaWiki\Api\ApiBase.
Definition at line 2308 of file ApiMain.php.
MediaWiki\Api\ApiMain::getModule | ( | ) |
Get the API module object.
Only works after executeAction()
Definition at line 789 of file ApiMain.php.
MediaWiki\Api\ApiMain::getModuleManager | ( | ) |
Overrides to return this instance's module manager.
Reimplemented from MediaWiki\Api\ApiBase.
Definition at line 2465 of file ApiMain.php.
|
protected |
Get the request parameters used in the course of the preceding execute() request.
Definition at line 2117 of file ApiMain.php.
MediaWiki\Api\ApiMain::getParamValidator | ( | ) |
MediaWiki\Api\ApiMain::getPrinter | ( | ) |
Get the result formatter object.
Only works after setupExecuteAction()
Definition at line 798 of file ApiMain.php.
MediaWiki\Api\ApiMain::getResult | ( | ) |
Get the ApiResult object associated with current request.
Reimplemented from MediaWiki\Api\ApiBase.
Definition at line 715 of file ApiMain.php.
Referenced by MediaWiki\Rest\Handler\ActionModuleBasedHandler\execute().
|
protected |
Get the request parameters that should be considered sensitive.
Definition at line 2134 of file ApiMain.php.
MediaWiki\Api\ApiMain::getUpload | ( | $name | ) |
Get a request upload, and register the fact that it was used, for logging.
string | $name | Parameter name |
Definition at line 2190 of file ApiMain.php.
References MediaWiki\Api\getRequest().
MediaWiki\Api\ApiMain::getUserAgent | ( | ) |
Fetches the user agent used for this request.
This returns the value of the 'Api-User-Agent' header, if any, or the standard User-Agent header, otherwise.
Definition at line 2477 of file ApiMain.php.
References MediaWiki\Api\getRequest().
MediaWiki\Api\ApiMain::getVal | ( | $name, | |
$default = null ) |
Get a request value, and register the fact that it was used, for logging.
string | $name | |
string | null | $default |
Definition at line 2157 of file ApiMain.php.
References MediaWiki\Api\getRequest().
|
static |
Handle a throwable from the ApiBeforeMain hook.
This tries to print the throwable as an API response, to be more friendly to clients. If it fails, it will rethrow the throwable.
Throwable | $e |
Throwable |
Definition at line 1065 of file ApiMain.php.
Referenced by MediaWiki\Api\ApiEntryPoint\execute().
|
protected |
Check the &origin= query parameter against the Origin: HTTP header and respond appropriately.
If no origin parameter is present, nothing happens. If an origin parameter is present but doesn't match the Origin header, a 403 status code is set and false is returned. If the parameter and the header do match, the header is checked against $wgCrossSiteAJAXdomains and $wgCrossSiteAJAXdomainExceptions, and if the origin qualifies, the appropriate CORS headers are set. https://www.w3.org/TR/cors/#resource-requests https://www.w3.org/TR/cors/#resource-preflight-requests
Definition at line 1097 of file ApiMain.php.
References MediaWiki\MainConfigNames\AllowedCorsHeaders, MediaWiki\MainConfigNames\CrossSiteAJAXdomainExceptions, MediaWiki\MainConfigNames\CrossSiteAJAXdomains, MediaWiki\Api\getRequest(), and MediaWiki\Rest\HeaderParser\Origin\parseHeaderList().
|
protected |
Handle a throwable as an API response.
Throwable | $e |
Definition at line 990 of file ApiMain.php.
References MediaWiki\Api\getRequest(), and MediaWiki\Api\ApiUsageException\getStatusValue().
MediaWiki\Api\ApiMain::isInternalMode | ( | ) |
Return true if the API was started by other PHP code using MediaWiki\Request\FauxRequest.
Definition at line 706 of file ApiMain.php.
MediaWiki\Api\ApiMain::isReadMode | ( | ) |
MediaWiki\Api\ApiMain::lacksSameOriginSecurity | ( | ) |
Get the security flag for the current request.
Reimplemented from MediaWiki\Api\ApiBase.
Definition at line 723 of file ApiMain.php.
References MediaWiki\Api\ApiBase\getHookRunner(), MediaWiki\Api\getRequest(), and MediaWiki\Api\ApiMain\lacksSameOriginSecurity().
Referenced by MediaWiki\Api\ApiMain\__construct(), and MediaWiki\Api\ApiMain\lacksSameOriginSecurity().
|
protected |
Log the preceding request.
float | $time | Time in seconds |
Throwable | null | $e | Throwable caught while processing the request |
Definition at line 2013 of file ApiMain.php.
References $header, MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Api\getRequest(), MediaWiki\Api\getUser(), MediaWiki\MainConfigNames\ServerName, wfDebugLog(), wfTimestamp(), and wfUrlencode().
MediaWiki\Api\ApiMain::markParamsSensitive | ( | $params | ) |
Mark parameters as sensitive.
This is called automatically for you when declaring a parameter with ApiBase::PARAM_SENSITIVE.
string | string[] | $params |
Definition at line 2147 of file ApiMain.php.
References $params.
MediaWiki\Api\ApiMain::markParamsUsed | ( | $params | ) |
Mark parameters as used.
string | string[] | $params |
Definition at line 2125 of file ApiMain.php.
References $params.
|
staticprotected |
Attempt to validate the value of Access-Control-Request-Headers against a list of headers that we allow the follow up request to send.
string | $requestedHeaders | Comma separated list of HTTP headers |
string[] | $allowedHeaders | List of allowed HTTP headers |
Definition at line 1205 of file ApiMain.php.
MediaWiki\Api\ApiMain::modifyHelp | ( | array & | $help, |
array | $options, | ||
array & | $tocData ) |
Called from ApiHelp before the pieces are joined together and returned.This exists mainly for ApiMain to add the Permissions and Credits sections. Other modules probably don't need it.
string[] | &$help | Array of help data |
array | $options | Options passed to ApiHelp::getHelp |
array | &$tocData | If a TOC is being generated, this array has keys as anchors in the page and values as for SectionMetadata::fromLegacy(). |
Reimplemented from MediaWiki\Api\ApiBase.
Definition at line 2321 of file ApiMain.php.
References $header, MediaWiki\Html\element(), MediaWiki\MediaWikiServices\getInstance(), and MediaWiki\Message\Message\listParam().
|
protected |
Print results using the current printer.
int | $httpCode | HTTP status code, or 0 to not change |
Definition at line 2228 of file ApiMain.php.
References MediaWiki\MainConfigNames\DebugAPI.
|
protected |
Report unused parameters, so the client gets a hint in case it gave us parameters we don't know, for example in case of spelling mistakes or a missing 'g' prefix for generators.
Definition at line 2200 of file ApiMain.php.
References MediaWiki\Api\getRequest(), and MediaWiki\Message\Message\listParam().
|
protected |
Send caching headers.
bool | $isError | Whether an error response is being output |
Definition at line 1231 of file ApiMain.php.
References MediaWiki\Api\getRequest(), MediaWiki\MainConfigNames\VaryOnXFP, and wfTimestamp().
MediaWiki\Api\ApiMain::setCacheControl | ( | $directives | ) |
Set directives (key/value pairs) for the Cache-Control header.
Boolean values will be formatted as such, by including or omitting without an equals sign.
Cache control values set here will only be used if the cache mode is not private, see setCacheMode().
array | $directives |
Definition at line 884 of file ApiMain.php.
MediaWiki\Api\ApiMain::setCacheMaxAge | ( | $maxage | ) |
Set how long the response should be cached.
int | $maxage |
Definition at line 807 of file ApiMain.php.
MediaWiki\Api\ApiMain::setCacheMode | ( | $mode | ) |
Set the type of caching headers which will be sent.
string | $mode | One of:
|
If the wiki does not allow anonymous users to read it, the mode set here will be ignored, and private caching headers will always be sent. In other words, the "public" mode is equivalent to saying that the data sent is as public as a page view.
For user-dependent data, the private mode should generally be used. The anon-public-user-private mode should only be used where there is a particularly good performance reason for caching the anonymous response, but where the response to logged-in users may differ, or may contain private data.
If this function is never called, then the default will be the private mode.
Definition at line 839 of file ApiMain.php.
References wfDebug().
MediaWiki\Api\ApiMain::setContinuationManager | ( | ?ApiContinuationManager | $manager = null | ) |
ApiContinuationManager | null | $manager |
Reimplemented from MediaWiki\Api\ApiBase.
Definition at line 766 of file ApiMain.php.
|
protected |
Set database connection, query, and write expectations given this module request.
ApiBase | $module |
Definition at line 1991 of file ApiMain.php.
References MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Api\getRequest(), Profiler\instance(), MediaWiki\Api\ApiBase\isWriteMode(), and MediaWiki\MainConfigNames\TrxProfilerLimits.
|
protected |
Set up for the execution.
Definition at line 1527 of file ApiMain.php.
References $params.
|
protected |
Check POST for external response and setup result printer.
ApiBase | $module | An Api module |
array | $params | An array with the request parameters |
Definition at line 1897 of file ApiMain.php.
References $params, MediaWiki\MainConfigNames\ForceHTTPS, MediaWiki\Api\getRequest(), MediaWiki\Message\Message\sizeParam(), and wfShorthandToInteger().
|
protected |
Set up the module for response.
ApiUsageException |
Definition at line 1541 of file ApiMain.php.
References wfEscapeWikiText().
|
protected |
Replace the result data with the information about a throwable.
Throwable | $e |
Definition at line 1405 of file ApiMain.php.
References $path, MediaWiki\MediaWikiServices\getInstance(), MediaWiki\Api\ApiErrorFormatter\isValidApiCode(), MediaWiki\Api\ApiResult\NO_SIZE_CHECK, MediaWiki\MainConfigNames\ShowExceptionDetails, and wfScript().