Exemple #1
0
 /**
  * The general method for handling the communication with the service.
  */
 public function request($resourceName, $getParams = [], $postData = [], $extraRequestOptions = [])
 {
     // Crash if we cannot make HTTP requests.
     \Wikia\Util\Assert::true(\MWHttpRequest::canMakeRequests());
     // Add client_id and client_secret to the GET data.
     $getParams['client_id'] = $this->clientId;
     $getParams['client_secret'] = $this->clientSecret;
     // Request URI pre-processing.
     $uri = "{$this->baseUri}{$resourceName}?" . http_build_query($getParams);
     // Request options pre-processing.
     $options = ['method' => 'GET', 'timeout' => 5, 'postData' => $postData, 'noProxy' => true, 'followRedirects' => false, 'returnInstance' => true, 'internalRequest' => true];
     $options = array_merge($options, $extraRequestOptions);
     /*
      * MediaWiki's MWHttpRequest class heavily relies on Messaging API
      * (wfMessage()) which happens to rely on the value of $wgLang.
      * $wgLang is set after $wgUser. On per-request authentication with
      * an access token we use MWHttpRequest before wgUser is created so
      * we need $wgLang to be present. With GlobalStateWrapper we can set
      * the global variable in the local, function's scope, so it is the
      * same as the already existing $wgContLang.
      */
     global $wgContLang;
     $wrapper = new GlobalStateWrapper(['wgLang' => $wgContLang]);
     // Request execution.
     /** @var \MWHttpRequest $request */
     $request = $wrapper->wrap(function () use($options, $uri) {
         return \Http::request($options['method'], $uri, $options);
     });
     $this->status = $request->status;
     $output = json_decode($request->getContent());
     if (!$output) {
         throw new ClientException('Invalid response.');
     }
     return $output;
 }
Exemple #2
0
 /**
  * @param $s Status
  */
 private function subscribeToMediaWikiAnnounce(Status $s)
 {
     $params = array('email' => $this->getVar('_AdminEmail'), 'language' => 'en', 'digest' => 0);
     // Mailman doesn't support as many languages as we do, so check to make
     // sure their selected language is available
     $myLang = $this->getVar('_UserLang');
     if (in_array($myLang, $this->mediaWikiAnnounceLanguages)) {
         $myLang = $myLang == 'pt-br' ? 'pt_BR' : $myLang;
         // rewrite to Mailman's pt_BR
         $params['language'] = $myLang;
     }
     if (MWHttpRequest::canMakeRequests()) {
         $res = MWHttpRequest::factory($this->mediaWikiAnnounceUrl, array('method' => 'POST', 'postData' => $params))->execute();
         if (!$res->isOK()) {
             $s->warning('config-install-subscribe-fail', $res->getMessage());
         }
     } else {
         $s->warning('config-install-subscribe-notpossible');
     }
 }