56 private $mimeAnalyzer;
64 MimeAnalyzer $mimeAnalyzer,
68 parent::__construct(
'MediaStatistics' );
72 $this->shownavigation =
false;
73 $this->mimeAnalyzer = $mimeAnalyzer;
98 $fakeTitle =
$dbr->buildConcat( [
100 $dbr->addQuotes(
';' ),
102 $dbr->addQuotes(
'/' ),
104 $dbr->addQuotes(
';' ),
105 $dbr->buildStringCast(
'COUNT(*)' ),
106 $dbr->addQuotes(
';' ),
107 $dbr->buildStringCast(
'SUM( img_size )' )
110 'tables' => [
'image' ],
112 'title' => $fakeTitle,
134 return [
'img_media_type',
'count(*)',
'img_major_mime',
'img_minor_mime' ];
148 $prevMediaType =
null;
149 foreach (
$res as $row ) {
150 $mediaStats = $this->splitFakeTitle( $row->title );
151 if ( count( $mediaStats ) < 4 ) {
155 if ( $prevMediaType !== $mediaType ) {
156 if ( $prevMediaType !==
null ) {
162 $this->totalPerType = 0;
163 $this->countPerType = 0;
165 $prevMediaType = $mediaType;
169 if ( $prevMediaType !==
null ) {
173 $this->
getOutput()->addWikiTextAsInterface(
174 $this->
msg(
'mediastatistics-allbytes' )
175 ->numParams( $this->totalSize )
176 ->sizeParams( $this->totalSize )
177 ->numParams( $this->totalCount )
188 Html::closeElement(
'tbody' ) .
189 Html::closeElement(
'table' )
191 $this->
getOutput()->addWikiTextAsInterface(
192 $this->
msg(
'mediastatistics-bytespertype' )
193 ->numParams( $this->totalPerType )
194 ->sizeParams( $this->totalPerType )
195 ->numParams( $this->
makePercentPretty( $this->totalPerType / $this->totalBytes ) )
196 ->numParams( $this->countPerType )
197 ->numParams( $this->
makePercentPretty( $this->countPerType / $this->totalCount ) )
213 $row = Html::rawElement(
216 $linkRenderer->makeLink( $mimeSearch,
$mime )
218 $row .= Html::rawElement(
221 $this->getExtensionList(
$mime )
223 $row .= Html::rawElement(
226 [
'data-sort-value' => $count ],
227 $this->
msg(
'mediastatistics-nfiles' )
228 ->numParams( $count )
233 $row .= Html::rawElement(
236 [
'data-sort-value' => $bytes ],
237 $this->
msg(
'mediastatistics-nbytes' )
238 ->numParams( $bytes )
239 ->sizeParams( $bytes )
244 $this->totalPerType += $bytes;
245 $this->countPerType += $count;
246 $this->
getOutput()->addHTML( Html::rawElement(
'tr', [], $row ) );
256 if ( $decimal == 0 ) {
259 if ( $decimal >= 100 ) {
262 $percent = sprintf(
"%." . max( 0, 2 - floor( log10( $decimal ) ) ) .
"f", $decimal );
264 return preg_replace(
'/\.?0*$/',
'', $percent );
273 private function getExtensionList(
$mime ) {
274 $exts = $this->mimeAnalyzer->getExtensionsFromMimeType(
$mime );
278 foreach ( $exts as &
$ext ) {
279 $ext = htmlspecialchars(
'.' .
$ext );
293 $out->addModuleStyles(
'jquery.tablesorter.styles' );
294 $out->addModules(
'jquery.tablesorter' );
299 'mw-mediastats-table',
300 'mw-mediastats-table-' . strtolower( $mediaType ),
306 Html::openElement(
'tbody' )
316 $headers = [
'mimetype',
'extensions',
'count',
'totalbytes' ];
318 foreach ( $headers as
$header ) {
319 $ths .= Html::rawElement(
325 $this->
msg(
'mediastatistics-table-' . $header )->parse()
328 return Html::rawElement(
'tr', [], $ths );
341 'mw-mediastats-mediatype',
342 'mw-mediastats-mediatype-' . strtolower( $mediaType )
351 $this->
msg(
'mediastatistics-header-' . strtolower( $mediaType ) )->text()
365 private function splitFakeTitle( $fakeTitle ) {
366 return explode(
';', $fakeTitle, 4 );
387 throw new LogicException(
"unimplemented" );
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