RecentChanges updated to use pseudo elements for presentation
authorjdlrobson <jdlrobson@gmail.com>
Wed, 27 Mar 2019 00:35:01 +0000 (17:35 -0700)
committerRoan Kattouw <roan.kattouw@gmail.com>
Tue, 2 Apr 2019 21:52:50 +0000 (14:52 -0700)
Bug: T219348
Change-Id: I6eeeaa3b58d37adb7fefb4cc6915022229b3b324

includes/Linker.php
includes/changes/ChangesList.php
includes/changes/EnhancedChangesList.php
includes/changes/RCCacheEntryFactory.php
includes/logging/LogFormatter.php
includes/templates/EnhancedChangesListGroup.mustache
tests/phpunit/includes/changes/EnhancedChangesListTest.php
tests/phpunit/includes/changes/RCCacheEntryFactoryTest.php

index 17dc037..4f0ab6a 100644 (file)
@@ -1001,7 +1001,7 @@ class Linker {
         * @return string
         */
        public static function userToolLinksRedContribs( $userId, $userText, $edits = null ) {
-               return self::userToolLinks( $userId, $userText, true, 0, $edits );
+               return self::userToolLinks( $userId, $userText, true, 0, $edits, false );
        }
 
        /**
index 2389997..184a2c1 100644 (file)
@@ -617,7 +617,13 @@ class ChangesList extends ContextSource {
                        return ' <span class="history-deleted">' .
                                $this->msg( 'rev-deleted-comment' )->escaped() . '</span>';
                } else {
-                       return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
+                       return Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle(),
+                               // Whether section links should refer to local page (using default false)
+                               false,
+                               // wikid to generate links for (using default null) */
+                               null,
+                               // whether parentheses should be rendered as part of the message
+                               false );
                }
        }
 
index 3e98f65..8186059 100644 (file)
@@ -393,7 +393,7 @@ class EnhancedChangesList extends ChangesList {
                }
                $classes = array_merge( $classes, $this->getHTMLClasses( $rcObj, $rcObj->watched ) );
 
-               $separator = ' <span class="mw-changeslist-separator">. .</span> ';
+               $separator = ' <span class="mw-changeslist-separator"></span> ';
 
                $data['recentChangesFlags'] = [
                        'newpage' => $type == RC_NEW,
@@ -556,19 +556,22 @@ class EnhancedChangesList extends ChangesList {
                                $isnew ||
                                $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE
                        ) {
-                               $links['total-changes'] = $nchanges[$n];
+                               $links['total-changes'] = Html::rawElement( 'span', [], $nchanges[$n] );
                        } else {
-                               $links['total-changes'] = $this->linkRenderer->makeKnownLink(
-                                       $block0->getTitle(),
-                                       new HtmlArmor( $nchanges[$n] ),
-                                       [ 'class' => 'mw-changeslist-groupdiff' ],
-                                       $queryParams + [
-                                               'diff' => $currentRevision,
-                                               'oldid' => $last->mAttribs['rc_last_oldid'],
-                                       ]
+                               $links['total-changes'] = Html::rawElement( 'span', [],
+                                       $this->linkRenderer->makeKnownLink(
+                                               $block0->getTitle(),
+                                               new HtmlArmor( $nchanges[$n] ),
+                                               [ 'class' => 'mw-changeslist-groupdiff' ],
+                                               $queryParams + [
+                                                       'diff' => $currentRevision,
+                                                       'oldid' => $last->mAttribs['rc_last_oldid'],
+                                               ]
+                                       )
                                );
                                if ( $sinceLast > 0 && $sinceLast < $n ) {
-                                       $links['total-changes-since-last'] = $this->linkRenderer->makeKnownLink(
+                                       $links['total-changes-since-last'] = Html::rawElement( 'span', [],
+                                               $this->linkRenderer->makeKnownLink(
                                                        $block0->getTitle(),
                                                        new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
                                                        [ 'class' => 'mw-changeslist-groupdiff' ],
@@ -576,7 +579,8 @@ class EnhancedChangesList extends ChangesList {
                                                                'diff' => $currentRevision,
                                                                'oldid' => $unvisitedOldid,
                                                        ]
-                                               );
+                                               )
+                                       );
                                }
                        }
                }
@@ -585,17 +589,19 @@ class EnhancedChangesList extends ChangesList {
                if ( $allLogs || $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE ) {
                        // don't show history link for logs
                } elseif ( $namehidden || !$block0->getTitle()->exists() ) {
-                       $links['history'] = $this->message['enhancedrc-history'];
+                       $links['history'] = Html::rawElement( 'span', [], $this->message['enhancedrc-history'] );
                } else {
                        $params = $queryParams;
                        $params['action'] = 'history';
 
-                       $links['history'] = $this->linkRenderer->makeKnownLink(
+                       $links['history'] = Html::rawElement( 'span', [],
+                               $this->linkRenderer->makeKnownLink(
                                        $block0->getTitle(),
                                        new HtmlArmor( $this->message['enhancedrc-history'] ),
                                        [ 'class' => 'mw-changeslist-history' ],
                                        $params
-                               );
+                               )
+                       );
                }
 
                # Allow others to alter, remove or add to these links
@@ -606,8 +612,8 @@ class EnhancedChangesList extends ChangesList {
                        return '';
                }
 
-               $logtext = implode( $this->message['pipe-separator'], $links );
-               $logtext = $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
+               $logtext = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ],
+                       implode( ' ', $links ) );
                return ' ' . $logtext;
        }
 
