summaryrefslogtreecommitdiff
path: root/includes/SpecialCategories.php
blob: 45e1ae6cc9eb785a1e1ec78f7434fbc0b326e95a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
 *
 * @addtogroup SpecialPage
 */

function wfSpecialCategories() {
	global $wgOut;

	$cap = new CategoryPager();
	$wgOut->addHTML( 
		wfMsgWikiHtml( 'categoriespagetext' ) .
		$cap->getNavigationBar()
		. '<ul>' . $cap->getBody() . '</ul>' .
		$cap->getNavigationBar()
		);
}

/**
 * @addtogroup SpecialPage
 * @addtogroup Pager
 */
class CategoryPager extends AlphabeticPager {
	function getQueryInfo() {
		return array(
			'tables' => array('categorylinks'),
			'fields' => array('cl_to','count(*) AS count'),
			'options' => array('GROUP BY' => 'cl_to')
			);
	}
	
	function getIndexField() {
		return "cl_to";
	}
	
	/* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
	function getBody() {
		if (!$this->mQueryDone) {
			$this->doQuery();
		}
		$batch = new LinkBatch;
	
		$this->mResult->rewind();
		
		while ( $row = $this->mResult->fetchObject() ) {
			$batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cl_to ) );
		}
		$batch->execute();
		$this->mResult->rewind();
		return parent::getBody();
	}
	
	function formatRow($result) {
		global $wgLang;
		$title = Title::makeTitle( NS_CATEGORY, $result->cl_to );
		return ( 
			'<li>' .
			$this->getSkin()->makeLinkObj( $title, $title->getText() )
			. ' ' .
			wfMsgExt( 'nmembers', array( 'parsemag', 'escape'),
				$wgLang->formatNum( $result->count ) )
			. "</li>\n" );
	}
}

?>