MediaWiki master
SpecialWantedPages.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
28
35
36 private LinksMigration $linksMigration;
37
38 public function __construct(
39 IConnectionProvider $dbProvider,
40 LinkBatchFactory $linkBatchFactory,
41 LinksMigration $linksMigration
42 ) {
43 parent::__construct( 'Wantedpages' );
44 $this->setDatabaseProvider( $dbProvider );
45 $this->setLinkBatchFactory( $linkBatchFactory );
46 $this->linksMigration = $linksMigration;
47 }
48
49 public function isIncludable() {
50 return true;
51 }
52
53 public function execute( $par ) {
54 $inc = $this->including();
55
56 if ( $inc ) {
57 $this->limit = (int)$par;
58 $this->offset = 0;
59 }
60 $this->shownavigation = !$inc;
61 parent::execute( $par );
62 }
63
64 public function getQueryInfo() {
65 $dbr = $this->getDatabaseProvider()->getReplicaDatabase();
66 $count = $this->getConfig()->get( MainConfigNames::WantedPagesThreshold ) - 1;
67 [ $blNamespace, $blTitle ] = $this->linksMigration->getTitleFields( 'pagelinks' );
68 $queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks', 'pagelinks' );
69 $query = [
70 'tables' => array_merge( $queryInfo['tables'], [
71 'pg1' => 'page',
72 'pg2' => 'page'
73 ] ),
74 'fields' => [
75 'namespace' => $blNamespace,
76 'title' => $blTitle,
77 'value' => 'COUNT(*)'
78 ],
79 'conds' => [
80 'pg1.page_namespace' => null,
81 $dbr->expr( $blNamespace, '!=', [ NS_USER, NS_USER_TALK ] ),
82 $dbr->expr( 'pg2.page_namespace', '!=', NS_MEDIAWIKI ),
83 ],
84 'options' => [
85 'HAVING' => [
86 'COUNT(*) > ' . $dbr->addQuotes( $count ),
87 'COUNT(*) > SUM(pg2.page_is_redirect)'
88 ],
89 'GROUP BY' => [ $blNamespace, $blTitle ]
90 ],
91 'join_conds' => array_merge( [
92 'pg1' => [
93 'LEFT JOIN', [
94 'pg1.page_namespace = ' . $blNamespace,
95 'pg1.page_title = ' . $blTitle
96 ]
97 ],
98 'pg2' => [ 'LEFT JOIN', 'pg2.page_id = pl_from' ]
99 ], $queryInfo['joins'] )
100 ];
101 // Replacement for the WantedPages::getSQL hook
102 $this->getHookRunner()->onWantedPages__getQueryInfo( $this, $query );
103
104 return $query;
105 }
106
107 protected function getGroupName() {
108 return 'maintenance';
109 }
110}
111
116class_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.