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,
148 'filetypes' => [
'JOIN',
'file_type = ft_id' ],
149 'filerevision' => [
'JOIN',
'file_latest = fr_id' ]
164 return [
'img_media_type',
'count(*)',
'img_major_mime',
'img_minor_mime' ];
166 return [
'ft_media_type',
'count(*)',
'ft_major_mime',
'ft_minor_mime' ];
181 $prevMediaType =
null;
182 foreach ( $res as $row ) {
183 $mediaStats = $this->splitFakeTitle( $row->title );
184 if ( count( $mediaStats ) < 4 ) {
188 if ( $prevMediaType !== $mediaType ) {
189 if ( $prevMediaType !==
null ) {
195 $this->totalPerType = 0;
196 $this->countPerType = 0;
198 $prevMediaType = $mediaType;
202 if ( $prevMediaType !==
null ) {
206 $this->
getOutput()->addWikiTextAsInterface(
207 $this->
msg(
'mediastatistics-allbytes' )
208 ->numParams( $this->totalSize )
209 ->sizeParams( $this->totalSize )
210 ->numParams( $this->totalCount )
221 Html::closeElement(
'tbody' ) .
222 Html::closeElement(
'table' )
224 $this->
getOutput()->addWikiTextAsInterface(
225 $this->
msg(
'mediastatistics-bytespertype' )
226 ->numParams( $this->totalPerType )
227 ->sizeParams( $this->totalPerType )
228 ->numParams( $this->
makePercentPretty( $this->totalPerType / $this->totalBytes ) )
229 ->numParams( $this->countPerType )
230 ->numParams( $this->
makePercentPretty( $this->countPerType / $this->totalCount ) )
246 $row = Html::rawElement(
249 $linkRenderer->makeLink( $mimeSearch, $mime )
251 $row .= Html::rawElement(
254 $this->getExtensionList( $mime )
256 $row .= Html::rawElement(
259 [
'data-sort-value' => $count ],
260 $this->
msg(
'mediastatistics-nfiles' )
261 ->numParams( $count )
266 $row .= Html::rawElement(
269 [
'data-sort-value' => $bytes ],
270 $this->
msg(
'mediastatistics-nbytes' )
271 ->numParams( $bytes )
272 ->sizeParams( $bytes )
277 $this->totalPerType += $bytes;
278 $this->countPerType += $count;
279 $this->
getOutput()->addHTML( Html::rawElement(
'tr', [], $row ) );
289 if ( $decimal == 0 ) {
292 if ( $decimal >= 100 ) {
295 $percent = sprintf(
"%." . max( 0, 2 - floor( log10( $decimal ) ) ) .
"f", $decimal );
297 return preg_replace(
'/\.?0*$/',
'', $percent );
306 private function getExtensionList( $mime ) {
307 $exts = $this->mimeAnalyzer->getExtensionsFromMimeType( $mime );
311 foreach ( $exts as &$ext ) {
312 $ext = htmlspecialchars(
'.' . $ext );
326 $out->addModuleStyles(
'jquery.tablesorter.styles' );
327 $out->addModules(
'jquery.tablesorter' );
332 'mw-mediastats-table',
333 'mw-mediastats-table-' . strtolower( $mediaType ),
339 Html::openElement(
'tbody' )
349 $headers = [
'mimetype',
'extensions',
'count',
'totalbytes' ];
351 foreach ( $headers as $header ) {
352 $ths .= Html::rawElement(
358 $this->
msg(
'mediastatistics-table-' . $header )->parse()
361 return Html::rawElement(
'tr', [], $ths );
374 'id' => Sanitizer::escapeIdForAttribute(
375 'mw-mediastats-mediatype-' . strtolower( $mediaType )
378 'mw-mediastats-mediatype',
379 'mw-mediastats-mediatype-' . strtolower( $mediaType )
389 $this->
msg(
'mediastatistics-header-' . strtolower( $mediaType ) )->text()
403 private function splitFakeTitle( $fakeTitle ) {
404 return explode(
';', $fakeTitle, 4 );
428 $this->totalCount = $this->totalBytes = 0;
429 foreach ( $res as $row ) {
430 $mediaStats = $this->splitFakeTitle( $row->title );
431 $this->totalCount += $mediaStats[2] ?? 0;
432 $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.