<?php
-# See deferred.doc
-
+/**
+ * See deferred.txt
+ * @package MediaWiki
+ */
+
+/**
+ *
+ * @package MediaWiki
+ */
class SquidUpdate {
var $urlArr, $mMaxTitles;
$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 ) ;
+ $page = $dbr->tableName( 'page' );
+
+ $res = $dbr->select( array( 'links', 'page' ),
+ array( 'page_namespace', 'page_title' ),
+ array(
+ 'pl_namespace' => $title->getNamespace(),
+ 'pl_title' => $title->getDbKey(),
+ 'pl_from=page_id' ),
+ $fname );
$blurlArr = $title->getSquidURLs();
if ( $dbr->numRows( $res ) <= $this->mMaxTitles ) {
while ( $BL = $dbr->fetchObject ( $res ) )
{
- $tobj = Title::makeTitle( $BL->cur_namespace, $BL->cur_title ) ;
+ $tobj = Title::makeTitle( $BL->page_namespace, $BL->page_title ) ;
$blurlArr[] = $tobj->getInternalURL();
}
}
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
- $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 ( $dbr->numRows( $res ) <= $this->mMaxTitles ) {
- while ( $BL = $dbr->fetchObject( $res ) )
- {
- $tobj = Title::makeTitle( $BL->cur_namespace, $BL->cur_title );
- $blurlArr[] = $tobj->getInternalURL();
- }
+ /* static */ function newFromTitles( &$titles, $urlArr = array() ) {
+ foreach ( $titles as $title ) {
+ $urlArr[] = $title->getInternalURL();
}
- $dbr->freeResult( $res );
- wfProfileOut( $fname );
- return new SquidUpdate( $blurlArr );
+ return new SquidUpdate( $urlArr );
}
/* static */ function newSimplePurge( &$title ) {
XXX report broken Squids per mail or log */
/* static */ function purge( $urlArr ) {
- global $wgSquidServers;
+ global $wgSquidServers, $wgHTCPMulticastAddress, $wgHTCPPort;
if ( $wgSquidServers == 'echo' ) {
- echo implode("<br>\n", $urlArr);
+ echo implode("<br />\n", $urlArr);
return;
}
+ if ( $wgHTCPMulticastAddress && $wgHTCPPort )
+ SquidUpdate::HTCPPurge( $urlArr );
+
$fname = 'SquidUpdate::purge';
wfProfileIn( $fname );
wfProfileOut( $fname );
}
+ /* static */ function HTCPPurge( $urlArr ) {
+ global $wgHTCPMulticastAddress, $wgHTCPMulticastTTL, $wgHTCPPort;
+ $fname = 'SquidUpdate::HTCPPurge';
+ wfProfileIn( $fname );
+
+ $htcpOpCLR = 4; // HTCP CLR
+
+ // FIXME PHP doesn't support these socket constants (include/linux/in.h)
+ define( "IPPROTO_IP", 0 );
+ define( "IP_MULTICAST_LOOP", 34 );
+ define( "IP_MULTICAST_TTL", 33 );
+
+ // pfsockopen doesn't work because we need set_sock_opt
+ $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
+ if ( $conn ) {
+ // Set socket options
+ socket_set_option( $conn, IPPROTO_IP, IP_MULTICAST_LOOP, 0 );
+ if ( $wgHTCPMulticastTTL != 1 )
+ socket_set_option( $conn, IPPROTO_IP, IP_MULTICAST_TTL,
+ $wgHTCPMulticastTTL );
+
+ foreach ( $urlArr as $url ) {
+ // Construct a minimal HTCP request diagram
+ // as per RFC 2756
+ // Opcode 'CLR', no response desired, no auth
+ $htcpTransID = rand();
+
+ $htcpSpecifier = pack( 'na4na*na8n',
+ 4, 'NONE', strlen( $url ), $url,
+ 8, 'HTTP/1.0', 0 );
+
+ $htcpDataLen = 8 + 2 + strlen( $htcpSpecifier );
+ $htcpLen = 4 + $htcpDataLen + 2;
+
+ // Note! Squid gets the bit order of the first
+ // word wrong, wrt the RFC. Apparently no other
+ // implementation exists, so adapt to Squid
+ $htcpPacket = pack( 'nxxnCxNxxa*n',
+ $htcpLen, $htcpDataLen, $htcpOpCLR,
+ $htcpTransID, $htcpSpecifier, 2);
+
+ // Send out
+ wfDebug( "Purging URL $url via HTCP\n" );
+ socket_sendto( $conn, $htcpPacket, $htcpLen, 0,
+ $wgHTCPMulticastAddress, $wgHTCPPort );
+ }
+ } else {
+ $errstr = socket_strerror( socket_last_error() );
+ wfDebug( "SquidUpdate::HTCPPurge(): Error opening UDP socket: $errstr\n" );
+ }
+ wfProfileOut( $fname );
+ }
+
function debug( $text ) {
global $wgDebugSquid;
if ( $wgDebugSquid ) {