/** * Get 10 most popular cross wiki articles * * @param string $hubName * @param string $langCode * @return array of articles - format * [ * ['wikiId' => 1, 'articleId' => 2], * ['wikiId' => 2, 'articleId' => 3], * ] */ protected function getTopArticles($hubName, $langCode) { wfProfileIn(__METHOD__); $topArticles = []; $results = \DataMartService::getTopCrossWikiArticlesByPageview($hubName, [$langCode], [NS_MAIN]); $articlesCount = ceil(self::MAX_LIMIT / count($results)); foreach ($results as $wikiResult) { for ($i = 0; $i < $articlesCount; $i++) { $topArticles[] = ['wikiId' => $wikiResult['wiki']['id'], 'articleId' => $wikiResult['articles'][$i]['id']]; } } wfDebug(sprintf("%s: returning %s items\n", __METHOD__, count($topArticles))); wfProfileOut(__METHOD__); return $topArticles; }
/** * Get the top articles by pageviews for a hub optionally filtering by namespace and/or language, * available only on the www.wikia.com main domain (see examples) * * @requestParam string $hub The name of the vertical (e.g. Gaming, Entertainment, Lifestyle, etc.) to use as a filter * @requestParam string $lang [OPTIONAL] The language code (e.g. en, de, fr, es, it, etc.) to use as a filter * @requestParam array $namespaces [OPTIONAL] The ID's of the namespaces (e.g. 0, 14, 6, etc.) to use as a filter, comma separated * * @responseParam array $items The list of top 10 wikis, each with a collection of top articles, the schema is as follows:[ [ wiki => [ id, name, language, domain ], articles => [ id, ns ] ] ] * * @example http://www.wikia.com/wikia.php?controller=ArticlesApi&method=getTopByHub&hub=Gaming * @example http://www.wikia.com/wikia.php?controller=ArticlesApi&method=getTopByHub&hub=Gaming&namespaces=0,14 * @example http://www.wikia.com/wikia.php?controller=ArticlesApi&method=getTopByHub&hub=Gaming&lang=de */ public function getTopByHub() { wfProfileIn(__METHOD__); if ($this->wg->DBname == 'wikiaglobal') { $hub = trim($this->request->getVal(self::PARAMETER_HUB, null)); $langs = $this->request->getArray(self::PARAMETER_LANGUAGES); $namespaces = self::processNamespaces($this->request->getArray(self::PARAMETER_NAMESPACES, null), __METHOD__); if (empty($hub)) { wfProfileOut(__METHOD__); throw new MissingParameterApiException(self::PARAMETER_HUB); } if (!empty($langs) && count($langs) > self::LANGUAGES_LIMIT) { wfProfileOut(__METHOD__); throw new LimitExceededApiException(self::PARAMETER_LANGUAGES, self::LANGUAGES_LIMIT); } $res = DataMartService::getTopCrossWikiArticlesByPageview($hub, $langs, $namespaces); wfProfileOut(__METHOD__); if (empty($res)) { wfProfileOut(__METHOD__); throw new NotFoundApiException(); } $this->response->setVal('items', $res); } else { wfProfileOut(__METHOD__); throw new BadRequestApiException(); } }