Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312165

Change subject: Only pull in damaging scores when damaging model is enabled
......................................................................

Only pull in damaging scores when damaging model is enabled

And some other cleanup

Change-Id: I75ab039ec62d9ac0125ee021c13898e87427c87f
---
M includes/Hooks.php
1 file changed, 53 insertions(+), 46 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ORES 
refs/changes/65/312165/1

diff --git a/includes/Hooks.php b/includes/Hooks.php
index 72cf720..65744b3 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -128,32 +128,40 @@
                if ( !self::oresEnabled( $wgUser ) ) {
                        return true;
                }
-
-               $threshold = self::getDamagingThreshold( $wgUser );
                $dbr = \wfGetDB( DB_REPLICA );
+               $filtering = false;
 
-               $tables['ores_damaging_mdl'] = 'ores_model';
-               $tables['ores_damaging_cls'] = 'ores_classification';
+               if ( self::isModelEnabled( 'damaging' ) ) {
+                       $threshold = self::getDamagingThreshold( $wgUser );
 
-               $fields['ores_damaging_score'] = 
'ores_damaging_cls.oresc_probability';
-               // Add user-based threshold
-               $fields['ores_damaging_threshold'] = $dbr->addQuotes( 
$threshold );
+                       $tables['ores_damaging_mdl'] = 'ores_model';
+                       $tables['ores_damaging_cls'] = 'ores_classification';
 
-               $join_conds['ores_damaging_mdl'] = [ 'LEFT JOIN', [
-                       'ores_damaging_mdl.oresm_is_current' => 1,
-                       'ores_damaging_mdl.oresm_name' => 'damaging'
-               ] ];
-               $join_conds['ores_damaging_cls'] = [ 'LEFT JOIN', [
-                       'ores_damaging_cls.oresc_model = 
ores_damaging_mdl.oresm_id',
-                       'rc_this_oldid = ores_damaging_cls.oresc_rev',
-                       'ores_damaging_cls.oresc_class' => 1
-               ] ];
+                       $fields['ores_damaging_score'] = 
'ores_damaging_cls.oresc_probability';
+                       // Add user-based threshold
+                       $fields['ores_damaging_threshold'] = $dbr->addQuotes( 
$threshold );
+
+                       $join_conds['ores_damaging_mdl'] = [ 'LEFT JOIN', [
+                               'ores_damaging_mdl.oresm_is_current' => 1,
+                               'ores_damaging_mdl.oresm_name' => 'damaging'
+                       ] ];
+                       $join_conds['ores_damaging_cls'] = [ 'LEFT JOIN', [
+                               'ores_damaging_cls.oresc_model = 
ores_damaging_mdl.oresm_id',
+                               'rc_this_oldid = ores_damaging_cls.oresc_rev',
+                               'ores_damaging_cls.oresc_class' => 1
+                       ] ];
 
 
-               if ( self::isModelEnabled( 'damaging' ) && $opts->getValue( 
'hidenondamaging' ) ) {
-                       // Filter out non-damaging edits.
-                       $conds[] = 'ores_damaging_cls.oresc_probability > '
-                               . $dbr->addQuotes( $threshold );
+                       if ( $opts->getValue( 'hidenondamaging' ) ) {
+                               // Filter out non-damaging edits.
+                               $conds[] = 'ores_damaging_cls.oresc_probability 
> ' .
+                                       $dbr->addQuotes( $threshold );
+                               $filtering = true;
+                       }
+               }
+
+
+               if ( $filtering ) {
                        $conds['rc_patrolled'] = 0;
                        $query_options[] = 'STRAIGHT_JOIN';
                }
@@ -245,32 +253,36 @@
                if ( !self::oresEnabled( $pager->getUser() ) ) {
                        return true;
                }
-
-               $threshold = self::getDamagingThreshold( $pager->getUser() );
                $dbr = \wfGetDB( DB_REPLICA );
 
-               $query['tables']['ores_damaging_mdl'] = 'ores_model';
-               $query['tables']['ores_damaging_cls'] = 'ores_classification';
+               if ( self::isModelEnabled( 'damaging' ) ) {
+                       $threshold = self::getDamagingThreshold( 
$pager->getUser() );
 
-               $query['fields']['ores_damaging_score'] = 
'ores_damaging_cls.oresc_probability';
-               // Add user-based threshold
-               $query['fields']['ores_damaging_threshold'] = $dbr->addQuotes( 
$threshold );
+                       $query['tables']['ores_damaging_mdl'] = 'ores_model';
+                       $query['tables']['ores_damaging_cls'] = 
'ores_classification';
 
-               $query['join_conds']['ores_damaging_mdl'] = [ 'LEFT JOIN', [
-                       'ores_damaging_mdl.oresm_is_current' => 1,
-                       'ores_damaging_mdl.oresm_name' => 'damaging',
-               ] ];
+                       $query['fields']['ores_damaging_score'] = 
'ores_damaging_cls.oresc_probability';
+                       // Add user-based threshold
+                       $query['fields']['ores_damaging_threshold'] = 
$dbr->addQuotes( $threshold );
 
-               $query['join_conds']['ores_damaging_cls'] = [ 'LEFT JOIN', [
-                       'ores_damaging_cls.oresc_model = 
ores_damaging_mdl.oresm_id',
-                       'rev_id = ores_damaging_cls.oresc_rev',
-                       'ores_damaging_cls.oresc_class' => 1
-               ] ];
+                       $query['join_conds']['ores_damaging_mdl'] = [ 'LEFT 
JOIN', [
+                               'ores_damaging_mdl.oresm_is_current' => 1,
+                               'ores_damaging_mdl.oresm_name' => 'damaging',
+                       ] ];
 
-               if ( self::isModelEnabled( 'damaging' ) && 
$pager->getContext()->getRequest()->getVal( 'hidenondamaging' ) ) {
-                       // Filter out non-damaging edits.
-                       $query['conds'][] = 
'ores_damaging_cls.oresc_probability > '
-                               . $dbr->addQuotes( $threshold );
+                       $query['join_conds']['ores_damaging_cls'] = [ 'LEFT 
JOIN', [
+                               'ores_damaging_cls.oresc_model = 
ores_damaging_mdl.oresm_id',
+                               'rev_id = ores_damaging_cls.oresc_rev',
+                               'ores_damaging_cls.oresc_class' => 1
+                       ] ];
+
+                       if ( $pager->getContext()->getRequest()->getVal( 
'hidenondamaging' ) ) {
+                               // Filter out non-damaging edits.
+                               $query['conds'][] = 
'ores_damaging_cls.oresc_probability > ' .
+                                       $dbr->addQuotes( $threshold );
+                       }
+               }
+
                }
        }
 
@@ -281,12 +293,7 @@
                        return true;
                }
 
-               // Doesn't have ores score, skipping.
-               if ( !isset( $row->ores_damaging_score ) ) {
-                       return true;
-               }
-
-               if ( $row->ores_damaging_score > $row->ores_damaging_threshold 
) {
+               if ( isset ( $row->ores_damaging_score ) && 
$row->ores_damaging_score > $row->ores_damaging_threshold ) {
                        // Prepend the "r" flag
                        array_unshift( $flags, ChangesList::flag( 'damaging' ) 
);
                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I75ab039ec62d9ac0125ee021c13898e87427c87f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Catrope <roan.katt...@gmail.com>

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

Reply via email to