MediaWiki master
SpecialWantedPages.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Specials;
25
31
38
39 private LinksMigration $linksMigration;
40
45 public function __construct(
46 IConnectionProvider $dbProvider,
47 LinkBatchFactory $linkBatchFactory,
48 LinksMigration $linksMigration
49 ) {
50 parent::__construct( 'Wantedpages' );
51 $this->setDatabaseProvider( $dbProvider );
52 $this->setLinkBatchFactory( $linkBatchFactory );
53 $this->linksMigration = $linksMigration;
54 }
55
56 public function isIncludable() {
57 return true;
58 }
59
60 public function execute( $par ) {
61 $inc = $this->including();
62
63 if ( $inc ) {
64 $this->limit = (int)$par;
65 $this->offset = 0;
66 }
67 $this->shownavigation = !$inc;
68 parent::execute( $par );
69 }
70
71 public function getQueryInfo() {
72 $dbr = $this->getDatabaseProvider()->getReplicaDatabase();
73 $count = $this->getConfig()->get( MainConfigNames::WantedPagesThreshold ) - 1;
74 [ $blNamespace, $blTitle ] = $this->linksMigration->getTitleFields( 'pagelinks' );
75 $queryInfo = $this->linksMigration->getQueryInfo( 'pagelinks', 'pagelinks' );
76 $query = [
77 'tables' => array_merge( $queryInfo['tables'], [
78 'pg1' => 'page',
79 'pg2' => 'page'
80 ] ),
81 'fields' => [
82 'namespace' => $blNamespace,
83 'title' => $blTitle,
84 'value' => 'COUNT(*)'
85 ],
86 'conds' => [
87 'pg1.page_namespace' => null,
88 $dbr->expr( $blNamespace, '!=', [ NS_USER, NS_USER_TALK ] ),
89 $dbr->expr( 'pg2.page_namespace', '!=', NS_MEDIAWIKI ),
90 ],
91 'options' => [
92 'HAVING' => [
93 'COUNT(*) > ' . $dbr->addQuotes( $count ),
94 'COUNT(*) > SUM(pg2.page_is_redirect)'
95 ],
96 'GROUP BY' => [ $blNamespace, $blTitle ]
97 ],
98 'join_conds' => array_merge( [
99 'pg1' => [
100 'LEFT JOIN', [
101 'pg1.page_namespace = ' . $blNamespace,
102 'pg1.page_title = ' . $blTitle
103 ]
104 ],
105 'pg2' => [ 'LEFT JOIN', 'pg2.page_id = pl_from' ]
106 ], $queryInfo['joins'] )
107 ];
108 // Replacement for the WantedPages::getSQL hook
109 $this->getHookRunner()->onWantedPages__getQueryInfo( $this, $query );
110
111 return $query;
112 }
113
114 protected function getGroupName() {
115 return 'maintenance';
116 }
117}
118
123class_alias( SpecialWantedPages::class, 'WantedPagesPage' );
const NS_USER
Definition Defines.php:66
const NS_MEDIAWIKI
Definition Defines.php:72
const NS_USER_TALK
Definition Defines.php:67
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.
Class definition for a wanted query page like WantedPages, WantedTemplates, etc.
A special page that lists most linked pages that does 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.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...