/**
  * Summarizes all the requests made in this process and reports
  * them along with the test they belong to.
  * Only public due to php 5.3 not having access from closures
  */
 public static function reportLogContexts()
 {
     global $wgRequest;
     if (!self::$logContexts) {
         return;
     }
     $ut = UserTesting::getInstance();
     if (!$ut->getActiveTestNames()) {
         return;
     }
     $queries = array();
     $parameters = array('index' => array(), 'queryType' => array());
     $elasticTook = 0;
     $hits = 0;
     foreach (self::$logContexts as $context) {
         $hits += isset($context['hitsTotal']) ? $context['hitsTotal'] : 0;
         if (isset($context['query'])) {
             $queries[] = $context['query'];
         }
         if (isset($context['elasticTookMs'])) {
             $elasticTook += $context['elasticTookMs'];
         }
         if (isset($context['index'])) {
             $parameters['index'][] = $context['index'];
         }
         if (isset($context['queryType'])) {
             $parameters['queryType'][] = $context['queryType'];
         }
     }
     foreach (array('index', 'queryType') as $key) {
         $parameters[$key] = array_unique($parameters[$key]);
     }
     $message = array(wfWikiId(), '', FormatJson::encode($queries), $hits, self::getExecutionContext(), $elasticTook, $wgRequest->getIP(), preg_replace("/[\t\"']/", "", $wgRequest->getHeader('User-Agent')), FormatJson::encode($parameters));
     $tests = array();
     $logger = LoggerFactory::getInstance('CirrusSearchUserTesting');
     foreach ($ut->getActiveTestNames() as $test) {
         $bucket = $ut->getBucket($test);
         $message[1] = "{$test}-{$bucket}";
         $logger->debug(implode("\t", $message));
     }
     self::$logContexts = null;
 }
 public function testDoesNotReinitializeFromGetInstance()
 {
     $this->setMwGlobals(array('wgCirrusSearchUserTesting' => $this->config('test', 10, array('wgCirrusSearchBoostLinks' => true)), 'wgCirrusSearchBoostLinks' => false));
     $ut = UserTesting::getInstance(function () {
         return true;
     });
     $this->assertEquals(true, $GLOBALS['wgCirrusSearchBoostLinks']);
     $GLOBALS['wgCirrusSearchBoostLinks'] = false;
     $ut = UserTesting::getInstance(function () {
         return true;
     });
     $this->assertEquals(false, $GLOBALS['wgCirrusSearchBoostLinks']);
 }
 private static function buildUserTestingLog()
 {
     global $wgRequest;
     $ut = UserTesting::getInstance();
     if (!$ut->getActiveTestNames()) {
         return;
     }
     $queries = array();
     $parameters = array('index' => array(), 'queryType' => array(), 'acceptLang' => $GLOBALS['wgRequest']->getHeader('Accept-Language'));
     $elasticTook = 0;
     $hits = 0;
     foreach (self::$logContexts as $context) {
         $hits += isset($context['hitsTotal']) ? $context['hitsTotal'] : 0;
         if (isset($context['query'])) {
             $queries[] = $context['query'];
         }
         if (isset($context['elasticTookMs'])) {
             $elasticTook += $context['elasticTookMs'];
         }
         if (isset($context['index'])) {
             $parameters['index'][] = $context['index'];
         }
         if (isset($context['queryType'])) {
             $parameters['queryType'][] = $context['queryType'];
         }
         if (!empty($context['langdetect'])) {
             $parameters['langdetect'] = $context['langdetect'];
         }
     }
     foreach (array('index', 'queryType') as $key) {
         $parameters[$key] = array_values(array_unique($parameters[$key]));
     }
     $message = array(wfWikiId(), '', FormatJson::encode($queries), $hits, self::getExecutionContext(), $elasticTook, $wgRequest->getIP(), preg_replace("/[\t\"']/", "", $wgRequest->getHeader('User-Agent')), FormatJson::encode($parameters), self::generateIdentToken());
     $logger = LoggerFactory::getInstance('CirrusSearchUserTesting');
     foreach ($ut->getActiveTestNames() as $test) {
         $bucket = $ut->getBucket($test);
         $message[1] = "{$test}-{$bucket}";
         $logger->debug(implode("\t", $message));
     }
 }