r16742 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r16741 | r16742 (on ViewVC) | r16743 >
Date:18:27, 2 October 2006
Author:yurik
Status:new
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
===================================================================
--- trunk/phase3/includes/api/ApiQueryBase.php	(revision 16741)
+++ trunk/phase3/includes/api/ApiQueryBase.php	(revision 16742)
@@ -98,7 +98,7 @@
 		return str_replace('_', ' ', $key);
 	}
 
-	public function getVersion() {
+	public static function getBaseVersion() {
 		return __CLASS__ . ': $Id$';
 	}
 }
Index: trunk/phase3/includes/api/ApiQuery.php
===================================================================
--- trunk/phase3/includes/api/ApiQuery.php	(revision 16741)
+++ trunk/phase3/includes/api/ApiQuery.php	(revision 16742)
@@ -331,8 +331,9 @@
 
 	public function getVersion() {
 		$psModule = new ApiPageSet($this);
-		$vers = $psModule->getVersion();
+		$vers = array();
 		$vers[] = __CLASS__ . ': $Id$';
+		$vers[] = $psModule->getVersion();
 		return $vers;
 	}
 }
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryRevisions.php	(revision 16741)
+++ trunk/phase3/includes/api/ApiQueryRevisions.php	(revision 16742)
@@ -99,9 +99,6 @@
 						$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';
@@ -127,7 +124,14 @@
 			if ($rvendid !== 0 && isset ($rvend))
 				$this->dieUsage('rvend and rvend cannot be used together', 'rv_badparams');
 
-			$options['ORDER BY'] = 'rev_timestamp' . ($dirNewer ? '' : ' DESC');
+			// This code makes an assumption that sorting by rev_id and rev_timestamp produces
+			// the same result. This way users may request revisions starting at a given time,
+			// but to page through results use the rev_id returned after each page.
+			// Switching to rev_id removes the potential problem of having more than 
+			// one row with the same timestamp for the same page. 
+			// The order needs to be the same as start parameter to avoid SQL filesort.
+			$options['ORDER BY'] = ($rvstartid !== 0 ? 'rev_id' : 'rev_timestamp') . ($dirNewer ? '' : ' DESC');
+
 			$before = ($dirNewer ? '<=' : '>=');
 			$after = ($dirNewer ? '>=' : '<=');
 
Index: trunk/phase3/includes/api/ApiBase.php
===================================================================
--- trunk/phase3/includes/api/ApiBase.php	(revision 16741)
+++ trunk/phase3/includes/api/ApiBase.php	(revision 16742)
@@ -398,7 +398,9 @@
 		return $this->mDBTime;
 	}
 
-	public function getVersion() {
+	public abstract function getVersion();
+	
+	public static function getBaseVersion() {
 		return __CLASS__ . ': $Id$';
 	}
 }
Index: trunk/phase3/includes/api/ApiQueryAllpages.php
===================================================================
--- trunk/phase3/includes/api/ApiQueryAllpages.php	(revision 16741)
+++ trunk/phase3/includes/api/ApiQueryAllpages.php	(revision 16742)
@@ -127,7 +127,12 @@
 	}
 
 	protected function getParamDescription() {
-		return array ();
+		return array (
+			'apfrom' => 'The page title to start enumerating from.',
+			'apnamespace' => 'The namespace to enumerate. Default 0 (Main).',
+			'apfilterredir' => 'Which pages to list: "all" (default), "redirects", or "nonredirects"',
+			'aplimit' => 'How many total pages to return'
+		);
 	}
 
 	protected function getDescription() {
Index: trunk/phase3/includes/api/ApiFormatBase.php
===================================================================
--- trunk/phase3/includes/api/ApiFormatBase.php	(revision 16741)
+++ trunk/phase3/includes/api/ApiFormatBase.php	(revision 16742)
@@ -142,6 +142,8 @@
 		$text = ereg_replace("api\\.php\\?[^ ()<\n\t]+", '<a href="\\0">\\0</a>', $text);
 		// make strings inside * bold
 		$text = ereg_replace("\\*[^<>\n]+\\*", '<b>\\0</b>', $text);
+		// make strings inside $ italic
+		$text = ereg_replace("\\$[^<>\n]+\\$", '<b><i>\\0</i></b>', $text);
 
 		return $text;
 	}
