Mooeypoo has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/325851 )
Change subject: Add userExpLevel filter in the RCFilters UI ...................................................................... Add userExpLevel filter in the RCFilters UI Bug: T149435 Change-Id: I6a19d4b24c45068dbd9ddb8a36a0f8a87868b912 --- M languages/i18n/en.json M languages/i18n/qqq.json M resources/Resources.php M resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FiltersViewModel.js M resources/src/mediawiki.rcfilters/mw.rcfilters.init.js 5 files changed, 118 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/51/325851/1 diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 2fa0f5b..bc91c6c 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -1367,6 +1367,13 @@ "rcfilters-filter-editsbyself-description": "Edits by you.", "rcfilters-filter-editsbyother-label": "Edits by others", "rcfilters-filter-editsbyother-description": "Edits created by other users (not you.)", + "rcfilters-filtergroup-userExpLevel": "User experience level", + "rcfilters-filter-userExpLevel-newcomer-label": "Newcomer", + "rcfilters-filter-userExpLevel-newcomer-description": "Very new editors: fewer than 10 edits and 4 days of activity.", + "rcfilters-filter-userExpLevel-experienced-label": "Experienced", + "rcfilters-filter-userExpLevel-experienced-description": "More days of activity and edits than 'Newcomers' but fewer than 'More experienced.'", + "rcfilters-filter-userExpLevel-moreexperienced-label": "More experienced", + "rcfilters-filter-userExpLevel-moreexperienced-description": "More than 30 days of activity and 500 edits.", "rcnotefrom": "Below {{PLURAL:$5|is the change|are the changes}} since <strong>$3, $4</strong> (up to <strong>$1</strong> shown).", "rclistfrom": "Show new changes starting from $2, $3", "rcshowhideminor": "$1 minor edits", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index faac517..edac791 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -1551,6 +1551,13 @@ "rcfilters-filter-editsbyself-description": "Description for the filter for showing edits made by the current user.", "rcfilters-filter-editsbyother-label": "Label for the filter for showing edits made by anyone other than the current user.", "rcfilters-filter-editsbyother-description": "Description for the filter for showing edits made by anyone other than the current user.", + "rcfilters-filtergroup-userExpLevel": "Title for the filter group for user experience levels.", + "rcfilters-filter-userExpLevel-newcomer-label": "Label for the filter for showing edits made by new editors.", + "rcfilters-filter-userExpLevel-newcomer-description": "Description for the filter for showing edits made by new editors.", + "rcfilters-filter-userExpLevel-experienced-label": "Label for the filter for showing edits made by experienced editors.", + "rcfilters-filter-userExpLevel-experienced-description": "Description for the filter for showing edits made by experienced editors.", + "rcfilters-filter-userExpLevel-moreexperienced-label": "Label for the filter for showing edits made by more experienced editors.", + "rcfilters-filter-userExpLevel-moreexperienced-description": "Description for the filter for showing edits made by more experienced editors.", "rcnotefrom": "This message is displayed at [[Special:RecentChanges]] when viewing recentchanges from some specific time.\n\nThe corresponding message is {{msg-mw|Rclistfrom}}.\n\nParameters:\n* $1 - the maximum number of changes that are displayed\n* $2 - (Optional) a date and time\n* $3 - a date\n* $4 - a time\n* $5 - Number of changes are displayed, for use with PLURAL", "rclistfrom": "Used on [[Special:RecentChanges]]. Parameters:\n* $1 - (Currently not use) date and time. The date and the time adds to the rclistfrom description.\n* $2 - time. The time adds to the rclistfrom link description (with split of date and time).\n* $3 - date. The date adds to the rclistfrom link description (with split of date and time).\n\nThe corresponding message is {{msg-mw|Rcnotefrom}}.", "rcshowhideminor": "Option text in [[Special:RecentChanges]]. Parameters:\n* $1 - the \"show/hide\" command, with the text taken from either {{msg-mw|rcshowhideminor-show}} or {{msg-mw|rcshowhideminor-hide}}\n{{Identical|Minor edit}}", diff --git a/resources/Resources.php b/resources/Resources.php index b1e55c3..0e338e1 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1806,6 +1806,13 @@ 'rcfilters-filter-editsbyself-description', 'rcfilters-filter-editsbyother-label', 'rcfilters-filter-editsbyother-description', + 'rcfilters-filtergroup-userExpLevel', + 'rcfilters-filter-userExpLevel-newcomer-label', + 'rcfilters-filter-userExpLevel-newcomer-description', + 'rcfilters-filter-userExpLevel-experienced-label', + 'rcfilters-filter-userExpLevel-experienced-description', + 'rcfilters-filter-userExpLevel-moreexperienced-label', + 'rcfilters-filter-userExpLevel-moreexperienced-description', ], 'dependencies' => [ 'oojs-ui', diff --git a/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FiltersViewModel.js b/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FiltersViewModel.js index 15300ec..b120e06 100644 --- a/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FiltersViewModel.js +++ b/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.FiltersViewModel.js @@ -85,6 +85,7 @@ model.groups[ group ].title = data.title; model.groups[ group ].type = data.type; + model.groups[ group ].separator = data.separator || '|'; for ( i = 0; i < data.filters.length; i++ ) { filterItem = new mw.rcfilters.dm.FilterItem( data.filters[ i ].name, { @@ -150,7 +151,17 @@ if ( this.groups[ groupName ] ) { this.groups[ groupName ].filters.forEach( function ( filter ) { // Get the parameter value - groupParamValues.push( Number( model.parameters[ filter.getName() ] || 0 ) ); + if ( model.groups[ groupName ].type === 'send_unselected_if_any' ) { + groupParamValues.push( Number( model.parameters[ filter.getName() ] || 0 ) ); + } else if ( model.groups[ groupName ].type === 'string_options' ) { + if ( !model.parameters[ groupName ] ) { + // The parameter doesn't exist; it's valid + return true; + } +debugger; + // This group uses a parameter of the group name, separated by the given separator + groupParamValues = model.parameters[ groupName ].split( model.groups[ groupName ].separator ); + } } ); // Go over the values and validate @@ -158,6 +169,14 @@ // With this type of group, if all params in the group are true // the group is invalid return groupParamValues.reduce( function ( a, b ) { return Number( a ) + Number( b ); } ) !== groupParamValues.length; + } else if ( this.groups[ groupName ].type === 'string_options' ) { + groupValues = this.groups[ groupName ].filters.map( function ( filter ) { return filter.getName(); } ); + // For this group, we need to see if the value(s) are either + // any of the filter names or the word 'all' + return ( groupParamValues.length === 1 && groupParamValues[ 0 ] === 'all' ) || + groupParamValues.every( function ( val ) { + return groupValues.indexOf( val ) > -1; + } ); } } @@ -201,8 +220,12 @@ paramGroup[ filterItem.getName() ] = false; } } ); - model.updateParameters( paramGroup ); + } else if ( data.type === 'string_options' ) { + // If this group came in invalid, we assume the + // correction is "all" + paramGroup[ groupName ] = 'all'; } + model.updateParameters( paramGroup ); } } ); }; @@ -270,14 +293,14 @@ * @return {Object} Parameter state object */ mw.rcfilters.dm.FiltersViewModel.prototype.getFiltersToParameters = function () { - var i, filterItems, anySelected, + var i, filterItems, anySelected, values, result = {}, groupItems = this.getFilterGroups(); $.each( groupItems, function ( group, data ) { - if ( data.type === 'send_unselected_if_any' ) { - filterItems = data.filters; + filterItems = data.filters; + if ( data.type === 'send_unselected_if_any' ) { // First, check if any of the items are selected at all. // If none is selected, we're treating it as if they are // all false @@ -293,6 +316,20 @@ for ( i = 0; i < filterItems.length; i++ ) { result[ filterItems[ i ].getName() ] = anySelected ? !filterItems[ i ].isSelected() : false; + } + } else if ( data.type === 'string_options' ) { + values = []; + for ( i = 0; i < filterItems.length; i++ ) { + if ( filterItems[ i ].isSelected() ) { + values.push( filterItems[ i ].getName() ); + } + } + + if ( values.length === filterItems.length ) { + result[ group ] = 'all'; + } else if ( values.length > 0 ) { +debugger; + result[ group ] = values.join( data.separator ); } } } ); @@ -320,7 +357,6 @@ $.each( params, function ( paramName, paramValue ) { // Find the filter item filterItem = model.getItemByName( paramName ); - // Ignore if no filter item exists if ( filterItem ) { groupMap[ filterItem.getGroup() ] = groupMap[ filterItem.getGroup() ] || {}; @@ -334,15 +370,36 @@ // Add the relevant filter into the group map groupMap[ filterItem.getGroup() ].filters = groupMap[ filterItem.getGroup() ].filters || []; groupMap[ filterItem.getGroup() ].filters.push( filterItem ); + } else if ( Object.keys( model.groups ).indexOf( paramName ) > -1 ) { + // This parameter represents a group (values are the filters) + // this is equivalent to checking if the group is 'string_options' + groupMap[ paramName ] = {}; +debugger; + paramValue = paramValue.split( model.groups[ paramName ].separator ); + + if ( + ( paramValue.length === 1 && paramValue[ 0 ] === 'all' ) || + ( paramValue.length === model.groups[ paramName ].length ) + ) { + // All true is the same as all false + $.each( model.groups[ paramName ].filters, function ( filterItem ) { + groupMap[ paramName ][ filterItem.getName() ] = true; + } ); + } else { + // Mark the filters that correspond to the values + model.groups[ paramName ].filters.forEach( function ( filterItem ) { + groupMap[ paramName ][ filterItem.getName() ] = paramValue.indexOf( filterItem.getName() ) > -1; + } ); + } } } ); // Now that we know the groups' selection states, we need to go over // the filters in the groups and mark their selected states appropriately $.each( groupMap, function ( group, data ) { - if ( model.groups[ group ].type === 'send_unselected_if_any' ) { - allItemsInGroup = model.groups[ group ].filters; + allItemsInGroup = model.groups[ group ].filters; + if ( model.groups[ group ].type === 'send_unselected_if_any' ) { for ( i = 0; i < allItemsInGroup.length; i++ ) { filterItem = allItemsInGroup[ i ]; @@ -355,6 +412,11 @@ // group, which means the state is false false; } + } else if ( model.groups[ group ].type === 'string_options' ) { + // We already have the correct result in our group map, + // override the current states of the filters from this + // group + result = $.extend( {}, result, groupMap[ group ] ); } } ); return result; diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js index 7c1ff1d..bdf0f4a 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.init.js @@ -38,6 +38,33 @@ description: mw.msg( 'rcfilters-filter-editsbyother-description' ) } ] + }, + userExpLevel: { + title: mw.msg( 'rcfilters-filtergroup-userExpLevel' ), + // Type 'string_options' means that the group is evaluated by + // string values separated by pipe; for example, param=opt1|opt2 + // If all options are selected they are replaced by the term "all". + // The filters are the values for the parameter defined by the group. + // ** In this case, the parameter name is the group name. ** + type: 'string_options', + separator: ',', + filters: [ + { + name: 'newcomer', + label: mw.msg( 'rcfilters-filter-userExpLevel-newcomer-label' ), + description: mw.msg( 'rcfilters-filter-userExpLevel-newcomer-description' ) + }, + { + name: 'experienced', + label: mw.msg( 'rcfilters-filter-userExpLevel-experienced-label' ), + description: mw.msg( 'rcfilters-filter-userExpLevel-experienced-description' ) + }, + { + name: 'moreexperienced', + label: mw.msg( 'rcfilters-filter-userExpLevel-moreexperienced-label' ), + description: mw.msg( 'rcfilters-filter-userExpLevel-moreexperienced-description' ) + } + ] } } ); -- To view, visit https://gerrit.wikimedia.org/r/325851 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6a19d4b24c45068dbd9ddb8a36a0f8a87868b912 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