* API: Refactored per brion's suggestions
authorYuri Astrakhan <yurik@users.mediawiki.org>
Wed, 27 Sep 2006 05:13:48 +0000 (05:13 +0000)
committerYuri Astrakhan <yurik@users.mediawiki.org>
Wed, 27 Sep 2006 05:13:48 +0000 (05:13 +0000)
* API: began query revisions implementation (incomplete)

17 files changed:
api.php
includes/api/ApiBase.php
includes/api/ApiFormatBase.php
includes/api/ApiFormatJson.php
includes/api/ApiFormatXml.php
includes/api/ApiFormatYaml.php
includes/api/ApiHelp.php
includes/api/ApiLogin.php
includes/api/ApiMain.php
includes/api/ApiPageSet.php
includes/api/ApiQuery.php
includes/api/ApiQueryAllpages.php
includes/api/ApiQueryBase.php
includes/api/ApiQueryInfo.php
includes/api/ApiQueryRevisions.php
includes/api/ApiQuerySiteinfo.php
includes/api/ApiResult.php

diff --git a/api.php b/api.php
index d862d6c..d75ef10 100644 (file)
--- a/api.php
+++ b/api.php
@@ -29,11 +29,6 @@ $wgApiStartTime = microtime(true);
  */\r
 define('API_DEFAULT_FORMAT', 'xmlfm');\r
 \r
-/**\r
- * All API classes reside in this directory\r
- */\r
-$wgApiDirectory = 'includes/api/';\r
-\r
 /**\r
  * List of classes and containing files.\r
  */\r
@@ -89,7 +84,7 @@ $wgApiFormats = array (
 );\r
 \r
 // Initialise common code\r
-require_once ('./includes/WebStart.php');\r
+require (dirname(__FILE__) . "/includes/WebStart.php");\r
 wfProfileIn('api.php');\r
 \r
 // Verify that the API has not been disabled\r
@@ -102,23 +97,20 @@ if (!isset ($wgEnableAPI) || !$wgEnableAPI) {
        die(-1);\r
 }\r
 \r
-ApiInitAutoloadClasses($wgApiAutoloadClasses, $wgApiDirectory);\r
+apiInitAutoloadClasses($wgApiAutoloadClasses, "$IP/includes/api/");\r
 $processor = new ApiMain($wgApiStartTime, $wgApiModules, $wgApiFormats);\r
-$processor->Execute();\r
+$processor->execute();\r
 \r
 wfProfileOut('api.php');\r
 wfLogProfilingData();\r
 exit; // Done!\r
 \r
