API: applied the patch by amidaniel to allow the same limits for sysops as for bots.
authorYuri Astrakhan <yurik@users.mediawiki.org>
Tue, 22 May 2007 04:39:49 +0000 (04:39 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Tue, 22 May 2007 04:39:49 +0000 (04:39 +0000)
api.php
includes/api/ApiBase.php
includes/api/ApiMain.php

diff --git a/api.php b/api.php
index 28c1ef3..7db2ce0 100644 (file)
--- a/api.php
+++ b/api.php
@@ -1,7 +1,6 @@
 <?php
 
-
-/**
+/*
 * API for MediaWiki 1.8+
 *
 * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
 * 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();
 ?>
index 5c83567..723a679 100644 (file)
@@ -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) {
index 2319a02..54b9f8f 100644 (file)
@@ -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;