MediaWiki master
SpecialUnusedImages.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
12
19
20 private readonly int $fileMigrationStage;
21
22 public function __construct( IConnectionProvider $dbProvider ) {
23 parent::__construct( 'Unusedimages' );
24 $this->setDatabaseProvider( $dbProvider );
25 $this->fileMigrationStage = $this->getConfig()->get( MainConfigNames::FileSchemaMigrationStage );
26 }
27
29 public function isExpensive() {
30 return true;
31 }
32
34 protected function sortDescending() {
35 return false;
36 }
37
39 public function isSyndicated() {
40 return false;
41 }
42
44 public function getQueryInfo() {
45 if ( $this->fileMigrationStage & SCHEMA_COMPAT_READ_OLD ) {
46 $imageTables = [ 'image' ];
47 $nameField = 'img_name';
48 $timestampField = 'img_timestamp';
49 $fileConds = [];
50 $fileJoins = [];
51 } else {
52 $imageTables = [ 'file', 'filerevision' ];
53 $nameField = 'file_name';
54 $timestampField = 'fr_timestamp';
55 $fileConds = [ 'file_deleted' => 0 ];
56 $fileJoins = [ 'filerevision' => [ 'JOIN', 'file_latest = fr_id' ] ];
57 }
58
59 $retval = [
60 'tables' => [ ...$imageTables, 'linktarget', 'imagelinks' ],
61 'fields' => [
62 'namespace' => NS_FILE,
63 'title' => $nameField,
64 'value' => $timestampField,
65 ],
66 'conds' => [
67 'il_target_id' => null,
68 ...$fileConds
69 ],
70 'join_conds' => [
71 ...$fileJoins,
72 'linktarget' => [ 'LEFT JOIN', [ 'lt_title = ' . $nameField, 'lt_namespace' => NS_FILE ] ],
73 'imagelinks' => [ 'LEFT JOIN', 'il_target_id = lt_id' ]
74 ],
75 ];
76
78 // Order is significant
79 $retval['tables'] = [ ...$imageTables, 'page', 'categorylinks', 'linktarget', 'imagelinks' ];
80 $retval['conds']['page_namespace'] = NS_FILE;
81 $retval['conds']['cl_from'] = null;
82 $retval['join_conds']['page'] = [ 'JOIN', $nameField . ' = page_title' ];
83 $retval['join_conds']['categorylinks'] = [ 'LEFT JOIN', 'cl_from = page_id' ];
84 }
85
86 return $retval;
87 }
88
90 public function usesTimestamps() {
91 return true;
92 }
93
95 protected function getPageHeader() {
97 return $this->msg(
98 'unusedimagestext-categorizedimgisused'
99 )->parseAsBlock();
100 }
101 return $this->msg( 'unusedimagestext' )->parseAsBlock();
102 }
103
105 protected function getGroupName() {
106 return 'maintenance';
107 }
108}
109
114class_alias( SpecialUnusedImages::class, 'SpecialUnusedImages' );
const NS_FILE
Definition Defines.php:57
const SCHEMA_COMPAT_READ_OLD
Definition Defines.php:294
A class containing constants representing the names of configuration variables.
const CountCategorizedImagesAsUsed
Name constant for the CountCategorizedImagesAsUsed setting, for use with Config::get()
const FileSchemaMigrationStage
Name constant for the FileSchemaMigrationStage setting, for use with Config::get()
Variant of QueryPage which uses a gallery to output results, thus suited for reports generating image...
setDatabaseProvider(IConnectionProvider $databaseProvider)
getConfig()
Shortcut to get main config object.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
isSyndicated()
Sometimes we don't want to build rss / atom feeds.to override bool
getPageHeader()
The content returned by this function will be output before any result.to override string
isExpensive()
Should this query page only be updated offline on large wikis?If the query for this page is considere...
usesTimestamps()
Does this query return timestamps rather than integers in its 'value' field? If true,...
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
__construct(IConnectionProvider $dbProvider)
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
sortDescending()
Override to sort by increasing values.to override bool
Provide primary and replica IDatabase connections.