Ejemplo n.º 1
0
 /**
  * Get list of two most linked categories current article is in
  */
 public function getMostLinkedCategories()
 {
     wfProfileIn(__METHOD__);
     global $wgOut, $wgMemc;
     // check whether current article belongs to any category
     $categoryLinks = $wgOut->getCategoryLinks();
     if (empty($categoryLinks)) {
         wfProfileOut(__METHOD__);
         return array();
     }
     // try to get cached data
     $key = $this->getKey('mostlinkedcategories');
     $categories = $wgMemc->get($key);
     if (!is_array($categories)) {
         wfProfileIn(__METHOD__ . '::miss');
         $limit = 2;
         // get list of articles categories with number of articles "linked" to them
         $dbr = wfGetDB(DB_SLAVE);
         // check querycache first
         $res = $dbr->select(array('querycache', 'categorylinks'), array('qc_title as cl_to, qc_value as cnt'), array('qc_title = cl_to', 'qc_type' => 'Mostpopularcategories', 'cl_from' => $this->pageId), __METHOD__, array('ORDER BY' => 'qc_value DESC', 'LIMIT' => $limit));
         // order and filter out blacklisted categories
         $service = new CategoriesService();
         $categories = array();
         while ($obj = $dbr->fetchObject($res)) {
             if (!$service->isCategoryBlacklisted($obj->cl_to) && !$service->isCategoryHidden($obj->cl_to)) {
                 $categories[$obj->cl_to] = $obj->cnt;
             }
         }
         $wgMemc->set($key, $categories, self::CACHE_TTL);
         wfProfileOut(__METHOD__ . '::miss');
     }
     wfProfileOut(__METHOD__);
     return $categories;
 }
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));
	}