r88816 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88815‎ | r88816 | r88817 >
Date:18:58, 25 May 2011
Author:reedy
Status:ok
Tags:
Comment:
More documentation stuffs
Modified paths:
  • /trunk/phase3/includes/db/CloneDatabase.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseError.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseUtility.php (modified) (history)
  • /trunk/phase3/includes/db/LBFactory.php (modified) (history)
  • /trunk/phase3/includes/db/LBFactory_Multi.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseError.php
@@ -21,6 +21,10 @@
2222 parent::__construct( $error );
2323 }
2424
 25+ /**
 26+ * @param $html string
 27+ * @return string
 28+ */
2529 protected function getContentMessage( $html ) {
2630 if ( $html ) {
2731 return nl2br( htmlspecialchars( $this->getMessage() ) );
@@ -29,6 +33,9 @@
3034 }
3135 }
3236
 37+ /**
 38+ * @return string
 39+ */
3340 function getText() {
3441 global $wgShowDBErrorBacktrace;
3542
@@ -41,6 +48,9 @@
4249 return $s;
4350 }
4451
 52+ /**
 53+ * @return string
 54+ */
4555 function getHTML() {
4656 global $wgShowDBErrorBacktrace;
4757
@@ -95,11 +105,17 @@
96106 return false;
97107 }
98108
 109+ /**
 110+ * @return string
 111+ */
99112 function getPageTitle() {
100113 global $wgSitename;
101114 return htmlspecialchars( $this->msg( 'dberr-header', "$wgSitename has a problem" ) );
102115 }
103116
 117+ /**
 118+ * @return string
 119+ */
104120 function getHTML() {
105121 global $wgShowDBErrorBacktrace;
106122
@@ -158,6 +174,9 @@
159175 return parent::reportHTML();
160176 }
161177
 178+ /**
 179+ * @return string
 180+ */
162181 function searchForm() {
163182 global $wgSitename, $wgServer;
164183
@@ -192,6 +211,9 @@
193212 return $trygoogle;
194213 }
195214
 215+ /**
 216+ * @return string
 217+ */
196218 private function fileCachedPage() {
197219 global $wgTitle, $wgOut;
198220
@@ -237,6 +259,10 @@
238260 $this->fname = $fname;
239261 }
240262
 263+ /**
 264+ * @param $html string
 265+ * @return string
 266+ */
241267 function getContentMessage( $html ) {
242268 if ( $this->useMessageCache() ) {
243269 $msg = $html ? 'dberrortext' : 'dberrortextcl';
@@ -251,6 +277,9 @@
252278 }
253279 }
254280
 281+ /**
 282+ * @return String
 283+ */
255284 function getSQL() {
256285 global $wgShowSQLErrors;
257286
@@ -266,6 +295,9 @@
267296 return false;
268297 }
269298
 299+ /**
 300+ * @return String
 301+ */