Index: trunk/phase3/includes/api/ApiMain.php
===================================================================
--- trunk/phase3/includes/api/ApiMain.php	(revision 16741)
+++ trunk/phase3/includes/api/ApiMain.php	(revision 16742)
@@ -31,14 +31,15 @@
 
 class ApiMain extends ApiBase {
 
-	private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames, $mApiStartTime, $mResult, $mShowVersions;
+	private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
+	private $mApiStartTime, $mResult, $mShowVersions, $mEnableWrite;
 
 	/**
 	* Constructor
 	* $apiStartTime - time of the originating call for profiling purposes
 	* $modules - an array of actions (keys) and classes that handle them (values) 
 	*/
-	public function __construct($apiStartTime, $modules, $formats) {
+	public function __construct($apiStartTime, $modules, $formats, $enableWrite) {
 		// Special handling for the main module: $parent === $this
 		parent :: __construct($this);
 
@@ -49,6 +50,7 @@
 		$this->mApiStartTime = $apiStartTime;
 		$this->mResult = new ApiResult($this);
 		$this->mShowVersions = false;
+		$this->mEnableWrite = $enableWrite;
 	}
 
 	public function & getResult() {
@@ -59,6 +61,12 @@
 		return $this->mShowVersions;
 	}
 
+	public function requestWriteMode() {
+		if (!$this->mEnableWrite)
+			$this->dieUsage('Editing of this site is disabled. Make sure the $wgEnableWriteAPI=true; ' .
+			'statement is included in the site\'s LocalSettings.php file', 'readonly');
+	}
+
 	protected function getAllowedParams() {
 		return array (
 			'format' => array (
@@ -190,9 +198,12 @@
 	}
 
 	public function getVersion() {
-
-		return array (
-		parent :: getVersion(), __CLASS__ . ': $Id$', ApiFormatBase :: getBaseVersion());
+		$vers = array ();
+		$vers[] = __CLASS__ . ': $Id$';
+		$vers[] = ApiBase :: getBaseVersion();
+		$vers[] = ApiFormatBase :: getBaseVersion();
+		$vers[] = ApiQueryBase :: getBaseVersion();
+		return $vers;
 	}
 }
 
Index: trunk/phase3/includes/api/ApiPageSet.php
===================================================================
--- trunk/phase3/includes/api/ApiPageSet.php	(revision 16741)
+++ trunk/phase3/includes/api/ApiPageSet.php	(revision 16742)
@@ -401,8 +401,7 @@
 	}
 
 	public function getVersion() {
-		return array (
-		parent :: getVersion(), __CLASS__ . ': $Id$');
+		return __CLASS__ . ': $Id$';
 	}
 }
 ?>
\ No newline at end of file
Index: trunk/phase3/api.php
===================================================================
--- trunk/phase3/api.php	(revision 16741)
+++ trunk/phase3/api.php	(revision 16742)
@@ -103,7 +103,11 @@
 }
 
 $wgAutoloadClasses = array_merge($wgAutoloadClasses, $wgApiAutoloadClasses);
-$processor = new ApiMain($wgApiStartTime, $wgApiModules, $wgApiFormats);
+
+if (!isset($wgEnableWriteAPI))
+	$wgEnableWriteAPI = false;	// This should be 'true' later, once the api is stable. 
+	
+$processor = new ApiMain($wgApiStartTime, $wgApiModules, $wgApiFormats, $wgEnableWriteAPI);
 $processor->execute();
 
 wfProfileOut('api.php');
Views
Toolbox