18use Wikimedia\Mime\MimeAnalyzer;
51 private readonly
int $migrationStage;
54 private readonly MimeAnalyzer $mimeAnalyzer,
58 parent::__construct(
'MediaStatistics' );
62 $this->shownavigation =
false;
92 $fakeTitle = $dbr->buildConcat( [
94 $dbr->addQuotes(
';' ),
96 $dbr->addQuotes(
'/' ),
98 $dbr->addQuotes(
';' ),
99 $dbr->buildStringCast(
'COUNT(*)' ),
100 $dbr->addQuotes(
';' ),
101 $dbr->buildStringCast(
'SUM( img_size )' )
104 'tables' => [
'image' ],
106 'title' => $fakeTitle,
119 $fakeTitle = $dbr->buildConcat( [
121 $dbr->addQuotes(
';' ),
123 $dbr->addQuotes(
'/' ),
125 $dbr->addQuotes(
';' ),
126 $dbr->buildStringCast(
'COUNT(*)' ),
127 $dbr->addQuotes(
';' ),
128 $dbr->buildStringCast(
'SUM( fr_size )' )
131 'tables' => [
'file',
'filetypes',
'filerevision' ],
133 'title' => $fakeTitle,
149 'filetypes' => [
'JOIN',
'file_type = ft_id' ],
150 'filerevision' => [
'JOIN',
'file_latest = fr_id' ]
165 return [
'img_media_type',
'count(*)',
'img_major_mime',
'img_minor_mime' ];
167 return [
'file_type',
'count(*)',
'ft_media_type',
'ft_major_mime',
'ft_minor_mime' ];
182 $prevMediaType =
null;
183 foreach ( $res as $row ) {
184 $mediaStats = $this->splitFakeTitle( $row->title );
185 if ( count( $mediaStats ) < 4 ) {
189 if ( $prevMediaType !== $mediaType ) {
190 if ( $prevMediaType !==
null ) {
196 $this->totalPerType = 0;
197 $this->countPerType = 0;
199 $prevMediaType = $mediaType;
203 if ( $prevMediaType !==
null ) {
207 $this->
getOutput()->addWikiTextAsInterface(
208 $this->
msg(
'mediastatistics-allbytes' )
209 ->numParams( $this->totalSize )
210 ->sizeParams( $this->totalSize )
211 ->numParams( $this->totalCount )
222 Html::closeElement(
'tbody' ) .
223 Html::closeElement(
'table' )
225 $this->
getOutput()->addWikiTextAsInterface(
226 $this->
msg(
'mediastatistics-bytespertype' )
227 ->numParams( $this->totalPerType )
228 ->sizeParams( $this->totalPerType )
229 ->numParams( $this->
makePercentPretty( $this->totalPerType / $this->totalBytes ) )
230 ->numParams( $this->countPerType )
231 ->numParams( $this->
makePercentPretty( $this->countPerType / $this->totalCount ) )
247 $row = Html::rawElement(
250 $linkRenderer->makeLink( $mimeSearch, $mime )
252 $row .= Html::rawElement(
255 $this->getExtensionList( $mime )
257 $row .= Html::rawElement(
260 [
'data-sort-value' => $count ],
261 $this->
msg(
'mediastatistics-nfiles' )
262 ->numParams( $count )
267 $row .= Html::rawElement(
270 [
'data-sort-value' => $bytes ],
271 $this->
msg(
'mediastatistics-nbytes' )
272 ->numParams( $bytes )
273 ->sizeParams( $bytes )
278 $this->totalPerType += $bytes;
279 $this->countPerType += $count;
280 $this->
getOutput()->addHTML( Html::rawElement(
'tr', [], $row ) );
290 if ( $decimal == 0 ) {
293 if ( $decimal >= 100 ) {
296 $percent = sprintf(
"%." . max( 0, 2 - floor( log10( $decimal ) ) ) .
"f", $decimal );
298 return preg_replace(
'/\.?0*$/',
'', $percent );
307 private function getExtensionList( $mime ) {
308 $exts = $this->mimeAnalyzer->getExtensionsFromMimeType( $mime );
312 foreach ( $exts as &$ext ) {
313 $ext = htmlspecialchars(
'.' . $ext );
327 $out->addModuleStyles(
'jquery.tablesorter.styles' );
328 $out->addModules(
'jquery.tablesorter' );
333 'mw-mediastats-table',
334 'mw-mediastats-table-' . strtolower( $mediaType ),
340 Html::openElement(
'tbody' )
350 $headers = [
'mimetype',
'extensions',
'count',
'totalbytes' ];
352 foreach ( $headers as $header ) {
353 $ths .= Html::rawElement(
359 $this->
msg(
'mediastatistics-table-' . $header )->parse()
362 return Html::rawElement(
'tr', [], $ths );
375 'id' => Sanitizer::escapeIdForAttribute(
376 'mw-mediastats-mediatype-' . strtolower( $mediaType )
379 'mw-mediastats-mediatype',
380 'mw-mediastats-mediatype-' . strtolower( $mediaType )
390 $this->
msg(
'mediastatistics-header-' . strtolower( $mediaType ) )->text()
404 private function splitFakeTitle( $fakeTitle ) {
405 return explode(
';', $fakeTitle, 4 );
429 $this->totalCount = $this->totalBytes = 0;
430 foreach ( $res as $row ) {
431 $mediaStats = $this->splitFakeTitle( $row->title );
432 $this->totalCount += $mediaStats[2] ?? 0;
433 $this->totalBytes += $mediaStats[3] ?? 0;
443class_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.
Factory for LinkBatch objects to batch query page metadata.
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.