25 namespace MediaWiki\Specials;
76 parent::__construct(
'MediaStatistics' );
80 $this->shownavigation =
false;
81 $this->mimeAnalyzer = $mimeAnalyzer;
106 $fakeTitle = $dbr->buildConcat( [
108 $dbr->addQuotes(
';' ),
110 $dbr->addQuotes(
'/' ),
112 $dbr->addQuotes(
';' ),
113 $dbr->buildStringCast(
'COUNT(*)' ),
114 $dbr->addQuotes(
';' ),
115 $dbr->buildStringCast(
'SUM( img_size )' )
118 'tables' => [
'image' ],
120 'title' => $fakeTitle,
142 return [
'img_media_type',
'count(*)',
'img_major_mime',
'img_minor_mime' ];
156 $prevMediaType =
null;
157 foreach ( $res as $row ) {
158 $mediaStats = $this->splitFakeTitle( $row->title );
159 if ( count( $mediaStats ) < 4 ) {
163 if ( $prevMediaType !== $mediaType ) {
164 if ( $prevMediaType !==
null ) {
170 $this->totalPerType = 0;
171 $this->countPerType = 0;
173 $prevMediaType = $mediaType;
177 if ( $prevMediaType !==
null ) {
181 $this->
getOutput()->addWikiTextAsInterface(
182 $this->
msg(
'mediastatistics-allbytes' )
183 ->numParams( $this->totalSize )
184 ->sizeParams( $this->totalSize )
185 ->numParams( $this->totalCount )
199 $this->
getOutput()->addWikiTextAsInterface(
200 $this->
msg(
'mediastatistics-bytespertype' )
201 ->numParams( $this->totalPerType )
202 ->sizeParams( $this->totalPerType )
203 ->numParams( $this->
makePercentPretty( $this->totalPerType / $this->totalBytes ) )
204 ->numParams( $this->countPerType )
205 ->numParams( $this->
makePercentPretty( $this->countPerType / $this->totalCount ) )
224 $linkRenderer->makeLink( $mimeSearch,
$mime )
229 $this->getExtensionList(
$mime )
234 [
'data-sort-value' => $count ],
235 $this->
msg(
'mediastatistics-nfiles' )
236 ->numParams( $count )
244 [
'data-sort-value' => $bytes ],
245 $this->
msg(
'mediastatistics-nbytes' )
246 ->numParams( $bytes )
247 ->sizeParams( $bytes )
252 $this->totalPerType += $bytes;
253 $this->countPerType += $count;
264 if ( $decimal == 0 ) {
267 if ( $decimal >= 100 ) {
270 $percent = sprintf(
"%." . max( 0, 2 - floor( log10( $decimal ) ) ) .
"f", $decimal );
272 return preg_replace(
'/\.?0*$/',
'', $percent );
281 private function getExtensionList(
$mime ) {
282 $exts = $this->mimeAnalyzer->getExtensionsFromMimeType(
$mime );
286 foreach ( $exts as &
$ext ) {
287 $ext = htmlspecialchars(
'.' .
$ext );
301 $out->addModuleStyles(
'jquery.tablesorter.styles' );
302 $out->addModules(
'jquery.tablesorter' );
307 'mw-mediastats-table',
308 'mw-mediastats-table-' . strtolower( $mediaType ),
324 $headers = [
'mimetype',
'extensions',
'count',
'totalbytes' ];
326 foreach ( $headers as
$header ) {
333 $this->
msg(
'mediastatistics-table-' . $header )->parse()
349 'mw-mediastats-mediatype',
350 'mw-mediastats-mediatype-' . strtolower( $mediaType )
359 $this->
msg(
'mediastatistics-header-' . strtolower( $mediaType ) )->text()
373 private function splitFakeTitle( $fakeTitle ) {
374 return explode(
';', $fakeTitle, 4 );
395 throw new LogicException(
"unimplemented" );
406 $this->totalCount = $this->totalBytes = 0;
407 foreach ( $res as $row ) {
408 $mediaStats = $this->splitFakeTitle( $row->title );
409 $this->totalCount += $mediaStats[2] ?? 0;
410 $this->totalBytes += $mediaStats[3] ?? 0;
420 class_alias( SpecialMediaStatistics::class,
'SpecialMediaStatistics' );
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.
Implements functions related to MIME types such as detection and mapping to file extension.
The base class for all skins.
if(!is_readable( $file)) $ext