Merge changes I8b6b8510,I1cae6174
[lhc/web/wiklou.git] / includes / changes / EnhancedChangesList.php
index 433adb3..1727da0 100644 (file)
@@ -42,8 +42,10 @@ class EnhancedChangesList extends ChangesList {
                        'jquery.makeCollapsible',
                        'mediawiki.icon',
                ) );
+
                return '';
        }
+
        /**
         * Format a line for enhanced recentchange (aka with javascript and block of lines).
         *
@@ -55,14 +57,14 @@ class EnhancedChangesList extends ChangesList {
        public function recentChangesLine( &$baseRC, $watched = false ) {
                wfProfileIn( __METHOD__ );
 
-               # Create a specialised object
-               $rc = RCCacheEntry::newFromParent( $baseRC );
-
-               $curIdEq = array( 'curid' => $rc->mAttribs['rc_cur_id'] );
-
                # If it's a new day, add the headline and flush the cache
-               $date = $this->getLanguage()->userDate( $rc->mAttribs['rc_timestamp'], $this->getUser() );
+               $date = $this->getLanguage()->userDate(
+                       $baseRC->mAttribs['rc_timestamp'],
+                       $this->getUser()
+               );
+
                $ret = '';
+
                if ( $date != $this->lastdate ) {
                        # Process current cache
                        $ret = $this->recentChangesBlock();
@@ -71,53 +73,62 @@ class EnhancedChangesList extends ChangesList {
                        $this->lastdate = $date;
                }
 
+               # Create a specialised object
+               $cacheEntry = RCCacheEntry::newFromParent( $baseRC );
+
+               $curIdEq = array( 'curid' => $cacheEntry->mAttribs['rc_cur_id'] );
+
                # Should patrol-related stuff be shown?
-               $rc->unpatrolled = $this->showAsUnpatrolled( $rc );
+               $cacheEntry->unpatrolled = $this->showAsUnpatrolled( $cacheEntry );
 
                $showdifflinks = true;
+
                # Make article link
-               $type = $rc->mAttribs['rc_type'];
-               $logType = $rc->mAttribs['rc_log_type'];
+               $type = $cacheEntry->mAttribs['rc_type'];
+               $logType = $cacheEntry->mAttribs['rc_log_type'];
+
                // Page moves, very old style, not supported anymore
                if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
                // New unpatrolled pages
-               } elseif ( $rc->unpatrolled && $type == RC_NEW ) {
-                       $clink = Linker::linkKnown( $rc->getTitle() );
+               } elseif ( $cacheEntry->unpatrolled && $type == RC_NEW ) {
+                       $clink = Linker::linkKnown( $cacheEntry->getTitle() );
                // Log entries
                } elseif ( $type == RC_LOG ) {
                        if ( $logType ) {
                                $logtitle = SpecialPage::getTitleFor( 'Log', $logType );
                                $logpage = new LogPage( $logType );
                                $logname = $logpage->getName()->escaped();
-                               $clink = $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logtitle, $logname ) )->escaped();
+                               $clink = $this->msg( 'parentheses' )
+                                       ->rawParams( Linker::linkKnown( $logtitle, $logname ) )->escaped();
                        } else {
-                               $clink = Linker::link( $rc->getTitle() );
+                               $clink = Linker::link( $cacheEntry->getTitle() );
                        }
                        $watched = false;
                // Log entries (old format) and special pages
-               } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
+               } elseif ( $cacheEntry->mAttribs['rc_namespace'] == NS_SPECIAL ) {
                        wfDebug( "Unexpected special page in recentchanges\n" );
                        $clink = '';
                // Edits
                } else {
-                       $clink = Linker::linkKnown( $rc->getTitle() );
+                       $clink = Linker::linkKnown( $cacheEntry->getTitle() );
                }
 
                # Don't show unusable diff links
-               if ( !ChangesList::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
+               if ( !ChangesList::userCan( $cacheEntry, Revision::DELETED_TEXT, $this->getUser() ) ) {
                        $showdifflinks = false;
                }
 
-               $time = $this->getLanguage()->userTime( $rc->mAttribs['rc_timestamp'], $this->getUser() );
-               $rc->watched = $watched;
-               $rc->link = $clink;
-               $rc->timestamp = $time;
-               $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
+               $time = $this->getLanguage()->userTime( $cacheEntry->mAttribs['rc_timestamp'], $this->getUser() );
+
+               $cacheEntry->watched = $watched;
+               $cacheEntry->link = $clink;
+               $cacheEntry->timestamp = $time;
+               $cacheEntry->numberofWatchingusers = $baseRC->numberofWatchingusers;
 
                # Make "cur" and "diff" links.  Do not use link(), it is too slow if
                # called too many times (50% of CPU time on RecentChanges!).
-               $thisOldid = $rc->mAttribs['rc_this_oldid'];
-               $lastOldid = $rc->mAttribs['rc_last_oldid'];
+               $thisOldid = $cacheEntry->mAttribs['rc_this_oldid'];
+               $lastOldid = $cacheEntry->mAttribs['rc_last_oldid'];
 
                $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $thisOldid );
                $querydiff = $curIdEq + array( 'diff' => $thisOldid, 'oldid' => $lastOldid );
@@ -129,13 +140,13 @@ class EnhancedChangesList extends ChangesList {
                        if ( $type != RC_NEW ) {
                                $curLink = $this->message['cur'];
                        } else {
-                               $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
+                               $curUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $querycur ) );
                                $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
                        }
                        $diffLink = $this->message['diff'];
                } else {
-                       $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querydiff ) );
-                       $curUrl = htmlspecialchars( $rc->getTitle()->getLinkURL( $querycur ) );
+                       $diffUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $querydiff ) );
+                       $curUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $querycur ) );
                        $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
                        $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
                }
@@ -146,29 +157,38 @@ class EnhancedChangesList extends ChangesList {
                } elseif ( in_array( $type, array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ) ) ) {
                        $lastLink = $this->message['last'];
                } else {
-                       $lastLink = Linker::linkKnown( $rc->getTitle(), $this->message['last'],
+                       $lastLink = Linker::linkKnown( $cacheEntry->getTitle(), $this->message['last'],
                                array(), $curIdEq + array( 'diff' => $thisOldid, 'oldid' => $lastOldid ) );
                }
 
                # Make user links
-               if ( $this->isDeleted( $rc, Revision::DELETED_USER ) ) {
-                       $rc->userlink = ' <span class="history-deleted">' . $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
+               if ( $this->isDeleted( $cacheEntry, Revision::DELETED_USER ) ) {
+                       $cacheEntry->userlink = ' <span class="history-deleted">' .
+                               $this->msg( 'rev-deleted-user' )->escaped() . '</span>';
                } else {
-                       $rc->userlink = Linker::userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
-                       $rc->usertalklink = Linker::userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
+                       $cacheEntry->userlink = Linker::userLink(
+                               $cacheEntry->mAttribs['rc_user'],
+                               $cacheEntry->mAttribs['rc_user_text']
+                       );
+
+                       $cacheEntry->usertalklink = Linker::userToolLinks(
+                               $cacheEntry->mAttribs['rc_user'],
+                               $cacheEntry->mAttribs['rc_user_text']
+                       );
                }
 
-               $rc->lastlink = $lastLink;
-               $rc->curlink = $curLink;
-               $rc->difflink = $diffLink;
+               $cacheEntry->lastlink = $lastLink;
+               $cacheEntry->curlink = $curLink;
+               $cacheEntry->difflink = $diffLink;
 
                # Put accumulated information into the cache, for later display
                # Page moves go on their own line
-               $title = $rc->getTitle();
+               $title = $cacheEntry->getTitle();
                $secureName = $title->getPrefixedDBkey();
+
                if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) {
                        # Use an @ character to prevent collision with page names
-                       $this->rc_cache['@@' . ( $this->rcMoveIndex++ )] = array( $rc );
+                       $this->rc_cache['@@' . ( $this->rcMoveIndex++ )] = array( $cacheEntry );
                } else {
                        # Logs are grouped by type
                        if ( $type == RC_LOG ) {
@@ -178,7 +198,7 @@ class EnhancedChangesList extends ChangesList {
                                $this->rc_cache[$secureName] = array();
                        }
 
-                       array_push( $this->rc_cache[$secureName], $rc );
+                       array_push( $this->rc_cache[$secureName], $cacheEntry );
                }
 
                wfProfileOut( __METHOD__ );
@@ -200,10 +220,10 @@ class EnhancedChangesList extends ChangesList {
                if ( $block[0]->mAttribs['rc_log_type'] ) {
                        # Log entry
                        $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
-                                       . $block[0]->mAttribs['rc_log_type'] . '-' . $block[0]->mAttribs['rc_title'] );
+                               . $block[0]->mAttribs['rc_log_type'] . '-' . $block[0]->mAttribs['rc_title'] );
                } else {
                        $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns'
-                                       . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
+                               . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
                }
                $classes[] = $block[0]->watched && $block[0]->mAttribs['rc_timestamp'] >= $block[0]->watched
                        ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
@@ -268,7 +288,9 @@ class EnhancedChangesList extends ChangesList {
                        $text = $userlink;
                        $text .= $this->getLanguage()->getDirMark();
                        if ( $count > 1 ) {
-                               $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->formatNum( $count ) . '×' )->escaped();
+                               // @todo FIXME: Hardcoded '×'. Should be a message.
+                               $formattedCount = $this->getLanguage()->formatNum( $count ) . '×';
+                               $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped();
                        }
                        array_push( $users, $text );
                }
@@ -278,7 +300,8 @@ class EnhancedChangesList extends ChangesList {
                                implode( $this->message['semicolon-separator'], $users )
                        )->escaped() . '</span>';
 
-               $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
+               $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow ' .
+                       'mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
                $r .= "<td>$tl</td>";
 
                # Main line
@@ -294,7 +317,8 @@ class EnhancedChangesList extends ChangesList {
 
                # Article link
                if ( $namehidden ) {
-                       $r .= ' <span class="history-deleted">' . $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
+                       $r .= ' <span class="history-deleted">' .
+                               $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
                } elseif ( $allLogs ) {
                        $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
                } else {
@@ -409,6 +433,7 @@ class EnhancedChangesList extends ChangesList {
 
                $r .= $users;
                $r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers );
+               $r .= '</td></tr>';
 
                # Sub-entries
                foreach ( $block as $rcObj ) {
@@ -443,11 +468,11 @@ class EnhancedChangesList extends ChangesList {
                        } else {
 
                                $link = Linker::linkKnown(
-                                               $rcObj->getTitle(),
-                                               $rcObj->timestamp,
-                                               array(),
-                                               $params
-                                       );
+                                       $rcObj->getTitle(),
+                                       $rcObj->timestamp,
+                                       array(),
+                                       $params
+                               );
                                if ( $this->isDeleted( $rcObj, Revision::DELETED_TEXT ) ) {
                                        $link = '<span class="history-deleted">' . $link . '</span> ';
                                }
@@ -455,7 +480,11 @@ class EnhancedChangesList extends ChangesList {
                        $r .= $link . '</span>';
 
                        if ( !$type == RC_LOG || $type == RC_NEW ) {
-                               $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->curlink . $this->message['pipe-separator'] . $rcObj->lastlink )->escaped();
+                               $r .= ' ' . $this->msg( 'parentheses' )->rawParams(
+                                       $rcObj->curlink .
+                                               $this->message['pipe-separator'] .
+                                               $rcObj->lastlink
+                               )->escaped();
                        }
                        $r .= ' <span class="mw-changeslist-separator">. .</span> ';
 
@@ -504,6 +533,7 @@ class EnhancedChangesList extends ChangesList {
                $encUrl = htmlspecialchars( $wgStylePath . '/common/images/Arr_' . $dir . '.png' );
                $encAlt = htmlspecialchars( $alt );
                $encTitle = htmlspecialchars( $title );
+
                return "<img src=\"$encUrl\" width=\"12\" height=\"12\" alt=\"$encAlt\" title=\"$encTitle\" />";
        }
 
@@ -514,6 +544,7 @@ class EnhancedChangesList extends ChangesList {
         */
        protected function sideArrow() {
                $dir = $this->getLanguage()->isRTL() ? 'l' : 'r';
+
                return $this->arrow( $dir, '+', $this->msg( 'rc-enhanced-expand' )->text() );
        }
 
