r34556 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34555‎ | r34556 | r34557 >
Date:09:29, 10 May 2008
Author:catrope
Status:old
Tags:
Comment:
Re-applying r34440 (documenting ApiQueryBase)
Modified paths:
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiMain.php
@@ -546,6 +546,10 @@
547547 return $this->mIsSysop;
548548 }
549549
 550+ /**
 551+ * Check whether the current user is allowed to use high limits
 552+ * @return bool
 553+ */
550554 public function canApiHighLimits() {
551555 if (!isset($this->mCanApiHighLimits)) {
552556 global $wgUser;
@@ -555,6 +559,10 @@
556560 return $this->mCanApiHighLimits;
557561 }
558562
 563+ /**
 564+ * Check whether the user wants us to show version information in the API help
 565+ * @return bool
 566+ */
559567 public function getShowVersions() {
560568 return $this->mShowVersions;
561569 }
Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -45,6 +45,9 @@
4646 $this->resetQueryParams();
4747 }
4848
 49+ /**
 50+ * Blank the internal arrays with query parameters
 51+ */
4952 protected function resetQueryParams() {
5053 $this->tables = array ();
5154 $this->where = array ();
@@ -52,6 +55,11 @@
5356 $this->options = array ();
5457 }
5558
 59+ /**
 60+ * Add a set of tables to the internal array
 61+ * @param mixed $tables Table name or array of table names
 62+ * @param mixed $alias Table alias, or null for no alias. Cannot be used with multiple tables
 63+ */
5664 protected function addTables($tables, $alias = null) {
5765 if (is_array($tables)) {
5866 if (!is_null($alias))
@@ -64,6 +72,10 @@
6573 }
6674 }
6775
 76+ /**
 77+ * Add a set of fields to select to the internal array
 78+ * @param mixed $value Field name or array of field names
 79+ */
6880 protected function addFields($value) {
6981 if (is_array($value))
7082 $this->fields = array_merge($this->fields, $value);
@@ -71,6 +83,12 @@
7284 $this->fields[] = $value;
7385 }
7486
 87+ /**
 88+ * Same as addFields(), but add the fields only if a condition is met
 89+ * @param mixed $value See addFields()
 90+ * @param bool $condition If false, do nothing
 91+ * @return bool $condition
 92+ */
