RCFilters: Move aggregation of highlight classes to the backend
authorRoan Kattouw <roan.kattouw@gmail.com>
Tue, 26 Jun 2018 23:52:59 +0000 (16:52 -0700)
committerRoan Kattouw <roan.kattouw@gmail.com>
Wed, 27 Jun 2018 00:55:50 +0000 (17:55 -0700)
Construction of the highlight containers was moved to the backend, but
setupHighlightContainers() also aggregates the CSS classes used for
highlights for grouped entries in enhanced mode.

Move that to the backend too, and get rid of setupHighlightContainers().

Also move the namespace classes to getHTMLClassesForFilters() so that
they get picked up too, and pick up classes for tags separately because
the way they're handled is weird.

Bug: T197168
Change-Id: I4c374f82e7d128025f4e2b2f39b0adba14b76ef3

includes/changes/ChangesList.php
includes/changes/EnhancedChangesList.php
includes/templates/EnhancedChangesListGroup.mustache
resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.ChangesListWrapperWidget.js

index 0bf3eb4..57c4026 100644 (file)
@@ -208,8 +208,6 @@ class ChangesList extends ContextSource {
                        $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns' .
                                $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
                }
-               $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
-                       $rc->mAttribs['rc_namespace'] );
 
                // Indicate watched status on the line to allow for more
                // comprehensive styling.
@@ -223,7 +221,8 @@ class ChangesList extends ContextSource {
        }
 
        /**
-        * Get an array of CSS classes attributed to filters for this row
+        * Get an array of CSS classes attributed to filters for this row. Used for highlighting
+        * in the front-end.
         *
         * @param RecentChange $rc
         * @return array Array of CSS classes
@@ -231,6 +230,9 @@ class ChangesList extends ContextSource {
        protected function getHTMLClassesForFilters( $rc ) {
                $classes = [];
 
+               $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
+                       $rc->mAttribs['rc_namespace'] );
+
                if ( $this->filterGroups !== null ) {
                        foreach ( $this->filterGroups as $filterGroup ) {
                                foreach ( $filterGroup->getFilters() as $filter ) {
index 0c56fdd..ada02ce 100644 (file)
@@ -266,6 +266,7 @@ class EnhancedChangesList extends ChangesList {
 
                # Sub-entries
                $lines = [];
+               $filterClasses = [];
                foreach ( $block as $i => $rcObj ) {
                        $line = $this->getLineData( $block, $rcObj, $queryParams );
                        if ( !$line ) {
@@ -293,12 +294,19 @@ class EnhancedChangesList extends ChangesList {
                                }
                        }
 
+                       // Roll up filter-based CSS classes
+                       $filterClasses = array_merge( $filterClasses, $this->getHTMLClassesForFilters( $rcObj ) );
+                       // Add classes for change tags separately, getHTMLClassesForFilters() doesn't add them
+                       $this->getTags( $rcObj, $filterClasses );
+                       $filterClasses = array_unique( $filterClasses );
+
                        $lines[] = $line;
                }
 
                // 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 );
+               $filterClasses = array_values( $filterClasses );
 
                if ( empty( $block ) || !$lines ) {
                        // if we can't show anything, don't display this block altogether
@@ -339,6 +347,7 @@ class EnhancedChangesList extends ChangesList {
                        'articleLink' => $articleLink,
                        'charDifference' => $charDifference,
                        'collectedRcFlags' => $this->recentChangesFlags( $collectedRcFlags ),
+                       'filterClasses' => $filterClasses,
                        'languageDirMark' => $this->getLanguage()->getDirMark(),
                        'lines' => $lines,
                        'logText' => $logText,
index 24f0613..e41a98b 100644 (file)
@@ -1,5 +1,5 @@
 <table class="{{# tableClasses }}{{ . }} {{/ tableClasses }}" data-mw-ts="{{{ fullTimestamp }}}">
-       <tr class="mw-rcfilters-ui-highlights-enhanced-toplevel">
+       <tr class="mw-rcfilters-ui-highlights-enhanced-toplevel {{# filterClasses }}{{ . }} {{/ filterClasses }}">
                <td>
                        <div class="mw-rcfilters-ui-highlights">
                                <div class="mw-rcfilters-ui-highlights-color-none" data-color="none"></div>
index ec3fe31..94b2505 100644 (file)
         */
        mw.rcfilters.ui.ChangesListWrapperWidget.prototype.onFiltersModelInitialize = function () {
                this.filtersModelInitialized = true;
-               // Set up highlight containers. We need to wait for the filters model
-               // to be initialized, so we can make sure we have all the css class definitions
-               // we get from the server with our filters
-               this.setupHighlightContainers( this.$element );
        };
 
        /**
                                }
                        }
 
-                       // Set up highlight containers
-                       this.setupHighlightContainers( this.$element );
-
                        // Apply highlight
                        this.applyHighlight();
 
                        .fadeIn( 1000 );
        };
 
-       /**
-        * Set up the highlight containers with all color circle indicators.
-        *
-        * @param {jQuery|string} $content The content of the updated changes list
-        */
-       mw.rcfilters.ui.ChangesListWrapperWidget.prototype.setupHighlightContainers = function ( $content ) {
-               var $enhancedTopPageCell,
-                       widget = this;
-
-               if ( this.inEnhancedMode() ) {
-                       $enhancedTopPageCell = $content.find( 'table.mw-enhanced-rc.mw-collapsible' );
-                       // Go over pages that have sub results
-                       // HACK: We really only can collect those by targetting the collapsible class
-                       $enhancedTopPageCell.each( function () {
-                               var collectedClasses,
-                                       $table = $( this );
-
-                               // Go over <tr>s and pick up all recognized classes
-                               collectedClasses = widget.getHighlightClasses().filter( function ( className ) {
-                                       return $table.find( 'tr' ).hasClass( className );
-                               } );
-
-                               $table.find( 'tr:first-child' )
-                                       .addClass( collectedClasses.join( ' ' ) );
-                       } );
-               }
-       };
-
        /**
         * In enhanced mode, we need to check whether the grouped results all have the
         * same active highlights in order to see whether the "parent" of the group should