270302 function getPageTitle() {
271303 return $this->msg( 'databaseerror', 'Database error' );
272304 }
Index: trunk/phase3/includes/db/LBFactory_Multi.php
@@ -179,6 +179,8 @@
180180
181181 /**
182182 * Make a server array as expected by LoadBalancer::__construct, using a template and load array
 183+ *
 184+ * @return array
183185 */
184186 function makeServerArray( $template, $loads, $groupLoads ) {
185187 $servers = array();
Index: trunk/phase3/includes/db/Database.php
@@ -67,7 +67,7 @@
6868 * Fetch the next row from the given result object, in associative array
6969 * form. Fields are retrieved with $row['fieldname'].
7070 *
71 - * @param $res SQL result object as returned from DatabaseBase::query(), etc.
 71+ * @param $res ResultWrapper result object as returned from DatabaseBase::query(), etc.
7272 * @return Row object
7373 * @throws DBUnexpectedError Thrown if the database returns an error
7474 */
@@ -255,6 +255,8 @@
256256 /**
257257 * Turns buffering of SQL result sets on (true) or off (false).
258258 * Default is "on" and it should not be changed without good reasons.
 259+ *
 260+ * @return bool
259261 */
260262 function bufferResults( $buffer = null ) {
261263 if ( is_null( $buffer ) ) {
@@ -309,6 +311,11 @@
310312 }
311313 }
312314
 315+ /**
 316+ * @param $name
 317+ * @param $value
 318+ * @return void
 319+ */
313320 function setLBInfo( $name, $value = null ) {
314321 if ( is_null( $value ) ) {
315322 $this->mLBInfo = $name;
@@ -402,20 +409,28 @@
403410 * Return the last query that went through DatabaseBase::query()
404411 * @return String
405412 */
406 - function lastQuery() { return $this->mLastQuery; }
 413+ function lastQuery() {
 414+ return $this->mLastQuery;
 415+ }
407416
408417
409418 /**
410419 * Returns true if the connection may have been used for write queries.
411420 * Should return true if unsure.
 421+ *
 422+ * @return bool
412423 */
413 - function doneWrites() { return $this->mDoneWrites; }
 424+ function doneWrites() {
 425+ return $this->mDoneWrites;
 426+ }
414427
415428 /**
416429 * Is a connection to the database open?
417430 * @return Boolean
418431 */
419 - function isOpen() { return $this->mOpened; }
 432+ function isOpen() {
 433+ return $this->mOpened;
 434+ }
420435
421436 /**
422437 * Set a flag for this connection
@@ -459,6 +474,9 @@
460475 return $this->$name;
461476 }
462477
 478+ /**
 479+ * @return string
 480+ */
463481 function getWikiID() {
464482 if ( $this->mTablePrefix ) {
465483 return "{$this->mDBname}-{$this->mTablePrefix}";
@@ -469,6 +487,8 @@
470488
471489 /**
472490 * Return a path to the DBMS-specific schema, otherwise default to tables.sql
 491+ *
 492+ * @return string
473493 */
474494 public function getSchema() {
475495 global $IP;
@@ -522,6 +542,8 @@
523543 /**
524544 * Same as new DatabaseMysql( ... ), kept for backward compatibility
525545 * @deprecated since 1.17
 546+ *
 547+ * @return DatabaseMysql
526548 */
527549 static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) {
528550 wfDeprecated( __METHOD__ );
@@ -620,6 +642,8 @@
621643 /**
622644 * Determine whether a query writes to the DB.
623645 * Should return true if unsure.
 646+ *
 647+ * @return bool
624648 */
625649 function isWriteQuery( $sql ) {
626650 return !preg_match( '/^(?:SELECT|BEGIN|COMMIT|SET|SHOW|\(SELECT)\b/i', $sql );
@@ -780,6 +804,8 @@
781805 * ! = raw SQL bit (a function for instance)
782806 * & = filename; reads the file and inserts as a blob
783807 * (we don't use this though...)
 808+ *
 809+ * @return array
784810 */
785811 function prepare( $sql, $func = 'DatabaseBase::prepare' ) {
786812 /* MySQL doesn't support prepared statements (yet), so just
@@ -796,6 +822,8 @@
797823 * Execute a prepared query with the various arguments
798824 * @param $prepared String: the prepared sql
799825 * @param $args Mixed: Either an array here, or put scalars as varargs
 826+ *
 827+ * @return ResultWrapper
800828 */
801829 function execute( $prepared, $args = null ) {
802830 if ( !is_array( $args ) ) {
@@ -814,6 +842,8 @@
815843 * in the appropriate places.
816844 * @param $query String
817845 * @param $args ...
 846+ *
 847+ * @return ResultWrapper
818848 */
819849 function safeQuery( $query, $args = null ) {
820850 $prepared = $this->prepare( $query, 'DatabaseBase::safeQuery' );
@@ -890,6 +920,8 @@
891921 *
892922 * This function exists for historical reasons, DatabaseBase::update() has a more standard
893923 * calling convention and feature set
 924+ *
 925+ * @return bool
894926 */
895927 function set( $table, $var, $value, $cond, $fname = 'DatabaseBase::set' ) {
896928 $table = $this->tableName( $table );
@@ -1211,6 +1243,8 @@
12121244 * Determines whether an index exists
12131245 * Usually aborts on failure
12141246 * If errors are explicitly ignored, returns NULL on failure
 1247+ *
 1248+ * @return bool|null
12151249 */
12161250 function indexExists( $table, $index, $fname = 'DatabaseBase::indexExists' ) {
12171251 $info = $this->indexInfo( $table, $index, $fname );
@@ -1223,6 +1257,10 @@
12241258
12251259 /**
12261260 * Query whether a given table exists
 1261+ *
 1262+ * @string table
 1263+ *
 1264+ * @return bool
12271265 */
12281266 function tableExists( $table ) {
12291267 $table = $this->tableName( $table );
@@ -1246,6 +1284,11 @@
12471285
12481286 /**
12491287 * Determines if a given index is unique
 1288+ *
 1289+ * @param $table string
 1290+ * @param $index string
 1291+ *
 1292+ * @return bool
12501293 */
12511294 function indexUnique( $table, $index ) {
12521295 $indexInfo = $this->indexInfo( $table, $index );
@@ -1375,7 +1418,7 @@
13761419 /**
13771420 * Makes an encoded list of strings from an array
13781421 * @param $a Array
1379 - * @param $mode
 1422+ * @param $mode int
13801423 * LIST_COMMA - comma separated, no field names
13811424 * LIST_AND - ANDed WHERE clause (without the WHERE)
13821425 * LIST_OR - ORed WHERE clause (without the WHERE)
@@ -1488,14 +1531,28 @@
14891532 * Bitwise operations
14901533 */
14911534
 1535+ /**
 1536+ * @param $field
 1537+ * @return string
 1538+ */
14921539 function bitNot( $field ) {
14931540 return "(~$field)";
14941541 }
14951542
 1543+ /**
 1544+ * @param $fieldLeft
 1545+ * @param $fieldRight
 1546+ * @return string
 1547+ */
14961548 function bitAnd( $fieldLeft, $fieldRight ) {
14971549 return "($fieldLeft & $fieldRight)";
14981550 }
14991551
 1552+ /**
 1553+ * @param $fieldLeft
 1554+ * @param $fieldRight
 1555+ * @return string
 1556+ */
15001557 function bitOr( $fieldLeft, $fieldRight ) {
15011558 return "($fieldLeft | $fieldRight)";
15021559 }
@@ -1731,6 +1788,10 @@
17321789
17331790 /**
17341791 * Get the name of an index in a given table
 1792+ *
 1793+ * @param $index
 1794+ *
 1795+ * @return string
17351796 */
17361797 function indexName( $index ) {
17371798 // Backwards-compatibility hack
@@ -1750,6 +1811,10 @@
17511812 /**
17521813 * If it's a string, adds quotes and backslashes
17531814 * Otherwise returns as-is
 1815+ *
 1816+ * @param $s string
 1817+ *
 1818+ * @return string
17541819 */
17551820 function addQuotes( $s ) {
17561821 if ( $s === null ) {
@@ -1768,6 +1833,8 @@
17691834 * MySQL uses `backticks` while basically everything else uses double quotes.
17701835 * Since MySQL is the odd one out here the double quotes are our generic
17711836 * and we implement backticks in DatabaseMysql.
 1837+ *
 1838+ * @return string
17721839 */
17731840 public function addIdentifierQuotes( $s ) {
17741841 return '"' . str_replace( '"', '""', $s ) . '"';
@@ -1776,6 +1843,9 @@
17771844 /**
17781845 * Returns if the given identifier looks quoted or not according to
17791846 * the database convention for quoting identifiers .
 1847+ *
 1848+ * @param $name string
 1849+ *
17801850 * @return boolean
17811851 */
17821852 public function isQuotedIdentifier( $name ) {
@@ -1787,6 +1857,8 @@
17881858 * which used quote_ident which does not follow our naming conventions
17891859 * was renamed to addIdentifierQuotes.
17901860 * @deprecated since 1.18 use addIdentifierQuotes
 1861+ *
 1862+ * @return string
17911863 */
17921864 function quote_ident( $s ) {
17931865 wfDeprecated( __METHOD__ );
@@ -1846,6 +1918,8 @@
18471919
18481920 /**
18491921 * Returns a token for buildLike() that denotes a '_' to be used in a LIKE query
 1922+ *
 1923+ * @return LikeMatch
18501924 */
18511925 function anyChar() {
18521926 return new LikeMatch( '_' );
@@ -1853,6 +1927,8 @@
18541928
18551929 /**
18561930 * Returns a token for buildLike() that denotes a '%' to be used in a LIKE query
 1931+ *
 1932+ * @rerturn LikeMatch
18571933 */
18581934 function anyString() {
18591935 return new LikeMatch( '%' );
@@ -2008,6 +2084,8 @@
20092085 * Source items may be literals rather than field names, but strings should be quoted with DatabaseBase::addQuotes()
20102086 * $conds may be "*" to copy the whole table
20112087 * srcTable may be an array of tables.
 2088+ *
 2089+ * @return ResultWrapper
20122090 */
20132091 function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = 'DatabaseBase::insertSelect',
20142092 $insertOptions = array(), $selectOptions = array() )
@@ -2060,6 +2138,8 @@
20612139 * @param $sql String: SQL query we will append the limit too
20622140 * @param $limit Integer: the SQL limit
20632141 * @param $offset Integer the SQL offset (default false)
 2142+ *
 2143+ * @return string
20642144 */
20652145 function limitResult( $sql, $limit, $offset = false ) {
20662146 if ( !is_numeric( $limit ) ) {
@@ -2117,6 +2197,8 @@
21182198 * @param $orig String: column to modify
21192199 * @param $old String: column to seek
21202200 * @param $new String: column to replace with
 2201+ *
 2202+ * @return string
21212203 */
21222204 function strreplace( $orig, $old, $new ) {
21232205 return "REPLACE({$orig}, {$old}, {$new})";
@@ -2125,6 +2207,8 @@
21262208 /**
21272209 * Determines if the last failure was due to a deadlock
21282210 * STUB
 2211+ *
 2212+ * @return bool
21292213 */
21302214 function wasDeadlock() {
21312215 return false;
@@ -2134,6 +2218,8 @@
21352219 * Determines if the last query error was something that should be dealt
21362220 * with by pinging the connection and reissuing the query.
21372221 * STUB
 2222+ *
 2223+ * @return bool
21382224 */
21392225 function wasErrorReissuable() {
21402226 return false;
@@ -2142,6 +2228,8 @@
21432229 /**
21442230 * Determines if the last failure was due to the database being read-only.
21452231 * STUB
 2232+ *
 2233+ * @return bool
21462234 */
21472235 function wasReadOnlyError() {
21482236 return false;
@@ -2257,6 +2345,8 @@
22582346
22592347 /**
22602348 * Get the position of the master from SHOW SLAVE STATUS
 2349+ *
 2350+ * @return MySQLMasterPos|false
22612351 */
22622352 function getSlavePos() {
22632353 if ( !is_null( $this->mFakeSlaveLag ) ) {
@@ -2278,6 +2368,8 @@
22792369
22802370 /**
22812371 * Get the position of the master from SHOW MASTER STATUS
 2372+ *
 2373+ * @return MySQLMasterPos|false
22822374 */
22832375 function getMasterPos() {
22842376 if ( $this->mFakeMaster ) {
@@ -2353,6 +2445,8 @@
23542446
23552447 /**
23562448 * Return MW-style timestamp used for MySQL schema
 2449+ *
 2450+ * @return string
23572451 */
23582452 function timestamp( $ts = 0 ) {
23592453 return wfTimestamp( TS_MW, $ts );
@@ -2360,6 +2454,8 @@
23612455
23622456 /**
23632457 * Local database timestamp format or null
 2458+ *
 2459+ * @return string
23642460 */
23652461 function timestampOrNull( $ts = null ) {
23662462 if ( is_null( $ts ) ) {
@@ -2371,6 +2467,8 @@
23722468
23732469 /**
23742470 * @todo document
 2471+ *
 2472+ * @return ResultWrapper
23752473 */
23762474 function resultObject( $result ) {
23772475 if ( empty( $result ) ) {
@@ -2413,6 +2511,8 @@
24142512
24152513 /**
24162514 * Get status information from SHOW STATUS in an associative array
 2515+ *
 2516+ * @return array
24172517 */
24182518 function getStatus( $which = "%" ) {
24192519 $res = $this->query( "SHOW STATUS LIKE '{$which}'" );
@@ -2427,6 +2527,8 @@
24282528
24292529 /**
24302530 * Return the maximum number of items allowed in a list, or 0 for unlimited.
 2531+ *
 2532+ * return int
24312533 */
24322534 function maxListLen() {
24332535 return 0;
Index: trunk/phase3/includes/db/CloneDatabase.php
@@ -62,6 +62,7 @@
6363 * @param $tablesToClone Array An array of tables to clone, unprefixed
6464 * @param $newTablePrefix String Prefix to assign to the tables
6565 * @param $oldTablePrefix String Prefix on current tables, if not $wgDBprefix
 66+ * @param $dropCurrentTables bool
6667 */
6768 public function __construct( DatabaseBase $db, array $tablesToClone,
6869 $newTablePrefix = 'parsertest', $oldTablePrefix = '', $dropCurrentTables = true )
Index: trunk/phase3/includes/db/LBFactory.php
@@ -28,6 +28,8 @@
2929
3030 /**
3131 * Get an LBFactory instance
 32+ *
 33+ * @return LBFactory
3234 */
3335 static function &singleton() {
3436 if ( is_null( self::$instance ) ) {
@@ -52,6 +54,8 @@
5355
5456 /**
5557 * Set the instance to be the given object
 58+ *
 59+ * @param $instance LBFactory
5660 */
5761 static function setInstance( $instance ) {
5862 self::destroyInstance();
@@ -151,6 +155,10 @@
152156 $this->chronProt = new ChronologyProtector;
153157 }
154158
 159+ /**
 160+ * @param $wiki
 161+ * @return LoadBalancer
 162+ */
155163 function newMainLB( $wiki = false ) {
156164 global $wgDBservers, $wgMasterWaitTimeout;
157165 if ( $wgDBservers ) {
@@ -174,6 +182,10 @@
175183 ));
176184 }
177185
 186+ /**
 187+ * @param $wiki
 188+ * @return LoadBalancer
 189+ */
178190 function getMainLB( $wiki = false ) {
179191 if ( !isset( $this->mainLB ) ) {
180192 $this->mainLB = $this->newMainLB( $wiki );
@@ -183,6 +195,12 @@
184196 return $this->mainLB;
185197 }
186198
 199+ /**
 200+ * @throws MWException
 201+ * @param $cluster
 202+ * @param $wiki
 203+ * @return LoadBalancer
 204+ */
187205 function newExternalLB( $cluster, $wiki = false ) {
188206 global $wgExternalServers;
189207 if ( !isset( $wgExternalServers[$cluster] ) ) {
@@ -193,6 +211,11 @@
194212 ));
195213 }
196214
 215+ /**
 216+ * @param $cluster
 217+ * @param $wiki
 218+ * @return array
 219+ */
197220 function &getExternalLB( $cluster, $wiki = false ) {
198221 if ( !isset( $this->extLBs[$cluster] ) ) {
199222 $this->extLBs[$cluster] = $this->newExternalLB( $cluster, $wiki );
Index: trunk/phase3/includes/db/DatabaseUtility.php
@@ -191,6 +191,9 @@
192192 $this->result = $array;
193193 }
194194
 195+ /**
 196+ * @return int
 197+ */
195198 function numRows() {
196199 return count( $this->result );
197200 }

Status & tagging log