64 private MimeAnalyzer $mimeAnalyzer;
72 MimeAnalyzer $mimeAnalyzer,
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 )
196 Html::closeElement(
'tbody' ) .
197 Html::closeElement(
'table' )
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 ) )
221 $row = Html::rawElement(
224 $linkRenderer->makeLink( $mimeSearch, $mime )
226 $row .= Html::rawElement(
229 $this->getExtensionList( $mime )
231 $row .= Html::rawElement(
234 [
'data-sort-value' => $count ],
235 $this->
msg(
'mediastatistics-nfiles' )
236 ->numParams( $count )
241 $row .= Html::rawElement(
244 [
'data-sort-value' => $bytes ],
245 $this->
msg(
'mediastatistics-nbytes' )
246 ->numParams( $bytes )
247 ->sizeParams( $bytes )
252 $this->totalPerType += $bytes;
253 $this->countPerType += $count;
254 $this->
getOutput()->addHTML( Html::rawElement(
'tr', [], $row ) );
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 ),
314 Html::openElement(
'tbody' )
324 $headers = [
'mimetype',
'extensions',
'count',
'totalbytes' ];
326 foreach ( $headers as
$header ) {
327 $ths .= Html::rawElement(
333 $this->
msg(
'mediastatistics-table-' . $header )->parse()
336 return Html::rawElement(
'tr', [], $ths );
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 );
398 $this->totalCount = $this->totalBytes = 0;
399 foreach ( $res as $row ) {
400 $mediaStats = $this->splitFakeTitle( $row->title );
401 $this->totalCount += $mediaStats[2] ?? 0;
402 $this->totalBytes += $mediaStats[3] ?? 0;
412class_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.