Fix r53270: drop &returntoquery parameter if empty, and prevent Special:Userlogin...
[lhc/web/wiklou.git] / includes / RecentChange.php
index d071466..2ca2f69 100644 (file)
@@ -119,6 +119,8 @@ class RecentChange
        public function &getTitle() {
                if( $this->mTitle === false ) {
                        $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
+                       # Make sure the correct page ID is process cached
+                       $this->mTitle->resetArticleID( $this->mAttribs['rc_cur_id'] );
                }
                return $this->mTitle;
        }
@@ -158,7 +160,7 @@ class RecentChange
 
                ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
                if( $dbw->cascadingDeletes() and $this->mAttribs['rc_cur_id']==0 ) {
-                       unset ( $this->mAttribs['rc_cur_id'] );
+                       unset( $this->mAttribs['rc_cur_id'] );
                }
 
                # Insert new row
@@ -166,6 +168,9 @@ class RecentChange
 
                # Set the ID
                $this->mAttribs['rc_id'] = $dbw->insertId();
+               
+               # Notify extensions
+               wfRunHooks( 'RecentChange_save', array( &$this ) );
 
                # Notify external application via UDP
                if( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
@@ -193,9 +198,14 @@ class RecentChange
                                $this->mAttribs['rc_minor'],
                                $this->mAttribs['rc_last_oldid'] );
                }
-
-               # Notify extensions
-               wfRunHooks( 'RecentChange_save', array( &$this ) );
+       }
+       
+       public function notifyRC2UDP() {
+               global $wgRC2UDPAddress, $wgRC2UDPOmitBots;
+               # Notify external application via UDP
+               if( $wgRC2UDPAddress && ( !$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots ) ) {
+                       self::sendToUDP( $this->getIRCLine() );
+               }
        }
 
        /**
@@ -215,21 +225,24 @@ class RecentChange
                        $conn = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
                        if( $conn ) {
                                $line = $prefix . $line;
+                               wfDebug( __METHOD__ . ": sending UDP line: $line\n" );
                                socket_sendto( $conn, $line, strlen($line), 0, $address, $wgRC2UDPPort );
                                socket_close( $conn );
                                return true;
+                       } else {
+                               wfDebug( __METHOD__ . ": failed to create UDP socket\n" );
                        }
                }
                return false;
        }
        
        /**
-        * Remove newlines and carriage returns
+        * Remove newlines, carriage returns and decode html entites
         * @param string $line
         * @return string
         */
        public static function cleanupForIRC( $text ) {
-               return str_replace(array("\n", "\r"), array("", ""), $text);
+               return Sanitizer::decodeCharReferences( str_replace( array( "\n", "\r" ), array( "", "" ), $text ) );
        }
 
        /**
@@ -310,14 +323,12 @@ class RecentChange
        }
 
        # Makes an entry in the database corresponding to an edit
-       public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment,
-               $oldId, $lastTimestamp, $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0)
+       public static function notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId,
+               $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0 )
        {
                if( !$ip ) {
                        $ip = wfGetIP();
-                       if( !$ip ) {
-                               $ip = '';
-                       }
+                       if( !$ip ) $ip = '';
                }
 
                $rc = new RecentChange;
@@ -338,7 +349,7 @@ class RecentChange
                        'rc_moved_to_ns'        => 0,
                        'rc_moved_to_title'     => '',
                        'rc_ip'         => $ip,
-                       'rc_patrolled'  => 0,
+                       'rc_patrolled'  => intval($patrol),
                        'rc_new'        => 0,  # obsolete
                        'rc_old_len'    => $oldSize,
                        'rc_new_len'    => $newSize,
@@ -365,13 +376,11 @@ class RecentChange
         * @todo Document parameters and return
         */
        public static function notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot,
-         $ip='', $size = 0, $newId = 0 )
+               $ip='', $size=0, $newId=0, $patrol=0 )
        {
                if( !$ip ) {
                        $ip = wfGetIP();
-                       if( !$ip ) {
-                               $ip = '';
-                       }
+                       if( !$ip ) $ip = '';
                }
 
                $rc = new RecentChange;
@@ -392,7 +401,7 @@ class RecentChange
                        'rc_moved_to_ns'    => 0,
                        'rc_moved_to_title' => '',
                        'rc_ip'             => $ip,
-                       'rc_patrolled'      => 0,
+                       'rc_patrolled'      => intval($patrol),
                        'rc_new'                => 1, # obsolete
                        'rc_old_len'        => 0,
                        'rc_new_len'        => $size,
@@ -417,12 +426,9 @@ class RecentChange
        public static function notifyMove( $timestamp, &$oldTitle, &$newTitle, &$user, $comment, $ip='', $overRedir = false )
        {
                global $wgRequest;
-
                if( !$ip ) {
                        $ip = wfGetIP();
-                       if( !$ip ) {
-                               $ip = '';
-                       }
+                       if( !$ip ) $ip = '';
                }
 
                $rc = new RecentChange;
@@ -470,16 +476,27 @@ class RecentChange
                RecentChange::notifyMove( $timestamp, $oldTitle, $newTitle, $user, $comment, $ip, true );
        }
 
-       public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip='',
-          $type, $action, $target, $logComment, $params, $newId=0 )
+       public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip='', $type, 
+               $action, $target, $logComment, $params, $newId=0 )
        {
-               global $wgRequest;
+               global $wgLogRestrictions;
+               # Don't add private logs to RC!
+               if( isset($wgLogRestrictions[$type]) && $wgLogRestrictions[$type] != '*' ) {
+                       return false;
+               }
+               $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
+                       $target, $logComment, $params, $newId );
+               $rc->save();
+               return true;
+       }
 
