public function index() { wfProfileIn(__METHOD__); Wikia::addAssetsToOutput('recent_wiki_activity_scss'); Wikia::addAssetsToOutput('recent_wiki_activity_js'); $this->changeList = WikiaDataAccess::cache(wfMemcKey(self::$memcKey), 0, function () { global $wgContentNamespaces, $wgLang; $maxElements = 4; $includeNamespaces = implode('|', $wgContentNamespaces); $parameters = array('type' => 'widget', 'maxElements' => $maxElements, 'flags' => array('shortlist'), 'uselang' => $wgLang->getCode(), 'includeNamespaces' => $includeNamespaces); $feedProxy = new ActivityFeedAPIProxy($includeNamespaces, $this->userName); $feedProvider = new DataFeedProvider($feedProxy, 1, $parameters); $feedData = $feedProvider->get($maxElements); foreach ($feedData['results'] as &$result) { if (!empty($result['articleComment'])) { $title = Title::newFromText($result['title'], $result['ns']); if ($title instanceof Title) { $result['url'] = $title->getLocalURL(); } } } return $feedData['results']; }); wfProfileOut(__METHOD__); }
/** * @desc Returns an array with all available components configuration * * @return array */ public function getAllComponents() { $components = WikiaDataAccess::cache(wfSharedMemcKey(__CLASS__, 'all_components_list_with_details', self::MEMCACHE_VERSION_KEY, $this->userLangCode), Wikia\UI\Factory::MEMCACHE_EXPIRATION, [$this, 'getAllComponentsFromDirectories']); $this->initComponents($components); $this->includeComponentsAssets($components); return $components; }
public function set($key, $value) { $db = $this->getSpecialsDB(DB_MASTER); $db->replace(self::TABLE_NAME, [self::DB_KEY_FIELD], [self::DB_KEY_FIELD => $key, self::DB_VALUE_FIELD => $this->encodeData($value)]); WikiaDataAccess::cache($this->getMemcacheKey($key), self::CACHE_DURATION, function () use($value) { return $value; }, WikiaDataAccess::REFRESH_CACHE); }
protected static function getFileInfo($name) { $info = \WikiaDataAccess::cache(self::getFileKey($name), self::ICON_CACHE_TTL, function () use($name) { $file = \GlobalFile::newFromText($name . '.gif', \Wikia::NEWSLETTER_WIKI_ID); return ['name' => $name, 'url' => $file->getUrlGenerator()->url(), 'height' => $file->getHeight(), 'width' => $file->getWidth()]; }); return $info; }
public function getCommercialUseNotAllowedWikis() { if (empty(self::$wikiList)) { self::$wikiList = WikiaDataAccess::cache(wfSharedMemcKey(self::CACHE_KEY_COMMERCIAL_NOT_ALLOWED), self::CACHE_VALID_TIME, function () { return $this->getWikisWithVar(); }); } return self::$wikiList; }
public function getCollection(Category $category) { return WikiaDataAccess::cache($this->getItemsCollectionCacheKey($category->getID()), self::CACHE_TTL_ITEMSCOLLECTION, function () use($category) { wfProfileIn(__METHOD__); $viewer = new WikiaMobileCategoryViewer($category); $viewer->doCategoryQuery(); wfProfileOut(__METHOD__); return $viewer->getData(); }); }
public function loadData(EditHubModel $model, $params) { $hubParams = $this->getHubsParams(); $lastTimestamp = $model->getLastPublishedTimestamp($hubParams, $params['ts']); $structuredData = WikiaDataAccess::cache($this->getMemcacheKey($lastTimestamp, $this->skinName), 6 * 60 * 60, function () use($model, $params) { return $this->loadStructuredData($model, $params); }); if ($this->getShouldFilterCommercialData()) { $structuredData = $this->filterCommercialData($structuredData); } return $structuredData; }
/** * get stats * @responseParam integer visitors * @responseParam integer mobilePercentage * @responseParam integer totalPages * @responseParam integer edits * @responseParam integer communities * @responseParam integer newCommunities */ public function getWikiaStats() { wfProfileIn(__METHOD__); $statsFromWF = WikiaStatsModel::getWikiaStatsFromWF(); $stats = WikiaDataAccess::cache($this->getStatsMemcacheKey(), self::WIKIA_STATS_CACHE_VALIDITY, function () use($statsFromWF) { $wikiaStatsModel = new WikiaStatsModel(); return $wikiaStatsModel->getWikiaStatsIncludingFallbacks($statsFromWF); }); foreach ($stats as $key => $value) { $this->{$key} = $value; } wfProfileOut(__METHOD__); }
/** * @param int $limit limit number of results. * @param array $namespaces list of namespaces to filter by. No filter applied if null * @return array */ public function getLatestRevisions($limit, $namespaces) { $key = self::createCacheKey($this->queryLimit, $namespaces); $listOfRevisions = WikiaDataAccess::cache($key, $this->cacheTime, function () use($namespaces) { return $this->getLatestRevisionsNoCacheAllowDuplicates($this->queryLimit, $namespaces); }); $filterMethod = $this->getFilterMethod(); if ($filterMethod !== self::DEFAULT_FILTERING_METHOD) { $listOfRevisions = $this->{$filterMethod}($listOfRevisions); } $listOfRevisions = $this->limitCount($listOfRevisions, $limit); return $listOfRevisions; }
/** * @param int $articleId * @param int $limit - max limit = 10 * @return array of articles with details */ public function get($articleId, $limit) { wfProfileIn(__METHOD__); $hubName = $this->getHubName(); $lang = $this->getContentLangCode(); $out = \WikiaDataAccess::cache(\wfSharedMemcKey('RecommendationApi', self::RECOMMENDATION_ENGINE, $hubName, $lang, self::MCACHE_VERSION), \WikiaResponse::CACHE_STANDARD, function () use($hubName, $lang) { $topArticles = $this->getTopArticles($hubName, $lang); return $this->getArticlesInfo($topArticles); }); shuffle($out); $out = array_slice($out, 0, $limit); wfProfileOut(__METHOD__); return $out; }
/** * data provider * * @author Maciej Błaszkowski <marooned at wikia-inc.com> * * @param User $user * @return array list of global groups */ static function getGlobalGroups(User $user) { if ($user->isAnon()) { return []; } $fname = __METHOD__; $userId = $user->getId(); if (!isset(self::$globalGroups[$userId])) { $globalGroups = WikiaDataAccess::cache(self::getMemcKey($user), WikiaResponse::CACHE_LONG, function () use($userId, $fname) { $dbr = self::getDB(); return $dbr->selectFieldValues('user_groups', 'ug_group', ['ug_user' => $userId], $fname); }); global $wgWikiaGlobalUserGroups; self::$globalGroups[$userId] = array_intersect($globalGroups, $wgWikiaGlobalUserGroups); } return self::$globalGroups[$userId]; }
/** * @desc Fetch all time top contributors for article * * @param int $articleId - Article id * @param $limit - maximum number of contributors to fetch * @return array */ public function topContributorsPerArticle($articleId, $limit) { $key = self::getTopContributorsKey($articleId, $limit); $method = __METHOD__; $contributions = WikiaDataAccess::cache($key, self::CACHE_TIME_TOP_CONTRIBUTORS, function () use($articleId, $limit, $method) { // Log DB hit Wikia::log($method, false, sprintf('Cache for articleId: %d was empty', $articleId)); $db = wfGetDB(DB_SLAVE); $res = $db->select('revision', ['rev_user', 'count(1) AS cntr'], ['rev_page = ' . $articleId, 'rev_deleted = 0', 'rev_user != 0'], $method, ['GROUP BY' => 'rev_user', 'ORDER BY' => 'count(1) DESC', 'LIMIT' => $limit]); $result = []; while ($row = $db->fetchObject($res)) { $result[(int) $row->rev_user] = (int) $row->cntr; } return $result; }); // Cached results may contain more than the $limit results $contributions = array_slice($contributions, 0, $limit, true); return array_keys($contributions); }
function testCacheHit() { $key = 'TESTKEY'; $value = 'TESTVALUE' . rand(); $ttl = 568; // Mock our memcache class $memc = $this->getMock('MemcachedPhpBagOStuff'); // 'get' should be called and return our value $memc->expects($this->once())->method('get')->willReturn($value); // 'set' should never be called $memc->expects($this->never())->method('set'); // Set the memc used to our mock object F::app()->wg->Memc = $memc; // Cache backed data access $returnValue = WikiaDataAccess::cache($key, $ttl, function () use($value) { return $value; }); // Make sure we get back what we expect $this->assertEquals($value, $returnValue, 'Cache MISS test'); }
/** * Gets data from ArticlesApi and renders it */ public function index() { $this->response->setTemplateEngine(WikiaResponse::TEMPLATE_ENGINE_MUSTACHE); if ($this->wg->Request->getVal('action', 'view') == 'view' && $this->wg->Title->getArticleId() != 0) { $trendingArticles = WikiaDataAccess::cache(wfMemcKey(__METHOD__, self::MAX_TRENDING_ARTICLES), 86400, function () { $trendingArticles = []; //fetch Trending Articles try { $trendingArticlesData = $this->app->sendRequest('ArticlesApi', 'getTop')->getVal('items'); } catch (Exception $e) { $trendingArticlesData = false; } if (!empty($trendingArticlesData)) { $items = array_slice($trendingArticlesData, 0, self::MAX_TRENDING_ARTICLES); //load data from response to template $trendingArticles = []; foreach ($items as $item) { $img = $this->app->sendRequest('ImageServing', 'getImages', ['ids' => [$item['id']], 'height' => self::IMG_HEIGHT, 'width' => self::IMG_WIDTH, 'count' => 1])->getVal('result'); $thumbnail = $img[$item['id']][0]['url']; if (empty($thumbnail)) { $thumbnail = false; } $trendingArticles[] = ['url' => $item['url'], 'title' => $item['title'], 'imgUrl' => $thumbnail, 'width' => self::IMG_WIDTH, 'height' => self::IMG_HEIGHT]; } } return $trendingArticles; }); if (!empty($trendingArticles)) { $this->response->setVal('trendingArticles', $trendingArticles); $this->response->setVal('blankImg', $this->wg->BlankImgUrl); $this->response->setVal('trendingArticlesHeading', wfMessage('wikiamobile-trending-articles-heading')->plain()); } else { $this->skipRendering(); } } else { $this->skipRendering(); } }
/** * @param $category * @return array|null|string */ private static function getCategoryMembers($category, $limit = 5000, $offset = '', $namespaces = '', $sort = 'sortkey', $dir = 'asc') { return WikiaDataAccess::cache(self::getCacheKey($category, self::CATEGORY_CACHE_ID, [$limit, $offset, $namespaces, $dir]), self::getMetadataCacheTime(), function () use($category, $limit, $offset, $namespaces, $sort, $dir) { $ids = ApiService::call(array('action' => 'query', 'list' => 'categorymembers', 'cmprop' => 'ids|title', 'cmsort' => $sort, 'cmnamespace' => $namespaces, 'cmdir' => $dir, 'cmtitle' => $category, 'cmlimit' => $limit, 'cmcontinue' => $offset)); if (!empty($ids)) { return array($ids['query']['categorymembers'], !empty($ids['query-continue']) ? $ids['query-continue']['categorymembers']['cmcontinue'] : null); } else { return null; } }); }
public function getLastMessage() { $key = wfMemcKey(__CLASS__, '-thread-lastreply-key', $this->mThreadId); $threadId = $this->mThreadId; $data = WikiaDataAccess::cache($key, 30 * 24 * 60 * 60, function () use($threadId) { $db = wfGetDB(DB_SLAVE); $row = $db->selectRow(array('comments_index'), array('max(first_rev_id) rev_id'), array('parent_comment_id' => $threadId, 'archived' => 0, 'deleted' => 0, 'removed' => 0), __METHOD__); return $row; }); // get last post info $revision = Revision::newFromId($data->rev_id); if ($revision instanceof Revision) { $title = $revision->getTitle(); $wallMessage = WallMessage::newFromId($title->getArticleId()); if (!empty($wallMessage)) { $wallMessage->load(); return $wallMessage; } } return null; }
private function getCuratedContentData($section = null) { try { $data = WikiaDataAccess::cache(self::curatedContentDataMemcKey($section), WikiaResponse::CACHE_STANDARD, function () use($section) { $rawData = $this->sendRequest('CuratedContent', 'getList', empty($section) ? [] : ['section' => $section])->getData(); return $this->mercuryApi->processCuratedContent($rawData); }); } catch (NotFoundException $ex) { WikiaLogger::instance()->info('Curated content and categories are empty'); } return $data; }
public function hasAtLeast($ns, $count) { wfProfileIn(__METHOD__); $out = WikiaDataAccess::cache(wfMemcKey('Forum_hasAtLeast', $ns, $count), 24 * 60 * 60, function () use($ns, $count) { $db = wfGetDB(DB_MASTER); // check if there is more then 5 forum pages (5 is number of forum pages from starter) // limit 6 is faster solution then count(*) and the compare in php $result = $db->select(array('page'), array('page_id'), array('page_namespace' => $ns), __METHOD__, array('LIMIT' => $count + 1)); $rowCount = $db->numRows($result); //string value is a work around for false value problem in memc if ($rowCount > $count) { return "YES"; } else { return "NO"; } }); wfProfileOut(__METHOD__); return $out == "YES"; }
/** * @desc Returns "CSS Updates" headline for selected language * * @return String | null */ protected function getCssUpdateHeadline() { $lang = $this->getCssUpdateLang(); $headline = WikiaDataAccess::cache(wfSharedMemcKey(self::MEMC_KEY, self::MEMC_KEY_HEADLINE_SUFFIX, $lang), 60 * 60 * 24, function () use($lang) { $headline = $this->wg->Lang->getMessageFor('special-css-community-update-headline', $lang); return $headline; }); return $headline; }
/** * * Returns list of categories on a wiki in batches by self::LIMIT * * @requestParam Integer limit * @requestParam String offset * * @response categories * @response offset */ private function getCategories() { wfProfileIn(__METHOD__); $limit = $this->request->getVal('limit', self::LIMIT * 2); $offset = $this->request->getVal('offset', ''); $categories = WikiaDataAccess::cache(wfMemcKey(__METHOD__, $offset, $limit, self::NEW_API_VERSION), 6 * self::HOURS, function () use($limit, $offset) { return ApiService::call(array('action' => 'query', 'list' => 'allcategories', 'redirects' => true, 'aclimit' => $limit, 'acfrom' => $offset, 'acprop' => 'id|size', 'acmin' => 1)); }); $allCategories = $categories['query']['allcategories']; if (!empty($allCategories)) { $ret = []; foreach ($allCategories as $value) { if ($value['size'] - $value['files'] > 0) { $ret[] = array('title' => $value['*'], 'id' => isset($value['pageid']) ? (int) $value['pageid'] : 0); } } $this->response->setVal('items', $ret); if (!empty($categories['query-continue'])) { $this->response->setVal('offset', $categories['query-continue']['allcategories']['acfrom']); } } else { wfProfileOut(__METHOD__); throw new NotFoundApiException('No Categories'); } wfProfileOut(__METHOD__); }
protected function getTopArticles($wikiId, $lang) { return \WikiaDataAccess::cache(wfSharedMemcKey("CombinedSearchService", $wikiId, $lang), self::TOP_ARTICLES_CACHE_TIME, function () use($wikiId, $lang) { $timer = Time::start(["CombinedSearchService", "getTopArticles"]); $requestedFields = ["title", "url", "id", "score", "pageid", "lang", "wid", "article_quality_i", Utilities::field('html', $lang)]; $topArticlesMap = \DataMartService::getTopArticlesByPageview($wikiId, null, [NS_MAIN], false, self::TOP_ARTICLES_PER_WIKI + 1); $query = " +(" . Utilities::valueForField("wid", $wikiId) . ") "; $query .= " +( " . implode(" OR ", array_map(function ($x) { return Utilities::valueForField("pageid", $x); }, array_keys($topArticlesMap))) . ") "; $query .= " +(is_main_page:false) "; $searchConfig = new Config(); $searchConfig->setLimit(self::TOP_ARTICLES_PER_WIKI)->setQuery($query)->setPage(1)->setRequestedFields($requestedFields)->setDirectLuceneQuery(true)->setWikiId($wikiId); $resultSet = (new Factory())->getFromConfig($searchConfig)->search(); $currentResults = $resultSet->toArray($requestedFields); $articles = []; foreach ($currentResults as $article) { $articles[$article['pageid']] = $this->processArticle($article); if (sizeof($articles) >= self::TOP_ARTICLES_PER_WIKI) { break; } } $result = []; foreach ($topArticlesMap as $id => $a) { if (isset($articles[$id])) { $result[] = $articles[$id]; } } $timer->stop(); return $result; }); }
/** * Get last timestamp when vertical was published (before selected timestamp) * * @param int $cityId * @param int $timestamp - max timestamp that we should search for published hub * * @return int timestamp */ public function getLastPublishedTimestamp($cityId, $timestamp = null, $useMaster = false) { if ($timestamp === null) { $timestamp = time(); } $timestamp = strtotime(self::STRTOTIME_MIDNIGHT, $timestamp); if ($timestamp == strtotime(self::STRTOTIME_MIDNIGHT)) { $lastPublishedTimestamp = WikiaDataAccess::cache($this->getMKeyForLastPublishedTimestamp($cityId, $timestamp), 6 * 60 * 60, function () use($cityId, $timestamp, $useMaster) { return $this->getLastPublishedTimestampFromDB($cityId, $timestamp, $useMaster); }); } else { $lastPublishedTimestamp = $this->getLastPublishedTimestampFromDB($cityId, $timestamp, $useMaster); } return $lastPublishedTimestamp; }
protected function getIdsBlacklistedWikis() { $blacklistIds = WikiaDataAccess::cache(wfSharedMemcKey('wam_blacklist', self::MEMCACHE_VER), self::CACHE_DURATION, function () { $contentWarningWikis = $excludedWikis = []; // Exlude wikias with ContentWarning extension enabled $blacklistExtVarId = WikiFactory::getVarIdByName(self::WAM_BLACKLIST_EXT_VAR_NAME); if ($blacklistExtVarId) { $contentWarningWikis = array_keys(WikiFactory::getListOfWikisWithVar($blacklistExtVarId, 'bool', '=', true)); } // Exclude wikias with an exclusion flag set to true $blacklistFlagVarId = WikiFactory::getVarIdByName(self::WAM_EXCLUDE_FLAG_NAME); if ($blacklistFlagVarId) { $excludedWikis = array_keys(WikiFactory::getListOfWikisWithVar($blacklistFlagVarId, 'bool', '=', true)); } return array_merge($contentWarningWikis, $excludedWikis); }); return $blacklistIds; }
public function getWikisIncludedInCorporateFooterDropdown() { $wikiFactoryList = []; $varId = WikiFactory::getVarIdByName(self::IS_WIKI_INCLUDED_IN_CORPORATE_FOOTER_DROPDOWN_VAR_NAME); if (is_int($varId)) { $wikiFactoryList = WikiaDataAccess::cache(wfMemcKey('wikis_included_in_corporate_footer_dropdown', self::WIKIA_HOME_PAGE_HELPER_MEMC_VERSION), 24 * 60 * 60, function () use($varId) { $list = WikiFactory::getListOfWikisWithVar($varId, 'bool', '=', true); return $this->cleanWikisDataArray($list); }, WikiaDataAccess::REFRESH_CACHE); } return $wikiFactoryList; }
/** * loadVariableFromDB * * Read variable data from database in most efficient way. If you've found * faster version - fix this one. * * @author eloy@wikia * @access private * @static * * @param integer $cv_id variable id in city_variables_pool * @param string $cv_name variable name in city_variables_pool * @param integer $city_id wiki id in city_list * @param boolean $master use master or slave connection * * @return string: path to file or null if id is not a number */ private static function loadVariableFromDB($cv_id, $cv_name, $city_id, $master = false) { if (!self::isUsed()) { Wikia::log(__METHOD__, "", "WikiFactory is not used."); return false; } /** * $wiki could be empty, but we have to know which variable read */ if (!$cv_id && !$cv_name) { return false; } wfProfileIn(__METHOD__); /** * if both are defined cv_id has precedence */ if ($cv_id) { $condition = ["cv_id" => $cv_id]; $cacheKey = "id:{$cv_id}"; } else { $condition = ["cv_name" => $cv_name]; $cacheKey = "name:{$cv_name}"; } $dbr = $master ? self::db(DB_MASTER) : self::db(DB_SLAVE); $caller = wfGetCallerClassMethod(__CLASS__); $fname = __METHOD__ . " (from {$caller})"; if ($master || !isset(self::$variablesCache[$cacheKey])) { $oRow = WikiaDataAccess::cache(self::getVarMetadataKey($cacheKey), WikiaResponse::CACHE_STANDARD, function () use($dbr, $condition, $fname) { $oRow = $dbr->selectRow(["city_variables_pool"], ["cv_id", "cv_name", "cv_description", "cv_variable_type", "cv_variable_group", "cv_access_level", "cv_is_unique"], $condition, $fname); // log typos in calls to WikiFactory::loadVariableFromDB if (!is_object($oRow)) { WikiaLogger::instance()->error('WikiFactory - variable not found', ['condition' => $condition, 'exception' => new Exception()]); } return $oRow; }, $master ? WikiaDataAccess::REFRESH_CACHE : WikiaDataAccess::USE_CACHE); self::$variablesCache[$cacheKey] = $oRow; } $oRow = self::$variablesCache[$cacheKey]; if (is_object($oRow)) { $oRow = clone $oRow; } if (!isset($oRow->cv_id)) { /** * variable doesn't exist */ wfProfileOut(__METHOD__); return null; } if (!empty($city_id)) { $oRow2 = WikiaDataAccess::cache(self::getVarValueKey($city_id, $oRow->cv_id), 3600, function () use($dbr, $oRow, $city_id, $fname) { return $dbr->selectRow(["city_variables"], ["cv_city_id", "cv_variable_id", "cv_value"], ["cv_variable_id" => $oRow->cv_id, "cv_city_id" => $city_id], $fname); }); if (isset($oRow2->cv_variable_id)) { $oRow->cv_city_id = $oRow2->cv_city_id; $oRow->cv_variable_id = $oRow2->cv_variable_id; $oRow->cv_value = $oRow2->cv_value; } else { $oRow->cv_city_id = $city_id; $oRow->cv_variable_id = $oRow->cv_id; $oRow->cv_value = null; } } else { $oRow->cv_city_id = null; $oRow->cv_variable_id = $oRow->cv_id; $oRow->cv_value = null; } wfProfileOut(__METHOD__); return $oRow; }
/** * Get restricted wiki ids * * @return array Array with restricted wiki ids */ public static function getRestrictedWikisIds() { return WikiaDataAccess::cache(self::getRestrictedWikisKey(), self::GLOBAL_RESTRICTED_WIKIS_CACHE_TIME, function () { return self::getRestrictedWikisFromDB(); }); }
private function getTextSnippetSource($articleId) { // Memoize to avoid Memcache access overhead when the same article needs to be processed // more than once in the same process if (array_key_exists($articleId, self::$localCache)) { $text = self::$localCache[$articleId]; } else { $key = self::getCacheKey($articleId); $service = $this; $text = self::$localCache[$articleId] = WikiaDataAccess::cache($key, 86400, function () use($service) { $content = ''; if (!$this->wg->DevelEnvironment && !empty($this->wg->SolrMaster)) { $content = $service->getTextFromSolr(); } if ($content === '') { // back-off is to use mediawiki $content = $service->getUncachedSnippetFromArticle(); } return $content; }); } return $text; }
/** * get list of top editors * * @param integer $wikiId * @param integer $limit * @param bool $excludeBots * * @return array topEditors [ array( user_id => edits ) ] */ public function getTopEditors($wikiId = 0, $limit = 30, $excludeBots = false) { wfProfileIn(__METHOD__); $wikiId = empty($wikiId) ? $this->wg->CityId : $wikiId; $fname = __METHOD__; $topEditors = WikiaDataAccess::cache(wfSharedMemcKey('wiki_top_editors', $wikiId, $excludeBots), static::TOPUSER_CACHE_VALID, function () use($wikiId, $excludeBots, $fname) { global $wgSpecialsDB; $topEditors = array(); $db = wfGetDB(DB_SLAVE, array(), $wgSpecialsDB); $result = $db->select(array('events_local_users'), array('user_id', 'edits', 'all_groups'), array('wiki_id' => $wikiId, 'edits != 0'), $fname, array('ORDER BY' => 'edits desc', 'LIMIT' => static::TOPUSER_LIMIT)); while ($row = $db->fetchObject($result)) { if (!($excludeBots && $this->isBotGroup($row->all_groups))) { $topEditors[$row->user_id] = intval($row->edits); } } return $topEditors; }); wfProfileOut(__METHOD__); return array_slice($topEditors, 0, $limit, true); }
/** * @return string * @throws GWTAuthenticationException */ private function getAuthToken() { $cacheKey = $this->mEmail; return WikiaDataAccess::cache($cacheKey, 60 * 60, function () { $content = Http::post('https://www.google.com/accounts/ClientLogin', array('postData' => array("Email" => $this->mEmail, "Passwd" => $this->mPass, "accountType" => $this->mType, "source" => $this->mSource, "service" => $this->mService))); if (preg_match('/Auth=(\\S+)/', $content, $matches)) { return $matches[1]; } else { throw new GWTAuthenticationException(); } }); }
/** * @param Array $collectionsList 2d array in example: [$collection1, $collection2, ...] where $collection1 = [$wikiId1, $wikiId2, ..., $wikiId17] * @param String $lang language code */ public function getCollectionsWikisData(array $collectionsList) { $collectionsWikisData = []; $helper = $this->getWikiaHomePageHelper(); foreach ($collectionsList as $collection => $collectionsWikis) { $collectionsWikisData[$collection] = WikiaDataAccess::cache($this->getCollectionCacheKey($collection), 6 * 60 * 60, function () use($collection, $collectionsWikis) { $wikiListConditioner = new WikiListConditionerForCollection($collectionsWikis); return $this->getWikisList($wikiListConditioner); }); } $collectionsWikisData = $helper->prepareBatchesForVisualization($collectionsWikisData); return $collectionsWikisData; }