We still want details in page history
[lhc/web/wiklou.git] / includes / ChangesList.php
index a49f1fc..8b8fd50 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' ) );
                        }
                }
        }
@@ -75,17 +75,38 @@ class ChangesList {
         * @param bool $patrolled
         * @param string $nothing, string to use for empty space
         * @param bool $bot
+        * @param bool $newbie
         * @return string
         */
-       protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false ) {
+       protected function recentChangesFlags( $new, $minor, $patrolled, $nothing = ' ', $bot = false, $newbie = 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;
+               $f .= $newbie ? '<span class="newuser">*</span>' : $nothing;
                return $f;
        }
+       
+       protected static function userIsNew( $attribs ) {
+               global $wgAutoConfirmCount, $wgAutoConfirmAge;
+               if( !array_key_exists('user_editcount',$attribs) || !array_key_exists('user_registration',$attribs) ) {
+                       return false; // missing input!
+               }
+               static $time;
+               $time = time();
+               $edits = $attribs['user_editcount'];
+               $age = $attribs['user_registration'];
+               if( $wgAutoConfirmCount && !$edits || $wgAutoConfirmAge && !$age ) {
+                       return true;
+               } else if( $wgAutoConfirmCount && $edits < $wgAutoConfirmCount ) {
+                       return true;
+               } else if( $wgAutoConfirmAge && ($time - wfTimestampOrNull(TS_UNIX,$age)) < $wgAutoConfirmAge ) {
+                       return true;
+               }
+               return false;
+       }
 
        /**
         * Returns text for the start of the tabular part of RC
@@ -130,7 +151,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 +214,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 +242,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 );
                        }
                }
@@ -246,8 +266,8 @@ class ChangesList {
         * @return bool
         */
        public static function usePatrol() {
-               global $wgUseRCPatrol, $wgUser;
-               return( $wgUseRCPatrol && ($wgUser->isAllowed('patrol') || $wgUser->isAllowed('patrolmarks')) );
+               global $wgUser;
+               return $wgUser->useRCPatrol();
        }
 
        /**
@@ -266,7 +286,7 @@ class ChangesList {
                        return '';
                }
        }
-       
+
        /**
         * Determine if said field of a revision is hidden
         * @param RCCacheEntry $rc
@@ -276,7 +296,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.
@@ -288,7 +308,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 );
@@ -307,7 +327,7 @@ class OldChangesList extends ChangesList {
         * Format a line using the old system (aka without any javascript).
         */
        public function recentChangesLine( &$rc, $watched = false ) {
-               global $wgContLang, $wgRCShowChangedSize;
+               global $wgContLang, $wgRCShowChangedSize, $wgUser;
 
                $fname = 'ChangesList::recentChangesLineOld';
                wfProfileIn( $fname );
@@ -317,11 +337,12 @@ class OldChangesList extends ChangesList {
                extract( $rc->mAttribs );
 
                # Should patrol-related stuff be shown?
-               $unpatrolled = $this->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 = '<li>';
 
                // Moved pages
                if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
@@ -343,9 +364,10 @@ class OldChangesList extends ChangesList {
                        wfProfileIn($fname.'-page');
 
                        $this->insertDiffHist($s, $rc, $unpatrolled);
-
                        # M, N, b and ! (minor, new, bot and unpatrolled)
-                       $s .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $unpatrolled, '', $rc_bot );
+                       $newbie = self::userIsNew( $rc->mAttribs );
+                       $s .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $unpatrolled, '', 
+                               $rc_bot, $newbie );
                        $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
 
                        wfProfileOut($fname.'-page');
@@ -364,7 +386,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>';
@@ -374,10 +396,12 @@ class OldChangesList extends ChangesList {
 
                $s .= "</li>\n";
 
+               wfRunHooks('OldChangesListRecentChangesLine', array(&$this, &$s, &$rc));
+
                wfProfileOut( $fname.'-rest' );
 
                wfProfileOut( $fname );
-               return $s;
+               return $dateheader . $s;
        }
 }
 
@@ -390,7 +414,7 @@ class EnhancedChangesList extends ChangesList {
         * Format a line for enhanced recentchange (aka with javascript and block of lines).
         */
        public function recentChangesLine( &$baseRC, $watched = false ) {
-               global $wgLang, $wgContLang;
+               global $wgLang, $wgContLang, $wgUser;
 
                # Create a specialised object
                $rc = RCCacheEntry::newFromParent( $baseRC );
@@ -412,7 +436,7 @@ class EnhancedChangesList extends ChangesList {
                }
 
                # Should patrol-related stuff be shown?
-               if( $this->usePatrol() ) {
+               if( $wgUser->useRCPatrol() ) {
                        $rc->unpatrolled = !$rc_patrolled;
                } else {
                        $rc->unpatrolled = false;
@@ -439,11 +463,20 @@ class EnhancedChangesList extends ChangesList {
                // New unpatrolled pages
                } else if( $rc->unpatrolled && $rc_type == RC_NEW ) {
                        $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
-               // Other edits or log entries
+               // Log entries
+               } else if( $rc_type == RC_LOG ) {
+                       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;
@@ -465,7 +498,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'];
@@ -478,7 +511,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'];
@@ -488,7 +521,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>';
@@ -509,6 +542,7 @@ class EnhancedChangesList extends ChangesList {
                        # Use an @ character to prevent collision with page names
                        $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
                } else {
+                       # Logs are grouped by type
                        if( $rc_type == RC_LOG ){
                                $secureName = SpecialPage::getTitleFor( 'Log', $rc_log_type )->getPrefixedDBkey();
                        }
@@ -530,15 +564,14 @@ class EnhancedChangesList extends ChangesList {
                # Collate list of users
                $userlinks = array();
                # Other properties
-               $unpatrolled = false;
-               $isnew = false;
+               $unpatrolled = $isnew = $newbie = false;
                $curId = $currentRevision = 0;
                # Some catalyst variables...
                $namehidden = true;
                $alllogs = true;
                foreach( $block as $rcObj ) {
                        $oldid = $rcObj->mAttribs['rc_last_oldid'];
-                       if( $rcObj->mAttribs['rc_new'] ) {
+                       if( $rcObj->mAttribs['rc_type'] == RC_NEW ) {
                                $isnew = true;
                        }
                        // If all log actions to this page were hidden, then don't
@@ -556,6 +589,9 @@ class EnhancedChangesList extends ChangesList {
                        if( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
                                $alllogs = false;
                        }
+                       if( self::userIsNew( $rcObj->mAttribs ) ) {
+                               $newbie = true;
+                       }
                        # Get the latest entry with a page_id and oldid
                        # since logs may not have these.
                        if( !$curId && $rcObj->mAttribs['rc_cur_id'] ) {
@@ -564,7 +600,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]++;
                }
@@ -577,12 +613,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;
@@ -594,22 +630,13 @@ class EnhancedChangesList extends ChangesList {
                $r .= '<td valign="top" style="white-space: nowrap"><tt>'.$tl.'&nbsp;';
 
                # Main line
-               $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&nbsp;', $bot );
+               $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, '&nbsp;', $bot, $newbie );
 
                # Timestamp
                $r .= '&nbsp;'.$block[0]->timestamp.'&nbsp;</tt></td><td>';
 
                # Article link
-               if( $alllogs ){
-                       $logtype = $block[0]->mAttribs['rc_log_type'];
-                       if( is_null( $logtype ) ){
-                               //Old format
-                               $r .= $block[0]->link;
-                       } else {
-                               $logname = LogPage::logName( $logtype );
-                               $r .= ' (' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Log', $logtype ), $logname ) . ')';
-                       }
-               } else if( $namehidden ) {
+               if( $namehidden ) {
                        $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
                } else {
                        $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
@@ -638,7 +665,7 @@ class EnhancedChangesList extends ChangesList {
                        }
                        $r .= ') . . ';
                }
-               
+
                # Character difference (does not apply if only log items)
                if( $wgRCShowChangedSize && !$alllogs ) {
                        $last = 0;
@@ -653,7 +680,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 {
@@ -662,16 +689,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
@@ -684,29 +713,33 @@ class EnhancedChangesList extends ChangesList {
                        #$r .= '<tr><td valign="top">'.$this->spacerArrow();
                        $r .= '<tr><td valign="top">';
                        $r .= '<tt>'.$this->spacerIndent() . $this->spacerIndent();
-                       $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
+                       $newbie = self::userIsNew( $rcObj->mAttribs );
+                       $r .= $this->recentChangesFlags( $rc_new, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot, $newbie );
                        $r .= '&nbsp;</tt></td><td valign="top">';
 
                        $o = '';
                        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 .= ')';
                        }
@@ -785,11 +818,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;';
        }
@@ -807,17 +840,18 @@ class EnhancedChangesList extends ChangesList {
                $curIdEq = 'curid='.$rc_cur_id;
 
                $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
                } else {
-                       $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, '&nbsp;', $rc_bot );
+                       $newbie = self::userIsNew( $rcObj->mAttribs );
+                       $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled, 
+                               '&nbsp;', $rc_bot, $newbie );
                }
                $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 );
@@ -828,14 +862,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'] . ' ';
+               if( $rc_type != RC_LOG ) {
+                  $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() . ' . . ' ) ;
@@ -849,8 +883,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