r67073 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67072‎ | r67073 | r67074 >
Date:14:48, 30 May 2010
Author:siebrand
Status:ok
Tags:
Comment:
Ran stylize.php, removed trailing whitespace, updated indentation and code formatting.
Modified paths:
  • /trunk/phase3/includes/AuthPlugin.php (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/Autopromote.php (modified) (history)
  • /trunk/phase3/includes/BacklinkCache.php (modified) (history)
  • /trunk/phase3/includes/BagOStuff.php (modified) (history)
  • /trunk/phase3/includes/Block.php (modified) (history)
  • /trunk/phase3/includes/CacheDependency.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/BagOStuff.php
@@ -104,6 +104,7 @@
105105 public function add( $key, $value, $exptime = 0 ) {
106106 if ( $this->get( $key ) == false ) {
107107 $this->set( $key, $value, $exptime );
 108+
108109 return true;
109110 }
110111 }
@@ -130,6 +131,7 @@
131132 if ( !$this->lock( $key ) ) {
132133 return false;
133134 }
 135+
134136 $value = intval( $value );
135137
136138 $n = false;
@@ -138,6 +140,7 @@
139141 $this->set( $key, $n ); // exptime?
140142 }
141143 $this->unlock( $key );
 144+
142145 return $n;
143146 }
144147
@@ -146,8 +149,9 @@
147150 }
148151
149152 public function debug( $text ) {
150 - if ( $this->debugMode )
 153+ if ( $this->debugMode ) {
151154 wfDebug( "BagOStuff debug: $text\n" );
 155+ }
152156 }
153157
154158 /**
@@ -178,10 +182,13 @@
179183
180184 protected function expire( $key ) {
181185 $et = $this->bag[$key][1];
 186+
182187 if ( ( $et == 0 ) || ( $et > time() ) ) {
183188 return false;
184189 }
 190+
185191 $this->delete( $key );
 192+
186193 return true;
187194 }
188195
@@ -189,9 +196,11 @@
190197 if ( !isset( $this->bag[$key] ) ) {
191198 return false;
192199 }
 200+
193201 if ( $this->expire( $key ) ) {
194202 return false;
195203 }
 204+
196205 return $this->bag[$key][0];
197206 }
198207
@@ -203,7 +212,9 @@
204213 if ( !isset( $this->bag[$key] ) ) {
205214 return false;
206215 }
 216+
207217 unset( $this->bag[$key] );
 218+
208219 return true;
209220 }
210221
@@ -223,6 +234,7 @@
224235
225236 protected function getDB() {
226237 global $wgDBtype;
 238+
227239 if ( !isset( $this->db ) ) {
228240 /* We must keep a separate connection to MySQL in order to avoid deadlocks
229241 * However, SQLite has an opposite behaviour.
@@ -236,6 +248,7 @@
237249 $this->db->clearFlag( DBO_TRX );
238250 }
239251 }
 252+
240253 return $this->db;
241254 }
242255
@@ -245,12 +258,14 @@
246259 $db = $this->getDB();
247260 $row = $db->selectRow( 'objectcache', array( 'value', 'exptime' ),
248261 array( 'keyname' => $key ), __METHOD__ );
 262+
249263 if ( !$row ) {
250264 $this->debug( 'get: no matching rows' );
251265 return false;
252266 }
253267
254268 $this->debug( "get: retrieved data; expiry time is " . $row->exptime );
 269+
255270 if ( $this->isExpired( $row->exptime ) ) {
256271 $this->debug( "get: key has expired, deleting" );
257272 try {
@@ -266,20 +281,28 @@
267282 } catch ( DBQueryError $e ) {
268283 $this->handleWriteError( $e );
269284 }
 285+
270286 return false;
271287 }
 288+
272289 return $this->unserialize( $db->decodeBlob( $row->value ) );
273290 }
274291
275292 public function set( $key, $value, $exptime = 0 ) {
276293 $db = $this->getDB();
277294 $exptime = intval( $exptime );
278 - if ( $exptime < 0 ) $exptime = 0;
 295+
 296+ if ( $exptime < 0 ) {
 297+ $exptime = 0;
 298+ }
 299+
279300 if ( $exptime == 0 ) {
280301 $encExpiry = $this->getMaxDateTime();
281302 } else {
282 - if ( $exptime < 3.16e8 ) # ~10 years
 303+ if ( $exptime < 3.16e8 ) { # ~10 years
283304 $exptime += time();
 305+ }
 306+
284307 $encExpiry = $db->timestamp( $exptime );
285308 }
286309 try {
@@ -294,21 +317,26 @@
295318 $db->commit();
296319 } catch ( DBQueryError $e ) {
297320 $this->handleWriteError( $e );
 321+
298322 return false;
299323 }
 324+
300325 return true;
301326 }
302327
303328 public function delete( $key, $time = 0 ) {
304329 $db = $this->getDB();
 330+
305331 try {
306332 $db->begin();
307333 $db->delete( 'objectcache', array( 'keyname' => $key ), __METHOD__ );
308334 $db->commit();
309335 } catch ( DBQueryError $e ) {
310336 $this->handleWriteError( $e );
 337+
311338 return false;
312339 }
 340+
313341 return true;
314342 }
315343
@@ -323,12 +351,14 @@
324352 if ( $row === false ) {
325353 // Missing
326354 $db->commit();
 355+
327356 return false;
328357 }
329358 $db->delete( 'objectcache', array( 'keyname' => $key ), __METHOD__ );
330359 if ( $this->isExpired( $row->exptime ) ) {
331360 // Expired, do not reinsert
332361 $db->commit();
 362+
333363 return false;
334364 }
335365
@@ -343,8 +373,10 @@
344374 $db->commit();
345375 } catch ( DBQueryError $e ) {
346376 $this->handleWriteError( $e );
 377+
347378 return false;
348379 }
 380+
349381 return $newValue;
350382 }
351383
@@ -352,9 +384,11 @@
353385 $db = $this->getDB();
354386 $res = $db->select( 'objectcache', array( 'keyname' ), false, __METHOD__ );
355387 $result = array();
 388+
356389 foreach ( $res as $row ) {
357390 $result[] = $row->keyname;
358391 }
 392+
359393 return $result;
360394 }
361395
@@ -385,6 +419,7 @@
386420 public function expireAll() {
387421 $db = $this->getDB();
388422 $now = $db->timestamp();
 423+
389424 try {
390425 $db->begin();
391426 $db->delete( 'objectcache', array( 'exptime < ' . $db->addQuotes( $now ) ), __METHOD__ );
@@ -396,6 +431,7 @@
397432
398433 public function deleteAll() {
399434 $db = $this->getDB();
 435+
400436 try {
401437 $db->begin();
402438 $db->delete( 'objectcache', '*', __METHOD__ );
@@ -415,6 +451,7 @@
416452 */
417453 protected function serialize( &$data ) {
418454 $serial = serialize( $data );
 455+
419456 if ( function_exists( 'gzdeflate' ) ) {
420457 return gzdeflate( $serial );
421458 } else {
@@ -430,11 +467,14 @@
431468 protected function unserialize( $serial ) {
432469 if ( function_exists( 'gzinflate' ) ) {
433470 $decomp = @gzinflate( $serial );
 471+
434472 if ( false !== $decomp ) {
435473 $serial = $decomp;
436474 }
437475 }
 476+
438477 $ret = unserialize( $serial );
 478+
439479 return $ret;
440480 }
441481
@@ -444,13 +484,16 @@
445485 */
446486 protected function handleWriteError( $exception ) {
447487 $db = $this->getDB();
 488+
448489 if ( !$db->wasReadOnlyError() ) {
449490 throw $exception;
450491 }
 492+
451493 try {
452494 $db->rollback();
453495 } catch ( DBQueryError $e ) {
454496 }
 497+
455498 wfDebug( __METHOD__ . ": ignoring query error\n" );
456499 $db->ignoreErrors( false );
457500 }
@@ -469,19 +512,23 @@
470513 class APCBagOStuff extends BagOStuff {
471514 public function get( $key ) {
472515 $val = apc_fetch( $key );
 516+
473517 if ( is_string( $val ) ) {
474518 $val = unserialize( $val );
475519 }
 520+
476521 return $val;
477522 }
478523
479524 public function set( $key, $value, $exptime = 0 ) {
480525 apc_store( $key, serialize( $value ), $exptime );
 526+
481527 return true;
482528 }
483529
484530 public function delete( $key, $time = 0 ) {
485531 apc_delete( $key );
 532+
486533 return true;
487534 }
488535
@@ -489,9 +536,11 @@
490537 $info = apc_cache_info( 'user' );
491538 $list = $info['cache_list'];
492539 $keys = array();
 540+
493541 foreach ( $list as $entry ) {
494542 $keys[] = $entry['info'];
495543 }
 544+
496545 return $keys;
497546 }
498547 }
@@ -507,29 +556,35 @@
508557 class eAccelBagOStuff extends BagOStuff {
509558 public function get( $key ) {
510559 $val = eaccelerator_get( $key );
 560+
511561 if ( is_string( $val ) ) {
512562 $val = unserialize( $val );
513563 }
 564+
514565 return $val;
515566 }
516567
517568 public function set( $key, $value, $exptime = 0 ) {
518569 eaccelerator_put( $key, serialize( $value ), $exptime );
 570+
519571 return true;
520572 }
521573
522574 public function delete( $key, $time = 0 ) {
523575 eaccelerator_rm( $key );
 576+
524577 return true;
525578 }
526579
527580 public function lock( $key, $waitTimeout = 0 ) {
528581 eaccelerator_lock( $key );
 582+
529583 return true;
530584 }
531585
532586 public function unlock( $key ) {
533587 eaccelerator_unlock( $key );
 588+
534589 return true;
535590 }
536591 }
@@ -541,7 +596,6 @@
542597 * @ingroup Cache
543598 */
544599 class XCacheBagOStuff extends BagOStuff {
545 -
546600 /**
547601 * Get a value from the XCache object cache
548602 *
@@ -550,8 +604,11 @@
551605 */
552606 public function get( $key ) {
553607 $val = xcache_get( $key );
554 - if ( is_string( $val ) )
 608+
 609+ if ( is_string( $val ) ) {
555610 $val = unserialize( $val );
 611+ }
 612+
556613 return $val;
557614 }
558615
@@ -565,6 +622,7 @@
566623 */
567624 public function set( $key, $value, $expire = 0 ) {
568625 xcache_set( $key, serialize( $value ), $expire );
 626+
569627 return true;
570628 }
571629
@@ -577,6 +635,7 @@
578636 */
579637 public function delete( $key, $time = 0 ) {
580638 xcache_unset( $key );
 639+
581640 return true;
582641 }
583642 }
@@ -594,10 +653,12 @@
595654
596655 public function __construct( $dir = false ) {
597656 global $wgDBAhandler;
 657+
598658 if ( $dir === false ) {
599659 global $wgTmpDirectory;
600660 $dir = $wgTmpDirectory;
601661 }
 662+
602663 $this->mFile = "$dir/mw-cache-" . wfWikiID();
603664 $this->mFile .= '.db';
604665 wfDebug( __CLASS__ . ": using cache file {$this->mFile}\n" );
@@ -610,6 +671,7 @@
611672 function encode( $value, $expiry ) {
612673 # Convert to absolute time
613674 $expiry = $this->convertExpiry( $expiry );
 675+
614676 return sprintf( '%010u', intval( $expiry ) ) . ' ' . serialize( $value );
615677 }
616678
@@ -633,29 +695,36 @@
634696 } else {
635697 $handle = $this->getWriter();
636698 }
 699+
637700 if ( !$handle ) {
638701 wfDebug( "Unable to open DBA cache file {$this->mFile}\n" );
639702 }
 703+
640704 return $handle;
641705 }
642706
643707 function getWriter() {
644708 $handle = dba_open( $this->mFile, 'cl', $this->mHandler );
 709+
645710 if ( !$handle ) {
646711 wfDebug( "Unable to open DBA cache file {$this->mFile}\n" );
647712 }
 713+
648714 return $handle;
649715 }
650716
651717 function get( $key ) {
652718 wfProfileIn( __METHOD__ );
653719 wfDebug( __METHOD__ . "($key)\n" );
 720+
654721 $handle = $this->getReader();
655722 if ( !$handle ) {
656723 return null;
657724 }
 725+
658726 $val = dba_fetch( $key, $handle );
659727 list( $val, $expiry ) = $this->decode( $val );
 728+
660729 # Must close ASAP because locks are held
661730 dba_close( $handle );
662731
@@ -667,6 +736,7 @@
668737 wfDebug( __METHOD__ . ": $key expired\n" );
669738 $val = null;
670739 }
 740+
