From d656615e9f200af542751e713112ac9be42b135b Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 22 May 2007 04:39:49 +0000 Subject: [PATCH] API: applied the patch by amidaniel to allow the same limits for sysops as for bots. --- api.php | 21 +++++++++++++++++++-- includes/api/ApiBase.php | 12 ++++++------ includes/api/ApiMain.php | 19 ++++++++++++++++++- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/api.php b/api.php index 28c1ef37f6..7db2ce09b1 100644 --- a/api.php +++ b/api.php @@ -1,7 +1,6 @@ @gmail.com @@ -22,6 +21,17 @@ * http://www.gnu.org/copyleft/gpl.html */ +/** + * This file is the entry point for all API queries. It begins by checking + * whether the API is enabled on this wiki; if not, it informs the user that + * s/he should set $wgEnableAPI to true and exits. Otherwise, it constructs + * a new ApiMain using the parameter passed to it as an argument in the URL + * ('?action=') and with write-enabled set to the value of $wgEnableWriteAPI + * as specified in LocalSettings.php. It then invokes "execute()" on the + * ApiMain object instance, which produces output in the format sepecified + * in the URL. + */ + // Initialise common code require (dirname(__FILE__) . '/includes/WebStart.php'); @@ -34,9 +44,16 @@ if (!$wgEnableAPI) { die(-1); } +/* Construct an ApiMain with the arguments passed via the URL. What we get back + * is some form of an ApiMain, possibly even one that produces an error message, + * but we don't care here, as that is handled by the ctor. + */ $processor = new ApiMain($wgRequest, $wgEnableWriteAPI); + +// Generate the output. $processor->execute(); +// Log what the user did, for book-keeping purposes. wfProfileOut('api.php'); wfLogProfilingData(); ?> diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 5c83567b5e..723a6792f6 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -47,10 +47,10 @@ abstract class ApiBase { const PARAM_MAX2 = 4; const PARAM_MIN = 5; - const LIMIT_BIG1 = 500; // Fast query, user's limit - const LIMIT_BIG2 = 5000; // Fast query, bot's limit - const LIMIT_SML1 = 50; // Slow query, user's limit - const LIMIT_SML2 = 500; // Slow query, bot's limit + const LIMIT_BIG1 = 500; // Fast query, std user limit + const LIMIT_BIG2 = 5000; // Fast query, bot/sysop limit + const LIMIT_SML1 = 50; // Slow query, std user limit + const LIMIT_SML2 = 500; // Slow query, bot/sysop limit private $mMainModule, $mModuleName, $mParamPrefix; @@ -475,9 +475,9 @@ abstract class ApiBase { $this->dieUsage("$varname may not be less than $min (set to $value)", $varname); } - if ($this->getMain()->isBot()) { + if ($this->getMain()->isBot() || $this->getMain()->isSysop()) { if ($value > $botMax) { - $this->dieUsage("$varname may not be over $botMax (set to $value) for bots", $varname); + $this->dieUsage("$varname may not be over $botMax (set to $value) for bots or sysops", $varname); } } elseif ($value > $max) { diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 2319a02d02..54b9f8f697 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -80,7 +80,8 @@ class ApiMain extends ApiBase { private $mResult, $mShowVersions, $mEnableWrite, $mRequest, $mInternalMode, $mSquidMaxage; /** - * Constructor + * Constructs an instance of ApiMain that utilizes the module and format specified by $request. + * * @param $request object - if this is an instance of FauxRequest, errors are thrown and no printing occurs * @param $enableWrite bool should be set to true if the api may modify data */ @@ -377,6 +378,8 @@ class ApiMain extends ApiBase { private $mIsBot = null; + private $mIsSysop = null; + /** * Returns true if the currently logged in user is a bot, false otherwise */ @@ -387,6 +390,20 @@ class ApiMain extends ApiBase { } return $this->mIsBot; } + + /** + * Similar to isBot(), this method returns true if the logged in user is + * a sysop, and false if not. + */ + public function isSysop() { + if (!isset ($this->mIsSysop)) { + global $wgUser; + $this->mIsSysop = in_array( 'sysop', + $wgUser->getGroups()); + } + + return $this->mIsSysop; + } public function getShowVersions() { return $this->mShowVersions; -- 2.20.1