Awight has uploaded a new change for review. https://gerrit.wikimedia.org/r/247185
Change subject: Flag reverted risk rows using the recentChangesFlag ...................................................................... Flag reverted risk rows using the recentChangesFlag This is simpler to maintain and is consistent with other recent changes flags. Regresses slightly, by not rolling up child "R" flags into the top-level grouped lines, but I'd prefer to implement that in a general way in mw-core. Bug: T112856 Change-Id: Ic49a355a2a4a35d78dbd8dc720db2da4de2e628f --- M README M extension.json M i18n/en.json M i18n/qqq.json M includes/Hooks.php M includes/OresScoring.php 6 files changed, 56 insertions(+), 58 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ORES refs/changes/85/247185/1 diff --git a/README b/README index a8f8091..dcbc1d5 100644 --- a/README +++ b/README @@ -7,5 +7,4 @@ the database. $wgOresRevertTagThresholds - Map from threshold name to score cutoff. These -thresholds are used to flag recent changes for potential revert. Must be -listed in ascending order (FIXME). +thresholds are used to flag recent changes for potential revert. diff --git a/extension.json b/extension.json index 2542ed7..6c19190 100644 --- a/extension.json +++ b/extension.json @@ -63,6 +63,14 @@ "low": 0.8, "medium": 0.87, "high": 0.94 + }, + "RecentChangesFlags": { + "revertedRisk": { + "letter": "ores-reverted-letter", + "title": "ores-reverted-title", + "legend": "ores-reverted-legend", + "class": "ores-reverted" + } } }, "manifest_version": 1 diff --git a/i18n/en.json b/i18n/en.json index f3d32f5..e378da1 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -6,5 +6,9 @@ "ores-reverted-filter": "$1 revert predictions", "ores-reverted-high": "High risk, probability of revert $1%", "ores-reverted-medium": "Medium risk, probability of revert $1%", - "ores-reverted-low": "Some risk, probability of revert $1%" + "ores-reverted-low": "Some risk, probability of revert $1%", + + "ores-reverted-letter": "R", + "ores-reverted-title": "Revert risk", + "ores-reverted-legend": "ORES predicts that this change might be at risk of revert." } diff --git a/i18n/qqq.json b/i18n/qqq.json index f06f4d7..c736043 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -4,5 +4,9 @@ "ores-reverted-filter": "Label to toggle filtering of ORES data. Parameters:\n* $1 - Action to be performed by toggling.", "ores-reverted-high": "Title for high probability revert risk. Parameters:\n* $1 - Score as a percentage.", "ores-reverted-medium": "Title for medium probability revert risk. Parameters:\n* $1 - Score as a percentage.", - "ores-reverted-low": "Title for low probability revert risk. Parameters:\n* $1 - Score as a percentage." + "ores-reverted-low": "Title for low probability revert risk. Parameters:\n* $1 - Score as a percentage.", + + "ores-reverted-letter": "Single letter for tagging recent changes at risk of revert.", + "ores-reverted-title": "Tooltip for revert risk icon.", + "ores-reverted-legend": "Legend for revert risk icon." } diff --git a/includes/Hooks.php b/includes/Hooks.php index d463400..4e6c2ca 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -97,16 +97,8 @@ public static function onEnhancedChangesListModifyLineData( EnhancedChangesList $ecl, array &$data, array $block, RCCacheEntry $rcObj ) { - $score = $rcObj->getAttribute( 'ores_probability' ); - if ( $score !== null ) { - $type = self::getRevertThreshold( $score ); + self::processRecentChangesList( $rcObj, $data ); - if ( $type ) { - $data[] = self::getScoreHtml( $type, $score ); - - $ecl->getOutput()->addModuleStyles( 'ext.ores.styles' ); - } - } return true; } @@ -120,59 +112,24 @@ public static function onEnhancedChangesListModifyBlockLineData( EnhancedChangesList $ecl, array &$data, RCCacheEntry $rcObj ) { - $score = $rcObj->getAttribute( 'ores_probability' ); - if ( $score !== null ) { - $type = self::getRevertThreshold( $score ); + self::processRecentChangesList( $rcObj, $data ); - if ( $type ) { - $data[] = self::getScoreHtml( $type, $score ); - - $ecl->getOutput()->addModuleStyles( 'ext.ores.styles' ); - } - } return true; } - // FIXME: Repeated code. - public static function onOldChangesListRecentChangesLine( OldChangesList &$ocl, &$html, - RecentChange $rc, array &$classes - ) { - $score = $rc->getAttribute( 'ores_probability' ); + /** + * Internal helper to label matching rows + */ + protected static function processRecentChangesList( RCCacheEntry $rcObj, array &$data ) + { + $score = $rcObj->getAttribute( 'ores_probability' ); if ( $score !== null ) { - $type = self::getRevertThreshold( $score ); + $type = OresScoring::getRevertThreshold( $score ); if ( $type ) { - $html = $html . ' ' . self::getScoreHtml( $type, $score ); - - // TODO: once per page - $ocl->getOutput()->addModuleStyles( 'ext.ores.styles' ); + $data['recentChangesFlags']['revertedRisk'] = true; + // TODO: Stash the details in HTML so they can be retrieved by JS? } } - } - - protected static function getRevertThreshold( $score ) { - global $wgOresRevertTagThresholds; - - $score = floatval( $score ); - $type = null; - // TODO: Need to ensure the thresholds are ordered. - foreach ( $wgOresRevertTagThresholds as $name => $value ) { - if ( $score >= $value ) { - $type = $name; - } - } - return $type; - } - - protected static function getScoreHtml( $type, $score ) { - $cssClass = 'mw-ores-' . $type; - $rounded = intval( 100 * $score ); - $msg = wfMessage( 'ores-reverted-' . $type )->numParams( $rounded )->escaped(); - $html = Html::rawElement( 'span', array( - 'title' => $msg, - 'class' => array( $cssClass, 'mw-ores-score' ), - ), $msg ); - - return $html; } } diff --git a/includes/OresScoring.php b/includes/OresScoring.php index fc07974..c7d8567 100644 --- a/includes/OresScoring.php +++ b/includes/OresScoring.php @@ -45,6 +45,32 @@ return $wireData; } + /** + * @return string|null Threshold exceeded, or null if none. + * + * TODO: Should be in a model-specific module. + */ + public static function getRevertThreshold( $score ) { + global $wgOresRevertTagThresholds; + + $score = floatval( $score ); + $type = null; + + // Find the nearest threshold exceeded by $score. + $highestExceededThreshold = null; + foreach ( $wgOresRevertTagThresholds as $name => $threshold ) { + if ( $score >= $threshold + // Ignore threshold if it's further from $score. + && ( $threshold > $highestExceededThreshold || $highestExceededThreshold === null ) + ) { + $type = $name; + $highestExceededThreshold = $threshold; + } + } + return $type; + } + + public function instance() { return new OresScoring(); } -- To view, visit https://gerrit.wikimedia.org/r/247185 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic49a355a2a4a35d78dbd8dc720db2da4de2e628f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ORES Gerrit-Branch: master Gerrit-Owner: Awight <awi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits