Index: trunk/phase3/includes/Licenses.php |
— | — | @@ -28,6 +28,8 @@ |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Constructor |
| 32 | + * |
| 33 | + * @param $params array |
32 | 34 | */ |
33 | 35 | public function __construct( $params ) { |
34 | 36 | parent::__construct( $params ); |
— | — | @@ -38,7 +40,7 @@ |
39 | 41 | $this->makeLicenses(); |
40 | 42 | } |
41 | 43 | |
42 | | - /**#@+ |
| 44 | + /** |
43 | 45 | * @private |
44 | 46 | */ |
45 | 47 | protected function makeLicenses() { |
— | — | @@ -46,9 +48,9 @@ |
47 | 49 | $lines = explode( "\n", $this->msg ); |
48 | 50 | |
49 | 51 | foreach ( $lines as $line ) { |
50 | | - if ( strpos( $line, '*' ) !== 0 ) |
| 52 | + if ( strpos( $line, '*' ) !== 0 ) { |
51 | 53 | continue; |
52 | | - else { |
| 54 | + } else { |
53 | 55 | list( $level, $line ) = $this->trimStars( $line ); |
54 | 56 | |
55 | 57 | if ( strpos( $line, '|' ) !== false ) { |
— | — | @@ -68,19 +70,34 @@ |
69 | 71 | } |
70 | 72 | } |
71 | 73 | |
| 74 | + /** |
| 75 | + * @param $str |
| 76 | + * @return array |
| 77 | + */ |
72 | 78 | protected function trimStars( $str ) { |
73 | 79 | $numStars = strspn( $str, '*' ); |
74 | 80 | return array( $numStars, ltrim( substr( $str, $numStars ), ' ' ) ); |
75 | 81 | } |
76 | 82 | |
| 83 | + /** |
| 84 | + * @param $list |
| 85 | + * @param $path |
| 86 | + * @param $item |
| 87 | + */ |
77 | 88 | protected function stackItem( &$list, $path, $item ) { |
78 | 89 | $position =& $list; |
79 | | - if ( $path ) |
80 | | - foreach( $path as $key ) |
| 90 | + if ( $path ) { |
| 91 | + foreach( $path as $key ) { |
81 | 92 | $position =& $position[$key]; |
| 93 | + } |
| 94 | + } |
82 | 95 | $position[] = $item; |
83 | 96 | } |
84 | 97 | |
| 98 | + /** |
| 99 | + * @param $tagset |
| 100 | + * @param $depth int |
| 101 | + */ |
85 | 102 | protected function makeHtml( $tagset, $depth = 0 ) { |
86 | 103 | foreach ( $tagset as $key => $val ) |
87 | 104 | if ( is_array( $val ) ) { |
— | — | @@ -102,6 +119,13 @@ |
103 | 120 | } |
104 | 121 | } |
105 | 122 | |
| 123 | + /** |
| 124 | + * @param $text |
| 125 | + * @param $value |
| 126 | + * @param $attribs null |
| 127 | + * @param $depth int |
| 128 | + * @return string |
| 129 | + */ |
106 | 130 | protected function outputOption( $text, $value, $attribs = null, $depth = 0 ) { |
107 | 131 | $attribs['value'] = $value; |
108 | 132 | if ( $value === $this->selected ) |
— | — | @@ -122,11 +146,15 @@ |
123 | 147 | * |
124 | 148 | * @return array |
125 | 149 | */ |
126 | | - public function getLicenses() { return $this->licenses; } |
| 150 | + public function getLicenses() { |
| 151 | + return $this->licenses; |
| 152 | + } |
127 | 153 | |
128 | 154 | /** |
129 | 155 | * Accessor for $this->html |
130 | 156 | * |
| 157 | + * @param $value bool |
| 158 | + * |
131 | 159 | * @return string |
132 | 160 | */ |
133 | 161 | public function getInputHTML( $value ) { |
— | — | @@ -140,8 +168,9 @@ |
141 | 169 | 'name' => $this->mName, |
142 | 170 | 'id' => $this->mID |
143 | 171 | ); |
144 | | - if ( !empty( $this->mParams['disabled'] ) ) |
| 172 | + if ( !empty( $this->mParams['disabled'] ) ) { |
145 | 173 | $attibs['disabled'] = 'disabled'; |
| 174 | + } |
146 | 175 | |
147 | 176 | return Html::rawElement( 'select', $attribs, $this->html ); |
148 | 177 | } |
Index: trunk/phase3/includes/db/DatabaseSqlite.php |
— | — | @@ -20,6 +20,11 @@ |
21 | 21 | var $mName; |
22 | 22 | |
23 | 23 | /** |
| 24 | + * @var PDO |
| 25 | + */ |
| 26 | + protected $mConn; |
| 27 | + |
| 28 | + /** |
24 | 29 | * Constructor. |
25 | 30 | * Parameters $server, $user and $password are not used. |
26 | 31 | */ |
— | — | @@ -35,14 +40,21 @@ |
36 | 41 | } |
37 | 42 | } |
38 | 43 | |
| 44 | + /** |
| 45 | + * @return string |
| 46 | + */ |
39 | 47 | function getType() { |
40 | 48 | return 'sqlite'; |
41 | 49 | } |
42 | 50 | |
43 | 51 | /** |
44 | 52 | * @todo: check if it should be true like parent class |
| 53 | + * |
| 54 | + * @return bool |
45 | 55 | */ |
46 | | - function implicitGroupby() { return false; } |
| 56 | + function implicitGroupby() { |
| 57 | + return false; |
| 58 | + } |
47 | 59 | |
48 | 60 | /** Open an SQLite database and return a resource handle to it |
49 | 61 | * NOTE: only $dbName is used, the other parameters are irrelevant for SQLite databases |
— | — | @@ -61,7 +73,10 @@ |
62 | 74 | |
63 | 75 | /** |
64 | 76 | * 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 |
66 | 81 | */ |
67 | 82 | function openFile( $fileName ) { |
68 | 83 | $this->mDatabaseFile = $fileName; |
— | — | @@ -152,9 +167,12 @@ |
153 | 168 | /** |
154 | 169 | * Attaches external database to our connection, see http://sqlite.org/lang_attach.html |
155 | 170 | * for details. |
| 171 | + * |
156 | 172 | * @param $name String: database name to be used in queries like SELECT foo FROM dbname.table |
157 | 173 | * @param $file String: database file name. If omitted, will be generated using $name and $wgSQLiteDataDir |
158 | 174 | * @param $fname String: calling function name |
| 175 | + * |
| 176 | + * @return ResultWrapper |
159 | 177 | */ |
160 | 178 | function attachDatabase( $name, $file = false, $fname = 'DatabaseSqlite::attachDatabase' ) { |
161 | 179 | global $wgSQLiteDataDir; |
— | — | @@ -168,6 +186,8 @@ |
169 | 187 | /** |
170 | 188 | * @see DatabaseBase::isWriteQuery() |
171 | 189 | * |
| 190 | + * @param $sql string |
| 191 | + * |
172 | 192 | * @return bool |
173 | 193 | */ |
174 | 194 | function isWriteQuery( $sql ) { |
— | — | @@ -176,6 +196,10 @@ |
177 | 197 | |
178 | 198 | /** |
179 | 199 | * 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 |
180 | 204 | */ |
181 | 205 | function doQuery( $sql ) { |
182 | 206 | $res = $this->mConn->query( $sql ); |
— | — | @@ -189,6 +213,9 @@ |
190 | 214 | return $res; |
191 | 215 | } |
192 | 216 | |
| 217 | + /** |
| 218 | + * @param $res ResultWrapper |
| 219 | + */ |
193 | 220 | function freeResult( $res ) { |
194 | 221 | if ( $res instanceof ResultWrapper ) { |
195 | 222 | $res->result = null; |
— | — | @@ -197,6 +224,10 @@ |
198 | 225 | } |
199 | 226 | } |
200 | 227 | |
| 228 | + /** |
| 229 | + * @param $res ResultWrapper |
| 230 | + * @return |
| 231 | + */ |
201 | 232 | function fetchObject( $res ) { |
202 | 233 | if ( $res instanceof ResultWrapper ) { |
203 | 234 | $r =& $res->result; |
— | — | @@ -219,6 +250,10 @@ |
220 | 251 | return false; |
221 | 252 | } |
222 | 253 | |
| 254 | + /** |
| 255 | + * @param $res ResultWrapper |
| 256 | + * @return bool|mixed |
| 257 | + */ |
223 | 258 | function fetchRow( $res ) { |
224 | 259 | if ( $res instanceof ResultWrapper ) { |
225 | 260 | $r =& $res->result; |
— | — | @@ -235,37 +270,60 @@ |
236 | 271 | |
237 | 272 | /** |
238 | 273 | * The PDO::Statement class implements the array interface so count() will work |
| 274 | + * |
| 275 | + * @param $res ResultWrapper |
| 276 | + * |
| 277 | + * @return int |
239 | 278 | */ |
240 | 279 | function numRows( $res ) { |
241 | 280 | $r = $res instanceof ResultWrapper ? $res->result : $res; |
242 | 281 | return count( $r ); |
243 | 282 | } |
244 | 283 | |
| 284 | + /** |
| 285 | + * @param $res ResultWrapper |
| 286 | + * @return int |
| 287 | + */ |
245 | 288 | function numFields( $res ) { |
246 | 289 | $r = $res instanceof ResultWrapper ? $res->result : $res; |
247 | 290 | return is_array( $r ) ? count( $r[0] ) : 0; |
248 | 291 | } |
249 | 292 | |
| 293 | + /** |
| 294 | + * @param $res ResultWrapper |
| 295 | + * @param $n |
| 296 | + * @return bool |
| 297 | + */ |
250 | 298 | function fieldName( $res, $n ) { |
251 | 299 | $r = $res instanceof ResultWrapper ? $res->result : $res; |
252 | 300 | if ( is_array( $r ) ) { |
253 | 301 | $keys = array_keys( $r[0] ); |
254 | 302 | return $keys[$n]; |
255 | 303 | } |
256 | | - return false; |
| 304 | + return false; |
257 | 305 | } |
258 | 306 | |
259 | 307 | /** |
260 | 308 | * Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks |
| 309 | + * |
| 310 | + * @param $name |
| 311 | + * @param bool $quoted |
| 312 | + * @return string |
261 | 313 | */ |
262 | 314 | function tableName( $name, $quoted = true ) { |
263 | 315 | // 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 | + } |
265 | 319 | return str_replace( '"', '', parent::tableName( $name, $quoted ) ); |
266 | 320 | } |
267 | 321 | |
268 | 322 | /** |
269 | 323 | * Index names have DB scope |
| 324 | + * |
| 325 | + * @param $index string |
| 326 | + * |
| 327 | + * @return string |
270 | 328 | */ |
271 | 329 | function indexName( $index ) { |
272 | 330 | return $index; |
— | — | @@ -273,11 +331,17 @@ |
274 | 332 | |
275 | 333 | /** |
276 | 334 | * This must be called after nextSequenceVal |
| 335 | + * |
| 336 | + * @return int |
277 | 337 | */ |
278 | 338 | function insertId() { |
279 | 339 | return $this->mConn->lastInsertId(); |
280 | 340 | } |
281 | 341 | |
| 342 | + /** |
| 343 | + * @param $res ResultWrapper |
| 344 | + * @param $row |
| 345 | + */ |
282 | 346 | function dataSeek( $res, $row ) { |
283 | 347 | if ( $res instanceof ResultWrapper ) { |
284 | 348 | $r =& $res->result; |
— | — | @@ -292,6 +356,9 @@ |
293 | 357 | } |
294 | 358 | } |
295 | 359 | |
| 360 | + /** |
| 361 | + * @return string |
| 362 | + */ |
296 | 363 | function lastError() { |
297 | 364 | if ( !is_object( $this->mConn ) ) { |
298 | 365 | return "Cannot return last error, no db connection"; |
— | — | @@ -300,6 +367,9 @@ |
301 | 368 | return isset( $e[2] ) ? $e[2] : ''; |
302 | 369 | } |
303 | 370 | |
| 371 | + /** |
| 372 | + * @return string |
| 373 | + */ |
304 | 374 | function lastErrno() { |
305 | 375 | if ( !is_object( $this->mConn ) ) { |
306 | 376 | return "Cannot return last error, no db connection"; |
— | — | @@ -309,6 +379,9 @@ |
310 | 380 | } |
311 | 381 | } |
312 | 382 | |
| 383 | + /** |
| 384 | + * @return int |
| 385 | + */ |
313 | 386 | function affectedRows() { |
314 | 387 | return $this->mAffectedRows; |
315 | 388 | } |
— | — | @@ -317,6 +390,8 @@ |
318 | 391 | * Returns information about an index |
319 | 392 | * Returns false if the index does not exist |
320 | 393 | * - if errors are explicitly ignored, returns NULL on failure |
| 394 | + * |
| 395 | + * @return array |
321 | 396 | */ |
322 | 397 | function indexInfo( $table, $index, $fname = 'DatabaseSqlite::indexExists' ) { |
323 | 398 | $sql = 'PRAGMA index_info(' . $this->addQuotes( $this->indexName( $index ) ) . ')'; |
— | — | @@ -334,6 +409,12 @@ |
335 | 410 | return $info; |
336 | 411 | } |
337 | 412 | |
| 413 | + /** |
| 414 | + * @param $table |
| 415 | + * @param $index |
| 416 | + * @param $fname string |
| 417 | + * @return bool|null |
| 418 | + */ |
338 | 419 | function indexUnique( $table, $index, $fname = 'DatabaseSqlite::indexUnique' ) { |
339 | 420 | $row = $this->selectRow( 'sqlite_master', '*', |
340 | 421 | array( |
— | — | @@ -356,6 +437,10 @@ |
357 | 438 | |
358 | 439 | /** |
359 | 440 | * Filter the options used in SELECT statements |
| 441 | + * |
| 442 | + * @param $options array |
| 443 | + * |
| 444 | + * @return array |
360 | 445 | */ |
361 | 446 | function makeSelectOptions( $options ) { |
362 | 447 | foreach ( $options as $k => $v ) { |
— | — | @@ -421,6 +506,13 @@ |
422 | 507 | return $ret; |
423 | 508 | } |
424 | 509 | |
| 510 | + /** |
| 511 | + * @param $table |
| 512 | + * @param $uniqueIndexes |
| 513 | + * @param $rows |
| 514 | + * @param $fname string |
| 515 | + * @return bool|ResultWrapper |
| 516 | + */ |
425 | 517 | function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseSqlite::replace' ) { |
426 | 518 | if ( !count( $rows ) ) return true; |
427 | 519 | |
— | — | @@ -442,28 +534,47 @@ |
443 | 535 | /** |
444 | 536 | * Returns the size of a text field, or -1 for "unlimited" |
445 | 537 | * In SQLite this is SQLITE_MAX_LENGTH, by default 1GB. No way to query it though. |
| 538 | + * |
| 539 | + * @return int |
446 | 540 | */ |
447 | 541 | function textFieldSize( $table, $field ) { |
448 | 542 | return -1; |
449 | 543 | } |
450 | 544 | |
| 545 | + /** |
| 546 | + * @return bool |
| 547 | + */ |
451 | 548 | function unionSupportsOrderAndLimit() { |
452 | 549 | return false; |
453 | 550 | } |
454 | 551 | |
| 552 | + /** |
| 553 | + * @param $sqls |
| 554 | + * @param $all |
| 555 | + * @return string |
| 556 | + */ |
455 | 557 | function unionQueries( $sqls, $all ) { |
456 | 558 | $glue = $all ? ' UNION ALL ' : ' UNION '; |
457 | 559 | return implode( $glue, $sqls ); |
458 | 560 | } |
459 | 561 | |
| 562 | + /** |
| 563 | + * @return bool |
| 564 | + */ |
460 | 565 | function wasDeadlock() { |
461 | 566 | return $this->lastErrno() == 5; // SQLITE_BUSY |
462 | 567 | } |
463 | 568 | |
| 569 | + /** |
| 570 | + * @return bool |
| 571 | + */ |
464 | 572 | function wasErrorReissuable() { |
465 | 573 | return $this->lastErrno() == 17; // SQLITE_SCHEMA; |
466 | 574 | } |
467 | 575 | |
| 576 | + /** |
| 577 | + * @return bool |
| 578 | + */ |
468 | 579 | function wasReadOnlyError() { |
469 | 580 | return $this->lastErrno() == 8; // SQLITE_READONLY; |
470 | 581 | } |
— | — | @@ -509,35 +620,58 @@ |
510 | 621 | } |
511 | 622 | |
512 | 623 | function begin( $fname = '' ) { |
513 | | - if ( $this->mTrxLevel == 1 ) $this->commit(); |
| 624 | + if ( $this->mTrxLevel == 1 ) { |
| 625 | + $this->commit(); |
| 626 | + } |
514 | 627 | $this->mConn->beginTransaction(); |
515 | 628 | $this->mTrxLevel = 1; |
516 | 629 | } |
517 | 630 | |
518 | 631 | function commit( $fname = '' ) { |
519 | | - if ( $this->mTrxLevel == 0 ) return; |
| 632 | + if ( $this->mTrxLevel == 0 ) { |
| 633 | + return; |
| 634 | + } |
520 | 635 | $this->mConn->commit(); |
521 | 636 | $this->mTrxLevel = 0; |
522 | 637 | } |
523 | 638 | |
524 | 639 | function rollback( $fname = '' ) { |
525 | | - if ( $this->mTrxLevel == 0 ) return; |
| 640 | + if ( $this->mTrxLevel == 0 ) { |
| 641 | + return; |
| 642 | + } |
526 | 643 | $this->mConn->rollBack(); |
527 | 644 | $this->mTrxLevel = 0; |
528 | 645 | } |
529 | 646 | |
| 647 | + /** |
| 648 | + * @param $sql |
| 649 | + * @param $num |
| 650 | + * @return string |
| 651 | + */ |
530 | 652 | function limitResultForUpdate( $sql, $num ) { |
531 | 653 | return $this->limitResult( $sql, $num ); |
532 | 654 | } |
533 | 655 | |
| 656 | + /** |
| 657 | + * @param $s string |
| 658 | + * @return string |
| 659 | + */ |
534 | 660 | function strencode( $s ) { |
535 | 661 | return substr( $this->addQuotes( $s ), 1, - 1 ); |
536 | 662 | } |
537 | 663 | |
| 664 | + /** |
| 665 | + * @param $b |
| 666 | + * @return Blob |
| 667 | + */ |
538 | 668 | function encodeBlob( $b ) { |
539 | 669 | return new Blob( $b ); |
540 | 670 | } |
541 | 671 | |
| 672 | + /** |
| 673 | + * @param $b Blob|string |
| 674 | + * @return string |
| 675 | + */ |
542 | 676 | function decodeBlob( $b ) { |
543 | 677 | if ( $b instanceof Blob ) { |
544 | 678 | $b = $b->fetch(); |
— | — | @@ -545,6 +679,10 @@ |
546 | 680 | return $b; |
547 | 681 | } |
548 | 682 | |
| 683 | + /** |
| 684 | + * @param $s Blob|string |
| 685 | + * @return string |
| 686 | + */ |
549 | 687 | function addQuotes( $s ) { |
550 | 688 | if ( $s instanceof Blob ) { |
551 | 689 | return "x'" . bin2hex( $s->fetch() ) . "'"; |
— | — | @@ -553,6 +691,9 @@ |
554 | 692 | } |
555 | 693 | } |
556 | 694 | |
| 695 | + /** |
| 696 | + * @return string |
| 697 | + */ |
557 | 698 | function buildLike() { |
558 | 699 | $params = func_get_args(); |
559 | 700 | if ( count( $params ) > 0 && is_array( $params[0] ) ) { |
— | — | @@ -561,6 +702,9 @@ |
562 | 703 | return parent::buildLike( $params ) . "ESCAPE '\' "; |
563 | 704 | } |
564 | 705 | |
| 706 | + /** |
| 707 | + * @return string |
| 708 | + */ |
565 | 709 | public function getSearchEngine() { |
566 | 710 | return "SearchSqlite"; |
567 | 711 | } |
— | — | @@ -623,12 +767,22 @@ |
624 | 768 | /** |
625 | 769 | * Build a concatenation list to feed into a SQL query |
626 | 770 | * |
| 771 | + * @param $stringList array |
| 772 | + * |
627 | 773 | * @return string |
628 | 774 | */ |
629 | 775 | function buildConcat( $stringList ) { |
630 | 776 | return '(' . implode( ') || (', $stringList ) . ')'; |
631 | 777 | } |
632 | 778 | |
| 779 | + /** |
| 780 | + * @throws MWException |
| 781 | + * @param $oldName |
| 782 | + * @param $newName |
| 783 | + * @param $temporary bool |
| 784 | + * @param $fname string |
| 785 | + * @return bool|ResultWrapper |
| 786 | + */ |
633 | 787 | function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseSqlite::duplicateTableStructure' ) { |
634 | 788 | $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name=" . $this->addQuotes( $oldName ) . " AND type='table'", $fname ); |
635 | 789 | $obj = $this->fetchObject( $res ); |
— | — | @@ -722,6 +876,9 @@ |
723 | 877 | return $this->info->dflt_value; |
724 | 878 | } |
725 | 879 | |
| 880 | + /** |
| 881 | + * @return bool |
| 882 | + */ |
726 | 883 | function isNullable() { |
727 | 884 | return !$this->info->notnull; |
728 | 885 | } |