SpecialCategories.php 3.0 KB

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