671741 wfProfileOut( __METHOD__ );
672742 return $val;
673743 }
@@ -674,13 +744,17 @@
675745 function set( $key, $value, $exptime = 0 ) {
676746 wfProfileIn( __METHOD__ );
677747 wfDebug( __METHOD__ . "($key)\n" );
 748+
678749 $blob = $this->encode( $value, $exptime );
 750+
679751 $handle = $this->getWriter();
680752 if ( !$handle ) {
681753 return false;
682754 }
 755+
683756 $ret = dba_replace( $key, $blob, $handle );
684757 dba_close( $handle );
 758+
685759 wfProfileOut( __METHOD__ );
686760 return $ret;
687761 }
@@ -688,27 +762,36 @@
689763 function delete( $key, $time = 0 ) {
690764 wfProfileIn( __METHOD__ );
691765 wfDebug( __METHOD__ . "($key)\n" );
 766+
692767 $handle = $this->getWriter();
693768 if ( !$handle ) {
694769 return false;
695770 }
 771+
696772 $ret = dba_delete( $key, $handle );
697773 dba_close( $handle );
 774+
698775 wfProfileOut( __METHOD__ );
699776 return $ret;
700777 }
701778
702779 function add( $key, $value, $exptime = 0 ) {
703780 wfProfileIn( __METHOD__ );
 781+
704782 $blob = $this->encode( $value, $exptime );
 783+
705784 $handle = $this->getWriter();
 785+
706786 if ( !$handle ) {
707787 return false;
708788 }
 789+
709790 $ret = dba_insert( $key, $blob, $handle );
 791+
710792 # Insert failed, check to see if it failed due to an expired key
711793 if ( !$ret ) {
712794 list( $value, $expiry ) = $this->decode( dba_fetch( $key, $handle ) );
 795+
713796 if ( $expiry < time() ) {
714797 # Yes expired, delete and try again
715798 dba_delete( $key, $handle );
@@ -718,6 +801,7 @@
719802 }
720803
721804 dba_close( $handle );
 805+
722806 wfProfileOut( __METHOD__ );
723807 return $ret;
724808 }
@@ -725,13 +809,17 @@
726810 function keys() {
727811 $reader = $this->getReader();
728812 $k1 = dba_firstkey( $reader );
 813+
729814 if ( !$k1 ) {
730815 return array();
731816 }
 817+
732818 $result[] = $k1;
 819+
733820 while ( $key = dba_nextkey( $reader ) ) {
734821 $result[] = $key;
735822 }
 823+
736824 return $result;
737825 }
738826 }
@@ -752,8 +840,11 @@
753841 */
754842 public function get( $key ) {
755843 $val = wincache_ucache_get( $key );
756 - if ( is_string( $val ) )
 844+
 845+ if ( is_string( $val ) ) {
757846 $val = unserialize( $val );
 847+ }
 848+
758849 return $val;
759850 }
760851
@@ -767,6 +858,7 @@
768859 */
769860 public function set( $key, $value, $expire = 0 ) {
770861 wincache_ucache_set( $key, serialize( $value ), $expire );
 862+
771863 return true;
772864 }
773865
@@ -779,6 +871,7 @@
780872 */
781873 public function delete( $key, $time = 0 ) {
782874 wincache_ucache_delete( $key );
 875+
783876 return true;
784877 }
785878
@@ -786,9 +879,11 @@
787880 $info = wincache_ucache_info();
788881 $list = $info['ucache_entries'];
789882 $keys = array();
 883+
