81b337d8acc8100f175c3c8666864160b8400f71
[lhc/web/wiklou.git] / includes / specials / SpecialCategories.php
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
5 */
6
7 function wfSpecialCategories( $par=null ) {
8 global $wgOut, $wgRequest;
9
10 if( $par == '' ) {
11 $from = $wgRequest->getText( 'from' );
12 } else {
13 $from = $par;
14 }
15 $cap = new CategoryPager( $from );
16 $wgOut->addHTML(
17 XML::openElement( 'div', array('class' => 'mw-spcontent') ) .
18 wfMsgExt( 'categoriespagetext', array( 'parse' ) ) .
19 $cap->getStartForm( $from ) .
20 $cap->getNavigationBar() .
21 '<ul>' . $cap->getBody() . '</ul>' .
22 $cap->getNavigationBar() .
23 XML::closeElement( 'div' )
24 );
25 }
26
27 /**
28 * TODO: Allow sorting by count. We need to have a unique index to do this
29 * properly.
30 *
31 * @ingroup SpecialPage Pager
32 */
33 class CategoryPager extends AlphabeticPager {
34 function __construct( $from ) {
35 parent::__construct();
36 $from = str_replace( ' ', '_', $from );
37 if( $from !== '' ) {
38 global $wgCapitalLinks, $wgContLang;
39 if( $wgCapitalLinks ) {
40 $from = $wgContLang->ucfirst( $from );
41 }
42 $this->mOffset = $from;
43 }
44 }
45
46 function getQueryInfo() {
47 global $wgRequest;
48 return array(
49 'tables' => array( 'category' ),
50 'fields' => array( 'cat_title','cat_pages' ),
51 'conds' => array( 'cat_pages > 0' ),
52 'options' => array( 'USE INDEX' => 'cat_title' ),
53 );
54 }
55
56 function getIndexField() {
57 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
58 return 'cat_title';
59 }
60
61 function getDefaultQuery() {
62 parent::getDefaultQuery();
63 unset( $this->mDefaultQuery['from'] );
64 return $this->mDefaultQuery;
65 }
66 # protected function getOrderTypeMessages() {
67 # return array( 'abc' => 'special-categories-sort-abc',
68 # 'count' => 'special-categories-sort-count' );
69 # }
70
71 protected function getDefaultDirections() {
72 # return array( 'abc' => false, 'count' => true );
73 return false;
74 }
75
76 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
77 public function getBody() {
78 if (!$this->mQueryDone) {
79 $this->doQuery();
80 }
81 $batch = new LinkBatch;
82
83 $this->mResult->rewind();
84
85 while ( $row = $this->mResult->fetchObject() ) {
86 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
87 }
88 $batch->execute();
89 $this->mResult->rewind();
90 return parent::getBody();
91 }
92
93 function formatRow($result) {
94 global $wgLang;
95 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
96 $titleText = $this->getSkin()->makeLinkObj( $title, htmlspecialchars( $title->getText() ) );
97 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
98 $wgLang->formatNum( $result->cat_pages ) );
99 return Xml::tags('li', null, "$titleText ($count)" ) . "\n";
100 }
101
102 public function getStartForm( $from ) {
103 global $wgScript;
104 $t = SpecialPage::getTitleFor( 'Categories' );
105
106 return
107 Xml::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
108 Xml::hidden( 'title', $t->getPrefixedText() ) .
109 Xml::fieldset( wfMsg( 'categories' ),
110 Xml::inputLabel( wfMsg( 'categoriesfrom' ),
111 'from', 'from', 20, $from ) .
112 ' ' .
113 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) ) );
114 }
115 }