@@ -552,10 +583,10 @@ class EnhancedChangesList extends ChangesList {
                if ( $logType ) {
                        # Log entry
                        $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
-                                       . $logType . '-' . $rcObj->mAttribs['rc_title'] );
+                               . $logType . '-' . $rcObj->mAttribs['rc_title'] );
                } else {
                        $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' .
-                                       $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
+                               $rcObj->mAttribs['rc_namespace'] . '-' . $rcObj->mAttribs['rc_title'] );
                }
                $classes[] = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
                        ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
@@ -580,19 +611,21 @@ class EnhancedChangesList extends ChangesList {
                        $logPage = new LogPage( $logType );
                        $logTitle = SpecialPage::getTitleFor( 'Log', $logType );
                        $logName = $logPage->getName()->escaped();
-                       $r .= $this->msg( 'parentheses' )->rawParams( Linker::linkKnown( $logTitle, $logName ) )->escaped();
+                       $r .= $this->msg( 'parentheses' )
+                               ->rawParams( Linker::linkKnown( $logTitle, $logName ) )->escaped();
                } else {
                        $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
                }
                # Diff and hist links
                if ( $type != RC_LOG ) {
                        $query['action'] = 'history';
-                       $r .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->difflink . $this->message['pipe-separator'] . Linker::linkKnown(
-                               $rcObj->getTitle(),
-                               $this->message['hist'],
-                               array(),
-                               $query
-                       ) )->escaped();
+                       $r .= ' ' . $this->msg( 'parentheses' )
+                               ->rawParams( $rcObj->difflink . $this->message['pipe-separator'] . Linker::linkKnown(
+                                       $rcObj->getTitle(),
+                                       $this->message['hist'],
+                                       array(),
+                                       $query
+                               ) )->escaped();
                }
                $r .= ' <span class="mw-changeslist-separator">. .</span> ';
                # Character diff
@@ -630,7 +663,7 @@ class EnhancedChangesList extends ChangesList {
         * @return string
         */
        protected function recentChangesBlock() {
-               if ( count ( $this->rc_cache ) == 0 ) {
+               if ( count( $this->rc_cache ) == 0 ) {
                        return '';
                }
 
@@ -658,5 +691,4 @@ class EnhancedChangesList extends ChangesList {
        public function endRecentChangesList() {
                return $this->recentChangesBlock() . parent::endRecentChangesList();
        }
-
 }