Hook, methods, classes still to rename where appropriate.
Bug: T104148
Depends-On: Id34339dff88bc6d1863378ac94b96b2d590b891d
Depends-On: I4e2938395bcbf7956b83fff00978f09c61dcfa36
Change-Id: I7a725dae551c867a4fa7c213838d52c7fb862756
module or will be generated by Mediawiki itself (depending on the set-up).
==== Changed configuration ====
+* $wgUseCdn, $wgCdnServers, $wgCdnServersNoPurge, and $wgCdnMaxAge – These four
+ CDN-related config variables have been renamed from being specific to Squid –
+ they were previously $wgUseSquid, $wgSquidServers, $wgSquidServersNoPurge, and
+ $wgSquidMaxage respectively. This aligns them with the related existing
+ variable $wgCdnMaxageLagged. The previous configuration variable names are
+ deprecated, but will be used as the fall back if they are still set.
+ Note that wgSquidPurgeUseHostHeader has not been renamed, as it is deprecated.
* …
==== Removed configuration ====
# If CDN caches are configured, tell them to cache the response,
# and tell the client to always check with the CDN. Otherwise,
# tell the client to use a cached copy, without a way to purge it.
-
- if ( $this->mConfig->get( 'UseSquid' ) ) {
+ if ( $this->mConfig->get( 'UseCdn' ) ) {
# Expect explicit purge of the proxy cache, but require end user agents
# to revalidate against the proxy on each visit.
# Surrogate-Control controls our CDN, Cache-Control downstream caches
if ( !IP::isValid( $ipaddr ) ) {
continue;
}
- # Don't check trusted IPs (includes local squids which will be in every request)
+ # Don't check trusted IPs (includes local CDNs which will be in every request)
if ( $proxyLookup->isTrustedProxy( $ipaddr ) ) {
continue;
}
* @param array $ipChain List of IPs (strings). This is used to determine how "close"
* a block is to the server, and if a block matches exactly, or is in a range.
* The order is furthest from the server to nearest e.g., (Browser, proxy1, proxy2,
- * local-squid, ...)
+ * local-cdn, ...)
* @throws MWException
* @return Block|null The "best" block from the list
*/
* @name HTTP proxy (CDN) settings
*
* Many of these settings apply to any HTTP proxy used in front of MediaWiki,
- * although they are referred to as Squid settings for historical reasons.
+ * although they are sometimes still referred to as Squid settings for
+ * historical reasons.
*
* Achieving a high hit ratio with an HTTP proxy requires special
* configuration. See https://www.mediawiki.org/wiki/Manual:Squid_caching for
/**
* Enable/disable CDN.
* See https://www.mediawiki.org/wiki/Manual:Squid_caching
+ *
+ * @since 1.34 Renamed from $wgUseSquid.
*/
-$wgUseSquid = false;
+$wgUseCdn = false;
/**
* If you run Squid3 with ESI support, enable this (default:false):
* out s-maxage in the CDN config.
*
* 18000 seconds = 5 hours, more cache hits with 2678400 = 31 days.
+ *
+ * @since 1.34 Renamed from $wgSquidMaxage
*/
-$wgSquidMaxage = 18000;
+$wgCdnMaxAge = 18000;
/**
* Cache timeout for the CDN when DB replica DB lag is high
- * @see $wgSquidMaxage
+ * @see $wgCdnMaxAge
+ *
* @since 1.27
*/
$wgCdnMaxageLagged = 30;
/**
* Cache timeout for the CDN when a response is known to be wrong or incomplete (due to load)
- * @see $wgSquidMaxage
+ * @see $wgCdnMaxAge
* @since 1.27
*/
$wgCdnMaxageSubstitute = 60;
* headers sent/modified from these proxies when obtaining the remote IP address
*
* For a list of trusted servers which *aren't* purged, see $wgSquidServersNoPurge.
+ *
+ * @since 1.34 Renamed from $wgSquidServers.
*/
-$wgSquidServers = [];
+$wgCdnServers = [];
/**
- * As above, except these servers aren't purged on page changes; use to set a
- * list of trusted proxies, etc. Supports both individual IP addresses and
- * CIDR blocks.
+ * As with $wgCdnServers, except these servers aren't purged on page changes;
+ * use to set a list of trusted proxies, etc. Supports both individual IP
+ * addresses and CIDR blocks.
+ *
* @since 1.23 Supports CIDR ranges
+ * @since 1.34 Renamed from $wgSquidServersNoPurge
*/
-$wgSquidServersNoPurge = [];
+$wgCdnServersNoPurge = [];
/**
* Whether to use a Host header in purge requests sent to the proxy servers
- * configured in $wgSquidServers. Set this to false to support Squid
+ * configured in $wgCdnServers. Set this to false to support a CDN
* configured in forward-proxy mode.
*
* If this is set to true, a Host header will be sent, and only the path
/**
* Display the new debugging toolbar. This also enables profiling on database
* queries and other useful output.
- * Will be ignored if $wgUseFileCache or $wgUseSquid is enabled.
+ * Will be ignored if $wgUseFileCache or $wgUseCdn is enabled.
*
* @since 1.19
*/
}
# Let CDN cache things if we can purge them.
- if ( $this->config->get( 'UseSquid' ) &&
+ if ( $this->config->get( 'UseCdn' ) &&
in_array(
// Use PROTO_INTERNAL because that's what getCdnUrls() uses
wfExpandUrl( $request->getRequestURL(), PROTO_INTERNAL ),
$requestTitle->getCdnUrls()
)
) {
- $output->setCdnMaxage( $this->config->get( 'SquidMaxage' ) );
+ $output->setCdnMaxage( $this->config->get( 'CdnMaxAge' ) );
}
$action->show();
'user' => $this->getUser()->getTouched(),
'epoch' => $config->get( 'CacheEpoch' )
];
- if ( $config->get( 'UseSquid' ) ) {
+ if ( $config->get( 'UseCdn' ) ) {
$modifiedTimes['sepoch'] = wfTimestamp( TS_MW, $this->getCdnCacheEpoch(
time(),
- $config->get( 'SquidMaxage' )
+ $config->get( 'CdnMaxAge' )
) );
}
Hooks::run( 'OutputPageCheckLastModified', [ &$modifiedTimes, $this ] );
* @return int Timestamp
*/
private function getCdnCacheEpoch( $reqTime, $maxAge ) {
- // Ensure Last-Modified is never more than (wgSquidMaxage) in the past,
+ // Ensure Last-Modified is never more than $wgCdnMaxAge in the past,
// because even if the wiki page content hasn't changed since, static
// resources may have changed (skin HTML, interface messages, urls, etc.)
// and must roll-over in a timely manner (T46570)
*
* @param string|int|float|bool|null $mtime Last-Modified timestamp
* @param int $minTTL Minimum TTL in seconds [default: 1 minute]
- * @param int $maxTTL Maximum TTL in seconds [default: $wgSquidMaxage]
+ * @param int $maxTTL Maximum TTL in seconds [default: $wgCdnMaxAge]
* @since 1.28
*/
public function adaptCdnTTL( $mtime, $minTTL = 0, $maxTTL = 0 ) {
$minTTL = $minTTL ?: IExpiringStore::TTL_MINUTE;
- $maxTTL = $maxTTL ?: $this->getConfig()->get( 'SquidMaxage' );
+ $maxTTL = $maxTTL ?: $this->getConfig()->get( 'CdnMaxAge' );
if ( $mtime === null || $mtime === false ) {
return $minTTL; // entity does not exist
if ( $this->mEnableClientCache ) {
if (
- $config->get( 'UseSquid' ) &&
+ $config->get( 'UseCdn' ) &&
!$response->hasCookies() &&
!SessionManager::getGlobalSession()->isPersistent() &&
!$this->isPrintable() &&
# start with a shorter timeout for initial testing
# header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
$response->header(
- "Surrogate-Control: max-age={$config->get( 'SquidMaxage' )}" .
+ "Surrogate-Control: max-age={$config->get( 'CdnMaxAge' )}" .
"+{$this->mCdnMaxage}, content=\"ESI/1.0\""
);
$response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
'ProxyLookup' => function ( MediaWikiServices $services ) : ProxyLookup {
$mainConfig = $services->getMainConfig();
return new ProxyLookup(
- $mainConfig->get( 'SquidServers' ),
- $mainConfig->get( 'SquidServersNoPurge' )
+ $mainConfig->get( 'CdnServers' ),
+ $mainConfig->get( 'CdnServersNoPurge' )
);
},
// To determine the user language, use $wgLang->getCode()
$wgContLanguageCode = $wgLanguageCode;
+// Temporary backwards-compatibility reading of old Squid-named CDN settings as of MediaWiki 1.34,
+// to support sysadmins who fail to update their settings immediately:
+
+if ( isset( $wgUseSquid ) ) {
+ // If the sysadmin is still setting a value of $wgUseSquid to true but $wgUseCdn is the default of
+ // false, to be safe, assume they do want this still, so enable it.
+ if ( !$wgUseCdn && $wgUseSquid ) {
+ $wgUseCdn = $wgUseSquid;
+ wfDeprecated( '$wgUseSquid enabled but $wgUseCdn disabled; enabling CDN functions', '1.34' );
+ }
+} else {
+ // Backwards-compatibility for extensions that read this value.
+ $wgUseSquid = $wgUseCdn;
+}
+
+if ( isset( $wgSquidServers ) ) {
+ // If the sysadmin is still setting a value of $wgSquidServers but $wgCdnServers is the default of
+ // empty, to be safe, assume they do want these servers to be still used, so use them.
+ if ( !empty( $wgSquidServers ) && empty( $wgCdnServers ) ) {
+ $wgCdnServers = $wgSquidServers;
+ wfDeprecated( '$wgSquidServers set, $wgCdnServers empty; using them', '1.34' );
+ }
+} else {
+ // Backwards-compatibility for extensions that read this value.
+ $wgSquidServers = $wgCdnServers;
+}
+
+if ( isset( $wgSquidServersNoPurge ) ) {
+ // If the sysadmin is still setting values in $wgSquidServersNoPurge but $wgCdnServersNoPurge is
+ // the default of empty, to be safe, assume they do want these servers to be still used, so use
+ // them.
+ if ( !empty( $wgSquidServersNoPurge ) && empty( $wgCdnServersNoPurge ) ) {
+ $wgCdnServersNoPurge = $wgSquidServersNoPurge;
+ wfDeprecated( '$wgSquidServersNoPurge set, $wgCdnServersNoPurge empty; using them', '1.34' );
+ }
+} else {
+ // Backwards-compatibility for extensions that read this value.
+ $wgSquidServersNoPurge = $wgCdnServersNoPurge;
+}
+
+if ( isset( $wgSquidMaxage ) ) {
+ // If the sysadmin is still setting a value of $wgSquidMaxage and it's higher than $wgCdnMaxAge,
+ // to be safe, assume they want the higher (lower performance requirement) value, so use that.
+ if ( $wgCdnMaxAge < $wgSquidMaxage ) {
+ $wgCdnMaxAge = $wgSquidMaxage;
+ wfDeprecated( '$wgSquidMaxage set higher than $wgCdnMaxAge; using the higher value', '1.34' );
+ }
+} else {
+ // Backwards-compatibility for extensions that read this value.
+ $wgSquidMaxage = $wgCdnMaxAge;
+}
+
// Easy to forget to falsify $wgDebugToolbar for static caches.
// If file cache or CDN cache is on, just disable this (DWIMD).
-if ( $wgUseFileCache || $wgUseSquid ) {
+if ( $wgUseFileCache || $wgUseCdn ) {
$wgDebugToolbar = false;
}
$contentType = $this->getContentType();
- $maxage = $request->getInt( 'maxage', $config->get( 'SquidMaxage' ) );
+ $maxage = $request->getInt( 'maxage', $config->get( 'CdnMaxAge' ) );
$smaxage = $request->getIntOrNull( 'smaxage' );
if ( $smaxage === null ) {
if (
private $mContinuationManager;
private $mAction;
private $mEnableWrite;
- private $mInternalMode, $mSquidMaxage;
+ private $mInternalMode, $mCdnMaxAge;
/** @var ApiBase */
private $mModule;
$this->mContinuationManager = null;
$this->mEnableWrite = $enableWrite;
- $this->mSquidMaxage = -1; // flag for executeActionWithErrorHandling()
+ $this->mCdnMaxAge = -1; // flag for executeActionWithErrorHandling()
$this->mCommit = false;
}
$ts->format( 'D M j H:i:s Y' ) === $value ||
$ts->format( 'D M j H:i:s Y' ) === $value
) {
+ $config = $this->getConfig();
$lastMod = $module->getConditionalRequestData( 'last-modified' );
if ( $lastMod !== null ) {
// Mix in some MediaWiki modification times
$modifiedTimes = [
'page' => $lastMod,
'user' => $this->getUser()->getTouched(),
- 'epoch' => $this->getConfig()->get( 'CacheEpoch' ),
+ 'epoch' => $config->get( 'CacheEpoch' ),
];
- if ( $this->getConfig()->get( 'UseSquid' ) ) {
+
+ if ( $config->get( 'UseCdn' ) ) {
// T46570: the core page itself may not change, but resources might
$modifiedTimes['sepoch'] = wfTimestamp(
- TS_MW, time() - $this->getConfig()->get( 'SquidMaxage' )
+ TS_MW, time() - $config->get( 'CdnMaxAge' )
);
}
Hooks::run( 'OutputPageCheckLastModified', [ &$modifiedTimes, $this->getOutput() ] );
if ( IP::isIPv4( $this->host ) ) {
$this->ip = $this->host;
} elseif ( IP::isIPv6( $this->host ) ) {
- throw new MWException( '$wgSquidServers does not support IPv6' );
+ throw new MWException( '$wgCdnServers does not support IPv6' );
} else {
Wikimedia\suppressWarnings();
$this->ip = gethostbyname( $this->host );
}
/**
- * Purges a list of CDN nodes defined in $wgSquidServers.
+ * Purges a list of CDN nodes defined in $wgCdnServers.
* $urlArr should contain the full URLs to purge as values
* (example: $urlArr[] = 'http://my.host/something')
*
* @param string[] $urlArr List of full URLs to purge
*/
public static function purge( array $urlArr ) {
- global $wgSquidServers, $wgHTCPRouting;
+ global $wgCdnServers, $wgHTCPRouting;
if ( !$urlArr ) {
return;
}
// Do direct server purges if enabled (this does not scale very well)
- if ( $wgSquidServers ) {
- // Maximum number of parallel connections per squid
- $maxSocketsPerSquid = 8;
+ if ( $wgCdnServers ) {
+ // Maximum number of parallel connections per CDN
+ $maxSocketsPerCdn = 8;
// Number of requests to send per socket
// 400 seems to be a good tradeoff, opening a socket takes a while
$urlsPerSocket = 400;
- $socketsPerSquid = ceil( count( $urlArr ) / $urlsPerSocket );
- if ( $socketsPerSquid > $maxSocketsPerSquid ) {
- $socketsPerSquid = $maxSocketsPerSquid;
+ $socketsPerCdn = ceil( count( $urlArr ) / $urlsPerSocket );
+ if ( $socketsPerCdn > $maxSocketsPerCdn ) {
+ $socketsPerCdn = $maxSocketsPerCdn;
}
$pool = new SquidPurgeClientPool;
- $chunks = array_chunk( $urlArr, ceil( count( $urlArr ) / $socketsPerSquid ) );
- foreach ( $wgSquidServers as $server ) {
+ $chunks = array_chunk( $urlArr, ceil( count( $urlArr ) / $socketsPerCdn ) );
+ foreach ( $wgCdnServers as $server ) {
foreach ( $chunks as $chunk ) {
$client = new SquidPurgeClient( $server );
foreach ( $chunk as $url ) {
<?php
/**
- * Benchmark for Squid purge.
+ * Benchmark for CDN purge.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
require_once __DIR__ . '/Benchmarker.php';
/**
- * Maintenance script that benchmarks Squid purge.
+ * Maintenance script that benchmarks CDN purge.
*
* @ingroup Benchmark
*/
class BenchmarkPurge extends Benchmarker {
public function __construct() {
parent::__construct();
- $this->addDescription( 'Benchmark the Squid purge functions.' );
+ $this->addDescription( 'Benchmark the CDN purge functions.' );
}
public function execute() {
- global $wgUseSquid, $wgSquidServers;
- if ( !$wgUseSquid ) {
- $this->fatalError( "Squid purge benchmark doesn't do much without squid support on." );
+ global $wgUseCdn, $wgCdnServers;
+
+ if ( !$wgUseCdn ) {
+ $this->error( "CDN purge benchmark doesn't do much without CDN support on." );
} else {
- $this->output( "There are " . count( $wgSquidServers ) . " defined squid servers:\n" );
+ $this->output( "There are " . count( $wgCdnServers ) . " defined CDN servers:\n" );
if ( $this->hasOption( 'count' ) ) {
$lengths = [ intval( $this->getOption( 'count' ) ) ];
} else {
}
foreach ( $lengths as $length ) {
$urls = $this->randomUrlList( $length );
- $trial = $this->benchSquid( $urls );
+ $trial = $this->benchCdn( $urls );
$this->output( $trial . "\n" );
}
}
/**
* Run a bunch of URLs through CdnCacheUpdate::purge()
- * to benchmark Squid response times.
+ * to benchmark CDN response times.
* @param array $urls A bunch of URLs to purge
* @param int $trials How many times to run the test?
* @return string
*/
- private function benchSquid( $urls, $trials = 1 ) {
+ private function benchCdn( $urls, $trials = 1 ) {
$start = microtime( true );
for ( $i = 0; $i < $trials; $i++ ) {
CdnCacheUpdate::purge( $urls );
}
}
- // Send batch of purge requests out to squids
- $squid = new CdnCacheUpdate( $urls, count( $urls ) );
- $squid->doUpdate();
+ // Send batch of purge requests out to CDN servers
+ $cdn = new CdnCacheUpdate( $urls, count( $urls ) );
+ $cdn->doUpdate();
if ( $this->hasOption( 'sleep-per-batch' ) ) {
// sleep-per-batch is milliseconds, usleep wants micro seconds.
<?php
/**
- * Send purge requests for listed pages to squid
+ * Send purge requests for listed pages to CDN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
require_once __DIR__ . '/Maintenance.php';
/**
- * Maintenance script that sends purge requests for listed pages to squid.
+ * Maintenance script that sends purge requests for listed pages to CDN.
*
* @ingroup Maintenance
*/
class PurgeList extends Maintenance {
public function __construct() {
parent::__construct();
- $this->addDescription( 'Send purge requests for listed pages to squid' );
+ $this->addDescription( 'Send purge requests for listed pages to CDN' );
$this->addOption( 'purge', 'Whether to update page_touched.', false, false );
$this->addOption( 'namespace', 'Namespace number', false, true );
$this->addOption( 'all', 'Purge all pages', false, false );
/**
* Helper to purge an array of $urls
- * @param array $urls List of URLS to purge from squids
+ * @param array $urls List of URLS to purge from CDNs
*/
private function sendPurgeRequest( $urls ) {
if ( $this->hasOption( 'delay' ) ) {
$response = $wgRequest->response();
$response->header( "Content-type: $ctype" );
-// Set an Expires header so that squid can cache it for a short time
+// Set an Expires header so that CDN can cache it for a short time
// Short enough so that the sysadmin barely notices when $wgSitename is changed
$expiryTime = 600; # 10 minutes
$response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expiryTime ) . ' GMT' );
function ( $op ) {
$op->getContext()->setUser( $this->getTestUser()->getUser() );
} ],
- 'After Squid expiry' =>
+ 'After CDN expiry' =>
[ $lastModified, $lastModified, false,
- [ 'UseSquid' => true, 'SquidMaxage' => 3599 ] ],
+ [ 'UseCdn' => true, 'CdnMaxAge' => 3599 ] ],
'Hook allows cache use' =>
[ $lastModified + 1, $lastModified, true, [],
function ( $op, $that ) {
}
public function provideAdaptCdnTTL() {
- global $wgSquidMaxage;
+ global $wgCdnMaxAge;
$now = time();
self::$fakeTime = $now;
return [
'Five minutes from now' => [ [ $now + 300 ], IExpiringStore::TTL_MINUTE ],
'Five minutes ago, initial maxage four minutes' =>
[ [ $now - 300 ], 270, [ 'initialMaxage' => 240 ] ],
- 'A very long time ago' => [ [ $now - 1000000000 ], $wgSquidMaxage ],
+ 'A very long time ago' => [ [ $now - 1000000000 ], $wgCdnMaxAge ],
'Initial maxage zero' => [ [ $now - 300 ], 270, [ 'initialMaxage' => 0 ] ],
'false' => [ [ false ], IExpiringStore::TTL_MINUTE ],
* @dataProvider provideGetIP
* @covers WebRequest::getIP
*/
- public function testGetIP( $expected, $input, $squid, $xffList, $private, $description ) {
+ public function testGetIP( $expected, $input, $cdn, $xffList, $private, $description ) {
$this->setServerVars( $input );
$this->setMwGlobals( [
'wgUsePrivateIPs' => $private,
]
] );
- $this->setService( 'ProxyLookup', new ProxyLookup( [], $squid ) );
+ $this->setService( 'ProxyLookup', new ProxyLookup( [], $cdn ) );
$request = new WebRequest();
$result = $request->getIP();
public function testGetIpLackOfRemoteAddrThrowAnException() {
// ensure that local install state doesn't interfere with test
$this->setMwGlobals( [
- 'wgSquidServersNoPurge' => [],
- 'wgSquidServers' => [],
+ 'wgCdnServers' => [],
+ 'wgCdnServersNoPurge' => [],
'wgUsePrivateIPs' => false,
'wgHooks' => [],
] );
* @param int $status Expected response status
* @param array $options Array of options:
* post => true Request is a POST
- * cdn => true CDN is enabled ($wgUseSquid)
+ * cdn => true CDN is enabled ($wgUseCdn)
*/
public function testCheckConditionalRequestHeaders(
$headers, $conditions, $status, $options = []
$priv->mInternalMode = false;
if ( !empty( $options['cdn'] ) ) {
- $this->setMwGlobals( 'wgUseSquid', true );
+ $this->setMwGlobals( 'wgUseCdn', true );
}
// Can't do this in TestSetup.php because Setup.php will override it
}
public static function provideCheckConditionalRequestHeaders() {
- global $wgSquidMaxage;
+ global $wgCdnMaxAge;
$now = time();
return [
[ [ 'If-Modified-Since' => 'a potato' ],
[ 'last-modified' => wfTimestamp( TS_MW, $now - 1 ) ], 200 ],
- // Anything before $wgSquidMaxage seconds ago should be considered
+ // Anything before $wgCdnMaxAge seconds ago should be considered
// expired.
'If-Modified-Since with CDN post-expiry' =>
- [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now - $wgSquidMaxage * 2 ) ],
- [ 'last-modified' => wfTimestamp( TS_MW, $now - $wgSquidMaxage * 3 ) ],
+ [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now - $wgCdnMaxAge * 2 ) ],
+ [ 'last-modified' => wfTimestamp( TS_MW, $now - $wgCdnMaxAge * 3 ) ],
200, [ 'cdn' => true ] ],
'If-Modified-Since with CDN pre-expiry' =>
- [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now - $wgSquidMaxage / 2 ) ],
- [ 'last-modified' => wfTimestamp( TS_MW, $now - $wgSquidMaxage * 3 ) ],
+ [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now - $wgCdnMaxAge / 2 ) ],
+ [ 'last-modified' => wfTimestamp( TS_MW, $now - $wgCdnMaxAge * 3 ) ],
304, [ 'cdn' => true ] ],
];
}
// For 404 handled thumbnails, we only use the base name of the URI
// for the thumb params and the parent directory for the source file name.
- // Check that the zone relative path matches up so squid caches won't pick
+ // Check that the zone relative path matches up so CDN caches won't pick
// up thumbs that would not be purged on source file deletion (T36231).
if ( $rel404 !== null ) { // thumbnail was handled via 404
if ( rawurldecode( $rel404 ) === $img->getThumbRel( $thumbName ) ) {