MediaWiki master
SpecialUnusedImages.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
27
34 private int $migrationStage;
35
36 public function __construct( IConnectionProvider $dbProvider ) {
37 parent::__construct( 'Unusedimages' );
38 $this->setDatabaseProvider( $dbProvider );
39 $this->migrationStage = MediaWikiServices::getInstance()->getMainConfig()->get(
41 );
42 }
43
44 public function isExpensive() {
45 return true;
46 }
47
48 protected function sortDescending() {
49 return false;
50 }
51
52 public function isSyndicated() {
53 return false;
54 }
55
56 public function getQueryInfo() {
57 if ( $this->migrationStage & SCHEMA_COMPAT_READ_OLD ) {
58 $tables = [ 'image' ];
59 $nameField = 'img_name';
60 $timestampField = 'img_timestamp';
61 $extraConds = [];
62 $extraJoins = [];
63 } else {
64 $tables = [ 'file', 'filerevision' ];
65 $nameField = 'file_name';
66 $timestampField = 'fr_timestamp';
67 $extraConds = [ 'file_deleted' => 0 ];
68 $extraJoins = [ 'filerevision' => [ 'JOIN', 'file_latest = fr_id' ] ];
69 }
70
71 $retval = [
72 'tables' => array_merge( $tables, [ 'imagelinks' ] ),
73 'fields' => [
74 'namespace' => NS_FILE,
75 'title' => $nameField,
76 'value' => $timestampField,
77 ],
78 'conds' => array_merge( [ 'il_to' => null ], $extraConds ),
79 'join_conds' => array_merge(
80 [ 'imagelinks' => [ 'LEFT JOIN', 'il_to = ' . $nameField ] ],
81 $extraJoins
82 ),
83 ];
84
86 // Order is significant
87 $retval['tables'] = [ 'image', 'page', 'categorylinks',
88 'imagelinks' ];
89 $retval['conds']['page_namespace'] = NS_FILE;
90 $retval['conds']['cl_from'] = null;
91 $retval['conds'][] = $nameField . ' = page_title';
92 $retval['join_conds']['categorylinks'] = [
93 'LEFT JOIN', 'cl_from = page_id' ];
94 $retval['join_conds']['imagelinks'] = [
95 'LEFT JOIN', 'il_to = page_title' ];
96 }
97
98 return $retval;
99 }
100
101 public function usesTimestamps() {
102 return true;
103 }
104
105 protected function getPageHeader() {
107 return $this->msg(
108 'unusedimagestext-categorizedimgisused'
109 )->parseAsBlock();
110 }
111 return $this->msg( 'unusedimagestext' )->parseAsBlock();
112 }
113
114 protected function getGroupName() {
115 return 'maintenance';
116 }
117}
118
123class_alias( SpecialUnusedImages::class, 'SpecialUnusedImages' );
const NS_FILE
Definition Defines.php:71
const SCHEMA_COMPAT_READ_OLD
Definition Defines.php:304
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()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
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.
getPageHeader()
The content returned by this function will be output before any result.
isExpensive()
Should this query page only be updated offline on large wikis?
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.
Provide primary and replica IDatabase connections.