Tell regexp parser to use extra analysis on external link regexp;
[lhc/web/wiklou.git] / includes / SquidUpdate.php
index 7d5a3ef..d35ffb3 100644 (file)
@@ -1,6 +1,13 @@
 <?php
-# See deferred.doc
+/**
+ * See deferred.doc
+ * @package MediaWiki
+ */
 
+/**
+ *
+ * @package MediaWiki
+ */
 class SquidUpdate {
        var $urlArr, $mMaxTitles;
 
@@ -18,36 +25,54 @@ class SquidUpdate {
        }
 
        /* static */ function newFromLinksTo( &$title ) {
+               $fname = 'SquidUpdate::newFromLinksTo';
+               wfProfileIn( $fname );
+
                # Get a list of URLs linking to this page
                $id = $title->getArticleID();
-               $sql = "SELECT cur_namespace,cur_title FROM links,cur WHERE l_to={$id} and l_from=cur_id" ;
-               $res = wfQuery ( $sql, DB_READ ) ;
+
+               $dbr =& wfGetDB( DB_SLAVE );
+               $links = $dbr->tableName( 'links' );
+               $cur = $dbr->tableName( 'cur' );
+
+               $sql = "SELECT cur_namespace,cur_title FROM $links,$cur WHERE l_to={$id} and l_from=cur_id" ;
+               $res = $dbr->query( $sql, $fname ) ;
                $blurlArr = $title->getSquidURLs();
-               if ( wfNumRows( $res ) <= $this->mMaxTitles ) {
-                       while ( $BL = wfFetchObject ( $res ) )
+               if ( $dbr->numRows( $res ) <= $this->mMaxTitles ) {
+                       while ( $BL = $dbr->fetchObject ( $res ) )
                        {
                                $tobj = Title::makeTitle( $BL->cur_namespace, $BL->cur_title ) ; 
                                $blurlArr[] = $tobj->getInternalURL();
                        }
                }
-               wfFreeResult ( $res ) ;
+               $dbr->freeResult ( $res ) ;
+
+               wfProfileOut( $fname );
                return new SquidUpdate( $blurlArr );
        }
 
        /* static */ function newFromBrokenLinksTo( &$title ) {
+               $fname = 'SquidUpdate::newFromBrokenLinksTo';
+               wfProfileIn( $fname );
+
                # Get a list of URLs linking to this (currently non-existent) page
-               $encTitle = $title->getPrefixedDBkey();
-               $sql = "SELECT cur_namespace,cur_title FROM brokenlinks,cur WHERE bl_to={$encTitle} AND bl_from=cur_id";
-               $res = wfQuery( $sql, DB_READ );
+               $dbr =& wfGetDB( DB_SLAVE );
+               $brokenlinks = $dbr->tableName( 'brokenlinks' );
+               $cur = $dbr->tableName( 'cur' );
+               $encTitle = $dbr->addQuotes( $title->getPrefixedDBkey() );
+
+               $sql = "SELECT cur_namespace,cur_title FROM $brokenlinks,$cur WHERE bl_to={$encTitle} AND bl_from=cur_id";
+               $res = $dbr->query( $sql, $fname );
                $blurlArr = array();
-               if ( wfNumRows( $res ) <= $this->mMaxTitles ) {
-                       while ( $BL = wfFetchObject( $res ) )
+               if ( $dbr->numRows( $res ) <= $this->mMaxTitles ) {
+                       while ( $BL = $dbr->fetchObject( $res ) )
                        {
                                $tobj = Title::makeTitle( $BL->cur_namespace, $BL->cur_title );
                                $blurlArr[] = $tobj->getInternalURL();
                        }
                }
-               wfFreeResult( $res );
+               $dbr->freeResult( $res );
+               wfProfileOut( $fname );
                return new SquidUpdate( $blurlArr );
        }
 
@@ -68,11 +93,14 @@ class SquidUpdate {
        /* static */ function purge( $urlArr ) {
                global  $wgSquidServers;
 
-               if ( $wgSquidServers == "echo" ) {
+               if ( $wgSquidServers == 'echo' ) {
                        echo implode("<br>\n", $urlArr);
                        return;
                }
 
+               $fname = 'SquidUpdate::purge';
+               wfProfileIn( $fname );
+               
                $maxsocketspersquid = 8; //  socket cap per Squid
                $urlspersocket = 400; // 400 seems to be a good tradeoff, opening a socket takes a while
                $firsturl = $urlArr[0];
@@ -98,20 +126,20 @@ class SquidUpdate {
                                        /* first socket for this server, do the tests */
                                        @list($server, $port) = explode(':', $wgSquidServers[$ss]);
                                        if(!isset($port)) $port = 80;
-                                       $this->debug("Opening socket to $server:$port");
+                                       #$this->debug("Opening socket to $server:$port");
                                        $socket = @fsockopen($server, $port, $error, $errstr, 3);
-                                       $this->debug("\n");
+                                       #$this->debug("\n");
                                        if (!$socket) {
                                                $failed = true;
                                                $totalsockets -= $sockspersq;
                                        } else {
-                                               $msg ="PURGE " . $firsturl . " HTTP/1.0\r\n".
+                                               $msg = 'PURGE ' . $firsturl . " HTTP/1.0\r\n".
                                                "Connection: Keep-Alive\r\n\r\n";
-                                               $this->debug($msg);
+                                               #$this->debug($msg);
                                                @fputs($socket,$msg);
-                                               $this->debug("...");
+                                               #$this->debug("...");
                                                $res = @fread($socket,512);
-                                               $this->debug("\n");
+                                               #$this->debug("\n");
                                                /* Squid only returns http headers with 200 or 404 status, 
                                                if there's more returned something's wrong */
                                                if (strlen($res) > 250) {
@@ -148,15 +176,15 @@ class SquidUpdate {
                                                }
                                        }
                                        $urindex = $r + $urlspersocket * ($s - $sockspersq * floor($s / $sockspersq));
-                                       $msg = "PURGE " . $urlArr[$urindex] . " HTTP/1.0\r\n".
+                                       $msg = 'PURGE ' . $urlArr[$urindex] . " HTTP/1.0\r\n".
                                        "Connection: Keep-Alive\r\n\r\n";
-                                       $this->debug($msg);
+                                       #$this->debug($msg);
                                        @fputs($sockets[$s],$msg);
-                                       $this->debug("\n");
+                                       #$this->debug("\n");
                                }
                        }
                }
-               $this->debug("Reading response...");
+               #$this->debug("Reading response...");
                foreach ($sockets as $socket) {
                        $res = '';
                        $esc = 0;
@@ -168,7 +196,8 @@ class SquidUpdate {
 
                        @fclose($socket);
                }
-               $this->debug("\n");
+               #$this->debug("\n");
+               wfProfileOut( $fname );
        }
 
        function debug( $text ) {