fix synxtax
[lhc/web/wiklou.git] / includes / ChangesList.php
index 54b7981..507e88f 100644 (file)
@@ -1,15 +1,7 @@
 <?php
-/**
- * @package MediaWiki
- * Contain class to show various lists of change:
- * - what's link here
- * - related changes
- * - recent changes
- */
 
 /**
  * @todo document
- * @package MediaWiki
  */
 class RCCacheEntry extends RecentChange
 {
@@ -17,8 +9,7 @@ class RCCacheEntry extends RecentChange
        var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
        var $userlink, $timestamp, $watched;
 
-       function newFromParent( $rc )
-       {
+       static function newFromParent( $rc ) {
                $rc2 = new RCCacheEntry;
                $rc2->mAttribs = $rc->mAttribs;
                $rc2->mExtra = $rc->mExtra;
@@ -27,14 +18,17 @@ class RCCacheEntry extends RecentChange
 } ;
 
 /**
- * @package MediaWiki
+ * Class to show various lists of changes:
+ * - what links here
+ * - related changes
+ * - recent changes
  */
 class ChangesList {
        # Called by history lists and recent changes
        #
 
        /** @todo document */
-       function ChangesList( &$skin ) {
+       function __construct( &$skin ) {
                $this->skin =& $skin;
                $this->preCacheMessages();
        }
@@ -47,7 +41,7 @@ class ChangesList {
         * @return ChangesList derivative
         */
        public static function newFromUser( &$user ) {
-               $sk =& $user->getSkin();
+               $sk = $user->getSkin();
                $list = NULL;
                if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) {
                        return $user->getOption( 'usenewrc' ) ? new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
@@ -64,7 +58,7 @@ class ChangesList {
                // Precache various messages
                if( !isset( $this->message ) ) {
                        foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
-                               'blocklink changes history boteditletter' ) as $msg ) {
+                               'blocklink history boteditletter semicolon-separator' ) as $msg ) {
                                $this->message[$msg] = wfMsgExt( $msg, array( 'escape') );
                        }
                }
@@ -177,17 +171,21 @@ class ChangesList {
                        ? 'rcid='.$rc->mAttribs['rc_id']
                        : '';
                $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
-               if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
+               if( $watched )
+                       $articlelink = "<strong class=\"mw-watched\">{$articlelink}</strong>";
                global $wgContLang;
                $articlelink .= $wgContLang->getDirMark();
 
+               wfRunHooks('ChangesListInsertArticleLink',
+                       array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched));
+               
                $s .= ' '.$articlelink;
        }
 
        function insertTimestamp(&$s, $rc) {
                global $wgLang;
                # Timestamp
-               $s .= '; ' . $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
+               $s .= $this->message['semicolon-separator'] . ' ' . $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . ';
        }
 
        /** Insert links to user page, user talk page and eventually a blocking link */
@@ -210,10 +208,25 @@ class ChangesList {
         */
        function usePatrol() {
                global $wgUseRCPatrol, $wgUser;
-               return( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) );
+               return( $wgUseRCPatrol && ($wgUser->isAllowed('patrol') || $wgUser->isAllowed('patrolmarks')) );
        }
 
-
+       /**
+        * Returns the string which indicates the number of watching users
+        */
+       function numberofWatchingusers( $count ) {
+               global $wgLang;
+               static $cache = array();
+               if ( $count > 0 ) {
+                       if ( !isset( $cache[$count] ) ) {
+                               $cache[$count] = wfMsgExt('number_of_watching_users_RCview',
+                                       array('parsemag', 'escape'), $wgLang->formatNum($count));
+                       }
+                       return $cache[$count];
+               } else {
+                       return '';
+               }
+       }
 }
 
 
@@ -225,13 +238,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
+               // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
                extract( $rc->mAttribs );
 
                # Should patrol-related stuff be shown?
@@ -268,12 +281,15 @@ 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);
 
-               if($rc->numberofWatchingusers > 0) {
-                       $s .= ' ' . wfMsg('number_of_watching_users_RCview',  $wgContLang->formatNum($rc->numberofWatchingusers));
-               }
+               $s .=  rtrim(' ' . $this->numberofWatchingusers($rc->numberofWatchingusers));
 
                $s .= "</li>\n";
 
@@ -299,6 +315,7 @@ class EnhancedChangesList extends ChangesList {
                $rc = RCCacheEntry::newFromParent( $baseRC );
 
                # Extract fields from DB into the function scope (rc_xxxx variables)
+               // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
                extract( $rc->mAttribs );
                $curIdEq = 'curid=' . $rc_cur_id;
 
@@ -403,7 +420,7 @@ class EnhancedChangesList extends ChangesList {
         * Enhanced RC group
         */
        function recentChangesBlockGroup( $block ) {
-               global $wgContLang;
+               global $wgLang, $wgContLang, $wgRCShowChangedSize;
                $r = '';
 
                # Collate list of users
@@ -439,7 +456,7 @@ class EnhancedChangesList extends ChangesList {
                        array_push( $users, $text );
                }
 
-               $users = ' <span class="changedby">['.implode('; ',$users).']</span>';
+               $users = ' <span class="changedby">[' . implode( $this->message['semicolon-separator'] . ' ', $users ) . ']</span>';
 
                # Arrow
                $rci = 'RCI'.$this->rcCacheIndex;
@@ -455,8 +472,7 @@ class EnhancedChangesList extends ChangesList {
                $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 );
@@ -466,33 +482,52 @@ class EnhancedChangesList extends ChangesList {
                $currentRevision = $block[0]->mAttribs['rc_this_oldid'];
                if( $block[0]->mAttribs['rc_type'] != RC_LOG ) {
                        # Changes
-                       $r .= ' ('.count($block).' ';
+
+                       $n = count($block);
+                       static $nchanges = array();
+                       if ( !isset( $nchanges[$n] ) ) {
+                               $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape'),
+                                       $wgLang->formatNum( $n ) );
+                       }
+
+                       $r .= ' (';
+
                        if( $isnew ) {
-                               $r .= $this->message['changes'];
+                               $r .= $nchanges[$n];
                        } else {
                                $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
-                                       $this->message['changes'], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
+                                       $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" );
                        }
-                       $r .= '; ';
+
+                       $r .= ') . . ';
+
+                       if( $wgRCShowChangedSize ) {
+                               # 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(),
+                       $r .= '(' . $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
                                $this->message['history'], $curIdEq.'&action=history' );
                        $r .= ')';
                }
 
                $r .= $users;
 
-               if($block[0]->numberofWatchingusers > 0) {
-                       global $wgContLang;
-                       $r .= wfMsg('number_of_watching_users_RCview',  $wgContLang->formatNum($block[0]->numberofWatchingusers));
-               }
+               $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers);
                $r .= "<br />\n";
 
                # Sub-entries
                $r .= '<div id="'.$rci.'" style="display:none">';
                foreach( $block as $rcObj ) {
                        # Get rc_xxxx variables
+                       // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
                        extract( $rcObj->mAttribs );
 
                        $r .= $this->spacerArrow();
@@ -514,9 +549,16 @@ class EnhancedChangesList extends ChangesList {
                        $r .= $link;
                        $r .= ' (';
                        $r .= $rcObj->curlink;
-                       $r .= '; ';
+                       $r .= $this->message['semicolon-separator'] . ' ';
                        $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";
@@ -530,7 +572,7 @@ class EnhancedChangesList extends ChangesList {
        function maybeWatchedLink( $link, $watched=false ) {
                if( $watched ) {
                        // FIXME: css style might be more appropriate
-                       return '<strong>' . $link . '</strong>';
+                       return '<strong class="mw-watched">' . $link . '</strong>';
                } else {
                        return $link;
                }
@@ -586,9 +628,10 @@ 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
+               // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
                extract( $rcObj->mAttribs );
                $curIdEq = 'curid='.$rc_cur_id;
 
@@ -611,22 +654,25 @@ class EnhancedChangesList extends ChangesList {
                $r .= $this->maybeWatchedLink( $rcObj->link, $rcObj->watched );
 
                # Diff
-               $r .= ' ('. $rcObj->difflink .'; ';
+               $r .= ' ('. $rcObj->difflink . $this->message['semicolon-separator'] . ' ';
 
                # 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 ) {
                        $r .= $this->skin->commentBlock( $rc_comment, $rcObj->getTitle() );
                }
 
-               if( $rcObj->numberofWatchingusers > 0 ) {
-                       $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rcObj->numberofWatchingusers));
-               }
+               $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
 
                $r .= "<br />\n";
                return $r;
@@ -661,4 +707,3 @@ class EnhancedChangesList extends ChangesList {
        }
 
 }
-?>