29use Wikimedia\Mime\MimeAnalyzer;
63 private MimeAnalyzer $mimeAnalyzer;
71 MimeAnalyzer $mimeAnalyzer,
75 parent::__construct(
'MediaStatistics' );
79 $this->shownavigation =
false;
80 $this->mimeAnalyzer = $mimeAnalyzer;
105 $fakeTitle = $dbr->buildConcat( [
107 $dbr->addQuotes(
';' ),
109 $dbr->addQuotes(
'/' ),
111 $dbr->addQuotes(
';' ),
112 $dbr->buildStringCast(
'COUNT(*)' ),
113 $dbr->addQuotes(
';' ),
114 $dbr->buildStringCast(
'SUM( img_size )' )
117 'tables' => [
'image' ],
119 'title' => $fakeTitle,
141 return [
'img_media_type',
'count(*)',
'img_major_mime',
'img_minor_mime' ];
155 $prevMediaType =
null;
156 foreach ( $res as $row ) {
157 $mediaStats = $this->splitFakeTitle( $row->title );
158 if ( count( $mediaStats ) < 4 ) {
162 if ( $prevMediaType !== $mediaType ) {
163 if ( $prevMediaType !==
null ) {
169 $this->totalPerType = 0;
170 $this->countPerType = 0;
172 $prevMediaType = $mediaType;
176 if ( $prevMediaType !==
null ) {
180 $this->
getOutput()->addWikiTextAsInterface(
181 $this->
msg(
'mediastatistics-allbytes' )
182 ->numParams( $this->totalSize )
183 ->sizeParams( $this->totalSize )
184 ->numParams( $this->totalCount )
195 Html::closeElement(
'tbody' ) .
196 Html::closeElement(
'table' )
198 $this->
getOutput()->addWikiTextAsInterface(
199 $this->
msg(
'mediastatistics-bytespertype' )
200 ->numParams( $this->totalPerType )
201 ->sizeParams( $this->totalPerType )
202 ->numParams( $this->
makePercentPretty( $this->totalPerType / $this->totalBytes ) )
203 ->numParams( $this->countPerType )
204 ->numParams( $this->
makePercentPretty( $this->countPerType / $this->totalCount ) )
220 $row = Html::rawElement(
223 $linkRenderer->makeLink( $mimeSearch, $mime )
225 $row .= Html::rawElement(
228 $this->getExtensionList( $mime )
230 $row .= Html::rawElement(
233 [
'data-sort-value' => $count ],
234 $this->
msg(
'mediastatistics-nfiles' )
235 ->numParams( $count )
240 $row .= Html::rawElement(
243 [
'data-sort-value' => $bytes ],
244 $this->
msg(
'mediastatistics-nbytes' )
245 ->numParams( $bytes )
246 ->sizeParams( $bytes )
251 $this->totalPerType += $bytes;
252 $this->countPerType += $count;
253 $this->
getOutput()->addHTML( Html::rawElement(
'tr', [], $row ) );
263 if ( $decimal == 0 ) {
266 if ( $decimal >= 100 ) {
269 $percent = sprintf(
"%." . max( 0, 2 - floor( log10( $decimal ) ) ) .
"f", $decimal );
271 return preg_replace(
'/\.?0*$/',
'', $percent );
280 private function getExtensionList( $mime ) {
281 $exts = $this->mimeAnalyzer->getExtensionsFromMimeType( $mime );
285 foreach ( $exts as &$ext ) {
286 $ext = htmlspecialchars(
'.' . $ext );
300 $out->addModuleStyles(
'jquery.tablesorter.styles' );
301 $out->addModules(
'jquery.tablesorter' );
306 'mw-mediastats-table',
307 'mw-mediastats-table-' . strtolower( $mediaType ),
313 Html::openElement(
'tbody' )
323 $headers = [
'mimetype',
'extensions',
'count',
'totalbytes' ];
325 foreach ( $headers as
$header ) {
326 $ths .= Html::rawElement(
332 $this->
msg(
'mediastatistics-table-' . $header )->parse()
335 return Html::rawElement(
'tr', [], $ths );
348 'mw-mediastats-mediatype',
349 'mw-mediastats-mediatype-' . strtolower( $mediaType )
358 $this->
msg(
'mediastatistics-header-' . strtolower( $mediaType ) )->text()
372 private function splitFakeTitle( $fakeTitle ) {
373 return explode(
';', $fakeTitle, 4 );
397 $this->totalCount = $this->totalBytes = 0;
398 foreach ( $res as $row ) {
399 $mediaStats = $this->splitFakeTitle( $row->title );
400 $this->totalCount += $mediaStats[2] ?? 0;
401 $this->totalBytes += $mediaStats[3] ?? 0;
411class_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.