/**
  * A method to get WAM index (list of wikis with their WAM ranks)
  *
  * @requestParam integer $wam_day [OPTIONAL] day for which the WAM scores are displayed. Defaults to yesterday
  * @requestParam integer $wam_previous_day [OPTIONAL] day from which the difference in WAM scores is calculated.
  *                             Defaults to day before yesterday
  * @requestParam integer $vertical_id [OPTIONAL] vertical for which wiki list is to be pulled. By default pulls
  *                             major verticals (2,3,9 - Gaming, Entertainment, Lifestyle)
  * @requestParam string $wiki_lang [OPTIONAL] Language code if narrowing the results to specific language. Defaults to null
  * @requestParam integer $wiki_id [OPTIONAL] Id of specific wiki to pull. Defaults to null
  * @requestParam string $wiki_word [OPTIONAL] Fragment of url to search for amongst wikis. Defaults to null
  * @requestParam boolean $exclude_blacklist [OPTIONAL] Determines if exclude blacklisted wikis (with Content Warning enabled). Defaults to false
  * @requestParam boolean $fetch_admins [OPTIONAL] Determines if admins of each wiki are to be returned. Defaults to false
  * @requestParam integer $avatar_size [OPTIONAL] Size of admin avatars in pixels if fetch_admins is enabled
  * @requestParam boolean $fetch_wiki_images [OPTIONAL] Determines if image of each wiki isto be returned. Defaults to false
  * @requestParam integer $wiki_image_width [OPTIONAL] Width of wiki image in pixels if fetch_wiki_images is enabled
  * @requestParam integer $wiki_image_height [OPTIONAL] Height of wiki image in pixels if fetch_wiki_images is enabled. You can pass here -1 to keep aspect ratio
  * @requestParam string $sort_column [OPTIONAL] Column by which to sort. Allowed values: wam_rank, wam_change. Defaults to WAM score (wam)
  * @requestParam string $sort_direction [OPTIONAL] Either ASC or DESC. Defaults to ASC
  * @requestParam integer $offset [OPTIONAL] offset from the beginning of data. Defaults to 0
  * @requestParam integer $limit [OPTIONAL] limit on fetched number of wikis. Defaults to 20, max 20
  *
  * @responseParam array $wam_index The result list of wikis
  * 	one item from index is an array that contain:
  * 		wiki_id - wiki id
  * 		wam - wam score
  * 		wam_rank - wiki wam rank in whole wam index
  * 		hub_wam_rank - wiki wam rank within its hub
  *		peak_wam_rank - the peak WAM Rank achieved by this Wiki
  * 		peak_hub_wam_rank - peak WAM Rank within its Hub
  * 		top_1k_days - the number of days that the Wiki has been in the top 1000 Wikis
  * 		top_1k_weeks - the number of weeks that the Wiki has been in the top 1000 Wikis
  * 		first_peak - the first date that the Wiki achieved its peak_wam_rank
  * 		last_peak - the last time that the Wiki was at its peak_wam_rank
  * 		title - wiki title
  * 		url - wiki url
  * 		vertical_id - wiki vertical id
  * 		wam_change - wam score change from $wam_previous_day
  * 		wam_is_new - 1 if wiki wasn't classified on $wam_previous_day, 0 if this wiki was in index
  * @responseParam array $wam_results_total The total count of wikis available for provided params
  * @responseParam integer $wam_index_date date of received list
  */
 public function getWAMIndex()
 {
     $app = F::app();
     $options = $this->getWAMParameters();
     $wamIndex = WikiaDataAccess::cacheWithLock(wfSharedMemcKey('wam_index_table', WAMService::MEMCACHE_VER, $app->wg->ContLang->getCode(), implode(':', $options)), 6 * 60 * 60, function () use($options) {
         $wamService = new WAMService();
         $wamIndex = $wamService->getWamIndex($options);
         if ($options['fetchAdmins']) {
             if (empty($wikiService)) {
                 $wikiService = new WikiService();
             }
             foreach ($wamIndex['wam_index'] as &$row) {
                 $row['admins'] = $wikiService->getMostActiveAdmins($row['wiki_id'], $options['avatarSize']);
                 $row['admins'] = $this->prepareAdmins($row['admins'], self::DEFAULT_WIKI_ADMINS_LIMIT);
             }
         }
         if ($options['fetchWikiImages']) {
             if (empty($wikiService)) {
                 $wikiService = new WikiService();
             }
             $images = $wikiService->getWikiImages(array_keys($wamIndex['wam_index']), $options['wikiImageWidth'], $options['wikiImageHeight']);
             foreach ($wamIndex['wam_index'] as $wiki_id => &$wiki) {
                 $wiki['wiki_image'] = !empty($images[$wiki_id]) ? $images[$wiki_id] : null;
             }
         }
         return $wamIndex;
     });
     if (!$this->request->isInternal() && empty($wamIndex['wam_index'])) {
         $wamIndex['wam_index'] = (object) $wamIndex['wam_index'];
     }
     $this->setResponseData(['wam_index' => $wamIndex['wam_index'], 'wam_results_total' => $wamIndex['wam_results_total'], 'wam_index_date' => $wamIndex['wam_index_date']], ['urlFields' => ['avatarUrl', 'userPageUrl', 'userContributionsUrl']], self::WAM_RESPONSE_CACHE_VALIDITY);
 }
