add tests for {{#special:}}
[lhc/web/wiklou.git] / includes / ChangesList.php
index a34b496..fe3ec1b 100644 (file)
@@ -39,12 +39,20 @@ class ChangesList {
                $this->preCacheMessages();
        }
 
+       /**
+        * 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
+        */
        function newFromUser( &$user ) {
                $sk =& $user->getSkin();
-               if( $user->getOption('usenewrc') ) {
-                       return new EnhancedChangesList( $sk );
+               $list = NULL;
+               if( wfRunHooks( 'FetchChangesList', array( &$user, &$skin, &$list ) ) ) {
+                       return $user->getOption( 'usenewrc' ) ? new EnhancedChangesList( $sk ) : new OldChangesList( $sk );
                } else {
-                       return new OldChangesList( $sk );
+                       return $list;
                }
        }
 
@@ -56,7 +64,7 @@ class ChangesList {
                // Precache various messages
                if( !isset( $this->message ) ) {
                        foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
-                               'blocklink changes history' ) as $msg ) {
+                               'blocklink changes history boteditletter' ) as $msg ) {
                                $this->message[$msg] = wfMsgExt( $msg, array( 'escape') );
                        }
                }
@@ -64,13 +72,14 @@ class ChangesList {
 
 
        /**
-        * Returns the appropiate flags for new page, minor change and patrolling
+        * Returns the appropriate flags for new page, minor change and patrolling
         */
-       function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ' ) {
+       function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) {
                $f = $new ? '<span class="newpage">' . $this->message['newpageletter'] . '</span>'
                                : $nothing;
                $f .= $minor ? '<span class="minor">' . $this->message['minoreditletter'] . '</span>'
                                : $nothing;
+               $f .= $bot ? '<span class="bot">' . $this->message['boteditletter'] . '</span>' : $nothing;
                $f .= $patrolled ? '<span class="unpatrolled">!</span>' : $nothing;
                return $f;
        }
@@ -169,6 +178,8 @@ class ChangesList {
                        : '';
                $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
                if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
+               global $wgContLang;
+               $articlelink .= $wgContLang->getDirMark();
 
                $s .= ' '.$articlelink;
        }
@@ -235,16 +246,21 @@ 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');
 
                        $this->insertDiffHist($s, $rc, $unpatrolled);
 
-                       # M, N and ! (minor, new and unpatrolled)
-                       $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $unpatrolled, '' );
+                       # M, N, b and ! (minor, new, bot and unpatrolled)
+                       $s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $unpatrolled, '', $rc_bot );
                        $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
 
                        wfProfileOut($fname.'-page');
@@ -310,11 +326,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}" );
@@ -383,6 +404,7 @@ class EnhancedChangesList extends ChangesList {
         * Enhanced RC group
         */
        function recentChangesBlockGroup( $block ) {
+               global $wgContLang;
                $r = '';
 
                # Collate list of users
@@ -402,6 +424,7 @@ class EnhancedChangesList extends ChangesList {
                        if( $rcObj->unpatrolled ) {
                                $unpatrolled = true;
                        }
+                       $bot = $rcObj->mAttribs['rc_bot'];
                        $userlinks[$u]++;
                }
 
@@ -411,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;)';
                        }
@@ -430,7 +454,7 @@ class EnhancedChangesList extends ChangesList {
 
                # Main line
                $r .= '<tt>';
-               $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled );
+               $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&nbsp;', $bot );
 
                # Timestamp
                $r .= ' '.$block[0]->timestamp.' ';
@@ -438,6 +462,7 @@ class EnhancedChangesList extends ChangesList {
 
                # 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'];
@@ -474,7 +499,7 @@ class EnhancedChangesList extends ChangesList {
 
                        $r .= $this->spacerArrow();
                        $r .= '<tt>&nbsp; &nbsp; &nbsp; &nbsp;';
-                       $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled );
+                       $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
                        $r .= '&nbsp;</tt>';
 
                        $o = '';
@@ -580,7 +605,7 @@ class EnhancedChangesList extends ChangesList {
                if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
                        $r .= '&nbsp;&nbsp;&nbsp;';
                } else {
-                       $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled );
+                       $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
                }
                $r .= ' '.$rcObj->timestamp.' </tt>';