790884 foreach ( $list as $entry ) {
791885 $keys[] = $entry['key_name'];
792886 }
 887+
793888 return $keys;
794889 }
795890 }
Index: trunk/phase3/includes/CacheDependency.php
@@ -5,6 +5,7 @@
66 * than instantiating one of these objects directly.
77 * @ingroup Cache
88 */
 9+
910 class DependencyWrapper {
1011 var $value;
1112 var $deps;
@@ -17,9 +18,11 @@
1819 */
1920 function __construct( $value = false, $deps = array() ) {
2021 $this->value = $value;
 22+
2123 if ( !is_array( $deps ) ) {
2224 $deps = array( $deps );
2325 }
 26+
2427 $this->deps = $deps;
2528 }
2629
@@ -32,6 +35,7 @@
3336 return true;
3437 }
3538 }
 39+
3640 return false;
3741 }
3842
@@ -81,6 +85,7 @@
8286 $callbackParams = array(), $deps = array() )
8387 {
8488 $obj = $cache->get( $key );
 89+
8590 if ( is_object( $obj ) && $obj instanceof DependencyWrapper && !$obj->isExpired() ) {
8691 $value = $obj->value;
8792 } elseif ( $callback ) {
@@ -91,6 +96,7 @@
9297 } else {
9398 $value = null;
9499 }
 100+
95101 return $value;
96102 }
97103 }
@@ -207,6 +213,7 @@
208214 if ( !isset( $this->titleObj ) ) {
209215 $this->titleObj = Title::makeTitle( $this->ns, $this->dbk );
210216 }
 217+