Beispiel #2
0
 /**
  * Returns the latest WAM score provided a wiki ID
  * @param int $wikiId
  * @return number
  */
 public function getCurrentWamScoreForWiki($wikiId)
 {
     wfProfileIn(__METHOD__);
     $memKey = wfSharedMemcKey('datamart', self::MEMCACHE_VER, 'wam', $wikiId);
     $getData = function () use($wikiId) {
         $db = $this->getDB();
         $result = $db->select(array('fact_wam_scores'), array('wam'), array('wiki_id' => $wikiId), __METHOD__, array('ORDER BY' => 'time_id DESC', 'LIMIT' => 1));
         return ($row = $db->fetchObject($result)) ? $row->wam : 0;
     };
     $wamScore = WikiaDataAccess::cacheWithLock($memKey, self::CACHE_DURATION, $getData);
     wfProfileOut(__METHOD__);
     return $wamScore;
 }
 public function getWikiAdmins($wikiId, $avatarSize, $limit = null)
 {
     return WikiaDataAccess::cacheWithLock(wfsharedMemcKey('get_wiki_admins', $wikiId, $avatarSize, $limit), 3 * 60 * 60, function () use($wikiId, $avatarSize, $limit) {
         $admins = array();
         try {
             $admins = $this->getWikiAdminIds($wikiId, false, true, $limit, false);
             $checkUserCallback = function ($user) {
                 return true;
             };
             foreach ($admins as &$admin) {
                 $userInfo = $this->getUserInfo($admin, $wikiId, $avatarSize, $checkUserCallback);
                 $admin = $userInfo;
             }
         } catch (Exception $e) {
             // for devboxes
         }
         return $admins;
     });
 }
