/**
  * 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);
 }
 /**
  * get wiki stats ( pages, images, videos, users )
  * @param integer $wikiId
  * @return array wikiStats
  */
 public function getWikiStats($wikiId)
 {
     $wikiStats = 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
             $sitestats = $wikiService->getSiteStats($wikiId);
             $videos = $wikiService->getTotalVideos($wikiId);
         } catch (Exception $e) {
             $sitestats = array('articles' => 0, 'pages' => 0, 'images' => 0, 'users' => 0);
             $videos = 0;
         }
         $wikiStats = array('articles' => intval($sitestats['articles']), 'pages' => intval($sitestats['pages']), 'images' => intval($sitestats['images']), 'videos' => $videos, 'users' => intval($sitestats['users']));
     }
     return $wikiStats;
 }
 /**
  * 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__);
 }
Example #4
0
 /**
  * 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;
 }