211218 return $this->titleObj;
212219 }
213220
@@ -255,6 +262,7 @@
256263 foreach ( $this->getLinkBatch()->data as $ns => $dbks ) {
257264 if ( count( $dbks ) > 0 ) {
258265 $timestamps[$ns] = array();
 266+
259267 foreach ( $dbks as $dbk => $value ) {
260268 $timestamps[$ns][$dbk] = false;
261269 }
@@ -276,6 +284,7 @@
277285 $timestamps[$row->page_namespace][$row->page_title] = $row->page_touched;
278286 }
279287 }
 288+
280289 return $timestamps;
281290 }
282291
@@ -297,6 +306,7 @@
298307
299308 function isExpired() {
300309 $newTimestamps = $this->calculateTimestamps();
 310+
301311 foreach ( $this->timestamps as $ns => $dbks ) {
302312 foreach ( $dbks as $dbk => $oldTimestamp ) {
303313 $newTimestamp = $newTimestamps[$ns][$dbk];
@@ -319,6 +329,7 @@
320330 }
321331 }
322332 }
 333+
323334 return false;
324335 }
325336 }
Index: trunk/phase3/includes/AutoLoader.php
@@ -5,6 +5,7 @@
66 # Extension classes are specified with $wgAutoloadClasses
77 # This array is a global instead of a static member of AutoLoader to work around a bug in APC
88 global $wgAutoloadLocalClasses;
 9+
