SpecialTrackingCategories.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * Implements Special:TrackingCategories
  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. * A special page that displays list of tracking categories
  25. * Tracking categories allow pages with certain characteristics to be tracked.
  26. * It works by adding any such page to a category automatically.
  27. * Category is specified by the tracking category's system message.
  28. *
  29. * @ingroup SpecialPage
  30. * @since 1.23
  31. */
  32. class SpecialTrackingCategories extends SpecialPage {
  33. function __construct() {
  34. parent::__construct( 'TrackingCategories' );
  35. }
  36. function execute( $par ) {
  37. $this->setHeaders();
  38. $this->outputHeader();
  39. $this->addHelpLink( 'Help:Categories' );
  40. $this->getOutput()->allowClickjacking();
  41. $this->getOutput()->addModuleStyles( 'jquery.tablesorter.styles' );
  42. $this->getOutput()->addModules( 'jquery.tablesorter' );
  43. $this->getOutput()->addHTML(
  44. Html::openElement( 'table', [ 'class' => 'mw-datatable sortable',
  45. 'id' => 'mw-trackingcategories-table' ] ) . "\n" .
  46. "<thead><tr>
  47. <th>" .
  48. $this->msg( 'trackingcategories-msg' )->escaped() . "
  49. </th>
  50. <th>" .
  51. $this->msg( 'trackingcategories-name' )->escaped() .
  52. "</th>
  53. <th>" .
  54. $this->msg( 'trackingcategories-desc' )->escaped() . "
  55. </th>
  56. </tr></thead>"
  57. );
  58. $trackingCategories = new TrackingCategories( $this->getConfig() );
  59. $categoryList = $trackingCategories->getTrackingCategories();
  60. $batch = new LinkBatch();
  61. foreach ( $categoryList as $catMsg => $data ) {
  62. $batch->addObj( $data['msg'] );
  63. foreach ( $data['cats'] as $catTitle ) {
  64. $batch->addObj( $catTitle );
  65. }
  66. }
  67. $batch->execute();
  68. Hooks::run( 'SpecialTrackingCategories::preprocess', [ $this, $categoryList ] );
  69. $linkRenderer = $this->getLinkRenderer();
  70. foreach ( $categoryList as $catMsg => $data ) {
  71. $allMsgs = [];
  72. $catDesc = $catMsg . '-desc';
  73. $catMsgTitleText = $linkRenderer->makeLink(
  74. $data['msg'],
  75. $catMsg
  76. );
  77. foreach ( $data['cats'] as $catTitle ) {
  78. $html = $linkRenderer->makeLink(
  79. $catTitle,
  80. $catTitle->getText()
  81. );
  82. Hooks::run( 'SpecialTrackingCategories::generateCatLink',
  83. [ $this, $catTitle, &$html ] );
  84. $allMsgs[] = $html;
  85. }
  86. # Extra message, when no category was found
  87. if ( $allMsgs === [] ) {
  88. $allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
  89. }
  90. /*
  91. * Show category description if it exists as a system message
  92. * as category-name-desc
  93. */
  94. $descMsg = $this->msg( $catDesc );
  95. if ( $descMsg->isBlank() ) {
  96. $descMsg = $this->msg( 'trackingcategories-nodesc' );
  97. }
  98. $this->getOutput()->addHTML(
  99. Html::openElement( 'tr' ) .
  100. Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-name' ] ) .
  101. $this->getLanguage()->commaList( array_unique( $allMsgs ) ) .
  102. Html::closeElement( 'td' ) .
  103. Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-msg' ] ) .
  104. $catMsgTitleText .
  105. Html::closeElement( 'td' ) .
  106. Html::openElement( 'td', [ 'class' => 'mw-trackingcategories-desc' ] ) .
  107. $descMsg->parse() .
  108. Html::closeElement( 'td' ) .
  109. Html::closeElement( 'tr' )
  110. );
  111. }
  112. $this->getOutput()->addHTML( Html::closeElement( 'table' ) );
  113. }
  114. protected function getGroupName() {
  115. return 'pages';
  116. }
  117. }