MediaWiki
REL1_22
|
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. | |
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. | |
getCheck ($name) | |
Get a boolean request value, and register the fact that the parameter was used, for logging. | |
getDescription () | |
See ApiBase for description. | |
getFormats () | |
Returns the list of supported formats in form ( 'format' => 'ClassName' ) | |
getModule () | |
Get the API module object. | |
getModuleManager () | |
Overrides to return this instance's module manager. | |
getModules () | |
Get the array mapping module names to class names. | |
getParamDescription () | |
See ApiBase for description. | |
getPossibleErrors () | |
getPrinter () | |
Get the result formatter object. | |
getResult () | |
Get the ApiResult object associated with current request. | |
getShowVersions () | |
Check whether the user wants us to show version information in the API help. | |
getUpload ($name) | |
Get a request upload, and register the fact that it was used, for logging. | |
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 FauxRequest. | |
isReadMode () | |
makeHelpMsg () | |
Override the parent to generate help messages for all available modules. | |
reallyMakeHelpMsg () | |
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. | |
setCachePrivate () | |
setHelp ($help=true) | |
Sets whether the pretty-printer should format *bold* and $italics$. | |
setVaryCookie () | |
Make sure Vary: Cookie and friends are set. | |
Static Public Member Functions | |
static | makeHelpMsgHeader ($module, $paramName) |
Public Attributes | |
$mModule | |
$mResult | |
$mSquidMaxage | |
const | API_DEFAULT_FORMAT = 'xmlfm' |
When no format parameter is given, this format will be used. | |
Protected Member Functions | |
addFormat ($name, $class) | |
Add or overwrite an output format for this ApiMain. | |
addModule ($name, $class) | |
Add or overwrite a module in this ApiMain instance. | |
checkExecutePermissions ($module) | |
Check for sufficient permissions to execute. | |
checkMaxLag ($module, $params) | |
Check the max lag if necessary. | |
encodeRequestLogValue ($s) | |
Encode a value in a format suitable for a space-separated log line. | |
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. | |
getCredits () | |
Returns an array of strings with credits for the API. | |
getParamsUsed () | |
Get the request parameters used in the course of the preceding execute() request. | |
handleCORS () | |
Check the &origin= query parameter against the Origin: HTTP header and respond appropriately. | |
logRequest ($time) | |
Log the preceding request. | |
printResult ($isError) | |
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 () | |
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 ($e) | |
Replace the result data with the information about an exception. | |
Static Protected Member Functions | |
static | matchOrigin ($value, $rules, $exceptions) |
Attempt to match an Origin header against a set of rules and a set of exceptions. | |
static | wildcardToRegex ($wildcard) |
Helper function to convert wildcard string into a regex '*' => '. | |
Private Attributes | |
$mAction | |
$mCacheControl = array() | |
$mCacheMode = 'private' | |
$mCanApiHighLimits = null | |
$mEnableWrite | |
$mInternalMode | |
$mModuleMgr | |
$mParamsUsed = array() | |
ApiFormatBase | $mPrinter |
Static Private Attributes | |
static | $Formats |
List of available formats: format name => format class. | |
static | $Modules |
List of available modules: action name => module class. | |
static | $mRights |
List of user roles that are specifically relevant to the API. |
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.
Definition at line 41 of file ApiMain.php.
ApiMain::__construct | ( | $ | context = null , |
$ | enableWrite = false |
||
) |
Constructs an instance of ApiMain that utilizes the module and format specified by $request.
$context | IContextSource|WebRequest - 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 149 of file ApiMain.php.
ApiMain::addFormat | ( | $ | name, |
$ | class | ||
) | [protected] |
Add or overwrite an output format for this ApiMain.
Intended for use by extending classes who wish to add to or modify current formatters.
string | $name | The identifier for this format. |
$class | ApiFormatBase The class implementing this format. |
Definition at line 1268 of file ApiMain.php.
ApiMain::addModule | ( | $ | name, |
$ | class | ||
) | [protected] |
Add or overwrite a module in this ApiMain instance.
Intended for use by extending classes who wish to add their own modules to their lexicon or override the behavior of inherent ones.
string | $name | The identifier for this module. |
$class | ApiBase The class where this module is implemented. |
Definition at line 1256 of file ApiMain.php.
Check whether the current user is allowed to use high limits.
Definition at line 1221 of file ApiMain.php.
ApiMain::checkExecutePermissions | ( | $ | module | ) | [protected] |
Check for sufficient permissions to execute.
$module | ApiBase An Api module |
Definition at line 758 of file ApiMain.php.
ApiMain::checkMaxLag | ( | $ | module, |
$ | params | ||
) | [protected] |
Check the max lag if necessary.
$module | ApiBase object: Api module being used | |
array | $params | an array containing the request parameters. |
Definition at line 731 of file ApiMain.php.
ApiMain::createPrinterByName | ( | $ | format | ) |
Create an instance of an output formatter by its name.
$format | string |
Definition at line 334 of file ApiMain.php.
ApiMain::encodeRequestLogValue | ( | $ | s | ) | [protected] |
Encode a value in a format suitable for a space-separated log line.
Definition at line 875 of file ApiMain.php.
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 345 of file ApiMain.php.
ApiMain::executeAction | ( | ) | [protected] |
Execute the actual module, without any error handling.
Definition at line 811 of file ApiMain.php.
ApiMain::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 360 of file ApiMain.php.
See ApiBase for description.
Reimplemented from ApiBase.
Definition at line 989 of file ApiMain.php.
ApiMain::getCheck | ( | $ | name | ) |
Get a boolean request value, and register the fact that the parameter was used, for logging.
Definition at line 905 of file ApiMain.php.
ApiMain::getCredits | ( | ) | [protected] |
Returns an array of strings with credits for the API.
Definition at line 1108 of file ApiMain.php.
See ApiBase for description.
Reimplemented from ApiBase.
Definition at line 1052 of file ApiMain.php.
Returns the list of supported formats in form ( 'format' => 'ClassName' )
Definition at line 1288 of file ApiMain.php.
Get the API module object.
Only works after executeAction()
Definition at line 219 of file ApiMain.php.
Overrides to return this instance's module manager.
Reimplemented from ApiBase.
Definition at line 1243 of file ApiMain.php.
Get the array mapping module names to class names.
Definition at line 1277 of file ApiMain.php.
See ApiBase for description.
Reimplemented from ApiBase.
Definition at line 1021 of file ApiMain.php.
ApiMain::getParamsUsed | ( | ) | [protected] |
Get the request parameters used in the course of the preceding execute() request.
Definition at line 889 of file ApiMain.php.
Get the result formatter object.
Only works after setupExecuteAction()
Definition at line 228 of file ApiMain.php.
Get the ApiResult object associated with current request.
Reimplemented from ApiBase.
Definition at line 210 of file ApiMain.php.
Check whether the user wants us to show version information in the API help.
Definition at line 1234 of file ApiMain.php.
ApiMain::getUpload | ( | $ | name | ) |
Get a request upload, and register the fact that it was used, for logging.
string | $name | Parameter name |
Definition at line 917 of file ApiMain.php.
ApiMain::getVal | ( | $ | name, |
$ | default = null |
||
) |
Get a request value, and register the fact that it was used, for logging.
Definition at line 896 of file ApiMain.php.
ApiMain::handleCORS | ( | ) | [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.
Definition at line 440 of file ApiMain.php.
Return true if the API was started by other PHP code using FauxRequest.
Definition at line 201 of file ApiMain.php.
ApiMain::logRequest | ( | $ | time | ) | [protected] |
Log the preceding request.
$time | Time in seconds |
Definition at line 847 of file ApiMain.php.
Override the parent to generate help messages for all available modules.
Reimplemented from ApiBase.
Definition at line 1136 of file ApiMain.php.
static ApiMain::makeHelpMsgHeader | ( | $ | module, |
$ | paramName | ||
) | [static] |
$module | ApiBase | |
string | $paramName | What type of request is this? e.g. action, query, list, prop, meta, format |
Definition at line 1206 of file ApiMain.php.
Referenced by ApiHelp\buildModuleHelp().
static ApiMain::matchOrigin | ( | $ | value, |
$ | rules, | ||
$ | exceptions | ||
) | [static, protected] |
Attempt to match an Origin header against a set of rules and a set of exceptions.
string | $value | Origin header |
array | $rules | Set of wildcard rules |
array | $exceptions | Set of wildcard rules |
Definition at line 482 of file ApiMain.php.
ApiMain::printResult | ( | $ | isError | ) | [protected] |
Print results using the current printer.
$isError | bool |
Definition at line 952 of file ApiMain.php.
Definition at line 1158 of file ApiMain.php.
ApiMain::reportUnusedParams | ( | ) | [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 926 of file ApiMain.php.
ApiMain::sendCacheHeaders | ( | ) | [protected] |
Definition at line 515 of file ApiMain.php.
References $name, $out, $response, $value, as, ContextSource\getOutput(), ApiBase\getParameter(), ContextSource\getRequest(), global, and wfTimestamp().
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().
$directives | array |
Definition at line 308 of file ApiMain.php.
ApiMain::setCacheMaxAge | ( | $ | maxage | ) |
Set how long the response should be cached.
$maxage |
Definition at line 237 of file ApiMain.php.
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 269 of file ApiMain.php.
If there is a need, you can use $this->setCacheMode('private')
Definition at line 293 of file ApiMain.php.
ApiMain::setHelp | ( | $ | help = true | ) |
Sets whether the pretty-printer should format *bold* and $italics$.
$help | bool |
Definition at line 1127 of file ApiMain.php.
ApiMain::setupExecuteAction | ( | ) | [protected] |
ApiMain::setupExternalResponse | ( | $ | module, |
$ | params | ||
) | [protected] |
Check POST for external response and setup result printer.
$module | ApiBase An Api module | |
array | $params | an array with the request parameters |
Definition at line 789 of file ApiMain.php.
ApiMain::setupModule | ( | ) | [protected] |
Set up the module for response.
Definition at line 703 of file ApiMain.php.
Make sure Vary: Cookie and friends are set.
Use this when the output of a request may be cached for anons but may not be cached for logged-in users.
WARNING: This function must be called CONSISTENTLY for a given URL. This means that a given URL must either always or never call this function; if it sometimes does and sometimes doesn't, stuff will break.
Definition at line 322 of file ApiMain.php.
ApiMain::substituteResultWithError | ( | $ | e | ) | [protected] |
Replace the result data with the information about an exception.
Returns the error code
$e | Exception |
Definition at line 601 of file ApiMain.php.
static ApiMain::wildcardToRegex | ( | $ | wildcard | ) | [static, protected] |
Helper function to convert wildcard string into a regex '*' => '.
*?' '?' => '.'
string | $wildcard | String with wildcards |
Definition at line 505 of file ApiMain.php.
ApiMain::$Formats [static, private] |
array( 'json' => 'ApiFormatJson', 'jsonfm' => 'ApiFormatJson', 'php' => 'ApiFormatPhp', 'phpfm' => 'ApiFormatPhp', 'wddx' => 'ApiFormatWddx', 'wddxfm' => 'ApiFormatWddx', 'xml' => 'ApiFormatXml', 'xmlfm' => 'ApiFormatXml', 'yaml' => 'ApiFormatYaml', 'yamlfm' => 'ApiFormatYaml', 'rawfm' => 'ApiFormatJson', 'txt' => 'ApiFormatTxt', 'txtfm' => 'ApiFormatTxt', 'dbg' => 'ApiFormatDbg', 'dbgfm' => 'ApiFormatDbg', 'dump' => 'ApiFormatDump', 'dumpfm' => 'ApiFormatDump', 'none' => 'ApiFormatNone', )
List of available formats: format name => format class.
Definition at line 92 of file ApiMain.php.
ApiMain::$mAction [private] |
Definition at line 135 of file ApiMain.php.
ApiMain::$mCacheControl = array() [private] |
Definition at line 140 of file ApiMain.php.
ApiMain::$mCacheMode = 'private' [private] |
Definition at line 139 of file ApiMain.php.
ApiMain::$mCanApiHighLimits = null [private] |
Definition at line 1215 of file ApiMain.php.
ApiMain::$mEnableWrite [private] |
Definition at line 136 of file ApiMain.php.
ApiMain::$mInternalMode [private] |
Definition at line 137 of file ApiMain.php.
ApiMain::$mModule |
Definition at line 137 of file ApiMain.php.
ApiMain::$mModuleMgr [private] |
Definition at line 134 of file ApiMain.php.
ApiMain::$Modules [static, private] |
List of available modules: action name => module class.
Definition at line 51 of file ApiMain.php.
ApiMain::$mParamsUsed = array() [private] |
Definition at line 141 of file ApiMain.php.
ApiFormatBase ApiMain::$mPrinter [private] |
Definition at line 132 of file ApiMain.php.
ApiMain::$mResult |
Definition at line 134 of file ApiMain.php.
ApiMain::$mRights [static, private] |
array( 'writeapi' => array( 'msg' => 'Use of the write API', 'params' => array() ), 'apihighlimits' => array( 'msg' => 'Use higher limits in API queries (Slow queries: $1 results; Fast queries: $2 results). The limits for slow queries also apply to multivalue parameters.', 'params' => array( ApiBase::LIMIT_SML2, ApiBase::LIMIT_BIG2 ) ) )
List of user roles that are specifically relevant to the API.
array( 'right' => array ( 'msg' => 'Some message with a $1', 'params' => array ( $someVarToSubst ) ), );
Definition at line 119 of file ApiMain.php.
ApiMain::$mSquidMaxage |
Definition at line 137 of file ApiMain.php.
const ApiMain::API_DEFAULT_FORMAT = 'xmlfm' |
When no format parameter is given, this format will be used.
Definition at line 46 of file ApiMain.php.