]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialCategories.php
MediaWiki 1.16.1-scripts
[autoinstallsdev/mediawiki.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         $wgOut->allowClickjacking();
16         $cap = new CategoryPager( $from );
17         $cap->doQuery();
18         $wgOut->addHTML(
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' )
26         );
27 }
28
29 /**
30  * TODO: Allow sorting by count.  We need to have a unique index to do this
31  * properly.
32  *
33  * @ingroup SpecialPage Pager
34  */
35 class CategoryPager extends AlphabeticPager {
36         function __construct( $from ) {
37                 parent::__construct();
38                 $from = str_replace( ' ', '_', $from );
39                 if( $from !== '' ) {
40                         $from = Title::capitalize( $from, NS_CATEGORY );
41                         $this->mOffset = $from;
42                 }
43         }
44         
45         function getQueryInfo() {
46                 return array(
47                         'tables' => array( 'category' ),
48                         'fields' => array( 'cat_title','cat_pages' ),
49                         'conds' => array( 'cat_pages > 0' ), 
50                         'options' => array( 'USE INDEX' => 'cat_title' ),
51                 );
52         }
53
54         function getIndexField() {
55 #               return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
56                 return 'cat_title';
57         }
58
59         function getDefaultQuery() {
60                 parent::getDefaultQuery();
61                 unset( $this->mDefaultQuery['from'] );
62                 return $this->mDefaultQuery;
63         }
64 #       protected function getOrderTypeMessages() {
65 #               return array( 'abc' => 'special-categories-sort-abc',
66 #                       'count' => 'special-categories-sort-count' );
67 #       }
68
69         protected function getDefaultDirections() {
70 #               return array( 'abc' => false, 'count' => true );
71                 return false;
72         }
73
74         /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
75         public function getBody() {
76                 $batch = new LinkBatch;
77
78                 $this->mResult->rewind();
79
80                 while ( $row = $this->mResult->fetchObject() ) {
81                         $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
82                 }
83                 $batch->execute();
84                 $this->mResult->rewind();
85                 return parent::getBody();
86         }
87
88         function formatRow($result) {
89                 global $wgLang;
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";
95         }
96         
97         public function getStartForm( $from ) {
98                 global $wgScript;
99                 $t = SpecialPage::getTitleFor( 'Categories' );
100         
101                 return
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 ) .
107                                         ' ' .
108                                         Xml::submitButton( wfMsg( 'allpagessubmit' ) ) ) );
109         }
110 }