MediaWiki r9775 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r9774‎ | r9775 (on ViewVC)‎ | r9776 >
Date:07:01, 29 June 2005
Author:vibber
Status:old
Tags:
Comment:
* Copy IRC-over-UDP update option from REL1_4
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/Article.php
===================================================================
--- trunk/phase3/includes/Article.php	(revision 9774)
+++ trunk/phase3/includes/Article.php	(revision 9775)
@@ -938,7 +938,8 @@
 
 		Article::onArticleCreate( $this->mTitle );
 		if(!$suppressRC) {
-			RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary );
+			RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary, 'default', 
+			  '', strlen( $text ) );
 		}
 
 		if ($watchthis) {
@@ -1088,6 +1089,8 @@
 		}
 
 		$oldtext = $this->getContent( true );
+		$oldsize = strlen( $oldtext );
+		$newsize = strlen( $text );
 		$lastRevision = 0;
 
 		if ( 0 != strcmp( $text, $oldtext ) ) {
@@ -1117,7 +1120,7 @@
 				# Update recentchanges and purge cache and whatnot
 				$bot = (int)($wgUser->isBot() || $forceBot);
 				RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $wgUser, $summary,
-					$lastRevision, $this->getTimestamp(), $bot );
+					$lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize );
 				Article::onArticleEdit( $this->mTitle );
 			}
 		}
Index: trunk/phase3/includes/RecentChange.php
===================================================================
--- trunk/phase3/includes/RecentChange.php	(revision 9774)
+++ trunk/phase3/includes/RecentChange.php	(revision 9775)
@@ -16,7 +16,7 @@
 
 /**
  * Utility class for creating new RC entries
- * mAttributes:
+ * mAttribs:
  * 	rc_id           id of the row in the recentchanges table
  * 	rc_timestamp    time the entry was made
  * 	rc_cur_time     timestamp on the cur row
@@ -39,6 +39,8 @@
  * 	prefixedDBkey   prefixed db key, used by external app via msg queue
  * 	lastTimestamp   timestamp of previous entry, used in WHERE clause during update
  * 	lang            the interwiki prefix, automatically set in save()
+ *  oldSize         text size before the change
+ *  newSize         text size after the change
  * 
  * temporary:		not stored in the database
  *      notificationtimestamp
@@ -102,7 +104,7 @@
 	# Writes the data in this object to the database
 	function save()
 	{
-		global $wgUseRCQueue, $wgRCQueueID, $wgLocalInterwiki, $wgPutIPinRC;
+		global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, $wgRC2UDPPort, $wgRC2UDPPrefix;
 		$fname = 'RecentChange::save';
 
 		$dbw =& wfGetDB( DB_MASTER );
@@ -153,13 +155,13 @@
 				array( 'rc_cur_id' => $curId ), $fname );
 		}
 
-		# Notify external application
-		if ( $wgUseRCQueue ) {
-			$queue = msg_get_queue( $wgRCQueueID );
-			if (!msg_send( $queue, array_merge( $this->mAttribs, 1, $this->mExtra ),
-				true, false, $error ))
-			{
-				wfDebug( "Error sending message to RC queue, code $error\n" );
+		# Notify external application via UDP
+		if ( $wgRC2UDPAddress ) {
+			$conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
+			if ( $conn ) {
+				$line = $wgRC2UDPPrefix . $this->getIRCLine();
+				socket_sendto( $conn, $line, strlen($line), 0, $wgRC2UDPAddress, $wgRC2UDPPort );
+				socket_close( $conn );
 			}
 		}
 	}
@@ -182,7 +184,7 @@
 
 	# Makes an entry in the database corresponding to an edit
 	/*static*/ function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
