Tweak code style a little more: add more escaping and make the default value for...
[lhc/web/wiklou.git] / includes / SquidUpdate.php
index 700fc8e..f69d1f0 100644 (file)
@@ -1,10 +1,13 @@
 <?php
 /**
  * See deferred.txt
+ * @file
+ * @ingroup Cache
  */
 
 /**
- *
+ * @todo document
+ * @ingroup Cache
  */
 class SquidUpdate {
        var $urlArr, $mMaxTitles;
@@ -22,7 +25,7 @@ class SquidUpdate {
                $this->urlArr = $urlArr;
        }
 
-       /* static */ function newFromLinksTo( &$title ) {
+       static function newFromLinksTo( &$title ) {
                $fname = 'SquidUpdate::newFromLinksTo';
                wfProfileIn( $fname );
 
@@ -32,7 +35,7 @@ class SquidUpdate {
                        array( 'page_namespace', 'page_title' ),
                        array(
                                'pl_namespace' => $title->getNamespace(),
-                               'pl_title'     => $title->getDbKey(),
+                               'pl_title'     => $title->getDBkey(),
                                'pl_from=page_id' ),
                        $fname );
                $blurlArr = $title->getSquidURLs();
@@ -49,7 +52,7 @@ class SquidUpdate {
                return new SquidUpdate( $blurlArr );
        }
 
-       /* static */ function newFromTitles( &$titles, $urlArr = array() ) {
+       static function newFromTitles( &$titles, $urlArr = array() ) {
                global $wgMaxSquidPurgeTitles;
                if ( count( $titles ) > $wgMaxSquidPurgeTitles ) {
                        $titles = array_slice( $titles, 0, $wgMaxSquidPurgeTitles );
@@ -60,7 +63,7 @@ class SquidUpdate {
                return new SquidUpdate( $urlArr );
        }
 
-       /* static */ function newSimplePurge( &$title ) {
+       static function newSimplePurge( &$title ) {
                $urlArr = $title->getSquidURLs();
                return new SquidUpdate( $urlArr );
        }
@@ -74,7 +77,7 @@ class SquidUpdate {
        (example: $urlArr[] = 'http://my.host/something')
        XXX report broken Squids per mail or log */
 
-       /* static */ function purge( $urlArr ) {
+       static function purge( $urlArr ) {
                global $wgSquidServers, $wgHTCPMulticastAddress, $wgHTCPPort;
 
                /*if ( (@$wgSquidServers[0]) == 'echo' ) {
@@ -82,8 +85,13 @@ class SquidUpdate {
                        return;
                }*/
 
-               if ( $wgHTCPMulticastAddress && $wgHTCPPort )
-                       SquidUpdate::HTCPPurge( $urlArr );
+               if( empty( $urlArr ) ) {
+                       return;
+               }
+
+               if ( $wgHTCPMulticastAddress && $wgHTCPPort ) {
+                       return SquidUpdate::HTCPPurge( $urlArr );
+               }
 
                $fname = 'SquidUpdate::purge';
                wfProfileIn( $fname );
@@ -143,8 +151,9 @@ class SquidUpdate {
                                        /* open the remaining sockets for this server */
                                        list($server, $port) = explode(':', $wgSquidServers[$ss]);
                                        if(!isset($port)) $port = 80;
-                                       $sockets[$so+1] = @fsockopen($server, $port, $error, $errstr, 2);
-                                       @stream_set_blocking($sockets[$so+1],false);
+                                       $socket = @fsockopen($server, $port, $error, $errstr, 2);
+                                       @stream_set_blocking($socket,false);
+                                       $sockets[] = $socket;
                                }
                                $so++;
                        }
@@ -189,7 +198,7 @@ class SquidUpdate {
                wfProfileOut( $fname );
        }
 
-       /* static */ function HTCPPurge( $urlArr ) {
+       static function HTCPPurge( $urlArr ) {
                global $wgHTCPMulticastAddress, $wgHTCPMulticastTTL, $wgHTCPPort;
                $fname = 'SquidUpdate::HTCPPurge';
                wfProfileIn( $fname );
@@ -214,10 +223,10 @@ class SquidUpdate {
 
                        foreach ( $urlArr as $url ) {
                                if( !is_string( $url ) ) {
-                                       wfDebugDieBacktrace( 'Bad purge URL' );
+                                       throw new MWException( 'Bad purge URL' );
                                }
                                $url = SquidUpdate::expand( $url );
-                               
+
                                // Construct a minimal HTCP request diagram
                                // as per RFC 2756
                                // Opcode 'CLR', no response desired, no auth
@@ -255,7 +264,7 @@ 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-
@@ -277,4 +286,3 @@ class SquidUpdate {
                return $url;
        }
 }
-?>