SpecialUnwatchedPages.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * Implements Special:Unwatchedpages
  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 displays a list of pages that are not on anyones watchlist.
  31. *
  32. * @ingroup SpecialPage
  33. */
  34. class SpecialUnwatchedPages extends QueryPage {
  35. function __construct( $name = 'Unwatchedpages' ) {
  36. parent::__construct( $name, 'unwatchedpages' );
  37. }
  38. public function isExpensive() {
  39. return true;
  40. }
  41. function isSyndicated() {
  42. return false;
  43. }
  44. /**
  45. * Pre-cache page existence to speed up link generation
  46. *
  47. * @param IDatabase $db
  48. * @param IResultWrapper $res
  49. */
  50. public function preprocessResults( $db, $res ) {
  51. if ( !$res->numRows() ) {
  52. return;
  53. }
  54. $batch = new LinkBatch();
  55. foreach ( $res as $row ) {
  56. $batch->add( $row->namespace, $row->title );
  57. }
  58. $batch->execute();
  59. $res->seek( 0 );
  60. }
  61. public function getQueryInfo() {
  62. $dbr = wfGetDB( DB_REPLICA );
  63. return [
  64. 'tables' => [ 'page', 'watchlist' ],
  65. 'fields' => [
  66. 'namespace' => 'page_namespace',
  67. 'title' => 'page_title',
  68. 'value' => 'page_namespace'
  69. ],
  70. 'conds' => [
  71. 'wl_title IS NULL',
  72. 'page_is_redirect' => 0,
  73. 'page_namespace != ' . $dbr->addQuotes( NS_MEDIAWIKI ),
  74. ],
  75. 'join_conds' => [ 'watchlist' => [
  76. 'LEFT JOIN', [ 'wl_title = page_title',
  77. 'wl_namespace = page_namespace' ] ] ]
  78. ];
  79. }
  80. function sortDescending() {
  81. return false;
  82. }
  83. function getOrderFields() {
  84. return [ 'page_namespace', 'page_title' ];
  85. }
  86. /**
  87. * Add the JS
  88. * @param string|null $par
  89. */
  90. public function execute( $par ) {
  91. parent::execute( $par );
  92. $this->getOutput()->addModules( 'mediawiki.special.unwatchedPages' );
  93. $this->addHelpLink( 'Help:Watchlist' );
  94. }
  95. /**
  96. * @param Skin $skin
  97. * @param object $result Result row
  98. * @return string
  99. */
  100. function formatResult( $skin, $result ) {
  101. $nt = Title::makeTitleSafe( $result->namespace, $result->title );
  102. if ( !$nt ) {
  103. return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
  104. Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
  105. }
  106. $text = MediaWikiServices::getInstance()->getContentLanguage()->
  107. convert( htmlspecialchars( $nt->getPrefixedText() ) );
  108. $linkRenderer = $this->getLinkRenderer();
  109. $plink = $linkRenderer->makeKnownLink( $nt, new HtmlArmor( $text ) );
  110. $wlink = $linkRenderer->makeKnownLink(
  111. $nt,
  112. $this->msg( 'watch' )->text(),
  113. [ 'class' => 'mw-watch-link' ],
  114. [ 'action' => 'watch' ]
  115. );
  116. return $this->getLanguage()->specialList( $plink, $wlink );
  117. }
  118. protected function getGroupName() {
  119. return 'maintenance';
  120. }
  121. }