When aborting EnhancedRC block line, block should reflect that
authorMatthias Mullie <mmullie@wikimedia.org>
Wed, 16 Sep 2015 10:44:04 +0000 (10:44 +0000)
committerMatthias Mullie <git@mullie.eu>
Wed, 16 Sep 2015 10:46:44 +0000 (12:46 +0200)
It was possible to abort the rendering of all block lines, but
the block would still be rendered (with nothing inside). It
would also render a "x changes" link, even though that "x" is
no longer correct.

This had been reverted in adba11dfe332c4c10dbbf0f817982d4a225de6b1,
but has now been fixed up.

Change-Id: Ic5d15e56bc2f46fa6aa8c9375f3cafeb13e1ea9c

includes/changes/EnhancedChangesList.php

index 9635c17..1a02a97 100644 (file)
@@ -270,6 +270,20 @@ class EnhancedChangesList extends ChangesList {
 
                $queryParams['curid'] = $curId;
 
+               # Sub-entries
+               $lines = '';
+               foreach ( $block as $i => $rcObj ) {
+                       $line = $this->getLineData( $block, $rcObj, $queryParams );
+                       $lines .= $line;
+                       if ( !$line ) {
+                               // completely ignore this RC entry if we don't want to render it
+                               unset( $block[$i] );
+                       }
+               }
+               // Further down are some assumptions that $block is a 0-indexed array
+               // with (count-1) as last key. Let's make sure it is.
+               $block = array_values( $block );
+
                $r .= $this->getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden );
 
                $r .= ' <span class="mw-changeslist-separator">. .</span> ';
@@ -299,116 +313,133 @@ class EnhancedChangesList extends ChangesList {
                $r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers );
                $r .= '</td></tr>';
 
-               # Sub-entries
-               foreach ( $block as $rcObj ) {
-                       # Classes to apply -- TODO implement
-                       $classes = array();
-                       $type = $rcObj->mAttribs['rc_type'];
-                       $data = array();
-
-                       $trClass = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
-                               ? ' class="mw-enhanced-watched"' : '';
-                       $separator = ' <span class="mw-changeslist-separator">. .</span> ';
-
-                       $data['recentChangesFlags'] = array(
-                               'newpage' => $type == RC_NEW,
-                               'minor' => $rcObj->mAttribs['rc_minor'],
-                               'unpatrolled' => $rcObj->unpatrolled,
-                               'bot' => $rcObj->mAttribs['rc_bot'],
-                       );
+               if ( !$lines ) {
+                       // if there are no lines to be rendered (all aborted by hook), don't render the block
+                       return '';
+               }
 
-                       $params = $queryParams;
+               $r .= $lines;
+               $r .= "</table>\n";
 
-                       if ( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
-                               $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
-                       }
+               $this->rcCacheIndex++;
+
+               return $r;
+       }
 
-                       # Log timestamp
-                       if ( $type == RC_LOG ) {
-                               $link = $rcObj->timestamp;
+       /**
+        * @param RCCacheEntry[] $block
+        * @param RCCacheEntry $rcObj
+        * @param array $queryParams
+        * @return string
+        * @throws Exception
+        * @throws FatalError
+        * @throws MWException
+        */
+       protected function getLineData( array $block, RCCacheEntry $rcObj, array $queryParams = array() ) {
+               $RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' );
+
+               # Classes to apply -- TODO implement
+               $classes = array();
+               $type = $rcObj->mAttribs['rc_type'];
+               $data = array();
+
+               $trClass = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
+                       ? ' class="mw-enhanced-watched"' : '';
+               $separator = ' <span class="mw-changeslist-separator">. .</span> ';
+
+               $data['recentChangesFlags'] = array(
+                       'newpage' => $type == RC_NEW,
+                       'minor' => $rcObj->mAttribs['rc_minor'],
+                       'unpatrolled' => $rcObj->unpatrolled,
+                       'bot' => $rcObj->mAttribs['rc_bot'],
+               );
+
+               $params = $queryParams;
+
+               if ( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
+                       $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
+               }
+
+               # Log timestamp
+               if ( $type == RC_LOG ) {
+                       $link = $rcObj->timestamp;
                        # Revision link
-                       } elseif ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
-                               $link = '<span class="history-deleted">' . $rcObj->timestamp . '</span> ';
-                       } else {
-                               $link = Linker::linkKnown(
-                                       $rcObj->getTitle(),
-                                       $rcObj->timestamp,
-                                       array(),
-                                       $params
-                               );
-                               if ( $this->isDeleted( $rcObj, Revision::DELETED_TEXT ) ) {
-                                       $link = '<span class="history-deleted">' . $link . '</span> ';
-                               }
+               } elseif ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
+                       $link = '<span class="history-deleted">' . $rcObj->timestamp . '</span> ';
+               } else {
+                       $link = Linker::linkKnown(
+                               $rcObj->getTitle(),
+                               $rcObj->timestamp,
+                               array(),
+                               $params
+                       );
+                       if ( $this->isDeleted( $rcObj, Revision::DELETED_TEXT ) ) {
+                               $link = '<span class="history-deleted">' . $link . '</span> ';
                        }
-                       $data['timestampLink'] = $link;
+               }
+               $data['timestampLink'] = $link;
 
