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 asscosiated with current request. | |
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. | |
makeHelpMsg () | |
Override the parent to generate help messages for all available modules. | |
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 | |
$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 134 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 827 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 815 of file ApiMain.php.
ApiMain::canApiHighLimits | ( | ) |
Check whether the current user is allowed to use high limits.
Definition at line 774 of file ApiMain.php.
References $wgUser.
ApiMain::createPrinterByName | ( | $ | format | ) |
Create an instance of an output formatter by its name.
Definition at line 296 of file ApiMain.php.
References ApiBase::dieUsage().
Referenced by executeAction(), makeHelpMsg(), 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 305 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 495 of file ApiMain.php.
References $maxLag, $wgShowHostnames, $wgUser, createPrinterByName(), ApiBase::dieUsage(), ApiBase::dieUsageMsg(), ApiBase::extractRequestParams(), 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 319 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 599 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 674 of file ApiMain.php.
Referenced by makeHelpMsg().
ApiMain::getDescription | ( | ) |
See ApiBase for description.
Reimplemented from ApiBase.
Definition at line 643 of file ApiMain.php.
ApiMain::getModules | ( | ) |
ApiMain::getParamDescription | ( | ) |
See ApiBase for description.
Reimplemented from ApiBase.
Definition at line 628 of file ApiMain.php.
ApiMain::getRequest | ( | ) |
Return the request object that contains client's request.
Definition at line 182 of file ApiMain.php.
Referenced by substituteResultWithError().
ApiMain::getResult | ( | ) |
Get the ApiResult object asscosiated with current request.
Reimplemented from ApiBase.
Definition at line 189 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 787 of file ApiMain.php.
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 795 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 748 of file ApiMain.php.
References $wgUser.
ApiMain::isInternalMode | ( | ) |
Return true if the API was started by other PHP code using FauxRequest.
Definition at line 175 of file ApiMain.php.
ApiMain::isReadMode | ( | ) |
Indicates whether this module requires read rights.
Reimplemented from ApiBase.
Definition at line 592 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 761 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 690 of file ApiMain.php.
References $msg, createPrinterByName(), getCredits(), User::getGroupsWithPermission(), makeHelpMsgHeader(), and wfMsgReplaceArgs().
Referenced by substituteResultWithError().
static ApiMain::makeHelpMsgHeader | ( | $ | module, | |
$ | paramName | |||
) | [static] |
Definition at line 732 of file ApiMain.php.
Referenced by makeHelpMsg(), and ApiQuery::makeHelpMsgHelper().
ApiMain::printResult | ( | $ | isError | ) | [protected] |
Print results using the current printer.
Definition at line 574 of file ApiMain.php.
References getResult().
Referenced by executeAction(), and executeActionWithErrorHandling().
ApiMain::requestWriteMode | ( | ) |
Only kept for backwards compatibility.
Definition at line 197 of file ApiMain.php.
References ApiBase::dieUsageMsg(), and wfReadOnly().
ApiMain::sendCacheHeaders | ( | ) | [protected] |
Definition at line 368 of file ApiMain.php.
References $name, $wgOut, $wgUser, 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 275 of file ApiMain.php.
Referenced by setCacheMaxAge().
ApiMain::setCacheMaxAge | ( | $ | maxage | ) |
Set how long the response should be cached.
Definition at line 207 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 239 of file ApiMain.php.
References $mode, User::getGroupPermissions(), and wfDebug().
Referenced by executeActionWithErrorHandling(), setCachePrivate(), and setVaryCookie().
ApiMain::setCachePrivate | ( | ) |
Definition at line 263 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 289 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 437 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 88 of file ApiMain.php.
ApiMain::$mAction [private] |
Definition at line 124 of file ApiMain.php.
ApiMain::$mCacheControl = array() [private] |
Definition at line 126 of file ApiMain.php.
ApiMain::$mCacheMode = 'private' [private] |
Definition at line 125 of file ApiMain.php.
ApiMain::$mCanApiHighLimits = null [private] |
Definition at line 742 of file ApiMain.php.
ApiMain::$mEnableWrite [private] |
Definition at line 124 of file ApiMain.php.
ApiMain::$mFormatNames [private] |
Definition at line 123 of file ApiMain.php.
ApiMain::$mFormats [private] |
Definition at line 123 of file ApiMain.php.
ApiMain::$mInternalMode [private] |
Definition at line 124 of file ApiMain.php.
ApiMain::$mIsBot = null [private] |
Definition at line 740 of file ApiMain.php.
ApiMain::$mIsSysop = null [private] |
Definition at line 741 of file ApiMain.php.
ApiMain::$mModuleNames [private] |
Definition at line 123 of file ApiMain.php.
ApiMain::$mModules [private] |
Definition at line 123 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', 'emailuser' => 'ApiEmailUser', 'watch' => 'ApiWatch', 'patrol' => 'ApiPatrol', 'import' => 'ApiImport', )
Definition at line 58 of file ApiMain.php.
ApiMain::$mPrinter [private] |
Definition at line 123 of file ApiMain.php.
ApiMain::$mRequest [private] |
Definition at line 124 of file ApiMain.php.
ApiMain::$mResult [private] |
Definition at line 124 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 112 of file ApiMain.php.
ApiMain::$mShowVersions [private] |
Definition at line 124 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().