MediaWiki master
SpecialWantedPages.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
28
35
36 private LinksMigration $linksMigration;
37
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
120class_alias( SpecialWantedPages::class, 'WantedPagesPage' );
const NS_USER
Definition Defines.php:67
const NS_MEDIAWIKI
Definition Defines.php:73
const NS_USER_TALK
Definition Defines.php:68
Service for compat reading of links tables.
A class containing constants representing the names of configuration variables.
const WantedPagesThreshold
Name constant for the WantedPagesThreshold setting, for use with Config::get()
setDatabaseProvider(IConnectionProvider $databaseProvider)
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
getConfig()
Shortcut to get main config object.
including( $x=null)
Whether the special page is being evaluated via transclusion.
Base class for a "wanted" query page like WantedPages, WantedTemplates, etc.
List of the most-linked pages that do not exist.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
isIncludable()
Whether it's allowed to transclude the special page via {{Special:Foo/params}}.
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
__construct(IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory, LinksMigration $linksMigration)
execute( $par)
This is the actual workhorse.
Provide primary and replica IDatabase connections.