SpecialMostCategories.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * Implements Special:Mostcategories
  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 special page that list pages that have highest category count
  31. *
  32. * @ingroup SpecialPage
  33. */
  34. class SpecialMostCategories extends QueryPage {
  35. function __construct( $name = 'Mostcategories' ) {
  36. parent::__construct( $name );
  37. }
  38. public function isExpensive() {
  39. return true;
  40. }
  41. function isSyndicated() {
  42. return false;
  43. }
  44. public function getQueryInfo() {
  45. return [
  46. 'tables' => [ 'categorylinks', 'page' ],
  47. 'fields' => [
  48. 'namespace' => 'page_namespace',
  49. 'title' => 'page_title',
  50. 'value' => 'COUNT(*)'
  51. ],
  52. 'conds' => [ 'page_namespace' =>
  53. MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces() ],
  54. 'options' => [
  55. 'HAVING' => 'COUNT(*) > 1',
  56. 'GROUP BY' => [ 'page_namespace', 'page_title' ]
  57. ],
  58. 'join_conds' => [
  59. 'page' => [
  60. 'LEFT JOIN',
  61. 'page_id = cl_from'
  62. ]
  63. ]
  64. ];
  65. }
  66. /**
  67. * @param IDatabase $db
  68. * @param IResultWrapper $res
  69. */
  70. function preprocessResults( $db, $res ) {
  71. $this->executeLBFromResultWrapper( $res );
  72. }
  73. /**
  74. * @param Skin $skin
  75. * @param object $result Result row
  76. * @return string
  77. */
  78. function formatResult( $skin, $result ) {
  79. $title = Title::makeTitleSafe( $result->namespace, $result->title );
  80. if ( !$title ) {
  81. return Html::element(
  82. 'span',
  83. [ 'class' => 'mw-invalidtitle' ],
  84. Linker::getInvalidTitleDescription(
  85. $this->getContext(),
  86. $result->namespace,
  87. $result->title
  88. )
  89. );
  90. }
  91. $linkRenderer = $this->getLinkRenderer();
  92. if ( $this->isCached() ) {
  93. $link = $linkRenderer->makeLink( $title );
  94. } else {
  95. $link = $linkRenderer->makeKnownLink( $title );
  96. }
  97. $count = $this->msg( 'ncategories' )->numParams( $result->value )->escaped();
  98. return $this->getLanguage()->specialList( $link, $count );
  99. }
  100. protected function getGroupName() {
  101. return 'highuse';
  102. }
  103. }