r45610 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45609‎ | r45610 | r45611 >
Date:18:30, 9 January 2009
Author:aaron
Status:resolved (Comments)
Tags:
Comment:
Revert r45605 and generalize the ability to have logs go to UDP.
Modified paths:
  • /trunk/phase3/includes/LogPage.php (modified) (history)
  • /trunk/phase3/includes/PatrolLog.php (modified) (history)
  • /trunk/phase3/includes/RecentChange.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/RecentChange.php
@@ -476,6 +476,14 @@
477477 public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip='',
478478 $type, $action, $target, $logComment, $params, $newId=0 )
479479 {
 480+ $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
 481+ $target, $logComment, $params, $newId );
 482+ $rc->save();
 483+ }
 484+
 485+ public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip='',
 486+ $type, $action, $target, $logComment, $params, $newId=0 )
 487+ {
480488 global $wgRequest;
481489
482490 if( !$ip ) {
@@ -518,7 +526,7 @@
519527 'lastTimestamp' => 0,
520528 'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
521529 );
522 - $rc->save();
 530+ return $rc;
523531 }
524532
525533 # Initialises the members of this object from a mysql row object
Index: trunk/phase3/includes/PatrolLog.php
@@ -23,14 +23,8 @@
2424 $title = Title::makeTitleSafe( $rc->getAttribute( 'rc_namespace' ), $rc->getAttribute( 'rc_title' ) );
2525 if( is_object( $title ) ) {
2626 $params = self::buildParams( $rc, $auto );
27 - $log = new LogPage( 'patrol', false ); # False suppresses RC entries
 27+ $log = new LogPage( 'patrol', false, true ); # False suppresses RC entries
2828 $log->addEntry( 'patrol', $title, '', $params );
29 - # Notify external application via UDP.
30 - # We send this to IRC but do not want to add it the RC table.
31 - global $wgRC2UDPAddress, $wgRC2UDPOmitBots;
32 - if( $wgRC2UDPAddress && ( !$rc->getAttribute('rc_bot') || !$wgRC2UDPOmitBots ) ) {
33 - RecentChange::sendToUDP( $rc->getIRCLine() );
34 - }
3529 return true;
3630 }
3731 return false;
Index: trunk/phase3/includes/LogPage.php
@@ -37,7 +37,7 @@
3838 /* @access private */
3939 var $type, $action, $comment, $params, $target, $doer;
4040 /* @acess public */
41 - var $updateRecentChanges;
 41+ var $updateRecentChanges, $sendToUDP;
4242
4343 /**
4444 * Constructor
@@ -45,10 +45,12 @@
4646 * @param string $type One of '', 'block', 'protect', 'rights', 'delete',
4747 * 'upload', 'move'
4848 * @param bool $rc Whether to update recent changes as well as the logging table
 49+ * @param bool $udp Whether to send to the UDP feed
4950 */
50 - function __construct( $type, $rc = true ) {
 51+ function __construct( $type, $rc = true, $udp = true ) {
5152 $this->type = $type;
5253 $this->updateRecentChanges = $rc;
 54+ $this->sendToUDP = $udp;
5355 }
5456
5557 protected function saveContent() {
@@ -85,6 +87,17 @@
8688 RecentChange::notifyLog( $now, $titleObj, $this->doer, $rcComment, '',
8789 $this->type, $this->action, $this->target, $this->comment, $this->params, $newId );
8890 }
 91+ } else if( $this->sendToUDP ) {
 92+ # Notify external application via UDP.
 93+ # We send this to IRC but do not want to add it the RC table.
 94+ global $wgRC2UDPAddress, $wgRC2UDPOmitBots;
 95+ $titleObj = SpecialPage::getTitleFor( 'Log', $this->type );
 96+ $rcComment = $this->getRcComment();
 97+ $rc = RecentChange::newLogEntry( $now, $titleObj, $this->doer, $rcComment, '',
 98+ $this->type, $this->action, $this->target, $this->comment, $this->params, $newId );
 99+ if( $wgRC2UDPAddress && ( !$rc->getAttribute('rc_bot') || !$wgRC2UDPOmitBots ) ) {
 100+ RecentChange::sendToUDP( $rc->getIRCLine() );
 101+ }
89102 }
90103 return true;
91104 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r45605Send manual patrols to IRC (bug 16604)aaron17:57, 9 January 2009

Comments

#Comment by Brion VIBBER (talk | contribs)   00:54, 14 January 2009
+	function __construct( $type, $rc = true, $udp = true ) {

I don't really like adding more boolean parameters; it's totall unobvious what it means when one calls:

+			$log = new LogPage( 'patrol', false, true ); # False suppresses RC entries


+			global $wgRC2UDPAddress, $wgRC2UDPOmitBots;
+			if( $wgRC2UDPAddress && ( !$rc->getAttribute('rc_bot') || !$wgRC2UDPOmitBots ) ) {
+				RecentChange::sendToUDP( $rc->getIRCLine() );
+			}

That bit looks to me like it needs to be encapsulated in a method; the whole bit otherwise is gonna get repeated everyplace that wants to spit out some stuff.

#Comment by Aaron Schulz (talk | contribs)   14:01, 16 January 2009

Tweaked in r45762

Status & tagging log