/** * Called from maintenance script only. Send Digest emails for any founders with that preference enabled * * @param array $events Events is empty for this type */ public function process(array $events) { global $wgTitle; wfProfileIn(__METHOD__); $founderEmailObj = FounderEmails::getInstance(); $wgTitle = Title::newMainPage(); // Get list of founders with digest mode turned on $cityList = $founderEmailObj->getFoundersWithPreference('founderemails-views-digest'); $wikiService = new WikiService(); // Gather daily page view stats for each wiki requesting views digest foreach ($cityList as $cityID) { $user_ids = $wikiService->getWikiAdminIds($cityID); $foundingWiki = WikiFactory::getWikiById($cityID); $page_url = GlobalTitle::newFromText('Createpage', NS_SPECIAL, $cityID)->getFullUrl(array('modal' => 'AddPage')); $emailParams = array('$WIKINAME' => $foundingWiki->city_title, '$WIKIURL' => $foundingWiki->city_url, '$PAGEURL' => $page_url, '$UNIQUEVIEWS' => $founderEmailObj->getPageViews($cityID)); foreach ($user_ids as $user_id) { $user = User::newFromId($user_id); // skip if not enable if (!$this->enabled($user, $cityID)) { continue; } self::addParamsUser($cityID, $user->getName(), $emailParams); $langCode = $user->getGlobalPreference('language'); $links = array('$WIKINAME' => $emailParams['$WIKIURL']); $mailSubject = strtr(wfMsgExt('founderemails-email-views-digest-subject', array('content')), $emailParams); $mailBody = strtr(wfMsgExt('founderemails-email-views-digest-body', array('content', 'parsemag'), $emailParams['$UNIQUEVIEWS']), $emailParams); $mailBodyHTML = F::app()->renderView('FounderEmails', 'GeneralUpdate', array_merge($emailParams, array('language' => 'en', 'type' => 'views-digest'))); $mailBodyHTML = strtr($mailBodyHTML, FounderEmails::addLink($emailParams, $links)); $mailCategory = FounderEmailsEvent::CATEGORY_VIEWS_DIGEST . (!empty($langCode) && $langCode == 'en' ? 'EN' : 'INT'); $founderEmailObj->notifyFounder($user, $this, $mailSubject, $mailBody, $mailBodyHTML, $cityID, $mailCategory); } } wfProfileOut(__METHOD__); }
/** * 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); }
/** * @covers WikiService::getMostLinkedPages */ public function testGetMostLinkedPages() { /* mocking MemCache */ $mockCache = $this->getMock('MemCachedClientforWiki', array('get', 'set'), array(array())); $mockCache->expects($this->any())->method('get')->will($this->returnValue(false)); $mockCache->expects($this->any())->method('set')->will($this->returnValue(false)); $this->mockGlobalVariable('wgMemc', $mockCache); /* Mocking DB response */ $row1 = new stdClass(); $row1->page_id = 100; $row1->page_title = "Abc Page 1"; $row1->backlink_cnt = 10; $row2 = new stdClass(); $row2->page_id = 200; $row2->page_title = "Abc Page 2"; $row2->backlink_cnt = 6; $mockDb = $this->getMock('DatabaseMysql', array('select', 'fetchObject')); $mockDb->expects($this->any())->method('select')->will($this->returnValue(false)); $mockDb->expects($this->at(1))->method('fetchObject')->will($this->returnValue($row1)); $mockDb->expects($this->at(2))->method('fetchObject')->will($this->returnValue($row2)); $mockDb->expects($this->at(3))->method('fetchObject')->will($this->returnValue(null)); $this->mockGlobalFunction('wfGetDb', $mockDb); $wikiService = new WikiService(); $result = $wikiService->getMostLinkedPages(); $keys = array_keys($result); $this->assertEquals(count($keys), 2); foreach ($keys as $key) { $this->assertEquals($key, $result[$key]['page_id']); } }
protected static function invalidateCacheWikiTotalImages($file, $reupload) { $title = $file->getTitle(); if ($title instanceof Title && !WikiaFileHelper::isVideoFile($file) && !$reupload) { $wikiService = new WikiService(); $wikiService->invalidateCacheTotalImages(); } }
public function enabled_wiki($wgCityId) { $wikiService = new WikiService(); $user_ids = $wikiService->getWikiAdminIds($wgCityId); foreach ($user_ids as $user_id) { $user = User::newFromId($user_id); if ($this->enabled($user, $wgCityId)) { return true; } } return false; }
/** * Get statistical information about the current wiki [DEPRECATED] * * @responseParam Integer $edits Number of edits on a wiki * @responseParam Integer $articles Number of real articles on a wiki * @responseParam Integer $pages Number of all pages on a wiki (eg. File pages, Articles, Category pages ...) * @responseParam Integer $users Stats Number of all users in a wiki * @responseParam Integer $activeUsers Number of active users on a wiki * @responseParam Integer $images Number of all images on a wiki * @responseParam Integer $videos Number of all videos on a wiki * @responseParam Integer $admins Number of all admins on a wiki * * @example */ function getData() { $this->response->setCacheValidity(self::CACHE_VALIDITY); $wikiService = new WikiService(); $siteStats = $wikiService->getSiteStats(); $siteStats['videos'] = $wikiService->getTotalVideos(); //views are empty anyway... unset($siteStats['views']); //lets return always integers for consistency foreach ($siteStats as &$stat) { $stat = (int) $stat; } $siteStats['admins'] = count($wikiService->getWikiAdminIds()); $this->response->setValues($siteStats); }
/** * @param array $events * * @return bool */ public function process(array $events) { // Make sure we have some events if (count($events) == 0) { return false; } // get just one event when we have more... for now, just randomly $event = $events[rand(0, count($events) - 1)]; $eventData = $event['data']; if ($this->isEditorThrottled($eventData)) { return true; } $wikiService = new WikiService(); $adminUserIds = $wikiService->getWikiAdminIds(); foreach ($adminUserIds as $adminId) { $this->processForUser($adminId, $eventData); } return true; }
/** * Called from maintenance script only. Send Digest emails for any founders with that preference enabled * @param array $events */ public function process(array $events) { global $wgTitle; wfProfileIn(__METHOD__); $wgTitle = Title::newMainPage(); $founderEmailObj = FounderEmails::getInstance(); // Get list of founders with digest mode turned on (defined in FounderEmailsEvent $cityList = $founderEmailObj->getFoundersWithPreference('founderemails-complete-digest'); $wikiService = new WikiService(); foreach ($cityList as $cityID) { $user_ids = $wikiService->getWikiAdminIds($cityID); $foundingWiki = WikiFactory::getWikiById($cityID); $page_url = GlobalTitle::newFromText('WikiActivity', NS_SPECIAL, $cityID)->getFullUrl(); $emailParams = array('$WIKINAME' => $foundingWiki->city_title, '$WIKIURL' => $foundingWiki->city_url, '$PAGEURL' => $page_url, '$UNIQUEVIEWS' => $founderEmailObj->getPageViews($cityID), '$USERJOINS' => $founderEmailObj->getNewUsers($cityID), '$USEREDITS' => $founderEmailObj->getDailyEdits($cityID)); foreach ($user_ids as $user_id) { $user = User::newFromId($user_id); // skip if not enable if (!$this->enabled($user, $cityID)) { continue; } self::addParamsUser($cityID, $user->getName(), $emailParams); // Only send email if there is some kind of activity to report if ($emailParams['$UNIQUEVIEWS'] == 0 && $emailParams['$USERJOINS'] == 0 && $emailParams['$USEREDITS'] == 0) { continue; } $langCode = $user->getGlobalPreference('language'); $links = array('$WIKINAME' => $emailParams['$WIKIURL']); $mailSubject = strtr(wfMsgExt('founderemails-email-complete-digest-subject', array('language' => $langCode)), $emailParams); $mailBody = strtr(wfMsgExt('founderemails-email-complete-digest-body', array('language' => $langCode, 'parsemag'), $emailParams['$UNIQUEVIEWS'], $emailParams['$USEREDITS'], $emailParams['$USERJOINS']), $emailParams); $mailBodyHTML = F::app()->renderView("FounderEmails", "GeneralUpdate", array_merge($emailParams, array('language' => $langCode, 'type' => 'complete-digest'))); $mailBodyHTML = strtr($mailBodyHTML, FounderEmails::addLink($emailParams, $links)); $mailCategory = FounderEmailsEvent::CATEGORY_COMPLETE_DIGEST . (!empty($langCode) && $langCode == 'en' ? 'EN' : 'INT'); // Send the e-mail $founderEmailObj->notifyFounder($user, $this, $mailSubject, $mailBody, $mailBodyHTML, $cityID, $mailCategory); } } wfProfileOut(__METHOD__); }
public function getMostLinked() { $expand = $this->request->getBool(static::PARAMETER_EXPAND, false); $nameSpace = NS_MAIN; $wikiService = new WikiService(); $mostLinked = $wikiService->getMostLinkedPages(); $mostLinkedOutput = []; if ($expand) { $params = $this->getDetailsParams(); $mostLinkedOutput = $this->getArticlesDetails(array_keys($mostLinked), $params['titleKeys'], $params['width'], $params['height'], $params['length'], true); } else { foreach ($mostLinked as $item) { $title = Title::newFromText($item['page_title'], $nameSpace); if (!empty($title) && $title instanceof Title && !$title->isMainPage()) { $mostLinkedOutput[] = ['id' => $item['page_id'], 'title' => $item['page_title'], 'url' => $title->getLocalURL(), 'ns' => $nameSpace]; } } } $this->setResponseData(['basepath' => $this->wg->Server, 'items' => $mostLinkedOutput], ['imgFields' => 'thumbnail', 'urlFields' => ['thumbnail', 'url']], self::getMetadataCacheTime()); }
/** * Hook - clear cache for list of admin_ids * @param object $user * @param array $addgroup * @param array $removegroup * @return true */ public static function onUserRightsChange($user, $addgroup, $removegroup) { global $wgCityId, $wgMemc; wfProfileIn(__METHOD__); if (!empty($wgCityId)) { if ($addgroup && (in_array('sysop', $addgroup) || in_array('bureaucrat', $addgroup)) || $removegroup && (in_array('sysop', $removegroup) || in_array('bureaucrat', $removegroup))) { $wikiService = new WikiService(); /* @var $wikiService WikiService */ $memKey = $wikiService->getMemKeyAdminIds($wgCityId); $wgMemc->delete($memKey); $memKey = $wikiService->getMemKeyAdminIds($wgCityId, true); $wgMemc->delete($memKey); $wikiService->getWikiAdminIds($wgCityId, true); } } wfProfileOut(__METHOD__); return true; }
/** * Gets the information about wikis [DEPRECATED] * * @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 getWikiData() { wfProfileIn(__METHOD__); $ids = $this->request->getArray('ids'); $imageWidth = $this->request->getInt('width', static::DEFAULT_WIDTH); $imageHeight = $this->request->getInt('height', static::DEFAULT_HEIGHT); $length = $this->request->getVal('snippet', static::DEFAULT_SNIPPET_LENGTH); $items = array(); $service = new WikiService(); foreach ($ids as $wikiId) { if (($cached = $this->getFromCacheWiki($wikiId, __METHOD__)) !== false) { //get from cache $wikiInfo = $cached; } else { //get data providers $wikiObj = WikiFactory::getWikiByID($wikiId); $wikiStats = $service->getSiteStats($wikiId); $topUsers = $service->getTopEditors($wikiId, static::DEFAULT_TOP_EDITORS_NUMBER, true); $wikiInfo = array('id' => (int) $wikiId, 'articles' => (int) $wikiStats['articles'], 'images' => (int) $wikiStats['images'], 'videos' => (int) $service->getTotalVideos($wikiId), 'topUsers' => array_keys($topUsers), 'title' => $wikiObj->city_title, 'url' => $wikiObj->city_url); //cache data $this->cacheWikiData($wikiInfo, __METHOD__); } $wikiDesc = $service->getWikiDescription([$wikiId], $imageWidth, $imageHeight); //set snippet $wikiInfo['description'] = $this->getSnippet(isset($wikiDesc[$wikiId]) ? $wikiDesc[$wikiId]['desc'] : '', $length); //add image, its cached on different level $wikiInfo['thumbnail'] = isset($wikiDesc[$wikiId]) ? $wikiDesc[$wikiId]['image_url'] : ''; //add to result $items[] = $wikiInfo; } $this->response->setVal('items', $items); wfProfileOut(__METHOD__); }
/** * get list of top editor info ( name, avatarUrl, userPageUrl, edits ) * @param integer $wikiId * @return array $topEditorAvatars */ public function getWikiTopEditorAvatars($wikiId) { $topEditorAvatars = array(); if (!empty($wikiId)) { $wikiService = new WikiService(); try { //this try-catch block is here because of devbox environments //where we don't have all wikis imported $topEditors = $wikiService->getTopEditors($wikiId, 100, true); } catch (Exception $e) { $topEditors = array(); } foreach ($topEditors as $userId => $edits) { $userInfo = $wikiService->getUserInfo($userId, $wikiId, self::AVATAR_SIZE, array($this, 'isValidUserForInterstitial')); if (!empty($userInfo)) { $userInfo['edits'] = $edits; if (!empty($topEditorAvatars[$userInfo['name']])) { $userInfo['edits'] += $topEditorAvatars[$userInfo['name']]['edits']; } $topEditorAvatars[$userInfo['name']] = $userInfo; if (count($topEditorAvatars) >= self::LIMIT_TOP_EDITOR_AVATARS) { break; } } } } return $topEditorAvatars; }
public function process(array $events) { global $wgExternalSharedDB, $wgEnableAnswers, $wgTitle, $wgContLang; wfProfileIn(__METHOD__); $wgTitle = Title::newMainPage(); $founderEmailObj = FounderEmails::getInstance(); $wikiService = new WikiService(); foreach ($events as $event) { $wikiId = $event['wikiId']; if ($wikiId == 0) { continue; } // should "never" happen BugId:12717 $activateTime = $event['data']['activateTime']; $activateDays = $event['data']['activateDays']; $user_ids = $wikiService->getWikiAdminIds($wikiId); if (time() >= $activateTime) { $emailParams = array('$WIKINAME' => $event['data']['wikiName'], '$WIKIURL' => $event['data']['wikiUrl'], '$WIKIMAINPAGEURL' => $event['data']['wikiMainpageUrl'], '$ADDAPAGEURL' => $event['data']['addapageUrl'], '$ADDAPHOTOURL' => $event['data']['addaphotoUrl'], '$CUSTOMIZETHEMEURL' => $event['data']['customizethemeUrl'], '$EDITMAINPAGEURL' => $event['data']['editmainpageUrl'], '$EXPLOREURL' => $event['data']['exploreUrl']); $wikiType = !empty($wgEnableAnswers) ? '-answers' : ''; foreach ($user_ids as $user_id) { $user = User::newFromId($user_id); // skip if not enable if (!$this->enabled($user, $wikiId)) { continue; } self::addParamsUser($wikiId, $user->getName(), $emailParams); $emailParams['$USERPAGEEDITURL'] = $user->getUserPage()->getFullUrl(array('action' => 'edit')); $langCode = $user->getGlobalPreference('language'); // force loading messages for given languege, to make maintenance script works properly $wgContLang = Language::factory($langCode); $mailSubject = strtr(wfMsgExt('founderemails' . $wikiType . '-email-' . $activateDays . '-days-passed-subject', array('content')), $emailParams); $mailBody = strtr(wfMsgForContent('founderemails' . $wikiType . '-email-' . $activateDays . '-days-passed-body'), $emailParams); $mailCategory = FounderEmailsEvent::CATEGORY_DEFAULT; if ($activateDays == 3) { $mailCategory = FounderEmailsEvent::CATEGORY_3_DAY; } else { if ($activateDays == 10) { $mailCategory = FounderEmailsEvent::CATEGORY_10_DAY; } else { if ($activateDays == 0) { $mailCategory = FounderEmailsEvent::CATEGORY_0_DAY; } } } $mailCategory .= !empty($langCode) && $langCode == 'en' ? 'EN' : 'INT'; if (empty($wgEnableAnswers)) { $links = array('$WIKINAME' => $emailParams['$WIKIURL']); $emailParams_new = FounderEmails::addLink($emailParams, $links); $emailParams_new['$HDWIKINAME'] = str_replace('#2C85D5', '#fa5c1f', $emailParams_new['$WIKINAME']); // header color = #fa5c1f $mailBodyHTML = F::app()->renderView('FounderEmails', $event['data']['dayName'], array('language' => 'en')); $mailBodyHTML = strtr($mailBodyHTML, $emailParams_new); } else { $mailBodyHTML = $this->getLocalizedMsg('founderemails' . $wikiType . '-email-' . $activateDays . '-days-passed-body-HTML', $emailParams); } $founderEmailObj->notifyFounder($user, $this, $mailSubject, $mailBody, $mailBodyHTML, $wikiId, $mailCategory); } $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB); $dbw->delete('founder_emails_event', array('feev_id' => $event['id'])); } } // always return false to prevent deleting from FounderEmails::processEvent wfProfileOut(__METHOD__); return false; }
/** * Uses WikiService to access stats info. * We add '_count' to each key clarify these are count values * @param int $wikiId * @return array */ public function getStatsInfoForWikiId($wikiId) { $service = new \WikiService(); $statsInfo = $service->getSiteStats($wikiId); $statsInfo['videos'] = $service->getTotalVideos($wikiId); foreach ($statsInfo as $key => $val) { $statsInfo[$key . '_count'] = $val; unset($statsInfo[$key]); } return $statsInfo; }
<?php /* * Copyright STMicroelectronics, 2005 * * Originally written by Manuel Vacelet, STMicroelectronics, 2005. * * This file is a part of Codendi. * * Codendi is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Codendi is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Codendi; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ require_once 'pre.php'; PHPWikiPluginRedirector::redirect(); require_once 'common/wiki/WikiService.class.php'; $wiki = new WikiService($request->get('group_id')); $wiki->process();