summaryrefslogtreecommitdiff
path: root/includes/api/ApiMain.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2008-03-21 11:49:34 +0100
committerPierre Schmitz <pierre@archlinux.de>2008-03-21 11:49:34 +0100
commit086ae52d12011746a75f5588e877347bc0457352 (patch)
treee73263c7a29d0f94fafb874562610e16eb292ba8 /includes/api/ApiMain.php
parent749e7fb2bae7bbda855de3c9e319435b9f698ff7 (diff)
Update auf MediaWiki 1.12.0
Diffstat (limited to 'includes/api/ApiMain.php')
-rw-r--r--includes/api/ApiMain.php112
1 files changed, 94 insertions, 18 deletions
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php
index 00b3f63f..874e531c 100644
--- a/includes/api/ApiMain.php
+++ b/includes/api/ApiMain.php
@@ -53,10 +53,26 @@ class ApiMain extends ApiBase {
*/
private static $Modules = array (
'login' => 'ApiLogin',
+ 'logout' => 'ApiLogout',
'query' => 'ApiQuery',
+ 'expandtemplates' => 'ApiExpandTemplates',
+ 'parse' => 'ApiParse',
'opensearch' => 'ApiOpenSearch',
'feedwatchlist' => 'ApiFeedWatchlist',
'help' => 'ApiHelp',
+ 'paraminfo' => 'ApiParamInfo',
+ );
+
+ private static $WriteModules = array (
+ 'rollback' => 'ApiRollback',
+ 'delete' => 'ApiDelete',
+ 'undelete' => 'ApiUndelete',
+ 'protect' => 'ApiProtect',
+ 'block' => 'ApiBlock',
+ 'unblock' => 'ApiUnblock',
+ 'move' => 'ApiMove',
+ #'changerights' => 'ApiChangeRights'
+ # Disabled for now
);
/**
@@ -73,7 +89,11 @@ class ApiMain extends ApiBase {
'xmlfm' => 'ApiFormatXml',
'yaml' => 'ApiFormatYaml',
'yamlfm' => 'ApiFormatYaml',
- 'rawfm' => 'ApiFormatJson'
+ 'rawfm' => 'ApiFormatJson',
+ 'txt' => 'ApiFormatTxt',
+ 'txtfm' => 'ApiFormatTxt',
+ 'dbg' => 'ApiFormatDbg',
+ 'dbgfm' => 'ApiFormatDbg'
);
private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
@@ -108,14 +128,17 @@ class ApiMain extends ApiBase {
if (!$wgUser->isAllowed('read')) {
self::$Modules = array(
- 'login' => self::$Modules['login'],
- 'help' => self::$Modules['help']
+ 'login' => self::$Modules['login'],
+ 'logout' => self::$Modules['logout'],
+ 'help' => self::$Modules['help'],
);
}
}
- global $wgAPIModules; // extension modules
+ global $wgAPIModules, $wgEnableWriteAPI; // extension modules
$this->mModules = $wgAPIModules + self :: $Modules;
+ if($wgEnableWriteAPI)
+ $this->mModules += self::$WriteModules;
$this->mModuleNames = array_keys($this->mModules); // todo: optimize
$this->mFormats = self :: $Formats;
@@ -157,7 +180,7 @@ class ApiMain extends ApiBase {
public function requestWriteMode() {
if (!$this->mEnableWrite)
$this->dieUsage('Editing of this site is disabled. Make sure the $wgEnableWriteAPI=true; ' .
- 'statement is included in the site\'s LocalSettings.php file', 'readonly');
+ 'statement is included in the site\'s LocalSettings.php file', 'noapiwrite');
}
/**
@@ -271,7 +294,7 @@ class ApiMain extends ApiBase {
// Something is seriously wrong
//
$errMessage = array (
- 'code' => 'internal_api_error',
+ 'code' => 'internal_api_error_'. get_class($e),
'info' => "Exception Caught: {$e->getMessage()}"
);
ApiResult :: setContent($errMessage, "\n\n{$e->getTraceAsString()}\n\n");
@@ -287,16 +310,34 @@ class ApiMain extends ApiBase {
* 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();
@@ -326,7 +367,16 @@ class ApiMain extends ApiBase {
protected function printResult($isError) {
$printer = $this->mPrinter;
$printer->profileIn();
+
+ /* If the help message is requested in the default (xmlfm) format,
+ * tell the printer not to escape ampersands so that our links do
+ * not break. */
+ $params = $this->extractRequestParams();
+ $printer->setUnescapeAmps ( ( $this->mAction == 'help' || $isError )
+ && $params['format'] == ApiMain::API_DEFAULT_FORMAT );
+
$printer->initPrinter($isError);
+
$printer->execute();
$printer->closePrinter();
$printer->profileOut();
@@ -335,7 +385,7 @@ class ApiMain extends ApiBase {
/**
* See ApiBase for description.
*/
- protected function getAllowedParams() {
+ public function getAllowedParams() {
return array (
'format' => array (
ApiBase :: PARAM_DFLT => ApiMain :: API_DEFAULT_FORMAT,
@@ -345,25 +395,29 @@ class ApiMain extends ApiBase {
ApiBase :: PARAM_DFLT => 'help',
ApiBase :: PARAM_TYPE => $this->mModuleNames
),
- 'version' => false
+ 'version' => false,
+ 'maxlag' => array (
+ ApiBase :: PARAM_TYPE => 'integer'
+ ),
);
}
/**
* See ApiBase for description.
*/
- protected function getParamDescription() {
+ public function getParamDescription() {
return array (
'format' => 'The format of the output',
'action' => 'What action you would like to perform',
- 'version' => 'When showing help, include version for each module'
+ 'version' => 'When showing help, include version for each module',
+ 'maxlag' => 'Maximum lag'
);
}
/**
* See ApiBase for description.
*/
- protected function getDescription() {
+ public function getDescription() {
return array (
'',
'',
@@ -396,8 +450,9 @@ class ApiMain extends ApiBase {
*/
protected function getCredits() {
return array(
- 'This API is being implemented by Yuri Astrakhan [[User:Yurik]] / <Firstname><Lastname>@gmail.com',
- 'Please leave your comments and suggestions at http://www.mediawiki.org/wiki/API'
+ 'This API is being implemented by Roan Kattouw <Firstname>.<Lastname>@home.nl',
+ 'Please send your comments, suggestions and questions to mediawiki-api@lists.wikimedia.org',
+ 'or file a bug report at http://bugzilla.wikimedia.org/'
);
}
@@ -405,6 +460,8 @@ class ApiMain extends ApiBase {
* Override the parent to generate help messages for all available modules.
*/
public function makeHelpMsg() {
+
+ $this->mPrinter->setHelp();
// Use parent to make default message for the main module
$msg = parent :: makeHelpMsg();
@@ -445,11 +502,12 @@ class ApiMain extends ApiBase {
}
private $mIsBot = null;
-
private $mIsSysop = null;
+ private $mCanApiHighLimits = null;
/**
* Returns true if the currently logged in user is a bot, false otherwise
+ * OBSOLETE, use canApiHighLimits() instead
*/
public function isBot() {
if (!isset ($this->mIsBot)) {
@@ -462,6 +520,7 @@ class ApiMain extends ApiBase {
/**
* Similar to isBot(), this method returns true if the logged in user is
* a sysop, and false if not.
+ * OBSOLETE, use canApiHighLimits() instead
*/
public function isSysop() {
if (!isset ($this->mIsSysop)) {
@@ -471,6 +530,15 @@ class ApiMain extends ApiBase {
return $this->mIsSysop;
}
+
+ public function canApiHighLimits() {
+ if (!isset($this->mCanApiHighLimits)) {
+ global $wgUser;
+ $this->mCanApiHighLimits = $wgUser->isAllowed('apihighlimits');
+ }
+
+ return $this->mCanApiHighLimits;
+ }
public function getShowVersions() {
return $this->mShowVersions;
@@ -483,7 +551,7 @@ class ApiMain extends ApiBase {
public function getVersion() {
$vers = array ();
$vers[] = 'MediaWiki ' . SpecialVersion::getVersion();
- $vers[] = __CLASS__ . ': $Id: ApiMain.php 25364 2007-08-31 15:23:48Z tstarling $';
+ $vers[] = __CLASS__ . ': $Id: ApiMain.php 31484 2008-03-03 05:46:20Z brion $';
$vers[] = ApiBase :: getBaseVersion();
$vers[] = ApiFormatBase :: getBaseVersion();
$vers[] = ApiQueryBase :: getBaseVersion();
@@ -515,6 +583,13 @@ class ApiMain extends ApiBase {
protected function addFormat( $fmtName, $fmtClass ) {
$this->mFormats[$fmtName] = $fmtClass;
}
+
+ /**
+ * Get the array mapping module names to class names
+ */
+ function getModules() {
+ return $this->mModules;
+ }
}
/**
@@ -539,3 +614,4 @@ class UsageException extends Exception {
}
}
+