7593 protected function addFieldsIf($value, $condition) {
7694 if ($condition) {
7795 $this->addFields($value);
@@ -79,6 +97,15 @@
8098 return false;
8199 }
82100
 101+ /**
 102+ * Add a set of WHERE clauses to the internal array.
 103+ * Clauses can be formatted as 'foo=bar' or array('foo' => 'bar'),
 104+ * the latter only works if the value is a constant (i.e. not another field)
 105+ *
 106+ * For example, array('foo=bar', 'baz' => 3, 'bla' => 'foo') translates
 107+ * to "foo=bar AND baz='3' AND bla='foo'"
 108+ * @param mixed $value String or array
 109+ */
83110 protected function addWhere($value) {
84111 if (is_array($value))
85112 $this->where = array_merge($this->where, $value);
@@ -86,6 +113,12 @@
87114 $this->where[] = $value;
88115 }
89116
 117+ /**
 118+ * Same as addWhere(), but add the WHERE clauses only if a condition is met
 119+ * @param mixed $value See addWhere()
 120+ * @param bool $condition If false, do nothing
 121+ * @return bool $condition
 122+ */
90123 protected function addWhereIf($value, $condition) {
91124 if ($condition) {
92125 $this->addWhere($value);
@@ -94,11 +127,24 @@
95128 return false;
96129 }
97130
 131+ /**
 132+ * Equivalent to addWhere(array($field => $value))
 133+ * @param string $field Field name
 134+ * @param string $value Value; ignored if nul;
 135+ */
98136 protected function addWhereFld($field, $value) {
99137 if (!is_null($value))
100138 $this->where[$field] = $value;
101139 }
102140
 141+ /**
 142+ * Add a WHERE clause corresponding to a range, and an ORDER BY
 143+ * clause to sort in the right direction
 144+ * @param string $field Field name
 145+ * @param string $dir If 'newer', sort in ascending order, otherwise sort in descending order
 146+ * @param string $start Value to start the list at. If $dir == 'newer' this is the lower boundary, otherwise it's the upper boundary
 147+ * @param string $end Value to end the list at. If $dir == 'newer' this is the upper boundary, otherwise it's the lower boundary
 148+ */
103149 protected function addWhereRange($field, $dir, $start, $end) {
104150 $isDirNewer = ($dir === 'newer');
105151 $after = ($isDirNewer ? '>=' : '<=');
@@ -118,6 +164,11 @@
119165 $this->addOption('ORDER BY', $this->options['ORDER BY'] . ', ' . $order);
120166 }
121167
 168+ /**
 169+ * Add an option such as LIMIT or USE INDEX
 170+ * @param string $name Option name
 171+ * @param string $value Option value
 172+ */
122173 protected function addOption($name, $value = null) {
123174 if (is_null($value))
124175 $this->options[] = $name;
@@ -125,6 +176,11 @@
126177 $this->options[$name] = $value;
127178 }
128179
 180+ /**
 181+ * Execute a SELECT query based on the values in the internal arrays
 182+ * @param string $method Function the query should be attributed to. You should usually use __METHOD__ here
 183+ * @return ResultWrapper
 184+ */
129185 protected function select($method) {
130186
131187 // getDB has its own profileDBIn/Out calls
@@ -137,6 +193,11 @@
138194 return $res;
139195 }
140196
 197+ /**
 198+ * Estimate the row count for the SELECT query that would be run if we
 199+ * called select() right now, and check if it's acceptable.
 200+ * @return bool true if acceptable, false otherwise
 201+ */
141202 protected function checkRowCount() {
142203 $db = $this->getDB();
143204 $this->profileDBIn();
@@ -149,6 +210,12 @@
150211 return true;
151212 }
152213
 214+ /**
 215+ * Add information (title and namespace) about a Title object to a result array
 216+ * @param array $arr Result array � la ApiResult
 217+ * @param Title $title Title object
 218+ * @param string $prefix Module prefix
 219+ */
153220 public static function addTitleInfo(&$arr, $title, $prefix='') {
154221 $arr[$prefix . 'ns'] = intval($title->getNamespace());
155222 $arr[$prefix . 'title'] = $title->getPrefixedText();
@@ -157,19 +224,23 @@
158225 /**
159226 * Override this method to request extra fields from the pageSet
160227 * using $pageSet->requestField('fieldName')
 228+ * @param ApiPageSet $pageSet
161229 */
162230 public function requestExtraData($pageSet) {
163231 }
164232
165233 /**
166234 * Get the main Query module
 235+ * @return ApiQuery
167236 */
168237 public function getQuery() {
169238 return $this->mQueryModule;
170239 }
171240
172241 /**
173 - * Add sub-element under the page element with the given pageId.
 242+ * Add a sub-element under the page element with the given page ID
 243+ * @param int $pageId Page ID
 244+ * @param array $data Data array � la ApiResult
174245 */
175246 protected function addPageSubItems($pageId, $data) {
176247 $result = $this->getResult();
@@ -179,19 +250,21 @@
180251 $data);
181252 }
182253
 254+ /**
 255+ * Set a query-continue value
 256+ * @param $paramName Parameter name
 257+ * @param $paramValue Parameter value
 258+ */
183259 protected function setContinueEnumParameter($paramName, $paramValue) {
184260
185261 $paramName = $this->encodeParamName($paramName);
186262 $msg = array( $paramName => $paramValue );
187 -
188 -// This is an alternative continue format as a part of the URL string
189 -// ApiResult :: setContent($msg, $paramName . '=' . urlencode($paramValue));
190 -
191263 $this->getResult()->addValue('query-continue', $this->getModuleName(), $msg);
192264 }
193265
194266 /**
195267 * Get the Query database connection (readonly)
 268+ * @return Database
196269 */
197270 protected function getDB() {
198271 if (is_null($this->mDb))
@@ -204,6 +277,10 @@
205278 * If no such connection has been requested before, it will be created.
206279 * Subsequent calls with the same $name will return the same connection
207280 * as the first, regardless of $db or $groups new values.
 281+ * @param string $name Name to assign to the database connection
 282+ * @param int $db One of the DB_* constants
 283+ * @param array $groups Query groups
 284+ * @return Database
208285 */
209286 public function selectNamedDB($name, $db, $groups) {
210287 $this->mDb = $this->getQuery()->getNamedDB($name, $db, $groups);
@@ -211,7 +288,7 @@
212289
213290 /**
214291 * Get the PageSet object to work on
215 - * @return ApiPageSet data
 292+ * @return ApiPageSet
216293 */
217294 protected function getPageSet() {
218295 return $this->getQuery()->getPageSet();
@@ -221,15 +298,29 @@
222299 * This is a very simplistic utility function
223300 * to convert a non-namespaced title string to a db key.
224301 * It will replace all ' ' with '_'
 302+ * @param string $title Page title with spaces
 303+ * @return string Page title with underscores
225304 */
226305 public static function titleToKey($title) {
227306 return str_replace(' ', '_', $title);
228307 }
229308
 309+ /**
 310+ * The inverse of titleToKey()
 311+ * @param string $key Page title with underscores
 312+ * @return string Page title with spaces
 313+ */
230314 public static function keyToTitle($key) {
231315 return str_replace('_', ' ', $key);
232316 }
233317
 318+ /**
 319+ * Check whether the current user requested a certain token and
 320+ * is actually allowed to request it.
 321+ * @param array $tokenArr Array of tokens the user requested
 322+ * @param string $action Action to check for
 323+ * @return bool true if the user requested the token and is allowed to, false otherwise
 324+ */
234325 public function getTokenFlag($tokenArr, $action) {
235326 if ($this->getMain()->getRequest()->getVal('callback') !== null) {
236327 // Don't do any session-specific data.
@@ -245,6 +336,10 @@
246337 return false;
247338 }
248339
 340+ /**
 341+ * Get version string for use in the API help output
 342+ * @return string
 343+ */
249344 public static function getBaseVersion() {
250345 return __CLASS__ . ': $Id$';
251346 }
@@ -262,6 +357,10 @@
263358 $this->mIsGenerator = false;
264359 }
265360
 361+ /**
 362+ * Switch this module to generator mode. By default, generator mode is
 363+ * switched off and the module acts like a normal query module.
 364+ */
266365 public function setGeneratorMode() {
267366 $this->mIsGenerator = true;
268367 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r34440Documenting some API stuffcatrope15:46, 8 May 2008

Status & tagging log