MediaWiki master
SpecialWantedPages.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
15
22
23 public function __construct(
24 IConnectionProvider $dbProvider,
25 LinkBatchFactory $linkBatchFactory,
26 private readonly LinksMigration $linksMigration
27 ) {
28 parent::__construct( 'Wantedpages' );
29 $this->setDatabaseProvider( $dbProvider );
30 $this->setLinkBatchFactory( $linkBatchFactory );
31 }
32
34 public function isIncludable() {
35 return true;
36 }
37
39 public function execute( $par ) {
40 $inc = $this->including();
41
42 if ( $inc ) {
43 $this->limit = (int)$par;
44 $this->offset = 0;
45 }
46 $this->shownavigation = !$inc;
47 parent::execute( $par );
48 }
49
51 public function getQueryInfo() {
52 $dbr = $this->getDatabaseProvider()->getReplicaDatabase();
53 $count = $this->getConfig()->get( MainConfigNames::WantedPagesThreshold ) - 1;
54 [ $blNamespace, $blTitle ] = $this->linksMigration->getTitleFields( 'pagelinks' );
55 $queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks', 'pagelinks' );
56 $query = [
57 'tables' => array_merge( $queryInfo['tables'], [
58 'pg1' => 'page',
59 'pg2' => 'page'
60 ] ),
61 'fields' => [
62 'namespace' => $blNamespace,
63 'title' => $blTitle,
64 'value' => 'COUNT(*)'
65 ],
66 'conds' => [
67 'pg1.page_namespace' => null,
68 $dbr->expr( $blNamespace, '!=', [ NS_USER, NS_USER_TALK ] ),
69 $dbr->expr( 'pg2.page_namespace', '!=', NS_MEDIAWIKI ),
70 ],
71 'options' => [
72 'HAVING' => [
73 'COUNT(*) > ' . $dbr->addQuotes( $count ),
74 'COUNT(*) > SUM(pg2.page_is_redirect)'
75 ],
76 'GROUP BY' => [ $blNamespace, $blTitle ]
77 ],
78 'join_conds' => array_merge( [
79 'pg1' => [
80 'LEFT JOIN', [
81 'pg1.page_namespace = ' . $blNamespace,
82 'pg1.page_title = ' . $blTitle
83 ]
84 ],
85 'pg2' => [ 'LEFT JOIN', 'pg2.page_id = pl_from' ]
86 ], $queryInfo['joins'] )
87 ];
88 // Replacement for the WantedPages::getSQL hook
89 $this->getHookRunner()->onWantedPages__getQueryInfo( $this, $query );
90
91 return $query;
92 }
93
95 protected function getRecacheDB() {
96 return $this->getDatabaseProvider()->getReplicaDatabase(
97 PageLinksTable::VIRTUAL_DOMAIN,
98 'vslow'
99 );
100 }
101
103 protected function getGroupName() {
104 return 'maintenance';
105 }
106}
107
112class_alias( SpecialWantedPages::class, 'WantedPagesPage' );
const NS_USER
Definition Defines.php:53
const NS_MEDIAWIKI
Definition Defines.php:59
const NS_USER_TALK
Definition Defines.php:54
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()
Factory for LinkBatch objects to batch query page metadata.
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...
__construct(IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory, private readonly LinksMigration $linksMigration)
isIncludable()
Whether it's allowed to transclude the special page via {{Special:Foo/params}}.to override bool
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
getRecacheDB()
Get a DB connection to be used for slow recache queries.to override IReadableDatabase
execute( $par)
This is the actual workhorse.It does everything needed to make a real, honest-to-gosh query page....
Provide primary and replica IDatabase connections.