910 $wgAutoloadLocalClasses = array(
1011 # Includes
1112 'AjaxDispatcher' => 'includes/AjaxDispatcher.php',
@@ -328,7 +329,7 @@
329330 'ApiQueryLogEvents' => 'includes/api/ApiQueryLogEvents.php',
330331 'ApiQueryProtectedTitles' => 'includes/api/ApiQueryProtectedTitles.php',
331332 'ApiQueryRandom' => 'includes/api/ApiQueryRandom.php',
332 - 'ApiQueryRecentChanges'=> 'includes/api/ApiQueryRecentChanges.php',
 333+ 'ApiQueryRecentChanges' => 'includes/api/ApiQueryRecentChanges.php',
333334 'ApiQueryRevisions' => 'includes/api/ApiQueryRevisions.php',
334335 'ApiQuerySearch' => 'includes/api/ApiQuerySearch.php',
335336 'ApiQuerySiteinfo' => 'includes/api/ApiQuerySiteinfo.php',
@@ -652,14 +653,17 @@
653654 # The case can sometimes be wrong when unserializing PHP 4 objects
654655 $filename = false;
655656 $lowerClass = strtolower( $className );
 657+
656658 foreach ( $wgAutoloadLocalClasses as $class2 => $file2 ) {
657659 if ( strtolower( $class2 ) == $lowerClass ) {
658660 $filename = $file2;
659661 }
660662 }
 663+
661664 if ( !$filename ) {
662 - if( function_exists( 'wfDebug' ) )
 665+ if ( function_exists( 'wfDebug' ) )
663666 wfDebug( "Class {$className} not found; skipped loading\n" );
 667+
664668 # Give up
665669 return false;
666670 }
@@ -670,15 +674,17 @@
671675 global $IP;
672676 $filename = "$IP/$filename";
673677 }
 678+
674679 require( $filename );
 680+
675681 return true;
676682 }
677683
678684 static function loadAllExtensions() {
679685 global $wgAutoloadClasses;
680686
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 ) ) ) {
683689 require( $file );
684690 }
685691 }
Index: trunk/phase3/includes/BacklinkCache.php
@@ -41,6 +41,7 @@
4242 if ( !isset( $this->db ) ) {
4343 $this->db = wfGetDB( DB_SLAVE );
4444 }
 45+
4546 return $this->db;
4647 }
4748
@@ -60,14 +61,17 @@
6162 // Partial range, not cached
6263 wfDebug( __METHOD__ . ": from DB (uncacheable range)\n" );
6364 $conds = $this->getConditions( $table );
 65+
6466 // Use the from field in the condition rather than the joined page_id,
6567 // because databases are stupid and don't necessarily propagate indexes.
6668 if ( $startId ) {
6769 $conds[] = "$fromField >= " . intval( $startId );
6870 }
 71+
6972 if ( $endId ) {
7073 $conds[] = "$fromField <= " . intval( $endId );
7174 }
 75+
7276 $res = $this->getDB()->select(
7377 array( $table, 'page' ),
7478 array( 'page_namespace', 'page_title', 'page_id' ),
@@ -78,6 +82,7 @@
7983 'ORDER BY' => $fromField
8084 ) );
8185 $ta = TitleArray::newFromResult( $res );
 86+
8287 wfProfileOut( __METHOD__ );
8388 return $ta;
8489 }
@@ -95,7 +100,9 @@
96101 ) );
97102 $this->fullResultCache[$table] = $res;
98103 }
 104+
99105 $ta = TitleArray::newFromResult( $this->fullResultCache[$table] );
 106+
100107 wfProfileOut( __METHOD__ );
101108 return $ta;
102109 }
@@ -150,6 +157,7 @@
151158 default:
152159 throw new MWException( "Invalid table \"$table\" in " . __CLASS__ );
153160 }
 161+
154162 return $conds;
155163 }
156164
@@ -167,6 +175,7 @@
168176 }
169177
170178 $titleArray = $this->getLinks( $table );
 179+
