Ladsgroup has uploaded a new change for review.

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

Change subject: Expose ores scores in js
......................................................................

Expose ores scores in js

Bug: T143611
Change-Id: I42300f9bad536e8dcb2fa2f4025051f70ee1f805
---
M includes/Hooks.php
1 file changed, 39 insertions(+), 6 deletions(-)


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

diff --git a/includes/Hooks.php b/includes/Hooks.php
index 0b5955b..08b1f03 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -11,6 +11,7 @@
 use FormOptions;
 use JobQueueGroup;
 use Html;
+use IContextSource;
 use MediaWiki\Logger\LoggerFactory;
 use OutputPage;
 use RCCacheEntry;
@@ -191,7 +192,7 @@
                        return true;
                }
 
-               self::processRecentChangesList( $rcObj, $data, $classes );
+               self::processRecentChangesList( $rcObj, $data, $classes, 
$ecl->getContext() );
 
                return true;
        }
@@ -213,7 +214,8 @@
                        return true;
                }
 
-               self::processRecentChangesList( $rcObj, $data );
+               $classes = [];
+               self::processRecentChangesList( $rcObj, $data, $classes, 
$ecl->getContext() );
 
                return true;
        }
@@ -239,7 +241,7 @@
                        return true;
                }
 
-               $damaging = self::getScoreRecentChangesList( $rc );
+               $damaging = self::getScoreRecentChangesList( $rc, 
$changesList->getContext() );
                if ( $damaging ) {
                        $separator = ' <span class="mw-changeslist-separator">. 
.</span> ';
                        if ( strpos( $s, $separator ) === false ) {
@@ -319,6 +321,8 @@
                        return true;
                }
 
+               self::addRowData( $context, $row->rev_id, 
(float)$row->ores_damaging_score, 'damaging' );
+
                if ( $row->ores_damaging_score > $row->ores_damaging_threshold 
) {
                        // Prepend the "r" flag
                        array_unshift( $flags, ChangesList::flag( 'damaging' ) 
);
@@ -388,9 +392,10 @@
        protected static function processRecentChangesList(
                RCCacheEntry $rcObj,
                array &$data,
-               array &$classes = []
+               array &$classes = [],
+               IContextSource $context
        ) {
-               $damaging = self::getScoreRecentChangesList( $rcObj );
+               $damaging = self::getScoreRecentChangesList( $rcObj, $context );
                if ( $damaging ) {
                        $classes[] = 'damaging';
                        $data['recentChangesFlags']['damaging'] = true;
@@ -400,9 +405,10 @@
        /**
         * Check if we should flag a row
         * @param RecentChange $rcObj
+        * @param IContextSource $context
         * @return bool
         */
-       public static function getScoreRecentChangesList( $rcObj ) {
+       public static function getScoreRecentChangesList( $rcObj, 
IContextSource $context ) {
                global $wgUser;
                $threshold = $rcObj->getAttribute( 'ores_damaging_threshold' );
                if ( $threshold === null ) {
@@ -411,6 +417,8 @@
                $score = $rcObj->getAttribute( 'ores_damaging_score' );
                $patrolled = $rcObj->getAttribute( 'rc_patrolled' );
 
+               self::addRowData( $context, (float)$rcObj->getAttribute( 
'rc_this_oldid' ), $score,
+               'damaging');
                return $score && $score >= $threshold && !$patrolled;
        }
 
@@ -481,6 +489,13 @@
                if ( !self::oresEnabled( $out->getUser() ) ) {
                        return true;
                }
+
+               $oresData = $out->getProperty( 'oresData' );
+
+               if ( $oresData !== null ) {
+                       $out->addJsConfigVars( 'oresData', $oresData );
+               }
+
                $out->addModuleStyles( 'ext.ores.styles' );
                return true;
        }
@@ -525,4 +540,22 @@
                global $wgOresModels;
                return isset( $wgOresModels[$model] ) && $wgOresModels[$model];
        }
+
+       /**
+        * @param IContextSource $context
+        * @param int $revisionId
+        * @param float $score
+        * @param string $model
+        */
+       private static function addRowData( IContextSource $context, 
$revisionId, $score, $model ) {
+               $out = $context->getOutput();
+               $data = $out->getProperty( 'oresData' );
+               if ( !isset( $data[$revisionId] ) ) {
+                       $data[$revisionId] = [];
+               }
+               $data[$revisionId][$model] = $score;
+               $out->setProperty( 'oresData', $data );
+       }
+
 }
+

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I42300f9bad536e8dcb2fa2f4025051f70ee1f805
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to