SpecialMostInterwikis.php 2.8 KB

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