31use Wikimedia\Mime\MimeAnalyzer;
65 private MimeAnalyzer $mimeAnalyzer;
66 private int $migrationStage;
69 MimeAnalyzer $mimeAnalyzer,
73 parent::__construct(
'MediaStatistics' );
77 $this->shownavigation =
false;
78 $this->mimeAnalyzer = $mimeAnalyzer;
107 $fakeTitle = $dbr->buildConcat( [
109 $dbr->addQuotes(
';' ),
111 $dbr->addQuotes(
'/' ),
113 $dbr->addQuotes(
';' ),
114 $dbr->buildStringCast(
'COUNT(*)' ),
115 $dbr->addQuotes(
';' ),
116 $dbr->buildStringCast(
'SUM( img_size )' )
119 'tables' => [
'image' ],
121 'title' => $fakeTitle,
134 $fakeTitle = $dbr->buildConcat( [
136 $dbr->addQuotes(
';' ),
138 $dbr->addQuotes(
'/' ),
140 $dbr->addQuotes(
';' ),
141 $dbr->buildStringCast(
'COUNT(*)' ),
142 $dbr->addQuotes(
';' ),
143 $dbr->buildStringCast(
'SUM( fr_size )' )
146 'tables' => [
'file',
'filetypes',
'filerevision' ],
148 'title' => $fakeTitle,
164 'filetypes' => [
'JOIN',
'file_type = ft_id' ],
165 'filerevision' => [
'JOIN',
'file_latest = fr_id' ]
180 return [
'img_media_type',
'count(*)',
'img_major_mime',
'img_minor_mime' ];
182 return [
'file_type',
'count(*)',
'ft_media_type',
'ft_major_mime',
'ft_minor_mime' ];
197 $prevMediaType =
null;
198 foreach ( $res as $row ) {
199 $mediaStats = $this->splitFakeTitle( $row->title );
200 if ( count( $mediaStats ) < 4 ) {
204 if ( $prevMediaType !== $mediaType ) {
205 if ( $prevMediaType !==
null ) {
211 $this->totalPerType = 0;
212 $this->countPerType = 0;
214 $prevMediaType = $mediaType;
218 if ( $prevMediaType !==
null ) {
222 $this->
getOutput()->addWikiTextAsInterface(
223 $this->
msg(
'mediastatistics-allbytes' )
224 ->numParams( $this->totalSize )
225 ->sizeParams( $this->totalSize )
226 ->numParams( $this->totalCount )
237 Html::closeElement(
'tbody' ) .
238 Html::closeElement(
'table' )
240 $this->
getOutput()->addWikiTextAsInterface(
241 $this->
msg(
'mediastatistics-bytespertype' )
242 ->numParams( $this->totalPerType )
243 ->sizeParams( $this->totalPerType )
244 ->numParams( $this->
makePercentPretty( $this->totalPerType / $this->totalBytes ) )
245 ->numParams( $this->countPerType )
246 ->numParams( $this->
makePercentPretty( $this->countPerType / $this->totalCount ) )
262 $row = Html::rawElement(
265 $linkRenderer->makeLink( $mimeSearch, $mime )
267 $row .= Html::rawElement(
270 $this->getExtensionList( $mime )
272 $row .= Html::rawElement(
275 [
'data-sort-value' => $count ],
276 $this->
msg(
'mediastatistics-nfiles' )
277 ->numParams( $count )
282 $row .= Html::rawElement(
285 [
'data-sort-value' => $bytes ],
286 $this->
msg(
'mediastatistics-nbytes' )
287 ->numParams( $bytes )
288 ->sizeParams( $bytes )
293 $this->totalPerType += $bytes;
294 $this->countPerType += $count;
295 $this->
getOutput()->addHTML( Html::rawElement(
'tr', [], $row ) );
305 if ( $decimal == 0 ) {
308 if ( $decimal >= 100 ) {
311 $percent = sprintf(
"%." . max( 0, 2 - floor( log10( $decimal ) ) ) .
"f", $decimal );
313 return preg_replace(
'/\.?0*$/',
'', $percent );
322 private function getExtensionList( $mime ) {
323 $exts = $this->mimeAnalyzer->getExtensionsFromMimeType( $mime );
327 foreach ( $exts as &$ext ) {
328 $ext = htmlspecialchars(
'.' . $ext );
342 $out->addModuleStyles(
'jquery.tablesorter.styles' );
343 $out->addModules(
'jquery.tablesorter' );
348 'mw-mediastats-table',
349 'mw-mediastats-table-' . strtolower( $mediaType ),
355 Html::openElement(
'tbody' )
365 $headers = [
'mimetype',
'extensions',
'count',
'totalbytes' ];
367 foreach ( $headers as $header ) {
368 $ths .= Html::rawElement(
374 $this->
msg(
'mediastatistics-table-' . $header )->parse()
377 return Html::rawElement(
'tr', [], $ths );
390 'mw-mediastats-mediatype',
391 'mw-mediastats-mediatype-' . strtolower( $mediaType )
400 $this->
msg(
'mediastatistics-header-' . strtolower( $mediaType ) )->text()
414 private function splitFakeTitle( $fakeTitle ) {
415 return explode(
';', $fakeTitle, 4 );
439 $this->totalCount = $this->totalBytes = 0;
440 foreach ( $res as $row ) {
441 $mediaStats = $this->splitFakeTitle( $row->title );
442 $this->totalCount += $mediaStats[2] ?? 0;
443 $this->totalBytes += $mediaStats[3] ?? 0;
453class_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.