Merge "Add support for FormData in mw.Api.upload"
[lhc/web/wiklou.git] / includes / SquidPurgeClient.php
index 0997a7a..ca8f11a 100644 (file)
  * Could be replaced by curl_multi_exec() or some such.
  */
 class SquidPurgeClient {
-       var $host, $port, $ip;
+       /** @var string */
+       protected $host;
 
-       var $readState = 'idle';
-       var $writeBuffer = '';
-       var $requests = array();
-       var $currentRequestIndex;
+       /** @var int */
+       protected $port;
+
+       /** @var string|bool */
+       protected $ip;
+
+       /** @var string */
+       protected $readState = 'idle';
+
+       /** @var string */
+       protected $writeBuffer = '';
+
+       /** @var array */
+       protected $requests = array();
+
+       /** @var mixed */
+       protected $currentRequestIndex;
 
        const EINTR = 4;
        const EAGAIN = 11;
@@ -41,13 +55,16 @@ class SquidPurgeClient {
        const BUFFER_SIZE = 8192;
 
        /**
-        * The socket resource, or null for unconnected, or false for disabled due to error
+        * @var resource|null The socket resource, or null for unconnected, or false
+        *   for disabled due to error.
         */
-       var $socket;
+       protected $socket;
 
-       var $readBuffer;
+       /** @var string */
+       protected $readBuffer;
 
-       var $bodyRemaining;
+       /** @var int */
+       protected $bodyRemaining;
 
        /**
         * @param string $server
@@ -78,9 +95,9 @@ class SquidPurgeClient {
                }
                $this->socket = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
                socket_set_nonblock( $this->socket );
-               wfSuppressWarnings();
+               MediaWiki\suppressWarnings();
                $ok = socket_connect( $this->socket, $ip, $this->port );
-               wfRestoreWarnings();
+               MediaWiki\restoreWarnings();
                if ( !$ok ) {
                        $error = socket_last_error( $this->socket );
                        if ( $error !== self::EINPROGRESS ) {
@@ -126,6 +143,7 @@ class SquidPurgeClient {
        /**
         * Get the host's IP address.
         * Does not support IPv6 at present due to the lack of a convenient interface in PHP.
+        * @throws MWException
         * @return string
         */
        protected function getIP() {
@@ -135,12 +153,12 @@ class SquidPurgeClient {
                        } elseif ( IP::isIPv6( $this->host ) ) {
                                throw new MWException( '$wgSquidServers does not support IPv6' );
                        } else {
-                               wfSuppressWarnings();
+                               MediaWiki\suppressWarnings();
                                $this->ip = gethostbyname( $this->host );
                                if ( $this->ip === $this->host ) {
                                        $this->ip = false;
                                }
-                               wfRestoreWarnings();
+                               MediaWiki\restoreWarnings();
                        }
                }
                return $this->ip;
@@ -160,11 +178,11 @@ class SquidPurgeClient {
         */
        public function close() {
                if ( $this->socket ) {
-                       wfSuppressWarnings();
+                       MediaWiki\suppressWarnings();
                        socket_set_block( $this->socket );
                        socket_shutdown( $this->socket );
                        socket_close( $this->socket );
-                       wfRestoreWarnings();
+                       MediaWiki\restoreWarnings();
                }
                $this->socket = null;
                $this->readBuffer = '';
@@ -234,9 +252,9 @@ class SquidPurgeClient {
                        $buf = substr( $this->writeBuffer, 0, self::BUFFER_SIZE );
                        $flags = 0;
                }
-               wfSuppressWarnings();
+               MediaWiki\suppressWarnings();
                $bytesSent = socket_send( $socket, $buf, strlen( $buf ), $flags );
-               wfRestoreWarnings();
+               MediaWiki\restoreWarnings();
 
                if ( $bytesSent === false ) {
                        $error = socket_last_error( $socket );
@@ -260,9 +278,9 @@ class SquidPurgeClient {
                }
 
                $buf = '';
-               wfSuppressWarnings();
+               MediaWiki\suppressWarnings();
                $bytesRead = socket_recv( $socket, $buf, self::BUFFER_SIZE, 0 );
-               wfRestoreWarnings();
+               MediaWiki\restoreWarnings();
                if ( $bytesRead === false ) {
                        $error = socket_last_error( $socket );
                        if ( $error != self::EAGAIN && $error != self::EINTR ) {
@@ -325,7 +343,6 @@ class SquidPurgeClient {
 
        /**
         * @param string $line
-        * @return
         */
        protected function processStatusLine( $line ) {
                if ( !preg_match( '!^HTTP/(\d+)\.(\d+) (\d{3}) (.*)$!', $line, $m ) ) {
@@ -379,12 +396,11 @@ class SquidPurgeClient {
 }
 
 class SquidPurgeClientPool {
+       /** @var array Array of SquidPurgeClient */
+       protected $clients = array();
 
-       /**
-        * @var array of SquidPurgeClient
-        */
-       var $clients = array();
-       var $timeout = 5;
+       /** @var int */
+       protected $timeout = 5;
 
        /**
         * @param array $options
@@ -426,9 +442,9 @@ class SquidPurgeClientPool {
                        }
                        $exceptSockets = null;
                        $timeout = min( $startTime + $this->timeout - microtime( true ), 1 );
-                       wfSuppressWarnings();
+                       MediaWiki\suppressWarnings();
                        $numReady = socket_select( $readSockets, $writeSockets, $exceptSockets, $timeout );
-                       wfRestoreWarnings();
+                       MediaWiki\restoreWarnings();
                        if ( $numReady === false ) {
                                wfDebugLog( 'squid', __METHOD__ . ': Error in stream_select: ' .
                                        socket_strerror( socket_last_error() ) . "\n" );