Fix for r41837 -- apply HTML stripping to explicit alt text as well as implicit.
[lhc/web/wiklou.git] / includes / ChangesList.php
index 6bb93d6..41d2039 100644 (file)
@@ -27,7 +27,7 @@ class ChangesList {
        # Called by history lists and recent changes
        #
 
-       /** 
+       /**
        * Changeslist contructor
        * @param Skin $skin
        */
@@ -62,7 +62,7 @@ class ChangesList {
                if( !isset( $this->message ) ) {
                        foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '.
                                'blocklink history boteditletter semicolon-separator' ) as $msg ) {
-                               $this->message[$msg] = wfMsgExt( $msg, array( 'escape') );
+                               $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
                        }
                }
        }
@@ -130,7 +130,6 @@ class ChangesList {
 
                # Make date header if necessary
                $date = $wgLang->date( $rc_timestamp, true, true );
-               $s = '';
                if( $date != $this->lastdate ) {
                        if( '' != $this->lastdate ) {
                                $s .= "</ul>\n";
@@ -194,20 +193,20 @@ class ChangesList {
 
                wfRunHooks('ChangesListInsertArticleLink',
                        array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched));
-               
+
                $s .= ' '.$articlelink;
        }
 
        protected function insertTimestamp(&$s, $rc) {
                global $wgLang;
                # Timestamp
-               $s .= $this->message['semicolon-separator'] . ' ' . $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 */
-       protected function insertUserRelatedLinks(&$s, &$rc) {
+       public function insertUserRelatedLinks(&$s, &$rc) {
                if ( $this->isDeleted($rc,Revision::DELETED_USER) ) {
-                  $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';   
+                  $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';
                } else {
                  $s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
                  $s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
@@ -222,7 +221,7 @@ class ChangesList {
                        if ( $this->isDeleted($rc,LogPage::DELETED_ACTION) ) {
                                $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
                        } else {
-                               $s .= ' ' . LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'], 
+                               $s .= ' ' . LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'],
                                        $rc->getTitle(), $this->skin, LogPage::extractParams($rc->mAttribs['rc_params']), true, true );
                        }
                }
@@ -241,6 +240,15 @@ class ChangesList {
                }
        }
 
+       /**
+        * Check whether to enable recent changes patrol features
+        * @return bool
+        */
+       public static function usePatrol() {
+               global $wgUser;
+               return $wgUser->useRCPatrol();
+       }
+
        /**
         * Returns the string which indicates the number of watching users
         */
@@ -257,7 +265,7 @@ class ChangesList {
                        return '';
                }
        }
-       
+
        /**
         * Determine if said field of a revision is hidden
         * @param RCCacheEntry $rc
@@ -267,7 +275,7 @@ class ChangesList {
        public static function isDeleted( $rc, $field ) {
                return ($rc->mAttribs['rc_deleted'] & $field) == $field;
        }
-       
+
        /**
         * Determine if the current user is allowed to view a particular
         * field of this revision, if it's marked as deleted.
@@ -279,7 +287,7 @@ class ChangesList {
                if( ( $rc->mAttribs['rc_deleted'] & $field ) == $field ) {
                        global $wgUser;
                        $permission = ( $rc->mAttribs['rc_deleted'] & Revision::DELETED_RESTRICTED ) == Revision::DELETED_RESTRICTED
-                               ? 'hiderevision'
+                               ? 'suppressrevision'
                                : 'deleterevision';
                        wfDebug( "Checking for $permission due to $field match on $rc->mAttribs['rc_deleted']\n" );
                        return $wgUser->isAllowed( $permission );
@@ -308,11 +316,12 @@ class OldChangesList extends ChangesList {
                extract( $rc->mAttribs );
 
                # Should patrol-related stuff be shown?
-               $unpatrolled = $wgUser->usePatrol() && $rc_patrolled == 0;
+               $unpatrolled = $wgUser->useRCPatrol() && $rc_patrolled == 0;
 
-               $this->insertDateHeader($s,$rc_timestamp);
+               $dateheader = ""; // $s now contains only <li>...</li>, for hooks' convenience.
+               $this->insertDateHeader($dateheader,$rc_timestamp);
 
-               $s .= '<li>';
+               $s = '';
 
                // Moved pages
                if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
@@ -355,7 +364,7 @@ class OldChangesList extends ChangesList {
                $this->insertAction($s, $rc);
                # Edit or log comment
                $this->insertComment($s, $rc);
-               
+
                # Mark revision as deleted if so
                if ( !$rc_log_type && $this->isDeleted($rc,Revision::DELETED_TEXT) )
                   $s .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
@@ -363,12 +372,14 @@ class OldChangesList extends ChangesList {
                        $s .= ' ' . wfMsg('number_of_watching_users_RCview',  $wgContLang->formatNum($rc->numberofWatchingusers));
                }
 
-               $s .= "</li>\n";
+               wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
+               
+               $s = "<li>$s</li>\n";
 
                wfProfileOut( $fname.'-rest' );
 
                wfProfileOut( $fname );
-               return $s;
+               return $dateheader . $s;
        }
 }
 
@@ -403,7 +414,7 @@ class EnhancedChangesList extends ChangesList {
                }
 
                # Should patrol-related stuff be shown?
-               if( $wgUser->usePatrol() ) {
+               if( $wgUser->useRCPatrol() ) {
                        $rc->unpatrolled = !$rc_patrolled;
                } else {
                        $rc->unpatrolled = false;
@@ -432,12 +443,18 @@ class EnhancedChangesList extends ChangesList {
                        $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
                // Log entries
                } else if( $rc_type == RC_LOG ) {
-                       $clink = $this->skin->makeLinkObj( $rc->getTitle(), '' );
+                       if( $rc_log_type ) {
+                               $logtitle = SpecialPage::getTitleFor( 'Log', $rc_log_type );
+                               $clink = '(' . $this->skin->makeKnownLinkObj( $logtitle, LogPage::logName($rc_log_type) ) . ')';
+                       } else {
+                               $clink = $this->skin->makeLinkObj( $rc->getTitle(), '' );
+                       }
+                       $watched = false;
                // Edits
                } else {
                        $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '' );
                }
-               
+
                # Don't show unusable diff links
                if ( !ChangesList::userCan($rc,Revision::DELETED_TEXT) ) {
                        $showdifflinks = false;
@@ -459,7 +476,7 @@ class EnhancedChangesList extends ChangesList {
                $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
                $aprops = ' tabindex="'.$baseRC->counter.'"';
                $curLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['cur'], $querycur, '' ,'', $aprops );
-               
+
                # Make "diff" an "cur" links
                if( !$showdifflinks ) {
                   $curLink = $this->message['cur'];
@@ -472,7 +489,7 @@ class EnhancedChangesList extends ChangesList {
                } else {
                        $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'], $querydiff, '' ,'', $aprops );
                }
-               
+
                # Make "last" link
                if( !$showdifflinks ) {
                    $lastLink = $this->message['last'];
@@ -482,7 +499,7 @@ class EnhancedChangesList extends ChangesList {
                        $lastLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['last'],
                        $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
                }
-               
+
                # Make user links
                if( $this->isDeleted($rc,Revision::DELETED_USER) ) {
                        $rc->userlink = ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';
@@ -503,9 +520,8 @@ class EnhancedChangesList extends ChangesList {
                        # Use an @ character to prevent collision with page names
                        $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
                } else {
-                       global $wgRCTypeGroupedLogs;
-                       # Some logs are best grouped by type (block,rights)
-                       if( $rc_type == RC_LOG && in_array($rc_log_type,$wgRCTypeGroupedLogs) ){
+                       # Logs are grouped by type
+                       if( $rc_type == RC_LOG ){
                                $secureName = SpecialPage::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
                        }
                        if( !isset( $this->rc_cache[$secureName] ) ) {
@@ -560,7 +576,7 @@ class EnhancedChangesList extends ChangesList {
                        if( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) {
                                $currentRevision = $rcObj->mAttribs['rc_this_oldid'];
                        }
-                       
+
                        $bot = $rcObj->mAttribs['rc_bot'];
                        $userlinks[$u]++;
                }
@@ -573,12 +589,12 @@ class EnhancedChangesList extends ChangesList {
                        $text = $userlink;
                        $text .= $wgContLang->getDirMark();
                        if( $count > 1 ) {
-                               $text .= ' ('.$count.'&times;)';
+                               $text .= ' (' . $wgLang->formatNum( $count ) . '×)';
                        }
                        array_push( $users, $text );
                }
 
-               $users = ' <span class="changedby">[' . implode( $this->message['semicolon-separator'] . ' ', $users ) . ']</span>';
+               $users = ' <span class="changedby">[' . implode( $this->message['semicolon-separator'], $users ) . ']</span>';
 
                # Arrow
                $rci = 'RCI'.$this->rcCacheIndex;
@@ -625,7 +641,7 @@ class EnhancedChangesList extends ChangesList {
                        }
                        $r .= ') . . ';
                }
-               
+
                # Character difference (does not apply if only log items)
                if( $wgRCShowChangedSize && !$alllogs ) {
                        $last = 0;
@@ -640,7 +656,7 @@ class EnhancedChangesList extends ChangesList {
                        # Get net change
                        $chardiff = $rcObj->getCharacterDifference( $block[$first]->mAttribs['rc_old_len'],
                                $block[$last]->mAttribs['rc_new_len'] );
-                       
+
                        if( $chardiff == '' ) {
                                $r .= ' ';
                        } else {
@@ -649,16 +665,18 @@ class EnhancedChangesList extends ChangesList {
                }
 
                # History
-               if( $namehidden || $alllogs ) {
+               if( $alllogs ) {
+                       // don't show history link for logs
+               } else if( $namehidden || !$block[0]->getTitle()->exists() ) {
                        $r .= '(' . $this->message['history'] . ')';
                } else {
                        $r .= '(' . $this->skin->makeKnownLinkObj( $block[0]->getTitle(),
                                $this->message['history'], $curIdEq.'&action=history' ) . ')';
                }
-               
+
                $r .= $users;
-               $r .=$this->numberofWatchingusers($block[0]->numberofWatchingusers);
-               
+               $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers);
+
                $r .= "</td></tr></table>\n";
 
                # Sub-entries
@@ -678,22 +696,25 @@ class EnhancedChangesList extends ChangesList {
                        if( $rc_this_oldid != 0 ) {
                                $o = 'oldid='.$rc_this_oldid;
                        }
-                       # Revision link
+                       # Log timestamp
                        if( $rc_type == RC_LOG ) {
                                $link = '<tt>'.$rcObj->timestamp.'</tt> ';
+                       # Revision link
                        } else if( !ChangesList::userCan($rcObj,Revision::DELETED_TEXT) ) {
                                $link = '<span class="history-deleted"><tt>'.$rcObj->timestamp.'</tt></span> ';
                        } else {
-                               $link = '<tt>'.$this->skin->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp, $curIdEq.'&'.$o ).'</tt>';
+                               $rcIdEq = ($rcObj->unpatrolled && $rc_type == RC_NEW) ? '&rcid='.$rcObj->mAttribs['rc_id'] : '';
+                               
+                               $link = '<tt>'.$this->skin->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp, $curIdEq.'&'.$o.$rcIdEq ).'</tt>';
                                if( $this->isDeleted($rcObj,Revision::DELETED_TEXT) )
                                        $link = '<span class="history-deleted">'.$link.'</span> ';
                        }
                        $r .= $link;
-                       
+
                        if ( !$rc_type == RC_LOG || $rc_type == RC_NEW ) {
                                $r .= ' (';
                                $r .= $rcObj->curlink;
-                               $r .= $this->message['semicolon-separator'] . ' ';
+                               $r .= $this->message['semicolon-separator'];
                                $r .= $rcObj->lastlink;
                                $r .= ')';
                        }
@@ -772,11 +793,11 @@ class EnhancedChangesList extends ChangesList {
        protected function spacerArrow() {
                return $this->arrow( '', ' ' );
        }
-       
+
        /**
         * Add a set of spaces
         * @return string HTML <td> tag
-        */     
+        */
        protected function spacerIndent() {
                return '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
        }
@@ -796,7 +817,7 @@ class EnhancedChangesList extends ChangesList {
                $r = '<table cellspacing="0" cellpadding="0" border="0" style="background: none"><tr>';
 
                $r .= '<td valign="top" style="white-space: nowrap"><tt>' . $this->spacerArrow() . '&nbsp;';
-               
+
                # Flag and Timestamp
                if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
                        $r .= '&nbsp;&nbsp;&nbsp;&nbsp;'; // 4 flags -> 4 spaces
@@ -804,7 +825,7 @@ class EnhancedChangesList extends ChangesList {
                        $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
                }
                $r .= '&nbsp;'.$rcObj->timestamp.'&nbsp;</tt></td><td>';
-               
+
                # Article or log link
                if( $rc_log_type ) {
                        $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
@@ -815,14 +836,14 @@ class EnhancedChangesList extends ChangesList {
                } else {
                        $r .= $this->maybeWatchedLink( $rcObj->link, $rcObj->watched );
                }
-               
+
                # Diff and hist links
                if ( $rc_type != RC_LOG ) {
-                  $r .= ' ('. $rcObj->difflink . $this->message['semicolon-separator'] . ' ';
+                  $r .= ' ('. $rcObj->difflink . $this->message['semicolon-separator'];
                   $r .= $this->skin->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' ) . ')';
                }
                $r .= ' . . ';
-               
+
                # Character diff
                if( $wgRCShowChangedSize ) {
                        $r .= ( $rcObj->getCharacterDifference() == '' ? '' : '&nbsp;' . $rcObj->getCharacterDifference() . ' . . ' ) ;
@@ -836,8 +857,9 @@ class EnhancedChangesList extends ChangesList {
                        if( $this->isDeleted($rcObj,LogPage::DELETED_ACTION) ) {
                                $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
                        } else {
-                               $r .= ' ' . LogPage::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(), $this->skin, LogPage::extractParams($rc_params), true, true );
-                       } 
+                               $r .= ' ' . LogPage::actionText( $rc_log_type, $rc_log_action, $rcObj->getTitle(), 
+                                       $this->skin, LogPage::extractParams($rc_params), true, true );
+                       }
                }
 
                # Edit or log comment