7 function wfSpecialCategories( $par=null ) {
8 global $wgOut, $wgRequest;
11 $from = $wgRequest->getText( 'from' );
15 $wgOut->allowClickjacking();
16 $cap = new CategoryPager( $from );
19 XML::openElement( 'div', array('class' => 'mw-spcontent') ) .
20 wfMsgExt( 'categoriespagetext', array( 'parse' ), $cap->getNumRows() ) .
21 $cap->getStartForm( $from ) .
22 $cap->getNavigationBar() .
23 '<ul>' . $cap->getBody() . '</ul>' .
24 $cap->getNavigationBar() .
25 XML::closeElement( 'div' )
30 * TODO: Allow sorting by count. We need to have a unique index to do this
33 * @ingroup SpecialPage Pager
35 class CategoryPager extends AlphabeticPager {
36 function __construct( $from ) {
37 parent::__construct();
38 $from = str_replace( ' ', '_', $from );
40 $from = Title::capitalize( $from, NS_CATEGORY );
41 $this->mOffset = $from;
45 function getQueryInfo() {
47 'tables' => array( 'category' ),
48 'fields' => array( 'cat_title','cat_pages' ),
49 'conds' => array( 'cat_pages > 0' ),
50 'options' => array( 'USE INDEX' => 'cat_title' ),
54 function getIndexField() {
55 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
59 function getDefaultQuery() {
60 parent::getDefaultQuery();
61 unset( $this->mDefaultQuery['from'] );
62 return $this->mDefaultQuery;
64 # protected function getOrderTypeMessages() {
65 # return array( 'abc' => 'special-categories-sort-abc',
66 # 'count' => 'special-categories-sort-count' );
69 protected function getDefaultDirections() {
70 # return array( 'abc' => false, 'count' => true );
74 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
75 public function getBody() {
76 $batch = new LinkBatch;
78 $this->mResult->rewind();
80 while ( $row = $this->mResult->fetchObject() ) {
81 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
84 $this->mResult->rewind();
85 return parent::getBody();
88 function formatRow($result) {
90 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
91 $titleText = $this->getSkin()->link( $title, htmlspecialchars( $title->getText() ) );
92 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
93 $wgLang->formatNum( $result->cat_pages ) );
94 return Xml::tags('li', null, "$titleText ($count)" ) . "\n";
97 public function getStartForm( $from ) {
99 $t = SpecialPage::getTitleFor( 'Categories' );
102 Xml::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
103 Xml::hidden( 'title', $t->getPrefixedText() ) .
104 Xml::fieldset( wfMsg( 'categories' ),
105 Xml::inputLabel( wfMsg( 'categoriesfrom' ),
106 'from', 'from', 20, $from ) .
108 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) ) );