Fix disabling of APC cache when loading message files: apc.enabled has been PHP_INI_S...
[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 $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 global $wgCapitalLinks, $wgContLang;
40 if( $wgCapitalLinks ) {
41 $from = $wgContLang->ucfirst( $from );
42 }
43 $this->mOffset = $from;
44 }
45 }
46
47 function getQueryInfo() {
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 $batch = new LinkBatch;
79
80 $this->mResult->rewind();
81
82 while ( $row = $this->mResult->fetchObject() ) {
83 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
84 }
85 $batch->execute();
86 $this->mResult->rewind();
87 return parent::getBody();
88 }
89
90 function formatRow($result) {
91 global $wgLang;
92 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
93 $titleText = $this->getSkin()->link( $title, htmlspecialchars( $title->getText() ) );
94 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
95 $wgLang->formatNum( $result->cat_pages ) );
96 return Xml::tags('li', null, "$titleText ($count)" ) . "\n";
97 }
98
99 public function getStartForm( $from ) {
100 global $wgScript;
101 $t = SpecialPage::getTitleFor( 'Categories' );
102
103 return
104 Xml::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
105 Xml::hidden( 'title', $t->getPrefixedText() ) .
106 Xml::fieldset( wfMsg( 'categories' ),
107 Xml::inputLabel( wfMsg( 'categoriesfrom' ),
108 'from', 'from', 20, $from ) .
109 ' ' .
110 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) ) );
111 }
112 }