X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2FBlock.php;h=8663d0328cd75201adccd38e497162e4763fb442;hb=1f83b424294a6fd78cb73cf43db3464ca7481774;hp=a11ba26484874cf20d68eccb70ed8a9fd6c9b0e0;hpb=84851a43f3ea8ea146c4d82c55fd01b9fa302347;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Block.php b/includes/Block.php index a11ba26484..8663d0328c 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -1417,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. *