r10948 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10947‎ | r10948 | r10949 >
Date:10:37, 8 September 2005
Author:vibber
Status:old
Tags:
Comment:
Initial blocker daemon interface; command-line tool and backend only, no hook.
Modified paths:
  • /trunk/extensions/MWBlocker (added) (history)
  • /trunk/extensions/MWBlocker/MWBlocker.php (added) (history)
  • /trunk/extensions/MWBlocker/blockerTool.php (added) (history)

Diff [purge]

Index: trunk/extensions/MWBlocker/blockerTool.php
@@ -0,0 +1,35 @@
 2+<?php
 3+
 4+require_once 'commandLine.inc';
 5+
 6+if( count( $argv ) == 0 ) {
 7+ echo "Available actions: status, check <ip>\n";
 8+ exit( 0 );
 9+}
 10+
 11+function errorOrValue( $val ) {
 12+ if( WikiError::isError( $val ) ) {
 13+ die( $val->toString() . "\n" );
 14+ }
 15+ return $val;
 16+}
 17+
 18+function showStatus() {
 19+ $ret = errorOrValue( MWBlocker::getStatus() );
 20+ echo $ret . "\n";
 21+}
 22+
 23+switch( $argv[0] ) {
 24+case "status":
 25+ showStatus();
 26+ break;
 27+case "check":
 28+ errorOrValue( MWBlocker::queueCheck( $argv[1], "command-line check" ) );
 29+ showStatus();
 30+ break;
 31+default:
 32+ echo "Unrecognized verb.\n";
 33+ exit( -1 );
 34+}
 35+
 36+?>
Property changes on: trunk/extensions/MWBlocker/blockerTool.php
___________________________________________________________________
Added: svn:keywords
137 + Author Date Id Revision
Added: svn:eol-style
238 + native
Index: trunk/extensions/MWBlocker/MWBlocker.php
@@ -0,0 +1,105 @@
 2+<?php
 3+
 4+// Requires PEAR XML_RPC module
 5+
 6+// todo: combine shared code from MWSearchUpdater into a base module
 7+
 8+require_once( 'PEAR.php' );
 9+require_once( 'XML/RPC.php' );
 10+
 11+$mwBlockerHost = 'localhost';
 12+$mwBlockerPort = 8126;
 13+$mwBlockerDebug = false;
 14+
 15+class MWBlocker {
 16+ /**
 17+ * Queue a request to update a page in the search index.
 18+ *
 19+ * @param string $dbname
 20+ * @param Title $title
 21+ * @param string $text
 22+ * @return bool
 23+ * @static
 24+ */
 25+ function queueCheck( $ip, $note ) {
 26+ return MWBlocker::sendRPC( 'blocker.queueCheck',
 27+ array( $ip, $note ) );
 28+ }
 29+
 30+ /**
 31+ * Get a brief bit of status info on the update daemon.
 32+ * @return string
 33+ * @static
 34+ */
 35+ function getStatus() {
 36+ return MWBlocker::sendRPC( 'blocker.getStatus' );
 37+ }
 38+
 39+ /**
 40+ * @access private
 41+ * @static
 42+ */
 43+ function outParam( $param ) {
 44+ if( is_object( $param ) && is_a( $param, 'Title' ) ) {
 45+ return new XML_RPC_Value(
 46+ array(
 47+ 'Namespace' => new XML_RPC_Value( $param->getNamespace(), 'int' ),
 48+ 'Text' => new XML_RPC_Value( $param->getText(), 'string' ) ),
 49+ 'struct' );
 50+ } elseif( is_string( $param ) ) {
 51+ return new XML_RPC_Value( $param, 'string' );
 52+ } elseif( is_array( $param ) ) {
 53+ $type = 'array';
 54+ if( count( $param ) ) {
 55+ $keys = array_keys( $param );
 56+ if( $keys[0] !== 0 ) {
 57+ $type = 'struct';
 58+ }
 59+ }
 60+ $translated = array_map( array( 'MWBlocker', 'outParam' ), $param );
 61+ return new XML_RPC_Value( $translated, $type );
 62+ } else {
 63+ return new WikiError( 'MWBlocker::sendRPC given bogus parameter' );
 64+ }
 65+ }
 66+
 67+ /**
 68+ * @access private
 69+ * @static
 70+ */
 71+ function sendRPC( $method, $params=array() ) {
 72+ global $mwBlockerHost, $mwBlockerPort, $mwBlockerDebug;
 73+ $client = new XML_RPC_Client( '/Blocker', $mwBlockerHost, $mwBlockerPort );
 74+ if( $mwBlockerDebug ) {
 75+ $client->debug = true;
 76+ }
 77+
 78+ $rpcParams = array_map( array( 'MWBlocker', 'outParam' ), $params );
 79+
 80+ $message = new XML_RPC_Message( $method, $rpcParams );
 81+ wfSuppressWarnings();
 82+ $start = wfTime();
 83+ $result = $client->send( $message );
 84+ $delta = wfTime() - $start;
 85+ wfRestoreWarnings();
 86+
 87+ $debug = sprintf( "MWBlocker::sendRPC for %s took %0.2fms\n",
 88+ $method, $delta * 1000.0 );
 89+ wfDebug( $debug );
 90+ if( $mwBlockerDebug ) {
 91+ echo $debug;
 92+ }
 93+
 94+ if( !is_object( $result ) ) {
 95+ return new WikiError( "Unknown XML-RPC error" );
 96+ } elseif( $result->faultCode() ) {
 97+ return new WikiError( $result->faultCode() . ': ' . $result->faultString() );
 98+ } else {
 99+ $value = $result->value();
 100+ return $value->getval();
 101+ }
 102+ }
 103+}
 104+
 105+
 106+?>
Property changes on: trunk/extensions/MWBlocker/MWBlocker.php
___________________________________________________________________
Added: svn:keywords
1107 + Author Date Id Revision
Added: svn:eol-style
2108 + native

Status & tagging log