public function testShouldProperlyReadCORSConfigFromGlobal()
 {
     global $wgCORSAllowOrigin;
     $wgCORSAllowOrigin = ["a", "b", "c"];
     $dummyResponse = new WikiaResponse("tmp");
     $cors = new CrossOriginResourceSharingHeaderHelper();
     $cors->readConfig()->setHeaders($dummyResponse);
     $headers = $dummyResponse->getHeader(CrossOriginResourceSharingHeaderHelper::ALLOW_ORIGIN_HEADER_NAME);
     $this->assertEquals($headers[0]['value'], 'a,b,c');
 }
 public function getAsSimpleJson()
 {
     $this->cors->setHeaders($this->response);
     $articleId = (int) $this->getRequest()->getInt(self::SIMPLE_JSON_ARTICLE_ID_PARAMETER_NAME, NULL);
     if (empty($articleId)) {
         throw new InvalidParameterApiException(self::SIMPLE_JSON_ARTICLE_ID_PARAMETER_NAME);
     }
     $article = Article::newFromID($articleId);
     if (empty($article)) {
         throw new NotFoundApiException("Unable to find any article with " . self::SIMPLE_JSON_ARTICLE_ID_PARAMETER_NAME . '=' . $articleId);
     }
     $jsonFormatService = new JsonFormatService();
     $jsonSimple = $jsonFormatService->getSimpleFormatForArticle($article);
     $this->setResponseData($jsonSimple, ['imgFields' => 'images', 'urlFields' => 'src'], self::SIMPLE_JSON_VARNISH_CACHE_EXPIRATION);
 }
 /**
  * Gets the information about wikis
  *
  * @requestParam array $ids The list of wiki ids that will be fetched
  * @requestParam int $height [OPTIONAL] Thumbnail height in pixels
  * @requestParam int $width [OPTIONAL] Thumbnail width in pixels
  * @requestParam int $snippet [OPTIONAL] Maximum number of words returned in description
  *
  * @responseParam array $items The list of wikis, each containing: title, url, description, thumbnail, no. of articles, no. of photos, list of top contributors, no. of videos
  *
  * @example &ids=159,831,3125
  * @example &ids=159,831,3125&width=100
  * @example &ids=159,831,3125&height=100&width=100&snippet=25
  */
 public function getDetails()
 {
     wfProfileIn(__METHOD__);
     $this->cors->setHeaders($this->response);
     $this->setOutputFieldType("items", self::OUTPUT_FIELD_TYPE_OBJECT);
     $ids = $this->request->getVal(self::PARAMETER_WIKI_IDS, null);
     if (!empty($ids)) {
         $ids = explode(',', $ids);
     } else {
         throw new MissingParameterApiException(self::PARAMETER_WIKI_IDS);
     }
     $params = $this->getDetailsParams();
     $items = array();
     foreach ($ids as $wikiId) {
         $details = $this->getWikiDetailsService()->getWikiDetails($wikiId, $params['imageWidth'], $params['imageHeight'], $params['length']);
         if (!empty($details)) {
             $items[(int) $wikiId] = $details;
         }
     }
     $this->setResponseData(['items' => $items], ['urlFields' => ['wordmark', 'image']], static::CACHE_1_DAY);
     wfProfileOut(__METHOD__);
 }