SpecialMostLinked.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Implements Special:Mostlinked
  4. *
  5. * Copyright © 2005 Ævar Arnfjörð Bjarmason, 2006 Rob Church
  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. * @author Rob Church <robchur@gmail.com>
  26. */
  27. use Wikimedia\Rdbms\IResultWrapper;
  28. use Wikimedia\Rdbms\IDatabase;
  29. /**
  30. * A special page to show pages ordered by the number of pages linking to them.
  31. *
  32. * @ingroup SpecialPage
  33. */
  34. class SpecialMostLinked extends QueryPage {
  35. function __construct( $name = 'Mostlinked' ) {
  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' => [ 'pagelinks', 'page' ],
  47. 'fields' => [
  48. 'namespace' => 'pl_namespace',
  49. 'title' => 'pl_title',
  50. 'value' => 'COUNT(*)',
  51. 'page_namespace'
  52. ],
  53. 'options' => [
  54. 'HAVING' => 'COUNT(*) > 1',
  55. 'GROUP BY' => [
  56. 'pl_namespace', 'pl_title',
  57. 'page_namespace'
  58. ]
  59. ],
  60. 'join_conds' => [
  61. 'page' => [
  62. 'LEFT JOIN',
  63. [
  64. 'page_namespace = pl_namespace',
  65. 'page_title = pl_title'
  66. ]
  67. ]
  68. ]
  69. ];
  70. }
  71. /**
  72. * Pre-fill the link cache
  73. *
  74. * @param IDatabase $db
  75. * @param IResultWrapper $res
  76. */
  77. function preprocessResults( $db, $res ) {
  78. $this->executeLBFromResultWrapper( $res );
  79. }
  80. /**
  81. * Make a link to "what links here" for the specified title
  82. *
  83. * @param Title $title Title being queried
  84. * @param string $caption Text to display on the link
  85. * @return string
  86. */
  87. function makeWlhLink( $title, $caption ) {
  88. $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
  89. $linkRenderer = $this->getLinkRenderer();
  90. return $linkRenderer->makeKnownLink( $wlh, $caption );
  91. }
  92. /**
  93. * Make links to the page corresponding to the item,
  94. * and the "what links here" page for it
  95. *
  96. * @param Skin $skin Skin to be used
  97. * @param object $result Result row
  98. * @return string
  99. */
  100. function formatResult( $skin, $result ) {
  101. $title = Title::makeTitleSafe( $result->namespace, $result->title );
  102. if ( !$title ) {
  103. return Html::element(
  104. 'span',
  105. [ 'class' => 'mw-invalidtitle' ],
  106. Linker::getInvalidTitleDescription(
  107. $this->getContext(),
  108. $result->namespace,
  109. $result->title )
  110. );
  111. }
  112. $linkRenderer = $this->getLinkRenderer();
  113. $link = $linkRenderer->makeLink( $title );
  114. $wlh = $this->makeWlhLink(
  115. $title,
  116. $this->msg( 'nlinks' )->numParams( $result->value )->text()
  117. );
  118. return $this->getLanguage()->specialList( $link, $wlh );
  119. }
  120. protected function getGroupName() {
  121. return 'highuse';
  122. }
  123. }