public function execute()
 {
     $prefix = $this->getOption('prefix');
     $namespace = intval($this->getOption('namespace', 0));
     $isDryRun = $this->hasOption('dry-run');
     $this->output("Looking for pages matching '{$prefix}' prefix in namespace #{$namespace}... ");
     $res = ApiService::call(array('action' => 'query', 'list' => 'allpages', 'apnamespace' => $namespace, 'apprefix' => $prefix, 'aplimit' => 5000));
     $pages = !empty($res['query']['allpages']) ? $res['query']['allpages'] : array();
     $this->output(count($pages) . " article(s) found\n\n");
     if (count($pages) === 0) {
         $this->output("No articles found!\n");
         die;
     }
     foreach ($pages as $page) {
         if ($isDryRun) {
             $this->output("* {$page['title']} not deleted (dry run)\n");
             continue;
         }
         $this->output("* Deleting {$page['title']}...");
         $article = Article::newFromID($page['pageid']);
         if ($article instanceof Article) {
             $res = $article->doDeleteArticle(self::REASON);
             if ($res === true) {
                 $this->output(" done\n");
             } else {
                 $this->output(" error!\n");
             }
         } else {
             $this->output(" article not found by its ID!\n");
         }
     }
     $this->output("\nDone!\n");
 }
 private function getMostPopularArticlesFromCat($Category)
 {
     $this->app->wf->profileIn(__METHOD__);
     //Getting list of articles belonging to specified category using API
     $result = ApiService::call(array('action' => 'query', 'list' => 'categorymembers', 'cmtitle' => 'Category:' . $Category, 'cmnamespace' => '0', 'cmlimit' => '5000'));
     //Preparing arrays to be used as parameters for next method
     $result = $result['query']['categorymembers'];
     $ids = array();
     foreach ($result as $item) {
         $ids[] = $item['pageid'];
     }
     $allArticlesCount = count($ids);
     $dbr = $this->getDB();
     $resultSecondQuery = array();
     $newquery = $dbr->select(array('revision', 'page'), array('page_id', 'page_title AS title', 'COUNT(*) AS value'), array('page_id = rev_page', 'page_id' => $ids), __METHOD__, array('GROUP BY' => 'page_title', 'ORDER BY' => 'value desc', 'LIMIT' => '120'));
     while ($row = $dbr->fetchObject($newquery)) {
         $resultSecondQuery[] = $row;
     }
     $res = array();
     $map = array();
     foreach ($resultSecondQuery as $i => $item) {
         $articleTitle = str_replace('_', ' ', $item->title);
         $res[] = array('title' => $articleTitle, 'id' => $item->page_id, 'connections' => array());
         $map[$articleTitle] = $i;
     }
     $new = array('nodes' => $this->query($res, $map), 'all' => $allArticlesCount);
     $this->app->wf->profileOut(__METHOD__);
     return $new;
 }
 /**
  * Fetches the top N pages on the wiki with thumbnails
  * used in the 404 pages implementation
  *
  * @author Jakub Olek <*****@*****.**>
  *
  * @return Array[] The array of results
  */
 public function getPopularPages()
 {
     wfProfileIn(__METHOD__);
     $memKey = $this->getPopularPagesCacheKey();
     $pages = $this->wg->Memc->get($memKey);
     if (!is_array($pages) || !count($pages)) {
         $res = ApiService::call(array('action' => 'query', 'list' => 'wkpoppages', 'wklimit' => self::POPULAR_PAGES_NUMBER_LIMIT));
         if (is_array($res)) {
             $res = $res['query']['wkpoppages'];
             $ids = array();
             foreach ($res as $r) {
                 array_push($ids, $r['id']);
             }
             //ImageServing does not return results if id is wrong
             $is = $this->app->sendRequest('ImageServingController', 'getImages', array('ids' => $ids, 'width' => 100, 'height' => 100, 'count' => 5));
             $pages = $is->getVal('result');
             if (is_array($pages)) {
                 foreach ($pages as $key => $r) {
                     array_unshift($pages[$key], $res[$key]['title']);
                 }
                 $this->wg->Memc->set($memKey, $pages, self::POPULAR_PAGES_CACHE_TIME);
             }
         }
     }
     wfProfileOut(__METHOD__);
     return $pages;
 }
 public function getLatestThumbsUrls()
 {
     global $wgMemc;
     $thumbUrls = $wgMemc->get(LatestPhotosController::memcacheKey());
     if (empty($thumbUrls)) {
         // api service
         $helper = new LatestPhotosHelper();
         $params = ['action' => 'query', 'list' => 'logevents', 'letype' => 'upload', 'leprop' => 'title', 'lelimit' => 50];
         $apiData = ApiService::call($params);
         if (empty($apiData)) {
             $this->response->setVal('thumbUrls', false);
         }
         $imageList = $apiData['query']['logevents'];
         $fileList = array_map([$helper, "getImageData"], $imageList);
         $fileList = array_filter($fileList, [$helper, "filterImages"]);
         // make sure the list of images is unique and limited to 11 images (12 including the see all image)
         $shaList = [];
         $uniqueList = [];
         foreach ($fileList as $data) {
             $sha = $data['file']->sha1;
             if (!array_key_exists($sha, $shaList) && $data['file']->media_type != 'VIDEO') {
                 $shaList[$sha] = true;
                 $uniqueList[] = $data;
             }
             if (count($uniqueList) > 10) {
                 break;
             }
         }
         $thumbUrls = array_map(array($helper, 'getTemplateData'), $uniqueList);
         $wgMemc->set(self::memcacheKey(), $thumbUrls);
     }
     $this->response->setVal('thumbUrls', $thumbUrls);
 }
 /**
  * Get the embed code for the given title from the video wiki, rather than the local wiki.  This is
  * useful when a video of the same name from youtube (or other non-premium provider) exists on the local wiki
  * and we want to show the equivalent video from the video wiki.  See also getEmbedCode in this controller.
  *
  * @requestParam string fileTitle The title of the video to find the embed code for
  * @requestParam int width The desired width of video playback to return with the embed code
  * @requestParam boolean autoplay Whether the video should play immediately on page load
  * @responseParam string videoId A unique identifier for the video title given
  * @responseParam string asset A URL for the video
  * @responseParam string embedCode The HTML to embed on the page to play the video given by fileTitle
  */
 public function getPremiumEmbedCode()
 {
     // Pass through all the same parameters
     $params = array('controller' => __CLASS__, 'method' => 'getEmbedCode', 'fileTitle' => $this->getVal('fileTitle', ''), 'width' => $this->getVal('width', ''), 'autoplay' => $this->getVal('autoplay', false));
     // Call out to the getEmbedCode method in the context of the Video Wiki (WikiaVideoRepoDBName)
     $response = ApiService::foreignCall(F::app()->wg->WikiaVideoRepoDBName, $params, ApiService::WIKIA, true);
     // Map the foreign call response back to our response
     foreach ($response as $key => $val) {
         $this->setVal($key, $val);
     }
 }
 public static function getImageOriginalUrl($wikiId, $pageId)
 {
     $app = F::app();
     $app->wf->ProfileIn(__METHOD__);
     $dbname = WikiFactory::IDtoDB($wikiId);
     $title = GlobalTitle::newFromId($pageId, $wikiId);
     $param = array('action' => 'query', 'prop' => 'imageinfo', 'iiprop' => 'url', 'titles' => $title->getPrefixedText());
     $response = ApiService::foreignCall($dbname, $param);
     $app->wf->ProfileOut(__METHOD__);
     return array('src' => $imageSrc, 'page' => $imagePage);
 }
 /**
  * updatePages
  * updates infoboxes on all census enabled pages
  */
 public function updatePages()
 {
     wfProfileIn(__METHOD__);
     //get all pages from category
     $aReturn = ApiService::call(array('action' => 'query', 'list' => 'categorymembers', 'cmtitle' => CensusDataRetrieval::getFlagCategoryTitle()->getPrefixedDBkey(), 'cmnamespace' => '0'));
     //perform update foreach page from category
     foreach ($aReturn['query']['categorymembers'] as $cm) {
         $oTitle = Title::newFromText($cm['title']);
         $oArticle = new Article($oTitle);
         $newText = $this->getUpdatedContent($oArticle->getContent(), $oTitle);
         //save updated content
         $oArticle->doEdit($newText, 'Updating infobox with data from Sony DB', EDIT_UPDATE);
     }
     wfProfileOut(__METHOD__);
 }
 public static function getImageOriginalUrl($wikiId, $pageId)
 {
     wfProfileIn(__METHOD__);
     $dbname = WikiFactory::IDtoDB($wikiId);
     $title = GlobalTitle::newFromId($pageId, $wikiId);
     $param = array('action' => 'query', 'prop' => 'imageinfo', 'iiprop' => 'url', 'titles' => $title->getPrefixedText());
     $imagePage = $title->getFullUrl();
     $response = ApiService::foreignCall($dbname, $param, ApiService::API, true);
     if (!empty($response['query']['pages'])) {
         $imagePageData = array_shift($response['query']['pages']);
         $imageInfo = array_shift($imagePageData['imageinfo']);
         $imageSrc = empty($imageInfo['url']) ? '' : $imageInfo['url'];
     } else {
         $imageSrc = '';
     }
     wfProfileOut(__METHOD__);
     return array('src' => $imageSrc, 'page' => $imagePage);
 }
 public function execute()
 {
     global $wgUser, $wgTitle;
     $wgUser = User::newFromName('Wikia');
     $wgUser->load();
     //get list of pages from how-to category
     $aReturn = ApiService::call(array('action' => 'query', 'list' => 'categorymembers', 'cmtitle' => 'Category:How-to', 'cmnamespace' => '120'));
     //perform update foreach page from category
     foreach ($aReturn['query']['categorymembers'] as $cm) {
         $oWebinarTitle = Title::newFromText($cm['title']);
         $wgTitle = $oWebinarTitle;
         $oWebinarArticle = new Article($oWebinarTitle);
         echo "Webinar page: " . $oWebinarTitle->getText() . "\n";
         //get video link
         $content = $oWebinarArticle->getContent();
         //preq match
         $matches = $this->matchFile($content);
         if (!empty($matches)) {
             //remove params
             $aFileTitWithParams = explode('|', $matches[1]);
             //get file title
             $oFilePageTitle = Title::newFromText($aFileTitWithParams[0], NS_FILE);
             echo "video file title: " . $oFilePageTitle->getText() . "\n";
             if (WikiaFileHelper::isFileTypeVideo($oFilePageTitle)) {
                 //to test
                 echo "=----------- IS VIDEO \n";
                 //prepare new content without link to video file
                 $newFileContent = str_replace($matches[0], '', $content);
                 //article obj
                 $oFileArticle = new Article($oFilePageTitle);
                 //set new contnet without file link at the begining
                 $oFileArticle->doEdit($newFileContent, 'Moving How-to webinars to video file pages');
                 //set redirect
                 $oWebinarArticle->doEdit("#redirect[[" . $oFilePageTitle->getPrefixedDBkey() . "]]", 'Setting redirect - conent was moveed to video file page');
             }
         }
     }
 }