-                       $currentAndLastLinks = '';
-                       if ( !$type == RC_LOG || $type == RC_NEW ) {
-                               $currentAndLastLinks .= ' ' . $this->msg( 'parentheses' )->rawParams(
+               $currentAndLastLinks = '';
+               if ( !$type == RC_LOG || $type == RC_NEW ) {
+                       $currentAndLastLinks .= ' ' . $this->msg( 'parentheses' )->rawParams(
                                        $rcObj->curlink .
-                                               $this->message['pipe-separator'] .
-                                               $rcObj->lastlink
+                                       $this->message['pipe-separator'] .
+                                       $rcObj->lastlink
                                )->escaped();
-                       }
-                       $data['currentAndLastLinks'] = $currentAndLastLinks;
-                       $data['separatorAfterCurrentAndLastLinks'] = $separator;
-
-                       # Character diff
-                       if ( $RCShowChangedSize ) {
-                               $cd = $this->formatCharacterDifference( $rcObj );
-                               if ( $cd !== '' ) {
-                                       $data['characterDiff'] = $cd;
-                                       $data['separatorAfterCharacterDiff'] = $separator;
-                               }
-                       }
+               }
+               $data['currentAndLastLinks'] = $currentAndLastLinks;
+               $data['separatorAfterCurrentAndLastLinks'] = $separator;
 
-                       if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
-                               $data['logEntry'] = $this->insertLogEntry( $rcObj );
-                       } else {
-                               # User links
-                               $data['userLink'] = $rcObj->userlink;
-                               $data['userTalkLink'] = $rcObj->usertalklink;
-                               $data['comment'] = $this->insertComment( $rcObj );
+               # Character diff
+               if ( $RCShowChangedSize ) {
+                       $cd = $this->formatCharacterDifference( $rcObj );
+                       if ( $cd !== '' ) {
+                               $data['characterDiff'] = $cd;
+                               $data['separatorAfterCharacterDiff'] = $separator;
                        }
+               }
 
-                       # Rollback
-                       $data['rollback'] = $this->getRollback( $rcObj );
-
-                       # Tags
-                       $data['tags'] = $this->getTags( $rcObj, $classes );
-
-                       // give the hook a chance to modify the data
-                       $success = Hooks::run( 'EnhancedChangesListModifyLineData',
-                               array( $this, &$data, $block, $rcObj ) );
-                       if ( !$success ) {
-                               // skip entry if hook aborted it
-                               continue;
-                       }
+               if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
+                       $data['logEntry'] = $this->insertLogEntry( $rcObj );
+               } else {
+                       # User links
+                       $data['userLink'] = $rcObj->userlink;
+                       $data['userTalkLink'] = $rcObj->usertalklink;
+                       $data['comment'] = $this->insertComment( $rcObj );
+               }
 
-                       $line = '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
-                       if ( isset( $data['recentChangesFlags'] ) ) {
-                               $line .= $this->recentChangesFlags( $data['recentChangesFlags'] );
-                               unset( $data['recentChangesFlags'] );
-                       }
-                       $line .= '&#160;</td><td class="mw-enhanced-rc-nested">';
+               # Rollback
+               $data['rollback'] = $this->getRollback( $rcObj );
 
-                       if ( isset( $data['timestampLink'] ) ) {
-                               $line .= '<span class="mw-enhanced-rc-time">' . $data['timestampLink'] . '</span>';
-                               unset( $data['timestampLink'] );
-                       }
+               # Tags
+               $data['tags'] = $this->getTags( $rcObj, $classes );
 
-                       // everything else: makes it easier for extensions to add or remove data
-                       $line .= implode( '', $data );
+               // give the hook a chance to modify the data
+               $success = Hooks::run( 'EnhancedChangesListModifyLineData',
+                       array( $this, &$data, $block, $rcObj ) );
+               if ( !$success ) {
+                       // skip entry if hook aborted it
+                       return '';
+               }
 
-                       $line .= "</td></tr>\n";
+               $line = '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
+               if ( isset( $data['recentChangesFlags'] ) ) {
+                       $line .= $this->recentChangesFlags( $data['recentChangesFlags'] );
+                       unset( $data['recentChangesFlags'] );
+               }
+               $line .= '&#160;</td><td class="mw-enhanced-rc-nested">';
 
-                       $r .= $line;
+               if ( isset( $data['timestampLink'] ) ) {
+                       $line .= '<span class="mw-enhanced-rc-time">' . $data['timestampLink'] . '</span>';
+                       unset( $data['timestampLink'] );
                }
-               $r .= "</table>\n";
 
-               $this->rcCacheIndex++;
+               // everything else: makes it easier for extensions to add or remove data
+               $line .= implode( '', $data );
 
-               return $r;
+               $line .= "</td></tr>\n";
+
+               return $line;
        }
 
        /**