From 95e391545a69a899f3b433211c07a15139c90e3a Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 24 May 2006 21:57:25 +0000 Subject: [PATCH] * (bug 6074) Correct squid purging of offsite upload URLs You can now feed both local relative URLs and fully-qualified URLs to the squid purge functions; local URLs will have $wgInternalServer prepended if needed. This avoids the broken URLs produced by other functions prepending it when it wasn't always needed. --- RELEASE-NOTES | 2 ++ includes/Image.php | 16 ++++++---------- includes/ImagePage.php | 6 +++--- includes/SquidUpdate.php | 28 ++++++++++++++++++++++++++-- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2c526e6521..3c544749d3 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -327,6 +327,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Add {{CURRENTTIMESTAMP}} magic word * (bug 6061) Improper escaping in some html forms * (bug 6065) Remove underscore when using NAMESPACE and TALKSPACE magics. +* (bug 6074) Correct squid purging of offsite upload URLs + == Compatibility == diff --git a/includes/Image.php b/includes/Image.php index 090469469a..98ce5b50b2 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -909,7 +909,7 @@ class Image * @private */ function renderThumb( $width, $useScript = true ) { - global $wgUseSquid, $wgInternalServer; + global $wgUseSquid; global $wgSVGMaxSize, $wgMaxImageArea, $wgThumbnailEpoch; $fname = 'Image::renderThumb'; @@ -1017,11 +1017,7 @@ class Image # This has to be done after the image is updated and present for all machines on NFS, # or else the old version might be stored into the squid again if ( $wgUseSquid ) { - if ( substr( $url, 0, 4 ) == 'http' ) { - $urlArr = array( $url ); - } else { - $urlArr = array( $wgInternalServer.$url ); - } + $urlArr = array( $url ); wfPurgeSquidServers($urlArr); } } @@ -1232,7 +1228,7 @@ class Image * Delete all previously generated thumbnails, refresh metadata in memcached and purge the squid */ function purgeCache( $archiveFiles = array(), $shared = false ) { - global $wgInternalServer, $wgUseSquid; + global $wgUseSquid; // Refresh metadata cache $this->purgeMetadataCache(); @@ -1243,16 +1239,16 @@ class Image $urls = array(); foreach ( $files as $file ) { if ( preg_match( '/^(\d+)px/', $file, $m ) ) { - $urls[] = $wgInternalServer . $this->thumbUrl( $m[1], $this->fromSharedDirectory ); + $urls[] = $this->thumbUrl( $m[1], $this->fromSharedDirectory ); @unlink( "$dir/$file" ); } } // Purge the squid if ( $wgUseSquid ) { - $urls[] = $wgInternalServer . $this->getViewURL(); + $urls[] = $this->getViewURL(); foreach ( $archiveFiles as $file ) { - $urls[] = $wgInternalServer . wfImageArchiveUrl( $file ); + $urls[] = wfImageArchiveUrl( $file ); } wfPurgeSquidServers( $urls ); } diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 840dc8e807..d92648138c 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -480,7 +480,7 @@ END } function doDelete() { - global $wgOut, $wgRequest, $wgUseSquid, $wgInternalServer; + global $wgOut, $wgRequest, $wgUseSquid; global $wgPostCommitUpdateList; $fname = 'ImagePage::doDelete'; @@ -506,7 +506,7 @@ END # Squid purging if ( $wgUseSquid ) { $urlArr = array( - $wgInternalServer.wfImageArchiveUrl( $oldimage ), + wfImageArchiveUrl( $oldimage ), $this->mTitle->getInternalURL() ); wfPurgeSquidServers($urlArr); @@ -542,7 +542,7 @@ END $urlArr = Array(); while ( $s = $dbw->fetchObject( $res ) ) { $this->doDeleteOldImage( $s->oi_archive_name ); - $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name ); + $urlArr[] = wfImageArchiveUrl( $s->oi_archive_name ); } # And also the HTML of all pages using this image diff --git a/includes/SquidUpdate.php b/includes/SquidUpdate.php index dba47c563d..7ccdf5bc61 100644 --- a/includes/SquidUpdate.php +++ b/includes/SquidUpdate.php @@ -90,7 +90,7 @@ class SquidUpdate { $maxsocketspersquid = 8; // socket cap per Squid $urlspersocket = 400; // 400 seems to be a good tradeoff, opening a socket takes a while - $firsturl = $urlArr[0]; + $firsturl = SquidUpdate::expand( $urlArr[0] ); unset($urlArr[0]); $urlArr = array_values($urlArr); $sockspersq = max(ceil(count($urlArr) / $urlspersocket ),1); @@ -164,7 +164,8 @@ class SquidUpdate { } } $urindex = $r + $urlspersocket * ($s - $sockspersq * floor($s / $sockspersq)); - $msg = 'PURGE ' . $urlArr[$urindex] . " HTTP/1.0\r\n". + $url = SquidUpdate::expand( $urlArr[$urindex] ); + $msg = 'PURGE ' . $url . " HTTP/1.0\r\n". "Connection: Keep-Alive\r\n\r\n"; #$this->debug($msg); @fputs($sockets[$s],$msg); @@ -210,6 +211,8 @@ class SquidUpdate { $wgHTCPMulticastTTL ); foreach ( $urlArr as $url ) { + $url = SquidUpdate::expand( $url ); + // Construct a minimal HTCP request diagram // as per RFC 2756 // Opcode 'CLR', no response desired, no auth @@ -247,5 +250,26 @@ class SquidUpdate { wfDebug( $text ); } } + + /** + * Expand local URLs to fully-qualified URLs using the internal protocol + * and host defined in $wgInternalServer. Input that's already fully- + * qualified will be passed through unchanged. + * + * This is used to generate purge URLs that may be either local to the + * main wiki or include a non-native host, such as images hosted on a + * second internal server. + * + * Client functions should not need to call this. + * + * @return string + */ + static function expand( $url ) { + global $wgInternalServer; + if( $url != '' && $url{0} == '/' ) { + return $wgInternalServer . $url; + } + return $url; + } } ?> -- 2.20.1