Debian Codegraph @

includes/specials/SpecialUnwatchedPages.php

raw symbols SCIP
1 <?php
2 /**
3 * Copyright © 2005 Ævar Arnfjörð Bjarmason
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 */
22
23 namespace MediaWiki\Specials;
24
25 use HtmlArmor;
26 use MediaWiki\Cache\LinkBatchFactory;
27 use MediaWiki\Html\Html;
28 use MediaWiki\Language\ILanguageConverter;
29 use MediaWiki\Languages\LanguageConverterFactory;
30 use MediaWiki\Linker\Linker;
31 use MediaWiki\SpecialPage\QueryPage;
32 use MediaWiki\Title\Title;
33 use Skin;
34 use stdClass;
35 use Wikimedia\Rdbms\IConnectionProvider;
36 use Wikimedia\Rdbms\IDatabase;
37 use Wikimedia\Rdbms\IResultWrapper;
38
39 /**
40 * List of pages that are not on anyone's watchlist.
41 *
42 * @ingroup SpecialPage
43 * @author Ævar Arnfjörð Bjarmason <[email protected]om>
44 */
45 class SpecialUnwatchedPages extends QueryPage {
46
47 private LinkBatchFactory $linkBatchFactory;
48 private ILanguageConverter $languageConverter;
49
50 /**
51 * @param LinkBatchFactory $linkBatchFactory
52 * @param IConnectionProvider $dbProvider
53 * @param LanguageConverterFactory $languageConverterFactory
54 */
55 public function __construct(
56 LinkBatchFactory $linkBatchFactory,
57 IConnectionProvider $dbProvider,
58 LanguageConverterFactory $languageConverterFactory
59 ) {
60 parent::__construct( 'Unwatchedpages', 'unwatchedpages' );
61 $this->linkBatchFactory = $linkBatchFactory;
62 $this->setDatabaseProvider( $dbProvider );
63 $this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() );
64 }
65
66 public function isExpensive() {
67 return true;
68 }
69
70 public function isSyndicated() {
71 return false;
72 }
73
74 /**
75 * Pre-cache page existence to speed up link generation
76 *
77 * @param IDatabase $db
78 * @param IResultWrapper $res
79 */
80 public function preprocessResults( $db, $res ) {
81 if ( !$res->numRows() ) {
82 return;
83 }
84
85 $batch = $this->linkBatchFactory->newLinkBatch();
86 foreach ( $res as $row ) {
87 $batch->add( $row->namespace, $row->title );
88 }
89 $batch->execute();
90
91 $res->seek( 0 );
92 }
93
94 public function getQueryInfo() {
95 $dbr = $this->getDatabaseProvider()->getReplicaDatabase();
96 return [
97 'tables' => [ 'page', 'watchlist' ],
98 'fields' => [
99 'namespace' => 'page_namespace',
100 'title' => 'page_title',
101 'value' => 'page_namespace'
102 ],
103 'conds' => [
104 'wl_title' => null,
105 'page_is_redirect' => 0,
106 $dbr->expr( 'page_namespace', '!=', NS_MEDIAWIKI ),
107 ],
108 'join_conds' => [ 'watchlist' => [
109 'LEFT JOIN', [ 'wl_title = page_title',
110 'wl_namespace = page_namespace' ] ] ]
111 ];
112 }
113
114 protected function sortDescending() {
115 return false;
116 }
117
118 protected function getOrderFields() {
119 return [ 'page_namespace', 'page_title' ];
120 }
121
122 /**
123 * Add the JS
124 * @param string|null $par
125 */
126 public function execute( $par ) {
127 parent::execute( $par );
128 $this->getOutput()->addModules( 'mediawiki.special.unwatchedPages' );
129 $this->addHelpLink( 'Help:Watchlist' );
130 }
131
132 /**
133 * @param Skin $skin
134 * @param stdClass $result Result row
135 * @return string
136 */
137 public function formatResult( $skin, $result ) {
138 $nt = Title::makeTitleSafe( $result->namespace, $result->title );
139 if ( !$nt ) {
140 return Html::element( 'span', [ 'class' => 'mw-invalidtitle' ],
141 Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
142 }
143
144 $text = $this->languageConverter->convertHtml( $nt->getPrefixedText() );
145
146 $linkRenderer = $this->getLinkRenderer();
147
148 $plink = $linkRenderer->makeKnownLink( $nt, new HtmlArmor( $text ) );
149 $wlink = $linkRenderer->makeKnownLink(
150 $nt,
151 $this->msg( 'watch' )->text(),
152 [ 'class' => 'mw-watch-link' ],
153 [ 'action' => 'watch' ]
154 );
155
156 return $this->getLanguage()->specialList( $plink, $wlink );
157 }
158
159 protected function getGroupName() {
160 return 'maintenance';
161 }
162 }
163
164 /**
165 * Retain the old class name for backwards compatibility.
166 * @deprecated since 1.41
167 */
168 class_alias( SpecialUnwatchedPages::class, 'SpecialUnwatchedPages' );