[MediaWiki-commits] [Gerrit] mediawiki...WikimediaEvents[wmf/1.30.0-wmf.16]: Encode human search relevance survey into html output

2017-09-06 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/376444 )

Change subject: Encode human search relevance survey into html output
..


Encode human search relevance survey into html output

Moves the search relevance configuration from javascript into php
configuration so it can be run on a larger number of pages without
exploding the size of javascript delivered to everyone with all
that config.

The downside of this approach is that because the config is cached
into the page html any updates have to work their way through varnish
caching. For the initial test this should be fine as we can purge the
relevant pages over some small time period. In the future when we are
doing larger scale collection we just have to keep in mind that
configuration changes take around 7 days to propogate.

Bug: T174387
Change-Id: I7ae522155e67610d25b5857d7b3918559bce8bc7
(cherry picked from commit e722fe1a9b0d41c3597f9f9326e7fc6f0e1cd9c6)
---
M WikimediaEventsHooks.php
M extension.json
M modules/ext.wikimediaEvents.humanSearchRelevance.js
3 files changed, 35 insertions(+), 220 deletions(-)

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



diff --git a/WikimediaEventsHooks.php b/WikimediaEventsHooks.php
index 0d8b7e5..709eb12 100644
--- a/WikimediaEventsHooks.php
+++ b/WikimediaEventsHooks.php
@@ -644,4 +644,14 @@
);
}
 
+   public static function onMakeGlobalVariablesScript( array &$vars, 
OutputPage $out ) {
+   global $wgWMESearchRelevancePages;
+   if ( $vars['wgAction'] === 'view' ) {
+   $articleId = $out->getTitle()->getArticleID();
+   if ( isset( $wgWMESearchRelevancePages[$articleId] ) ) {
+   $vars['wgWMESearchRelevancePages'] = 
$wgWMESearchRelevancePages[$articleId];
+   }
+   }
+   return true;
+   }
 }
diff --git a/extension.json b/extension.json
index 63a8487..db369ac 100644
--- a/extension.json
+++ b/extension.json
@@ -73,6 +73,9 @@
],
"ChangesListSpecialPageStructuredFilters": [

"WikimediaEventsHooks::onChangesListSpecialPageStructuredFilters"
+   ],
+   "MakeGlobalVariablesScript": [
+   "WikimediaEventsHooks::onMakeGlobalVariablesScript"
]
},
"MessagesDirs": {
@@ -167,7 +170,8 @@
],
"skinScripts": {
"default": [
-   
"ext.wikimediaEvents.searchSatisfaction.js"
+   
"ext.wikimediaEvents.searchSatisfaction.js",
+   
"ext.wikimediaEvents.humanSearchRelevance.js"
],
"minerva": []
},
@@ -219,7 +223,10 @@
"config": {
"WMEReadingDepthSamplingRate": 0.005,
"WMEReadingDepthEnabled": false,
-   "WMEStatsdBaseUri": false
+   "WMEStatsdBaseUri": false,
+   "WMESearchRelevancePages": {
+   "_merge_strategy": "array_plus"
+   }
},
"manifest_version": 1
 }
diff --git a/modules/ext.wikimediaEvents.humanSearchRelevance.js 
b/modules/ext.wikimediaEvents.humanSearchRelevance.js
index 7ac..5ee8fb2 100644
--- a/modules/ext.wikimediaEvents.humanSearchRelevance.js
+++ b/modules/ext.wikimediaEvents.humanSearchRelevance.js
@@ -1,10 +1,15 @@
 ( function ( mw, $, undefined ) {
'use strict';
 
-   function oneIn( populationSize ) {
+   function sample( acceptPercentage ) {
var rand = mw.user.generateRandomSessionId(),
+   // take the first 52 bits of the rand value to match js
+   // integer precision
parsed = parseInt( rand.slice( 0, 13 ), 16 );
-   return parsed % populationSize === 0;
+   if ( acceptPercentage >= 1 ) {
+   return true;
+   }
+   return parsed / Math.pow( 2, 52 ) < acceptPercentage;
}
 
function chooseOne( options ) {
@@ -14,228 +19,23 @@
return options[ Math.floor( parsed / step ) ];
}
 
-   // Only accept enwiki, NS_MAIN for MVP feasability test
-   if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 ||
-   mw.config.get( 'wgDBname' ) !== 'enwiki'
-   ) {
+   // Page is not part of this test
+   if ( !mw.config.exists( 'wgWMESearchRelevancePages' ) ) {
return;
}
 
-   // For the MVP we are simply hardcoding the list of queries and 
articles.
-   // If the MVP shows to return data that isn't complete junk this will be
-   // 

[MediaWiki-commits] [Gerrit] mediawiki...WikimediaEvents[wmf/1.30.0-wmf.16]: Encode human search relevance survey into html output

2017-09-06 Thread EBernhardson (Code Review)
EBernhardson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/376444 )

Change subject: Encode human search relevance survey into html output
..

Encode human search relevance survey into html output

Moves the search relevance configuration from javascript into php
configuration so it can be run on a larger number of pages without
exploding the size of javascript delivered to everyone with all
that config.

The downside of this approach is that because the config is cached
into the page html any updates have to work their way through varnish
caching. For the initial test this should be fine as we can purge the
relevant pages over some small time period. In the future when we are
doing larger scale collection we just have to keep in mind that
configuration changes take around 7 days to propogate.

Bug: T174387
Change-Id: I7ae522155e67610d25b5857d7b3918559bce8bc7
(cherry picked from commit e722fe1a9b0d41c3597f9f9326e7fc6f0e1cd9c6)
---
M WikimediaEventsHooks.php
M extension.json
M modules/ext.wikimediaEvents.humanSearchRelevance.js
3 files changed, 35 insertions(+), 220 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaEvents 
refs/changes/44/376444/1

diff --git a/WikimediaEventsHooks.php b/WikimediaEventsHooks.php
index 0d8b7e5..709eb12 100644
--- a/WikimediaEventsHooks.php
+++ b/WikimediaEventsHooks.php
@@ -644,4 +644,14 @@
);
}
 