Example #10
0
 public static function setup()
 {
     /* Setting up the app-configurations globally for use across classes */
     global $configs;
     $configs = json_decode(file_get_contents('collap-configs.json'), true);
     /* Setting up the logger globally for use across classes */
     global $logger;
     $logger = new ShopbookLogger();
     $logger->enabled = true;
     $logger->debug("Setting up ...");
     /* Setting up the cache object globally for use across classes */
     global $cache;
     $cache = AppCacheRegistry::getCacheObject('redis');
     /* Setting up the warnings payload as a global variable to be able 
     			to dump warnings along the API flow */
     global $warnings_payload;
     /* Logging API stats */
     $memoryUsage = memory_get_usage(true) / (1024 * 1024);
     $cpuLoad = Util::ServerLoad();
     self::$pageTimer = new Timer('page_timer');
     self::$pageTimer->start();
     $logger->debug("Init Memory: {$memoryUsage} MB; Init CPU: {$cpuLoad}%");
 }
 /**
  * Prints results to the OutputPage provided, if there was a query for an intersection of categories. Otherwise
  * prints some placeholder text.
  *
  * @param out - OutputPage to add HTML to.
  */
 private function showResults($out)
 {
     wfProfileIn(__METHOD__);
     global $wgRequest, $wgServer, $wgScriptPath;
     $html = "";
     $html .= "<div class='ci_results'>\n";
     $html .= "<h2>" . wfMsg('categoryintersection-results-title') . "</h2>\n";
     $submit = $wgRequest->getVal('wpSubmit');
     if (!empty($submit)) {
         $limit = $wgRequest->getVal('limit', $this->defaultLimit);
         $categories = array();
         $keys = array_keys($_GET);
         foreach ($keys as $key) {
             if (startsWith($key, self::$CAT_PREFIX)) {
                 $cat = $wgRequest->getVal($key);
                 if (!empty($cat)) {
                     $categories[] = $cat;
                     if (!startsWith($cat, $this->CATEGORY_NS_PREFIX)) {
                         $html .= "<em>Warning: \"{$cat}\" does not start with \"{$this->CATEGORY_NS_PREFIX}\".</em><br/>\n";
                     }
                 }
             }
         }
         // Use the API to get actual results.
         $apiParams = array('action' => 'query', 'list' => 'categoryintersection', 'limit' => $limit, 'categories' => implode("|", $categories));
         $apiData = ApiService::call($apiParams);
         if (empty($apiData)) {
             $RESULTS_FOUND = 0;
             $html .= "<em>" . wfMsg('categoryintersection-summary', implode($categories, ", "), $limit, $RESULTS_FOUND) . "</em>\n";
             $html .= "<em>" . wfMsg('categoryintersection-noresults') . "</em>\n";
         } else {
             $articles = $apiData['query']['categoryintersection'];
             // Summary of the query and the results.
             $html .= "<small><em>" . wfMsg('categoryintersection-summary', implode($categories, ", "), $limit, count($articles)) . "</em></small><br/>\n";
             $html .= "<ul>\n";
             foreach ($articles as $articleData) {
                 $title = $articleData['title'];
                 $titleObj = Title::newFromText($title);
                 $html .= "<li><a href='" . $titleObj->getFullURL() . "'>{$title}</a></li>\n";
             }
             $html .= "</ul>\n";
         }
         // Display the URL that could be used to make that API call.
         $apiUrl = $wgServer . $wgScriptPath . "/api.php?" . http_build_query($apiParams);
         $apiUrl = strtr($apiUrl, array("%3A" => ":", "%2F" => "/", "%7C" => "|"));
         $html .= "<br/><strong>" . wfMsg('categoryintersection-query-used') . "</strong><br/>\n";
         $html .= "<a href='{$apiUrl}'>{$apiUrl}</a>\n";
     } else {
         // TODO: Some placeholder text that explains that you should use the form on the left to make a query.
         // TODO: Some placeholder text that explains that you should use the form on the left to make a query.
     }
     $html .= "</div>\n";
     $out->addHTML($html);
     wfProfileOut(__METHOD__);
 }
 /**
  * Get recent article revisions with filtered users
  */
 private function getRevisionsFromAPI($limit)
 {
     wfProfileIn(__METHOD__);
     $apiData = ApiService::call(array('action' => 'query', 'prop' => 'revisions', 'pageids' => $this->pageId, 'rvlimit' => $limit * 4, 'rvprop' => 'timestamp|user'));
     if (empty($apiData)) {
         wfProfileOut(__METHOD__);
         return false;
     }
     $pageData = array_pop($apiData['query']['pages']);
     // article has no revisions
     if (empty($pageData['revisions'])) {
         wfProfileOut(__METHOD__);
         return false;
     }
     $revisions = $pageData['revisions'];
     $filteredRevisions = array();
     $count = 0;
     // filter out bots and blocked users
     foreach ($revisions as $revision) {
         if (self::filterOutEditors($revision)) {
             $filteredRevisions[] = $revision;
             $count++;
         }
         if ($count >= $limit) {
             break;
         }
     }
     $ret = array('latest' => $revisions[0]['timestamp'], 'revisions' => $filteredRevisions);
     wfProfileOut(__METHOD__);
     return $ret;
 }
	public function executeIndex() {
		global $wgUser, $wgMemc;

		$this->isUserLoggedIn = $wgUser->isLoggedIn();

		// get the count of images on this wiki
		$wikiService = F::build( 'WikiService' );
		$this->total = $wikiService->getTotalImages();

		// Pull the list of images from memcache first
		// FIXME: create and use service (see RT #79288)

		$this->thumbUrls = $wgMemc->get( LatestPhotosController::memcacheKey() );
		if (empty($this->thumbUrls)) {
			// api service

			$params = array(
				'action' => 'query',
				'list' => 'logevents',
				'letype' => 'upload',
				'leprop' => 'title',
				'lelimit' => 50,
			);

			$apiData = ApiService::call($params);

			if (empty($apiData)) {
				return false;
			}
			$imageList = $apiData['query']['logevents'];

			$fileList = array_map(array($this, "getImageData"), $imageList);
			$fileList = array_filter($fileList, array($this, "filterImages"));

			// make sure the list of images is unique and limited to 11 images (12 including the see all image)
			$shaList = array();
			$uniqueList = array();

			foreach ($fileList as $data) {
				$sha = $data['file']->sha1;
				if ( !array_key_exists($sha, $shaList) && ( $data['file']->media_type != 'VIDEO' ) ) {
					$shaList[$sha] = true;
					$uniqueList[] = $data;
				}
				if (count($uniqueList) > 10) break;
			}

			$this->thumbUrls = array_map(array($this, 'getTemplateData'), $uniqueList);
			$wgMemc->set( LatestPhotosController::memcacheKey(), $this->thumbUrls);
		}

		if (count($this->thumbUrls) < 3) {
			$this->enableScroll = false;
		} else {
			$this->enableScroll = true;
		}

		if (count($this->thumbUrls)  <= 0) {
			$this->enableEmptyGallery = true;
		} else {
			$this->enableEmptyGallery = false;
		}
	}
 /**
  * Same as 'VideoHandlerHelper::getVideoDetail' but retrieves information from an external wiki
  * Typically used to get premium video info from video.wikia.com when on another wiki.
  * @param string $dbName - The DB name of the wiki that should be used to find video details
  * @param array|string $title - The list of title of the video to get details for
  * @param array $videoOptions
  *   [ array( 'thumbWidth' => int, 'thumbHeight' => int, 'postedInArticles' => int, 'getThumbnail' => bool, 'thumbOptions' => array ) ]
  * @return array - As associative array of video information
  */
 public function getVideoDetailFromWiki($dbName, $title, $videoOptions)
 {
     wfProfileIn(__METHOD__);
     $params = ['controller' => 'VideoHandler', 'method' => 'getVideoDetail', 'fileTitle' => $title, 'videoOptions' => $videoOptions];
     $response = ApiService::foreignCall($dbName, $params, ApiService::WIKIA);
     $videoDetail = empty($response['detail']) ? [] : $response['detail'];
     wfProfileOut(__METHOD__);
     return $videoDetail;
 }
 /**
  * @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;
         }
     });
 }
 /**
  * This method calls out to the wiki given by $wikiId to get revision data, since
  * this data cannot be gathered locally if $wikiId != $wgCityId
  *
  * @param int $revId
  * @param int $wikiId
  *
  * @return bool
  */
 public function loadDataFromRevIdOnWiki($revId, $wikiId, $useMasterDB = false)
 {
     $dbName = WikiFactory::IDtoDB($wikiId);
     $params = ['controller' => 'WallNotifications', 'method' => 'getEntityData', 'revId' => $revId, 'useMasterDB' => $useMasterDB];
     $response = ApiService::foreignCall($dbName, $params, ApiService::WIKIA);
     if (!empty($response['status']) && $response['status'] == 'ok') {
         $this->parentTitleDbKey = $response['parentTitleDbKey'];
         $this->msgText = $response['msgText'];
         $this->threadTitleFull = $response['threadTitleFull'];
         $this->data = $response['data'];
         return true;
     }
     return false;
 }
 /**
  * Get list of recently uploaded files (RT #79288)
  *
  * @param $limit
  *
  * @return Title[]
  */
 public static function getRecentlyUploaded($limit)
 {
     global $wgEnableAchievementsExt;
     wfProfileIn(__METHOD__);
     $images = false;
     // get list of recent log entries (type = 'upload')
     // limit*2 because of possible duplicates in log caused by image reuploads
     $res = ApiService::call(array('action' => 'query', 'list' => 'logevents', 'letype' => 'upload', 'leprop' => 'title', 'lelimit' => $limit * 2));
     if (!empty($res['query']['logevents'])) {
         foreach ($res['query']['logevents'] as $entry) {
             // ignore Video:foo entries from VideoEmbedTool
             if ($entry['ns'] == NS_IMAGE && !WikiaFileHelper::isTitleVideo($entry['title'])) {
                 $image = Title::newFromText($entry['title']);
                 if (!empty($image)) {
                     // skip badges upload (RT #90607)
                     if (!empty($wgEnableAchievementsExt) && Ach_isBadgeImage($image->getText())) {
                         continue;
                     }
                     // use keys to remove duplicates
                     $images[$image->getDBkey()] = $image;
                     // limit number of results
                     if (count($images) == $limit) {
                         break;
                     }
                 }
             }
         }
         // use numeric keys
         if (is_array($images)) {
             $images = array_values($images);
         }
     }
     wfProfileOut(__METHOD__);
     return $images;
 }
