MediaWiki master
SpecialUnusedImages.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Specials;
8
13
20 private int $migrationStage;
21
22 public function __construct( IConnectionProvider $dbProvider ) {
23 parent::__construct( 'Unusedimages' );
24 $this->setDatabaseProvider( $dbProvider );
25 $this->migrationStage = MediaWikiServices::getInstance()->getMainConfig()->get(
27 );
28 }
29
31 public function isExpensive() {
32 return true;
33 }
34
36 protected function sortDescending() {
37 return false;
38 }
39
41 public function isSyndicated() {
42 return false;
43 }
44
46 public function getQueryInfo() {
47 if ( $this->migrationStage & SCHEMA_COMPAT_READ_OLD ) {
48 $tables = [ 'image' ];
49 $nameField = 'img_name';
50 $timestampField = 'img_timestamp';
51 $extraConds = [];
52 $extraJoins = [];
53 } else {
54 $tables = [ 'file', 'filerevision' ];
55 $nameField = 'file_name';
56 $timestampField = 'fr_timestamp';
57 $extraConds = [ 'file_deleted' => 0 ];
58 $extraJoins = [ 'filerevision' => [ 'JOIN', 'file_latest = fr_id' ] ];
59 }
60
61 $retval = [
62 'tables' => array_merge( $tables, [ 'imagelinks' ] ),
63 'fields' => [
64 'namespace' => NS_FILE,
65 'title' => $nameField,
66 'value' => $timestampField,
67 ],
68 'conds' => array_merge( [ 'il_to' => null ], $extraConds ),
69 'join_conds' => array_merge(
70 [ 'imagelinks' => [ 'LEFT JOIN', 'il_to = ' . $nameField ] ],
71 $extraJoins
72 ),
73 ];
74
76 // Order is significant
77 $retval['tables'] = [ 'image', 'page', 'categorylinks',
78 'imagelinks' ];
79 $retval['conds']['page_namespace'] = NS_FILE;
80 $retval['conds']['cl_from'] = null;
81 $retval['conds'][] = $nameField . ' = page_title';
82 $retval['join_conds']['categorylinks'] = [
83 'LEFT JOIN', 'cl_from = page_id' ];
84 $retval['join_conds']['imagelinks'] = [
85 'LEFT JOIN', 'il_to = page_title' ];
86 }
87
88 return $retval;
89 }
90
92 public function usesTimestamps() {
93 return true;
94 }
95
97 protected function getPageHeader() {
99 return $this->msg(
100 'unusedimagestext-categorizedimgisused'
101 )->parseAsBlock();
102 }
103 return $this->msg( 'unusedimagestext' )->parseAsBlock();
104 }
105
107 protected function getGroupName() {
108 return 'maintenance';
109 }
110}
111
116class_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()
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.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.