Fix NS_PROJECT_TALK (bug #7792)
[lhc/web/wiklou.git] / includes / ChangesList.php
index 4588c04..a2c1a26 100644 (file)
@@ -39,12 +39,20 @@ class ChangesList {
                $this->preCacheMessages();
        }
 
-       function newFromUser( &$user ) {
+       /**
+        * Fetch an appropriate changes list class for the specified user
+        * Some users might want to use an enhanced list format, for instance
+        *
+        * @param $user User to fetch the list class for
+        * @return ChangesList derivative
+        */
+       public static function newFromUser( &$user ) {
                $sk =& $user->getSkin();
-               if( $user->getOption('usenewrc') ) {
-                       return new EnhancedChangesList( $sk );
+               $list = NULL;
+               if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
+                       return $user->getOption( 'usenewrc' ) ? new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
                } else {
-                       return new OldChangesList( $sk );
+                       return $list;
                }
        }
 
@@ -170,11 +178,13 @@ class ChangesList {
                        : '';
                $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
                if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
+               global $wgContLang;
+               $articlelink .= $wgContLang->getDirMark();
 
                $s .= ' '.$articlelink;
        }
 
-       function insertTimestamp(&$s, &$rc) {
+       function insertTimestamp(&$s, $rc) {
                global $wgLang;
                # Timestamp
                $s .= '; ' . $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
@@ -202,8 +212,6 @@ class ChangesList {
                global $wgUseRCPatrol, $wgUser;
                return( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) );
        }
-
-
 }
 
 
@@ -215,15 +223,13 @@ class OldChangesList extends ChangesList {
         * Format a line using the old system (aka without any javascript).
         */
        function recentChangesLine( &$rc, $watched = false ) {
-               global $wgContLang;
+               global $wgContLang, $wgRCShowChangedSize;
 
                $fname = 'ChangesList::recentChangesLineOld';
                wfProfileIn( $fname );
 
-
                # Extract DB fields into local scope
                extract( $rc->mAttribs );
-               $curIdEq = 'curid=' . $rc_cur_id;
 
                # Should patrol-related stuff be shown?
                $unpatrolled = $this->usePatrol() && $rc_patrolled == 0;
@@ -236,8 +242,13 @@ class OldChangesList extends ChangesList {
                if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
                        $this->insertMove( $s, $rc );
                // log entries
-               } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
-                       $this->insertLog($s, $rc->getTitle(), $matches[1]);
+               } elseif ( $rc_namespace == NS_SPECIAL ) {
+                       list( $specialName, $specialSubpage ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
+                       if ( $specialName == 'Log' ) {
+                               $this->insertLog( $s, $rc->getTitle(), $specialSubpage );
+                       } else {
+                               wfDebug( "Unexpected special page in recentchanges\n" );
+                       }
                // all other stuff
                } else {
                        wfProfileIn($fname.'-page');
@@ -254,6 +265,11 @@ class OldChangesList extends ChangesList {
                wfProfileIn( $fname.'-rest' );
 
                $this->insertTimestamp($s,$rc);
+
+               if( $wgRCShowChangedSize ) {
+                       $s .= ( $rc->getCharacterDifference() == '' ? '' : $rc->getCharacterDifference() . ' . . ' );
+               }
+
                $this->insertUserRelatedLinks($s,$rc);
                $this->insertComment($s, $rc);
 
@@ -311,11 +327,16 @@ class EnhancedChangesList extends ChangesList {
                        $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
                        $clink = wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
                          $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
-               } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
-                       # Log updates, etc
-                       $logtype = $matches[1];
-                       $logname = LogPage::logName( $logtype );
-                       $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
+               } elseif( $rc_namespace == NS_SPECIAL ) {
+                       list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
+                       if ( $specialName == 'Log' ) {
+                               # Log updates, etc
+                               $logname = LogPage::logName( $logtype );
+                               $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
+                       } else {
+                               wfDebug( "Unexpected special page in recentchanges\n" );
+                               $clink = '';
+                       }
                } elseif( $rc->unpatrolled && $rc_type == RC_NEW ) {
                        # Unpatrolled new page, give rc_id in query
                        $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
@@ -384,6 +405,7 @@ class EnhancedChangesList extends ChangesList {
         * Enhanced RC group
         */
        function recentChangesBlockGroup( $block ) {
+               global $wgContLang, $wgRCShowChangedSize;
                $r = '';
 
                # Collate list of users
@@ -392,7 +414,6 @@ class EnhancedChangesList extends ChangesList {
                $userlinks = array();
                foreach( $block as $rcObj ) {
                        $oldid = $rcObj->mAttribs['rc_last_oldid'];
-                       $newid = $rcObj->mAttribs['rc_this_oldid'];
                        if( $rcObj->mAttribs['rc_new'] ) {
                                $isnew = true;
                        }
@@ -413,6 +434,7 @@ class EnhancedChangesList extends ChangesList {
                $users = array();
                foreach( $userlinks as $userlink => $count) {
                        $text = $userlink;
+                       $text .= $wgContLang->getDirMark();
                        if( $count > 1 ) {
                                $text .= ' ('.$count.'&times;)';
                        }
@@ -432,27 +454,37 @@ class EnhancedChangesList extends ChangesList {
 
                # Main line
                $r .= '<tt>';
-               $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '', $bot );
+               $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&nbsp;', $bot );
 
                # Timestamp
-               $r .= ' '.$block[0]->timestamp.' ';
-               $r .= '</tt>';
+               $r .= ' '.$block[0]->timestamp.' </tt>';
 
                # Article link
                $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
+               $r .= $wgContLang->getDirMark();
 
                $curIdEq = 'curid=' . $block[0]->mAttribs['rc_cur_id'];
                $currentRevision = $block[0]->mAttribs['rc_this_oldid'];
                if( $block[0]->mAttribs['rc_type'] != RC_LOG ) {
                        # Changes
                        $r .= ' ('.count($block).' ';
+
                        if( $isnew ) {
                                $r .= $this->message['changes'];
                        } else {
                                $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
                                        $this->message['changes'], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
                        }
-                       $r .= '; ';
+
+                       # Character difference
+                       $chardiff = $rcObj->getCharacterDifference( $block[ count( $block ) - 1 ]->mAttribs['rc_old_len'],
+                                       $block[0]->mAttribs['rc_new_len'] );
+                       if( $chardiff == '' ) {
+                               $r .= '; ';
+                       } else {
+                               $r .= '; ' . $chardiff . ' ';
+                       }
+                       
 
                        # History
                        $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
@@ -476,7 +508,7 @@ class EnhancedChangesList extends ChangesList {
 
                        $r .= $this->spacerArrow();
                        $r .= '<tt>&nbsp; &nbsp; &nbsp; &nbsp;';
-                       $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '', $rc_bot );
+                       $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
                        $r .= '&nbsp;</tt>';
 
                        $o = '';
@@ -495,7 +527,14 @@ class EnhancedChangesList extends ChangesList {
                        $r .= $rcObj->curlink;
                        $r .= '; ';
                        $r .= $rcObj->lastlink;
-                       $r .= ') . . '.$rcObj->userlink;
+                       $r .= ') . . ';
+
+                       # Character diff
+                       if( $wgRCShowChangedSize ) {
+                               $r .= ( $rcObj->getCharacterDifference() == '' ? '' : $rcObj->getCharacterDifference() . ' . . ' ) ;
+                       }
+
+                       $r .= $rcObj->userlink;
                        $r .= $rcObj->usertalklink;
                        $r .= $this->skin->commentBlock( $rc_comment, $rcObj->getTitle() );
                        $r .= "<br />\n";
@@ -565,7 +604,7 @@ class EnhancedChangesList extends ChangesList {
         * @return string a HTML formated line (generated using $r)
         */
        function recentChangesBlockLine( $rcObj ) {
-               global $wgContLang;
+               global $wgContLang, $wgRCShowChangedSize;
 
                # Get rc_xxxx variables
                extract( $rcObj->mAttribs );
@@ -593,10 +632,15 @@ class EnhancedChangesList extends ChangesList {
                $r .= ' ('. $rcObj->difflink .'; ';
 
                # Hist
-               $r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
+               $r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ) . ') . . ';
+
+               # Character diff
+               if( $wgRCShowChangedSize ) {
+                       $r .= ( $rcObj->getCharacterDifference() == '' ? '' : '&nbsp;' . $rcObj->getCharacterDifference() . ' . . ' ) ;
+               }
 
                # User/talk
-               $r .= ') . . '.$rcObj->userlink . $rcObj->usertalklink;
+               $r .= $rcObj->userlink . $rcObj->usertalklink;
 
                # Comment
                if( $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
@@ -620,7 +664,7 @@ class EnhancedChangesList extends ChangesList {
                        return '';
                }
                $blockOut = '';
-               foreach( $this->rc_cache as $secureName => $block ) {
+               foreach( $this->rc_cache as $block ) {
                        if( count( $block ) < 2 ) {
                                $blockOut .= $this->recentChangesBlockLine( array_shift( $block ) );
                        } else {