SpecialMostLinkedCategories.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Implements Special:Mostlinkedcategories
  4. *
  5. * Copyright © 2005, Ævar Arnfjörð Bjarmason
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. * http://www.gnu.org/copyleft/gpl.html
  21. *
  22. * @file
  23. * @ingroup SpecialPage
  24. * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
  25. */
  26. use MediaWiki\MediaWikiServices;
  27. use Wikimedia\Rdbms\IResultWrapper;
  28. use Wikimedia\Rdbms\IDatabase;
  29. /**
  30. * A querypage to show categories ordered in descending order by the pages in them
  31. *
  32. * @ingroup SpecialPage
  33. */
  34. class SpecialMostLinkedCategories extends QueryPage {
  35. function __construct( $name = 'Mostlinkedcategories' ) {
  36. parent::__construct( $name );
  37. }
  38. function isSyndicated() {
  39. return false;
  40. }
  41. public function getQueryInfo() {
  42. return [
  43. 'tables' => [ 'category' ],
  44. 'fields' => [ 'title' => 'cat_title',
  45. 'namespace' => NS_CATEGORY,
  46. 'value' => 'cat_pages' ],
  47. 'conds' => [ 'cat_pages > 0' ],
  48. ];
  49. }
  50. function sortDescending() {
  51. return true;
  52. }
  53. /**
  54. * Fetch user page links and cache their existence
  55. *
  56. * @param IDatabase $db
  57. * @param IResultWrapper $res
  58. */
  59. function preprocessResults( $db, $res ) {
  60. $this->executeLBFromResultWrapper( $res );
  61. }
  62. /**
  63. * @param Skin $skin
  64. * @param object $result Result row
  65. * @return string
  66. */
  67. function formatResult( $skin, $result ) {
  68. $nt = Title::makeTitleSafe( NS_CATEGORY, $result->title );
  69. if ( !$nt ) {
  70. return Html::element(
  71. 'span',
  72. [ 'class' => 'mw-invalidtitle' ],
  73. Linker::getInvalidTitleDescription(
  74. $this->getContext(),
  75. NS_CATEGORY,
  76. $result->title )
  77. );
  78. }
  79. $text = MediaWikiServices::getInstance()->getContentLanguage()
  80. ->convert( htmlspecialchars( $nt->getText() ) );
  81. $plink = $this->getLinkRenderer()->makeLink( $nt, new HtmlArmor( $text ) );
  82. $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
  83. return $this->getLanguage()->specialList( $plink, $nlinks );
  84. }
  85. protected function getGroupName() {
  86. return 'highuse';
  87. }
  88. }