r70896 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70895‎ | r70896 | r70897 >
Date:15:41, 11 August 2010
Author:daniel
Status:deferred
Tags:
Comment:
changed logging to use wfDebugLog; fixed config
Modified paths:
  • /trunk/extensions/XMLRC/XMLRC.class.php (modified) (history)
  • /trunk/extensions/XMLRC/XMLRC.php (modified) (history)
  • /trunk/extensions/XMLRC/XMLRC_File.class.php (modified) (history)
  • /trunk/extensions/XMLRC/XMLRC_UDP.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/XMLRC/XMLRC.class.php
@@ -20,7 +20,7 @@
2121 public static function RecentChange_save( $rc ) {
2222 global $wgXMLRCTransport, $wgXMLRCProperties;
2323
24 - if ( !empty( $GLOBALS['wgXMLRCTransport'] ) ) {
 24+ if ( $wgXMLRCTransport ) {
2525 $xmlrc = new XMLRC( $wgXMLRCTransport, $wgXMLRCProperties );
2626 $xmlrc->processRecentChange( $rc );
2727 }
@@ -71,7 +71,7 @@
7272 if ( !$prop ) $prop = "title|timestamp|ids"; //default taken from the API
7373
7474 if ( is_string( $prop ) ) {
75 - $prop = preg_split( '\\s*[,;/|+]\\s*', $prop );
 75+ $prop = preg_split( '!\\s*[,;/|+]\\s*!', $prop );
7676 }
7777
7878 foreach ( $prop as $k => $v ) {
@@ -106,12 +106,12 @@
107107 $row = $rc->getAttributes();
108108 $row = XMLRC::array2object( $row );
109109
110 - #wfDebug( "XMLRC: got attribute row: " . preg_replace('/\s+/', ' ', var_export($row, true)) . "\n" );
 110+ #wfDebugLog( "XMLRC", "got attribute row: " . preg_replace('/\s+/', ' ', var_export($row, true)) . "\n" );
111111
112112 $info = $query->extractRowInfo( $row );
113113 $info['wikiid'] = wfWikiID();
114114
115 - #wfDebug( "XMLRC: got info: " . preg_replace('/\s+/', ' ', var_export($info, true)) . "\n" );
 115+ #wfDebugLog( "XMLRC", "got info: " . preg_replace('/\s+/', ' ', var_export($info, true)) . "\n" );
116116
117117 $xml = $format->recXmlPrint( "rc", $info, "" );
118118 $xml = trim( $xml );
@@ -120,8 +120,7 @@
121121 }
122122
123123 public function sendRecentChangeXML( $xml ) {
124 - if ( !is_string( $xml ) ) wfDebugDieBacktrace( "XMLRC: parameter xml must be a string\n" );
125 - else wfDebug( "XMLRC: sending xml\n" );
 124+ wfDebugLog( "XMLRC", "sending xml\n" );
126125
127126 $transport = $this->getTransport();
128127 $transport->send( $xml );
Index: trunk/extensions/XMLRC/XMLRC_UDP.class.php
@@ -6,34 +6,35 @@
77
88 class XMLRC_UDP extends XMLRC_Transport {
99 function __construct( $config ) {
10 - $this->conn = null;
 10+ $this->socket = null;
1111
1212 $this->address = isset( $config['address'] ) ? $config['address'] : '127.0.0.1';
1313 $this->port = isset( $config['port'] ) ? $config['port'] : 4455;
1414 }
1515
1616 public function connect() {
17 - if ( $this->conn ) return;
 17+ if ( $this->socket ) return;
1818
19 - $this->conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
20 - if ( !$this->handle ) wfDebug("XMLRC_UDP: failed to create UDP socket\n");
21 - else wfDebug("XMLRC_UDP: created UDP socket\n");
 19+ $this->socket = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
 20+ if ( !$this->socket ) wfDebugLog("XMLRC", "failed to create UDP socket\n");
 21+ else wfDebugLog("XMLRC", "created UDP socket\n");
2222 }
2323
2424 public function disconnect() {
25 - if ( !$this->conn ) return;
 25+ if ( !$this->socket ) return;
2626
27 - socket_close( $this->conn );
28 - $this->conn = null;
29 - wfDebug("XMLRC_UDP: closed UDP socket\n");
 27+ socket_close( $this->socket );
 28+ $this->socket = null;
 29+ wfDebugLog("XMLRC", "closed UDP socket\n");
3030 }
3131
3232 public function send( $xml ) {
33 - $do_disconnect = !$this->conn;
 33+ $do_disconnect = !$this->socket;
3434 $this->connect();
3535
36 - $ok = socket_sendto( $this->conn, $xml, strlen($xml), 0, $this->address, $this->port );
37 - if ( !$ok ) wfDebug("XMLRC_UDP: failed to send UDP packet to {$this->address}:{$this->port}\n");
 36+ $ok = socket_sendto( $this->socket, $xml, strlen($xml), 0, $this->address, $this->port );
 37+ if ( $ok ) wfDebugLog("XMLRC", "sent UDP packet to {$this->address}:{$this->port}\n");
 38+ else wfDebugLog("XMLRC", "failed to send UDP packet to {$this->address}:{$this->port}\n");
3839
3940 if ( $do_disconnect ) $this->disconnect();
4041 }
Index: trunk/extensions/XMLRC/XMLRC.php
@@ -31,36 +31,12 @@
3232 # 'address' => '127.0.0.1',
3333 #);
3434
35 -$wgXMLRCProperties = 'user|comment|flags|timestamp|title|ids|sizes|redirect|loginfo'; # sensible default
 35+$wgXMLRCProperties = 'user|comment|flags|timestamp|title|ids|sizes|redirect|loginfo|tags'; # sensible default
3636 # $wgXMLRCProperties = 'title|timestamp|ids'; # default as per the API
3737 # $wgXMLRCProperties = 'user|comment|parsedcomment|flags|timestamp|title|ids|sizes|redirect|loginfo|tags'; # everything except "patrolled", which is verboten
3838
39 -/*
40 -$wgXMLRCTransport = array(
41 - 'class' => 'XMLRC_XMPP',
42 - 'channel' => 'recentchanges',
43 - 'nickname' => $wgSitename,
44 - 'host' => 'localhost',
45 - 'port' => 5222,
46 - 'user' => 'mediawiki',
47 - 'server' => 'localhost',
48 - 'resource' => 'recentchanges',
49 - 'password' => 'yourpassword',
50 - 'include_path' => './xmpphp',
51 -);
52 -*/
53 -
54 -/*
55 -$wgXMLRCTransport = array(
56 - 'class' => 'XMLRC_UDP',
57 - 'address' => 'localhost',
58 - 'port' => 12345,
59 -);
60 -*/
61 -
6239 $wgAutoloadClasses[ 'XMLRC' ] = "$dir/XMLRC.class.php";
6340 $wgAutoloadClasses[ 'XMLRC_Transport' ] = "$dir/XMLRC.class.php";
64 -$wgAutoloadClasses[ 'XMLRC_XMPP' ] = "$dir/XMLRC_XMPP.class.php";
6541 $wgAutoloadClasses[ 'XMLRC_UDP' ] = "$dir/XMLRC_UDP.class.php";
6642 $wgAutoloadClasses[ 'XMLRC_File' ] = "$dir/XMLRC_File.class.php";
6743
Index: trunk/extensions/XMLRC/XMLRC_File.class.php
@@ -15,8 +15,8 @@
1616 if ( $this->handle ) return;
1717
1818 $this->handle = fopen( $this->file, 'a' );
19 - if ( !$this->handle ) wfDebug("XMLRC_File: failed to open {$this->file}\n");
20 - else wfDebug("XMLRC_File: opened {$this->file}\n");
 19+ if ( !$this->handle ) wfDebugLog("XMLRC", "failed to open {$this->file}\n");
 20+ else wfDebugLog("XMLRC", "opened {$this->file}\n");
2121 }
2222
2323 public function close() {
@@ -25,7 +25,7 @@
2626 fclose( $this->handle );
2727 $this->handle = null;
2828
29 - wfDebug("XMLRC_File: closed {$this->file}\n");
 29+ wfDebugLog("XMLRC", "closed {$this->file}\n");
3030 }
3131
3232 public function send( $xml ) {
@@ -34,7 +34,7 @@
3535
3636 $ok = fwrite( $this->handle, $xml . "\n" );
3737 if ( $ok ) $ok = fflush( $this->handle );
38 - if ( !$ok ) wfDebug("XMLRC_File: failed to write to {$this->file}\n");
 38+ if ( !$ok ) wfDebugLog("XMLRC", "failed to write to {$this->file}\n");
3939
4040 if ( $do_close ) $this->close();
4141 }

Status & tagging log