r97301 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97300‎ | r97301 | r97302 >
Date:17:58, 16 September 2011
Author:reedy
Status:ok
Tags:
Comment:
Moar documentations
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseError.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMysql.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseUtility.php (modified) (history)
  • /trunk/phase3/includes/db/LBFactory_Multi.php (modified) (history)
  • /trunk/phase3/includes/db/LBFactory_Single.php (modified) (history)
  • /trunk/phase3/includes/db/LoadBalancer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -3153,6 +3153,8 @@
31543154 *
31553155 * @param $wiki String
31563156 * @param $bits String
 3157+ *
 3158+ * @return array
31573159 */
31583160 function wfSplitWikiID( $wiki ) {
31593161 $bits = explode( '-', $wiki, 2 );
Index: trunk/phase3/includes/db/DatabaseMysql.php
@@ -14,6 +14,10 @@
1515 * @see Database
1616 */
1717 class DatabaseMysql extends DatabaseBase {
 18+
 19+ /**
 20+ * @return string
 21+ */
1822 function getType() {
1923 return 'mysql';
2024 }
@@ -138,6 +142,9 @@
139143 return $success;
140144 }
141145
 146+ /**
 147+ * @return bool
 148+ */
142149 function close() {
143150 $this->mOpened = false;
144151 if ( $this->mConn ) {
@@ -188,6 +195,11 @@
189196 return $row;
190197 }
191198
 199+ /**
 200+ * @throws DBUnexpectedError
 201+ * @param $res
 202+ * @return int
 203+ */
192204 function numRows( $res ) {
193205 if ( $res instanceof ResultWrapper ) {
194206 $res = $res->result;
@@ -201,6 +213,10 @@
202214 return $n;
203215 }
204216
 217+ /**
 218+ * @param $res
 219+ * @return int
 220+ */
205221 function numFields( $res ) {
206222 if ( $res instanceof ResultWrapper ) {
207223 $res = $res->result;
@@ -208,6 +224,11 @@
209225 return mysql_num_fields( $res );
210226 }
211227
 228+ /**
 229+ * @param $res
 230+ * @param $n
 231+ * @return string
 232+ */
212233 function fieldName( $res, $n ) {
213234 if ( $res instanceof ResultWrapper ) {
214235 $res = $res->result;
@@ -215,7 +236,12 @@
216237 return mysql_field_name( $res, $n );
217238 }
218239
219 - function insertId() { return mysql_insert_id( $this->mConn ); }
 240+ /**
 241+ * @return int
 242+ */
 243+ function insertId() {
 244+ return mysql_insert_id( $this->mConn );
 245+ }
220246
221247 function dataSeek( $res, $row ) {
222248 if ( $res instanceof ResultWrapper ) {
@@ -250,7 +276,12 @@
251277 return $error;
252278 }
253279
254 - function affectedRows() { return mysql_affected_rows( $this->mConn ); }
 280+ /**
 281+ * @return int
 282+ */
 283+ function affectedRows() {
 284+ return mysql_affected_rows( $this->mConn );
 285+ }
255286
256287 function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseMysql::replace' ) {
257288 return $this->nativeReplace( $table, $rows, $fname );
@@ -260,6 +291,8 @@
261292 * Estimate rows in dataset
262293 * Returns estimated count, based on EXPLAIN output
263294 * Takes same arguments as Database::select()
 295+ *
 296+ * @return int
264297 */
265298 public function estimateRowCount( $table, $vars='*', $conds='', $fname = 'DatabaseMysql::estimateRowCount', $options = array() ) {
266299 $options['EXPLAIN'] = true;
@@ -278,6 +311,11 @@
279312 return $rows;
280313 }
281314
 315+ /**
 316+ * @param $table string
 317+ * @param $field string
 318+ * @return bool|MySQLField
 319+ */
282320 function fieldInfo( $table, $field ) {
283321 $table = $this->tableName( $table );
284322 $res = $this->query( "SELECT * FROM $table LIMIT 1", __METHOD__, true );
@@ -297,6 +335,8 @@
298336 /**
299337 * Get information about an index into an object
300338 * Returns false if the index does not exist
 339+ *
 340+ * @return false|array
301341 */
302342 function indexInfo( $table, $index, $fname = 'DatabaseMysql::indexInfo' ) {
303343 # SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not.
@@ -322,11 +362,20 @@
323363 return empty( $result ) ? false : $result;
324364 }
325365
 366+ /**
 367+ * @param $db
 368+ * @return bool
 369+ */
326370 function selectDB( $db ) {
327371 $this->mDBname = $db;
328372 return mysql_select_db( $db, $this->mConn );
329373 }
330374
 375+ /**
 376+ * @param $s string
 377+ *
 378+ * @return string
 379+ */
331380 function strencode( $s ) {
332381 $sQuoted = mysql_real_escape_string( $s, $this->mConn );
333382
@@ -339,15 +388,26 @@
340389
341390 /**
342391 * MySQL uses `backticks` for identifier quoting instead of the sql standard "double quotes".
 392+ *
 393+ * @param $s string
 394+ *
 395+ * @return string
343396 */
344397 public function addIdentifierQuotes( $s ) {
345398 return "`" . $this->strencode( $s ) . "`";
346399 }
347400
 401+ /**
 402+ * @param $name string
 403+ * @return bool
 404+ */
348405 public function isQuotedIdentifier( $name ) {
349 - return strlen($name) && $name[0] == '`' && substr( $name, -1, 1 ) == '`';
 406+ return strlen( $name ) && $name[0] == '`' && substr( $name, -1, 1 ) == '`';
350407 }
351408
 409+ /**
 410+ * @return bool
 411+ */
352412 function ping() {
353413 $ping = mysql_ping( $this->mConn );
354414 if ( $ping ) {
@@ -516,18 +576,31 @@
517577 }
518578 }
519579
 580+ /**
 581+ * @return string
 582+ */
520583 function getServerVersion() {
521584 return mysql_get_server_info( $this->mConn );
522585 }
523586
 587+ /**
 588+ * @param $index
 589+ * @return string
 590+ */
524591 function useIndexClause( $index ) {
525592 return "FORCE INDEX (" . $this->indexName( $index ) . ")";
526593 }
527594
 595+ /**
 596+ * @return string
 597+ */
528598 function lowPriorityOption() {
529599 return 'LOW_PRIORITY';
530600 }
531601
 602+ /**
 603+ * @return string
 604+ */
532605 public static function getSoftwareLink() {
533606 return '[http://www.mysql.com/ MySQL]';
534607 }
@@ -630,6 +703,8 @@
631704
632705 /**
633706 * Determines if the last failure was due to a deadlock
 707+ *
 708+ * @return bool
634709 */
635710 function wasDeadlock() {
636711 return $this->lastErrno() == 1213;
@@ -638,6 +713,8 @@
639714 /**
640715 * Determines if the last query error was something that should be dealt
641716 * with by pinging the connection and reissuing the query
 717+ *
 718+ * @return bool
642719 */
643720 function wasErrorReissuable() {
644721 return $this->lastErrno() == 2013 || $this->lastErrno() == 2006;
@@ -645,6 +722,8 @@
646723
647724 /**
648725 * Determines if the last failure was due to the database being read-only.
 726+ *
 727+ * @return bool
649728 */
650729 function wasReadOnlyError() {
651730 return $this->lastErrno() == 1223 ||
@@ -702,6 +781,11 @@
703782 return $endArray;
704783 }
705784
 785+ /**
 786+ * @param $tableName
 787+ * @param $fName string
 788+ * @return bool|ResultWrapper
 789+ */
706790 public function dropTable( $tableName, $fName = 'DatabaseMysql::dropTable' ) {
707791 if( !$this->tableExists( $tableName ) ) {
708792 return false;
@@ -735,6 +819,8 @@
736820
737821 /**
738822 * Legacy support: Database == DatabaseMysql
 823+ *
 824+ * @deprecated in 1.16
739825 */
740826 class Database extends DatabaseMysql {}
741827
@@ -759,10 +845,16 @@
760846 $this->type = $info->type;
761847 }
762848
 849+ /**
 850+ * @return string
 851+ */
763852 function name() {
764853 return $this->name;
765854 }
766855
 856+ /**
 857+ * @return string
 858+ */
767859 function tableName() {
768860 return $this->tableName;
769861 }
@@ -771,6 +863,9 @@
772864 return $this->type;
773865 }
774866
 867+ /**
 868+ * @return bool
 869+ */
775870 function isNullable() {
776871 return $this->nullable;
777872 }
@@ -779,14 +874,23 @@
780875 return $this->default;
781876 }
782877
 878+ /**
 879+ * @return bool
 880+ */
783881 function isKey() {
784882 return $this->is_key;
785883 }
786884
 885+ /**
 886+ * @return bool
 887+ */
787888 function isMultipleKey() {
788889 return $this->is_multiple;
789890 }
790891
 892+ /**
 893+ * @return int
 894+ */
791895 function maxLength() {
792896 return $this->max_length;
793897 }
Index: trunk/phase3/includes/db/DatabaseError.php
@@ -87,6 +87,11 @@
8888 return false;
8989 }
9090
 91+ /**
 92+ * @param $key
 93+ * @param $fallback
 94+ * @return string
 95+ */
9196 function msg( $key, $fallback /*[, params...] */ ) {
9297 global $wgLang;
9398
Index: trunk/phase3/includes/db/LBFactory_Multi.php
@@ -59,7 +59,7 @@
6060 $required = array( 'sectionsByDB', 'sectionLoads', 'serverTemplate' );
6161 $optional = array( 'groupLoadsBySection', 'groupLoadsByDB', 'hostsByName',
6262 'externalLoads', 'externalTemplateOverrides', 'templateOverridesByServer',
63 - 'templateOverridesByCluster', 'masterTemplateOverrides',
 63+ 'templateOverridesByCluster', 'masterTemplateOverrides',
6464 'readOnlyBySection' );
6565
6666 foreach ( $required as $key ) {
@@ -83,6 +83,10 @@
8484 }
8585 }
8686
 87+ /**
 88+ * @param $wiki bool|string
 89+ * @return string
 90+ */
8791 function getSectionForWiki( $wiki = false ) {
8892 if ( $this->lastWiki === $wiki ) {
8993 return $this->lastSection;
@@ -99,7 +103,7 @@
100104 }
101105
102106 /**
103 - * @param $wiki string
 107+ * @param $wiki bool|string
104108 * @return LoadBalancer
105109 */
106110 function newMainLB( $wiki = false ) {
@@ -116,7 +120,7 @@
117121 }
118122
119123 /**
120 - * @param $wiki
 124+ * @param $wiki bool|string
121125 * @return LoadBalancer
122126 */
123127 function getMainLB( $wiki = false ) {
@@ -172,7 +176,7 @@
173177 $servers = $this->makeServerArray( $template, $loads, $groupLoads );
174178 $lb = new LoadBalancer( array(
175179 'servers' => $servers,
176 - 'masterWaitTimeout' => $wgMasterWaitTimeout
 180+ 'masterWaitTimeout' => $wgMasterWaitTimeout
177181 ));
178182 return $lb;
179183 }
@@ -180,6 +184,9 @@
181185 /**
182186 * Make a server array as expected by LoadBalancer::__construct, using a template and load array
183187 *
 188+ * @param $template
 189+ * @param $loads
 190+ * @param $groupLoads
184191 * @return array
185192 */
186193 function makeServerArray( $template, $loads, $groupLoads ) {
@@ -220,6 +227,8 @@
221228
222229 /**
223230 * Take a group load array indexed by group then server, and reindex it by server then group
 231+ * @param $groupLoads
 232+ * @return array
224233 */
225234 function reindexGroupLoads( $groupLoads ) {
226235 $reindexed = array();
@@ -233,6 +242,8 @@
234243
235244 /**
236245 * Get the database name and prefix based on the wiki ID
 246+ * @param bool $wiki
 247+ * @return array
237248 */
238249 function getDBNameAndPrefix( $wiki = false ) {
239250 if ( $wiki === false ) {
@@ -247,6 +258,8 @@
248259 * Execute a function for each tracked load balancer
249260 * The callback is called with the load balancer as the first parameter,
250261 * and $params passed as the subsequent parameters.
 262+ * @param $callback
 263+ * @param $params array
251264 */
252265 function forEachLB( $callback, $params = array() ) {
253266 foreach ( $this->mainLBs as $lb ) {
Index: trunk/phase3/includes/db/Database.php
@@ -224,6 +224,8 @@
225225 protected $mDefaultBigSelects = null;
226226 protected $mSchemaVars = false;
227227
 228+ protected $preparedArgs;
 229+
228230 # ------------------------------------------------------------------------------
229231 # Accessors
230232 # ------------------------------------------------------------------------------
@@ -290,7 +292,7 @@
291293 * code should use lastErrno() and lastError() to handle the
292294 * situation as appropriate.
293295 *
294 - * @param $ignoreErrors
 296+ * @param $ignoreErrors bool|null
295297 *
296298 * @return The previous value of the flag.
297299 */
@@ -433,6 +435,8 @@
434436 /**
435437 * Returns true if this database does an implicit order by when the column has an index
436438 * For example: SELECT page_title FROM page LIMIT 1
 439+ *
 440+ * @return bool
437441 */
438442 function implicitOrderby() {
439443 return true;
@@ -530,6 +534,10 @@
531535
532536 /**
533537 * General read-only accessor
 538+ *
 539+ * @param $name string
 540+ *
 541+ * @return string
534542 */
535543 function getProperty( $name ) {
536544 return $this->$name;
@@ -707,7 +715,7 @@
708716 * The DBMS-dependent part of query()
709717 *
710718 * @param $sql String: SQL query.
711 - * @return Result object to feed to fetchObject, fetchRow, ...; or false on failure
 719+ * @return ResultWrapper Result object to feed to fetchObject, fetchRow, ...; or false on failure
712720 */
713721 protected abstract function doQuery( $sql );
714722
@@ -1182,7 +1190,6 @@
11831191 * @param $options Array Query options
11841192 * @param $join_conds Array Join conditions
11851193 *
1186 - *
11871194 * @param $table string|array
11881195 *
11891196 * May be either an array of table names, or a single string holding a table
@@ -1429,8 +1436,8 @@
14301437 * Takes the same arguments as DatabaseBase::select().
14311438 *
14321439 * @param $table String: table name
1433 - * @param $vars Array: unused
1434 - * @param $conds Array: filters on the table
 1440+ * @param Array|string $vars : unused
 1441+ * @param Array|string $conds : filters on the table
14351442 * @param $fname String: function name for profiling
14361443 * @param $options Array: options for select
14371444 * @return Integer: row count
Index: trunk/phase3/includes/db/LBFactory_Single.php
@@ -15,7 +15,7 @@
1616 }
1717
1818 /**
19 - * @param $wiki
 19+ * @param $wiki bool|string
2020 *
2121 * @return LoadBalancer_Single
2222 */
@@ -24,7 +24,7 @@
2525 }
2626
2727 /**
28 - * @param $wiki
 28+ * @param $wiki bool|string
2929 *
3030 * @return LoadBalancer_Single
3131 */
@@ -34,7 +34,7 @@
3535
3636 /**
3737 * @param $cluster
38 - * @param $wiki
 38+ * @param $wiki bool|string
3939 *
4040 * @return LoadBalancer_Single
4141 */
@@ -44,7 +44,7 @@
4545
4646 /**
4747 * @param $cluster
48 - * @param $wiki
 48+ * @param $wiki bool|string
4949 *
5050 * @return LoadBalancer_Single
5151 */
Index: trunk/phase3/includes/db/LoadBalancer.php
@@ -391,6 +391,9 @@
392392
393393 /**
394394 * Wait for a given slave to catch up to the master pos stored in $this
 395+ * @param $index
 396+ * @param $open bool
 397+ * @return bool
395398 */
396399 function doWait( $index, $open = false ) {
397400 # Find a connection to wait on
@@ -668,7 +671,7 @@
669672 function reallyOpenConnection( $server, $dbNameOverride = false ) {
670673 if( !is_array( $server ) ) {
671674 throw new MWException( 'You must update your load-balancing configuration. ' .
672 - 'See DefaultSettings.php entry for $wgDBservers.' );
 675+ 'See DefaultSettings.php entry for $wgDBservers.' );
673676 }
674677
675678 $host = $server['host'];
@@ -837,8 +840,7 @@
838841 * Close a connection
839842 * Using this function makes sure the LoadBalancer knows the connection is closed.
840843 * If you use $conn->close() directly, the load balancer won't update its state.
841 - * @param $conn
842 - * @return void
 844+ * @param $conn DatabaseBase
843845 */
844846 function closeConnection( $conn ) {
845847 $done = false;
@@ -890,10 +892,17 @@
891893 }
892894 }
893895
 896+ /**
 897+ * @param $value null
 898+ * @return Mixed
 899+ */
894900 function waitTimeout( $value = null ) {
895901 return wfSetVar( $this->mWaitTimeout, $value );
896902 }
897903
 904+ /**
 905+ * @return bool
 906+ */
898907 function getLaggedSlaveMode() {
899908 return $this->mLaggedSlaveMode;
900909 }
@@ -906,6 +915,9 @@
907916 $this->mAllowLagged = $mode;
908917 }
909918
 919+ /**
 920+ * @return bool
 921+ */
910922 function pingAll() {
911923 $success = true;
912924 foreach ( $this->mConns as $conns2 ) {
@@ -1005,6 +1017,10 @@
10061018 * potentially restricted queries such as SHOW SLAVE STATUS. Using this
10071019 * function instead of Database::getLag() avoids a fatal error in this
10081020 * case on many installations.
 1021+ *
 1022+ * @param $conn DatabaseBase
 1023+ *
 1024+ * @return int
10091025 */
10101026 function safeGetLag( $conn ) {
10111027 if ( $this->getServerCount() == 1 ) {
Index: trunk/phase3/includes/db/DatabaseUtility.php
@@ -155,6 +155,9 @@
156156 $this->currentRow = null;
157157 }
158158
 159+ /**
 160+ * @return int
 161+ */
159162 function current() {
160163 if ( is_null( $this->currentRow ) ) {
161164 $this->next();
@@ -162,16 +165,25 @@
163166 return $this->currentRow;
164167 }
165168
 169+ /**
 170+ * @return int
 171+ */
166172 function key() {
167173 return $this->pos;
168174 }
169175
 176+ /**
 177+ * @return int
 178+ */
170179 function next() {
171180 $this->pos++;
172181 $this->currentRow = $this->fetchObject();
173182 return $this->currentRow;
174183 }
175184
 185+ /**
 186+ * @return bool
 187+ */
176188 function valid() {
177189 return $this->current() !== false;
178190 }

Status & tagging log