2declare( strict_types = 1 );
4namespace MediaWiki\Extension\Translate\WebService;
6use MediaWiki\MediaWikiServices;
18 protected $queries = [];
19 protected $responses = [];
20 protected $timeout = 0;
21 protected $hasRun =
false;
28 $this->queries[] = $query;
30 $this->timeout = max( $query->getTimeout(), $this->timeout );
31 return count( $this->queries ) - 1;
40 if ( !$this->hasRun ) {
41 throw new RuntimeException(
'Tried to get response before queries ran' );
48 public function run(): void {
51 $version = TranslateUtils::getVersion();
54 'reqTimeout' => $this->timeout,
56 'userAgent' =>
"MediaWiki Translate extension $version for $wgSitename"
59 $httpRequestFactory = MediaWikiServices::getInstance()->getHttpRequestFactory();
61 $http = $httpRequestFactory->createMultiClient( $clientOptions );
62 $responses = $http->runMulti( $this->getMultiHttpQueries( $this->queries ) );
63 foreach ( $responses as $index => $response ) {
64 $this->responses[$index] = $response;
77 'url' => $q->getUrl(),
78 'method' => $q->getMethod(),
79 'query' => $q->getQueryParameters(),
80 'body' => $q->getBody(),
81 'headers' => $q->getHeaders(),
85 return array_map( $converter, $queries );
Essentially random collection of helper functions, similar to GlobalFunctions.php.