Link content pages and uploaded files to AllPages and FileList respectively
[lhc/web/wiklou.git] / includes / specials / SpecialCategories.php
1 <?php
2 /**
3 * Implements Special:Categories
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * @ingroup SpecialPage
26 */
27 class SpecialCategories extends SpecialPage {
28
29 function __construct() {
30 parent::__construct( 'Categories' );
31 }
32
33 function execute( $par ) {
34 global $wgOut, $wgRequest;
35
36 $this->setHeaders();
37 $this->outputHeader();
38 $wgOut->allowClickjacking();
39
40 $from = $wgRequest->getText( 'from', $par );
41
42 $cap = new CategoryPager( $from );
43 $cap->doQuery();
44
45 $wgOut->addHTML(
46 Html::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) .
47 wfMsgExt( 'categoriespagetext', array( 'parse' ), $cap->getNumRows() ) .
48 $cap->getStartForm( $from ) .
49 $cap->getNavigationBar() .
50 '<ul>' . $cap->getBody() . '</ul>' .
51 $cap->getNavigationBar() .
52 Html::closeElement( 'div' )
53 );
54 }
55 }
56
57 /**
58 * TODO: Allow sorting by count. We need to have a unique index to do this
59 * properly.
60 *
61 * @ingroup SpecialPage Pager
62 */
63 class CategoryPager extends AlphabeticPager {
64 function __construct( $from ) {
65 parent::__construct();
66 $from = str_replace( ' ', '_', $from );
67 if( $from !== '' ) {
68 $from = Title::capitalize( $from, NS_CATEGORY );
69 $this->mOffset = $from;
70 }
71 }
72
73 function getQueryInfo() {
74 return array(
75 'tables' => array( 'category' ),
76 'fields' => array( 'cat_title','cat_pages' ),
77 'conds' => array( 'cat_pages > 0' ),
78 'options' => array( 'USE INDEX' => 'cat_title' ),
79 );
80 }
81
82 function getTitle() {
83 return SpecialPage::getTitleFor( 'Categories' );
84 }
85
86 function getIndexField() {
87 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
88 return 'cat_title';
89 }
90
91 function getDefaultQuery() {
92 parent::getDefaultQuery();
93 unset( $this->mDefaultQuery['from'] );
94 return $this->mDefaultQuery;
95 }
96 # protected function getOrderTypeMessages() {
97 # return array( 'abc' => 'special-categories-sort-abc',
98 # 'count' => 'special-categories-sort-count' );
99 # }
100
101 protected function getDefaultDirections() {
102 # return array( 'abc' => false, 'count' => true );
103 return false;
104 }
105
106 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
107 public function getBody() {
108 $batch = new LinkBatch;
109
110 $this->mResult->rewind();
111
112 foreach ( $this->mResult as $row ) {
113 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
114 }
115 $batch->execute();
116 $this->mResult->rewind();
117 return parent::getBody();
118 }
119
120 function formatRow($result) {
121 global $wgLang;
122 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
123 $titleText = $this->getSkin()->link( $title, htmlspecialchars( $title->getText() ) );
124 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
125 $wgLang->formatNum( $result->cat_pages ) );
126 return Xml::tags('li', null, "$titleText ($count)" ) . "\n";
127 }
128
129 public function getStartForm( $from ) {
130 global $wgScript;
131
132 return
133 Xml::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
134 Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
135 Xml::fieldset( wfMsg( 'categories' ),
136 Xml::inputLabel( wfMsg( 'categoriesfrom' ),
137 'from', 'from', 20, $from ) .
138 ' ' .
139 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) ) );
140 }
141 }