-function ApiInitAutoloadClasses($apiAutoloadClasses, $apiDirectory) {\r
+function apiInitAutoloadClasses($apiAutoloadClasses, $apiDirectory) {\r
 \r
        // Prefix each api class with the proper prefix,\r
        // and append them to $wgAutoloadClasses\r
        global $wgAutoloadClasses;\r
 \r
-       if (!isset ($wgAutoloadClasses))\r
-               $wgAutoloadClasses = array ();\r
-\r
        foreach ($apiAutoloadClasses as $className => $classFile)\r
                $wgAutoloadClasses[$className] = $apiDirectory . $classFile;\r
 }\r
index 649ae51..1f87592 100644 (file)
@@ -46,42 +46,42 @@ abstract class ApiBase {
        /**\r
         * Executes this module\r
         */\r
-       abstract function Execute();\r
+       abstract function execute();\r
 \r
        /**\r
         * Get main module\r
         */\r
-       public function GetMain() {\r
+       public function getMain() {\r
                return $this->mMainModule;\r
        }\r
 \r
        /**\r
         * If this module's $this is the same as $this->mMainModule, its the root, otherwise no\r
         */\r
-       public function IsMain() {\r
+       public function isMain() {\r
                return $this === $this->mMainModule;\r
        }\r
 \r
        /**\r
         * Get result object\r
         */\r
-       public function GetResult() {\r
-               // Main module has GetResult() method overriden\r
+       public function getResult() {\r
+               // Main module has getResult() method overriden\r
                // Safety - avoid infinite loop:\r
-               if ($this->IsMain())\r
-                       $this->DieDebug(__METHOD__ .\r
+               if ($this->isMain())\r
+                       $this->dieDebug(__METHOD__ .\r
                        ' base method was called on main module. ');\r
-               return $this->GetMain()->GetResult();\r
+               return $this->getMain()->getResult();\r
        }\r
 \r
        /**\r
         * Generates help message for this module, or false if there is no description\r
         */\r
-       public function MakeHelpMsg() {\r
+       public function makeHelpMsg() {\r
 \r
                static $lnPrfx = "\n  ";\r
 \r
-               $msg = $this->GetDescription();\r
+               $msg = $this->getDescription();\r
 \r
                if ($msg !== false) {\r
 \r
@@ -92,9 +92,9 @@ abstract class ApiBase {
                        $msg = $lnPrfx . implode($lnPrfx, $msg) . "\n";\r
 \r
                        // Parameters\r
-                       $params = $this->GetAllowedParams();\r
+                       $params = $this->getAllowedParams();\r
                        if ($params !== false) {\r
-                               $paramsDescription = $this->GetParamDescription();\r
+                               $paramsDescription = $this->getParamDescription();\r
                                $msg .= "Parameters:\n";\r
                                foreach (array_keys($params) as $paramName) {\r
                                        $desc = isset ($paramsDescription[$paramName]) ? $paramsDescription[$paramName] : '';\r
@@ -105,7 +105,7 @@ abstract class ApiBase {
                        }\r
 \r
                        // Examples\r
-                       $examples = $this->GetExamples();\r
+                       $examples = $this->getExamples();\r
                        if ($examples !== false) {\r
                                if (!is_array($examples))\r
                                        $examples = array (\r
@@ -122,40 +122,40 @@ abstract class ApiBase {
        /**\r
         * Returns the description string for this module\r
         */\r
-       protected function GetDescription() {\r
+       protected function getDescription() {\r
                return false;\r
        }\r
 \r
        /**\r
         * Returns usage examples for this module. Return null if no examples are available.\r
         */\r
-       protected function GetExamples() {\r
+       protected function getExamples() {\r
                return false;\r
        }\r
 \r
        /**\r
         * Returns an array of allowed parameters (keys) => default value for that parameter\r
         */\r
-       protected function GetAllowedParams() {\r
+       protected function getAllowedParams() {\r
                return false;\r
        }\r
 \r
        /**\r
         * Returns the description string for the given parameter.\r
         */\r
-       protected function GetParamDescription() {\r
+       protected function getParamDescription() {\r
                return false;\r
        }\r
 \r
        /**\r
-       * Using GetAllowedParams(), makes an array of the values provided by the user,\r
+       * Using getAllowedParams(), makes an array of the values provided by the user,\r
        * with key being the name of the variable, and value - validated value from user or default.\r
        * This method can be used to generate local variables using extract().\r
        */\r
-       public function ExtractRequestParams() {\r
+       public function extractRequestParams() {\r
                global $wgRequest;\r
 \r
-               $params = $this->GetAllowedParams();\r
+               $params = $this->getAllowedParams();\r
                $results = array ();\r
 \r
                foreach ($params as $param => $enumParams) {\r
@@ -184,17 +184,17 @@ abstract class ApiBase {
 \r
                                if ($default !== false) {\r
                                        // Having a default value of anything other than 'false' is pointless\r
-                                       $this->DieDebug("Boolean param $param's default is set to '$default'");\r
+                                       $this->dieDebug("Boolean param $param's default is set to '$default'");\r
                                }\r
                        }\r
 \r
                        $value = $wgRequest->getVal($param, $default);\r
 \r
                        if (isset ($value) && ($multi || is_array($type)))\r
-                               $value = $this->ParseMultiValue($param, $value, $multi, is_array($type) ? $type : null);\r
+                               $value = $this->parseMultiValue($param, $value, $multi, is_array($type) ? $type : null);\r
 \r
                        // More validation only when choices were not given\r
-                       // choices were validated in ParseMultiValue()\r
+                       // choices were validated in parseMultiValue()\r
                        if (!is_array($type) && isset ($value)) {\r
 \r
                                switch ($type) {\r
@@ -207,25 +207,25 @@ abstract class ApiBase {
                                                break;\r
                                        case 'limit' :\r
                                                if (!isset ($enumParams[GN_ENUM_MAX1]) || !isset ($enumParams[GN_ENUM_MAX2]))\r
-                                                       $this->DieDebug("MAX1 or MAX2 are not defined for the limit $param");\r
+                                                       $this->dieDebug("MAX1 or MAX2 are not defined for the limit $param");\r
                                                if ($multi)\r
-                                                       $this->DieDebug("Multi-values not supported for $param");\r
+                                                       $this->dieDebug("Multi-values not supported for $param");\r
                                                $min = isset ($enumParams[GN_ENUM_MIN]) ? $enumParams[GN_ENUM_MIN] : 0;\r
                                                $value = intval($value);\r
-                                               $this->ValidateLimit($param, $value, $min, $enumParams[GN_ENUM_MAX1], $enumParams[GN_ENUM_MAX2]);\r
+                                               $this->validateLimit($param, $value, $min, $enumParams[GN_ENUM_MAX1], $enumParams[GN_ENUM_MAX2]);\r
                                                break;\r
                                        case 'boolean' :\r
                                                if ($multi)\r
-                                                       $this->DieDebug("Multi-values not supported for $param");\r
+                                                       $this->dieDebug("Multi-values not supported for $param");\r
                                                $value = isset ($value);\r
                                                break;\r
                                        case 'timestamp' :\r
                                                if ($multi)\r
-                                                       $this->DieDebug("Multi-values not supported for $param");\r
+                                                       $this->dieDebug("Multi-values not supported for $param");\r
                                                $value = $this->prepareTimestamp($value); // Adds quotes around timestamp                                                       \r
                                                break;\r
                                        default :\r
-                                               $this->DieDebug("Param $param's type is unknown - $type");\r
+                                               $this->dieDebug("Param $param's type is unknown - $type");\r
 \r
                                }\r
                        }\r
@@ -246,16 +246,16 @@ abstract class ApiBase {
        * @param allowedValues - An array of values to check against. If null, all values are accepted.\r
        * @return (allowMultiple ? an_array_of_values : a_single_value) \r
        */\r
-       protected function ParseMultiValue($valueName, $value, $allowMultiple, $allowedValues) {\r
+       protected function parseMultiValue($valueName, $value, $allowMultiple, $allowedValues) {\r
                $valuesList = explode('|', $value);\r
                if (!$allowMultiple && count($valuesList) != 1) {\r
                        $possibleValues = is_array($allowedValues) ? "of '" . implode("', '", $allowedValues) . "'" : '';\r
-                       $this->DieUsage("Only one $possibleValues is allowed for parameter '$valueName'", "multival_$valueName");\r
+                       $this->dieUsage("Only one $possibleValues is allowed for parameter '$valueName'", "multival_$valueName");\r
                }\r
                if (is_array($allowedValues)) {\r
                        $unknownValues = array_diff($valuesList, $allowedValues);\r
                        if ($unknownValues) {\r
-                               $this->DieUsage("Unrecognised value" . (count($unknownValues) > 1 ? "s '" : " '") . implode("', '", $unknownValues) . "' for parameter '$valueName'", "unknown_$valueName");\r
+                               $this->dieUsage("Unrecognised value" . (count($unknownValues) > 1 ? "s '" : " '") . implode("', '", $unknownValues) . "' for parameter '$valueName'", "unknown_$valueName");\r
                        }\r
                }\r
 \r
@@ -276,14 +276,14 @@ abstract class ApiBase {
        /**\r
        * Validate the value against the minimum and user/bot maximum limits. Prints usage info on failure.\r
        */\r
-       function ValidateLimit($varname, $value, $min, $max, $botMax) {\r
+       function validateLimit($varname, $value, $min, $max, $botMax) {\r
                global $wgUser;\r
 \r
                if ($value < $min) {\r
                        $this->dieUsage("$varname may not be less than $min (set to $value)", $varname);\r
                }\r
 \r
-               if ($this->GetMain()->IsBot()) {\r
+               if ($this->getMain()->isBot()) {\r
                        if ($value > $botMax) {\r
                                $this->dieUsage("$varname may not be over $botMax (set to $value) for bots", $varname);\r
                        }\r
@@ -297,12 +297,98 @@ abstract class ApiBase {
        /**\r
         * Call main module's error handler \r
         */\r
-       public function DieUsage($description, $errorCode, $httpRespCode = 0) {\r
-               $this->GetMain()->MainDieUsage($description, $errorCode, $httpRespCode);\r
+       public function dieUsage($description, $errorCode, $httpRespCode = 0) {\r
+               $this->getMain()->mainDieUsage($description, $errorCode, $httpRespCode);\r
        }\r
 \r
-       protected function DieDebug($message) {\r
+       /**\r
+        * Internal code errors should be reported with this method\r
+        */\r
+       protected function dieDebug($message) {\r
                wfDebugDieBacktrace("Internal error in '{get_class($this)}': $message");\r
        }\r
+       \r
+       /**\r
+        * Profiling: total module execution time\r
+        */\r
+       private $mTimeIn = 0, $mModuleTime = 0; \r
+       \r
+       /**\r
+        * Start module profiling\r
+        */\r
+       public function profileIn()\r
+       {\r
+               if ($this->mTimeIn !== 0)\r
+                       $this->dieDebug(__FUNCTION__ . ' called twice without calling profileOut()');\r
+               $this->mTimeIn = microtime(true);\r
+       }\r
+       \r
+       /**\r
+        * End module profiling\r
+        */\r
+       public function profileOut()\r
+       {\r
+               if ($this->mTimeIn === 0)\r
+                       $this->dieDebug(__FUNCTION__ . ' called without calling profileIn() first');\r
+               if ($this->mDBTimeIn !== 0)\r
+                       $this->dieDebug(__FUNCTION__ . ' must be called after database profiling is done with profileDBOut()');\r
+\r
+               $this->mModuleTime += microtime(true) - $this->mTimeIn;\r
+               $this->mTimeIn = 0;\r
+       }\r
+       \r
+       /**\r
+        * Total time the module was executed\r
+        */\r
+       public function getProfileTime()\r
+       {\r
+               if ($this->mTimeIn !== 0)\r
+                       $this->dieDebug(__FUNCTION__ . ' called without calling profileOut() first');\r
+               return $this->mModuleTime;\r
+       }\r
+       \r
+       /**\r
+        * Profiling: database execution time\r
+        */\r
+       private $mDBTimeIn = 0, $mDBTime = 0; \r
+       \r
+       /**\r
+        * Start module profiling\r
+        */\r
+       public function profileDBIn()\r
+       {\r
+               if ($this->mTimeIn === 0)\r
+                       $this->dieDebug(__FUNCTION__ . ' must be called while profiling the entire module with profileIn()');\r
+               if ($this->mDBTimeIn !== 0)\r
+                       $this->dieDebug(__FUNCTION__ . ' called twice without calling profileDBOut()');\r
+               $this->mDBTimeIn = microtime(true);\r
+       }\r
+       \r
+       /**\r
+        * End database profiling\r
+        */\r
+       public function profileDBOut()\r
+       {\r
+               if ($this->mTimeIn === 0)\r
+                       $this->dieDebug(__FUNCTION__ . ' must be called while profiling the entire module with profileIn()');\r
+               if ($this->mDBTimeIn === 0)\r
+                       $this->dieDebug(__FUNCTION__ . ' called without calling profileDBIn() first');\r
+\r
+               $time = microtime(true) - $this->mDBTimeIn;\r
+               $this->mDBTimeIn = 0;\r
+\r
+               $this->mDBTime += $time;\r
+               $this->getMain()->mDBTime += $time;\r
+       }\r
+       \r
+       /**\r
+        * Total time the module used the database\r
+        */\r
+       public function getProfileDBTime()\r
+       {\r
+               if ($this->mDBTimeIn !== 0)\r
+                       $this->dieDebug(__FUNCTION__ . ' called without calling profileDBOut() first');\r
+               return $this->mDBTime;\r
+       }\r
 }\r
 ?>
\ No newline at end of file
index 716201f..f0e9921 100644 (file)
@@ -50,12 +50,12 @@ abstract class ApiFormatBase extends ApiBase {
 
        /**
         * Overriding class returns the mime type that should be sent to the client.
-        * This method is not called if GetIsHtml() returns true.
+        * This method is not called if getIsHtml() returns true.
         * @return string
         */
-       public abstract function GetMimeType();
+       public abstract function getMimeType();
 
-       public function GetNeedsRawData() {
+       public function getNeedsRawData() {
                return false;
        }
 
@@ -64,7 +64,7 @@ abstract class ApiFormatBase extends ApiBase {
         * The default implementation assumes that formats ending with 'fm' 
         * should be formatted in HTML. 
         */
-       public function GetIsHtml() {
+       public function getIsHtml() {
                return $this->mIsHtml;
        }
 
@@ -73,9 +73,9 @@ abstract class ApiFormatBase extends ApiBase {
         * This method must be the first outputing method during execution.
         * A help screen's header is printed for the HTML-based output
         */
-       function InitPrinter($isError) {
-               $isHtml = $this->GetIsHtml();
-               $mime = $isHtml ? 'text/html' : $this->GetMimeType();
+       function initPrinter($isError) {
+               $isHtml = $this->getIsHtml();
+               $mime = $isHtml ? 'text/html' : $this->getMimeType();
                header("Content-Type: $mime; charset=utf-8;");
 
                if ($isHtml) {
@@ -111,8 +111,8 @@ abstract class ApiFormatBase extends ApiBase {
        /**
         * Finish printing. Closes HTML tags.
         */
-       public function ClosePrinter() {
-               if ($this->GetIsHtml()) {
+       public function closePrinter() {
+               if ($this->getIsHtml()) {
 ?>
                </pre>
                </body>
@@ -122,9 +122,9 @@ abstract class ApiFormatBase extends ApiBase {
                }
        }
 
-       public function PrintText($text) {
-               if ($this->GetIsHtml())
-                       echo $this->FormatHTML($text);
+       public function printText($text) {
+               if ($this->getIsHtml())
+                       echo $this->formatHTML($text);
                else
                        echo $text;
        }
@@ -133,7 +133,7 @@ abstract class ApiFormatBase extends ApiBase {
        * Prety-print various elements in HTML format, such as xml tags and URLs.
        * This method also replaces any "<" with &lt;
        */
-       protected function FormatHTML($text) {
+       protected function formatHTML($text) {
                // encode all tags as safe blue strings
                $text = ereg_replace('\<([^>]+)\>', '<font color=blue>&lt;\1&gt;</font>', $text);
                // identify URLs
@@ -149,7 +149,7 @@ abstract class ApiFormatBase extends ApiBase {
        /**
         * Returns usage examples for this format.
         */
-       protected function GetExamples() {
+       protected function getExamples() {
                return 'api.php?action=query&meta=siteinfo&si=namespaces&format=' . $this->mOriginalFormat;
        }
 }
index 3563de3..b24abfd 100644 (file)
@@ -35,17 +35,17 @@ class ApiFormatJson extends ApiFormatBase {
                parent :: __construct($main, $format);
        }
 
-       public function GetMimeType() {
+       public function getMimeType() {
                return 'application/json';
        }
 
-       public function Execute() {
-               require_once ('ApiFormatJson_json.php');
+       public function execute() {
+               require ('ApiFormatJson_json.php');
                $json = new Services_JSON();
-               $this->PrintText($json->encode($this->GetResult()->GetData(), true));
+               $this->printText($json->encode($this->getResult()->getData(), true));
        }
 
-       protected function GetDescription() {
+       protected function getDescription() {
                return 'Output data in JSON format';
        }
 }
index b27763b..06b93a0 100644 (file)
@@ -35,25 +35,25 @@ class ApiFormatXml extends ApiFormatBase {
                parent :: __construct($main, $format);
        }
 
-       public function GetMimeType() {
+       public function getMimeType() {
                return 'text/xml';
        }
 
-       public function GetNeedsRawData() {
+       public function getNeedsRawData() {
                return true;
        }
 
-       public function Execute() {
+       public function execute() {
                $xmlindent = null;
-               extract($this->ExtractRequestParams());
+               extract($this->extractRequestParams());
 
-               if ($xmlindent || $this->GetIsHtml())
+               if ($xmlindent || $this->getIsHtml())
                        $xmlindent = -2;
                else
                        $xmlindent = null;
 
-               $this->PrintText('<?xml version="1.0" encoding="utf-8"?>');
-               $this->recXmlPrint('api', $this->GetResult()->GetData(), $xmlindent);
+               $this->printText('<?xml version="1.0" encoding="utf-8"?>');
+               $this->recXmlPrint('api', $this->getResult()->getData(), $xmlindent);
        }
 
        /**
@@ -82,14 +82,14 @@ class ApiFormatXml extends ApiFormatBase {
                                        $subElemContent = $elemValue['*'];
                                        unset ($elemValue['*']);
                                        if (gettype($subElemContent) === 'array') {
-                                               $this->PrintText($indstr . wfElement($elemName, $elemValue, null));
+                                               $this->printText($indstr . wfElement($elemName, $elemValue, null));
                                                $this->recXmlPrint($elemName, $subElemContent, $indent);
-                                               $this->PrintText($indstr . "</$elemName>");
+                                               $this->printText($indstr . "</$elemName>");
                                        } else {
-                                               $this->PrintText($indstr . wfElement($elemName, $elemValue, $subElemContent));
+                                               $this->printText($indstr . wfElement($elemName, $elemValue, $subElemContent));
                                        }
                                } else {
-                                       $this->PrintText($indstr . wfElement($elemName, null, null));
+                                       $this->printText($indstr . wfElement($elemName, null, null));
                                        if (array_key_exists('_element', $elemValue)) {
                                                $subElemName = $elemValue['_element'];
                                                foreach ($elemValue as $subElemId => & $subElemValue) {
@@ -102,28 +102,28 @@ class ApiFormatXml extends ApiFormatBase {
                                                        $this->recXmlPrint($subElemName, $subElemValue, $indent);
                                                }
                                        }
-                                       $this->PrintText($indstr . "</$elemName>");
+                                       $this->printText($indstr . "</$elemName>");
                                }
                                break;
                        case 'object' :
                                // ignore
                                break;
                        default :
-                               $this->PrintText($indstr . wfElement($elemName, null, $elemValue));
+                               $this->printText($indstr . wfElement($elemName, null, $elemValue));
                                break;
                }
        }
-       protected function GetDescription() {
+       protected function getDescription() {
                return 'Output data in XML format';
        }
 
-       protected function GetAllowedParams() {
+       protected function getAllowedParams() {
                return array (
                        'xmlindent' => false
                );
        }
 
-       protected function GetParamDescription() {
+       protected function getParamDescription() {
                return array (
                        'xmlindent' => 'Enable XML indentation'
                );
index 1311c90..40b8375 100644 (file)
@@ -35,16 +35,16 @@ class ApiFormatYaml extends ApiFormatBase {
                parent :: __construct($main, $format);
        }
 
-       public function GetMimeType() {
+       public function getMimeType() {
                return 'application/yaml';
        }
 
-       public function Execute() {
-               require_once ('ApiFormatYaml_spyc.php');
-               $this->PrintText(Spyc :: YAMLDump($this->GetResult()->GetData()));
+       public function execute() {
+               require ('ApiFormatYaml_spyc.php');
+               $this->printText(Spyc :: YAMLDump($this->getResult()->getData()));
        }
 
-       protected function GetDescription() {
+       protected function getDescription() {
                return 'Output data in YAML format';
        }
 }
index 907fc2f..bc8aca2 100644 (file)
@@ -38,11 +38,11 @@ class ApiHelp extends ApiBase {
        /**\r
         * Stub module for displaying help when no parameters are given\r
         */\r
-       public function Execute() {\r
-               $this->DieUsage('', 'help');\r
+       public function execute() {\r
+               $this->dieUsage('', 'help');\r
        }\r
 \r
-       protected function GetDescription() {\r
+       protected function getDescription() {\r
                return array (\r
                        'Display this help screen.'\r
                );\r
index ca5a5c7..4a24545 100644 (file)
@@ -35,9 +35,9 @@ class ApiLogin extends ApiBase {
                parent :: __construct($main);
        }
 
-       public function Execute() {
+       public function execute() {
                $lgname = $lgpassword = $lgdomain = null;
-               extract($this->ExtractRequestParams());
+               extract($this->extractRequestParams());
 
                $params = new FauxRequest(array (
                        'wpName' => $lgname,
@@ -76,13 +76,13 @@ class ApiLogin extends ApiBase {
                                $result['result'] = 'AuthEmptyPass';
                                break;
                        default :
-                               $this->DieDebug("Unhandled case value");
+                               $this->dieDebug("Unhandled case value");
                }
 
-               $this->GetResult()->AddMessage('login', null, $result);
+               $this->getResult()->addMessage('login', null, $result);
        }
 
-       protected function GetAllowedParams() {
+       protected function getAllowedParams() {
                return array (
                        'lgname' => '',
                        'lgpassword' => '',
@@ -90,7 +90,7 @@ class ApiLogin extends ApiBase {
                );
        }
 
-       protected function GetParamDescription() {
+       protected function getParamDescription() {
                return array (
                        'lgname' => 'User Name',
                        'lgpassword' => 'Password',
@@ -98,7 +98,7 @@ class ApiLogin extends ApiBase {
                );
        }
 
-       protected function GetDescription() {
+       protected function getDescription() {
                return array (
                        'This module is used to login and get the authentication tokens.'
                );
index e31c879..2f2c12a 100644 (file)
@@ -29,22 +29,6 @@ if (!defined('MEDIAWIKI')) {
        require_once ("ApiBase.php");\r
 }\r
 \r
-/**\r
-* @desc This exception will be thrown when DieUsage is called to stop module execution.\r
-*/\r
-class UsageException extends Exception {\r
-\r
-       private $codestr;\r
-\r
-       public function __construct($message, $codestr) {\r
-               parent :: __construct($message);\r
-               $this->codestr = $codestr;\r
-       }\r
-       public function __toString() {\r
-               return "{$this->codestr}: {$this->message}";\r
-       }\r
-}\r
-\r
 class ApiMain extends ApiBase {\r
 \r
        private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames, $mApiStartTime, $mResult;\r
@@ -66,11 +50,11 @@ class ApiMain extends ApiBase {
                $this->mResult = new ApiResult($this);\r
        }\r
 \r
-       public function GetResult() {\r
+       public function getResult() {\r
                return $this->mResult;\r
        }\r
 \r
-       protected function GetAllowedParams() {\r
+       protected function getAllowedParams() {\r
                return array (\r
                        'format' => array (\r
                                GN_ENUM_DFLT => API_DEFAULT_FORMAT,\r
@@ -83,53 +67,61 @@ class ApiMain extends ApiBase {
                );\r
        }\r
 \r
-       protected function GetParamDescription() {\r
+       protected function getParamDescription() {\r
                return array (\r
                        'format' => 'The format of the output',\r
                        'action' => 'What action you would like to perform'\r
                );\r
        }\r
 \r
-       public function Execute() {\r
+       public function execute() {\r
+               $this->profileIn();\r
                $action = $format = null;\r
                try {\r
-                       extract($this->ExtractRequestParams());\r
+                       extract($this->extractRequestParams());\r
 \r
                        // Create an appropriate printer\r
                        $this->mPrinter = new $this->mFormats[$format] ($this, $format);\r
 \r
                        // Instantiate and execute module requested by the user\r
                        $module = new $this->mModules[$action] ($this, $action);\r
-                       $module->Execute();\r
-                       $this->PrintResult(false);\r
+                       $module->profileIn();\r
+                       $module->execute();\r
+                       $module->profileOut();\r
+                       $this->printResult(false);\r
                } catch (UsageException $e) {\r
-                       // Printer may not be initialized if the ExtractRequestParams() fails for the main module\r
+                       // Printer may not be initialized if the extractRequestParams() fails for the main module\r
                        if (!isset ($this->mPrinter))\r
                                $this->mPrinter = new $this->mFormats[API_DEFAULT_FORMAT] ($this, API_DEFAULT_FORMAT);\r
-                       $this->PrintResult(true);\r
+                       $this->printResult(true);\r
                }\r
+               $this->profileOut();\r
        }\r
 \r
        /**\r
         * Internal printer\r
         */\r
-       private function PrintResult($isError) {\r
-               $this->mPrinter->InitPrinter($isError);\r
-               if (!$this->mPrinter->GetNeedsRawData())\r
-                       $this->GetResult()->SanitizeData();\r
-               $this->mPrinter->Execute();\r
-               $this->mPrinter->ClosePrinter();\r
+       private function printResult($isError) {\r
+               $printer = $this->mPrinter;\r
+               $printer->profileIn();\r
+               $printer->initPrinter($isError);\r
+               if (!$printer->getNeedsRawData())\r
+                       $this->getResult()->SanitizeData();\r
+               $printer->execute();\r
+               $printer->closePrinter();\r
+               $printer->profileOut();\r
        }\r
 \r
-       protected function GetDescription() {\r
+       protected function getDescription() {\r
                return array (\r
                        '',\r
                        'This API allows programs to access various functions of MediaWiki software.',\r
+                       'For more details see API Home Page @ http://meta.wikimedia.org/wiki/API',\r
                        ''\r
                );\r
        }\r
 \r
-       public function MainDieUsage($description, $errorCode, $httpRespCode = 0) {\r
+       public function mainDieUsage($description, $errorCode, $httpRespCode = 0) {\r
                $this->mResult->Reset();\r
                $this->mResult->addMessage('error', null, $errorCode);\r
                if ($httpRespCode === 0)\r
@@ -137,7 +129,7 @@ class ApiMain extends ApiBase {
                else\r
                        header($errorCode, true, $httpRespCode);\r
 \r
-               $this->mResult->addMessage('usage', null, $this->MakeHelpMsg());\r
+               $this->mResult->addMessage('usage', null, $this->makeHelpMsg());\r
 \r
                throw new UsageException($description, $errorCode);\r
        }\r
@@ -145,17 +137,17 @@ class ApiMain extends ApiBase {
        /**\r
         * Override the parent to generate help messages for all available modules.\r
         */\r
-       public function MakeHelpMsg() {\r
+       public function makeHelpMsg() {\r
 \r
                // Use parent to make default message for the main module\r
-               $msg = parent :: MakeHelpMsg();\r
+               $msg = parent :: makeHelpMsg();\r
 \r
                $astriks = str_repeat('*** ', 10);\r
                $msg .= "\n\n$astriks Modules  $astriks\n\n";\r
                foreach ($this->mModules as $moduleName => $moduleClass) {\r
                        $msg .= "* action=$moduleName *";\r
                        $module = new $this->mModules[$moduleName] ($this, $moduleName);\r
-                       $msg2 = $module->MakeHelpMsg();\r
+                       $msg2 = $module->makeHelpMsg();\r
                        if ($msg2 !== false)\r
                                $msg .= $msg2;\r
                        $msg .= "\n";\r
@@ -165,7 +157,7 @@ class ApiMain extends ApiBase {
                foreach ($this->mFormats as $moduleName => $moduleClass) {\r
                        $msg .= "* format=$moduleName *";\r
                        $module = new $this->mFormats[$moduleName] ($this, $moduleName);\r
-                       $msg2 = $module->MakeHelpMsg();\r
+                       $msg2 = $module->makeHelpMsg();\r
                        if ($msg2 !== false)\r
                                $msg .= $msg2;\r
                        $msg .= "\n";\r
@@ -175,7 +167,7 @@ class ApiMain extends ApiBase {
        }\r
 \r
        private $mIsBot = null;\r
-       public function IsBot() {\r
+       public function isBot() {\r
                if (!isset ($this->mIsBot)) {\r
                        global $wgUser;\r
                        $this->mIsBot = $wgUser->isAllowed('bot');\r
@@ -183,4 +175,21 @@ class ApiMain extends ApiBase {
                return $this->mIsBot;\r
        }\r
 }\r
+\r
+/**\r
+* @desc This exception will be thrown when dieUsage is called to stop module execution.\r
+*/\r
+class UsageException extends Exception {\r
+\r
+       private $codestr;\r
+\r
+       public function __construct($message, $codestr) {\r
+               parent :: __construct($message);\r
+               $this->codestr = $codestr;\r
+       }\r
+       public function __toString() {\r
+               return "{$this->codestr}: {$this->message}";\r
+       }\r
+}\r
+\r
 ?>
\ No newline at end of file
index 4d77978..0a32b9a 100644 (file)
@@ -31,43 +31,43 @@ if (!defined('MEDIAWIKI')) {
 
 class ApiPageSet extends ApiQueryBase {
 
-       private $allPages; // [ns][dbkey] => page_id or 0 when missing
-       private $resolveRedirs;
-       private $goodTitles, $missingTitles, $redirectTitles, $normalizedTitles;
+       private $mAllPages; // [ns][dbkey] => page_id or 0 when missing
+       private $mResolveRedirs;
+       private $mGoodTitles, $mMissingTitles, $mRedirectTitles, $mNormalizedTitles;
 
        public function __construct($query, $resolveRedirs) {
                parent :: __construct($query, __CLASS__);
-               $this->resolveRedirs = $resolveRedirs;
+               $this->mResolveRedirs = $resolveRedirs;
 
-               $this->allPages = array ();
-               $this->goodTitles = array ();
-               $this->missingTitles = array ();
-               $this->redirectTitles = array ();
-               $this->normalizedTitles = array ();
+               $this->mAllPages = array ();
+               $this->mGoodTitles = array ();
+               $this->mMissingTitles = array ();
+               $this->mRedirectTitles = array ();
+               $this->mNormalizedTitles = array ();
        }
 
        /**
         * Title objects that were found in the database.
         * @return array page_id (int) => Title (obj)
         */
-       public function GetGoodTitles() {
-               return $this->goodTitles;
+       public function getGoodTitles() {
+               return $this->mGoodTitles;
        }
 
        /**
         * Title objects that were NOT found in the database.
         * @return array of Title objects
         */
-       public function GetMissingTitles() {
-               return $this->missingTitles;
+       public function getMissingTitles() {
+               return $this->mMissingTitles;
        }
 
        /**
         * Get a list of redirects when doing redirect resolution
         * @return array prefixed_title (string) => prefixed_title (string)
         */
-       public function GetRedirectTitles() {
-               return $this->redirectTitles;
+       public function getRedirectTitles() {
+               return $this->mRedirectTitles;
        }
 
        /**
@@ -75,43 +75,15 @@ class ApiPageSet extends ApiQueryBase {
         * with its normalized version.
         * @return array raw_prefixed_title (string) => prefixed_title (string) 
         */
-       public function GetNormalizedTitles() {
-               return $this->normalizedTitles;
+       public function getNormalizedTitles() {
+               return $this->mNormalizedTitles;
        }
 
        /**
-        * Given an array of title strings, convert them into Title objects.
-        * This method validates access rights for the title, 
-        * and appends normalization values to the output.
-        * 
-        * @return LinkBatch of title objects.
+        * Returns the number of unique pages (not revisions) in the set.
         */
-       private function ProcessTitlesStrings($titles) {
-
-               $linkBatch = new LinkBatch();
-
-               foreach ($titles as $titleString) {
-                       $titleObj = Title :: newFromText($titleString);
-
-                       // Validation
-                       if (!$titleObj)
-                               $this->dieUsage("bad title $titleString", 'invalidtitle');
-                       if ($titleObj->getNamespace() < 0)
-                               $this->dieUsage("No support for special page $titleString has been implemented", 'unsupportednamespace');
-                       if (!$titleObj->userCanRead())
-                               $this->dieUsage("No read permission for $titleString", 'titleaccessdenied');
-
-                       $linkBatch->addObj($titleObj);
-
-                       // Make sure we remember the original title that was given to us
-                       // This way the caller can correlate new titles with the originally requested,
-                       // i.e. namespace is localized or capitalization is different
-                       if ($titleString !== $titleObj->getPrefixedText()) {
-                               $this->normalizedTitles[$titleString] = $titleObj->getPrefixedText();
-                       }
-               }
-
-               return $linkBatch;
+       public function getPageCount() {
+               return count($this->getGoodTitles());   
        }
 
        /**
@@ -128,27 +100,28 @@ class ApiPageSet extends ApiQueryBase {
         * #5 Substitute the original LinkBatch object with the new list
         * #6 Repeat from step #1     
         */
-       public function PopulateTitles($titles) {
+       public function populateTitles($titles) {
+               $this->profileIn();
                $pageFlds = array (
                        'page_id',
                        'page_namespace',
                        'page_title'
                );
-               if ($this->resolveRedirs) {
+               if ($this->mResolveRedirs) {
                        $pageFlds[] = 'page_is_redirect';
                }
 
                // Get validated and normalized title objects
-               $linkBatch = $this->ProcessTitlesStrings($titles);
+               $linkBatch = $this->processTitlesStrings($titles);
 
-               $db = $this->GetDB();
+               $db = $this->getDB();
 
                //
                // Repeat until all redirects have been resolved
                //
                while (false !== ($set = $linkBatch->constructSet('page', $db))) {
 
-                       // Hack: Get the ns:titles stored in array(ns => array(titles)) format
+                       // Hack: get the ns:titles stored in array(ns => array(titles)) format
                        $remaining = $linkBatch->data;
 
                        $redirectIds = array ();
@@ -156,17 +129,19 @@ class ApiPageSet extends ApiQueryBase {
                        //
                        // Get data about $linkBatch from `page` table
                        //
+                       $this->profileDBIn();
                        $res = $db->select('page', $pageFlds, $set, __CLASS__ . '::' . __FUNCTION__);
+                       $this->profileDBOut();
                        while ($row = $db->fetchObject($res)) {
 
                                unset ($remaining[$row->page_namespace][$row->page_title]);
                                $title = Title :: makeTitle($row->page_namespace, $row->page_title);
-                               $this->allPages[$row->page_namespace][$row->page_title] = $row->page_id;
+                               $this->mAllPages[$row->page_namespace][$row->page_title] = $row->page_id;
 
-                               if ($this->resolveRedirs && $row->page_is_redirect == '1') {
+                               if ($this->mResolveRedirs && $row->page_is_redirect == '1') {
                                        $redirectIds[$row->page_id] = $title;
                                } else {
-                                       $this->goodTitles[$row->page_id] = $title;
+                                       $this->mGoodTitles[$row->page_id] = $title;
                                }
                        }
                        $db->freeResult($res);
@@ -176,12 +151,12 @@ class ApiPageSet extends ApiQueryBase {
                        //
                        foreach ($remaining as $ns => $dbkeys) {
                                foreach ($dbkeys as $dbkey => $nothing) {
-                                       $this->missingTitles[] = Title :: makeTitle($ns, $dbkey);
-                                       $this->allPages[$ns][$dbkey] = 0;
+                                       $this->mMissingTitles[] = Title :: makeTitle($ns, $dbkey);
+                                       $this->mAllPages[$ns][$dbkey] = 0;
                                }
                        }
 
-                       if (!$this->resolveRedirs || empty ($redirectIds))
+                       if (!$this->mResolveRedirs || empty ($redirectIds))
                                break;
 
                        //
@@ -192,6 +167,7 @@ class ApiPageSet extends ApiQueryBase {
                        $linkBatch = new LinkBatch();
 
                        // find redirect targets for all redirect pages
+                       $this->profileDBIn();
                        $res = $db->select('pagelinks', array (
                                'pl_from',
                                'pl_namespace',
@@ -199,7 +175,8 @@ class ApiPageSet extends ApiQueryBase {
                        ), array (
                                'pl_from' => array_keys($redirectIds
                        )), __CLASS__ . '::' . __FUNCTION__);
-
+                       $this->profileDBOut();
+                       
                        while ($row = $db->fetchObject($res)) {
 
                                // Bug 7304 workaround 
@@ -210,22 +187,58 @@ class ApiPageSet extends ApiQueryBase {
 
                                        $titleStrFrom = $redirectIds[$row->pl_from]->getPrefixedText();
                                        $titleStrTo = Title :: makeTitle($row->pl_namespace, $row->pl_title)->getPrefixedText();
-                                       $this->redirectTitles[$titleStrFrom] = $titleStrTo;
+                                       $this->mRedirectTitles[$titleStrFrom] = $titleStrTo;
 
                                        unset ($redirectIds[$row->pl_from]); // remove line when 7304 is fixed
 
                                        // Avoid an infinite loop by checking if we have already processed this target
-                                       if (!isset ($this->allPages[$row->pl_namespace][$row->pl_title])) {
+                                       if (!isset ($this->mAllPages[$row->pl_namespace][$row->pl_title])) {
                                                $linkBatch->add($row->pl_namespace, $row->pl_title);
                                        }
                                }
                        }
                        $db->freeResult($res);
                }
+               $this->profileOut();            
+       }
+       
+       /**
+        * Given an array of title strings, convert them into Title objects.
+        * This method validates access rights for the title, 
+        * and appends normalization values to the output.
+        * 
+        * @return LinkBatch of title objects.
+        */
+       private function processTitlesStrings($titles) {
+
+               $linkBatch = new LinkBatch();
+
+               foreach ($titles as $titleString) {
+                       $titleObj = Title :: newFromText($titleString);
+
+                       // Validation
+                       if (!$titleObj)
+                               $this->dieUsage("bad title $titleString", 'invalidtitle');
+                       if ($titleObj->getNamespace() < 0)
+                               $this->dieUsage("No support for special page $titleString has been implemented", 'unsupportednamespace');
+                       if (!$titleObj->userCanRead())
+                               $this->dieUsage("No read permission for $titleString", 'titleaccessdenied');
+
+                       $linkBatch->addObj($titleObj);
+
+                       // Make sure we remember the original title that was given to us
+                       // This way the caller can correlate new titles with the originally requested,
+                       // i.e. namespace is localized or capitalization is different
+                       if ($titleString !== $titleObj->getPrefixedText()) {
+                               $this->mNormalizedTitles[$titleString] = $titleObj->getPrefixedText();
+                       }
+               }
+
+               return $linkBatch;
        }
 
-       public function Execute() {
-               $this->DieDebug("Execute() is not supported on this object");
+       public function execute() {
+               $this->dieDebug("execute() is not supported on this object");
        }
 }
 ?>
\ No newline at end of file
index f122089..20ec0e8 100644 (file)
@@ -75,13 +75,13 @@ class ApiQuery extends ApiBase {
                $this->mAllowedGenerators = array_merge($this->mListModuleNames, $this->mPropModuleNames);\r
        }\r
 \r
-       public function GetDB() {\r
+       public function getDB() {\r
                if (!isset ($this->mSlaveDB))\r
                        $this->mSlaveDB = & wfGetDB(DB_SLAVE);\r
                return $this->mSlaveDB;\r
        }\r
 \r
-       public function GetData() {\r
+       public function getData() {\r
                return $this->mData;\r
        }\r
 \r
@@ -95,10 +95,10 @@ class ApiQuery extends ApiBase {
         * #4 Output all normalization and redirect resolution information\r
         * #5 Execute all requested modules\r
         */\r
-       public function Execute() {\r
+       public function execute() {\r
                $meta = $prop = $list = $generator = $titles = $pageids = $revids = null;\r
                $redirects = null;\r
-               extract($this->ExtractRequestParams());\r
+               extract($this->extractRequestParams());\r
 \r
                //\r
                // Create and initialize PageSet\r
@@ -109,12 +109,12 @@ class ApiQuery extends ApiBase {
                        $dataSource = 'titles';\r
                if (isset ($pageids)) {\r
                        if (isset ($dataSource))\r
-                               $this->DieUsage("Cannot use 'pageids' at the same time as '$dataSource'", 'multisource');\r
+                               $this->dieUsage("Cannot use 'pageids' at the same time as '$dataSource'", 'multisource');\r
                        $dataSource = 'pageids';\r
                }\r
                if (isset ($revids)) {\r
                        if (isset ($dataSource))\r
-                               $this->DieUsage("Cannot use 'revids' at the same time as '$dataSource'", 'multisource');\r
+                               $this->dieUsage("Cannot use 'revids' at the same time as '$dataSource'", 'multisource');\r
                        $dataSource = 'revids';\r
                }\r
 \r
@@ -122,13 +122,13 @@ class ApiQuery extends ApiBase {
 \r
                switch ($dataSource) {\r
                        case 'titles' :\r
-                               $this->mData->PopulateTitles($titles);\r
+                               $this->mData->populateTitles($titles);\r
                                break;\r
                        case 'pageids' :\r
-                               $this->mData->PopulatePageIDs($pageids);\r
+                               $this->mData->populatePageIDs($pageids);\r
                                break;\r
                        case 'titles' :\r
-                               $this->mData->PopulateRevIDs($revids);\r
+                               $this->mData->populateRevIDs($revids);\r
                                break;\r
                        default :\r
                                // Do nothing - some queries do not need any of the data sources.\r
@@ -139,7 +139,7 @@ class ApiQuery extends ApiBase {
                // If generator is provided, get a new dataset to work on\r
                //\r
                if (isset ($generator))\r
-                       $this->ExecuteGenerator($generator, $redirects);\r
+                       $this->executeGenerator($generator, $redirects);\r
 \r
                // Instantiate required modules\r
                // During instantiation, modules may optimize data requests through the $this->mData object \r
@@ -156,8 +156,8 @@ class ApiQuery extends ApiBase {
                                $modules[] = new $this->mQueryListModules[$moduleName] ($this, $moduleName);\r
 \r
                // Title normalizations\r
-               foreach ($this->mData->GetNormalizedTitles() as $rawTitleStr => $titleStr) {\r
-                       $this->GetResult()->AddMessage('query', 'normalized', array (\r
+               foreach ($this->mData->getNormalizedTitles() as $rawTitleStr => $titleStr) {\r
+                       $this->getResult()->addMessage('query', 'normalized', array (\r
                                'from' => $rawTitleStr,\r
                                'to' => $titleStr\r
                        ), 'n');\r
@@ -165,8 +165,8 @@ class ApiQuery extends ApiBase {
 \r
                // Show redirect information\r
                if ($redirects) {\r
-                       foreach ($this->mData->GetRedirectTitles() as $titleStrFrom => $titleStrTo) {\r
-                               $this->GetResult()->AddMessage('query', 'redirects', array (\r
+                       foreach ($this->mData->getRedirectTitles() as $titleStrFrom => $titleStrTo) {\r
+                               $this->getResult()->addMessage('query', 'redirects', array (\r
                                        'from' => $titleStrFrom,\r
                                        'to' => $titleStrTo\r
                                ), 'r');\r
@@ -174,11 +174,14 @@ class ApiQuery extends ApiBase {
                }\r
 \r
                // Execute all requested modules.\r
-               foreach ($modules as $module)\r
-                       $module->Execute();\r
+               foreach ($modules as $module) {\r
+                       $module->profileIn();\r
+                       $module->execute();\r
+                       $module->profileOut();\r
+               }\r
        }\r
 \r
-       protected function ExecuteGenerator($generator, $redirects) {\r
+       protected function executeGenerator($generator, $redirects) {\r
 \r
                // Find class that implements requested generator\r
                if (isset ($this->mQueryListModules[$generator]))\r
@@ -187,17 +190,17 @@ class ApiQuery extends ApiBase {
                        if (isset ($this->mQueryPropModules[$generator]))\r
                                $className = $this->mQueryPropModules[$generator];\r
                        else\r
-                               $this->DieDebug("Unknown generator=$generator");\r
+                               $this->dieDebug("Unknown generator=$generator");\r
 \r
                $module = new $className ($this, $generator, true);\r
 \r
                // change $this->mData\r
 \r
                // TODO: implement\r
-               $this->DieUsage("Generator execution has not been implemented", 'notimplemented');\r
+               $this->dieUsage("Generator execution has not been implemented", 'notimplemented');\r
        }\r
 \r
-       protected function GetAllowedParams() {\r
+       protected function getAllowedParams() {\r
                return array (\r
                        'meta' => array (\r
                                GN_ENUM_ISMULTI => true,\r
@@ -232,10 +235,10 @@ class ApiQuery extends ApiBase {
        /**\r
         * Override the parent to generate help messages for all available query modules.\r
         */\r
-       public function MakeHelpMsg() {\r
+       public function makeHelpMsg() {\r
 \r
                // Use parent to make default message for the query module\r
-               $msg = parent :: MakeHelpMsg();\r
+               $msg = parent :: makeHelpMsg();\r
 \r
                // Make sure the internal object is empty\r
                // (just in case a sub-module decides to optimize during instantiation)\r
@@ -243,33 +246,33 @@ class ApiQuery extends ApiBase {
 \r
                $astriks = str_repeat('--- ', 8);\r
                $msg .= "\n$astriks Query: Meta  $astriks\n\n";\r
-               $msg .= $this->MakeHelpMsgHelper($this->mQueryMetaModules, 'meta');\r
+               $msg .= $this->makeHelpMsgHelper($this->mQueryMetaModules, 'meta');\r
                $msg .= "\n$astriks Query: Prop  $astriks\n\n";\r
-               $msg .= $this->MakeHelpMsgHelper($this->mQueryPropModules, 'prop');\r
+               $msg .= $this->makeHelpMsgHelper($this->mQueryPropModules, 'prop');\r
                $msg .= "\n$astriks Query: List  $astriks\n\n";\r
-               $msg .= $this->MakeHelpMsgHelper($this->mQueryListModules, 'list');\r
+               $msg .= $this->makeHelpMsgHelper($this->mQueryListModules, 'list');\r
 \r
                return $msg;\r
        }\r
 \r
-       private function MakeHelpMsgHelper($moduleList, $paramName) {\r
+       private function makeHelpMsgHelper($moduleList, $paramName) {\r
                $msg = '';\r
 \r
                foreach ($moduleList as $moduleName => $moduleClass) {\r
                        $msg .= "* $paramName=$moduleName *";\r
-                       $module = new $moduleClass ($this, $moduleName);\r
-                       $msg2 = $module->MakeHelpMsg();\r
+                       $module = new $moduleClass ($this, $moduleName, null);\r
+                       $msg2 = $module->makeHelpMsg();\r
                        if ($msg2 !== false)\r
                                $msg .= $msg2;\r
                        $msg .= "\n";\r
-                       if ($module->GetCanGenerate())\r
+                       if ($module->getCanGenerate())\r
                                $msg .= "  * Can be used as a generator\n";\r
                }\r
 \r
                return $msg;\r
        }\r
 \r
-       protected function GetParamDescription() {\r
+       protected function getParamDescription() {\r
                return array (\r
                        'meta' => 'Which meta data to get about the site',\r
                        'prop' => 'Which properties to get for the titles/revisions/pageids',\r
@@ -282,7 +285,7 @@ class ApiQuery extends ApiBase {
                );\r
        }\r
 \r
-       protected function GetDescription() {\r
+       protected function getDescription() {\r
                return array (\r
                        'Query API module allows applications to get needed pieces of data from the MediaWiki databases,',\r
                        'and is loosely based on the Query API interface currently available on all MediaWiki servers.',\r
@@ -290,7 +293,7 @@ class ApiQuery extends ApiBase {
                );\r
        }\r
 \r
-       protected function GetExamples() {\r
+       protected function getExamples() {\r
                return array (\r
                        'api.php?action=query&what=content&titles=ArticleA|ArticleB'\r
                );\r
index a69ad43..0a715eb 100644 (file)
@@ -35,16 +35,16 @@ class ApiQueryAllpages extends ApiQueryBase {
                parent :: __construct($query, $moduleName, $generator);
        }
 
-       public function Execute() {
+       public function execute() {
                $aplimit = $apfrom = $apnamespace = $apfilterredir = null;
-               extract($this->ExtractRequestParams());
+               extract($this->extractRequestParams());
 
-               $db = $this->GetDB();
+               $db = $this->getDB();
                $where = array (
                        'page_namespace' => $apnamespace
                );
                if (isset ($apfrom))
-                       $where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase :: TitleToKey($apfrom));
+                       $where[] = 'page_title>=' . $db->addQuotes(ApiQueryBase :: titleToKey($apfrom));
 
                if ($apfilterredir === 'redirects')
                        $where['page_is_redirect'] = 1;
@@ -52,6 +52,7 @@ class ApiQueryAllpages extends ApiQueryBase {
                        if ($apfilterredir === 'nonredirects')
                                $where['page_is_redirect'] = 0;
 
+               $this->profileDBIn();
                $res = $db->select('page', array (
                        'page_id',
                        'page_namespace',
@@ -61,7 +62,8 @@ class ApiQueryAllpages extends ApiQueryBase {
                        'LIMIT' => $aplimit +1,
                        'ORDER BY' => 'page_namespace, page_title'
                ));
-
+               $this->profileDBOut();
+               
                $data = array ();
                $data['_element'] = 'p';
                $count = 0;
@@ -69,9 +71,9 @@ class ApiQueryAllpages extends ApiQueryBase {
                        if (++ $count > $aplimit) {
                                // We've reached the one extra which shows that there are additional pages to be had. Stop here...
                                $msg = array (
-                                       'continue' => 'apfrom=' . ApiQueryBase :: KeyToTitle($row->page_title
+                                       'continue' => 'apfrom=' . ApiQueryBase :: keyToTitle($row->page_title
                                ));
-                               $this->GetResult()->AddMessage('query-status', 'allpages', $msg);
+                               $this->getResult()->addMessage('query-status', 'allpages', $msg);
                                break;
                        }
 
@@ -91,10 +93,10 @@ class ApiQueryAllpages extends ApiQueryBase {
                        }
                }
                $db->freeResult($res);
-               $this->GetResult()->AddMessage('query', 'allpages', $data);
+               $this->getResult()->addMessage('query', 'allpages', $data);
        }
 
-       protected function GetAllowedParams() {
+       protected function getAllowedParams() {
 
                global $wgContLang;
                $validNamespaces = array ();
@@ -127,21 +129,21 @@ class ApiQueryAllpages extends ApiQueryBase {
                );
        }
 
-       protected function GetParamDescription() {
+       protected function getParamDescription() {
                return array ();
        }
 
-       protected function GetDescription() {
+       protected function getDescription() {
                return 'Enumerate all pages sequentially in a given namespace';
        }
 
-       protected function GetExamples() {
+       protected function getExamples() {
                return array (
                        'api.php?action=query&list=allpages',
                        'api.php?action=query&list=allpages&apfrom=B&aplimit=5'
                );
        }
-       public function GetCanGenerate() {
+       public function getCanGenerate() {
                return true;
        }
 }
index f64acfb..771c3ed 100644 (file)
@@ -34,7 +34,7 @@ abstract class ApiQueryBase extends ApiBase {
        private $mQueryModule, $mModuleName, $mGenerator;\r
 \r
        public function __construct($query, $moduleName, $generator = false) {\r
-               parent :: __construct($query->GetMain());\r
+               parent :: __construct($query->getMain());\r
                $this->mQueryModule = $query;\r
                $this->mModuleName = $moduleName;\r
                $this->mGenerator = $generator;\r
@@ -43,49 +43,50 @@ abstract class ApiQueryBase extends ApiBase {
        /**\r
         * Get the main Query module \r
         */\r
-       public function GetQuery() {\r
+       public function getQuery() {\r
                return $this->mQueryModule;\r
        }\r
 \r
        /**\r
         * Get the name of the query being executed by this instance \r
         */\r
-       public function GetModuleName() {\r
+       public function getModuleName() {\r
                return $this->mModuleName;\r
        }\r
 \r
        /**\r
         * Get the Query database connection (readonly)\r
         */\r
-       protected function GetDB() {\r
-               return $this->GetQuery()->GetDB();\r
+       protected function getDB() {\r
+               return $this->getQuery()->getDB();\r
        }\r
 \r
        /**\r
         * Get the PageSet object to work on\r
+        * @return ApiPageSet data\r
         */\r
-       protected function GetData() {\r
-               return $this->mQueryModule->GetData();\r
+       protected function getData() {\r
+               return $this->mQueryModule->getData();\r
        }\r
 \r
        /**\r
         * Return true if this instance is being used as a generator.\r
         */\r
-       protected function GetIsGenerator() {\r
+       protected function getIsGenerator() {\r
                return $this->mGenerator;\r
        }\r
 \r
        /**\r
         * Derived classes return true when they can be used as title generators for other query modules.\r
         */\r
-       public function GetCanGenerate() {\r
+       public function getCanGenerate() {\r
                return false;\r
        }\r
 \r
-       public static function TitleToKey($title) {\r
+       public static function titleToKey($title) {\r
                return str_replace(' ', '_', $title);\r
        }\r
-       public static function KeyToTitle($key) {\r
+       public static function keyToTitle($key) {\r
                return str_replace('_', ' ', $key);\r
        }\r
 }\r
index 2cddeb8..2387189 100644 (file)
@@ -31,15 +31,15 @@ if (!defined('MEDIAWIKI')) {
 
 class ApiQueryInfo extends ApiQueryBase {
 
-       public function __construct($main, $moduleName, $query) {
-               parent :: __construct($main, $moduleName, $query);
+       public function __construct($query, $moduleName, $generator = false) {
+               parent :: __construct($query, $moduleName, $generator);
        }
 
-       public function Execute() {
+       public function execute() {
 
        }
 
-       protected function GetAllowedParams() {
+       protected function getAllowedParams() {
                return array (
                        'param' => 'default',
                        'enumparam' => array (
@@ -53,15 +53,15 @@ class ApiQueryInfo extends ApiQueryBase {
                );
        }
 
-       protected function GetParamDescription() {
+       protected function getParamDescription() {
                return array ();
        }
 
-       protected function GetDescription() {
+       protected function getDescription() {
                return 'module a';
        }
 
-       protected function GetExamples() {
+       protected function getExamples() {
                return array (
                        'http://...'
                );
index 5e25c22..d3129b0 100644 (file)
@@ -35,13 +35,160 @@ class ApiQueryRevisions extends ApiQueryBase {
                parent :: __construct($query, $moduleName, $generator);
        }
 
-       public function Execute() {
+       public function execute() {
+               $rvlimit = $rvstartid = $rvendid = $rvstart = $rvend = $rvdir = $rvprop = null;
+               extract($this->extractRequestParams());
 
+               //
+               // Parameter validation
+               //
+
+               // true when ordered by timestamp from older to newer, false otherwise
+               $dirNewer = ($rvdir === 'newer');
+
+               // If any of those parameters are used, we work with single page only
+               $singePageMode = ($rvlimit !== 0 || $rvstartid !== 0 || $rvendid !== 0 || $dirNewer || isset ($rvstart) || isset ($rvend));
+
+               if ($rvstartid !== 0 || $rvendid !== 0)
+                       $this->dieUsage('rvstartid/rvendid not implemented', 'notimplemented');
+
+               $data = $this->getData();
+               $pageCount = $data->getPageCount();
+               if ($singePageMode && $pageCount > 1)
+                       $this->dieUsage('You have supplied multiple pages, but the specified revisions parameters may only be used with one page.', 'rv_multpages');
+
+               $tables = array (
+                       'revision'
+               );
+               $fields = array (
+                       'rev_id',
+                       'rev_page',
+                       'rev_text_id',
+                       'rev_minor_edit'
+               );
+               $conds = array (
+                       'rev_deleted' => 0
+               );
+               $options = array ();
+
+               $showTimestamp = $showUser = $showComment = $showContent = false;
+               if (isset ($rvprop)) {
+                       foreach ($rvprop as $prop) {
+                               switch ($prop) {
+                                       case 'timestamp' :
+                                               $fields[] = 'rev_timestamp';
+                                               $showTimestamp = true;
+                                               break;
+                                       case 'user' :
+                                               $fields[] = 'rev_user';
+                                               $fields[] = 'rev_user_text';
+                                               $showUser = true;
+                                               break;
+                                       case 'comment' :
+                                               $fields[] = 'rev_comment';
+                                               $showComment = true;
+                                               break;
+                                       case 'content' :
+                                               // todo: check the page count/limit when requesting content
+                                               //$this->validateLimit( 'content: (rvlimit*pages)+revids',
+                                               //$rvlimit * count($this->existingPageIds) + count($this->revIdsArray), 50, 200 );
+                                               $tables[] = 'text';
+                                               $conds[] = 'rev_text_id=old_id';
+                                               $fields[] = 'old_id';
+                                               $fields[] = 'old_text';
+                                               $fields[] = 'old_flags';
+                                               break;
+                                       default :
+                                               $this->dieDebug("unknown rvprop $prop");
+                               }
+                       }
+               }
+
+               if (isset ($rvstart))
+                       $conds[] = 'rev_timestamp >= ' . $this->prepareTimestamp($rvstart);
+               if (isset ($rvend))
+                       $conds[] = 'rev_timestamp <= ' . $this->prepareTimestamp($rvend);
+
+               if ($singePageMode) {
+                       if (!isset ($rvlimit))
+                               $rvlimit = 10;
+
+                       $options['LIMIT'] = $rvlimit + 1;
+                       $options['ORDER BY'] = 'rev_timestamp' . ($dirNewer ? '' : ' DESC');
+                       
+                       // get the first (and only) pageid => title pair
+                       foreach($data->getGoodTitles() as $pageId => $titleObj) {
+                               $conds['rev_page'] = $pageId;
+                               break;
+                       }
+               }
+
+               $db = $this->getDB();
+               $this->profileDBIn();
+               $res = $db->select($tables, $fields, $conds, __CLASS__ . '::' . __FUNCTION__, $options);
+               $this->profileDBOut();
+
+               $data = array ();
+               $count = 0;
+               while ($row = $db->fetchObject($res)) {
+
+                       if (++ $count > $rvlimit) {
+                               // We've reached the one extra which shows that there are additional pages to be had. Stop here...
+                               $startStr = 'rvstartid=' . $row->rev_id;
+                               $msg = array ('continue' => $startStr );
+                               $this->getResult()->addMessage('query-status', 'revisions', $msg);
+                               break;
+                       }
+
+
+                       $revid = intval($row->rev_id);
+                       $pageid = intval($row->rev_page);
+
+                       $vals = array (
+                               'revid' => $revid,
+                               'oldid' => intval($row->rev_text_id
+                       ));
+
+                       if( $row->rev_minor_edit ) {
+                               $vals['minor'] = '';
+                       }
+       
+                       if ($showTimestamp)
+                               $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->rev_timestamp);
+       
+                       if ($showUser) {
+                               $vals['user'] = $row->rev_user_text;
+                               if( !$row->rev_user )
+                                       $vals['anon'] = '';
+                       }
+
+                       if ($showComment)
+                               $vals['comment'] = $row->rev_comment;
+
+                       if ($showContent) {
+                               $vals['xml:space'] = 'preserve';
+                               $vals['*'] = Revision::getRevisionText( $row );
+                       } else {
+                               $vals['*'] = '';        // Force all elements to be attributes
+                       }
+
+                       $data[$pageid]['revisions']['_element'] = 'rv';
+                       $data[$pageid]['revisions'][$revid] = $vals;
+               }
+               $db->freeResult($res);
+
+               $this->getResult()->addMessage('query', 'allpages', $data);
        }
 
-       protected function GetAllowedParams() {
+       protected function getAllowedParams() {
                return array (
-                       'rvlimit' => 0,
+                       'rvlimit' => array (
+                               GN_ENUM_DFLT => 0,
+                               GN_ENUM_TYPE => 'limit',
+                               GN_ENUM_MIN => 0,
+                               GN_ENUM_MAX1 => 50,
+                               GN_ENUM_MAX2 => 500
+                       ),
                        'rvstartid' => 0,
                        'rvendid' => 0,
                        'rvstart' => array (
@@ -51,7 +198,7 @@ class ApiQueryRevisions extends ApiQueryBase {
                                GN_ENUM_TYPE => 'timestamp'
                        ),
                        'rvdir' => array (
-                               GN_ENUM_DFLT => 'newer',
+                               GN_ENUM_DFLT => 'older',
                                GN_ENUM_TYPE => array (
                                        'newer',
                                        'older'
@@ -69,13 +216,13 @@ class ApiQueryRevisions extends ApiQueryBase {
                );
        }
 
-       protected function GetDescription() {
+       protected function getDescription() {
                return 'module a';
        }
 
-       protected function GetExamples() {
+       protected function getExamples() {
                return array (
-                       'http://...'
+                       'api.php?action=query&prop=revisions&titles=ArticleA&rvprop=timestamp|user|comment|content'
                );
        }
 }
index 2d52e5a..c561f50 100644 (file)
@@ -35,9 +35,9 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                parent :: __construct($query, $moduleName);
        }
 
-       public function Execute() {
+       public function execute() {
                $siprop = null;
-               extract($this->ExtractRequestParams());
+               extract($this->extractRequestParams());
 
                foreach ($siprop as $prop) {
                        switch ($prop) {
@@ -52,7 +52,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                        $data['sitename'] = $wgSitename;
                                        $data['generator'] = "MediaWiki $wgVersion";
                                        $data['case'] = $wgCapitalLinks ? 'first-letter' : 'case-sensitive'; // "case-insensitive" option is reserved for future
-                                       $this->GetResult()->AddMessage('query', $prop, $data);
+                                       $this->getResult()->addMessage('query', $prop, $data);
                                        break;
 
                                case 'namespaces' :
@@ -65,16 +65,16 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                                                        'id' => $ns,
                                                        '*' => $title
                                                );
-                                       $this->GetResult()->AddMessage('query', $prop, $data);
+                                       $this->getResult()->addMessage('query', $prop, $data);
                                        break;
 
                                default :
-                                       $this->DieDebug("Unknown siprop=$prop");
+                                       $this->dieDebug("Unknown siprop=$prop");
                        }
                }
        }
 
-       protected function GetAllowedParams() {
+       protected function getAllowedParams() {
                return array (
                        'siprop' => array (
                                GN_ENUM_DFLT => 'general',
@@ -87,7 +87,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                );
        }
 
-       protected function GetParamDescription() {
+       protected function getParamDescription() {
                return array (
                        'siprop' => array (
                                'Which sysinfo properties to get:',
@@ -97,11 +97,11 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                );
        }
 
-       protected function GetDescription() {
+       protected function getDescription() {
                return 'Return general information about the site.';
        }
 
-       protected function GetExamples() {
+       protected function getExamples() {
                return 'api.php?action=query&meta=siteinfo&siprop=general|namespaces';
        }
 }
index 43eaaf1..b35aed2 100644 (file)
@@ -45,11 +45,11 @@ class ApiResult extends ApiBase {
                $this->mData = array ();\r
        }\r
 \r
-       function GetData() {\r
+       function getData() {\r
                return $this->mData;\r
        }\r
 \r
-       function AddMessage($mainSection, $subSection, $value, $multiitem = false, $preserveXmlSpacing = false) {\r
+       function addMessage($mainSection, $subSection, $value, $multiitem = false, $preserveXmlSpacing = false) {\r
                if (!array_key_exists($mainSection, $this->mData)) {\r
                        $this->mData[$mainSection] = array ();\r
                }\r
@@ -103,8 +103,8 @@ class ApiResult extends ApiBase {
                }\r
        }\r
 \r
-       public function Execute() {\r
-               $this->DieDebug("Execute() is not supported on Result object");\r
+       public function execute() {\r
+               $this->dieDebug("execute() is not supported on Result object");\r
        }\r
 }\r
 ?>\r