jenkins-bot has submitted this change and it was merged.

Change subject: Let people choose a threshold
......................................................................


Let people choose a threshold

It makes a radio button and let people choose between a
"soft threshold" (high recall, low precision) and "hard threshold"
(high precision, low recall).

Bug: T122684
Change-Id: I295eff8ff72da84c5a446311ebe39e9eee21a11f
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/Hooks.php
4 files changed, 70 insertions(+), 7 deletions(-)

Approvals:
  Ladsgroup: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index aee13d5..4db0679 100644
--- a/extension.json
+++ b/extension.json
@@ -35,6 +35,9 @@
                ],
                "OldChangesListRecentChangesLine": [
                        "ORES\\Hooks::onOldChangesListRecentChangesLine"
+               ],
+               "GetPreferences": [
+                       "ORES\\Hooks::onGetPreferences"
                ]
        },
        "ResourceFileModulePaths": {
@@ -57,7 +60,11 @@
                        "reverted",
                        "wp10"
                ],
-               "OresDamagingThreshold": 0.87,
+               "OresDamagingThresholds": {
+                       "hard": 0.70,
+                       "soft": 0.50
+               },
+               "OresDamagingDefault": "hard",
                "OresWikiId": null,
                "RecentChangesFlags": {
                        "damaging": {
diff --git a/i18n/en.json b/i18n/en.json
index 60b5917..3edcd59 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -4,7 +4,11 @@
        },
        "ores-desc": "Expose automated revision scores in the interface",
        "ores-damaging-filter": "$1 good edits",
+       "ores-damaging-hard": "Hard (higher)",
        "ores-damaging-letter": "r",
+       "ores-damaging-soft": "Soft (lower)",
        "ores-damaging-title": "This edit needs review",
-       "ores-damaging-legend": "ORES predicts that this change may be damaging 
and should be reviewed"
+       "ores-damaging-legend": "ORES predicts that this change may be damaging 
and should be reviewed",
+       "ores-pref-damaging": "ORES threshold for damaging model",
+       "prefs-ores" : "ORES"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index a3ca867..8e3dfd0 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -2,7 +2,11 @@
        "@metadata": [],
        "ores-desc": "Extension summary.",
        "ores-damaging-filter": "Label to toggle filtering on ORES data. 
Parameters:\n* $1 - Action to be performed by toggling. Can be either 'show' or 
'hide'.",
+       "ores-damaging-hard": "Name of \"Hard\" threshold ",
        "ores-damaging-letter": "Single letter for tagging possibly damaging 
recent changes.",
+       "ores-damaging-soft": "Name of \"Soft\" threshold ",
        "ores-damaging-title": "Tooltip for damaging risk icon.",
-       "ores-damaging-legend": "Legend for damaging risk icon."
+       "ores-damaging-legend": "Legend for damaging risk icon.",
+       "ores-pref-damaging": "Part asking for damaging threshold",
+       "prefs-ores" : "Name of ORES section in preferences"
 }
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 835f94e..b57b671 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -76,7 +76,7 @@
                $name, array &$tables, array &$fields, array &$conds,
                array &$query_options, array &$join_conds, FormOptions $opts
        ) {
-               global $wgOresDamagingThreshold;
+               $threshold = self::getThreshold();
 
                $tables[] = 'ores_classification';
                $fields[] = 'ores_probability';
@@ -84,11 +84,14 @@
                        'rc_this_oldid = ores_rev AND ores_model = \'damaging\' 
' .
                        'AND ores_is_predicted = 1 AND ores_class = \'true\'' );
 
+               // Add user-based threshold
+               $fields[] = $threshold . ' AS ores_threshold';
+
                if ( $opts->getValue( 'hidenondamaging' ) ) {
                        // Filter out non-damaging edits.
                        $conds[] = 'ores_is_predicted = 1';
                        $conds[] = 'ores_probability > '
-                               . wfGetDb( DB_SLAVE )->addQuotes( 
$wgOresDamagingThreshold );
+                               . wfGetDb( DB_SLAVE )->addQuotes( $threshold );
                }
 
                return true;
@@ -120,6 +123,7 @@
        public static function onEnhancedChangesListModifyBlockLineData( 
EnhancedChangesList $ecl,
                array &$data, RCCacheEntry $rcObj
        ) {
+
                self::processRecentChangesList( $rcObj, $data );
 
                return true;
@@ -168,14 +172,58 @@
         * Check if we should flag a row
         */
        protected static function getScoreRecentChangesList( $rcObj ) {
-               global $wgOresDamagingThreshold;
 
+               $score = $rcObj->getAttribute( 'ores_threshold' );
+               if ( $threshold === null ) {
+                       $logger = LoggerFactory::getInstance( 'ORES' );
+                       $logger->debug( 'WARNING: Running low perofrmance 
actions, ' .
+                               'getting threshold for each edit seperately' );
+                       $threshold = self::getThreshold();
+               }
                $score = $rcObj->getAttribute( 'ores_probability' );
                $patrolled = $rcObj->getAttribute( 'rc_patrolled' );
-               if ( $score && $score >= $wgOresDamagingThreshold && 
!$patrolled ) {
+               if ( $score && $score >= $threshold && !$patrolled ) {
                        return true;
                } else {
                        return false;
                }
        }
+
+       /**
+        * Internal helper to get threshold
+        */
+       protected static function getThreshold() {
+               global $wgOresDamagingThresholds;
+               global $wgOresDamagingDefault;
+               global $wgUser;
+
+               $pref = $wgUser->getOption( 'oresDamagingPref' );
+               // User is not logged in, returning default
+               if ( $wgOresDamagingThresholds[$pref] === null ) {
+                       return 
$wgOresDamagingThresholds[$wgOresDamagingDefault];
+               }
+               return $wgOresDamagingThresholds[$pref];
+       }
+
+       /**
+        * GetPreferences hook, adding ORES section, letting people choose a 
threshold
+        */
+       public static function onGetPreferences( $user, &$preferences ) {
+               global $wgOresDamagingThresholds;
+
+               $options = array();
+               foreach ( $wgOresDamagingThresholds as $case => $value ) {
+                       $text = wfMessage( 'ores-damaging-' . $case )->parse();
+                       $options[$text] = $case;
+               }
+               $preferences['oresDamagingPref'] = array(
+                       'type' => 'select',
+                       'label-message' => 'ores-pref-damaging',
+                       'section' => 'rc/ores',
+                       'options' => $options,
+                       'help-message' => 'ores-help-damaging-pref',
+               );
+
+               return true;
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/265676
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I295eff8ff72da84c5a446311ebe39e9eee21a11f
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Adamw <s...@ludd.net>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to