@@ -653,10 +659,9 @@ class EnhancedChangesList extends ChangesList {
                        $logPage = new LogPage( $logType );
                        $logTitle = SpecialPage::getTitleFor( 'Log', $logType );
                        $logName = $logPage->getName()->text();
-                       $data['logLink'] = $this->msg( 'parentheses' )
-                               ->rawParams(
-                                       $this->linkRenderer->makeKnownLink( $logTitle, $logName )
-                               )->escaped();
+                       $data['logLink'] = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ],
+                               $this->linkRenderer->makeKnownLink( $logTitle, $logName )
+                       );
                } else {
                        $data['articleLink'] = $this->getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
                }
@@ -664,16 +669,16 @@ class EnhancedChangesList extends ChangesList {
                # Diff and hist links
                if ( $type != RC_LOG && $type != RC_CATEGORIZE ) {
                        $query['action'] = 'history';
-                       $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
+                       $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query, false );
                }
-               $data['separatorAfterLinks'] = ' <span class="mw-changeslist-separator">. .</span> ';
+               $data['separatorAfterLinks'] = ' <span class="mw-changeslist-separator"></span> ';
 
                # Character diff
                if ( $this->getConfig()->get( 'RCShowChangedSize' ) ) {
                        $cd = $this->formatCharacterDifference( $rcObj );
                        if ( $cd !== '' ) {
                                $data['characterDiff'] = $cd;
-                               $data['separatorAftercharacterDiff'] = ' <span class="mw-changeslist-separator">. .</span> ';
+                               $data['separatorAftercharacterDiff'] = ' <span class="mw-changeslist-separator"></span> ';
                        }
                }
 
@@ -686,7 +691,7 @@ class EnhancedChangesList extends ChangesList {
                        $data['userTalkLink'] = $rcObj->usertalklink;
                        $data['comment'] = $this->insertComment( $rcObj );
                        if ( $type == RC_CATEGORIZE ) {
-                               $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
+                               $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query, false );
                        }
                        $data['rollback'] = $this->getRollback( $rcObj );
                }
@@ -744,7 +749,11 @@ class EnhancedChangesList extends ChangesList {
                ] );
 
                // everything else: makes it easier for extensions to add or remove data
-               $line .= implode( '', $data );
+               foreach ( $data as $key => $dataItem ) {
+                       $line .= Html::rawElement( 'span', [
+                               'class' => 'mw-changeslist-line-inner-' . $key,
+                       ], $dataItem );
+               }
 
                $line .= "</td></tr></table>\n";
 
