X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FBlock.php;h=8663d0328cd75201adccd38e497162e4763fb442;hb=1f83b424294a6fd78cb73cf43db3464ca7481774;hp=19ba0a28fbefd2b36db7f01a54156650b995786f;hpb=ba67060734ecfa835f54c83540c0c136db1690d7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Block.php b/includes/Block.php index 19ba0a28fb..8663d0328c 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -19,6 +19,9 @@ * * @file */ + +use MediaWiki\MediaWikiServices; + class Block { /** @var string */ public $mReason; @@ -689,11 +692,13 @@ class Block { public static function isWhitelistedFromAutoblocks( $ip ) { // Try to get the autoblock_whitelist from the cache, as it's faster // than getting the msg raw and explode()'ing it. - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $lines = $cache->getWithSetCallback( wfMemcKey( 'ipb', 'autoblock', 'whitelist' ), $cache::TTL_DAY, - function () { + function ( $curValue, &$ttl, array &$setOpts ) { + $setOpts += Database::getCacheSetOptions( wfGetDB( DB_REPLICA ) ); + return explode( "\n", wfMessage( 'autoblock_whitelist' )->inContentLanguage()->plain() ); } @@ -1120,6 +1125,7 @@ class Block { } $conds = []; + $proxyLookup = MediaWikiServices::getInstance()->getProxyLookup(); foreach ( array_unique( $ipChain ) as $ipaddr ) { # Discard invalid IP addresses. Since XFF can be spoofed and we do not # necessarily trust the header given to us, make sure that we are only @@ -1130,7 +1136,7 @@ class Block { continue; } # Don't check trusted IPs (includes local squids which will be in every request) - if ( IP::isTrustedProxy( $ipaddr ) ) { + if ( $proxyLookup->isTrustedProxy( $ipaddr ) ) { continue; } # Check both the original IP (to check against single blocks), as well as build @@ -1411,6 +1417,33 @@ class Block { $this->blocker = $user; } + /** + * Set the 'BlockID' cookie to this block's ID and expiry time. The cookie's expiry will be + * the same as the block's, unless it's greater than $wgCookieExpiration in which case + * $wgCookieExpiration will be used instead (defaults to 30 days). + * + * An empty value can also be set, in order to retain the cookie but remove the block ID + * (e.g. as used in User::getBlockedStatus). + * + * @param WebResponse $response The response on which to set the cookie. + * @param boolean $setEmpty Whether to set the cookie's value to the empty string. + */ + public function setCookie( WebResponse $response, $setEmpty = false ) { + // Calculate the default expiry time. + $config = RequestContext::getMain()->getConfig(); + $defaultExpiry = wfTimestamp() + $config->get( 'CookieExpiration' ); + + // Use the Block's expiry time only if it's less than the default. + $expiry = wfTimestamp( TS_UNIX, $this->getExpiry() ); + if ( $expiry > $defaultExpiry ) { + // The *default* default expiry is 30 days. + $expiry = $defaultExpiry; + } + + $cookieValue = $setEmpty ? '' : $this->getId(); + $response->setCookie( 'BlockID', $cookieValue, $expiry ); + } + /** * Get the key and parameters for the corresponding error message. *