Merge "Show protection log on creation-protected pages"
[lhc/web/wiklou.git] / includes / changes / EnhancedChangesList.php
index 1a2da1a..55cb9ed 100644 (file)
@@ -98,20 +98,21 @@ class EnhancedChangesList extends ChangesList {
         * @return string
         */
        public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
-
                $date = $this->getLanguage()->userDate(
                        $rc->mAttribs['rc_timestamp'],
                        $this->getUser()
                );
+               if ( $this->lastdate === '' ) {
+                       $this->lastdate = $date;
+               }
 
                $ret = '';
 
-               # If it's a new day, add the headline and flush the cache
-               if ( $date != $this->lastdate ) {
-                       # Process current cache
+               # If it's a new day, flush the cache and update $this->lastdate
+               if ( $date !== $this->lastdate ) {
+                       # Process current cache (uses $this->lastdate to generate a heading)
                        $ret = $this->recentChangesBlock();
                        $this->rc_cache = [];
-                       $ret .= Xml::element( 'h4', null, $date ) . "\n";
                        $this->lastdate = $date;
                }
 
@@ -243,8 +244,7 @@ class EnhancedChangesList extends ChangesList {
                        $text = $userlink;
                        $text .= $this->getLanguage()->getDirMark();
                        if ( $count > 1 ) {
-                               // @todo FIXME: Hardcoded '×'. Should be a message.
-                               $formattedCount = $this->getLanguage()->formatNum( $count ) . '×';
+                               $formattedCount = $this->msg( 'ntimes' )->numParams( $count )->escaped();
                                $text .= ' ' . $this->msg( 'parentheses' )->rawParams( $formattedCount )->escaped();
                        }
                        array_push( $users, $text );
@@ -447,13 +447,16 @@ class EnhancedChangesList extends ChangesList {
                # Tags
                $data['tags'] = $this->getTags( $rcObj, $classes );
 
+               $attribs = $this->getDataAttributes( $rcObj );
+
                // give the hook a chance to modify the data
                $success = Hooks::run( 'EnhancedChangesListModifyLineData',
-                       [ $this, &$data, $block, $rcObj, &$classes ] );
+                       [ $this, &$data, $block, $rcObj, &$classes, &$attribs ] );
                if ( !$success ) {
                        // skip entry if hook aborted it
                        return [];
                }
+               $attribs = wfArrayFilterByKey( $attribs, [ Sanitizer::class, 'isReservedDataAttribute' ] );
 
                $lineParams['recentChangesFlagsRaw'] = [];
                if ( isset( $data['recentChangesFlags'] ) ) {
@@ -469,6 +472,7 @@ class EnhancedChangesList extends ChangesList {
                }
 
                $lineParams['classes'] = array_values( $classes );
+               $lineParams['attribs'] = Html::expandAttributes( $attribs );
 
                // everything else: makes it easier for extensions to add or remove data
                $lineParams['data'] = array_values( $data );
@@ -671,6 +675,8 @@ class EnhancedChangesList extends ChangesList {
                # Show how many people are watching this if enabled
                $data['watchingUsers'] = $this->numberofWatchingusers( $rcObj->numberofWatchingusers );
 
+               $data['attribs'] = array_merge( $this->getDataAttributes( $rcObj ), [ 'class' => $classes ] );
+
                // give the hook a chance to modify the data
                $success = Hooks::run( 'EnhancedChangesListModifyBlockLineData',
                        [ $this, &$data, $rcObj ] );
@@ -678,9 +684,13 @@ class EnhancedChangesList extends ChangesList {
                        // skip entry if hook aborted it
                        return '';
                }
+               $attribs = $data['attribs'];
+               unset( $data['attribs'] );
+               $attribs = wfArrayFilterByKey( $attribs, function ( $key ) {
+                       return $key === 'class' || Sanitizer::isReservedDataAttribute( $key );
+               } );
 
-               $line = Html::openElement( 'table', [ 'class' => $classes ] ) .
-                       Html::openElement( 'tr' );
+               $line = Html::openElement( 'table', $attribs ) . Html::openElement( 'tr' );
                $line .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
 
                if ( isset( $data['recentChangesFlags'] ) ) {
@@ -717,6 +727,11 @@ class EnhancedChangesList extends ChangesList {
                if ( $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) {
                        // For categorizations we must swap the category title with the page title!
                        $pageTitle = Title::newFromID( $rc->getAttribute( 'rc_cur_id' ) );
+                       if ( !$pageTitle ) {
+                               // The page has been deleted, but the RC entry
+                               // deletion job has not run yet. Just skip.
+                               return '';
+                       }
                }
 
                $retVal = ' ' . $this->msg( 'parentheses' )
@@ -750,7 +765,11 @@ class EnhancedChangesList extends ChangesList {
                        }
                }
 
-               return '<div>' . $blockOut . '</div>';
+               if ( $blockOut === '' ) {
+                       return '';
+               }
+               // $this->lastdate is kept up to date by recentChangesLine()
+               return Xml::element( 'h4', null, $this->lastdate ) . "\n<div>" . $blockOut . '</div>';
        }
 
        /**