本文整理汇总了PHP中ApiBase::dieUsage方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiBase::dieUsage方法的具体用法?PHP ApiBase::dieUsage怎么用?PHP ApiBase::dieUsage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiBase
的用法示例。
在下文中一共展示了ApiBase::dieUsage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeAction
/**
* Execute the actual module, without any error handling
*/
protected function executeAction()
{
// First add the id to the top element
if ($this->mRequest->getCheck('requestid')) {
$this->getResult()->addValue(null, 'requestid', $this->mRequest->getVal('requestid'));
}
$params = $this->extractRequestParams();
$this->mShowVersions = $params['version'];
$this->mAction = $params['action'];
if (!is_string($this->mAction)) {
$this->dieUsage("The API requires a valid action parameter", 'unknown_action');
}
// Instantiate the module requested by the user
$module = new $this->mModules[$this->mAction]($this, $this->mAction);
if ($module->shouldCheckMaxlag() && isset($params['maxlag'])) {
// Check for maxlag
global $wgShowHostnames;
$maxLag = $params['maxlag'];
list($host, $lag) = wfGetLB()->getMaxLag();
if ($lag > $maxLag) {
header('Retry-After: ' . max(intval($maxLag), 5));
header('X-Database-Lag: ' . intval($lag));
// XXX: should we return a 503 HTTP error code like wfMaxlagError() does?
if ($wgShowHostnames) {
ApiBase::dieUsage("Waiting for {$host}: {$lag} seconds lagged", 'maxlag');
} else {
ApiBase::dieUsage("Waiting for a database server: {$lag} seconds lagged", 'maxlag');
}
return;
}
}
if (!$this->mInternalMode) {
// Ignore mustBePosted() for internal calls
if ($module->mustBePosted() && !$this->mRequest->wasPosted()) {
$this->dieUsage("The {$this->mAction} module requires a POST request", 'mustbeposted');
}
// See if custom printer is used
$this->mPrinter = $module->getCustomPrinter();
if (is_null($this->mPrinter)) {
// Create an appropriate printer
$this->mPrinter = $this->createPrinterByName($params['format']);
}
if ($this->mPrinter->getNeedsRawData()) {
$this->getResult()->setRawMode();
}
}
// Execute
$module->profileIn();
$module->execute();
wfRunHooks('APIAfterExecute', array(&$module));
$module->profileOut();
if (!$this->mInternalMode) {
// Print result data
$this->printResult(false);
}
}
示例2: setupModule
/**
* Set up the module for response
* @return ApiBase The module that will handle this action
*/
protected function setupModule()
{
// Instantiate the module requested by the user
// RT #1576 5.12.2008 Bartek
if (class_exists($this->mModules[$this->mAction])) {
$module = new $this->mModules[$this->mAction]($this, $this->mAction);
$this->mModule = $module;
} else {
ApiBase::dieUsage("Trying to load a nonexistant or undefined classname");
return;
}
$moduleParams = $module->extractRequestParams();
// Die if token required, but not provided (unless there is a gettoken parameter)
if (isset($moduleParams['gettoken'])) {
$gettoken = $moduleParams['gettoken'];
} else {
$gettoken = false;
}
$salt = $module->getTokenSalt();
if ($salt !== false && !$gettoken) {
if (!isset($moduleParams['token'])) {
$this->dieUsageMsg(array('missingparam', 'token'));
} else {
if (!$this->getUser()->matchEditToken($moduleParams['token'], $salt, $this->getRequest())) {
$this->dieUsageMsg('sessionfailure');
}
}
}
return $module;
}
示例3: executeAction
/**
* Execute the actual module, without any error handling
*/
protected function executeAction()
{
$params = $this->extractRequestParams();
$this->mShowVersions = $params['version'];
$this->mAction = $params['action'];
// Instantiate the module requested by the user
$module = new $this->mModules[$this->mAction]($this, $this->mAction);
if ($module->shouldCheckMaxlag() && isset($params['maxlag'])) {
// Check for maxlag
global $wgLoadBalancer, $wgShowHostnames;
$maxLag = $params['maxlag'];
list($host, $lag) = $wgLoadBalancer->getMaxLag();
if ($lag > $maxLag) {
if ($wgShowHostnames) {
ApiBase::dieUsage("Waiting for {$host}: {$lag} seconds lagged", 'maxlag');
} else {
ApiBase::dieUsage("Waiting for a database server: {$lag} seconds lagged", 'maxlag');
}
return;
}
}
if (!$this->mInternalMode) {
// Ignore mustBePosted() for internal calls
if ($module->mustBePosted() && !$this->mRequest->wasPosted()) {
$this->dieUsage("The {$this->mAction} module requires a POST request", 'mustbeposted');
}
// See if custom printer is used
$this->mPrinter = $module->getCustomPrinter();
if (is_null($this->mPrinter)) {
// Create an appropriate printer
$this->mPrinter = $this->createPrinterByName($params['format']);
}
if ($this->mPrinter->getNeedsRawData()) {
$this->getResult()->setRawMode();
}
}
// Execute
$module->profileIn();
$module->execute();
$module->profileOut();
if (!$this->mInternalMode) {
// Print result data
$this->printResult(false);
}
}