Debian Codegraph @

includes/specials/SpecialWantedPages.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Specials;
22
23 use MediaWiki\Cache\LinkBatchFactory;
24 use MediaWiki\Linker\LinksMigration;
25 use MediaWiki\MainConfigNames;
26 use MediaWiki\SpecialPage\WantedQueryPage;
27 use Wikimedia\Rdbms\IConnectionProvider;
28
29 /**
30 * List of the most-linked pages that do not exist.
31 *
32 * @ingroup SpecialPage
33 */
34 class SpecialWantedPages extends WantedQueryPage {
35
36 private LinksMigration $linksMigration;
37
38 /**
39 * @param IConnectionProvider $dbProvider
40 * @param LinkBatchFactory $linkBatchFactory
41 */
42 public function __construct(
43 IConnectionProvider $dbProvider,
44 LinkBatchFactory $linkBatchFactory,
45 LinksMigration $linksMigration
46 ) {
47 parent::__construct( 'Wantedpages' );
48 $this->setDatabaseProvider( $dbProvider );
49 $this->setLinkBatchFactory( $linkBatchFactory );
50 $this->linksMigration = $linksMigration;
51 }
52
53 public function isIncludable() {
54 return true;
55 }
56
57 public function execute( $par ) {
58 $inc = $this->including();
59
60 if ( $inc ) {
61 $this->limit = (int)$par;
62 $this->offset = 0;
63 }
64 $this->shownavigation = !$inc;
65 parent::execute( $par );
66 }
67
68 public function getQueryInfo() {
69 $dbr = $this->getDatabaseProvider()->getReplicaDatabase();
70 $count = $this->getConfig()->get( MainConfigNames::WantedPagesThreshold ) - 1;
71 [ $blNamespace, $blTitle ] = $this->linksMigration->getTitleFields( 'pagelinks' );
72 $queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks', 'pagelinks' );
73 $query = [
74 'tables' => array_merge( $queryInfo['tables'], [
75 'pg1' => 'page',
76 'pg2' => 'page'
77 ] ),
78 'fields' => [
79 'namespace' => $blNamespace,
80 'title' => $blTitle,
81 'value' => 'COUNT(*)'
82 ],
83 'conds' => [
84 'pg1.page_namespace' => null,
85 $dbr->expr( $blNamespace, '!=', [ NS_USER, NS_USER_TALK ] ),
86 $dbr->expr( 'pg2.page_namespace', '!=', NS_MEDIAWIKI ),
87 ],
88 'options' => [
89 'HAVING' => [
90 'COUNT(*) > ' . $dbr->addQuotes( $count ),
91 'COUNT(*) > SUM(pg2.page_is_redirect)'
92 ],
93 'GROUP BY' => [ $blNamespace, $blTitle ]
94 ],
95 'join_conds' => array_merge( [
96 'pg1' => [
97 'LEFT JOIN', [
98 'pg1.page_namespace = ' . $blNamespace,
99 'pg1.page_title = ' . $blTitle
100 ]
101 ],
102 'pg2' => [ 'LEFT JOIN', 'pg2.page_id = pl_from' ]
103 ], $queryInfo['joins'] )
104 ];
105 // Replacement for the WantedPages::getSQL hook
106 $this->getHookRunner()->onWantedPages__getQueryInfo( $this, $query );
107
108 return $query;
109 }
110
111 protected function getGroupName() {
112 return 'maintenance';
113 }
114 }
115
116 /**
117 * Retain the old class name for backwards compatibility.
118 * @deprecated since 1.40
119 */
120 class_alias( SpecialWantedPages::class, 'WantedPagesPage' );