From: Roan Kattouw Date: Tue, 26 Jun 2018 23:52:59 +0000 (-0700) Subject: RCFilters: Move aggregation of highlight classes to the backend X-Git-Tag: 1.34.0-rc.0~4938^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=39163edd17e0cc3ec7d87f9e3ac942e995d56326;p=lhc%2Fweb%2Fwiklou.git RCFilters: Move aggregation of highlight classes to the backend 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 --- diff --git a/includes/changes/ChangesList.php b/includes/changes/ChangesList.php index 0bf3eb45c6..57c4026763 100644 --- a/includes/changes/ChangesList.php +++ b/includes/changes/ChangesList.php @@ -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 ) { diff --git a/includes/changes/EnhancedChangesList.php b/includes/changes/EnhancedChangesList.php index 0c56fdd1d5..ada02ce081 100644 --- a/includes/changes/EnhancedChangesList.php +++ b/includes/changes/EnhancedChangesList.php @@ -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, diff --git a/includes/templates/EnhancedChangesListGroup.mustache b/includes/templates/EnhancedChangesListGroup.mustache index 24f06135d1..e41a98bf1c 100644 --- a/includes/templates/EnhancedChangesListGroup.mustache +++ b/includes/templates/EnhancedChangesListGroup.mustache @@ -1,5 +1,5 @@ - + 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
diff --git a/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.ChangesListWrapperWidget.js b/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.ChangesListWrapperWidget.js index ec3fe31f17..94b25053f9 100644 --- a/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.ChangesListWrapperWidget.js +++ b/resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.ChangesListWrapperWidget.js @@ -59,10 +59,6 @@ */ 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 ); }; /** @@ -179,9 +175,6 @@ } } - // Set up highlight containers - this.setupHighlightContainers( this.$element ); - // Apply highlight this.applyHighlight(); @@ -266,34 +259,6 @@ .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