* (bug 6074) Correct squid purging of offsite upload URLs
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 24 May 2006 21:57:25 +0000 (21:57 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 24 May 2006 21:57:25 +0000 (21:57 +0000)
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
includes/Image.php
includes/ImagePage.php
includes/SquidUpdate.php

index 2c526e6..3c54474 100644 (file)
@@ -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 ==
 
index 0904694..98ce5b5 100644 (file)
@@ -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 );
                }
index 840dc8e..d926481 100644 (file)
@@ -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
index dba47c5..7ccdf5b 100644 (file)
@@ -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;
+       }
 }
 ?>