Generalize recentChangesFlags rollup

Flags can be either 'any' or 'all' type, and both core and extension flags will be
rolled up into the top-level line of grouped changes.

See Ic49a355a2

Bug: T120921
Bug: T112856
Change-Id: If9fd6af3ac7ac2fbee9aa5536fe94d7574699966
This commit is contained in:
amir 2016-03-23 19:55:44 +04:30
parent 15474ac551
commit 78f109bfdd
2 changed files with 51 additions and 23 deletions

View file

@ -6479,6 +6479,10 @@ $wgUnwatchedPageThreshold = false;
* 'legend' => 'legend-msg',
* // optional (defaults to 'flag'), CSS class to put on changes lists rows
* 'class' => 'css-class',
* // optional (defaults to 'any'), how top-level flag is determined. 'any'
* // will set the top-level flag if any line contains the flag, 'all' will
* // only be set if all lines contain the flag.
* 'grouping' => 'any',
* );
* @endcode
*
@ -6489,23 +6493,27 @@ $wgRecentChangesFlags = [
'letter' => 'newpageletter',
'title' => 'recentchanges-label-newpage',
'legend' => 'recentchanges-legend-newpage',
'grouping' => 'any',
],
'minor' => [
'letter' => 'minoreditletter',
'title' => 'recentchanges-label-minor',
'legend' => 'recentchanges-legend-minor',
'class' => 'minoredit',
'grouping' => 'all',
],
'bot' => [
'letter' => 'boteditletter',
'title' => 'recentchanges-label-bot',
'legend' => 'recentchanges-legend-bot',
'class' => 'botedit',
'grouping' => 'all',
],
'unpatrolled' => [
'letter' => 'unpatrolledletter',
'title' => 'recentchanges-label-unpatrolled',
'legend' => 'recentchanges-legend-unpatrolled',
'grouping' => 'any',
],
];

View file

@ -157,8 +157,10 @@ class EnhancedChangesList extends ChangesList {
* Enhanced RC group
* @param RCCacheEntry[] $block
* @return string
* @throws DomainException
*/
protected function recentChangesBlockGroup( $block ) {
$recentChangesFlags = $this->getConfig()->get( 'RecentChangesFlags' );
# Add the namespace and title of the block as part of the class
$tableClasses = [ 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' ];
@ -186,20 +188,24 @@ class EnhancedChangesList extends ChangesList {
$namehidden = true;
$allLogs = true;
$RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' );
$collectedRcFlags = [
// All are by bots?
'bot' => true,
// Includes a new page?
'newpage' => false,
// All are minor edits?
'minor' => true,
// Contains an unpatrolled edit?
'unpatrolled' => false,
];
foreach ( $block as $rcObj ) {
if ( $rcObj->mAttribs['rc_type'] == RC_NEW ) {
$collectedRcFlags['newpage'] = true;
# Default values for RC flags
$collectedRcFlags = [];
foreach ( $recentChangesFlags as $key => $value ) {
$flagGrouping = ( isset( $recentChangesFlags[$key]['grouping'] ) ?
$recentChangesFlags[$key]['grouping'] : 'any' );
switch ( $flagGrouping ) {
case 'all':
$collectedRcFlags[$key] = true;
break;
case 'any':
$collectedRcFlags[$key] = false;
break;
default:
throw new DomainException( "Unknown grouping type \"{$flagGrouping}\"" );
}
}
foreach ( $block as $rcObj ) {
// If all log actions to this page were hidden, then don't
// give the name of the affected page for this block!
if ( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
@ -209,9 +215,6 @@ class EnhancedChangesList extends ChangesList {
if ( !isset( $userlinks[$u] ) ) {
$userlinks[$u] = 0;
}
if ( $rcObj->unpatrolled ) {
$collectedRcFlags['unpatrolled'] = true;
}
if ( $rcObj->mAttribs['rc_type'] != RC_LOG ) {
$allLogs = false;
}
@ -221,13 +224,6 @@ class EnhancedChangesList extends ChangesList {
$curId = $rcObj->mAttribs['rc_cur_id'];
}
if ( !$rcObj->mAttribs['rc_bot'] ) {
$collectedRcFlags['bot'] = false;
}
if ( !$rcObj->mAttribs['rc_minor'] ) {
$collectedRcFlags['minor'] = false;
}
$userlinks[$u]++;
}
@ -267,6 +263,27 @@ class EnhancedChangesList extends ChangesList {
// completely ignore this RC entry if we don't want to render it
unset( $block[$i] );
}
// Roll up flags
foreach ( $line['recentChangesFlagsRaw'] as $key => $value ) {
$flagGrouping = ( isset( $recentChangesFlags[$key]['grouping'] ) ?
$recentChangesFlags[$key]['grouping'] : 'any' );
switch ( $flagGrouping ) {
case 'all':
if ( !$value ) {
$collectedRcFlags[$key] = false;
}
break;
case 'any':
if ( $value ) {
$collectedRcFlags[$key] = true;
}
break;
default:
throw new DomainException( "Unknown grouping type \"{$flagGrouping}\"" );
}
}
$lines[] = $line;
}
// Further down are some assumptions that $block is a 0-indexed array
@ -436,8 +453,11 @@ class EnhancedChangesList extends ChangesList {
return [];
}
$lineParams['recentChangesFlagsRaw'] = [];
if ( isset( $data['recentChangesFlags'] ) ) {
$lineParams['recentChangesFlags'] = $this->recentChangesFlags( $data['recentChangesFlags'] );
# FIXME: This is used by logic, don't return it in the template params.
$lineParams['recentChangesFlagsRaw'] = $data['recentChangesFlags'];
unset( $data['recentChangesFlags'] );
}