Ejemplo n.º 1
0
 /**
  * get related pages for article
  * @param int $articleId Article ID
  * @param int $limit limit
  */
 public function get($articleId, $limit = 3)
 {
     global $wgContentNamespaces, $wgEnableRelatedPagesUnionSelectQueries, $wgUser;
     wfProfileIn(__METHOD__);
     $cs = new CategoriesService();
     // prevent from calling this function more than one, use reset() to omit
     if (is_array($this->getData())) {
         wfProfileOut(__METHOD__);
         return $this->getData();
     }
     $this->setData(array());
     $categories = $this->getCategories();
     if (count($categories) > 0) {
         //RT#80681/RT#139837: apply category blacklist
         $categories = CategoriesService::filterOutBlacklistedCategories($categories);
         $categories = $this->getCategoriesByRank($categories);
         if (count($categories) > $this->categoriesLimit) {
             // limit the number of categories to look for
             $categories = array_slice($categories, 0, $this->categoriesLimit);
         }
         // limit * 2 - get more pages (some can be filtered out - RT #72703)
         $pages = $this->getPagesForCategories($articleId, $limit * 2, $categories);
         $this->afterGet($pages, $limit);
     }
     wfProfileOut(__METHOD__);
     return $this->getData();
 }
Ejemplo n.º 2
0
	function testCategoriesService() {
		global $wgBiggestCategoriesBlacklist;

		// blacklist to be used by this unit test
		$wgBiggestCategoriesBlacklist = array('stub', 'foo');

		$service = new CategoriesService();

		$this->assertTrue($service->isCategoryBlacklisted('foo'));
		$this->assertTrue($service->isCategoryBlacklisted('BARFOO'));
		$this->assertTrue($service->isCategoryBlacklisted('Stubs'));
		$this->assertFalse($service->isCategoryBlacklisted('test'));
		$this->assertFalse($service->isCategoryBlacklisted('stu'));

		// test filtering helper method
		$categories = array('Characters', 'Stubs', 'Footest', 'testfoo', 'bar', 'test');

		$this->assertEquals(array('Characters', 'bar', 'test'), CategoriesService::filterOutBlacklistedCategories($categories));
	}
Ejemplo n.º 3
0
 /**
  * Get related pages for article
  *
  * @param int $articleId Article ID
  * @param int $limit limit (up to 10 - see LIMIT_MAX const)
  * @return array
  */
 public function get($articleId, $limit = 3)
 {
     wfProfileIn(__METHOD__);
     // prevent from calling this function more than one, use reset() to omit
     if (is_array($this->getData())) {
         wfProfileOut(__METHOD__);
         return $this->getData();
     }
     // get up to self::LIMIT_MAX items and cache them
     $data = WikiaDataAccess::cache(wfMemcKey(__METHOD__, $articleId, self::MCACHE_VER), WikiaResponse::CACHE_STANDARD, function () use($articleId) {
         $this->setData([]);
         $categories = $this->getCategories($articleId);
         if (count($categories) > 0) {
             // RT#80681/RT#139837: apply category blacklist
             $categories = CategoriesService::filterOutBlacklistedCategories($categories);
             $categories = $this->getCategoriesByRank($categories);
             if (count($categories) > $this->categoriesLimit) {
                 // limit the number of categories to look for
                 $categories = array_slice($categories, 0, $this->categoriesLimit);
             }
             // limit * 2 - get more pages (some can be filtered out - RT #72703)
             $pages = $this->getPagesForCategories($articleId, self::LIMIT_MAX * 2, $categories);
             $this->afterGet($pages, self::LIMIT_MAX);
         }
         return $this->getData();
     });
     // apply the limit
     $this->setData(array_slice($data, 0, $limit));
     wfProfileOut(__METHOD__);
     return $this->getData();
 }