+   public static function onMakeGlobalVariablesScript( array &$vars, 
OutputPage $out ) {
+   global $wgWMESearchRelevancePages;
+   if ( $vars['wgAction'] === 'view' ) {
+   $articleId = $out->getTitle()->getArticleID();
+   if ( isset( $wgWMESearchRelevancePages[$articleId] ) ) {
+   $vars['wgWMESearchRelevancePages'] = 
$wgWMESearchRelevancePages[$articleId];
+   }
+   }
+   return true;
+   }
 }
diff --git a/extension.json b/extension.json
index 63a8487..db369ac 100644
--- a/extension.json
+++ b/extension.json
@@ -73,6 +73,9 @@
],
"ChangesListSpecialPageStructuredFilters": [

"WikimediaEventsHooks::onChangesListSpecialPageStructuredFilters"
+   ],
+   "MakeGlobalVariablesScript": [
+   "WikimediaEventsHooks::onMakeGlobalVariablesScript"
]
},
"MessagesDirs": {
@@ -167,7 +170,8 @@
],
"skinScripts": {
"default": [
-   
"ext.wikimediaEvents.searchSatisfaction.js"
+   
"ext.wikimediaEvents.searchSatisfaction.js",
+   
"ext.wikimediaEvents.humanSearchRelevance.js"
],
"minerva": []
},
@@ -219,7 +223,10 @@
"config": {
"WMEReadingDepthSamplingRate": 0.005,
"WMEReadingDepthEnabled": false,
-   "WMEStatsdBaseUri": false
+   "WMEStatsdBaseUri": false,
+   "WMESearchRelevancePages": {
+   "_merge_strategy": "array_plus"
+   }
},
"manifest_version": 1
 }
diff --git a/modules/ext.wikimediaEvents.humanSearchRelevance.js 
b/modules/ext.wikimediaEvents.humanSearchRelevance.js
index 7ac..5ee8fb2 100644
--- a/modules/ext.wikimediaEvents.humanSearchRelevance.js
+++ b/modules/ext.wikimediaEvents.humanSearchRelevance.js
@@ -1,10 +1,15 @@
 ( function ( mw, $, undefined ) {
'use strict';
 
-   function oneIn( populationSize ) {
+   function sample( acceptPercentage ) {
var rand = mw.user.generateRandomSessionId(),
+   // take the first 52 bits of the rand value to match js
+   // integer precision
parsed = parseInt( rand.slice( 0, 13 ), 16 );
-   return parsed % populationSize === 0;
+   if ( acceptPercentage >= 1 ) {
+   return true;
+   }
+   return parsed / Math.pow( 2, 52 ) < acceptPercentage;
}
 
function chooseOne( options ) {
@@ -14,228 +19,23 @@
return options[ Math.floor( parsed / step ) ];
}
 
-   // Only accept enwiki, NS_MAIN for MVP feasability test
-   if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 ||
-   mw.config.get( 'wgDBname' ) !== 'enwiki'
-   ) {
+   // Page is not part of this test
+   if ( !mw.config.exists( 'wgWMESearchRelevancePages' ) ) {
return;
}
 
-   // For the MVP we are simply hardcoding the list of queries and 
articles.
-   // If the MVP shows to return data that isn't complete