Index: trunk/phase3/includes/BagOStuff.php |
— | — | @@ -104,6 +104,7 @@ |
105 | 105 | public function add( $key, $value, $exptime = 0 ) { |
106 | 106 | if ( $this->get( $key ) == false ) { |
107 | 107 | $this->set( $key, $value, $exptime ); |
| 108 | + |
108 | 109 | return true; |
109 | 110 | } |
110 | 111 | } |
— | — | @@ -130,6 +131,7 @@ |
131 | 132 | if ( !$this->lock( $key ) ) { |
132 | 133 | return false; |
133 | 134 | } |
| 135 | + |
134 | 136 | $value = intval( $value ); |
135 | 137 | |
136 | 138 | $n = false; |
— | — | @@ -138,6 +140,7 @@ |
139 | 141 | $this->set( $key, $n ); // exptime? |
140 | 142 | } |
141 | 143 | $this->unlock( $key ); |
| 144 | + |
142 | 145 | return $n; |
143 | 146 | } |
144 | 147 | |
— | — | @@ -146,8 +149,9 @@ |
147 | 150 | } |
148 | 151 | |
149 | 152 | public function debug( $text ) { |
150 | | - if ( $this->debugMode ) |
| 153 | + if ( $this->debugMode ) { |
151 | 154 | wfDebug( "BagOStuff debug: $text\n" ); |
| 155 | + } |
152 | 156 | } |
153 | 157 | |
154 | 158 | /** |
— | — | @@ -178,10 +182,13 @@ |
179 | 183 | |
180 | 184 | protected function expire( $key ) { |
181 | 185 | $et = $this->bag[$key][1]; |
| 186 | + |
182 | 187 | if ( ( $et == 0 ) || ( $et > time() ) ) { |
183 | 188 | return false; |
184 | 189 | } |
| 190 | + |
185 | 191 | $this->delete( $key ); |
| 192 | + |
186 | 193 | return true; |
187 | 194 | } |
188 | 195 | |
— | — | @@ -189,9 +196,11 @@ |
190 | 197 | if ( !isset( $this->bag[$key] ) ) { |
191 | 198 | return false; |
192 | 199 | } |
| 200 | + |
193 | 201 | if ( $this->expire( $key ) ) { |
194 | 202 | return false; |
195 | 203 | } |
| 204 | + |
196 | 205 | return $this->bag[$key][0]; |
197 | 206 | } |
198 | 207 | |
— | — | @@ -203,7 +212,9 @@ |
204 | 213 | if ( !isset( $this->bag[$key] ) ) { |
205 | 214 | return false; |
206 | 215 | } |
| 216 | + |
207 | 217 | unset( $this->bag[$key] ); |
| 218 | + |
208 | 219 | return true; |
209 | 220 | } |
210 | 221 | |
— | — | @@ -223,6 +234,7 @@ |
224 | 235 | |
225 | 236 | protected function getDB() { |
226 | 237 | global $wgDBtype; |
| 238 | + |
227 | 239 | if ( !isset( $this->db ) ) { |
228 | 240 | /* We must keep a separate connection to MySQL in order to avoid deadlocks |
229 | 241 | * However, SQLite has an opposite behaviour. |
— | — | @@ -236,6 +248,7 @@ |
237 | 249 | $this->db->clearFlag( DBO_TRX ); |
238 | 250 | } |
239 | 251 | } |
| 252 | + |
240 | 253 | return $this->db; |
241 | 254 | } |
242 | 255 | |
— | — | @@ -245,12 +258,14 @@ |
246 | 259 | $db = $this->getDB(); |
247 | 260 | $row = $db->selectRow( 'objectcache', array( 'value', 'exptime' ), |
248 | 261 | array( 'keyname' => $key ), __METHOD__ ); |
| 262 | + |
249 | 263 | if ( !$row ) { |
250 | 264 | $this->debug( 'get: no matching rows' ); |
251 | 265 | return false; |
252 | 266 | } |
253 | 267 | |
254 | 268 | $this->debug( "get: retrieved data; expiry time is " . $row->exptime ); |
| 269 | + |
255 | 270 | if ( $this->isExpired( $row->exptime ) ) { |
256 | 271 | $this->debug( "get: key has expired, deleting" ); |
257 | 272 | try { |
— | — | @@ -266,20 +281,28 @@ |
267 | 282 | } catch ( DBQueryError $e ) { |
268 | 283 | $this->handleWriteError( $e ); |
269 | 284 | } |
| 285 | + |
270 | 286 | return false; |
271 | 287 | } |
| 288 | + |
272 | 289 | return $this->unserialize( $db->decodeBlob( $row->value ) ); |
273 | 290 | } |
274 | 291 | |
275 | 292 | public function set( $key, $value, $exptime = 0 ) { |
276 | 293 | $db = $this->getDB(); |
277 | 294 | $exptime = intval( $exptime ); |
278 | | - if ( $exptime < 0 ) $exptime = 0; |
| 295 | + |
| 296 | + if ( $exptime < 0 ) { |
| 297 | + $exptime = 0; |
| 298 | + } |
| 299 | + |
279 | 300 | if ( $exptime == 0 ) { |
280 | 301 | $encExpiry = $this->getMaxDateTime(); |
281 | 302 | } else { |
282 | | - if ( $exptime < 3.16e8 ) # ~10 years |
| 303 | + if ( $exptime < 3.16e8 ) { # ~10 years |
283 | 304 | $exptime += time(); |
| 305 | + } |
| 306 | + |
284 | 307 | $encExpiry = $db->timestamp( $exptime ); |
285 | 308 | } |
286 | 309 | try { |
— | — | @@ -294,21 +317,26 @@ |
295 | 318 | $db->commit(); |
296 | 319 | } catch ( DBQueryError $e ) { |
297 | 320 | $this->handleWriteError( $e ); |
| 321 | + |
298 | 322 | return false; |
299 | 323 | } |
| 324 | + |
300 | 325 | return true; |
301 | 326 | } |
302 | 327 | |
303 | 328 | public function delete( $key, $time = 0 ) { |
304 | 329 | $db = $this->getDB(); |
| 330 | + |
305 | 331 | try { |
306 | 332 | $db->begin(); |
307 | 333 | $db->delete( 'objectcache', array( 'keyname' => $key ), __METHOD__ ); |
308 | 334 | $db->commit(); |
309 | 335 | } catch ( DBQueryError $e ) { |
310 | 336 | $this->handleWriteError( $e ); |
| 337 | + |
311 | 338 | return false; |
312 | 339 | } |
| 340 | + |
313 | 341 | return true; |
314 | 342 | } |
315 | 343 | |
— | — | @@ -323,12 +351,14 @@ |
324 | 352 | if ( $row === false ) { |
325 | 353 | // Missing |
326 | 354 | $db->commit(); |
| 355 | + |
327 | 356 | return false; |
328 | 357 | } |
329 | 358 | $db->delete( 'objectcache', array( 'keyname' => $key ), __METHOD__ ); |
330 | 359 | if ( $this->isExpired( $row->exptime ) ) { |
331 | 360 | // Expired, do not reinsert |
332 | 361 | $db->commit(); |
| 362 | + |
333 | 363 | return false; |
334 | 364 | } |
335 | 365 | |
— | — | @@ -343,8 +373,10 @@ |
344 | 374 | $db->commit(); |
345 | 375 | } catch ( DBQueryError $e ) { |
346 | 376 | $this->handleWriteError( $e ); |
| 377 | + |
347 | 378 | return false; |
348 | 379 | } |
| 380 | + |
349 | 381 | return $newValue; |
350 | 382 | } |
351 | 383 | |
— | — | @@ -352,9 +384,11 @@ |
353 | 385 | $db = $this->getDB(); |
354 | 386 | $res = $db->select( 'objectcache', array( 'keyname' ), false, __METHOD__ ); |
355 | 387 | $result = array(); |
| 388 | + |
356 | 389 | foreach ( $res as $row ) { |
357 | 390 | $result[] = $row->keyname; |
358 | 391 | } |
| 392 | + |
359 | 393 | return $result; |
360 | 394 | } |
361 | 395 | |
— | — | @@ -385,6 +419,7 @@ |
386 | 420 | public function expireAll() { |
387 | 421 | $db = $this->getDB(); |
388 | 422 | $now = $db->timestamp(); |
| 423 | + |
389 | 424 | try { |
390 | 425 | $db->begin(); |
391 | 426 | $db->delete( 'objectcache', array( 'exptime < ' . $db->addQuotes( $now ) ), __METHOD__ ); |
— | — | @@ -396,6 +431,7 @@ |
397 | 432 | |
398 | 433 | public function deleteAll() { |
399 | 434 | $db = $this->getDB(); |
| 435 | + |
400 | 436 | try { |
401 | 437 | $db->begin(); |
402 | 438 | $db->delete( 'objectcache', '*', __METHOD__ ); |
— | — | @@ -415,6 +451,7 @@ |
416 | 452 | */ |
417 | 453 | protected function serialize( &$data ) { |
418 | 454 | $serial = serialize( $data ); |
| 455 | + |
419 | 456 | if ( function_exists( 'gzdeflate' ) ) { |
420 | 457 | return gzdeflate( $serial ); |
421 | 458 | } else { |
— | — | @@ -430,11 +467,14 @@ |
431 | 468 | protected function unserialize( $serial ) { |
432 | 469 | if ( function_exists( 'gzinflate' ) ) { |
433 | 470 | $decomp = @gzinflate( $serial ); |
| 471 | + |
434 | 472 | if ( false !== $decomp ) { |
435 | 473 | $serial = $decomp; |
436 | 474 | } |
437 | 475 | } |
| 476 | + |
438 | 477 | $ret = unserialize( $serial ); |
| 478 | + |
439 | 479 | return $ret; |
440 | 480 | } |
441 | 481 | |
— | — | @@ -444,13 +484,16 @@ |
445 | 485 | */ |
446 | 486 | protected function handleWriteError( $exception ) { |
447 | 487 | $db = $this->getDB(); |
| 488 | + |
448 | 489 | if ( !$db->wasReadOnlyError() ) { |
449 | 490 | throw $exception; |
450 | 491 | } |
| 492 | + |
451 | 493 | try { |
452 | 494 | $db->rollback(); |
453 | 495 | } catch ( DBQueryError $e ) { |
454 | 496 | } |
| 497 | + |
455 | 498 | wfDebug( __METHOD__ . ": ignoring query error\n" ); |
456 | 499 | $db->ignoreErrors( false ); |
457 | 500 | } |
— | — | @@ -469,19 +512,23 @@ |
470 | 513 | class APCBagOStuff extends BagOStuff { |
471 | 514 | public function get( $key ) { |
472 | 515 | $val = apc_fetch( $key ); |
| 516 | + |
473 | 517 | if ( is_string( $val ) ) { |
474 | 518 | $val = unserialize( $val ); |
475 | 519 | } |
| 520 | + |
476 | 521 | return $val; |
477 | 522 | } |
478 | 523 | |
479 | 524 | public function set( $key, $value, $exptime = 0 ) { |
480 | 525 | apc_store( $key, serialize( $value ), $exptime ); |
| 526 | + |
481 | 527 | return true; |
482 | 528 | } |
483 | 529 | |
484 | 530 | public function delete( $key, $time = 0 ) { |
485 | 531 | apc_delete( $key ); |
| 532 | + |
486 | 533 | return true; |
487 | 534 | } |
488 | 535 | |
— | — | @@ -489,9 +536,11 @@ |
490 | 537 | $info = apc_cache_info( 'user' ); |
491 | 538 | $list = $info['cache_list']; |
492 | 539 | $keys = array(); |
| 540 | + |
493 | 541 | foreach ( $list as $entry ) { |
494 | 542 | $keys[] = $entry['info']; |
495 | 543 | } |
| 544 | + |
496 | 545 | return $keys; |
497 | 546 | } |
498 | 547 | } |
— | — | @@ -507,29 +556,35 @@ |
508 | 557 | class eAccelBagOStuff extends BagOStuff { |
509 | 558 | public function get( $key ) { |
510 | 559 | $val = eaccelerator_get( $key ); |
| 560 | + |
511 | 561 | if ( is_string( $val ) ) { |
512 | 562 | $val = unserialize( $val ); |
513 | 563 | } |
| 564 | + |
514 | 565 | return $val; |
515 | 566 | } |
516 | 567 | |
517 | 568 | public function set( $key, $value, $exptime = 0 ) { |
518 | 569 | eaccelerator_put( $key, serialize( $value ), $exptime ); |
| 570 | + |
519 | 571 | return true; |
520 | 572 | } |
521 | 573 | |
522 | 574 | public function delete( $key, $time = 0 ) { |
523 | 575 | eaccelerator_rm( $key ); |
| 576 | + |
524 | 577 | return true; |
525 | 578 | } |
526 | 579 | |
527 | 580 | public function lock( $key, $waitTimeout = 0 ) { |
528 | 581 | eaccelerator_lock( $key ); |
| 582 | + |
529 | 583 | return true; |
530 | 584 | } |
531 | 585 | |
532 | 586 | public function unlock( $key ) { |
533 | 587 | eaccelerator_unlock( $key ); |
| 588 | + |
534 | 589 | return true; |
535 | 590 | } |
536 | 591 | } |
— | — | @@ -541,7 +596,6 @@ |
542 | 597 | * @ingroup Cache |
543 | 598 | */ |
544 | 599 | class XCacheBagOStuff extends BagOStuff { |
545 | | - |
546 | 600 | /** |
547 | 601 | * Get a value from the XCache object cache |
548 | 602 | * |
— | — | @@ -550,8 +604,11 @@ |
551 | 605 | */ |
552 | 606 | public function get( $key ) { |
553 | 607 | $val = xcache_get( $key ); |
554 | | - if ( is_string( $val ) ) |
| 608 | + |
| 609 | + if ( is_string( $val ) ) { |
555 | 610 | $val = unserialize( $val ); |
| 611 | + } |
| 612 | + |
556 | 613 | return $val; |
557 | 614 | } |
558 | 615 | |
— | — | @@ -565,6 +622,7 @@ |
566 | 623 | */ |
567 | 624 | public function set( $key, $value, $expire = 0 ) { |
568 | 625 | xcache_set( $key, serialize( $value ), $expire ); |
| 626 | + |
569 | 627 | return true; |
570 | 628 | } |
571 | 629 | |
— | — | @@ -577,6 +635,7 @@ |
578 | 636 | */ |
579 | 637 | public function delete( $key, $time = 0 ) { |
580 | 638 | xcache_unset( $key ); |
| 639 | + |
581 | 640 | return true; |
582 | 641 | } |
583 | 642 | } |
— | — | @@ -594,10 +653,12 @@ |
595 | 654 | |
596 | 655 | public function __construct( $dir = false ) { |
597 | 656 | global $wgDBAhandler; |
| 657 | + |
598 | 658 | if ( $dir === false ) { |
599 | 659 | global $wgTmpDirectory; |
600 | 660 | $dir = $wgTmpDirectory; |
601 | 661 | } |
| 662 | + |
602 | 663 | $this->mFile = "$dir/mw-cache-" . wfWikiID(); |
603 | 664 | $this->mFile .= '.db'; |
604 | 665 | wfDebug( __CLASS__ . ": using cache file {$this->mFile}\n" ); |
— | — | @@ -610,6 +671,7 @@ |
611 | 672 | function encode( $value, $expiry ) { |
612 | 673 | # Convert to absolute time |
613 | 674 | $expiry = $this->convertExpiry( $expiry ); |
| 675 | + |
614 | 676 | return sprintf( '%010u', intval( $expiry ) ) . ' ' . serialize( $value ); |
615 | 677 | } |
616 | 678 | |
— | — | @@ -633,29 +695,36 @@ |
634 | 696 | } else { |
635 | 697 | $handle = $this->getWriter(); |
636 | 698 | } |
| 699 | + |
637 | 700 | if ( !$handle ) { |
638 | 701 | wfDebug( "Unable to open DBA cache file {$this->mFile}\n" ); |
639 | 702 | } |
| 703 | + |
640 | 704 | return $handle; |
641 | 705 | } |
642 | 706 | |
643 | 707 | function getWriter() { |
644 | 708 | $handle = dba_open( $this->mFile, 'cl', $this->mHandler ); |
| 709 | + |
645 | 710 | if ( !$handle ) { |
646 | 711 | wfDebug( "Unable to open DBA cache file {$this->mFile}\n" ); |
647 | 712 | } |
| 713 | + |
648 | 714 | return $handle; |
649 | 715 | } |
650 | 716 | |
651 | 717 | function get( $key ) { |
652 | 718 | wfProfileIn( __METHOD__ ); |
653 | 719 | wfDebug( __METHOD__ . "($key)\n" ); |
| 720 | + |
654 | 721 | $handle = $this->getReader(); |
655 | 722 | if ( !$handle ) { |
656 | 723 | return null; |
657 | 724 | } |
| 725 | + |
658 | 726 | $val = dba_fetch( $key, $handle ); |
659 | 727 | list( $val, $expiry ) = $this->decode( $val ); |
| 728 | + |
660 | 729 | # Must close ASAP because locks are held |
661 | 730 | dba_close( $handle ); |
662 | 731 | |
— | — | @@ -667,6 +736,7 @@ |
668 | 737 | wfDebug( __METHOD__ . ": $key expired\n" ); |
669 | 738 | $val = null; |
670 | 739 | } |
| 740 | + |
671 | 741 | wfProfileOut( __METHOD__ ); |
672 | 742 | return $val; |
673 | 743 | } |
— | — | @@ -674,13 +744,17 @@ |
675 | 745 | function set( $key, $value, $exptime = 0 ) { |
676 | 746 | wfProfileIn( __METHOD__ ); |
677 | 747 | wfDebug( __METHOD__ . "($key)\n" ); |
| 748 | + |
678 | 749 | $blob = $this->encode( $value, $exptime ); |
| 750 | + |
679 | 751 | $handle = $this->getWriter(); |
680 | 752 | if ( !$handle ) { |
681 | 753 | return false; |
682 | 754 | } |
| 755 | + |
683 | 756 | $ret = dba_replace( $key, $blob, $handle ); |
684 | 757 | dba_close( $handle ); |
| 758 | + |
685 | 759 | wfProfileOut( __METHOD__ ); |
686 | 760 | return $ret; |
687 | 761 | } |
— | — | @@ -688,27 +762,36 @@ |
689 | 763 | function delete( $key, $time = 0 ) { |
690 | 764 | wfProfileIn( __METHOD__ ); |
691 | 765 | wfDebug( __METHOD__ . "($key)\n" ); |
| 766 | + |
692 | 767 | $handle = $this->getWriter(); |
693 | 768 | if ( !$handle ) { |
694 | 769 | return false; |
695 | 770 | } |
| 771 | + |
696 | 772 | $ret = dba_delete( $key, $handle ); |
697 | 773 | dba_close( $handle ); |
| 774 | + |
698 | 775 | wfProfileOut( __METHOD__ ); |
699 | 776 | return $ret; |
700 | 777 | } |
701 | 778 | |
702 | 779 | function add( $key, $value, $exptime = 0 ) { |
703 | 780 | wfProfileIn( __METHOD__ ); |
| 781 | + |
704 | 782 | $blob = $this->encode( $value, $exptime ); |
| 783 | + |
705 | 784 | $handle = $this->getWriter(); |
| 785 | + |
706 | 786 | if ( !$handle ) { |
707 | 787 | return false; |
708 | 788 | } |
| 789 | + |
709 | 790 | $ret = dba_insert( $key, $blob, $handle ); |
| 791 | + |
710 | 792 | # Insert failed, check to see if it failed due to an expired key |
711 | 793 | if ( !$ret ) { |
712 | 794 | list( $value, $expiry ) = $this->decode( dba_fetch( $key, $handle ) ); |
| 795 | + |
713 | 796 | if ( $expiry < time() ) { |
714 | 797 | # Yes expired, delete and try again |
715 | 798 | dba_delete( $key, $handle ); |
— | — | @@ -718,6 +801,7 @@ |
719 | 802 | } |
720 | 803 | |
721 | 804 | dba_close( $handle ); |
| 805 | + |
722 | 806 | wfProfileOut( __METHOD__ ); |
723 | 807 | return $ret; |
724 | 808 | } |
— | — | @@ -725,13 +809,17 @@ |
726 | 810 | function keys() { |
727 | 811 | $reader = $this->getReader(); |
728 | 812 | $k1 = dba_firstkey( $reader ); |
| 813 | + |
729 | 814 | if ( !$k1 ) { |
730 | 815 | return array(); |
731 | 816 | } |
| 817 | + |
732 | 818 | $result[] = $k1; |
| 819 | + |
733 | 820 | while ( $key = dba_nextkey( $reader ) ) { |
734 | 821 | $result[] = $key; |
735 | 822 | } |
| 823 | + |
736 | 824 | return $result; |
737 | 825 | } |
738 | 826 | } |
— | — | @@ -752,8 +840,11 @@ |
753 | 841 | */ |
754 | 842 | public function get( $key ) { |
755 | 843 | $val = wincache_ucache_get( $key ); |
756 | | - if ( is_string( $val ) ) |
| 844 | + |
| 845 | + if ( is_string( $val ) ) { |
757 | 846 | $val = unserialize( $val ); |
| 847 | + } |
| 848 | + |
758 | 849 | return $val; |
759 | 850 | } |
760 | 851 | |
— | — | @@ -767,6 +858,7 @@ |
768 | 859 | */ |
769 | 860 | public function set( $key, $value, $expire = 0 ) { |
770 | 861 | wincache_ucache_set( $key, serialize( $value ), $expire ); |
| 862 | + |
771 | 863 | return true; |
772 | 864 | } |
773 | 865 | |
— | — | @@ -779,6 +871,7 @@ |
780 | 872 | */ |
781 | 873 | public function delete( $key, $time = 0 ) { |
782 | 874 | wincache_ucache_delete( $key ); |
| 875 | + |
783 | 876 | return true; |
784 | 877 | } |
785 | 878 | |
— | — | @@ -786,9 +879,11 @@ |
787 | 880 | $info = wincache_ucache_info(); |
788 | 881 | $list = $info['ucache_entries']; |
789 | 882 | $keys = array(); |
| 883 | + |
790 | 884 | foreach ( $list as $entry ) { |
791 | 885 | $keys[] = $entry['key_name']; |
792 | 886 | } |
| 887 | + |
793 | 888 | return $keys; |
794 | 889 | } |
795 | 890 | } |
Index: trunk/phase3/includes/CacheDependency.php |
— | — | @@ -5,6 +5,7 @@ |
6 | 6 | * than instantiating one of these objects directly. |
7 | 7 | * @ingroup Cache |
8 | 8 | */ |
| 9 | + |
9 | 10 | class DependencyWrapper { |
10 | 11 | var $value; |
11 | 12 | var $deps; |
— | — | @@ -17,9 +18,11 @@ |
18 | 19 | */ |
19 | 20 | function __construct( $value = false, $deps = array() ) { |
20 | 21 | $this->value = $value; |
| 22 | + |
21 | 23 | if ( !is_array( $deps ) ) { |
22 | 24 | $deps = array( $deps ); |
23 | 25 | } |
| 26 | + |
24 | 27 | $this->deps = $deps; |
25 | 28 | } |
26 | 29 | |
— | — | @@ -32,6 +35,7 @@ |
33 | 36 | return true; |
34 | 37 | } |
35 | 38 | } |
| 39 | + |
36 | 40 | return false; |
37 | 41 | } |
38 | 42 | |
— | — | @@ -81,6 +85,7 @@ |
82 | 86 | $callbackParams = array(), $deps = array() ) |
83 | 87 | { |
84 | 88 | $obj = $cache->get( $key ); |
| 89 | + |
85 | 90 | if ( is_object( $obj ) && $obj instanceof DependencyWrapper && !$obj->isExpired() ) { |
86 | 91 | $value = $obj->value; |
87 | 92 | } elseif ( $callback ) { |
— | — | @@ -91,6 +96,7 @@ |
92 | 97 | } else { |
93 | 98 | $value = null; |
94 | 99 | } |
| 100 | + |
95 | 101 | return $value; |
96 | 102 | } |
97 | 103 | } |
— | — | @@ -207,6 +213,7 @@ |
208 | 214 | if ( !isset( $this->titleObj ) ) { |
209 | 215 | $this->titleObj = Title::makeTitle( $this->ns, $this->dbk ); |
210 | 216 | } |
| 217 | + |
211 | 218 | return $this->titleObj; |
212 | 219 | } |
213 | 220 | |
— | — | @@ -255,6 +262,7 @@ |
256 | 263 | foreach ( $this->getLinkBatch()->data as $ns => $dbks ) { |
257 | 264 | if ( count( $dbks ) > 0 ) { |
258 | 265 | $timestamps[$ns] = array(); |
| 266 | + |
259 | 267 | foreach ( $dbks as $dbk => $value ) { |
260 | 268 | $timestamps[$ns][$dbk] = false; |
261 | 269 | } |
— | — | @@ -276,6 +284,7 @@ |
277 | 285 | $timestamps[$row->page_namespace][$row->page_title] = $row->page_touched; |
278 | 286 | } |
279 | 287 | } |
| 288 | + |
280 | 289 | return $timestamps; |
281 | 290 | } |
282 | 291 | |
— | — | @@ -297,6 +306,7 @@ |
298 | 307 | |
299 | 308 | function isExpired() { |
300 | 309 | $newTimestamps = $this->calculateTimestamps(); |
| 310 | + |
301 | 311 | foreach ( $this->timestamps as $ns => $dbks ) { |
302 | 312 | foreach ( $dbks as $dbk => $oldTimestamp ) { |
303 | 313 | $newTimestamp = $newTimestamps[$ns][$dbk]; |
— | — | @@ -319,6 +329,7 @@ |
320 | 330 | } |
321 | 331 | } |
322 | 332 | } |
| 333 | + |
323 | 334 | return false; |
324 | 335 | } |
325 | 336 | } |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -5,6 +5,7 @@ |
6 | 6 | # Extension classes are specified with $wgAutoloadClasses |
7 | 7 | # This array is a global instead of a static member of AutoLoader to work around a bug in APC |
8 | 8 | global $wgAutoloadLocalClasses; |
| 9 | + |
9 | 10 | $wgAutoloadLocalClasses = array( |
10 | 11 | # Includes |
11 | 12 | 'AjaxDispatcher' => 'includes/AjaxDispatcher.php', |
— | — | @@ -328,7 +329,7 @@ |
329 | 330 | 'ApiQueryLogEvents' => 'includes/api/ApiQueryLogEvents.php', |
330 | 331 | 'ApiQueryProtectedTitles' => 'includes/api/ApiQueryProtectedTitles.php', |
331 | 332 | 'ApiQueryRandom' => 'includes/api/ApiQueryRandom.php', |
332 | | - 'ApiQueryRecentChanges'=> 'includes/api/ApiQueryRecentChanges.php', |
| 333 | + 'ApiQueryRecentChanges' => 'includes/api/ApiQueryRecentChanges.php', |
333 | 334 | 'ApiQueryRevisions' => 'includes/api/ApiQueryRevisions.php', |
334 | 335 | 'ApiQuerySearch' => 'includes/api/ApiQuerySearch.php', |
335 | 336 | 'ApiQuerySiteinfo' => 'includes/api/ApiQuerySiteinfo.php', |
— | — | @@ -652,14 +653,17 @@ |
653 | 654 | # The case can sometimes be wrong when unserializing PHP 4 objects |
654 | 655 | $filename = false; |
655 | 656 | $lowerClass = strtolower( $className ); |
| 657 | + |
656 | 658 | foreach ( $wgAutoloadLocalClasses as $class2 => $file2 ) { |
657 | 659 | if ( strtolower( $class2 ) == $lowerClass ) { |
658 | 660 | $filename = $file2; |
659 | 661 | } |
660 | 662 | } |
| 663 | + |
661 | 664 | if ( !$filename ) { |
662 | | - if( function_exists( 'wfDebug' ) ) |
| 665 | + if ( function_exists( 'wfDebug' ) ) |
663 | 666 | wfDebug( "Class {$className} not found; skipped loading\n" ); |
| 667 | + |
664 | 668 | # Give up |
665 | 669 | return false; |
666 | 670 | } |
— | — | @@ -670,15 +674,17 @@ |
671 | 675 | global $IP; |
672 | 676 | $filename = "$IP/$filename"; |
673 | 677 | } |
| 678 | + |
674 | 679 | require( $filename ); |
| 680 | + |
675 | 681 | return true; |
676 | 682 | } |
677 | 683 | |
678 | 684 | static function loadAllExtensions() { |
679 | 685 | global $wgAutoloadClasses; |
680 | 686 | |
681 | | - foreach( $wgAutoloadClasses as $class => $file ) { |
682 | | - if( !( class_exists( $class, false ) || interface_exists( $class, false ) ) ) { |
| 687 | + foreach ( $wgAutoloadClasses as $class => $file ) { |
| 688 | + if ( !( class_exists( $class, false ) || interface_exists( $class, false ) ) ) { |
683 | 689 | require( $file ); |
684 | 690 | } |
685 | 691 | } |
Index: trunk/phase3/includes/BacklinkCache.php |
— | — | @@ -41,6 +41,7 @@ |
42 | 42 | if ( !isset( $this->db ) ) { |
43 | 43 | $this->db = wfGetDB( DB_SLAVE ); |
44 | 44 | } |
| 45 | + |
45 | 46 | return $this->db; |
46 | 47 | } |
47 | 48 | |
— | — | @@ -60,14 +61,17 @@ |
61 | 62 | // Partial range, not cached |
62 | 63 | wfDebug( __METHOD__ . ": from DB (uncacheable range)\n" ); |
63 | 64 | $conds = $this->getConditions( $table ); |
| 65 | + |
64 | 66 | // Use the from field in the condition rather than the joined page_id, |
65 | 67 | // because databases are stupid and don't necessarily propagate indexes. |
66 | 68 | if ( $startId ) { |
67 | 69 | $conds[] = "$fromField >= " . intval( $startId ); |
68 | 70 | } |
| 71 | + |
69 | 72 | if ( $endId ) { |
70 | 73 | $conds[] = "$fromField <= " . intval( $endId ); |
71 | 74 | } |
| 75 | + |
72 | 76 | $res = $this->getDB()->select( |
73 | 77 | array( $table, 'page' ), |
74 | 78 | array( 'page_namespace', 'page_title', 'page_id' ), |
— | — | @@ -78,6 +82,7 @@ |
79 | 83 | 'ORDER BY' => $fromField |
80 | 84 | ) ); |
81 | 85 | $ta = TitleArray::newFromResult( $res ); |
| 86 | + |
82 | 87 | wfProfileOut( __METHOD__ ); |
83 | 88 | return $ta; |
84 | 89 | } |
— | — | @@ -95,7 +100,9 @@ |
96 | 101 | ) ); |
97 | 102 | $this->fullResultCache[$table] = $res; |
98 | 103 | } |
| 104 | + |
99 | 105 | $ta = TitleArray::newFromResult( $this->fullResultCache[$table] ); |
| 106 | + |
100 | 107 | wfProfileOut( __METHOD__ ); |
101 | 108 | return $ta; |
102 | 109 | } |
— | — | @@ -150,6 +157,7 @@ |
151 | 158 | default: |
152 | 159 | throw new MWException( "Invalid table \"$table\" in " . __CLASS__ ); |
153 | 160 | } |
| 161 | + |
154 | 162 | return $conds; |
155 | 163 | } |
156 | 164 | |
— | — | @@ -167,6 +175,7 @@ |
168 | 176 | } |
169 | 177 | |
170 | 178 | $titleArray = $this->getLinks( $table ); |
| 179 | + |
171 | 180 | return $titleArray->count(); |
172 | 181 | } |
173 | 182 | |
— | — | @@ -193,29 +202,35 @@ |
194 | 203 | if ( isset( $this->fullResultCache[$table] ) ) { |
195 | 204 | $cacheEntry = $this->partitionResult( $this->fullResultCache[$table], $batchSize ); |
196 | 205 | wfDebug( __METHOD__ . ": got from full result cache\n" ); |
| 206 | + |
197 | 207 | return $cacheEntry['batches']; |
198 | 208 | } |
199 | 209 | |
200 | 210 | // Try memcached |
201 | 211 | global $wgMemc; |
| 212 | + |
202 | 213 | $memcKey = wfMemcKey( |
203 | 214 | 'backlinks', |
204 | 215 | md5( $this->title->getPrefixedDBkey() ), |
205 | 216 | $table, |
206 | 217 | $batchSize |
207 | 218 | ); |
| 219 | + |
208 | 220 | $memcValue = $wgMemc->get( $memcKey ); |
209 | 221 | |
210 | 222 | if ( is_array( $memcValue ) ) { |
211 | 223 | $cacheEntry = $memcValue; |
212 | 224 | wfDebug( __METHOD__ . ": got from memcached $memcKey\n" ); |
| 225 | + |
213 | 226 | return $cacheEntry['batches']; |
214 | 227 | } |
| 228 | + |
215 | 229 | // Fetch from database |
216 | 230 | $this->getLinks( $table ); |
217 | 231 | $cacheEntry = $this->partitionResult( $this->fullResultCache[$table], $batchSize ); |
218 | 232 | // Save to memcached |
219 | 233 | $wgMemc->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY ); |
| 234 | + |
220 | 235 | wfDebug( __METHOD__ . ": got from database\n" ); |
221 | 236 | return $cacheEntry['batches']; |
222 | 237 | } |
— | — | @@ -254,6 +269,7 @@ |
255 | 270 | |
256 | 271 | $batches[] = array( $start, $end ); |
257 | 272 | } |
| 273 | + |
258 | 274 | return array( 'numRows' => $numRows, 'batches' => $batches ); |
259 | 275 | } |
260 | 276 | } |
Index: trunk/phase3/includes/AuthPlugin.php |
— | — | @@ -1,6 +1,4 @@ |
2 | 2 | <?php |
3 | | -/** |
4 | | - */ |
5 | 3 | # Copyright (C) 2004 Brion Vibber <brion@pobox.com> |
6 | 4 | # http://www.mediawiki.org/ |
7 | 5 | # |
— | — | @@ -105,7 +103,6 @@ |
106 | 104 | return true; |
107 | 105 | } |
108 | 106 | |
109 | | - |
110 | 107 | /** |
111 | 108 | * Return true if the wiki should create a new local account automatically |
112 | 109 | * when asked to login a user who doesn't exist locally but does in the |
— | — | @@ -131,11 +128,11 @@ |
132 | 129 | * @return Boolean |
133 | 130 | */ |
134 | 131 | public function allowPropChange( $prop = '' ) { |
135 | | - if( $prop == 'realname' && is_callable( array( $this, 'allowRealNameChange' ) ) ) { |
| 132 | + if ( $prop == 'realname' && is_callable( array( $this, 'allowRealNameChange' ) ) ) { |
136 | 133 | return $this->allowRealNameChange(); |
137 | | - } elseif( $prop == 'emailaddress' && is_callable( array( $this, 'allowEmailChange' ) ) ) { |
| 134 | + } elseif ( $prop == 'emailaddress' && is_callable( array( $this, 'allowEmailChange' ) ) ) { |
138 | 135 | return $this->allowEmailChange(); |
139 | | - } elseif( $prop == 'nickname' && is_callable( array( $this, 'allowNickChange' ) ) ) { |
| 136 | + } elseif ( $prop == 'nickname' && is_callable( array( $this, 'allowNickChange' ) ) ) { |
140 | 137 | return $this->allowNickChange(); |
141 | 138 | } else { |
142 | 139 | return true; |
— | — | @@ -197,11 +194,10 @@ |
198 | 195 | * @param $realname String |
199 | 196 | * @return Boolean |
200 | 197 | */ |
201 | | - public function addUser( $user, $password, $email='', $realname='' ) { |
| 198 | + public function addUser( $user, $password, $email = '', $realname = '' ) { |
202 | 199 | return true; |
203 | 200 | } |
204 | 201 | |
205 | | - |
206 | 202 | /** |
207 | 203 | * Return true to prevent logins that don't authenticate here from being |
208 | 204 | * checked against the local database's password fields. |
— | — | @@ -236,7 +232,7 @@ |
237 | 233 | * @param $user User object. |
238 | 234 | * @param $autocreate Boolean: True if user is being autocreated on login |
239 | 235 | */ |
240 | | - public function initUser( &$user, $autocreate=false ) { |
| 236 | + public function initUser( &$user, $autocreate = false ) { |
241 | 237 | # Override this to do something. |
242 | 238 | } |
243 | 239 | |
— | — | @@ -247,7 +243,7 @@ |
248 | 244 | public function getCanonicalName( $username ) { |
249 | 245 | return $username; |
250 | 246 | } |
251 | | - |
| 247 | + |
252 | 248 | /** |
253 | 249 | * Get an instance of a User object |
254 | 250 | * |
— | — | @@ -262,22 +258,22 @@ |
263 | 259 | function __construct( $user ) { |
264 | 260 | # Override this! |
265 | 261 | } |
266 | | - |
| 262 | + |
267 | 263 | public function getId() { |
268 | 264 | # Override this! |
269 | 265 | return -1; |
270 | 266 | } |
271 | | - |
| 267 | + |
272 | 268 | public function isLocked() { |
273 | 269 | # Override this! |
274 | 270 | return false; |
275 | 271 | } |
276 | | - |
| 272 | + |
277 | 273 | public function isHidden() { |
278 | 274 | # Override this! |
279 | 275 | return false; |
280 | 276 | } |
281 | | - |
| 277 | + |
282 | 278 | public function resetAuthToken() { |
283 | 279 | # Override this! |
284 | 280 | return true; |
Index: trunk/phase3/includes/Autopromote.php |
— | — | @@ -3,6 +3,7 @@ |
4 | 4 | * This class checks if user can get extra rights |
5 | 5 | * because of conditions specified in $wgAutopromote |
6 | 6 | */ |
| 7 | + |
7 | 8 | class Autopromote { |
8 | 9 | /** |
9 | 10 | * Get the groups for the given user based on $wgAutopromote. |
— | — | @@ -12,9 +13,11 @@ |
13 | 14 | */ |
14 | 15 | public static function getAutopromoteGroups( User $user ) { |
15 | 16 | global $wgAutopromote; |
| 17 | + |
16 | 18 | $promote = array(); |
17 | | - foreach( $wgAutopromote as $group => $cond ) { |
18 | | - if( self::recCheckCondition( $cond, $user ) ) |
| 19 | + |
| 20 | + foreach ( $wgAutopromote as $group => $cond ) { |
| 21 | + if ( self::recCheckCondition( $cond, $user ) ) |
19 | 22 | $promote[] = $group; |
20 | 23 | } |
21 | 24 | |
— | — | @@ -41,38 +44,52 @@ |
42 | 45 | */ |
43 | 46 | private static function recCheckCondition( $cond, User $user ) { |
44 | 47 | $validOps = array( '&', '|', '^', '!' ); |
45 | | - if( is_array( $cond ) && count( $cond ) >= 2 && in_array( $cond[0], $validOps ) ) { |
| 48 | + |
| 49 | + if ( is_array( $cond ) && count( $cond ) >= 2 && in_array( $cond[0], $validOps ) ) { |
46 | 50 | # Recursive condition |
47 | | - if( $cond[0] == '&' ) { |
48 | | - foreach( array_slice( $cond, 1 ) as $subcond ) |
49 | | - if( !self::recCheckCondition( $subcond, $user ) ) |
| 51 | + if ( $cond[0] == '&' ) { |
| 52 | + foreach ( array_slice( $cond, 1 ) as $subcond ) { |
| 53 | + if ( !self::recCheckCondition( $subcond, $user ) ) { |
50 | 54 | return false; |
| 55 | + } |
| 56 | + } |
| 57 | + |
51 | 58 | return true; |
52 | | - } elseif( $cond[0] == '|' ) { |
53 | | - foreach( array_slice( $cond, 1 ) as $subcond ) |
54 | | - if( self::recCheckCondition( $subcond, $user ) ) |
| 59 | + } elseif ( $cond[0] == '|' ) { |
| 60 | + foreach ( array_slice( $cond, 1 ) as $subcond ) { |
| 61 | + if ( self::recCheckCondition( $subcond, $user ) ) { |
55 | 62 | return true; |
| 63 | + } |
| 64 | + } |
| 65 | + |
56 | 66 | return false; |
57 | | - } elseif( $cond[0] == '^' ) { |
| 67 | + } elseif ( $cond[0] == '^' ) { |
58 | 68 | $res = null; |
59 | | - foreach( array_slice( $cond, 1 ) as $subcond ) { |
60 | | - if( is_null( $res ) ) |
| 69 | + foreach ( array_slice( $cond, 1 ) as $subcond ) { |
| 70 | + if ( is_null( $res ) ) { |
61 | 71 | $res = self::recCheckCondition( $subcond, $user ); |
62 | | - else |
63 | | - $res = ($res xor self::recCheckCondition( $subcond, $user )); |
| 72 | + } else { |
| 73 | + $res = ( $res xor self::recCheckCondition( $subcond, $user ) ); |
| 74 | + } |
64 | 75 | } |
| 76 | + |
65 | 77 | return $res; |
66 | 78 | } elseif ( $cond[0] = '!' ) { |
67 | | - foreach( array_slice( $cond, 1 ) as $subcond ) |
68 | | - if( self::recCheckCondition( $subcond, $user ) ) |
| 79 | + foreach ( array_slice( $cond, 1 ) as $subcond ) { |
| 80 | + if ( self::recCheckCondition( $subcond, $user ) ) { |
69 | 81 | return false; |
| 82 | + } |
| 83 | + } |
| 84 | + |
70 | 85 | return true; |
71 | 86 | } |
72 | 87 | } |
73 | 88 | # If we got here, the array presumably does not contain other condi- |
74 | 89 | # tions; it's not recursive. Pass it off to self::checkCondition. |
75 | | - if( !is_array( $cond ) ) |
| 90 | + if ( !is_array( $cond ) ) { |
76 | 91 | $cond = array( $cond ); |
| 92 | + } |
| 93 | + |
77 | 94 | return self::checkCondition( $cond, $user ); |
78 | 95 | } |
79 | 96 | |
— | — | @@ -87,13 +104,15 @@ |
88 | 105 | * @return bool Whether the condition is true for the user |
89 | 106 | */ |
90 | 107 | private static function checkCondition( $cond, User $user ) { |
91 | | - if( count( $cond ) < 1 ) |
| 108 | + if ( count( $cond ) < 1 ) { |
92 | 109 | return false; |
| 110 | + } |
| 111 | + |
93 | 112 | switch( $cond[0] ) { |
94 | 113 | case APCOND_EMAILCONFIRMED: |
95 | | - if( User::isValidEmailAddr( $user->getEmail() ) ) { |
| 114 | + if ( User::isValidEmailAddr( $user->getEmail() ) ) { |
96 | 115 | global $wgEmailAuthentication; |
97 | | - if( $wgEmailAuthentication ) { |
| 116 | + if ( $wgEmailAuthentication ) { |
98 | 117 | return (bool)$user->getEmailAuthenticationTimestamp(); |
99 | 118 | } else { |
100 | 119 | return true; |
— | — | @@ -120,9 +139,10 @@ |
121 | 140 | default: |
122 | 141 | $result = null; |
123 | 142 | wfRunHooks( 'AutopromoteCondition', array( $cond[0], array_slice( $cond, 1 ), $user, &$result ) ); |
124 | | - if( $result === null ) { |
| 143 | + if ( $result === null ) { |
125 | 144 | throw new MWException( "Unrecognized condition {$cond[0]} for autopromotion!" ); |
126 | 145 | } |
| 146 | + |
127 | 147 | return $result ? true : false; |
128 | 148 | } |
129 | 149 | } |
Index: trunk/phase3/includes/Block.php |
— | — | @@ -63,6 +63,7 @@ |
64 | 64 | public static function newFromDB( $address, $user = 0, $killExpired = true ) { |
65 | 65 | $block = new Block; |
66 | 66 | $block->load( $address, $user, $killExpired ); |
| 67 | + |
67 | 68 | if ( $block->isValid() ) { |
68 | 69 | return $block; |
69 | 70 | } else { |
— | — | @@ -81,6 +82,7 @@ |
82 | 83 | $res = $dbr->resultObject( $dbr->select( 'ipblocks', '*', |
83 | 84 | array( 'ipb_id' => $id ), __METHOD__ ) ); |
84 | 85 | $block = new Block; |
| 86 | + |
85 | 87 | if ( $block->loadFromResult( $res ) ) { |
86 | 88 | return $block; |
87 | 89 | } else { |
— | — | @@ -142,6 +144,7 @@ |
143 | 145 | $db = wfGetDB( DB_SLAVE ); |
144 | 146 | $options = array(); |
145 | 147 | } |
| 148 | + |
146 | 149 | return $db; |
147 | 150 | } |
148 | 151 | |
— | — | @@ -163,6 +166,7 @@ |
164 | 167 | if ( 0 == $user && $address === '' ) { |
165 | 168 | # Invalid user specification, not blocked |
166 | 169 | $this->clear(); |
| 170 | + |
167 | 171 | return false; |
168 | 172 | } |
169 | 173 | |
— | — | @@ -170,6 +174,7 @@ |
171 | 175 | if ( $user ) { |
172 | 176 | $res = $db->resultObject( $db->select( 'ipblocks', '*', array( 'ipb_user' => $user ), |
173 | 177 | __METHOD__, $options ) ); |
| 178 | + |
174 | 179 | if ( $this->loadFromResult( $res, $killExpired ) ) { |
175 | 180 | return true; |
176 | 181 | } |
— | — | @@ -190,6 +195,7 @@ |
191 | 196 | if ( !$this->mCreateAccount ) { |
192 | 197 | $this->clear(); |
193 | 198 | } |
| 199 | + |
194 | 200 | return false; |
195 | 201 | } else { |
196 | 202 | return true; |
— | — | @@ -204,6 +210,7 @@ |
205 | 211 | if ( !$this->mCreateAccount ) { |
206 | 212 | $this->clear(); |
207 | 213 | } |
| 214 | + |
208 | 215 | return false; |
209 | 216 | } else { |
210 | 217 | return true; |
— | — | @@ -266,6 +273,7 @@ |
267 | 274 | } |
268 | 275 | } |
269 | 276 | $res->free(); |
| 277 | + |
270 | 278 | return $ret; |
271 | 279 | } |
272 | 280 | |
— | — | @@ -304,6 +312,7 @@ |
305 | 313 | |
306 | 314 | $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) ); |
307 | 315 | $success = $this->loadFromResult( $res, $killExpired ); |
| 316 | + |
308 | 317 | return $success; |
309 | 318 | } |
310 | 319 | |
— | — | @@ -368,6 +377,7 @@ |
369 | 378 | |
370 | 379 | $dbw = wfGetDB( DB_MASTER ); |
371 | 380 | $dbw->delete( 'ipblocks', array( 'ipb_id' => $this->mId ), __METHOD__ ); |
| 381 | + |
372 | 382 | return $dbw->affectedRows() > 0; |
373 | 383 | } |
374 | 384 | |
— | — | @@ -379,6 +389,7 @@ |
380 | 390 | */ |
381 | 391 | public function insert( $dbw = null ) { |
382 | 392 | wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" ); |
| 393 | + |
383 | 394 | if ( $dbw === null ) |
384 | 395 | $dbw = wfGetDB( DB_MASTER ); |
385 | 396 | |
— | — | @@ -476,6 +487,7 @@ |
477 | 488 | if ( !$this->mUser && $this->mAnonOnly ) { |
478 | 489 | $this->mBlockEmail = 0; |
479 | 490 | } |
| 491 | + |
480 | 492 | if ( !$this->mByName ) { |
481 | 493 | if ( $this->mBy ) { |
482 | 494 | $this->mByName = User::whoIs( $this->mBy ); |
— | — | @@ -520,8 +532,9 @@ |
521 | 533 | wfDebug( "No IP found to retroactively autoblock\n" ); |
522 | 534 | } else { |
523 | 535 | while ( $row = $dbr->fetchObject( $res ) ) { |
524 | | - if ( $row->rc_ip ) |
| 536 | + if ( $row->rc_ip ) { |
525 | 537 | $this->doAutoblock( $row->rc_ip ); |
| 538 | + } |
526 | 539 | } |
527 | 540 | } |
528 | 541 | } |
— | — | @@ -602,13 +615,16 @@ |
603 | 616 | # exceed the user block. If it would exceed, then do nothing, else |
604 | 617 | # prolong block time |
605 | 618 | if ( $this->mExpiry && |
606 | | - ( $this->mExpiry < Block::getAutoblockExpiry( $ipblock->mTimestamp ) ) ) { |
| 619 | + ( $this->mExpiry < Block::getAutoblockExpiry( $ipblock->mTimestamp ) ) |
| 620 | + ) { |
607 | 621 | return; |
608 | 622 | } |
| 623 | + |
609 | 624 | # Just update the timestamp |
610 | 625 | if ( !$justInserted ) { |
611 | 626 | $ipblock->updateTimestamp(); |
612 | 627 | } |
| 628 | + |
613 | 629 | return; |
614 | 630 | } else { |
615 | 631 | $ipblock = new Block; |
— | — | @@ -627,6 +643,7 @@ |
628 | 644 | # Continue suppressing the name if needed |
629 | 645 | $ipblock->mHideName = $this->mHideName; |
630 | 646 | $ipblock->mAllowUsertalk = $this->mAllowUsertalk; |
| 647 | + |
631 | 648 | # If the user is already blocked with an expiry date, we don't |
632 | 649 | # want to pile on top of that! |
633 | 650 | if ( $this->mExpiry ) { |
— | — | @@ -634,6 +651,7 @@ |
635 | 652 | } else { |
636 | 653 | $ipblock->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp ); |
637 | 654 | } |
| 655 | + |
638 | 656 | # Insert it |
639 | 657 | return $ipblock->insert(); |
640 | 658 | } |
— | — | @@ -644,6 +662,7 @@ |
645 | 663 | */ |
646 | 664 | public function deleteIfExpired() { |
647 | 665 | wfProfileIn( __METHOD__ ); |
| 666 | + |
648 | 667 | if ( $this->isExpired() ) { |
649 | 668 | wfDebug( "Block::deleteIfExpired() -- deleting\n" ); |
650 | 669 | $this->delete(); |
— | — | @@ -652,6 +671,7 @@ |
653 | 672 | wfDebug( "Block::deleteIfExpired() -- not expired\n" ); |
654 | 673 | $retVal = false; |
655 | 674 | } |
| 675 | + |
656 | 676 | wfProfileOut( __METHOD__ ); |
657 | 677 | return $retVal; |
658 | 678 | } |
— | — | @@ -662,6 +682,7 @@ |
663 | 683 | */ |
664 | 684 | public function isExpired() { |
665 | 685 | wfDebug( "Block::isExpired() checking current " . wfTimestampNow() . " vs $this->mExpiry\n" ); |
| 686 | + |
666 | 687 | if ( !$this->mExpiry ) { |
667 | 688 | return false; |
668 | 689 | } else { |
— | — | @@ -778,6 +799,7 @@ |
779 | 800 | */ |
780 | 801 | public static function getAutoblockExpiry( $timestamp ) { |
781 | 802 | global $wgAutoblockExpiry; |
| 803 | + |
782 | 804 | return wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $timestamp ) + $wgAutoblockExpiry ); |
783 | 805 | } |
784 | 806 | |
— | — | @@ -813,6 +835,7 @@ |
814 | 836 | $range = "$newip/{$parts[1]}"; |
815 | 837 | } |
816 | 838 | } |
| 839 | + |
817 | 840 | return $range; |
818 | 841 | } |
819 | 842 | |
— | — | @@ -849,6 +872,7 @@ |
850 | 873 | if ( is_null( $msg ) ) { |
851 | 874 | $msg = array(); |
852 | 875 | $keys = array( 'infiniteblock', 'expiringblock' ); |
| 876 | + |
853 | 877 | foreach ( $keys as $key ) { |
854 | 878 | $msg[$key] = wfMsgHtml( $key ); |
855 | 879 | } |
— | — | @@ -863,6 +887,7 @@ |
864 | 888 | $expiretimestr = htmlspecialchars( $wgLang->time( $expiry, true ) ); |
865 | 889 | $expirystr = wfMsgReplaceArgs( $msg['expiringblock'], array( $expiredatestr, $expiretimestr ) ); |
866 | 890 | } |
| 891 | + |
867 | 892 | return $expirystr; |
868 | 893 | } |
869 | 894 | |
— | — | @@ -881,7 +906,7 @@ |
882 | 907 | return false; |
883 | 908 | } |
884 | 909 | } |
| 910 | + |
885 | 911 | return $expiry; |
886 | 912 | } |
887 | | - |
888 | 913 | } |