r89051 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89050‎ | r89051 | r89052 >
Date:17:52, 28 May 2011
Author:reedy
Status:deferred
Tags:
Comment:
Some for MaxSem too
Modified paths:
  • /trunk/phase3/includes/Licenses.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseSqlite.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Licenses.php
@@ -28,6 +28,8 @@
2929
3030 /**
3131 * Constructor
 32+ *
 33+ * @param $params array
3234 */
3335 public function __construct( $params ) {
3436 parent::__construct( $params );
@@ -38,7 +40,7 @@
3941 $this->makeLicenses();
4042 }
4143
42 - /**#@+
 44+ /**
4345 * @private
4446 */
4547 protected function makeLicenses() {
@@ -46,9 +48,9 @@
4749 $lines = explode( "\n", $this->msg );
4850
4951 foreach ( $lines as $line ) {
50 - if ( strpos( $line, '*' ) !== 0 )
 52+ if ( strpos( $line, '*' ) !== 0 ) {
5153 continue;
52 - else {
 54+ } else {
5355 list( $level, $line ) = $this->trimStars( $line );
5456
5557 if ( strpos( $line, '|' ) !== false ) {
@@ -68,19 +70,34 @@
6971 }
7072 }
7173
 74+ /**
 75+ * @param $str
 76+ * @return array
 77+ */
7278 protected function trimStars( $str ) {
7379 $numStars = strspn( $str, '*' );
7480 return array( $numStars, ltrim( substr( $str, $numStars ), ' ' ) );
7581 }
7682
 83+ /**
 84+ * @param $list
 85+ * @param $path
 86+ * @param $item
 87+ */
7788 protected function stackItem( &$list, $path, $item ) {
7889 $position =& $list;
79 - if ( $path )
80 - foreach( $path as $key )
 90+ if ( $path ) {
 91+ foreach( $path as $key ) {
8192 $position =& $position[$key];
 93+ }
 94+ }
8295 $position[] = $item;
8396 }
8497
 98+ /**
 99+ * @param $tagset
 100+ * @param $depth int
 101+ */
85102 protected function makeHtml( $tagset, $depth = 0 ) {
86103 foreach ( $tagset as $key => $val )
87104 if ( is_array( $val ) ) {
@@ -102,6 +119,13 @@
103120 }
104121 }
105122
 123+ /**
 124+ * @param $text
 125+ * @param $value
 126+ * @param $attribs null
 127+ * @param $depth int
 128+ * @return string
 129+ */
106130 protected function outputOption( $text, $value, $attribs = null, $depth = 0 ) {
107131 $attribs['value'] = $value;
108132 if ( $value === $this->selected )
@@ -122,11 +146,15 @@
123147 *
124148 * @return array
125149 */
126 - public function getLicenses() { return $this->licenses; }
 150+ public function getLicenses() {
 151+ return $this->licenses;
 152+ }
127153
128154 /**
129155 * Accessor for $this->html
130156 *
 157+ * @param $value bool
 158+ *
131159 * @return string
132160 */
133161 public function getInputHTML( $value ) {
@@ -140,8 +168,9 @@
141169 'name' => $this->mName,
142170 'id' => $this->mID
143171 );
144 - if ( !empty( $this->mParams['disabled'] ) )
 172+ if ( !empty( $this->mParams['disabled'] ) ) {
145173 $attibs['disabled'] = 'disabled';
 174+ }
146175
147176 return Html::rawElement( 'select', $attribs, $this->html );
148177 }
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -20,6 +20,11 @@
2121 var $mName;
2222
2323 /**
 24+ * @var PDO
 25+ */
 26+ protected $mConn;
 27+
 28+ /**
2429 * Constructor.
2530 * Parameters $server, $user and $password are not used.
2631 */
@@ -35,14 +40,21 @@
3641 }
3742 }
3843
 44+ /**
 45+ * @return string
 46+ */
3947 function getType() {
4048 return 'sqlite';
4149 }
4250
4351 /**
4452 * @todo: check if it should be true like parent class
 53+ *
 54+ * @return bool
4555 */
46 - function implicitGroupby() { return false; }
 56+ function implicitGroupby() {
 57+ return false;
 58+ }
4759
4860 /** Open an SQLite database and return a resource handle to it
4961 * NOTE: only $dbName is used, the other parameters are irrelevant for SQLite databases
@@ -61,7 +73,10 @@
6274
6375 /**
6476 * Opens a database file
65 - * @return SQL connection or false if failed
 77+ *
 78+ * @param $fileName string
 79+ *
 80+ * @return PDO|false SQL connection or false if failed
6681 */
6782 function openFile( $fileName ) {
6883 $this->mDatabaseFile = $fileName;
@@ -152,9 +167,12 @@
153168 /**
154169 * Attaches external database to our connection, see http://sqlite.org/lang_attach.html
155170 * for details.
 171+ *
156172 * @param $name String: database name to be used in queries like SELECT foo FROM dbname.table
157173 * @param $file String: database file name. If omitted, will be generated using $name and $wgSQLiteDataDir
158174 * @param $fname String: calling function name
 175+ *
 176+ * @return ResultWrapper
159177 */
160178 function attachDatabase( $name, $file = false, $fname = 'DatabaseSqlite::attachDatabase' ) {
161179 global $wgSQLiteDataDir;
@@ -168,6 +186,8 @@
169187 /**
170188 * @see DatabaseBase::isWriteQuery()
171189 *
 190+ * @param $sql string
 191+ *
172192 * @return bool
173193 */
174194 function isWriteQuery( $sql ) {
@@ -176,6 +196,10 @@
177197
178198 /**
179199 * SQLite doesn't allow buffered results or data seeking etc, so we'll use fetchAll as the result
 200+ *
 201+ * @param $sql string
 202+ *
 203+ * @return ResultWrapper
180204 */
181205 function doQuery( $sql ) {
182206 $res = $this->mConn->query( $sql );
@@ -189,6 +213,9 @@
190214 return $res;
191215 }
192216
 217+ /**
 218+ * @param $res ResultWrapper
 219+ */
193220 function freeResult( $res ) {
194221 if ( $res instanceof ResultWrapper ) {
195222 $res->result = null;
@@ -197,6 +224,10 @@
198225 }
199226 }
200227
 228+ /**
 229+ * @param $res ResultWrapper
 230+ * @return
 231+ */
201232 function fetchObject( $res ) {
202233 if ( $res instanceof ResultWrapper ) {
203234 $r =& $res->result;
@@ -219,6 +250,10 @@
220251 return false;
221252 }
222253
 254+ /**
 255+ * @param $res ResultWrapper
 256+ * @return bool|mixed
 257+ */
223258 function fetchRow( $res ) {
224259 if ( $res instanceof ResultWrapper ) {
225260 $r =& $res->result;
@@ -235,37 +270,60 @@
236271
237272 /**
238273 * The PDO::Statement class implements the array interface so count() will work
 274+ *
 275+ * @param $res ResultWrapper
 276+ *
 277+ * @return int
239278 */
240279 function numRows( $res ) {
241280 $r = $res instanceof ResultWrapper ? $res->result : $res;
242281 return count( $r );
243282 }
244283
 284+ /**
 285+ * @param $res ResultWrapper
 286+ * @return int
 287+ */
245288 function numFields( $res ) {
246289 $r = $res instanceof ResultWrapper ? $res->result : $res;
247290 return is_array( $r ) ? count( $r[0] ) : 0;
248291 }
249292
 293+ /**
 294+ * @param $res ResultWrapper
 295+ * @param $n
 296+ * @return bool
 297+ */
250298 function fieldName( $res, $n ) {
251299 $r = $res instanceof ResultWrapper ? $res->result : $res;
252300 if ( is_array( $r ) ) {
253301 $keys = array_keys( $r[0] );
254302 return $keys[$n];
255303 }
256 - return false;
 304+ return false;
257305 }
258306
259307 /**
260308 * Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks
 309+ *
 310+ * @param $name
 311+ * @param bool $quoted
 312+ * @return string
261313 */
262314 function tableName( $name, $quoted = true ) {
263315 // table names starting with sqlite_ are reserved
264 - if ( strpos( $name, 'sqlite_' ) === 0 ) return $name;
 316+ if ( strpos( $name, 'sqlite_' ) === 0 ) {
 317+ return $name;
 318+ }
265319 return str_replace( '"', '', parent::tableName( $name, $quoted ) );
266320 }
267321
268322 /**
269323 * Index names have DB scope
 324+ *
 325+ * @param $index string
 326+ *
 327+ * @return string
270328 */
271329 function indexName( $index ) {
272330 return $index;
@@ -273,11 +331,17 @@
274332
275333 /**
276334 * This must be called after nextSequenceVal
 335+ *
 336+ * @return int
277337 */
278338 function insertId() {
279339 return $this->mConn->lastInsertId();
280340 }
281341
 342+ /**
 343+ * @param $res ResultWrapper
 344+ * @param $row
 345+ */
282346 function dataSeek( $res, $row ) {
283347 if ( $res instanceof ResultWrapper ) {
284348 $r =& $res->result;
@@ -292,6 +356,9 @@
293357 }
294358 }
295359
 360+ /**
 361+ * @return string
 362+ */
296363 function lastError() {
297364 if ( !is_object( $this->mConn ) ) {
298365 return "Cannot return last error, no db connection";
@@ -300,6 +367,9 @@
301368 return isset( $e[2] ) ? $e[2] : '';
302369 }
303370
 371+ /**
 372+ * @return string
 373+ */
304374 function lastErrno() {
305375 if ( !is_object( $this->mConn ) ) {
306376 return "Cannot return last error, no db connection";
@@ -309,6 +379,9 @@
310380 }
311381 }
312382
 383+ /**
 384+ * @return int
 385+ */
313386 function affectedRows() {
314387 return $this->mAffectedRows;
315388 }
@@ -317,6 +390,8 @@
318391 * Returns information about an index
319392 * Returns false if the index does not exist
320393 * - if errors are explicitly ignored, returns NULL on failure
 394+ *
 395+ * @return array
321396 */
322397 function indexInfo( $table, $index, $fname = 'DatabaseSqlite::indexExists' ) {
323398 $sql = 'PRAGMA index_info(' . $this->addQuotes( $this->indexName( $index ) ) . ')';
@@ -334,6 +409,12 @@
335410 return $info;
336411 }
337412
 413+ /**
 414+ * @param $table
 415+ * @param $index
 416+ * @param $fname string
 417+ * @return bool|null
 418+ */
338419 function indexUnique( $table, $index, $fname = 'DatabaseSqlite::indexUnique' ) {
339420 $row = $this->selectRow( 'sqlite_master', '*',
340421 array(
@@ -356,6 +437,10 @@
357438
358439 /**
359440 * Filter the options used in SELECT statements
 441+ *
 442+ * @param $options array
 443+ *
 444+ * @return array
360445 */
361446 function makeSelectOptions( $options ) {
362447 foreach ( $options as $k => $v ) {
@@ -421,6 +506,13 @@
422507 return $ret;
423508 }
424509
 510+ /**
 511+ * @param $table
 512+ * @param $uniqueIndexes
 513+ * @param $rows
 514+ * @param $fname string
 515+ * @return bool|ResultWrapper
 516+ */
425517 function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseSqlite::replace' ) {
426518 if ( !count( $rows ) ) return true;
427519
@@ -442,28 +534,47 @@
443535 /**
444536 * Returns the size of a text field, or -1 for "unlimited"
445537 * In SQLite this is SQLITE_MAX_LENGTH, by default 1GB. No way to query it though.
 538+ *
 539+ * @return int
446540 */
447541 function textFieldSize( $table, $field ) {
448542 return -1;
449543 }
450544
 545+ /**
 546+ * @return bool
 547+ */
451548 function unionSupportsOrderAndLimit() {
452549 return false;
453550 }
454551
 552+ /**
 553+ * @param $sqls
 554+ * @param $all
 555+ * @return string
 556+ */
455557 function unionQueries( $sqls, $all ) {
456558 $glue = $all ? ' UNION ALL ' : ' UNION ';
457559 return implode( $glue, $sqls );
458560 }
459561
 562+ /**
 563+ * @return bool
 564+ */
460565 function wasDeadlock() {
461566 return $this->lastErrno() == 5; // SQLITE_BUSY
462567 }
463568
 569+ /**
 570+ * @return bool
 571+ */
464572 function wasErrorReissuable() {
465573 return $this->lastErrno() == 17; // SQLITE_SCHEMA;
466574 }
467575
 576+ /**
 577+ * @return bool
 578+ */
468579 function wasReadOnlyError() {
469580 return $this->lastErrno() == 8; // SQLITE_READONLY;
470581 }
@@ -509,35 +620,58 @@
510621 }
511622
512623 function begin( $fname = '' ) {
513 - if ( $this->mTrxLevel == 1 ) $this->commit();
 624+ if ( $this->mTrxLevel == 1 ) {
 625+ $this->commit();
 626+ }
514627 $this->mConn->beginTransaction();
515628 $this->mTrxLevel = 1;
516629 }
517630
518631 function commit( $fname = '' ) {
519 - if ( $this->mTrxLevel == 0 ) return;
 632+ if ( $this->mTrxLevel == 0 ) {
 633+ return;
 634+ }
520635 $this->mConn->commit();
521636 $this->mTrxLevel = 0;
522637 }
523638
524639 function rollback( $fname = '' ) {
525 - if ( $this->mTrxLevel == 0 ) return;
 640+ if ( $this->mTrxLevel == 0 ) {
 641+ return;
 642+ }
526643 $this->mConn->rollBack();
527644 $this->mTrxLevel = 0;
528645 }
529646
 647+ /**
 648+ * @param $sql
 649+ * @param $num
 650+ * @return string
 651+ */
530652 function limitResultForUpdate( $sql, $num ) {
531653 return $this->limitResult( $sql, $num );
532654 }
533655
 656+ /**
 657+ * @param $s string
 658+ * @return string
 659+ */
534660 function strencode( $s ) {
535661 return substr( $this->addQuotes( $s ), 1, - 1 );
536662 }
537663
 664+ /**
 665+ * @param $b
 666+ * @return Blob
 667+ */
538668 function encodeBlob( $b ) {
539669 return new Blob( $b );
540670 }
541671
 672+ /**
 673+ * @param $b Blob|string
 674+ * @return string
 675+ */
542676 function decodeBlob( $b ) {
543677 if ( $b instanceof Blob ) {
544678 $b = $b->fetch();
@@ -545,6 +679,10 @@
546680 return $b;
547681 }
548682
 683+ /**
 684+ * @param $s Blob|string
 685+ * @return string
 686+ */
549687 function addQuotes( $s ) {
550688 if ( $s instanceof Blob ) {
551689 return "x'" . bin2hex( $s->fetch() ) . "'";
@@ -553,6 +691,9 @@
554692 }
555693 }
556694
 695+ /**
 696+ * @return string
 697+ */
557698 function buildLike() {
558699 $params = func_get_args();
559700 if ( count( $params ) > 0 && is_array( $params[0] ) ) {
@@ -561,6 +702,9 @@
562703 return parent::buildLike( $params ) . "ESCAPE '\' ";
563704 }
564705
 706+ /**
 707+ * @return string
 708+ */
565709 public function getSearchEngine() {
566710 return "SearchSqlite";
567711 }
@@ -623,12 +767,22 @@
624768 /**
625769 * Build a concatenation list to feed into a SQL query
626770 *
 771+ * @param $stringList array
 772+ *
627773 * @return string
628774 */
629775 function buildConcat( $stringList ) {
630776 return '(' . implode( ') || (', $stringList ) . ')';
631777 }
632778
 779+ /**
 780+ * @throws MWException
 781+ * @param $oldName
 782+ * @param $newName
 783+ * @param $temporary bool
 784+ * @param $fname string
 785+ * @return bool|ResultWrapper
 786+ */
633787 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseSqlite::duplicateTableStructure' ) {
634788 $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name=" . $this->addQuotes( $oldName ) . " AND type='table'", $fname );
635789 $obj = $this->fetchObject( $res );
@@ -722,6 +876,9 @@
723877 return $this->info->dflt_value;
724878 }
725879
 880+ /**
 881+ * @return bool
 882+ */
726883 function isNullable() {
727884 return !$this->info->notnull;
728885 }

Status & tagging log