171180 return $titleArray->count();
172181 }
173182
@@ -193,29 +202,35 @@
194203 if ( isset( $this->fullResultCache[$table] ) ) {
195204 $cacheEntry = $this->partitionResult( $this->fullResultCache[$table], $batchSize );
196205 wfDebug( __METHOD__ . ": got from full result cache\n" );
 206+
197207 return $cacheEntry['batches'];
198208 }
199209
200210 // Try memcached
201211 global $wgMemc;
 212+
202213 $memcKey = wfMemcKey(
203214 'backlinks',
204215 md5( $this->title->getPrefixedDBkey() ),
205216 $table,
206217 $batchSize
207218 );
 219+
208220 $memcValue = $wgMemc->get( $memcKey );
209221
210222 if ( is_array( $memcValue ) ) {
211223 $cacheEntry = $memcValue;
212224 wfDebug( __METHOD__ . ": got from memcached $memcKey\n" );
 225+
213226 return $cacheEntry['batches'];
214227 }
 228+
215229 // Fetch from database
216230 $this->getLinks( $table );
217231 $cacheEntry = $this->partitionResult( $this->fullResultCache[$table], $batchSize );
218232 // Save to memcached
219233 $wgMemc->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY );
 234+
220235 wfDebug( __METHOD__ . ": got from database\n" );
221236 return $cacheEntry['batches'];
222237 }
@@ -254,6 +269,7 @@
255270
256271 $batches[] = array( $start, $end );
257272 }
 273+
258274 return array( 'numRows' => $numRows, 'batches' => $batches );
259275 }
260276 }
Index: trunk/phase3/includes/AuthPlugin.php
@@ -1,6 +1,4 @@
22 <?php
3 -/**
4 - */
53 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
64 # http://www.mediawiki.org/
75 #
@@ -105,7 +103,6 @@
106104 return true;
107105 }
108106
109 -
110107 /**
111108 * Return true if the wiki should create a new local account automatically
112109 * when asked to login a user who doesn't exist locally but does in the
@@ -131,11 +128,11 @@
132129 * @return Boolean
133130 */
134131 public function allowPropChange( $prop = '' ) {
135 - if( $prop == 'realname' && is_callable( array( $this, 'allowRealNameChange' ) ) ) {
 132+ if ( $prop == 'realname' && is_callable( array( $this, 'allowRealNameChange' ) ) ) {
136133 return $this->allowRealNameChange();
137 - } elseif( $prop == 'emailaddress' && is_callable( array( $this, 'allowEmailChange' ) ) ) {
 134+ } elseif ( $prop == 'emailaddress' && is_callable( array( $this, 'allowEmailChange' ) ) ) {
138135 return $this->allowEmailChange();
139 - } elseif( $prop == 'nickname' && is_callable( array( $this, 'allowNickChange' ) ) ) {
 136+ } elseif ( $prop == 'nickname' && is_callable( array( $this, 'allowNickChange' ) ) ) {
140137 return $this->allowNickChange();
141138 } else {
142139 return true;
@@ -197,11 +194,10 @@
198195 * @param $realname String
199196 * @return Boolean
200197 */
201 - public function addUser( $user, $password, $email='', $realname='' ) {
 198+ public function addUser( $user, $password, $email = '', $realname = '' ) {
202199 return true;
203200 }
204201
205 -
206202 /**
207203 * Return true to prevent logins that don't authenticate here from being
208204 * checked against the local database's password fields.
@@ -236,7 +232,7 @@
237233 * @param $user User object.
238234 * @param $autocreate Boolean: True if user is being autocreated on login
239235 */
240 - public function initUser( &$user, $autocreate=false ) {
 236+ public function initUser( &$user, $autocreate = false ) {
241237 # Override this to do something.
242238 }
243239
@@ -247,7 +243,7 @@
248244 public function getCanonicalName( $username ) {
249245 return $username;
250246 }
251 -
 247+
252248 /**
253249 * Get an instance of a User object
254250 *
@@ -262,22 +258,22 @@
263259 function __construct( $user ) {
264260 # Override this!
265261 }
266 -
 262+
267263 public function getId() {
268264 # Override this!
269265 return -1;
270266 }
271 -
 267+
272268 public function isLocked() {
273269 # Override this!
274270 return false;
275271 }
276 -
 272+
277273 public function isHidden() {
278274 # Override this!
279275 return false;
280276 }
281 -
 277+
282278 public function resetAuthToken() {
283279 # Override this!
284280 return true;
Index: trunk/phase3/includes/Autopromote.php
@@ -3,6 +3,7 @@
44 * This class checks if user can get extra rights
55 * because of conditions specified in $wgAutopromote
66 */
 7+
78 class Autopromote {
89 /**
910 * Get the groups for the given user based on $wgAutopromote.
@@ -12,9 +13,11 @@
1314 */
1415 public static function getAutopromoteGroups( User $user ) {
1516 global $wgAutopromote;
 17+
1618 $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 ) )
1922 $promote[] = $group;
2023 }
2124
@@ -41,38 +44,52 @@
4245 */
4346 private static function recCheckCondition( $cond, User $user ) {
4447 $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 ) ) {
4650 # 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 ) ) {
5054 return false;
 55+ }
 56+ }
 57+
5158 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 ) ) {
5562 return true;
 63+ }
 64+ }
 65+
