MediaWiki r16742 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r16741‎ | r16742 (on ViewVC)‎ | r16743 >
Date:18:27, 2 October 2006
Author:yurik
Status:old
Tags:
Comment:
*API: better version gen, added check for read-only api, added allpages params description
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -98,7 +98,7 @@
9999 return str_replace('_', ' ', $key);
100100 }
101101
102 - public function getVersion() {
 102+ public static function getBaseVersion() {
103103 return __CLASS__ . ': $Id$';
104104 }
105105 }
Index: trunk/phase3/includes/api/ApiQuery.php
@@ -331,8 +331,9 @@
332332
333333 public function getVersion() {
334334 $psModule = new ApiPageSet($this);
335 - $vers = $psModule->getVersion();
 335+ $vers = array();
336336 $vers[] = __CLASS__ . ': $Id$';
 337+ $vers[] = $psModule->getVersion();
337338 return $vers;
338339 }
339340 }
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -99,9 +99,6 @@
100100 $showComment = true;
101101 break;
102102 case 'content' :
103 - // todo: check the page count/limit when requesting content
104 - //$this->validateLimit( 'content: (rvlimit*pages)+revids',
105 - //$rvlimit * count($this->existingPageIds) + count($this->revIdsArray), 50, 200 );
106103 $tables[] = 'text';
107104 $conds[] = 'rev_text_id=old_id';
108105 $fields[] = 'old_id';
@@ -127,7 +124,14 @@
128125 if ($rvendid !== 0 && isset ($rvend))
129126 $this->dieUsage('rvend and rvend cannot be used together', 'rv_badparams');
130127
131 - $options['ORDER BY'] = 'rev_timestamp' . ($dirNewer ? '' : ' DESC');
 128+ // This code makes an assumption that sorting by rev_id and rev_timestamp produces
 129+ // the same result. This way users may request revisions starting at a given time,
 130+ // but to page through results use the rev_id returned after each page.
 131+ // Switching to rev_id removes the potential problem of having more than
 132+ // one row with the same timestamp for the same page.
 133+ // The order needs to be the same as start parameter to avoid SQL filesort.
 134+ $options['ORDER BY'] = ($rvstartid !== 0 ? 'rev_id' : 'rev_timestamp') . ($dirNewer ? '' : ' DESC');
 135+
132136 $before = ($dirNewer ? '<=' : '>=');
133137 $after = ($dirNewer ? '>=' : '<=');
134138
Index: trunk/phase3/includes/api/ApiBase.php
@@ -398,7 +398,9 @@
399399 return $this->mDBTime;
400400 }
401401
402 - public function getVersion() {
 402+ public abstract function getVersion();
 403+
 404+ public static function getBaseVersion() {
403405 return __CLASS__ . ': $Id$';
404406 }
405407 }
Index: trunk/phase3/includes/api/ApiQueryAllpages.php
@@ -127,7 +127,12 @@
128128 }
129129
130130 protected function getParamDescription() {
131 - return array ();
 131+ return array (
 132+ 'apfrom' => 'The page title to start enumerating from.',
 133+ 'apnamespace' => 'The namespace to enumerate. Default 0 (Main).',
 134+ 'apfilterredir' => 'Which pages to list: "all" (default), "redirects", or "nonredirects"',
 135+ 'aplimit' => 'How many total pages to return'
 136+ );
132137 }
133138
134139 protected function getDescription() {
Index: trunk/phase3/includes/api/ApiFormatBase.php
@@ -142,6 +142,8 @@
143143 $text = ereg_replace("api\\.php\\?[^ ()<\n\t]+", '<a href="\\0">\\0</a>', $text);
144144 // make strings inside * bold
145145 $text = ereg_replace("\\*[^<>\n]+\\*", '<b>\\0</b>', $text);
 146+ // make strings inside $ italic
 147+ $text = ereg_replace("\\$[^<>\n]+\\$", '<b><i>\\0</i></b>', $text);
146148
147149 return $text;
148150 }
Index: trunk/phase3/includes/api/ApiMain.php
@@ -31,14 +31,15 @@
3232
3333 class ApiMain extends ApiBase {
3434
35 - private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames, $mApiStartTime, $mResult, $mShowVersions;
 35+ private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
 36+ private $mApiStartTime, $mResult, $mShowVersions, $mEnableWrite;
3637
3738 /**
3839 * Constructor
3940 * $apiStartTime - time of the originating call for profiling purposes
4041 * $modules - an array of actions (keys) and classes that handle them (values)
4142 */
42 - public function __construct($apiStartTime, $modules, $formats) {
 43+ public function __construct($apiStartTime, $modules, $formats, $enableWrite) {
4344 // Special handling for the main module: $parent === $this
4445 parent :: __construct($this);
4546
@@ -49,6 +50,7 @@
5051 $this->mApiStartTime = $apiStartTime;
5152 $this->mResult = new ApiResult($this);
5253 $this->mShowVersions = false;
 54+ $this->mEnableWrite = $enableWrite;
5355 }
5456
5557 public function & getResult() {
@@ -59,6 +61,12 @@
6062 return $this->mShowVersions;
6163 }
6264
 65+ public function requestWriteMode() {
 66+ if (!$this->mEnableWrite)
 67+ $this->dieUsage('Editing of this site is disabled. Make sure the $wgEnableWriteAPI=true; ' .
 68+ 'statement is included in the site\'s LocalSettings.php file', 'readonly');
 69+ }
 70+
6371 protected function getAllowedParams() {
6472 return array (
6573 'format' => array (
@@ -190,9 +198,12 @@
191199 }
192200
193201 public function getVersion() {
194 -
195 - return array (
196 - parent :: getVersion(), __CLASS__ . ': $Id$', ApiFormatBase :: getBaseVersion());
 202+ $vers = array ();
 203+ $vers[] = __CLASS__ . ': $Id$';
 204+ $vers[] = ApiBase :: getBaseVersion();
 205+ $vers[] = ApiFormatBase :: getBaseVersion();
 206+ $vers[] = ApiQueryBase :: getBaseVersion();
 207+ return $vers;
197208 }
198209 }
199210
Index: trunk/phase3/includes/api/ApiPageSet.php
@@ -401,8 +401,7 @@
402402 }
403403
404404 public function getVersion() {
405 - return array (
406 - parent :: getVersion(), __CLASS__ . ': $Id$');
 405+ return __CLASS__ . ': $Id$';
407406 }
408407 }
409408 ?>
\ No newline at end of file
Index: trunk/phase3/api.php
@@ -103,7 +103,11 @@
104104 }
105105
106106 $wgAutoloadClasses = array_merge($wgAutoloadClasses, $wgApiAutoloadClasses);
107 -$processor = new ApiMain($wgApiStartTime, $wgApiModules, $wgApiFormats);
 107+
 108+if (!isset($wgEnableWriteAPI))
 109+ $wgEnableWriteAPI = false; // This should be 'true' later, once the api is stable.
 110+
 111+$processor = new ApiMain($wgApiStartTime, $wgApiModules, $wgApiFormats, $wgEnableWriteAPI);
108112 $processor->execute();
109113
110114 wfProfileOut('api.php');