9use MediaWiki\Cache\LinkBatchFactory;
17use Wikimedia\Mime\MimeAnalyzer;
50 private MimeAnalyzer $mimeAnalyzer;
51 private int $migrationStage;
54 MimeAnalyzer $mimeAnalyzer,
56 LinkBatchFactory $linkBatchFactory
58 parent::__construct(
'MediaStatistics' );
62 $this->shownavigation =
false;
63 $this->mimeAnalyzer = $mimeAnalyzer;
93 $fakeTitle = $dbr->buildConcat( [
95 $dbr->addQuotes(
';' ),
97 $dbr->addQuotes(
'/' ),
99 $dbr->addQuotes(
';' ),
100 $dbr->buildStringCast(
'COUNT(*)' ),
101 $dbr->addQuotes(
';' ),
102 $dbr->buildStringCast(
'SUM( img_size )' )
105 'tables' => [
'image' ],
107 'title' => $fakeTitle,
120 $fakeTitle = $dbr->buildConcat( [
122 $dbr->addQuotes(
';' ),
124 $dbr->addQuotes(
'/' ),
126 $dbr->addQuotes(
';' ),
127 $dbr->buildStringCast(
'COUNT(*)' ),
128 $dbr->addQuotes(
';' ),
129 $dbr->buildStringCast(
'SUM( fr_size )' )
132 'tables' => [
'file',
'filetypes',
'filerevision' ],
134 'title' => $fakeTitle,
150 'filetypes' => [
'JOIN',
'file_type = ft_id' ],
151 'filerevision' => [
'JOIN',
'file_latest = fr_id' ]
166 return [
'img_media_type',
'count(*)',
'img_major_mime',
'img_minor_mime' ];
168 return [
'file_type',
'count(*)',
'ft_media_type',
'ft_major_mime',
'ft_minor_mime' ];
183 $prevMediaType =
null;
184 foreach ( $res as $row ) {
185 $mediaStats = $this->splitFakeTitle( $row->title );
186 if ( count( $mediaStats ) < 4 ) {
190 if ( $prevMediaType !== $mediaType ) {
191 if ( $prevMediaType !==
null ) {
197 $this->totalPerType = 0;
198 $this->countPerType = 0;
200 $prevMediaType = $mediaType;
204 if ( $prevMediaType !==
null ) {
208 $this->
getOutput()->addWikiTextAsInterface(
209 $this->
msg(
'mediastatistics-allbytes' )
210 ->numParams( $this->totalSize )
211 ->sizeParams( $this->totalSize )
212 ->numParams( $this->totalCount )
223 Html::closeElement(
'tbody' ) .
224 Html::closeElement(
'table' )
226 $this->
getOutput()->addWikiTextAsInterface(
227 $this->
msg(
'mediastatistics-bytespertype' )
228 ->numParams( $this->totalPerType )
229 ->sizeParams( $this->totalPerType )
230 ->numParams( $this->
makePercentPretty( $this->totalPerType / $this->totalBytes ) )
231 ->numParams( $this->countPerType )
232 ->numParams( $this->
makePercentPretty( $this->countPerType / $this->totalCount ) )
248 $row = Html::rawElement(
251 $linkRenderer->makeLink( $mimeSearch, $mime )
253 $row .= Html::rawElement(
256 $this->getExtensionList( $mime )
258 $row .= Html::rawElement(
261 [
'data-sort-value' => $count ],
262 $this->
msg(
'mediastatistics-nfiles' )
263 ->numParams( $count )
268 $row .= Html::rawElement(
271 [
'data-sort-value' => $bytes ],
272 $this->
msg(
'mediastatistics-nbytes' )
273 ->numParams( $bytes )
274 ->sizeParams( $bytes )
279 $this->totalPerType += $bytes;
280 $this->countPerType += $count;
281 $this->
getOutput()->addHTML( Html::rawElement(
'tr', [], $row ) );
291 if ( $decimal == 0 ) {
294 if ( $decimal >= 100 ) {
297 $percent = sprintf(
"%." . max( 0, 2 - floor( log10( $decimal ) ) ) .
"f", $decimal );
299 return preg_replace(
'/\.?0*$/',
'', $percent );
308 private function getExtensionList( $mime ) {
309 $exts = $this->mimeAnalyzer->getExtensionsFromMimeType( $mime );
313 foreach ( $exts as &$ext ) {
314 $ext = htmlspecialchars(
'.' . $ext );
328 $out->addModuleStyles(
'jquery.tablesorter.styles' );
329 $out->addModules(
'jquery.tablesorter' );
334 'mw-mediastats-table',
335 'mw-mediastats-table-' . strtolower( $mediaType ),
341 Html::openElement(
'tbody' )
351 $headers = [
'mimetype',
'extensions',
'count',
'totalbytes' ];
353 foreach ( $headers as $header ) {
354 $ths .= Html::rawElement(
360 $this->
msg(
'mediastatistics-table-' . $header )->parse()
363 return Html::rawElement(
'tr', [], $ths );
376 'mw-mediastats-mediatype',
377 'mw-mediastats-mediatype-' . strtolower( $mediaType )
386 $this->
msg(
'mediastatistics-header-' . strtolower( $mediaType ) )->text()
400 private function splitFakeTitle( $fakeTitle ) {
401 return explode(
';', $fakeTitle, 4 );
425 $this->totalCount = $this->totalBytes = 0;
426 foreach ( $res as $row ) {
427 $mediaStats = $this->splitFakeTitle( $row->title );
428 $this->totalCount += $mediaStats[2] ?? 0;
429 $this->totalBytes += $mediaStats[3] ?? 0;
439class_alias( SpecialMediaStatistics::class,
'SpecialMediaStatistics' );
const SCHEMA_COMPAT_READ_OLD
A class containing constants representing the names of configuration variables.
const FileSchemaMigrationStage
Name constant for the FileSchemaMigrationStage setting, for use with Config::get()
This is one of the Core classes and should be read at least once by any new developers.
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
setDatabaseProvider(IConnectionProvider $databaseProvider)
int $offset
The offset and limit in use, as passed to the query() function.
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getLanguage()
Shortcut to get user's language.