@@ -759,9 +768,10 @@ class EnhancedChangesList extends ChangesList {
         *
         * @param RCCacheEntry $rc
         * @param array $query array of key/value pairs to append as a query string
+        * @param bool $useParentheses (optional) Wrap comments in parentheses where needed
         * @return string HTML
         */
-       public function getDiffHistLinks( RCCacheEntry $rc, array $query ) {
+       public function getDiffHistLinks( RCCacheEntry $rc, array $query, $useParentheses = true ) {
                $pageTitle = $rc->getTitle();
                if ( $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) {
                        // For categorizations we must swap the category title with the page title!
@@ -773,15 +783,23 @@ class EnhancedChangesList extends ChangesList {
                        }
                }
 
-               $retVal = ' ' . $this->msg( 'parentheses' )
-                               ->rawParams( $rc->difflink . $this->message['pipe-separator']
-                                       . $this->linkRenderer->makeKnownLink(
-                                               $pageTitle,
-                                               new HtmlArmor( $this->message['hist'] ),
-                                               [ 'class' => 'mw-changeslist-history' ],
-                                               $query
-                                       ) )->escaped();
-               return $retVal;
+               $histLink = $this->linkRenderer->makeKnownLink(
+                       $pageTitle,
+                       new HtmlArmor( $this->message['hist'] ),
+                       [ 'class' => 'mw-changeslist-history' ],
+                       $query
+               );
+               if ( $useParentheses ) {
+                       $retVal = $this->msg( 'parentheses' )
+                       ->rawParams( $rc->difflink . $this->message['pipe-separator']
+                               . $histLink )->escaped();
+               } else {
+                       $retVal = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ],
+                               Html::rawElement( 'span', [], $rc->difflink ) .
+                               Html::rawElement( 'span', [], $histLink )
+                       );
+               }
+               return ' ' . $retVal;
        }
 
        /**
index e8c3a99..2d60ca2 100644 (file)
@@ -82,7 +82,15 @@ class RCCacheEntryFactory {
                if ( !ChangesList::isDeleted( $cacheEntry, Revision::DELETED_USER ) ) {
                        $cacheEntry->usertalklink = Linker::userToolLinks(
                                $cacheEntry->mAttribs['rc_user'],
-                               $cacheEntry->mAttribs['rc_user_text']
+                               $cacheEntry->mAttribs['rc_user_text'],
+                               // Should the contributions link be red if the user has no edits (using default)
+                               false,
+                               // Customisation flags (using default 0)
+                               0,
+                               // User edit count (using default )
+                               null,
+                               // do not wrap the message in parentheses
+                               false
                        );
                }
 
index 6d45ed5..1f37a35 100644 (file)
@@ -762,7 +762,9 @@ class LogFormatter {
                                        $user->getName(),
                                        true, // redContribsWhenNoEdits
                                        $toolFlags,
-                                       $user->getEditCount()
+                                       $user->getEditCount(),
+                                       // do not render parenthesises in the HTML markup (CSS will provide)
+                                       false
                                );
                        }
                }
index 6d9d6b0..5a5986f 100644 (file)
@@ -16,8 +16,8 @@
                <td class="mw-changeslist-line-inner">
                        {{# rev-deleted-event }}<span class="history-deleted">{{{ . }}}</span>{{/ rev-deleted-event }}
                        {{{ articleLink }}}{{{ languageDirMark }}}{{{ logText }}}
-                       <span class="mw-changeslist-separator">. .</span>
-                       {{# charDifference }}{{{ . }}} <span class="mw-changeslist-separator">. .</span>{{/ charDifference }}
+                       <span class="mw-changeslist-separator"></span>
+                       {{# charDifference }}{{{ . }}} <span class="mw-changeslist-separator"></span>{{/ charDifference }}
                        <span class="changedby">{{{ users }}}</span>
                        {{ numberofWatchingusers }}
                </td>
index eff2c85..1511d46 100644 (file)
@@ -124,14 +124,14 @@ class EnhancedChangesListTest extends MediaWikiLangTestCase {
                $html = $this->createCategorizationLine(
                        $this->getCategorizationChange( '20150629191735', 0, 0 )
                );
-               $this->assertNotContains( '(diff | hist)', strip_tags( $html ) );
+               $this->assertNotContains( 'diffhist', strip_tags( $html ) );
        }
 
        public function testCategorizationLineFormattingWithRevision() {
                $html = $this->createCategorizationLine(
                        $this->getCategorizationChange( '20150629191735', 1025, 1024 )
                );
-               $this->assertContains( '(diff | hist)', strip_tags( $html ) );
+               $this->assertContains( 'diffhist', strip_tags( $html ) );
        }
 
        /**
index b1857cc..8f914b7 100644 (file)
@@ -156,14 +156,15 @@ class RCCacheEntryFactoryTest extends MediaWikiLangTestCase {
 
                $this->assertValidHTML( $cacheEntry->usertalklink );
                $this->assertRegExp(
-                       '#^ <span class="mw-usertoollinks">\(.*<a .+>talk</a>.*\)</span>#',
+                       '#^ <span class="mw-usertoollinks mw-changeslist-links">.*<span><a .+>talk</a></span>.*</span>#',
                        $cacheEntry->usertalklink,
                        'verify user talk link'
                );
 
                $this->assertValidHTML( $cacheEntry->usertalklink );
                $this->assertRegExp(
-                       '#^ <span class="mw-usertoollinks">\(.*<a .+>contribs</a>.*\)</span>$#',
+                       '#^ <span class="mw-usertoollinks mw-changeslist-links">.*<span><a .+>' .
+                               'contribs</a></span>.*</span>$#',
                        $cacheEntry->usertalklink,
                        'verify user tool links'
                );