Beispiel #4
0
 /**
  * Get list of hidden categories (cached in memcached using WikiaDataAccess).
  *
  * Using WikiaDataAccess to limit number of processes regenerating cache and prevent delay when other
  * process is already regenerating data. The stalled data is returned in the latter case.
  *
  * @see https://wikia-inc.atlassian.net/browse/PLATFORM-615
  *
  * @return array
  */
 private function getHiddenCategories()
 {
     wfProfileIn(__METHOD__);
     $fname = __METHOD__;
     if (!is_array(self::$hiddenCategories)) {
         self::$hiddenCategories = WikiaDataAccess::cacheWithLock(wfMemcKey('hidden-categories-v2'), WikiaResponse::CACHE_SHORT, function () use($fname) {
             $dbr = wfGetDB(DB_SLAVE);
             $res = $dbr->query("SELECT page_title FROM page JOIN page_props ON page_id=pp_page AND pp_propname='hiddencat' LIMIT " . self::HIDDEN_CATEGORIES_LIMIT, $fname);
             $hiddenCategories = array();
             while ($row = $dbr->fetchObject($res)) {
                 $hiddenCategories[] = $row->page_title;
             }
             return $hiddenCategories;
         });
     }
     wfProfileOut(__METHOD__);
     return self::$hiddenCategories;
 }
 /**
  * get category rank, based on number of articles assigned
  * @return array
  */
 protected function getCategoryRank()
 {
     wfProfileIn(__METHOD__);
     $results = WikiaDataAccess::cacheWithLock(wfMemcKey(__METHOD__), WikiaResponse::CACHE_STANDARD, function () {
         global $wgContentNamespaces;
         $db = wfGetDB(DB_SLAVE);
         $sql = (new WikiaSQL())->SELECT("COUNT(cl_to)")->AS_("count")->FIELD('cl_to')->FROM('categorylinks')->GROUP_BY('cl_to')->HAVING('count > 1')->ORDER_BY(['count', 'desc']);
         if (count($wgContentNamespaces) > 0) {
             $join_cond = count($wgContentNamespaces) == 1 ? "page_namespace = " . intval(reset($wgContentNamespaces)) : "page_namespace in ( " . $db->makeList($wgContentNamespaces) . " )";
             $sql->JOIN('page')->ON("page_id = cl_from AND {$join_cond}");
         }
         $rank = 1;
         $results = $sql->runLoop($db, function (&$results, $row) use(&$rank) {
             $results[$row->cl_to] = $rank;
             $rank++;
         });
         return $results;
     });
     wfProfileOut(__METHOD__);
     return $results;
 }
Beispiel #6
0
 /**
  * Return array of top five users
  *
  * Called by NavigationModel::handleExtraWords
  *
  * Author: Inez Korczynski (inez at wikia.com)
  * @return array
  */
 public static final function GetTopFiveUsers($limit = 7)
 {
     wfProfileIn(__METHOD__);
     $fname = __METHOD__;
     $limit = min($limit, self::TOP_USERS_MAX_LIMIT);
     $results = WikiaDataAccess::cacheWithLock(wfMemcKey(__METHOD__), WikiaResponse::CACHE_STANDARD, function () use($fname) {
         global $wgCityId, $wgSpecialsDB;
         $dbr = wfGetDB(DB_SLAVE);
         $users_list = $dbr->selectFieldValues("user_groups", "ug_user", ['ug_group' => ['staff', 'bot']], $fname);
         // add more blacklisted user IDs
         $users_list[] = '0';
         $users_list[] = '22439';
         // Wikia
         $users_list[] = '929702';
         // CreateWiki script
         $users_list = array_unique($users_list);
         $dbs = wfGetDB(DB_SLAVE, [], $wgSpecialsDB);
         $res = $dbs->select('events_local_users', 'user_id', ['wiki_id' => $wgCityId, sprintf('user_id NOT IN (%s)', $dbs->makeList($users_list))], $fname, ['LIMIT' => self::TOP_USERS_MAX_LIMIT * 4, 'ORDER BY' => 'edits DESC']);
         $results = [];
         while ($row = $dbs->fetchObject($res)) {
             $user = User::newFromID($row->user_id);
             if (!$user->isBlocked() && !$user->isAllowed('bot') && $user->getUserPage()->exists()) {
                 $article['url'] = $user->getUserPage()->getLocalUrl();
                 $article['text'] = $user->getName();
                 $results[] = $article;
             }
             // no need to check more users here
             if (count($results) >= self::TOP_USERS_MAX_LIMIT) {
                 break;
             }
         }
         $dbs->freeResult($res);
         return $results;
     });
     // we cache self::TOP_USERS_MAX_LIMIT items
     // now return the requested number of items
     $results = array_slice($results, 0, $limit);
     wfProfileOut(__METHOD__);
     return $results;
 }