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