From d279df340e0b604e4186df5b2d3c4f99b1459050 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Sun, 30 May 2010 14:48:30 +0000 Subject: [PATCH] Ran stylize.php, removed trailing whitespace, updated indentation and code formatting. --- includes/AuthPlugin.php | 24 ++++---- includes/AutoLoader.php | 14 +++-- includes/Autopromote.php | 62 +++++++++++++------- includes/BacklinkCache.php | 16 ++++++ includes/BagOStuff.php | 107 +++++++++++++++++++++++++++++++++-- includes/Block.php | 31 +++++++++- includes/CacheDependency.php | 11 ++++ 7 files changed, 217 insertions(+), 48 deletions(-) diff --git a/includes/AuthPlugin.php b/includes/AuthPlugin.php index 87ac8adb75..0cb25b9489 100644 --- a/includes/AuthPlugin.php +++ b/includes/AuthPlugin.php @@ -1,6 +1,4 @@ # http://www.mediawiki.org/ # @@ -105,7 +103,6 @@ class AuthPlugin { return true; } - /** * Return true if the wiki should create a new local account automatically * when asked to login a user who doesn't exist locally but does in the @@ -131,11 +128,11 @@ class AuthPlugin { * @return Boolean */ public function allowPropChange( $prop = '' ) { - if( $prop == 'realname' && is_callable( array( $this, 'allowRealNameChange' ) ) ) { + if ( $prop == 'realname' && is_callable( array( $this, 'allowRealNameChange' ) ) ) { return $this->allowRealNameChange(); - } elseif( $prop == 'emailaddress' && is_callable( array( $this, 'allowEmailChange' ) ) ) { + } elseif ( $prop == 'emailaddress' && is_callable( array( $this, 'allowEmailChange' ) ) ) { return $this->allowEmailChange(); - } elseif( $prop == 'nickname' && is_callable( array( $this, 'allowNickChange' ) ) ) { + } elseif ( $prop == 'nickname' && is_callable( array( $this, 'allowNickChange' ) ) ) { return $this->allowNickChange(); } else { return true; @@ -197,11 +194,10 @@ class AuthPlugin { * @param $realname String * @return Boolean */ - public function addUser( $user, $password, $email='', $realname='' ) { + public function addUser( $user, $password, $email = '', $realname = '' ) { return true; } - /** * Return true to prevent logins that don't authenticate here from being * checked against the local database's password fields. @@ -236,7 +232,7 @@ class AuthPlugin { * @param $user User object. * @param $autocreate Boolean: True if user is being autocreated on login */ - public function initUser( &$user, $autocreate=false ) { + public function initUser( &$user, $autocreate = false ) { # Override this to do something. } @@ -247,7 +243,7 @@ class AuthPlugin { public function getCanonicalName( $username ) { return $username; } - + /** * Get an instance of a User object * @@ -262,22 +258,22 @@ class AuthPluginUser { function __construct( $user ) { # Override this! } - + public function getId() { # Override this! return -1; } - + public function isLocked() { # Override this! return false; } - + public function isHidden() { # Override this! return false; } - + public function resetAuthToken() { # Override this! return true; diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 81da88e96c..ef49db29c3 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -5,6 +5,7 @@ # Extension classes are specified with $wgAutoloadClasses # This array is a global instead of a static member of AutoLoader to work around a bug in APC global $wgAutoloadLocalClasses; + $wgAutoloadLocalClasses = array( # Includes 'AjaxDispatcher' => 'includes/AjaxDispatcher.php', @@ -328,7 +329,7 @@ $wgAutoloadLocalClasses = array( 'ApiQueryLogEvents' => 'includes/api/ApiQueryLogEvents.php', 'ApiQueryProtectedTitles' => 'includes/api/ApiQueryProtectedTitles.php', 'ApiQueryRandom' => 'includes/api/ApiQueryRandom.php', - 'ApiQueryRecentChanges'=> 'includes/api/ApiQueryRecentChanges.php', + 'ApiQueryRecentChanges' => 'includes/api/ApiQueryRecentChanges.php', 'ApiQueryRevisions' => 'includes/api/ApiQueryRevisions.php', 'ApiQuerySearch' => 'includes/api/ApiQuerySearch.php', 'ApiQuerySiteinfo' => 'includes/api/ApiQuerySiteinfo.php', @@ -652,14 +653,17 @@ class AutoLoader { # The case can sometimes be wrong when unserializing PHP 4 objects $filename = false; $lowerClass = strtolower( $className ); + foreach ( $wgAutoloadLocalClasses as $class2 => $file2 ) { if ( strtolower( $class2 ) == $lowerClass ) { $filename = $file2; } } + if ( !$filename ) { - if( function_exists( 'wfDebug' ) ) + if ( function_exists( 'wfDebug' ) ) wfDebug( "Class {$className} not found; skipped loading\n" ); + # Give up return false; } @@ -670,15 +674,17 @@ class AutoLoader { global $IP; $filename = "$IP/$filename"; } + require( $filename ); + return true; } static function loadAllExtensions() { global $wgAutoloadClasses; - foreach( $wgAutoloadClasses as $class => $file ) { - if( !( class_exists( $class, false ) || interface_exists( $class, false ) ) ) { + foreach ( $wgAutoloadClasses as $class => $file ) { + if ( !( class_exists( $class, false ) || interface_exists( $class, false ) ) ) { require( $file ); } } diff --git a/includes/Autopromote.php b/includes/Autopromote.php index c0adff43a4..2f96998087 100644 --- a/includes/Autopromote.php +++ b/includes/Autopromote.php @@ -3,6 +3,7 @@ * This class checks if user can get extra rights * because of conditions specified in $wgAutopromote */ + class Autopromote { /** * Get the groups for the given user based on $wgAutopromote. @@ -12,9 +13,11 @@ class Autopromote { */ public static function getAutopromoteGroups( User $user ) { global $wgAutopromote; + $promote = array(); - foreach( $wgAutopromote as $group => $cond ) { - if( self::recCheckCondition( $cond, $user ) ) + + foreach ( $wgAutopromote as $group => $cond ) { + if ( self::recCheckCondition( $cond, $user ) ) $promote[] = $group; } @@ -41,38 +44,52 @@ class Autopromote { */ private static function recCheckCondition( $cond, User $user ) { $validOps = array( '&', '|', '^', '!' ); - if( is_array( $cond ) && count( $cond ) >= 2 && in_array( $cond[0], $validOps ) ) { + + if ( is_array( $cond ) && count( $cond ) >= 2 && in_array( $cond[0], $validOps ) ) { # Recursive condition - if( $cond[0] == '&' ) { - foreach( array_slice( $cond, 1 ) as $subcond ) - if( !self::recCheckCondition( $subcond, $user ) ) + if ( $cond[0] == '&' ) { + foreach ( array_slice( $cond, 1 ) as $subcond ) { + if ( !self::recCheckCondition( $subcond, $user ) ) { return false; + } + } + return true; - } elseif( $cond[0] == '|' ) { - foreach( array_slice( $cond, 1 ) as $subcond ) - if( self::recCheckCondition( $subcond, $user ) ) + } elseif ( $cond[0] == '|' ) { + foreach ( array_slice( $cond, 1 ) as $subcond ) { + if ( self::recCheckCondition( $subcond, $user ) ) { return true; + } + } + return false; - } elseif( $cond[0] == '^' ) { + } elseif ( $cond[0] == '^' ) { $res = null; - foreach( array_slice( $cond, 1 ) as $subcond ) { - if( is_null( $res ) ) + foreach ( array_slice( $cond, 1 ) as $subcond ) { + if ( is_null( $res ) ) { $res = self::recCheckCondition( $subcond, $user ); - else - $res = ($res xor self::recCheckCondition( $subcond, $user )); + } else { + $res = ( $res xor self::recCheckCondition( $subcond, $user ) ); + } } + return $res; } elseif ( $cond[0] = '!' ) { - foreach( array_slice( $cond, 1 ) as $subcond ) - if( self::recCheckCondition( $subcond, $user ) ) + foreach ( array_slice( $cond, 1 ) as $subcond ) { + if ( self::recCheckCondition( $subcond, $user ) ) { return false; + } + } + return true; } } # If we got here, the array presumably does not contain other condi- # tions; it's not recursive. Pass it off to self::checkCondition. - if( !is_array( $cond ) ) + if ( !is_array( $cond ) ) { $cond = array( $cond ); + } + return self::checkCondition( $cond, $user ); } @@ -87,13 +104,15 @@ class Autopromote { * @return bool Whether the condition is true for the user */ private static function checkCondition( $cond, User $user ) { - if( count( $cond ) < 1 ) + if ( count( $cond ) < 1 ) { return false; + } + switch( $cond[0] ) { case APCOND_EMAILCONFIRMED: - if( User::isValidEmailAddr( $user->getEmail() ) ) { + if ( User::isValidEmailAddr( $user->getEmail() ) ) { global $wgEmailAuthentication; - if( $wgEmailAuthentication ) { + if ( $wgEmailAuthentication ) { return (bool)$user->getEmailAuthenticationTimestamp(); } else { return true; @@ -120,9 +139,10 @@ class Autopromote { default: $result = null; wfRunHooks( 'AutopromoteCondition', array( $cond[0], array_slice( $cond, 1 ), $user, &$result ) ); - if( $result === null ) { + if ( $result === null ) { throw new MWException( "Unrecognized condition {$cond[0]} for autopromotion!" ); } + return $result ? true : false; } } diff --git a/includes/BacklinkCache.php b/includes/BacklinkCache.php index 53f92dd958..b23fd56bd5 100644 --- a/includes/BacklinkCache.php +++ b/includes/BacklinkCache.php @@ -41,6 +41,7 @@ class BacklinkCache { if ( !isset( $this->db ) ) { $this->db = wfGetDB( DB_SLAVE ); } + return $this->db; } @@ -60,14 +61,17 @@ class BacklinkCache { // Partial range, not cached wfDebug( __METHOD__ . ": from DB (uncacheable range)\n" ); $conds = $this->getConditions( $table ); + // Use the from field in the condition rather than the joined page_id, // because databases are stupid and don't necessarily propagate indexes. if ( $startId ) { $conds[] = "$fromField >= " . intval( $startId ); } + if ( $endId ) { $conds[] = "$fromField <= " . intval( $endId ); } + $res = $this->getDB()->select( array( $table, 'page' ), array( 'page_namespace', 'page_title', 'page_id' ), @@ -78,6 +82,7 @@ class BacklinkCache { 'ORDER BY' => $fromField ) ); $ta = TitleArray::newFromResult( $res ); + wfProfileOut( __METHOD__ ); return $ta; } @@ -95,7 +100,9 @@ class BacklinkCache { ) ); $this->fullResultCache[$table] = $res; } + $ta = TitleArray::newFromResult( $this->fullResultCache[$table] ); + wfProfileOut( __METHOD__ ); return $ta; } @@ -150,6 +157,7 @@ class BacklinkCache { default: throw new MWException( "Invalid table \"$table\" in " . __CLASS__ ); } + return $conds; } @@ -167,6 +175,7 @@ class BacklinkCache { } $titleArray = $this->getLinks( $table ); + return $titleArray->count(); } @@ -193,29 +202,35 @@ class BacklinkCache { if ( isset( $this->fullResultCache[$table] ) ) { $cacheEntry = $this->partitionResult( $this->fullResultCache[$table], $batchSize ); wfDebug( __METHOD__ . ": got from full result cache\n" ); + return $cacheEntry['batches']; } // Try memcached global $wgMemc; + $memcKey = wfMemcKey( 'backlinks', md5( $this->title->getPrefixedDBkey() ), $table, $batchSize ); + $memcValue = $wgMemc->get( $memcKey ); if ( is_array( $memcValue ) ) { $cacheEntry = $memcValue; wfDebug( __METHOD__ . ": got from memcached $memcKey\n" ); + return $cacheEntry['batches']; } + // Fetch from database $this->getLinks( $table ); $cacheEntry = $this->partitionResult( $this->fullResultCache[$table], $batchSize ); // Save to memcached $wgMemc->set( $memcKey, $cacheEntry, self::CACHE_EXPIRY ); + wfDebug( __METHOD__ . ": got from database\n" ); return $cacheEntry['batches']; } @@ -254,6 +269,7 @@ class BacklinkCache { $batches[] = array( $start, $end ); } + return array( 'numRows' => $numRows, 'batches' => $batches ); } } diff --git a/includes/BagOStuff.php b/includes/BagOStuff.php index 563127dc78..aa52a842d9 100644 --- a/includes/BagOStuff.php +++ b/includes/BagOStuff.php @@ -104,6 +104,7 @@ abstract class BagOStuff { public function add( $key, $value, $exptime = 0 ) { if ( $this->get( $key ) == false ) { $this->set( $key, $value, $exptime ); + return true; } } @@ -130,6 +131,7 @@ abstract class BagOStuff { if ( !$this->lock( $key ) ) { return false; } + $value = intval( $value ); $n = false; @@ -138,6 +140,7 @@ abstract class BagOStuff { $this->set( $key, $n ); // exptime? } $this->unlock( $key ); + return $n; } @@ -146,8 +149,9 @@ abstract class BagOStuff { } public function debug( $text ) { - if ( $this->debugMode ) + if ( $this->debugMode ) { wfDebug( "BagOStuff debug: $text\n" ); + } } /** @@ -178,10 +182,13 @@ class HashBagOStuff extends BagOStuff { protected function expire( $key ) { $et = $this->bag[$key][1]; + if ( ( $et == 0 ) || ( $et > time() ) ) { return false; } + $this->delete( $key ); + return true; } @@ -189,9 +196,11 @@ class HashBagOStuff extends BagOStuff { if ( !isset( $this->bag[$key] ) ) { return false; } + if ( $this->expire( $key ) ) { return false; } + return $this->bag[$key][0]; } @@ -203,7 +212,9 @@ class HashBagOStuff extends BagOStuff { if ( !isset( $this->bag[$key] ) ) { return false; } + unset( $this->bag[$key] ); + return true; } @@ -223,6 +234,7 @@ class SqlBagOStuff extends BagOStuff { protected function getDB() { global $wgDBtype; + if ( !isset( $this->db ) ) { /* We must keep a separate connection to MySQL in order to avoid deadlocks * However, SQLite has an opposite behaviour. @@ -236,6 +248,7 @@ class SqlBagOStuff extends BagOStuff { $this->db->clearFlag( DBO_TRX ); } } + return $this->db; } @@ -245,12 +258,14 @@ class SqlBagOStuff extends BagOStuff { $db = $this->getDB(); $row = $db->selectRow( 'objectcache', array( 'value', 'exptime' ), array( 'keyname' => $key ), __METHOD__ ); + if ( !$row ) { $this->debug( 'get: no matching rows' ); return false; } $this->debug( "get: retrieved data; expiry time is " . $row->exptime ); + if ( $this->isExpired( $row->exptime ) ) { $this->debug( "get: key has expired, deleting" ); try { @@ -266,20 +281,28 @@ class SqlBagOStuff extends BagOStuff { } catch ( DBQueryError $e ) { $this->handleWriteError( $e ); } + return false; } + return $this->unserialize( $db->decodeBlob( $row->value ) ); } public function set( $key, $value, $exptime = 0 ) { $db = $this->getDB(); $exptime = intval( $exptime ); - if ( $exptime < 0 ) $exptime = 0; + + if ( $exptime < 0 ) { + $exptime = 0; + } + if ( $exptime == 0 ) { $encExpiry = $this->getMaxDateTime(); } else { - if ( $exptime < 3.16e8 ) # ~10 years + if ( $exptime < 3.16e8 ) { # ~10 years $exptime += time(); + } + $encExpiry = $db->timestamp( $exptime ); } try { @@ -294,21 +317,26 @@ class SqlBagOStuff extends BagOStuff { $db->commit(); } catch ( DBQueryError $e ) { $this->handleWriteError( $e ); + return false; } + return true; } public function delete( $key, $time = 0 ) { $db = $this->getDB(); + try { $db->begin(); $db->delete( 'objectcache', array( 'keyname' => $key ), __METHOD__ ); $db->commit(); } catch ( DBQueryError $e ) { $this->handleWriteError( $e ); + return false; } + return true; } @@ -323,12 +351,14 @@ class SqlBagOStuff extends BagOStuff { if ( $row === false ) { // Missing $db->commit(); + return false; } $db->delete( 'objectcache', array( 'keyname' => $key ), __METHOD__ ); if ( $this->isExpired( $row->exptime ) ) { // Expired, do not reinsert $db->commit(); + return false; } @@ -343,8 +373,10 @@ class SqlBagOStuff extends BagOStuff { $db->commit(); } catch ( DBQueryError $e ) { $this->handleWriteError( $e ); + return false; } + return $newValue; } @@ -352,9 +384,11 @@ class SqlBagOStuff extends BagOStuff { $db = $this->getDB(); $res = $db->select( 'objectcache', array( 'keyname' ), false, __METHOD__ ); $result = array(); + foreach ( $res as $row ) { $result[] = $row->keyname; } + return $result; } @@ -385,6 +419,7 @@ class SqlBagOStuff extends BagOStuff { public function expireAll() { $db = $this->getDB(); $now = $db->timestamp(); + try { $db->begin(); $db->delete( 'objectcache', array( 'exptime < ' . $db->addQuotes( $now ) ), __METHOD__ ); @@ -396,6 +431,7 @@ class SqlBagOStuff extends BagOStuff { public function deleteAll() { $db = $this->getDB(); + try { $db->begin(); $db->delete( 'objectcache', '*', __METHOD__ ); @@ -415,6 +451,7 @@ class SqlBagOStuff extends BagOStuff { */ protected function serialize( &$data ) { $serial = serialize( $data ); + if ( function_exists( 'gzdeflate' ) ) { return gzdeflate( $serial ); } else { @@ -430,11 +467,14 @@ class SqlBagOStuff extends BagOStuff { protected function unserialize( $serial ) { if ( function_exists( 'gzinflate' ) ) { $decomp = @gzinflate( $serial ); + if ( false !== $decomp ) { $serial = $decomp; } } + $ret = unserialize( $serial ); + return $ret; } @@ -444,13 +484,16 @@ class SqlBagOStuff extends BagOStuff { */ protected function handleWriteError( $exception ) { $db = $this->getDB(); + if ( !$db->wasReadOnlyError() ) { throw $exception; } + try { $db->rollback(); } catch ( DBQueryError $e ) { } + wfDebug( __METHOD__ . ": ignoring query error\n" ); $db->ignoreErrors( false ); } @@ -469,19 +512,23 @@ class MediaWikiBagOStuff extends SqlBagOStuff { } class APCBagOStuff extends BagOStuff { public function get( $key ) { $val = apc_fetch( $key ); + if ( is_string( $val ) ) { $val = unserialize( $val ); } + return $val; } public function set( $key, $value, $exptime = 0 ) { apc_store( $key, serialize( $value ), $exptime ); + return true; } public function delete( $key, $time = 0 ) { apc_delete( $key ); + return true; } @@ -489,9 +536,11 @@ class APCBagOStuff extends BagOStuff { $info = apc_cache_info( 'user' ); $list = $info['cache_list']; $keys = array(); + foreach ( $list as $entry ) { $keys[] = $entry['info']; } + return $keys; } } @@ -507,29 +556,35 @@ class APCBagOStuff extends BagOStuff { class eAccelBagOStuff extends BagOStuff { public function get( $key ) { $val = eaccelerator_get( $key ); + if ( is_string( $val ) ) { $val = unserialize( $val ); } + return $val; } public function set( $key, $value, $exptime = 0 ) { eaccelerator_put( $key, serialize( $value ), $exptime ); + return true; } public function delete( $key, $time = 0 ) { eaccelerator_rm( $key ); + return true; } public function lock( $key, $waitTimeout = 0 ) { eaccelerator_lock( $key ); + return true; } public function unlock( $key ) { eaccelerator_unlock( $key ); + return true; } } @@ -541,7 +596,6 @@ class eAccelBagOStuff extends BagOStuff { * @ingroup Cache */ class XCacheBagOStuff extends BagOStuff { - /** * Get a value from the XCache object cache * @@ -550,8 +604,11 @@ class XCacheBagOStuff extends BagOStuff { */ public function get( $key ) { $val = xcache_get( $key ); - if ( is_string( $val ) ) + + if ( is_string( $val ) ) { $val = unserialize( $val ); + } + return $val; } @@ -565,6 +622,7 @@ class XCacheBagOStuff extends BagOStuff { */ public function set( $key, $value, $expire = 0 ) { xcache_set( $key, serialize( $value ), $expire ); + return true; } @@ -577,6 +635,7 @@ class XCacheBagOStuff extends BagOStuff { */ public function delete( $key, $time = 0 ) { xcache_unset( $key ); + return true; } } @@ -594,10 +653,12 @@ class DBABagOStuff extends BagOStuff { public function __construct( $dir = false ) { global $wgDBAhandler; + if ( $dir === false ) { global $wgTmpDirectory; $dir = $wgTmpDirectory; } + $this->mFile = "$dir/mw-cache-" . wfWikiID(); $this->mFile .= '.db'; wfDebug( __CLASS__ . ": using cache file {$this->mFile}\n" ); @@ -610,6 +671,7 @@ class DBABagOStuff extends BagOStuff { function encode( $value, $expiry ) { # Convert to absolute time $expiry = $this->convertExpiry( $expiry ); + return sprintf( '%010u', intval( $expiry ) ) . ' ' . serialize( $value ); } @@ -633,29 +695,36 @@ class DBABagOStuff extends BagOStuff { } else { $handle = $this->getWriter(); } + if ( !$handle ) { wfDebug( "Unable to open DBA cache file {$this->mFile}\n" ); } + return $handle; } function getWriter() { $handle = dba_open( $this->mFile, 'cl', $this->mHandler ); + if ( !$handle ) { wfDebug( "Unable to open DBA cache file {$this->mFile}\n" ); } + return $handle; } function get( $key ) { wfProfileIn( __METHOD__ ); wfDebug( __METHOD__ . "($key)\n" ); + $handle = $this->getReader(); if ( !$handle ) { return null; } + $val = dba_fetch( $key, $handle ); list( $val, $expiry ) = $this->decode( $val ); + # Must close ASAP because locks are held dba_close( $handle ); @@ -667,6 +736,7 @@ class DBABagOStuff extends BagOStuff { wfDebug( __METHOD__ . ": $key expired\n" ); $val = null; } + wfProfileOut( __METHOD__ ); return $val; } @@ -674,13 +744,17 @@ class DBABagOStuff extends BagOStuff { function set( $key, $value, $exptime = 0 ) { wfProfileIn( __METHOD__ ); wfDebug( __METHOD__ . "($key)\n" ); + $blob = $this->encode( $value, $exptime ); + $handle = $this->getWriter(); if ( !$handle ) { return false; } + $ret = dba_replace( $key, $blob, $handle ); dba_close( $handle ); + wfProfileOut( __METHOD__ ); return $ret; } @@ -688,27 +762,36 @@ class DBABagOStuff extends BagOStuff { function delete( $key, $time = 0 ) { wfProfileIn( __METHOD__ ); wfDebug( __METHOD__ . "($key)\n" ); + $handle = $this->getWriter(); if ( !$handle ) { return false; } + $ret = dba_delete( $key, $handle ); dba_close( $handle ); + wfProfileOut( __METHOD__ ); return $ret; } function add( $key, $value, $exptime = 0 ) { wfProfileIn( __METHOD__ ); + $blob = $this->encode( $value, $exptime ); + $handle = $this->getWriter(); + if ( !$handle ) { return false; } + $ret = dba_insert( $key, $blob, $handle ); + # Insert failed, check to see if it failed due to an expired key if ( !$ret ) { list( $value, $expiry ) = $this->decode( dba_fetch( $key, $handle ) ); + if ( $expiry < time() ) { # Yes expired, delete and try again dba_delete( $key, $handle ); @@ -718,6 +801,7 @@ class DBABagOStuff extends BagOStuff { } dba_close( $handle ); + wfProfileOut( __METHOD__ ); return $ret; } @@ -725,13 +809,17 @@ class DBABagOStuff extends BagOStuff { function keys() { $reader = $this->getReader(); $k1 = dba_firstkey( $reader ); + if ( !$k1 ) { return array(); } + $result[] = $k1; + while ( $key = dba_nextkey( $reader ) ) { $result[] = $key; } + return $result; } } @@ -752,8 +840,11 @@ class WinCacheBagOStuff extends BagOStuff { */ public function get( $key ) { $val = wincache_ucache_get( $key ); - if ( is_string( $val ) ) + + if ( is_string( $val ) ) { $val = unserialize( $val ); + } + return $val; } @@ -767,6 +858,7 @@ class WinCacheBagOStuff extends BagOStuff { */ public function set( $key, $value, $expire = 0 ) { wincache_ucache_set( $key, serialize( $value ), $expire ); + return true; } @@ -779,6 +871,7 @@ class WinCacheBagOStuff extends BagOStuff { */ public function delete( $key, $time = 0 ) { wincache_ucache_delete( $key ); + return true; } @@ -786,9 +879,11 @@ class WinCacheBagOStuff extends BagOStuff { $info = wincache_ucache_info(); $list = $info['ucache_entries']; $keys = array(); + foreach ( $list as $entry ) { $keys[] = $entry['key_name']; } + return $keys; } } diff --git a/includes/Block.php b/includes/Block.php index db5a52161f..4208623c2e 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -63,6 +63,7 @@ class Block { public static function newFromDB( $address, $user = 0, $killExpired = true ) { $block = new Block; $block->load( $address, $user, $killExpired ); + if ( $block->isValid() ) { return $block; } else { @@ -81,6 +82,7 @@ class Block { $res = $dbr->resultObject( $dbr->select( 'ipblocks', '*', array( 'ipb_id' => $id ), __METHOD__ ) ); $block = new Block; + if ( $block->loadFromResult( $res ) ) { return $block; } else { @@ -142,6 +144,7 @@ class Block { $db = wfGetDB( DB_SLAVE ); $options = array(); } + return $db; } @@ -163,6 +166,7 @@ class Block { if ( 0 == $user && $address === '' ) { # Invalid user specification, not blocked $this->clear(); + return false; } @@ -170,6 +174,7 @@ class Block { if ( $user ) { $res = $db->resultObject( $db->select( 'ipblocks', '*', array( 'ipb_user' => $user ), __METHOD__, $options ) ); + if ( $this->loadFromResult( $res, $killExpired ) ) { return true; } @@ -190,6 +195,7 @@ class Block { if ( !$this->mCreateAccount ) { $this->clear(); } + return false; } else { return true; @@ -204,6 +210,7 @@ class Block { if ( !$this->mCreateAccount ) { $this->clear(); } + return false; } else { return true; @@ -266,6 +273,7 @@ class Block { } } $res->free(); + return $ret; } @@ -304,6 +312,7 @@ class Block { $res = $db->resultObject( $db->select( 'ipblocks', '*', $conds, __METHOD__, $options ) ); $success = $this->loadFromResult( $res, $killExpired ); + return $success; } @@ -368,6 +377,7 @@ class Block { $dbw = wfGetDB( DB_MASTER ); $dbw->delete( 'ipblocks', array( 'ipb_id' => $this->mId ), __METHOD__ ); + return $dbw->affectedRows() > 0; } @@ -379,6 +389,7 @@ class Block { */ public function insert( $dbw = null ) { wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" ); + if ( $dbw === null ) $dbw = wfGetDB( DB_MASTER ); @@ -476,6 +487,7 @@ class Block { if ( !$this->mUser && $this->mAnonOnly ) { $this->mBlockEmail = 0; } + if ( !$this->mByName ) { if ( $this->mBy ) { $this->mByName = User::whoIs( $this->mBy ); @@ -520,8 +532,9 @@ class Block { wfDebug( "No IP found to retroactively autoblock\n" ); } else { while ( $row = $dbr->fetchObject( $res ) ) { - if ( $row->rc_ip ) + if ( $row->rc_ip ) { $this->doAutoblock( $row->rc_ip ); + } } } } @@ -602,13 +615,16 @@ class Block { # exceed the user block. If it would exceed, then do nothing, else # prolong block time if ( $this->mExpiry && - ( $this->mExpiry < Block::getAutoblockExpiry( $ipblock->mTimestamp ) ) ) { + ( $this->mExpiry < Block::getAutoblockExpiry( $ipblock->mTimestamp ) ) + ) { return; } + # Just update the timestamp if ( !$justInserted ) { $ipblock->updateTimestamp(); } + return; } else { $ipblock = new Block; @@ -627,6 +643,7 @@ class Block { # Continue suppressing the name if needed $ipblock->mHideName = $this->mHideName; $ipblock->mAllowUsertalk = $this->mAllowUsertalk; + # If the user is already blocked with an expiry date, we don't # want to pile on top of that! if ( $this->mExpiry ) { @@ -634,6 +651,7 @@ class Block { } else { $ipblock->mExpiry = Block::getAutoblockExpiry( $this->mTimestamp ); } + # Insert it return $ipblock->insert(); } @@ -644,6 +662,7 @@ class Block { */ public function deleteIfExpired() { wfProfileIn( __METHOD__ ); + if ( $this->isExpired() ) { wfDebug( "Block::deleteIfExpired() -- deleting\n" ); $this->delete(); @@ -652,6 +671,7 @@ class Block { wfDebug( "Block::deleteIfExpired() -- not expired\n" ); $retVal = false; } + wfProfileOut( __METHOD__ ); return $retVal; } @@ -662,6 +682,7 @@ class Block { */ public function isExpired() { wfDebug( "Block::isExpired() checking current " . wfTimestampNow() . " vs $this->mExpiry\n" ); + if ( !$this->mExpiry ) { return false; } else { @@ -778,6 +799,7 @@ class Block { */ public static function getAutoblockExpiry( $timestamp ) { global $wgAutoblockExpiry; + return wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $timestamp ) + $wgAutoblockExpiry ); } @@ -813,6 +835,7 @@ class Block { $range = "$newip/{$parts[1]}"; } } + return $range; } @@ -849,6 +872,7 @@ class Block { if ( is_null( $msg ) ) { $msg = array(); $keys = array( 'infiniteblock', 'expiringblock' ); + foreach ( $keys as $key ) { $msg[$key] = wfMsgHtml( $key ); } @@ -863,6 +887,7 @@ class Block { $expiretimestr = htmlspecialchars( $wgLang->time( $expiry, true ) ); $expirystr = wfMsgReplaceArgs( $msg['expiringblock'], array( $expiredatestr, $expiretimestr ) ); } + return $expirystr; } @@ -881,7 +906,7 @@ class Block { return false; } } + return $expiry; } - } diff --git a/includes/CacheDependency.php b/includes/CacheDependency.php index 11e707380d..fd72acb4df 100644 --- a/includes/CacheDependency.php +++ b/includes/CacheDependency.php @@ -5,6 +5,7 @@ * than instantiating one of these objects directly. * @ingroup Cache */ + class DependencyWrapper { var $value; var $deps; @@ -17,9 +18,11 @@ class DependencyWrapper { */ function __construct( $value = false, $deps = array() ) { $this->value = $value; + if ( !is_array( $deps ) ) { $deps = array( $deps ); } + $this->deps = $deps; } @@ -32,6 +35,7 @@ class DependencyWrapper { return true; } } + return false; } @@ -81,6 +85,7 @@ class DependencyWrapper { $callbackParams = array(), $deps = array() ) { $obj = $cache->get( $key ); + if ( is_object( $obj ) && $obj instanceof DependencyWrapper && !$obj->isExpired() ) { $value = $obj->value; } elseif ( $callback ) { @@ -91,6 +96,7 @@ class DependencyWrapper { } else { $value = null; } + return $value; } } @@ -207,6 +213,7 @@ class TitleDependency extends CacheDependency { if ( !isset( $this->titleObj ) ) { $this->titleObj = Title::makeTitle( $this->ns, $this->dbk ); } + return $this->titleObj; } @@ -255,6 +262,7 @@ class TitleListDependency extends CacheDependency { foreach ( $this->getLinkBatch()->data as $ns => $dbks ) { if ( count( $dbks ) > 0 ) { $timestamps[$ns] = array(); + foreach ( $dbks as $dbk => $value ) { $timestamps[$ns][$dbk] = false; } @@ -276,6 +284,7 @@ class TitleListDependency extends CacheDependency { $timestamps[$row->page_namespace][$row->page_title] = $row->page_touched; } } + return $timestamps; } @@ -297,6 +306,7 @@ class TitleListDependency extends CacheDependency { function isExpired() { $newTimestamps = $this->calculateTimestamps(); + foreach ( $this->timestamps as $ns => $dbks ) { foreach ( $dbks as $dbk => $oldTimestamp ) { $newTimestamp = $newTimestamps[$ns][$dbk]; @@ -319,6 +329,7 @@ class TitleListDependency extends CacheDependency { } } } + return false; } } -- 2.20.1