-		$oldId, $lastTimestamp, $bot = "default", $ip = '' )
+		$oldId, $lastTimestamp, $bot = "default", $ip = '', $oldSize = 0, $newSize = 0 )
 	{
 		if ( $bot == 'default ' ) {
 			$bot = $user->isBot();
@@ -217,14 +219,17 @@
 
 		$rc->mExtra =  array(
 			'prefixedDBkey'	=> $title->getPrefixedDBkey(),
-			'lastTimestamp' => $lastTimestamp
+			'lastTimestamp' => $lastTimestamp,
+			'oldSize'       => $oldSize,
+			'newSize'       => $newSize,
 		);
 		$rc->save();
 	}
 
 	# Makes an entry in the database corresponding to page creation
 	# Note: the title object must be loaded with the new id using resetArticleID()
-	/*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default", $ip='' )
+	/*static*/ function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot = "default", 
+	  $ip='', $size = 0 )
 	{
 		if ( !$ip ) {
 			global $wgIP;
@@ -258,7 +263,9 @@
 
 		$rc->mExtra =  array(
 			'prefixedDBkey'	=> $title->getPrefixedDBkey(),
-			'lastTimestamp' => 0
+			'lastTimestamp' => 0,
+			'oldSize' => 0,
+			'newSize' => $size
 		);
 		$rc->save();
 	}
@@ -399,5 +406,45 @@
 		}
 		return $trail;
 	}
+
+	function getIRCLine() {
+		extract($this->mAttribs);
+		extract($this->mExtra);
+
+		$titleObj =& $this->getTitle();
+		
+		$bad = array("\n", "\r");
+		$empty = array("", "");	
+		$title = $titleObj->getPrefixedText();
+		$title = str_replace($bad, $empty, $title);
+		
+		if ( $rc_new ) {
+			$url = $titleObj->getFullURL();
+		} else {
+			$url = $titleObj->getFullURL("diff=0&oldid=$rc_last_oldid");
+		}
+
+		if ( isset( $oldSize ) && isset( $newSize ) ) {
+			$szdiff = $newSize - $oldSize;
+			if ($szdiff < -500)
+				$szdiff = "\002$szdiff\002";
+			else if ($szdiff >= 0)
+				$szdiff = "+$szdiff";
+			$szdiff = "($szdiff)";
+		} else {
+			$szdiff = '';
+		}
+
+		$comment = str_replace($bad, $empty, $rc_comment);
+		$user = str_replace($bad, $empty, $rc_user_text);
+		$flag = ($rc_minor ? "M" : "") . ($rc_new ? "N" : "");
+		# see http://www.irssi.org/?page=docs&doc=formats for some colour codes. prefix is \003, 
+		# no colour (\003) switches back to the term default
+		$comment = preg_replace("/\/\* (.*) \*\/(.*)/", "\00315\$1\003 - \00310\$2\003", $comment);
+		$fullString = "\00314[[\00307$title\00314]]\0034 $flag\00310 " .
+		              "\00302$url\003 \0035*\003 \00303$user\003 \0035*\003 $szdiff \00310$comment\003\n";
+
+		return $fullString;
+	}
 }
 ?>
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 9774)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 9775)
@@ -1086,6 +1086,11 @@
 $wgRCMaxAge = 7 * 24 * 3600;
 
 
+# Send RC updates via UDP
+$wgRC2UDPAddress = false;
+$wgRC2UDPPort = false;
+$wgRC2UDPPrefix = '';
+
 #
 # Copyright and credits settings
 #
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 9774)
+++ trunk/phase3/RELEASE-NOTES	(revision 9775)
@@ -419,6 +419,7 @@
 * (bug 2597) Don't crash when undeleting an image description page
 * (bug 2564) Don't show "editingold" warning for recent revision
 * Various code cleanup and HTML escaping fixlets
+* Copy IRC-over-UDP update option from REL1_4
 
 
 === Caveats ===

Status & tagging log

  • 15:03, 12 September 2011 Meno25 (Talk | contribs) changed the status of r9775 [removed: ok added: old]
  • 14:05, 18 June 2009 ^demon (Talk | contribs) changed the status of r9775 [removed: new added: ok]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox