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;
 }
 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);
 }
 /**
  * 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;
 }
 /**
  * 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 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');
             }
         }
     }
 }
 /**
  * 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;
		}
	}
 /**
  *
  * 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__);
 }
 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;
 }
 /**
  * @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));
 }
 /**
  *
  * Returns list of categories on a wiki in batches by self::LIMIT
  *
  * @requestParam Integer limit
  * @requestParam String offset
  *
  * @response items
  * @response offset
  */
 private function getCategories()
 {
     wfProfileIn(__METHOD__);
     $limit = $this->request->getVal('limit', self::LIMIT * 2);
     $offset = $this->request->getVal('offset', '');
     $items = WikiaDataAccess::cache(wfMemcKey(__METHOD__, $offset, $limit, self::NEW_API_VERSION), 6 * self::HOURS, function () use($limit, $offset) {
         return ApiService::call(['action' => 'query', 'list' => 'allcategories', 'redirects' => true, 'aclimit' => $limit, 'acfrom' => $offset, 'acprop' => 'id|size', 'acmin' => 1]);
     });
     $allCategories = $items['query']['allcategories'];
     if (!empty($allCategories)) {
         $ret = [];
         $app = F::app();
         $categoryName = $app->wg->contLang->getNsText(NS_CATEGORY);
         foreach ($allCategories as $value) {
             if ($value['size'] - $value['files'] > 0) {
                 $ret[] = $this::getJsonItem($value['*'], $categoryName, isset($value['pageid']) ? (int) $value['pageid'] : 0);
             }
         }
         $this->response->setVal('items', $ret);
         if (!empty($items['query-continue'])) {
             $this->response->setVal('offset', $items['query-continue']['allcategories']['acfrom']);
         }
     } else {
         wfProfileOut(__METHOD__);
         throw new NotFoundApiException('No Curated Content');
     }
     wfProfileOut(__METHOD__);
 }
Example #13
0
 /**
  * @author Jakub Kurcek
  * @param format string 'rss' or 'atom'
  *
  */
 private function FeedRecentChanges($format)
 {
     global $wgEnableBlogArticles, $wgParser, $wgUser, $wgServer, $wgOut, $wgExtensionsPath, $wgRequest;
     $userAvatarSize = 48;
     $aReturn = ApiService::call(array('action' => 'query', 'list' => 'recentchanges', 'rclimit' => '30', 'rcprop' => 'user|comment|timestamp|title|ids', 'rctype' => 'new|edit', 'rcshow' => '!anon|!bot', 'rcnamespace' => '0'));
     $feedArray = array();
     foreach ($aReturn['query']['recentchanges'] as $val) {
         $oTitle = Title::newFromText($val['title']);
         if ($val['type'] == 'edit') {
             $action = 'edited';
         } else {
             $action = 'created';
         }
         $feedArray[] = array('title' => $val['title'], 'description' => $val['user'] . ' ' . $action . ' the ' . $val['title'], 'url' => $oTitle->getFullURL(), 'date' => $val['timestamp'], 'author' => $val['user'], 'otherTags' => array('image' => AvatarService::getAvatarUrl($val['user'], $userAvatarSize)));
     }
     $this->showFeed($format, wfMsg('feed-title-recentchanges'), $feedArray);
 }
 /**
  * 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__);
 }
Example #15
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'));
 }
 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 [];
 }
 /**
  * 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;
 }
 /**
  * @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;
         }
     });
 }
 /**
  * @brief this is a function that return rendered article
  *
  * @requestParam String title of a page
  */
 public function renderPage()
 {
     $titleName = $this->request->getVal('title');
     $html = ApiService::call(array('action' => 'parse', 'page' => $titleName, 'prop' => 'text', 'redirects' => 1, 'useskin' => 'wikiamobile'));
     $globals = $this->sendSelfRequest('getGlobals');
     $this->response->setVal('globals', $globals->getVal('globals'));
     $this->response->setVal('messages', F::build('JSMessages')->getPackages(array('GameGuides')));
     $this->response->setVal('title', Title::newFromText($titleName)->getText());
     $this->response->setVal('html', $html['parse']['text']['*']);
 }