5666 return false;
57 - } elseif( $cond[0] == '^' ) {
 67+ } elseif ( $cond[0] == '^' ) {
5868 $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 ) ) {
6171 $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+ }
6475 }
 76+
6577 return $res;
6678 } 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 ) ) {
6981 return false;
 82+ }
 83+ }
 84+
7085 return true;
7186 }
7287 }
7388 # If we got here, the array presumably does not contain other condi-
7489 # tions; it's not recursive. Pass it off to self::checkCondition.
75 - if( !is_array( $cond ) )
 90+ if ( !is_array( $cond ) ) {
7691 $cond = array( $cond );
 92+ }
 93+
7794 return self::checkCondition( $cond, $user );
7895 }
7996
@@ -87,13 +104,15 @@
88105 * @return bool Whether the condition is true for the user
89106 */
90107 private static function checkCondition( $cond, User $user ) {
91 - if( count( $cond ) < 1 )
 108+ if ( count( $cond ) < 1 ) {
92109 return false;
 110+ }
 111+
93112 switch( $cond[0] ) {
94113 case APCOND_EMAILCONFIRMED:
95 - if( User::isValidEmailAddr( $user->getEmail() ) ) {
 114+ if ( User::isValidEmailAddr( $user->getEmail() ) ) {
96115 global $wgEmailAuthentication;
97 - if( $wgEmailAuthentication ) {
 116+ if ( $wgEmailAuthentication ) {
98117 return (bool)$user->getEmailAuthenticationTimestamp();
99118 } else {
100119 return true;
@@ -120,9 +139,10 @@
121140 default:
122141 $result = null;
123142 wfRunHooks( 'AutopromoteCondition', array( $cond[0], array_slice( $cond, 1 ), $user, &$result ) );
124 - if( $result === null ) {
 143+ if ( $result === null ) {
125144 throw new MWException( "Unrecognized condition {$cond[0]} for autopromotion!" );
126145 }
 146+
127147 return $result ? true : false;
128148 }
129149 }
Index: trunk/phase3/includes/Block.php
@@ -63,6 +63,7 @@
6464 public static function newFromDB( $address, $user = 0, $killExpired = true ) {
6565 $block = new Block;
6666 $block->load( $address, $user, $killExpired );
 67+
6768 if ( $block->isValid() ) {
6869 return $block;
6970 } else {
@@ -81,6 +82,7 @@
8283 $res = $dbr->resultObject( $dbr->select( 'ipblocks', '*',
8384 array( 'ipb_id' => $id ), __METHOD__ ) );
8485 $block = new Block;
 86+
8587 if ( $block->loadFromResult( $res ) ) {
8688 return $block;
8789 } else {
@@ -142,6 +144,7 @@
143145 $db = wfGetDB( DB_SLAVE );
144146 $options = array();
145147 }
 148+
146149 return $db;
147150 }
148151
@@ -163,6 +166,7 @@
164167 if ( 0 == $user && $address === '' ) {
165168 # Invalid user specification, not blocked
166169 $this->clear();
 170+
167171 return false;
168172 }
169173
@@ -170,6 +174,7 @@
171175 if ( $user ) {
172176 $res = $db->resultObject( $db->select( 'ipblocks', '*', array( 'ipb_user' => $user ),
173177 __METHOD__, $options ) );
 178+
174179 if ( $this->loadFromResult( $res, $killExpired ) ) {
175180 return true;
176181 }
@@ -190,6 +195,7 @@
191196 if ( !$this->mCreateAccount ) {
192197 $this->clear();
193198 }
 199+
194200 return false;
195201 } else {
196202 return true;
@@ -204,6 +210,7 @@
205211 if ( !$this->mCreateAccount ) {
206212 $this->clear();
207213 }
 214+
208215 return false;
209216 } else {
210217 return true;
@@ -266,6 +273,7 @@
267274 }
268275 }
269276 $res->free();
 277+
270278 return $ret;
271279 }
272280
@@ -304,6 +312,7 @@
305313
306314 $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) );
307315 $success = $this->loadFromResult( $res, $killExpired );
 316+
308317 return $success;
309318 }
310319
@@ -368,6 +377,7 @@
369378
370379 $dbw = wfGetDB( DB_MASTER );
371380 $dbw->delete( 'ipblocks', array( 'ipb_id' => $this->mId ), __METHOD__ );
 381+
372382 return $dbw->affectedRows() > 0;
373383 }
374384
@@ -379,6 +389,7 @@
380390 */
381391 public function insert( $dbw = null ) {
382392 wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" );
 393+
383394 if ( $dbw === null )
384395 $dbw = wfGetDB( DB_MASTER );
385396
@@ -476,6 +487,7 @@
477488 if ( !$this->mUser && $this->mAnonOnly ) {
478489 $this->mBlockEmail = 0;
479490 }
 491+
480492 if ( !$this->mByName ) {
481493 if ( $this->mBy ) {
482494 $this->mByName = User::whoIs( $this->mBy );
@@ -520,8 +532,9 @@
521533 wfDebug( "No IP found to retroactively autoblock\n" );
522534 } else {
523535 while ( $row = $dbr->fetchObject( $res ) ) {
524 - if ( $row->rc_ip )
 536+ if ( $row->rc_ip ) {
525537 $this->doAutoblock( $row->rc_ip );
 538+ }
526539 }
527540 }
528541 }
@@ -602,13 +615,16 @@
603616 # exceed the user block. If it would exceed, then do nothing, else
604617 # prolong block time
605618 if ( $this->mExpiry &&
606 - ( $this->mExpiry < Block::getAutoblockExpiry( $ipblock->mTimestamp ) ) ) {
 619+ ( $this->mExpiry < Block::getAutoblockExpiry( $ipblock->mTimestamp ) )
 620+ ) {
607621 return;
608622 }
 623+
609624 # Just update the timestamp
610625 if ( !$justInserted ) {
611626 $ipblock->updateTimestamp();
612627 }
 628+
613629 return;
614630 } else {
615631 $ipblock = new Block;
@@ -627,6 +643,7 @@
628644 # Continue suppressing the name if needed
629645 $ipblock->mHideName = $this->mHideName;
630646 $ipblock->mAllowUsertalk = $this->mAllowUsertalk;
 647+
631648 # If the user is already blocked with an expiry date, we don't
632649 # want to pile on top of that!
633650 if ( $this->mExpiry ) {
@@ -634,6 +651,7 @@
635652 } else {
636653 $ipblock->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp );
637654 }
 655+
