62 private MimeAnalyzer $mimeAnalyzer;
70 MimeAnalyzer $mimeAnalyzer,
74 parent::__construct(
'MediaStatistics' );
78 $this->shownavigation =
false;
79 $this->mimeAnalyzer = $mimeAnalyzer;
104 $fakeTitle = $dbr->buildConcat( [
106 $dbr->addQuotes(
';' ),
108 $dbr->addQuotes(
'/' ),
110 $dbr->addQuotes(
';' ),
111 $dbr->buildStringCast(
'COUNT(*)' ),
112 $dbr->addQuotes(
';' ),
113 $dbr->buildStringCast(
'SUM( img_size )' )
116 'tables' => [
'image' ],
118 'title' => $fakeTitle,
140 return [
'img_media_type',
'count(*)',
'img_major_mime',
'img_minor_mime' ];
154 $prevMediaType =
null;
155 foreach ( $res as $row ) {
156 $mediaStats = $this->splitFakeTitle( $row->title );
157 if ( count( $mediaStats ) < 4 ) {
161 if ( $prevMediaType !== $mediaType ) {
162 if ( $prevMediaType !==
null ) {
168 $this->totalPerType = 0;
169 $this->countPerType = 0;
171 $prevMediaType = $mediaType;
175 if ( $prevMediaType !==
null ) {
179 $this->
getOutput()->addWikiTextAsInterface(
180 $this->
msg(
'mediastatistics-allbytes' )
181 ->numParams( $this->totalSize )
182 ->sizeParams( $this->totalSize )
183 ->numParams( $this->totalCount )
194 Html::closeElement(
'tbody' ) .
195 Html::closeElement(
'table' )
197 $this->
getOutput()->addWikiTextAsInterface(
198 $this->
msg(
'mediastatistics-bytespertype' )
199 ->numParams( $this->totalPerType )
200 ->sizeParams( $this->totalPerType )
201 ->numParams( $this->
makePercentPretty( $this->totalPerType / $this->totalBytes ) )
202 ->numParams( $this->countPerType )
203 ->numParams( $this->
makePercentPretty( $this->countPerType / $this->totalCount ) )
219 $row = Html::rawElement(
222 $linkRenderer->makeLink( $mimeSearch, $mime )
224 $row .= Html::rawElement(
227 $this->getExtensionList( $mime )
229 $row .= Html::rawElement(
232 [
'data-sort-value' => $count ],
233 $this->
msg(
'mediastatistics-nfiles' )
234 ->numParams( $count )
239 $row .= Html::rawElement(
242 [
'data-sort-value' => $bytes ],
243 $this->
msg(
'mediastatistics-nbytes' )
244 ->numParams( $bytes )
245 ->sizeParams( $bytes )
250 $this->totalPerType += $bytes;
251 $this->countPerType += $count;
252 $this->
getOutput()->addHTML( Html::rawElement(
'tr', [], $row ) );
262 if ( $decimal == 0 ) {
265 if ( $decimal >= 100 ) {
268 $percent = sprintf(
"%." . max( 0, 2 - floor( log10( $decimal ) ) ) .
"f", $decimal );
270 return preg_replace(
'/\.?0*$/',
'', $percent );
279 private function getExtensionList( $mime ) {
280 $exts = $this->mimeAnalyzer->getExtensionsFromMimeType( $mime );
284 foreach ( $exts as &$ext ) {
285 $ext = htmlspecialchars(
'.' . $ext );
299 $out->addModuleStyles(
'jquery.tablesorter.styles' );
300 $out->addModules(
'jquery.tablesorter' );
305 'mw-mediastats-table',
306 'mw-mediastats-table-' . strtolower( $mediaType ),
312 Html::openElement(
'tbody' )
322 $headers = [
'mimetype',
'extensions',
'count',
'totalbytes' ];
324 foreach ( $headers as
$header ) {
325 $ths .= Html::rawElement(
331 $this->
msg(
'mediastatistics-table-' . $header )->parse()
334 return Html::rawElement(
'tr', [], $ths );
347 'mw-mediastats-mediatype',
348 'mw-mediastats-mediatype-' . strtolower( $mediaType )
357 $this->
msg(
'mediastatistics-header-' . strtolower( $mediaType ) )->text()
371 private function splitFakeTitle( $fakeTitle ) {
372 return explode(
';', $fakeTitle, 4 );
396 $this->totalCount = $this->totalBytes = 0;
397 foreach ( $res as $row ) {
398 $mediaStats = $this->splitFakeTitle( $row->title );
399 $this->totalCount += $mediaStats[2] ?? 0;
400 $this->totalBytes += $mediaStats[3] ?? 0;
410class_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.
The base class for all skins.