* Copy IRC-over-UDP update option from REL1_4
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 29 Jun 2005 07:01:24 +0000 (07:01 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 29 Jun 2005 07:01:24 +0000 (07:01 +0000)
RELEASE-NOTES
includes/Article.php
includes/DefaultSettings.php
includes/RecentChange.php

index 57d5fa2..39549a8 100644 (file)
@@ -419,6 +419,7 @@ Various bugfixes, small features, and a few experimental things:
 * (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 ===
index 141ce02..054c2e4 100644 (file)
@@ -938,7 +938,8 @@ class Article {
 
                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 @@ class Article {
                }
 
                $oldtext = $this->getContent( true );
+               $oldsize = strlen( $oldtext );
+               $newsize = strlen( $text );
                $lastRevision = 0;
 
                if ( 0 != strcmp( $text, $oldtext ) ) {
@@ -1117,7 +1120,7 @@ class Article {
                                # 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 689a22e..a4da936 100644 (file)
@@ -1086,6 +1086,11 @@ $wgPutIPinRC = false;
 $wgRCMaxAge = 7 * 24 * 3600;
 
 
+# Send RC updates via UDP
+$wgRC2UDPAddress = false;
+$wgRC2UDPPort = false;
+$wgRC2UDPPrefix = '';
+
 #
 # Copyright and credits settings
 #
index bf6d888..41f81fe 100644 (file)
@@ -16,7 +16,7 @@ define( 'RC_MOVE_OVER_REDIRECT', 4);
 
 /**
  * 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 @@ define( 'RC_MOVE_OVER_REDIRECT', 4);
  *     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 @@ class RecentChange
        # 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 @@ class RecentChange
                                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 @@ class RecentChange
 
        # 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 @@ class RecentChange
 
                $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 @@ class RecentChange
 
                $rc->mExtra =  array(
                        'prefixedDBkey' => $title->getPrefixedDBkey(),
-                       'lastTimestamp' => 0
+                       'lastTimestamp' => 0,
+                       'oldSize' => 0,
+                       'newSize' => $size
                );
                $rc->save();
        }
@@ -399,5 +406,45 @@ class RecentChange
                }
                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;
+       }
 }
 ?>