Inherits ApiBase.
Public Member Functions | |
__construct ($request, $enableWrite=false) | |
Constructs an instance of ApiMain that utilizes the module and format specified by $request. | |
isInternalMode () | |
Return true if the API was started by other PHP code using FauxRequest. | |
getRequest () | |
Return the request object that contains client's request. | |
getResult () | |
Get the ApiResult object associated with current request. | |
getModule () | |
Get the API module object. | |
requestWriteMode () | |
Only kept for backwards compatibility. | |
setCacheMaxAge ($maxage) | |
Set how long the response should be cached. | |
setCacheMode ($mode) | |
Set the type of caching headers which will be sent. | |
setCachePrivate () | |
setCacheControl ($directives) | |
Set directives (key/value pairs) for the Cache-Control header. | |
setVaryCookie () | |
Make sure Vary: Cookie and friends are set. | |
createPrinterByName ($format) | |
Create an instance of an output formatter by its name. | |
execute () | |
Execute api request. | |
isReadMode () | |
Indicates whether this module requires read rights. | |
getAllowedParams () | |
See ApiBase for description. | |
getParamDescription () | |
See ApiBase for description. | |
getDescription () | |
See ApiBase for description. | |
getPossibleErrors () | |
Returns a list of all possible errors returned by the module. | |
makeHelpMsg () | |
Override the parent to generate help messages for all available modules. | |
reallyMakeHelpMsg () | |
isBot () | |
Returns true if the currently logged in user is a bot, false otherwise OBSOLETE, use canApiHighLimits() instead. | |
isSysop () | |
Similar to isBot(), this method returns true if the logged in user is a sysop, and false if not. | |
canApiHighLimits () | |
Check whether the current user is allowed to use high limits. | |
getShowVersions () | |
Check whether the user wants us to show version information in the API help. | |
getVersion () | |
Returns the version information of this file, plus it includes the versions for all files that are not callable proper API modules. | |
getModules () | |
Get the array mapping module names to class names. | |
Static Public Member Functions | |
static | makeHelpMsgHeader ($module, $paramName) |
Public Attributes | |
const | API_DEFAULT_FORMAT = 'xmlfm' |
When no format parameter is given, this format will be used. | |
Protected Member Functions | |
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. | |
sendCacheHeaders () | |
substituteResultWithError ($e) | |
Replace the result data with the information about an exception. | |
executeAction () | |
Execute the actual module, without any error handling. | |
printResult ($isError) | |
Print results using the current printer. | |
getCredits () | |
Returns an array of strings with credits for the API. | |
addModule ($mdlName, $mdlClass) | |
Add or overwrite a module in this ApiMain instance. | |
addFormat ($fmtName, $fmtClass) | |
Add or overwrite an output format for this ApiMain. | |
Private Attributes | |
$mPrinter | |
$mModules | |
$mModuleNames | |
$mFormats | |
$mFormatNames | |
$mResult | |
$mAction | |
$mShowVersions | |
$mEnableWrite | |
$mRequest | |
$mInternalMode | |
$mSquidMaxage | |
$mModule | |
$mCacheMode = 'private' | |
$mCacheControl = array() | |
$mIsBot = null | |
$mIsSysop = null | |
$mCanApiHighLimits = null | |
Static Private Attributes | |
static | $Modules |
List of available modules: action name => module class. | |
static | $Formats |
List of available formats: format name => format class. | |
static | $mRights |
List of user roles that are specifically relevant to the API. |
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 48 of file ApiMain.php.
ApiMain::__construct | ( | $ | request, | |
$ | enableWrite = false | |||
) |
Constructs an instance of ApiMain that utilizes the module and format specified by $request.
$request | object - if this is an instance of FauxRequest, errors are thrown and no printing occurs | |
$enableWrite | bool should be set to true if the api may modify data |
Definition at line 138 of file ApiMain.php.
References $wgAPIModules, $wgUser, and wfDebug().
ApiMain::addFormat | ( | $ | fmtName, | |
$ | fmtClass | |||
) | [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.
$fmtName | The identifier for this format. | |
$fmtClass | The class implementing this format. |
Definition at line 889 of file ApiMain.php.
ApiMain::addModule | ( | $ | mdlName, | |
$ | mdlClass | |||
) | [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.
$mdlName | String The identifier for this module. | |
$mdlClass | String The class where this module is implemented. |
Definition at line 877 of file ApiMain.php.
ApiMain::canApiHighLimits | ( | ) |
Check whether the current user is allowed to use high limits.
Definition at line 837 of file ApiMain.php.
References $wgUser.
ApiMain::createPrinterByName | ( | $ | format | ) |
Create an instance of an output formatter by its name.
Definition at line 308 of file ApiMain.php.
References ApiBase::dieUsage().
Referenced by executeAction(), reallyMakeHelpMsg(), 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 317 of file ApiMain.php.
References executeAction(), executeActionWithErrorHandling(), ApiBase::profileIn(), and ApiBase::profileOut().
ApiMain::executeAction | ( | ) | [protected] |
Execute the actual module, without any error handling.
Definition at line 513 of file ApiMain.php.
References $maxLag, $wgGroupPermissions, $wgShowHostnames, $wgUser, createPrinterByName(), ApiBase::dieReadOnly(), ApiBase::dieUsage(), ApiBase::dieUsageMsg(), ApiBase::extractRequestParams(), User::getGroupPermissions(), ApiBase::getParameter(), getResult(), printResult(), wfGetLB(), wfReadOnly(), and wfRunHooks().
Referenced by execute(), and executeActionWithErrorHandling().
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 331 of file ApiMain.php.
References executeAction(), printResult(), sendCacheHeaders(), setCacheMode(), substituteResultWithError(), wfDebugLog(), and wfReportTime().
Referenced by execute().
ApiMain::getAllowedParams | ( | ) |
See ApiBase for description.
Reimplemented from ApiBase.
Definition at line 633 of file ApiMain.php.
References API_DEFAULT_FORMAT, ApiBase::PARAM_DFLT, and ApiBase::PARAM_TYPE.
ApiMain::getCredits | ( | ) | [protected] |
Returns an array of strings with credits for the API.
Definition at line 718 of file ApiMain.php.
Referenced by reallyMakeHelpMsg().
ApiMain::getDescription | ( | ) |
See ApiBase for description.
Reimplemented from ApiBase.
Definition at line 677 of file ApiMain.php.
ApiMain::getModule | ( | ) |
Get the API module object.
Only works after executeAction()
Definition at line 201 of file ApiMain.php.
ApiMain::getModules | ( | ) |
ApiMain::getParamDescription | ( | ) |
See ApiBase for description.
Reimplemented from ApiBase.
Definition at line 662 of file ApiMain.php.
ApiMain::getPossibleErrors | ( | ) |
Returns a list of all possible errors returned by the module.
Reimplemented from ApiBase.
Definition at line 705 of file ApiMain.php.
ApiMain::getRequest | ( | ) |
Return the request object that contains client's request.
Definition at line 187 of file ApiMain.php.
Referenced by substituteResultWithError().
ApiMain::getResult | ( | ) |
Get the ApiResult object associated with current request.
Reimplemented from ApiBase.
Definition at line 194 of file ApiMain.php.
Referenced by executeAction(), printResult(), and substituteResultWithError().
ApiMain::getShowVersions | ( | ) |
Check whether the user wants us to show version information in the API help.
Definition at line 850 of file ApiMain.php.
Referenced by makeHelpMsg().
ApiMain::getVersion | ( | ) |
Returns the version information of this file, plus it includes the versions for all files that are not callable proper API modules.
Reimplemented from ApiBase.
Definition at line 858 of file ApiMain.php.
References ApiBase::getBaseVersion().
ApiMain::isBot | ( | ) |
Returns true if the currently logged in user is a bot, false otherwise OBSOLETE, use canApiHighLimits() instead.
Definition at line 811 of file ApiMain.php.
References $wgUser.
ApiMain::isInternalMode | ( | ) |
Return true if the API was started by other PHP code using FauxRequest.
Definition at line 180 of file ApiMain.php.
ApiMain::isReadMode | ( | ) |
Indicates whether this module requires read rights.
Reimplemented from ApiBase.
Definition at line 626 of file ApiMain.php.
ApiMain::isSysop | ( | ) |
Similar to isBot(), this method returns true if the logged in user is a sysop, and false if not.
OBSOLETE, use canApiHighLimits() instead
Definition at line 824 of file ApiMain.php.
References $wgUser.
ApiMain::makeHelpMsg | ( | ) |
Override the parent to generate help messages for all available modules.
Reimplemented from ApiBase.
Definition at line 735 of file ApiMain.php.
References $wgAPICacheHelp, $wgAPICacheHelpTimeout, $wgMemc, ApiBase::getMain(), ApiBase::getModuleName(), getShowVersions(), SpecialVersion::getVersion(), reallyMakeHelpMsg(), and wfMemcKey().
Referenced by reallyMakeHelpMsg(), and substituteResultWithError().
static ApiMain::makeHelpMsgHeader | ( | $ | module, | |
$ | paramName | |||
) | [static] |
Definition at line 795 of file ApiMain.php.
Referenced by ApiQuery::makeHelpMsgHelper(), and reallyMakeHelpMsg().
ApiMain::printResult | ( | $ | isError | ) | [protected] |
Print results using the current printer.
Definition at line 608 of file ApiMain.php.
References getResult().
Referenced by executeAction(), and executeActionWithErrorHandling().
ApiMain::reallyMakeHelpMsg | ( | ) |
Definition at line 753 of file ApiMain.php.
References $msg, createPrinterByName(), getCredits(), User::getGroupsWithPermission(), makeHelpMsg(), makeHelpMsgHeader(), and wfMsgReplaceArgs().
Referenced by makeHelpMsg().
ApiMain::requestWriteMode | ( | ) |
Only kept for backwards compatibility.
Definition at line 209 of file ApiMain.php.
References ApiBase::dieUsageMsg(), and wfReadOnly().
ApiMain::sendCacheHeaders | ( | ) | [protected] |
Definition at line 381 of file ApiMain.php.
References $name, $wgOut, $wgUser, $wgUseXVO, ApiBase::getParameter(), wfDebug(), 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().
Definition at line 287 of file ApiMain.php.
Referenced by setCacheMaxAge().
ApiMain::setCacheMaxAge | ( | $ | maxage | ) |
Set how long the response should be cached.
Definition at line 219 of file ApiMain.php.
References setCacheControl().
ApiMain::setCacheMode | ( | $ | mode | ) |
Set the type of caching headers which will be sent.
$mode | One of:
|
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 251 of file ApiMain.php.
References $mode, User::getGroupPermissions(), and wfDebug().
Referenced by executeActionWithErrorHandling(), setCachePrivate(), and setVaryCookie().
ApiMain::setCachePrivate | ( | ) |
Definition at line 275 of file ApiMain.php.
References setCacheMode().
ApiMain::setVaryCookie | ( | ) |
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 301 of file ApiMain.php.
References setCacheMode().
ApiMain::substituteResultWithError | ( | $ | e | ) | [protected] |
Replace the result data with the information about an exception.
Returns the error code
Definition at line 457 of file ApiMain.php.
References $wgShowExceptionDetails, $wgShowSQLErrors, createPrinterByName(), ApiBase::getParameter(), getRequest(), getResult(), makeHelpMsg(), and ApiResult::setContent().
Referenced by executeActionWithErrorHandling().
ApiMain::$Formats [static, private] |
Initial value:
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' )
Definition at line 90 of file ApiMain.php.
ApiMain::$mAction [private] |
Definition at line 126 of file ApiMain.php.
ApiMain::$mCacheControl = array() [private] |
Definition at line 130 of file ApiMain.php.
ApiMain::$mCacheMode = 'private' [private] |
Definition at line 129 of file ApiMain.php.
ApiMain::$mCanApiHighLimits = null [private] |
Definition at line 805 of file ApiMain.php.
ApiMain::$mEnableWrite [private] |
Definition at line 126 of file ApiMain.php.
ApiMain::$mFormatNames [private] |
Definition at line 125 of file ApiMain.php.
ApiMain::$mFormats [private] |
Definition at line 125 of file ApiMain.php.
ApiMain::$mInternalMode [private] |
Definition at line 127 of file ApiMain.php.
ApiMain::$mIsBot = null [private] |
Definition at line 803 of file ApiMain.php.
ApiMain::$mIsSysop = null [private] |
Definition at line 804 of file ApiMain.php.
ApiMain::$mModule [private] |
Definition at line 127 of file ApiMain.php.
ApiMain::$mModuleNames [private] |
Definition at line 125 of file ApiMain.php.
ApiMain::$mModules [private] |
Definition at line 125 of file ApiMain.php.
ApiMain::$Modules [static, private] |
Initial value:
array ( 'login' => 'ApiLogin', 'logout' => 'ApiLogout', 'query' => 'ApiQuery', 'expandtemplates' => 'ApiExpandTemplates', 'parse' => 'ApiParse', 'opensearch' => 'ApiOpenSearch', 'feedwatchlist' => 'ApiFeedWatchlist', 'help' => 'ApiHelp', 'paraminfo' => 'ApiParamInfo', 'purge' => 'ApiPurge', 'rollback' => 'ApiRollback', 'delete' => 'ApiDelete', 'undelete' => 'ApiUndelete', 'protect' => 'ApiProtect', 'block' => 'ApiBlock', 'unblock' => 'ApiUnblock', 'move' => 'ApiMove', 'edit' => 'ApiEditPage', 'upload' => 'ApiUpload', 'emailuser' => 'ApiEmailUser', 'watch' => 'ApiWatch', 'patrol' => 'ApiPatrol', 'import' => 'ApiImport', 'userrights' => 'ApiUserrights', )
Definition at line 58 of file ApiMain.php.
ApiMain::$mPrinter [private] |
Definition at line 125 of file ApiMain.php.
ApiMain::$mRequest [private] |
Definition at line 126 of file ApiMain.php.
ApiMain::$mResult [private] |
Definition at line 126 of file ApiMain.php.
ApiMain::$mRights [static, private] |
Initial value:
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 ( ApiMain::LIMIT_SML2, ApiMain::LIMIT_BIG2 ) ) )
array( 'right' => array ( 'msg' => 'Some message with a $1', 'params' => array ( $someVarToSubst ) ), );
Definition at line 114 of file ApiMain.php.
ApiMain::$mShowVersions [private] |
Definition at line 126 of file ApiMain.php.
ApiMain::$mSquidMaxage [private] |
Definition at line 127 of file ApiMain.php.
const ApiMain::API_DEFAULT_FORMAT = 'xmlfm' |
When no format parameter is given, this format will be used.
Definition at line 53 of file ApiMain.php.
Referenced by getAllowedParams().