55 private $mimeAnalyzer;
63 MimeAnalyzer $mimeAnalyzer,
67 parent::__construct(
'MediaStatistics' );
71 $this->shownavigation =
false;
72 $this->mimeAnalyzer = $mimeAnalyzer;
97 $fakeTitle =
$dbr->buildConcat( [
99 $dbr->addQuotes(
';' ),
101 $dbr->addQuotes(
'/' ),
103 $dbr->addQuotes(
';' ),
104 $dbr->buildStringCast(
'COUNT(*)' ),
105 $dbr->addQuotes(
';' ),
106 $dbr->buildStringCast(
'SUM( img_size )' )
109 'tables' => [
'image' ],
111 'title' => $fakeTitle,
133 return [
'img_media_type',
'count(*)',
'img_major_mime',
'img_minor_mime' ];
147 $prevMediaType =
null;
148 foreach (
$res as $row ) {
149 $mediaStats = $this->splitFakeTitle( $row->title );
150 if ( count( $mediaStats ) < 4 ) {
154 if ( $prevMediaType !== $mediaType ) {
155 if ( $prevMediaType !==
null ) {
161 $this->totalPerType = 0;
162 $this->countPerType = 0;
164 $prevMediaType = $mediaType;
168 if ( $prevMediaType !==
null ) {
172 $this->
getOutput()->addWikiTextAsInterface(
173 $this->
msg(
'mediastatistics-allbytes' )
174 ->numParams( $this->totalSize )
175 ->sizeParams( $this->totalSize )
176 ->numParams( $this->totalCount )
187 Html::closeElement(
'tbody' ) .
188 Html::closeElement(
'table' )
190 $this->
getOutput()->addWikiTextAsInterface(
191 $this->
msg(
'mediastatistics-bytespertype' )
192 ->numParams( $this->totalPerType )
193 ->sizeParams( $this->totalPerType )
194 ->numParams( $this->
makePercentPretty( $this->totalPerType / $this->totalBytes ) )
195 ->numParams( $this->countPerType )
196 ->numParams( $this->
makePercentPretty( $this->countPerType / $this->totalCount ) )
212 $row = Html::rawElement(
215 $linkRenderer->makeLink( $mimeSearch,
$mime )
217 $row .= Html::rawElement(
220 $this->getExtensionList(
$mime )
222 $row .= Html::rawElement(
225 [
'data-sort-value' => $count ],
226 $this->
msg(
'mediastatistics-nfiles' )
227 ->numParams( $count )
232 $row .= Html::rawElement(
235 [
'data-sort-value' => $bytes ],
236 $this->
msg(
'mediastatistics-nbytes' )
237 ->numParams( $bytes )
238 ->sizeParams( $bytes )
243 $this->totalPerType += $bytes;
244 $this->countPerType += $count;
245 $this->
getOutput()->addHTML( Html::rawElement(
'tr', [], $row ) );
255 if ( $decimal == 0 ) {
258 if ( $decimal >= 100 ) {
261 $percent = sprintf(
"%." . max( 0, 2 - floor( log10( $decimal ) ) ) .
"f", $decimal );
263 return preg_replace(
'/\.?0*$/',
'', $percent );
272 private function getExtensionList(
$mime ) {
273 $exts = $this->mimeAnalyzer->getExtensionsFromMimeType(
$mime );
277 foreach ( $exts as &
$ext ) {
278 $ext = htmlspecialchars(
'.' .
$ext );
292 $out->addModuleStyles(
'jquery.tablesorter.styles' );
293 $out->addModules(
'jquery.tablesorter' );
298 'mw-mediastats-table',
299 'mw-mediastats-table-' . strtolower( $mediaType ),
305 Html::openElement(
'tbody' )
315 $headers = [
'mimetype',
'extensions',
'count',
'totalbytes' ];
317 foreach ( $headers as
$header ) {
318 $ths .= Html::rawElement(
324 $this->
msg(
'mediastatistics-table-' . $header )->parse()
327 return Html::rawElement(
'tr', [], $ths );
340 'mw-mediastats-mediatype',
341 'mw-mediastats-mediatype-' . strtolower( $mediaType )
350 $this->
msg(
'mediastatistics-header-' . strtolower( $mediaType ) )->text()
364 private function splitFakeTitle( $fakeTitle ) {
365 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;
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
setDBLoadBalancer(ILoadBalancer $loadBalancer)
int $offset
The offset and limit in use, as passed to the query() function.
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
getOutput()
Get the OutputPage being used for this instance.
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.
getLanguage()
Shortcut to get user's language.
if(!is_readable( $file)) $ext