예제 #1
0
 public function getWikisList($limit = null, $batch = 1)
 {
     wfProfileIn(__METHOD__);
     $cacheKey = $this->generateCacheKey(__METHOD__);
     $games = $this->loadFromCache($cacheKey);
     if (empty($games)) {
         $games = array();
         $wikiFactoryRecommendVar = WikiFactory::getVarByName(self::WF_WIKI_RECOMMEND_VAR, null);
         if (!empty($wikiFactoryRecommendVar)) {
             $recommendedIds = WikiFactory::getCityIDsFromVarValue($wikiFactoryRecommendVar->cv_variable_id, true, '=');
             foreach ($recommendedIds as $wikiId) {
                 $wikiName = WikiFactory::getVarValueByName('wgSitename', $wikiId);
                 $wikiGames = WikiFactory::getVarValueByName('wgWikiTopics', $wikiId);
                 $wikiDomain = str_replace('http://', '', WikiFactory::getVarValueByName('wgServer', $wikiId));
                 $wikiThemeSettings = WikiFactory::getVarValueByName('wgOasisThemeSettings', $wikiId);
                 $wordmarkUrl = $wikiThemeSettings['wordmark-image-url'];
                 $wordmarkType = $wikiThemeSettings['wordmark-type'];
                 //$wikiLogo = WikiFactory::getVarValueByName( "wgLogo", $wikiId );
                 $games[] = array('name' => !empty($wikiThemeSettings['wordmark-text']) ? $wikiThemeSettings['wordmark-text'] : $wikiName, 'games' => !empty($wikiGames) ? $wikiGames : '', 'color' => !empty($wikiThemeSettings['wordmark-color']) ? $wikiThemeSettings['wordmark-color'] : '#0049C6', 'backgroundColor' => !empty($wikiThemeSettings['color-page']) ? $wikiThemeSettings['color-page'] : '#FFFFFF', 'domain' => $wikiDomain, 'wordmarkUrl' => $wordmarkType == 'graphic' && !empty($wordmarkUrl) ? $wordmarkUrl : '');
             }
         } else {
             wfProfileOut(__METHOD__);
             throw new WikiaException('WikiFactory variable \'' . self::WF_WIKI_RECOMMEND_VAR . '\' not found');
         }
         $this->storeInCache($cacheKey, $games);
     }
     $ret = wfPaginateArray($games, $limit, $batch);
     wfProfileOut(__METHOD__);
     return $ret;
 }
 public function getBatch()
 {
     //see Category::newFromName for valid format
     $categoryName = str_replace(' ', '_', $this->request->getVal('category'));
     $index = $this->request->getVal('index');
     $batch = $this->request->getInt('batch');
     $err = false;
     if (!empty($categoryName) && isset($index) && !empty($batch)) {
         $category = Category::newFromTitle(Title::newFromText($categoryName, NS_CATEGORY));
         if ($category instanceof Category) {
             $this->initModel();
             $data = wfPaginateArray($this->model->getCollection($category)['items'][$index], WikiaMobileCategoryModel::BATCH_SIZE, $batch);
             if (!empty($data['items'])) {
                 //cache response for 3 hours in varnish and browser
                 $this->response->setCacheValidity(WikiaMobileCategoryService::CACHE_TIME);
                 $this->response->setVal('itemsBatch', $data['items']);
             } else {
                 $err = "No Data for given index or batch";
             }
         } else {
             $err = "Wrong category";
         }
     } else {
         $err = "Wrong values given";
     }
     if ($err) {
         Wikia::log(__METHOD__, false, "Error loading batch {$batch} for index {$index} in Category {$categoryName}. Msg: {$err}");
         header('Status: 404 Not Found', true, 404);
     }
 }
 /**
  * Finds wikis which name or topic match a keyword optionally filtering by vertical (hub) and/or language,
  * the total amount of results is limited to 250 items
  *
  * @requestParam string $keyword search term
  * @requestParam string $hub [OPTIONAL] The name of the vertical (e.g. Gaming, Entertainment, Lifestyle, etc.) to use as a filter
  * @requestParam string $lang [OPTIONAL] The comma-separated list of language codes (e.g. en,de,fr,es,it, etc.) to use as a filter
  * @requestParam integer $limit [OPTIONAL] The number of items per each batch/page, defaults to 25
  * @requestParam integer $batch [OPTIONAL] The batch/page index to retrieve, defaults to 1
  * @requestParam bool $includeDomain [OPTIONAL] Wheter to include wikis' domains as search targets or not,
  * defaults to false
  * @requestParam string $expand [OPTIONAL] if set will expand result with getDetails data
  *
  * @responseParam array $items The list of wikis matching the keyword and the optional filtering
  * @responseParam integer $total The total number of results
  * @responseParam integer $currentBatch The index of the current batch/page
  * @responseParam integer $batches The total number of batches/pages
  * @responseParam integer $next The amount of items in the next batch/page
  *
  * @example http://www.wikia.com/wikia.php?controller=WikisApi&method=getByString&string=call+of+duty&hub=Gaming&lang=en
  */
 public function getByString()
 {
     wfProfileIn(__METHOD__);
     $keyword = trim($this->request->getVal(self::PARAMETER_KEYWORD, null));
     $hub = trim($this->request->getVal('hub', null));
     $langs = $this->request->getArray(self::PARAMETER_LANGUAGES);
     $limit = $this->request->getInt('limit', self::ITEMS_PER_BATCH);
     $batch = $this->request->getInt('batch', 1);
     $includeDomain = $this->request->getBool('includeDomain', false);
     $expand = $this->request->getBool('expand', false);
     if (empty($keyword)) {
         throw new MissingParameterApiException(self::PARAMETER_KEYWORD);
     }
     if (!empty($langs) && count($langs) > self::LANGUAGES_LIMIT) {
         throw new LimitExceededApiException(self::PARAMETER_LANGUAGES, self::LANGUAGES_LIMIT);
     }
     $results = $this->getWikiService()->getByString($keyword, $langs, $hub, $includeDomain);
     $results = $this->filterNonCommercial($results);
     if (is_array($results)) {
         $batches = wfPaginateArray($results, $limit, $batch);
         if ($expand) {
             $batches = $this->expandBatches($batches);
         }
     } else {
         throw new NotFoundApiException();
     }
     //store only for 24h to allow new wikis
     //to appear in a reasonable amount of time in the search
     //results
     $this->setResponseData($batches, ['urlFields' => ['image', 'wordmark', 'url']], static::CACHE_1_DAY);
     wfProfileOut(__METHOD__);
 }
 * @var $collections Array
 * @var $requestedIndex Integer
 * @var $requestedBatch Integer
 * @var $total Integer
 */
?>
<section class="alphaSec noWrap">
	<header>
		<?php 
echo wfMessage('wikiamobile-categories-items-total', $wg->ContLang->formatNum($total))->inContentLanguage()->text();
?>
	</header>
<?php 
foreach ($collections as $index => $collection) {
    $batch = $index == $requestedIndex ? $requestedBatch : 1;
    $itemsBatch = wfPaginateArray($collection, WikiaMobileCategoryModel::BATCH_SIZE, $batch);
    $currentBatch = $itemsBatch['currentBatch'];
    $nextBatch = $currentBatch + 1;
    $prevBatch = $currentBatch - 1;
    $urlSafeIndex = rawurlencode($index);
    $id = 'catAlpha' . $urlSafeIndex;
    ?>
	<h2 id="<?php 
    echo $id;
    ?>
" data-count="<?php 
    echo $wg->ContLang->formatNum($itemsBatch['total']);
    ?>
"><?php 
    echo $index;
    ?>