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