638656 # Insert it
639657 return $ipblock->insert();
640658 }
@@ -644,6 +662,7 @@
645663 */
646664 public function deleteIfExpired() {
647665 wfProfileIn( __METHOD__ );
 666+
648667 if ( $this->isExpired() ) {
649668 wfDebug( "Block::deleteIfExpired() -- deleting\n" );
650669 $this->delete();
@@ -652,6 +671,7 @@
653672 wfDebug( "Block::deleteIfExpired() -- not expired\n" );
654673 $retVal = false;
655674 }
 675+
656676 wfProfileOut( __METHOD__ );
657677 return $retVal;
658678 }
@@ -662,6 +682,7 @@
663683 */
664684 public function isExpired() {
665685 wfDebug( "Block::isExpired() checking current " . wfTimestampNow() . " vs $this->mExpiry\n" );
 686+
666687 if ( !$this->mExpiry ) {
667688 return false;
668689 } else {
@@ -778,6 +799,7 @@
779800 */
780801 public static function getAutoblockExpiry( $timestamp ) {
781802 global $wgAutoblockExpiry;
 803+
782804 return wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $timestamp ) + $wgAutoblockExpiry );
783805 }
784806
@@ -813,6 +835,7 @@
814836 $range = "$newip/{$parts[1]}";
815837 }
816838 }
 839+
817840 return $range;
818841 }
819842
@@ -849,6 +872,7 @@
850873 if ( is_null( $msg ) ) {
851874 $msg = array();
852875 $keys = array( 'infiniteblock', 'expiringblock' );
 876+
853877 foreach ( $keys as $key ) {
854878 $msg[$key] = wfMsgHtml( $key );
855879 }
@@ -863,6 +887,7 @@
864888 $expiretimestr = htmlspecialchars( $wgLang->time( $expiry, true ) );
865889 $expirystr = wfMsgReplaceArgs( $msg['expiringblock'], array( $expiredatestr, $expiretimestr ) );
866890 }
 891+
867892 return $expirystr;
868893 }
869894
@@ -881,7 +906,7 @@
882907 return false;
883908 }
884909 }
 910+
885911 return $expiry;
886912 }
887 -
888913 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r75163Follow up r67073 : add curly to if statementhashar18:26, 21 October 2010

Status & tagging log