Example #18
0
 /**
  * Returns page ID statistics for a given wiki
  * @return array
  */
 public function getApiStatsForWiki()
 {
     return \ApiService::call(array('action' => 'query', 'prop' => 'info', 'inprop' => 'url|created|views|revcount', 'meta' => 'siteinfo', 'siprop' => 'statistics'));
 }
Example #19
0
 /**
  * @param array $topArticles - output from getTopArticles
  * @return array of article details. Format:
  * [
  *   'type' => self::RECOMMENDATION_TYPE,
  *   'title' => $articleDetails['title'],
  *   'url' => $response['basepath'] . $articleDetails['url'],
  *   'description' => $articleDetails['abstract'],
  *   'media' => [
  *     'url' => $articleDetails['thumbnail']
  *   ],
  *   'source' => self::RECOMMENDATION_ENGINE
  * ]
  */
 protected function getArticlesInfo($topArticles)
 {
     wfProfileIn(__METHOD__);
     $out = [];
     foreach ($topArticles as $topArticleInfo) {
         $articleId = $topArticleInfo['articleId'];
         $wikiId = $topArticleInfo['wikiId'];
         $params = ['controller' => 'ArticlesApiController', 'method' => 'getDetails', 'ids' => $articleId, 'width' => 400, 'height' => 225];
         $wikiData = \WikiFactory::getWikiByID($wikiId);
         $response = \ApiService::foreignCall($wikiData->city_dbname, $params, \ApiService::WIKIA);
         if (!empty($response['items'][$articleId])) {
             $articleDetails = $response['items'][$articleId];
             $media = ['thumbUrl' => $articleDetails['thumbnail'], 'originalWidth' => !empty($articleDetails['original_dimensions']['width']) ? (int) $articleDetails['original_dimensions']['width'] : null, 'originalHeight' => !empty($articleDetails['original_dimensions']['height']) ? (int) $articleDetails['original_dimensions']['height'] : null];
             $out[] = ['type' => self::RECOMMENDATION_TYPE, 'title' => $wikiData->city_title . ' - ' . $articleDetails['title'], 'url' => $response['basepath'] . $articleDetails['url'], 'description' => $articleDetails['abstract'], 'media' => $media, 'source' => self::RECOMMENDATION_ENGINE];
         }
     }
     wfProfileOut(__METHOD__);
     return $out;
 }
 /**
  * Add more detail for global articles to the current $data by making HTTP requests to the other wiki URLs
  * @param array $data
  * @return array
  */
 public function addGlobalSummary($data)
 {
     return $this->addSummary($data, function ($dbName, $articleIds) {
         $ids = array();
         $result = array();
         foreach ($articleIds as $id) {
             $memcKey = $this->getMemcKeyGlobalSummary($dbName, $id);
             $summary = $this->wg->Memc->get($memcKey);
             if (is_array($summary)) {
                 $result['summary'][$id] = $summary;
             } else {
                 $ids[] = $id;
             }
         }
         if (!empty($ids)) {
             $params = array('controller' => 'ArticleSummaryController', 'method' => 'blurb', 'ids' => implode(',', $ids));
             $response = ApiService::foreignCall($dbName, $params, ApiService::WIKIA);
             if (!empty($response['summary'])) {
                 foreach ($response['summary'] as $id => $info) {
                     if (!array_key_exists('error', $info)) {
                         $result['summary'][$id] = $info;
                         $memcKey = $this->getMemcKeyGlobalSummary($dbName, $id);
                         $this->wg->Memc->set($memcKey, $info, 60 * 60);
                     }
                 }
             }
         }
         return $result;
     });
 }
 private function getArticlesCategories($page_title, $page_id)
 {
     $as = new ApiService();
     $params = array("action" => "query", "prop" => "categories", "titles" => "{$page_title}");
     $res = $as->call($params);
     $res_part = $res["query"]["pages"];
     $filled_indexes = array_keys($res_part);
     $categories = array();
     $part = $res_part[$filled_indexes[0]];
     if ($this->indexIsInArray("categories", $part)) {
         $category = $part["categories"];
         foreach ($category as $cat) {
             $splited = explode(':', $cat["title"]);
             $categories[] = $splited[1];
         }
     }
     return $categories;
 }
