WARNING: HUGE COMMIT
[lhc/web/wiklou.git] / includes / SpecialCategories.php
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
5 */
6
7 function wfSpecialCategories() {
8 global $wgOut, $wgRequest;
9
10 $cap = new CategoryPager();
11 $wgOut->addHTML(
12 wfMsgExt( 'categoriespagetext', array( 'parse' ) ) .
13 $cap->getStartForm( str_replace( '_', ' ', $wgRequest->getVal( 'offset' ) ) ) .
14 $cap->getNavigationBar() .
15 '<ul>' . $cap->getBody() . '</ul>' .
16 $cap->getNavigationBar()
17 );
18 }
19
20 /**
21 * TODO: Allow sorting by count. We need to have a unique index to do this
22 * properly.
23 *
24 * @ingroup SpecialPage Pager
25 */
26 class CategoryPager extends AlphabeticPager {
27 function getQueryInfo() {
28 global $wgRequest;
29 return array(
30 'tables' => array( 'category' ),
31 'fields' => array( 'cat_title','cat_pages' ),
32 'conds' => array( 'cat_pages > 0' )
33 );
34 }
35
36 function getIndexField() {
37 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
38 return 'cat_title';
39 }
40
41 # protected function getOrderTypeMessages() {
42 # return array( 'abc' => 'special-categories-sort-abc',
43 # 'count' => 'special-categories-sort-count' );
44 # }
45
46 protected function getDefaultDirections() {
47 # return array( 'abc' => false, 'count' => true );
48 return false;
49 }
50
51 /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
52 public function getBody() {
53 if (!$this->mQueryDone) {
54 $this->doQuery();
55 }
56 $batch = new LinkBatch;
57
58 $this->mResult->rewind();
59
60 while ( $row = $this->mResult->fetchObject() ) {
61 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
62 }
63 $batch->execute();
64 $this->mResult->rewind();
65 return parent::getBody();
66 }
67
68 function formatRow($result) {
69 global $wgLang;
70 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
71 $titleText = $this->getSkin()->makeLinkObj( $title, htmlspecialchars( $title->getText() ) );
72 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
73 $wgLang->formatNum( $result->cat_pages ) );
74 return Xml::tags('li', null, "$titleText ($count)" ) . "\n";
75 }
76
77 public function getStartForm( $from='' ) {
78 global $wgScript;
79 $t = SpecialPage::getTitleFor( 'Categories' );
80
81 return
82 Xml::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
83 Xml::hidden( 'title', $t->getPrefixedText() ) .
84 Xml::fieldset( wfMsg( 'categories' ),
85 Xml::inputLabel( wfMsg( 'categoriesfrom' ),
86 'offset', 'offset', 20, $from ) .
87 ' ' .
88 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) ) );
89 }
90 }