MediaWiki
master
|
This is the main API class, used for both external and internal processing. More...
Public Member Functions | ||||||||||
__construct ( $context=null, $enableWrite=false) | ||||||||||
Constructs an instance of ApiMain that utilizes the module and format specified by $request. More... | ||||||||||
canApiHighLimits () | ||||||||||
Check whether the current user is allowed to use high limits. More... | ||||||||||
createPrinterByName ( $format) | ||||||||||
Create an instance of an output formatter by its name. More... | ||||||||||
execute () | ||||||||||
Execute api request. More... | ||||||||||
getAllowedParams () | ||||||||||
See ApiBase for description. More... | ||||||||||
getCheck ( $name) | ||||||||||
Get a boolean request value, and register the fact that the parameter was used, for logging. More... | ||||||||||
getContinuationManager () | ||||||||||
getErrorFormatter () | ||||||||||
Get the ApiErrorFormatter object associated with current request. More... | ||||||||||
getModule () | ||||||||||
Get the API module object. More... | ||||||||||
getModuleManager () | ||||||||||
Overrides to return this instance's module manager. More... | ||||||||||
getParamValidator () | ||||||||||
Get the parameter validator. More... | ||||||||||
getPrinter () | ||||||||||
Get the result formatter object. More... | ||||||||||
getResult () | ||||||||||
Get the ApiResult object associated with current request. More... | ||||||||||
getUpload ( $name) | ||||||||||
Get a request upload, and register the fact that it was used, for logging. More... | ||||||||||
getUserAgent () | ||||||||||
Fetches the user agent used for this request. More... | ||||||||||
getVal ( $name, $default=null) | ||||||||||
Get a request value, and register the fact that it was used, for logging. More... | ||||||||||
isInternalMode () | ||||||||||
Return true if the API was started by other PHP code using FauxRequest. More... | ||||||||||
isReadMode () | ||||||||||
lacksSameOriginSecurity () | ||||||||||
Get the security flag for the current request. More... | ||||||||||
markParamsSensitive ( $params) | ||||||||||
Mark parameters as sensitive. More... | ||||||||||
markParamsUsed ( $params) | ||||||||||
Mark parameters as used. More... | ||||||||||
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.Stable to override
| ||||||||||
setCacheControl ( $directives) | ||||||||||
Set directives (key/value pairs) for the Cache-Control header. More... | ||||||||||
setCacheMaxAge ( $maxage) | ||||||||||
Set how long the response should be cached. More... | ||||||||||
setCacheMode ( $mode) | ||||||||||
Set the type of caching headers which will be sent. More... | ||||||||||
setContinuationManager (ApiContinuationManager $manager=null) | ||||||||||
![]() | ||||||||||
__construct (ApiMain $mainModule, $moduleName, $modulePrefix='') | ||||||||||
Stable to call. More... | ||||||||||
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. More... | ||||||||||
getHelpUrls () | ||||||||||
Return links to more detailed help pages about the module. More... | ||||||||||
shouldCheckMaxlag () | ||||||||||
Indicates if this module needs maxlag to be checked Stable to override. More... | ||||||||||
isWriteMode () | ||||||||||
Indicates whether this module requires write mode. More... | ||||||||||
mustBePosted () | ||||||||||
Indicates whether this module must be called with a POST request Stable to override. More... | ||||||||||
isDeprecated () | ||||||||||
Indicates whether this module is deprecated. More... | ||||||||||
isInternal () | ||||||||||
Indicates whether this module is "internal" Internal API modules are not (yet) intended for 3rd party use and may be unstable. More... | ||||||||||
needsToken () | ||||||||||
Returns the token type this module requires in order to execute. More... | ||||||||||
getConditionalRequestData ( $condition) | ||||||||||
Returns data for HTTP conditional request mechanisms. More... | ||||||||||
getModuleName () | ||||||||||
Get the name of the module being executed by this instance. More... | ||||||||||
getModulePrefix () | ||||||||||
Get parameter prefix (usually two letters or an empty string). More... | ||||||||||
getMain () | ||||||||||
Get the main module. More... | ||||||||||
isMain () | ||||||||||
Returns true if this module is the main module ($this === $this->mMainModule), false otherwise. More... | ||||||||||
getParent () | ||||||||||
Get the parent of this module Stable to override. More... | ||||||||||
getModulePath () | ||||||||||
Get the path to this module. More... | ||||||||||
getModuleFromPath ( $path) | ||||||||||
Get a module from its module path. More... | ||||||||||
dynamicParameterDocumentation () | ||||||||||
Indicate if the module supports dynamically-determined parameters that cannot be included in self::getAllowedParams(). More... | ||||||||||
encodeParamName ( $paramName) | ||||||||||
This method mangles parameter name based on the prefix supplied to the constructor. More... | ||||||||||
extractRequestParams ( $options=[]) | ||||||||||
Using getAllowedParams(), this function makes an array of the values provided by the user, with key being the name of the variable, and value - validated value from user or default. More... | ||||||||||
requireOnlyOneParameter ( $params,... $required) | ||||||||||
Die if none or more than one of a certain set of parameters is set and not false. More... | ||||||||||
requireMaxOneParameter ( $params,... $required) | ||||||||||
Die if more than one of a certain set of parameters is set and not false. More... | ||||||||||
requireAtLeastOneParameter ( $params,... $required) | ||||||||||
Die if none of a certain set of parameters is set and not false. More... | ||||||||||
requirePostedParameters ( $params, $prefix='prefix') | ||||||||||
Die if any of the specified parameters were found in the query part of the URL rather than the post body. More... | ||||||||||
getTitleOrPageId ( $params, $load=false) | ||||||||||
Get a WikiPage object from a title or pageid param, if possible. More... | ||||||||||
getTitleFromTitleOrPageId ( $params) | ||||||||||
Get a Title object from a title or pageid param, if possible. More... | ||||||||||
handleParamNormalization ( $paramName, $value, $rawValue) | ||||||||||
Handle when a parameter was Unicode-normalized. More... | ||||||||||
validateToken ( $token, array $params) | ||||||||||
Validate the supplied token. More... | ||||||||||
getWatchlistUser ( $params) | ||||||||||
Gets the user for whom to get the watchlist. More... | ||||||||||
errorArrayToStatus (array $errors, User $user=null) | ||||||||||
Turn an array of message keys or key+param arrays into a Status. More... | ||||||||||
addBlockInfoToStatus (StatusValue $status, User $user=null) | ||||||||||
Add block info to block messages in a Status. More... | ||||||||||
addWarning ( $msg, $code=null, $data=null) | ||||||||||
Add a warning for this module. More... | ||||||||||
addDeprecation ( $msg, $feature, $data=[]) | ||||||||||
Add a deprecation warning for this module. More... | ||||||||||
addError ( $msg, $code=null, $data=null) | ||||||||||
Add an error for this module without aborting. More... | ||||||||||
addMessagesFromStatus (StatusValue $status, $types=[ 'warning', 'error'], array $filter=[]) | ||||||||||
Add warnings and/or errors from a Status. More... | ||||||||||
dieWithError ( $msg, $code=null, $data=null, $httpCode=null) | ||||||||||
Abort execution with an error. More... | ||||||||||
dieWithException (Throwable $exception, array $options=[]) | ||||||||||
Abort execution with an error derived from a throwable. More... | ||||||||||
dieBlocked (AbstractBlock $block) | ||||||||||
Throw an ApiUsageException, which will (if uncaught) call the main module's error handler and die with an error message including block info. More... | ||||||||||
dieStatus (StatusValue $status) | ||||||||||
Throw an ApiUsageException based on the Status object. More... | ||||||||||
dieReadOnly () | ||||||||||
Helper function for readonly errors. More... | ||||||||||
checkUserRightsAny ( $rights, $user=null) | ||||||||||
Helper function for permission-denied errors. More... | ||||||||||
checkTitleUserPermissions (LinkTarget $linkTarget, $actions, array $options=[]) | ||||||||||
Helper function for permission-denied errors. More... | ||||||||||
dieWithErrorOrDebug ( $msg, $code=null, $data=null, $httpCode=null) | ||||||||||
Will only set a warning instead of failing if the global $wgDebugAPI is set to true. More... | ||||||||||
logFeatureUsage ( $feature) | ||||||||||
Write logging information for API features to a debug log, for usage analysis. More... | ||||||||||
getFinalSummary () | ||||||||||
Get final module summary. More... | ||||||||||
getFinalDescription () | ||||||||||
Get final module description, after hooks have had a chance to tweak it as needed. More... | ||||||||||
getFinalParams ( $flags=0) | ||||||||||
Get final list of parameters, after hooks have had a chance to tweak it as needed. More... | ||||||||||
getFinalParamDescription () | ||||||||||
Get final parameter descriptions, after hooks have had a chance to tweak it as needed. More... | ||||||||||
![]() | ||||||||||
canUseWikiPage () | ||||||||||
Check whether a WikiPage object can be get with getWikiPage(). More... | ||||||||||
exportSession () | ||||||||||
Export the resolved user IP, HTTP headers, user ID, and session ID. More... | ||||||||||
getConfig () | ||||||||||
getContext () | ||||||||||
Get the base IContextSource object. More... | ||||||||||
getLanguage () | ||||||||||
getOutput () | ||||||||||
getRequest () | ||||||||||
getSkin () | ||||||||||
getStats () | ||||||||||
getTiming () | ||||||||||
getTitle () | ||||||||||
getUser () | ||||||||||
Stable to override. More... | ||||||||||
getWikiPage () | ||||||||||
Get the WikiPage object. More... | ||||||||||
msg ( $key,... $params) | ||||||||||
Get a Message object with context set Parameters are the same as wfMessage() More... | ||||||||||
setContext (IContextSource $context) | ||||||||||
Static Public Member Functions | |
static | handleApiBeforeMainException (Throwable $e) |
Handle a throwable from the ApiBeforeMain hook. More... | |
![]() | |
static | makeMessage ( $msg, IContextSource $context, array $params=null) |
Create a Message from a string or array. More... | |
Public Attributes | |
$mCdnMaxAge | |
$mErrorFormatter = null | |
$mParamValidator | |
$mResult | |
![]() | |
const | PARAM_RANGE_ENFORCE = 'api-param-range-enforce' |
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE More... | |
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. More... | |
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. More... | |
const | PARAM_HELP_MSG_INFO = 'api-param-help-msg-info' |
(array) Specify additional information tags for the parameter. More... | |
const | PARAM_VALUE_LINKS = 'api-param-value-links' |
Deprecated and unused. More... | |
const | PARAM_HELP_MSG_PER_VALUE = 'api-param-help-msg-per-value' |
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg for ApiBase::makeMessage(). More... | |
const | PARAM_TEMPLATE_VARS = 'param-template-vars' |
(array) Indicate that this is a templated parameter, and specify replacements. More... | |
const | ALL_DEFAULT_STRING = '*' |
(string|array|Message) Specify an alternative i18n documentation message for this parameter. More... | |
const | LIMIT_BIG1 = 500 |
Fast query, standard limit. More... | |
const | LIMIT_BIG2 = 5000 |
Fast query, apihighlimits limit. More... | |
const | LIMIT_SML1 = 50 |
Slow query, standard limit. More... | |
const | LIMIT_SML2 = 500 |
Slow query, apihighlimits limit. More... | |
const | GET_VALUES_FOR_HELP = 1 |
getAllowedParams() flag: When set, the result could take longer to generate, but should be more thorough. More... | |
string | $mModulePrefix |
(string|array|Message) Specify an alternative i18n documentation message for this parameter. More... | |
Protected Member Functions | |
addRequestedFields ( $force=[]) | |
Add requested fields to the result. More... | |
checkAsserts ( $params) | |
Check asserts of the user's rights. More... | |
checkConditionalRequestHeaders ( $module) | |
Check selected RFC 7232 precondition headers. More... | |
checkExecutePermissions ( $module) | |
Check for sufficient permissions to execute. More... | |
checkMaxLag ( $module, $params) | |
Check the max lag if necessary. More... | |
checkReadOnly ( $module) | |
Check if the DB is read-only for this user. More... | |
encodeRequestLogValue ( $s) | |
Encode a value in a format suitable for a space-separated log line. More... | |
errorMessagesFromException (Throwable $e, $type='error') | |
Create an error message for the given throwable. More... | |
executeAction () | |
Execute the actual module, without any error handling. More... | |
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. More... | |
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. More... | |
getSensitiveParams () | |
Get the request parameters that should be considered sensitive. More... | |
handleCORS () | |
Check the &origin= query parameter against the Origin: HTTP header and respond appropriately. More... | |
handleException (Throwable $e) | |
Handle a throwable as an API response. More... | |
logRequest ( $time, Throwable $e=null) | |
Log the preceding request. More... | |
printResult ( $httpCode=0) | |
Print results using the current printer. More... | |
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. More... | |
sendCacheHeaders ( $isError) | |
Send caching headers. More... | |
setRequestExpectations (ApiBase $module) | |
Set database connection, query, and write expectations given this module request. More... | |
setupExecuteAction () | |
Set up for the execution. More... | |
setupExternalResponse ( $module, $params) | |
Check POST for external response and setup result printer. More... | |
setupModule () | |
Set up the module for response. More... | |
substituteResultWithError (Throwable $e) | |
Replace the result data with the information about a throwable. More... | |
![]() | |
explodeMultiValue ( $value, $limit) | |
Split a multi-valued parameter string, like explode() More... | |
parseMultiValue ( $valueName, $value, $allowMultiple, $allowedValues, $allSpecifier=null, $limit1=null, $limit2=null) | |
Return an array of values that were given in a 'a|b|c' notation, after it optionally validates them against the list allowed values. More... | |
validateLimit ( $name, &$value, $min, $max, $botMax=null, $enforceLimits=false) | |
Validate the value against the minimum and user/bot maximum limits. More... | |
validateTimestamp ( $value, $encParamName) | |
Validate and normalize parameters of type 'timestamp'. More... | |
getWebUITokenSalt (array $params) | |
Fetch the salt used in the Web UI corresponding to this module. More... | |
getDB () | |
Gets a default replica DB connection object Stable to override. More... | |
getPermissionManager () | |
Obtain a PermissionManager instance that subclasses may use in their authorization checks. More... | |
getHookContainer () | |
Get a HookContainer, for running extension hooks or for hook metadata. More... | |
getHookRunner () | |
Get an ApiHookRunner for running core API hooks. More... | |
getParameter ( $paramName, $parseLimit=true) | |
Get a value for the given parameter. More... | |
getParameterFromSettings ( $name, $settings, $parseLimit) | |
Using the settings determine the value for the given parameter. More... | |
useTransactionalTimeLimit () | |
Call wfTransactionalTimeLimit() if this request was POSTed. More... | |
filterIDs ( $fields, array $ids) | |
Filter out-of-range values from a list of positive integer IDs. More... | |
dieContinueUsageIf ( $condition) | |
Die with the 'badcontinue' error. More... | |
getSummaryMessage () | |
Return the summary message. More... | |
getExtendedDescription () | |
Return the extended help text message. More... | |
getHelpFlags () | |
Generates the list of flags for the help screen and for action=paraminfo. More... | |
getModuleSourceInfo () | |
Returns information about the source of this module, if known. More... | |
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. More... | |
![]() | |
static | dieDebug ( $method, $message) |
Internal code errors should be reported with this method. More... | |
Private Member Functions | |
checkBotReadOnly () | |
Check whether we are readonly for bots. More... | |
createErrorPrinter () | |
Create the printer for error output. More... | |
getMaxLag () | |
Private Attributes | |
bool null | $lacksSameOriginSecurity = null |
Cached return value from self::lacksSameOriginSecurity() More... | |
$mAction | |
array | $mCacheControl = [] |
$mCacheMode = 'private' | |
$mCanApiHighLimits = null | |
ApiContinuationManager null | $mContinuationManager |
$mEnableWrite | |
$mInternalMode | |
ApiBase | $mModule |
$mModuleMgr | |
$mParamsSensitive = [] | |
$mParamsUsed = [] | |
ApiFormatBase | $mPrinter |
const | API_DEFAULT_FORMAT = 'jsonfm' |
When no format parameter is given, this format will be used. More... | |
const | API_DEFAULT_USELANG = 'user' |
When no uselang parameter is given, this language will be used. More... | |
const | FORMATS |
List of available formats: format name => format class. More... | |
const | MODULES |
List of available modules: action name => module class. More... | |
const | RIGHTS_MAP |
List of user roles that are specifically relevant to the API. More... | |
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 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.
@newable
Definition at line 48 of file ApiMain.php.
ApiMain::__construct | ( | $context = null , |
|
$enableWrite = false |
|||
) |
Constructs an instance of ApiMain that utilizes the module and format specified by $request.
Stable to call
IContextSource | WebRequest | null | $context | If this is an instance of FauxRequest, errors are thrown and no printing occurs |
bool | $enableWrite | Should be set to true if the api may modify data |
Definition at line 244 of file ApiMain.php.
References ContextSource\$context, $wgLang, ContextSource\getConfig(), getErrorFormatter(), ApiBase\getHookRunner(), ContextSource\getLanguage(), RequestContext\getMain(), ContextSource\getRequest(), lacksSameOriginSecurity(), RequestContext\sanitizeLangCode(), ContextSource\setContext(), 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 1147 of file ApiMain.php.
References ContextSource\getConfig(), getErrorFormatter(), ContextSource\getLanguage(), ApiBase\getParameter(), getResult(), ApiResult\NO_SIZE_CHECK, wfHostname(), and wfTimestamp().
Referenced by setupExecuteAction(), and substituteResultWithError().
ApiMain::canApiHighLimits | ( | ) |
Check whether the current user is allowed to use high limits.
Definition at line 2101 of file ApiMain.php.
References $mCanApiHighLimits, ApiBase\getPermissionManager(), and ContextSource\getUser().
|
protected |
Check asserts of the user's rights.
array | $params |
Definition at line 1506 of file ApiMain.php.
References ApiBase\dieWithError(), ApiBase\getPermissionManager(), ContextSource\getUser(), User\newFromName(), and wfEscapeWikiText().
Referenced by executeAction().
|
private |
Check whether we are readonly for bots.
Definition at line 1467 of file ApiMain.php.
References ApiBase\dieWithError(), ContextSource\getConfig(), and wfDebugLog().
Referenced by checkReadOnly().
|
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 1319 of file ApiMain.php.
References $s, ContextSource\getConfig(), WebRequest\GETHEADER_LIST, ApiBase\getHookRunner(), ContextSource\getOutput(), ContextSource\getRequest(), ContextSource\getUser(), wfResetOutputBuffers(), and wfTimestamp().
Referenced by executeAction().
|
protected |
Check for sufficient permissions to execute.
ApiBase | $module | An Api module |
Definition at line 1420 of file ApiMain.php.
References checkReadOnly(), ApiBase\dieWithError(), ApiBase\getHookRunner(), ApiBase\getPermissionManager(), ContextSource\getRequest(), and ContextSource\getUser().
Referenced by executeAction().
|
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 1273 of file ApiMain.php.
References ApiBase\dieWithError(), ContextSource\getConfig(), getMaxLag(), and ContextSource\getRequest().
Referenced by executeAction().
|
protected |
Check if the DB is read-only for this user.
ApiBase | $module | An Api module |
Definition at line 1451 of file ApiMain.php.
References checkBotReadOnly(), ApiBase\dieReadOnly(), and wfReadOnly().
Referenced by checkExecutePermissions().
|
private |
Create the printer for error output.
Definition at line 994 of file ApiMain.php.
References API_DEFAULT_FORMAT, createPrinterByName(), and ContextSource\getRequest().
Referenced by handleException().
ApiMain::createPrinterByName | ( | $format | ) |
Create an instance of an output formatter by its name.
string | $format |
Definition at line 545 of file ApiMain.php.
References ApiBase\dieWithError(), and wfEscapeWikiText().
Referenced by ApiFormatRaw\__construct(), createErrorPrinter(), and setupExternalResponse().
|
protected |
Encode a value in a format suitable for a space-separated log line.
string | $s |
Definition at line 1726 of file ApiMain.php.
References $s.
Referenced by logRequest().
|
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 1025 of file ApiMain.php.
References $type, ApiMessage\create(), ContextSource\getConfig(), WebRequest\getRequestId(), Message\newFromSpecifier(), and wfEscapeWikiText().
Referenced by logRequest(), and substituteResultWithError().
ApiMain::execute | ( | ) |
Execute api request.
Any errors will be handled if the API was called by the remote client.
Reimplemented from ApiBase.
Definition at line 559 of file ApiMain.php.
References executeAction(), and executeActionWithErrorHandling().
Referenced by MediaWiki\Rest\Handler\ActionModuleBasedHandler\execute().
|
protected |
Execute the actual module, without any error handling.
Definition at line 1584 of file ApiMain.php.
References MWDebug\appendDebugInfoToApiResult(), checkAsserts(), checkConditionalRequestHeaders(), checkExecutePermissions(), checkMaxLag(), ContextSource\getContext(), ApiBase\getHookRunner(), getResult(), printResult(), reportUnusedParams(), setRequestExpectations(), setupExecuteAction(), setupExternalResponse(), and setupModule().
Referenced by execute(), and executeActionWithErrorHandling().
|
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 571 of file ApiMain.php.
References $t, executeAction(), ContextSource\getContext(), ContextSource\getRequest(), handleCORS(), handleException(), logRequest(), MediaWiki\preOutputCommit(), and sendCacheHeaders().
Referenced by execute().
ApiMain::getAllowedParams | ( | ) |
See ApiBase for description.
Reimplemented from ApiBase.
Definition at line 1876 of file ApiMain.php.
References API_DEFAULT_FORMAT, API_DEFAULT_USELANG, ApiBase\PARAM_DFLT, and ApiBase\PARAM_TYPE.
ApiMain::getCheck | ( | $name | ) |
Get a boolean request value, and register the fact that the parameter was used, for logging.
string | $name |
Definition at line 1800 of file ApiMain.php.
References ContextSource\getRequest().
ApiMain::getContinuationManager | ( | ) |
Reimplemented from ApiBase.
Definition at line 413 of file ApiMain.php.
References $mContinuationManager.
ApiMain::getErrorFormatter | ( | ) |
Get the ApiErrorFormatter object associated with current request.
Reimplemented from ApiBase.
Definition at line 406 of file ApiMain.php.
References $mErrorFormatter.
Referenced by __construct(), addRequestedFields(), and substituteResultWithError().
|
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 ApiBase.
Definition at line 1926 of file ApiMain.php.
|
private |
Definition at line 1239 of file ApiMain.php.
References ContextSource\getConfig(), ApiBase\getHookRunner(), JobQueueGroup\singleton(), and wfHostname().
Referenced by checkMaxLag().
ApiMain::getModule | ( | ) |
Get the API module object.
Only works after executeAction()
Definition at line 443 of file ApiMain.php.
References $mModule.
ApiMain::getModuleManager | ( | ) |
Overrides to return this instance's module manager.
Reimplemented from ApiBase.
Definition at line 2114 of file ApiMain.php.
References $mModuleMgr.
|
protected |
Get the request parameters used in the course of the preceding execute() request.
Definition at line 1743 of file ApiMain.php.
Referenced by logRequest(), and reportUnusedParams().
ApiMain::getParamValidator | ( | ) |
Get the parameter validator.
Definition at line 434 of file ApiMain.php.
References $mParamValidator.
Referenced by modifyHelp().
ApiMain::getPrinter | ( | ) |
Get the result formatter object.
Only works after setupExecuteAction()
Definition at line 452 of file ApiMain.php.
References $mPrinter.
ApiMain::getResult | ( | ) |
Get the ApiResult object associated with current request.
Reimplemented from ApiBase.
Definition at line 362 of file ApiMain.php.
References $mResult.
Referenced by addRequestedFields(), MediaWiki\Rest\Handler\ActionModuleBasedHandler\execute(), executeAction(), and substituteResultWithError().
|
protected |
Get the request parameters that should be considered sensitive.
Definition at line 1760 of file ApiMain.php.
Referenced by logRequest().
ApiMain::getUpload | ( | $name | ) |
Get a request upload, and register the fact that it was used, for logging.
string | $name | Parameter name |
Definition at line 1812 of file ApiMain.php.
References ContextSource\getRequest().
ApiMain::getUserAgent | ( | ) |
Fetches the user agent used for this request.
The value will be the combination of the 'Api-User-Agent' header (if any) and the standard User-Agent header (if any).
Definition at line 2126 of file ApiMain.php.
References ContextSource\getRequest().
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 1779 of file ApiMain.php.
References ApiBase\addWarning(), and ContextSource\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 711 of file ApiMain.php.
References RequestContext\getMain().
Referenced by wfApiMain().
|
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 743 of file ApiMain.php.
References ContextSource\getConfig(), ContextSource\getOutput(), ApiBase\getParameter(), and ContextSource\getRequest().
Referenced by executeActionWithErrorHandling().
|
protected |
Handle a throwable as an API response.
Throwable | $e |
Definition at line 637 of file ApiMain.php.
References ApiBase\addWarning(), createErrorPrinter(), ApiBase\getHookRunner(), ContextSource\getRequest(), ApiUsageException\getStatusValue(), printResult(), MWExceptionHandler\rollbackMasterChangesAndLog(), setCacheMode(), and substituteResultWithError().
Referenced by executeActionWithErrorHandling().
ApiMain::isInternalMode | ( | ) |
Return true if the API was started by other PHP code using FauxRequest.
Definition at line 353 of file ApiMain.php.
References $mInternalMode.
ApiMain::isReadMode | ( | ) |
ApiMain::lacksSameOriginSecurity | ( | ) |
Get the security flag for the current request.
Reimplemented from ApiBase.
Definition at line 370 of file ApiMain.php.
References $lacksSameOriginSecurity, ApiBase\getHookRunner(), and ContextSource\getRequest().
Referenced by __construct().
|
protected |
Log the preceding request.
float | $time | Time in seconds |
Throwable | null | $e | Throwable caught while processing the request |
Definition at line 1647 of file ApiMain.php.
References $header, encodeRequestLogValue(), errorMessagesFromException(), ContextSource\getConfig(), WikiMap\getCurrentWikiDbDomain(), getParamsUsed(), ContextSource\getRequest(), WebRequest\getRequestId(), getSensitiveParams(), ContextSource\getUser(), wfDebugLog(), wfTimestamp(), and wfUrlencode().
Referenced by executeActionWithErrorHandling().
ApiMain::markParamsSensitive | ( | $params | ) |
Mark parameters as sensitive.
string | string[] | $params |
Definition at line 1769 of file ApiMain.php.
ApiMain::markParamsUsed | ( | $params | ) |
Mark parameters as used.
string | string[] | $params |
Definition at line 1751 of file ApiMain.php.
|
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 863 of file ApiMain.php.
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.Stable to override
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 Linker::generateTOC(). |
Reimplemented from ApiBase.
Definition at line 1939 of file ApiMain.php.
References $header, $help, $type, Html\closeElement(), Html\element(), Sanitizer\escapeIdForAttribute(), getParamValidator(), ApiBase\getPermissionManager(), Sanitizer\ID_FALLBACK, Sanitizer\ID_PRIMARY, Message\listParam(), Linker\makeHeadline(), ContextSource\msg(), Html\openElement(), and Html\rawElement().
|
protected |
Print results using the current printer.
int | $httpCode | HTTP status code, or 0 to not change |
Definition at line 1850 of file ApiMain.php.
References $mPrinter, ApiBase\addWarning(), ContextSource\getConfig(), and ApiFormatBase\initPrinter().
Referenced by executeAction(), and handleException().
|
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 1822 of file ApiMain.php.
References ApiBase\addWarning(), getParamsUsed(), ContextSource\getRequest(), and Message\listParam().
Referenced by executeAction().
|
protected |
Send caching headers.
bool | $isError | Whether an error response is being output |
Definition at line 888 of file ApiMain.php.
References ContextSource\getConfig(), ContextSource\getOutput(), ApiBase\getParameter(), ContextSource\getRequest(), and wfTimestamp().
Referenced by executeActionWithErrorHandling().
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 534 of file ApiMain.php.
References $mCacheControl.
Referenced by setCacheMaxAge().
ApiMain::setCacheMaxAge | ( | $maxage | ) |
Set how long the response should be cached.
int | $maxage |
Definition at line 461 of file ApiMain.php.
References setCacheControl().
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 493 of file ApiMain.php.
References ApiBase\getParameter(), ApiBase\getPermissionManager(), and wfDebug().
Referenced by handleException().
ApiMain::setContinuationManager | ( | ApiContinuationManager | $manager = null | ) |
ApiContinuationManager | null | $manager |
Reimplemented from ApiBase.
Definition at line 420 of file ApiMain.php.
|
protected |
Set database connection, query, and write expectations given this module request.
ApiBase | $module |
Definition at line 1628 of file ApiMain.php.
References ContextSource\getConfig(), ContextSource\getRequest(), Profiler\instance(), and ApiBase\isWriteMode().
Referenced by executeAction().
|
protected |
Set up for the execution.
Definition at line 1177 of file ApiMain.php.
References addRequestedFields(), and ApiBase\extractRequestParams().
Referenced by executeAction().
|
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 1542 of file ApiMain.php.
References ApiBase\addDeprecation(), createPrinterByName(), ApiBase\dieWithError(), ApiBase\dieWithErrorOrDebug(), and ContextSource\getRequest().
Referenced by executeAction().
|
protected |
Set up the module for response.
MWException | |
ApiUsageException |
Definition at line 1192 of file ApiMain.php.
References ApiBase\dieWithError(), and wfEscapeWikiText().
Referenced by executeAction().
|
protected |
Replace the result data with the information about a throwable.
Throwable | $e |
Definition at line 1063 of file ApiMain.php.
References $path, addRequestedFields(), errorMessagesFromException(), ContextSource\getConfig(), getErrorFormatter(), ApiUsageException\getModulePath(), MWExceptionHandler\getRedactedTraceAsString(), getResult(), ApiErrorFormatter\isValidApiCode(), ContextSource\msg(), ApiResult\NO_SIZE_CHECK, wfExpandUrl(), and wfScript().
Referenced by handleException().
|
private |
Cached return value from self::lacksSameOriginSecurity()
Definition at line 234 of file ApiMain.php.
Referenced by lacksSameOriginSecurity().
|
private |
Definition at line 221 of file ApiMain.php.
|
private |
Definition at line 229 of file ApiMain.php.
Referenced by setCacheControl().
|
private |
Definition at line 227 of file ApiMain.php.
|
private |
Definition at line 2095 of file ApiMain.php.
Referenced by canApiHighLimits().
ApiMain::$mCdnMaxAge |
Definition at line 223 of file ApiMain.php.
|
private |
Definition at line 220 of file ApiMain.php.
Referenced by getContinuationManager().
|
private |
Definition at line 222 of file ApiMain.php.
ApiMain::$mErrorFormatter = null |
Definition at line 218 of file ApiMain.php.
Referenced by getErrorFormatter().
|
private |
Definition at line 223 of file ApiMain.php.
Referenced by isInternalMode().
|
private |
Definition at line 225 of file ApiMain.php.
Referenced by getModule().
|
private |
Definition at line 218 of file ApiMain.php.
Referenced by getModuleManager().
|
private |
Definition at line 231 of file ApiMain.php.
|
private |
Definition at line 230 of file ApiMain.php.
ApiMain::$mParamValidator |
Definition at line 218 of file ApiMain.php.
Referenced by getParamValidator().
|
private |
Definition at line 216 of file ApiMain.php.
Referenced by getPrinter(), and printResult().
ApiMain::$mResult |
Definition at line 218 of file ApiMain.php.
Referenced by getResult().
|
private |
When no format parameter is given, this format will be used.
Definition at line 52 of file ApiMain.php.
Referenced by createErrorPrinter(), and getAllowedParams().
|
private |
When no uselang parameter is given, this language will be used.
Definition at line 57 of file ApiMain.php.
Referenced by getAllowedParams().
|
private |
List of available formats: format name => format class.
Definition at line 185 of file ApiMain.php.
|
private |
List of available modules: action name => module class.
Definition at line 62 of file ApiMain.php.
|
private |
List of user roles that are specifically relevant to the API.
[ 'right' => [ 'msg' => 'Some message with a $1', 'params' => [ $someVarToSubst ] ], ];
Definition at line 202 of file ApiMain.php.