Example #22
0
 protected function findIdForUrls($urls, $source = null)
 {
     $data = [];
     if (!empty($urls)) {
         foreach ($urls as $item) {
             $url = $item['url'];
             $result = GlobalTitle::explodeURL($url);
             $wikia_id = $result['wikiId'];
             $articleName = $result['articleName'];
             if (!(empty($wikia_id) || empty($articleName))) {
                 $res = ApiService::foreignCall(WikiFactory::IDtoDB($wikia_id), ['action' => 'query', 'titles' => $articleName, 'indexpageids', 'format' => 'json']);
                 if (!empty($res['query']['pages'])) {
                     $pages = array_keys($res['query']['pages']);
                     $page_id = array_shift($pages);
                     $newItem = $item;
                     $newItem['wikia_id'] = $wikia_id;
                     $newItem['page_id'] = $page_id;
                     $newItem['source'] = $source;
                     $data[] = $newItem;
                 }
             }
         }
     }
     return $data;
 }
 private function getRecentActivity($num = 5)
 {
     $wg = \F::app()->wg;
     $data = \ApiService::call(['action' => 'query', 'list' => 'recentchanges', 'rctype' => implode('|', ['new', 'edit']), 'rcprop' => implode('|', ['user', 'title']), 'rcnamespace' => implode('|', $wg->ContentNamespaces), 'rcexcludeuser' => $this->targetUser->getName(), 'rcshow' => implode('|', ['!minor', '!bot', '!anon', '!redirect']), 'rclimit' => $num, 'rctoponly' => 1]);
     if (!empty($data['query']['recentchanges'])) {
         return $data['query']['recentchanges'];
     }
     return [];
 }
 /**
  *
  * 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__);
 }
 /**
  * Get video list from Video wiki
  *
  * @return array
  */
 public function addVideosFromVideoWiki()
 {
     $params = ['controller' => 'VideoHandler', 'method' => 'getVideoList', 'sort' => $this->sort, 'limit' => $this->getPaddedVideoLimit(), 'category' => $this->categories];
     $response = \ApiService::foreignCall($this->wg->WikiaVideoRepoDBName, $params, \ApiService::WIKIA);
     $videosWithDetails = $this->getVideoDetailFromVideoWiki($this->getVideoTitles($response['videos']));
     foreach ($videosWithDetails as $video) {
         if ($this->atVideoLimit()) {
             break;
         }
         $this->addVideo($video);
     }
 }
 /**
  * @desc Returns data from API based on parameters
  *
  * @param array $params more documentation: http://en.wikipedia.org/w/api.php
  *
  * @return mixed
  */
 private function getApiData($params)
 {
     $dbName = $this->getCommunityDbName();
     $data = ApiService::foreignCall($dbName, $params);
     return $data;
 }
 /**
  * Returns given blog post data
  *
  * @param string $dbname database name
  * @param string $title page title
  * @param boolean $getSnippet include blog post snippet in the data
  * @return mixed blog post data
  */
 private function getBlogPostData($dbname, $title, $getSnippet = false)
 {
     wfProfileIn(__METHOD__);
     wfDebug(__METHOD__ . ": '{$title}' ({$dbname})\n");
     $cityId = WikiFactory::DBtoID($dbname);
     // get blog info
     $data = ApiService::foreignCall($dbname, array('action' => 'query', 'prop' => 'revisions', 'titles' => $title, 'rvprop' => 'timestamp|user|content'));
     $blogPostData = reset($data['query']['pages']);
     $revisionData = array_shift($blogPostData['revisions']);
     // page ID
     $pageId = intval($blogPostData['pageid']);
     // parse blog post wikitext and get summary
     if ($getSnippet === true) {
         $data = ApiService::foreignCall($dbname, array('action' => 'parse', 'text' => $revisionData['*'], 'title' => $title));
         $snippet = $this->getSnippet($data['parse']['text']['*']);
     }
     // generate full URL to blog post
     $blogPostTitle = F::build('GlobalTitle', array($pageId, $cityId), 'newFromId');
     if (empty($blogPostTitle)) {
         wfProfileOut(__METHOD__);
         return false;
     }
     $blogPostUrl = $blogPostTitle->getFullURL();
     // get blog post title
     $title = end(explode('/', $blogPostTitle->getText(), 2));
     // get creator real name
     $creator = F::build('User', array($revisionData['user']), 'newFromName');
     if (!empty($creator)) {
         $creatorName = $creator->getRealName();
         if ($creatorName == '') {
             $creatorName = $creator->getName();
         }
     } else {
         $creatorName = $revisionData['user'];
     }
     // get creator user page URL
     $blogCreatorPageTitle = F::build('GlobalTitle', array($revisionData['user'], NS_USER, $cityId), 'newFromText');
     // get 220x140 image
     $imageData = ApiService::foreignCall($dbname, array('action' => 'imagecrop', 'imgId' => $pageId, 'imgSize' => 220, 'imgHeight' => 140));
     // data
     $res = array('pageId' => $pageId, 'cityId' => $cityId, 'wikiname' => WikiFactory::getVarValueByName('wgSitename', $cityId), 'wikiUrl' => 'http://' . parse_url($blogPostUrl, PHP_URL_HOST), 'title' => $title, 'url' => $blogPostUrl, 'created' => $revisionData['timestamp'], 'creator' => $creatorName, 'creatorUrl' => $blogCreatorPageTitle->getFullURL(), 'snippet' => !empty($snippet) ? $snippet : false, 'image' => $imageData['image']['imagecrop']);
     wfProfileOut(__METHOD__);
     return $res;
 }
 /**
  * swap video
  * @requestParam string videoTitle
  * @requestParam string newTitle
  * @requestParam integer currentPage
  * @responseParam string result [ok/error]
  * @responseParam string msg - result message
  * @responseParam string html
  * @responseParam integer totalVideos - total videos with suggestions
  * @responseParam string redirect - redirect url
  */
 public function swapVideo()
 {
     $videoTitle = $this->request->getVal('videoTitle', '');
     $newTitle = $this->request->getVal('newTitle', '');
     $currentPage = $this->getVal('currentPage', 1);
     $sort = 'recent';
     // set default value for response params
     $this->setDefaultParams();
     // validate action
     $validAction = $this->sendRequest('LicensedVideoSwapSpecial', 'validateAction', array('videoTitle' => $videoTitle));
     $msg = $validAction->getVal('msg', '');
     if (!empty($msg)) {
         $this->result = 'error';
         $this->msg = $msg;
         return;
     }
     $file = WikiaFileHelper::getVideoFileFromTitle($videoTitle);
     // check if file exists
     if (empty($file)) {
         $this->html = '';
         $this->result = 'error';
         $this->msg = wfMessage('videohandler-error-video-no-exist')->text();
         return;
     }
     $helper = new LicensedVideoSwapHelper();
     // check if the file is swapped
     $articleId = $file->getTitle()->getArticleID();
     if ($helper->isSwapped($articleId)) {
         $this->result = 'error';
         $this->msg = wfMessage('lvs-error-already-swapped')->text();
         return;
     }
     // check if the file is premium
     if (!$file->isLocal()) {
         $this->result = 'error';
         $this->msg = wfMessage('lvs-error-permission')->text();
         return;
     }
     // set swap status
     $helper->setPageStatusInfo($articleId);
     // check if the new file exists
     $params = array('controller' => 'VideoHandlerController', 'method' => 'fileExists', 'fileTitle' => $newTitle);
     $response = ApiService::foreignCall($this->wg->WikiaVideoRepoDBName, $params, ApiService::WIKIA);
     if (empty($response['fileExists'])) {
         $helper->deletePageStatusInfo($articleId);
         $this->result = 'error';
         $this->msg = wfMessage('videohandler-error-video-no-exist')->text();
         return;
     }
     // remove local video
     $removeVideo = $this->sendRequest('VideoHandlerController', 'removeVideo', array('title' => $file->getName()));
     $result = $removeVideo->getVal('result', '');
     if ($result != 'ok') {
         $helper->deletePageStatusInfo($articleId);
         $this->result = 'error';
         $this->msg = $removeVideo->getVal('msg', '');
         return;
     }
     $isSameTitle = $videoTitle->getDBKey() == $newTitle;
     $swapValue['newTitle'] = $newTitle;
     // force to get new file for same title
     $newFile = WikiaFileHelper::getVideoFileFromTitle($newTitle, $isSameTitle);
     // check if new file exists
     if (empty($newFile)) {
         $helper->deletePageStatusInfo($articleId);
         $this->result = 'error';
         $this->msg = wfMessage('videohandler-error-video-no-exist')->text();
         return;
     }
     // add premium video
     wfRunHooks('AddPremiumVideo', array($newFile->getTitle()));
     $title = Title::newFromText($videoTitle->getDBKey(), NS_FILE);
     if (!$isSameTitle) {
         // add redirect url
         $status = $helper->addRedirectLink($title, $newFile->getTitle());
         if (!$status->isGood()) {
             $helper->deletePageStatusInfo($articleId);
             $this->result = 'error';
             $this->msg = $status->getMessage();
             return;
         }
         // set swap status
         $helper->setPageStatusSwap($title->getArticleID(), $articleId);
         $helper->setPageStatusInfoSwap($title->getArticleID(), $swapValue);
     } else {
         // set swap status
         $helper->setPageStatusSwapExact($title->getArticleID(), $articleId);
         $helper->setPageStatusInfoSwapExact($title->getArticleID(), $swapValue);
     }
     // remove old page status
     $helper->deletePageStatus($articleId);
     $helper->deletePageStatusInfo($articleId);
     // move suggestion data to new article
     $helper->moveSuggestionData($articleId, $title->getArticleID());
     // add to log
     $reason = wfMessage('lvs-log-summary', $file->getTitle()->getText(), $newFile->getTitle()->getText())->text();
     $helper->addLog($file->getTitle(), wfMessage('lvs-log-description')->text(), $reason);
     // clear cache for total videos
     $helper->invalidateCacheTotalVideos();
     // clear cache for total new videos
     $helper->invalidateCacheTotalNewVideos();
     // get video list
     $useMaster = true;
     $videoList = $helper->getRegularVideoList($sort, $currentPage, $useMaster);
     // get total videos with suggestions
     $this->totalVideos = $helper->getUnswappedVideoTotal($useMaster);
     if (empty($videoList)) {
         $this->redirect = $helper->getRedirectUrl($currentPage, $sort);
     } else {
         $this->html = $this->app->renderView('LicensedVideoSwapSpecial', 'row', array('videoList' => $videoList));
         $this->html .= $helper->getPagination($this->totalVideos, $currentPage, $sort);
     }
     $undoOptions = array('class' => 'undo', 'href' => '#', 'data-video-title' => $videoTitle->getDBKey(), 'data-new-title' => $newTitle->getDBKey());
     $undo = Xml::element('a', $undoOptions, wfMessage('lvs-undo-swap')->text());
     $this->msg = wfMessage('lvs-swap-video-success')->rawParams($undo)->parse();
 }