+       public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip='',
+               $type, $action, $target, $logComment, $params, $newId=0 )
+       {
+               global $wgRequest;
                if( !$ip ) {
                        $ip = wfGetIP();
-                       if( !$ip ) {
-                               $ip = '';
-                       }
+                       if( !$ip ) $ip = '';
                }
 
                $rc = new RecentChange;
@@ -515,7 +532,7 @@ class RecentChange
                        'lastTimestamp' => 0,
                        'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
                );
-               $rc->save();
+               return $rc;
        }
 
        # Initialises the members of this object from a mysql row object
@@ -523,7 +540,6 @@ class RecentChange
                $this->mAttribs = get_object_vars( $row );
                $this->mAttribs['rc_timestamp'] = wfTimestamp(TS_MW, $this->mAttribs['rc_timestamp']);
                $this->mAttribs['rc_deleted'] = $row->rc_deleted; // MUST be set
-               $this->mExtra = array();
        }
 
        # Makes a pseudo-RC entry from a cur row
@@ -556,7 +572,6 @@ class RecentChange
                        'rc_log_id' => isset($row->rc_log_id) ? $row->rc_log_id: 0,
                        'rc_deleted' => $row->rc_deleted // MUST be set
                );
-               $this->mExtra = array();
        }
 
        /**
@@ -588,7 +603,7 @@ class RecentChange
                return $trail;
        }
 
-       protected function getIRCLine() {
+       public function getIRCLine() {
                global $wgUseRCPatrol, $wgUseNPPatrol, $wgRC2UDPInterwikiPrefix, $wgLocalInterwiki;
 
                // FIXME: Would be good to replace these 2 extract() calls with something more explicit
@@ -604,19 +619,22 @@ class RecentChange
                $title = $titleObj->getPrefixedText();
                $title = self::cleanupForIRC( $title );
 
-               // FIXME: *HACK* these should be getFullURL(), hacked for SSL madness --brion 2005-12-26
                if( $rc_type == RC_LOG ) {
                        $url = '';
-               } elseif( $rc_new && ($wgUseRCPatrol || $wgUseNPPatrol) ) {
-                       $url = $titleObj->getInternalURL("rcid=$rc_id");
-               } else if( $rc_new ) {
-                       $url = $titleObj->getInternalURL();
-               } else if( $wgUseRCPatrol ) {
-                       $url = $titleObj->getInternalURL("diff=$rc_this_oldid&oldid=$rc_last_oldid&rcid=$rc_id");
-                       $url = preg_replace('/title=[^&]*&/', '', $url);
                } else {
-                       $url = $titleObj->getInternalURL("diff=$rc_this_oldid&oldid=$rc_last_oldid");
-                       $url = preg_replace('/title=[^&]*&/', '', $url);
+                       if( $rc_type == RC_NEW ) {
+                               $url = "oldid=$rc_this_oldid";
+                       } else {
+                               $url = "diff=$rc_this_oldid&oldid=$rc_last_oldid";
+                       }
+                       if( $wgUseRCPatrol || ($rc_type == RC_NEW && $wgUseNPPatrol) ) {
+                               $url .= "&rcid=$rc_id";
+                       }
+                       // XXX: *HACK* this should use getFullURL(), hacked for SSL madness --brion 2005-12-26
+                       // XXX: *HACK^2* the preg_replace() undoes much of what getInternalURL() does, but we 
+                       // XXX: need to call it so that URL paths on the Wikimedia secure server can be fixed
+                       // XXX: by a custom GetInternalURL hook --vyznev 2008-12-10
+                       $url = preg_replace( '/title=[^&]*&/', '', $titleObj->getInternalURL( $url ) );
                }
 
                if( isset( $oldSize ) && isset( $newSize ) ) {
@@ -639,7 +657,11 @@ class RecentChange
                        $flag = $rc_log_action;
                } else {
                        $comment = self::cleanupForIRC( $rc_comment );
-                       $flag = ($rc_new ? "N" : "") . ($rc_minor ? "M" : "") . ($rc_bot ? "B" : "");
+                       $flag = '';
+                       if( !$rc_patrolled && ($wgUseRCPatrol || $rc_new && $wgUseNPPatrol) ) {
+                               $flag .= '!';
+                       }
+                       $flag .= ($rc_new ? "N" : "") . ($rc_minor ? "M" : "") . ($rc_bot ? "B" : "");
                }
 
                if ( $wgRC2UDPInterwikiPrefix === true ) {
@@ -668,37 +690,15 @@ class RecentChange
         * The lengths can be given optionally.
         */
        public function getCharacterDifference( $old = 0, $new = 0 ) {
-               global $wgRCChangedSizeThreshold, $wgLang;
-
                if( $old === 0 ) {
                        $old = $this->mAttribs['rc_old_len'];
                }
                if( $new === 0 ) {
                        $new = $this->mAttribs['rc_new_len'];
                }
-
                if( $old === NULL || $new === NULL ) {
                        return '';
                }
-
-               $szdiff = $new - $old;
-               $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape'),
-                       $wgLang->formatNum($szdiff) );
-
-               
-               if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
-                       $tag = 'strong';
-               } 
-               else{
-                   $tag = 'span';
-               }
-
-               if( $szdiff === 0 ) {
-                       return "<$tag class='mw-plusminus-null'>($formatedSize)</$tag>";
-               } elseif( $szdiff > 0 ) {
-                       return "<$tag class='mw-plusminus-pos'>(+$formatedSize)</$tag>";
-           } else {
-                       return "<$tag class='mw-plusminus-neg'>($formatedSize)</$tag>";
-               }
+               return ChangesList::showCharacterDifference( $old, $new );
        }
 }