]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialCategories.php
MediaWiki 1.15.4-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         $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                 return array(
48                         'tables' => array( 'category' ),
49                         'fields' => array( 'cat_title','cat_pages' ),
50                         'conds' => array( 'cat_pages > 0' ), 
51                         'options' => array( 'USE INDEX' => 'cat_title' ),
52                 );
53         }
54
55         function getIndexField() {
56 #               return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
57                 return 'cat_title';
58         }
59
60         function getDefaultQuery() {
61                 parent::getDefaultQuery();
62                 unset( $this->mDefaultQuery['from'] );
63                 return $this->mDefaultQuery;
64         }
65 #       protected function getOrderTypeMessages() {
66 #               return array( 'abc' => 'special-categories-sort-abc',
67 #                       'count' => 'special-categories-sort-count' );
68 #       }
69
70         protected function getDefaultDirections() {
71 #               return array( 'abc' => false, 'count' => true );
72                 return false;
73         }
74
75         /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
76         public function getBody() {
77                 if (!$this->mQueryDone) {
78                         $this->doQuery();
79                 }
80                 $batch = new LinkBatch;
81
82                 $this->mResult->rewind();
83
84                 while ( $row = $this->mResult->fetchObject() ) {
85                         $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
86                 }
87                 $batch->execute();
88                 $this->mResult->rewind();
89                 return parent::getBody();
90         }
91
92         function formatRow($result) {
93                 global $wgLang;
94                 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
95                 $titleText = $this->getSkin()->makeLinkObj( $title, htmlspecialchars( $title->getText() ) );
96                 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
97                                 $wgLang->formatNum( $result->cat_pages ) );
98                 return Xml::tags('li', null, "$titleText ($count)" ) . "\n";
99         }
100         
101         public function getStartForm( $from ) {
102                 global $wgScript;
103                 $t = SpecialPage::getTitleFor( 'Categories' );
104         
105                 return
106                         Xml::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
107                                 Xml::hidden( 'title', $t->getPrefixedText() ) .
108                                 Xml::fieldset( wfMsg( 'categories' ),
109                                         Xml::inputLabel( wfMsg( 'categoriesfrom' ),
110                                                 'from', 'from', 20, $from ) .
111                                         ' ' .
112                                         Xml::submitButton( wfMsg( 'allpagessubmit' ) ) ) );
113         }
114 }