Example #29
0
 /**
  * add video to other wikis
  * @param string $videoUrl
  * @param array $wikis
  * @return array|false $result
  */
 public function addVideoAcrossWikis($videoUrl, $wikis)
 {
     wfProfileIn(__METHOD__);
     $params = array('controller' => 'VideosController', 'method' => 'addVideo', 'url' => $videoUrl);
     $result = false;
     foreach ($wikis as $wikiId => $wiki) {
         $result[$wikiId] = true;
         if (!empty($wiki['d'])) {
             $response = ApiService::foreignCall($wiki['d'], $params, ApiService::WIKIA, true);
             if (!empty($response['error'])) {
                 Wikia::log(__METHOD__, false, "Error: Cannot add video to wiki {$wikiId} ({$response['error']})", true, true);
                 $result[$wikiId] = false;
             }
         }
     }
     wfProfileOut(__METHOD__);
     return $result;
 }
 /**
  * @group Slow
  * @slowExecutionTime 0.14909 ms
  * @covers \Wikia\Search\MediaWikiService::getApiStatsForWiki
  */
 public function testGetApiStatsForWiki()
 {
     global $wgCityId;
     $this->assertEquals(\ApiService::call(array('action' => 'query', 'prop' => 'info', 'inprop' => 'url|created|views|revcount', 'meta' => 'siteinfo', 'siprop' => 'statistics')), (new MediaWikiService())->getApiStatsForWiki($wgCityId));
 }