Mooeypoo has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/332932 )
Change subject: RCFilters UI: Hide implemented filters from existing static list ...................................................................... RCFilters UI: Hide implemented filters from existing static list This is a bit of a hack until a better, more consistent loading mechanism can be figured out. For now, the existing Special:RecentChanges has filters that are implemented in the new RCFilters system and some that are not. We want to hide the filters that already appear in the RCFilters popup but leave the ones that aren't, whether they are base filters or come from an extension. If we hide individual <span> elements for implemented filters, we end up with a string of "| | | | " which are a pain to get rid of. Instead, this method steals the jQuery object of the current filters, and goes over each one to see if it can recognize its existence. If the filter is recognized, it's skipped. If it's unrecognized, its span element is shoved back into the group, and will be displayed. Enjoy. Change-Id: I501e69c1cbc22755710007d13bfc6a1daea9404b --- M resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js M resources/src/mediawiki.rcfilters/mw.rcfilters.init.js M resources/src/mediawiki.rcfilters/styles/mw.rcfilters.less 3 files changed, 71 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/32/332932/1 diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js index ea44b8b..95da0da 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js @@ -27,6 +27,66 @@ }; /** + * Take the existing static filter list and rebuild it so that only + * filters that are not reimplemented as filters in the current system + * are appearing. + * + * This method expects the jQuery object of the children() of static + * Special:RecentChanges under the span.rcshowhide block, and will return + * a suitable element to replace its contents. + * + * HACK: This entire method is a hack, to make sure that existing filters that + * are not implemented yet are still visible and operable to the user, but + * filters that are implemented in the new system aren't. Just hiding the + * spans of those filters creates a very ugly string that includes multiple + * pipes (" | | | | existing filter") so this method rebuilds the structure + * using only the relevant non-implemented filters, preserving current view. + * + * NOTE: Since the entire method is one big hack, individual "HACK!" comments + * were spared below. To the observant pedantic reader - please mentally add + * "HACK" before each line of code. + * + * @param {jQuery} $filterList jQuery block of the current static filters list + * @return {jQuery} jQuery block of the new static filters to display + */ + mw.rcfilters.Controller.prototype.rebuildStaticFilterList = function ( $filterList ) { + var filters = {}, + controller = this, + $newStructure = $filterList.clone( true ); + + $newStructure + .empty() + .addClass( 'mw-rcfilters-rcshowhide' ); + // Extract the filters + $filterList.children().each( function () { + var name, + classes = $( this ).attr( 'class' ).split( ' ' ); + + // Remove the 'rcshowhideoption' class; We're only doing + // this to make sure that we don't pick the wrong class + // if split() gave us the wrong order + classes.splice( classes.indexOf( 'rcshowhideoption' ), 1 ); + + // Get rid of the 'rcshow' prefix + // This is absolutely terrible, because we're making + // an assumption that all prefixes are these, but + // since the entire method is a temporary hack, we + // will pinch our noses and do it + name = classes[ 0 ].substr( 'rcshow'.length ); + + // Ignore filters that exist in the view model + if ( !controller.model.getItemByName( name ) ) { + // This filter doesn't exist, add its element + // back into the new structure + $newStructure.append( $( this ) ); + } + } ); + + // Return the contents + return $newStructure; + }; + + /** * Update the state of a filter * * @param {string} filterName Filter name diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js index 34df2f5..ce67021 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js @@ -9,9 +9,11 @@ var rcfilters = { /** */ init: function () { - var model = new mw.rcfilters.dm.FiltersViewModel(), + var $newStaticFilters, + model = new mw.rcfilters.dm.FiltersViewModel(), controller = new mw.rcfilters.Controller( model ), - widget = new mw.rcfilters.ui.FilterWrapperWidget( controller, model ); + widget = new mw.rcfilters.ui.FilterWrapperWidget( controller, model ), + $existingStaticFilters = $( '.rcshowhide' ); model.initializeFilters( { registration: { @@ -24,7 +26,7 @@ description: mw.msg( 'rcfilters-filter-registered-description' ) }, { - name: 'hideanon', + name: 'hideanons', label: mw.msg( 'rcfilters-filter-unregistered-label' ), description: mw.msg( 'rcfilters-filter-unregistered-description' ) } @@ -146,6 +148,10 @@ // Initialize values controller.initialize(); + // Replace the existing filter display + $newStaticFilters = controller.rebuildStaticFilterList( $existingStaticFilters ); + $existingStaticFilters.replaceWith( $newStaticFilters ); + $( '.rcoptions form' ).submit( function () { var $form = $( this ); diff --git a/resources/src/mediawiki.rcfilters/styles/mw.rcfilters.less b/resources/src/mediawiki.rcfilters/styles/mw.rcfilters.less index 7f71c0c..d825484 100644 --- a/resources/src/mediawiki.rcfilters/styles/mw.rcfilters.less +++ b/resources/src/mediawiki.rcfilters/styles/mw.rcfilters.less @@ -1,5 +1,3 @@ -.rcshowhidemine { - // HACK: Hide this filter since it already appears in - // the new filter drop-down. - display: none; +.mw-rcfilters-rcshowhide .rcshowhideoption + .rcshowhideoption::before { + content: ' | '; } -- To view, visit https://gerrit.wikimedia.org/r/332932 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I501e69c1cbc22755710007d13bfc6a1daea9404b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Mooeypoo <mor...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits