Page MenuHomePhabricator

Special:MediaStatistics doesn't have anchor tags for its headings
Closed, ResolvedPublicBUG REPORT

Assigned To
Authored By
Bugreporter2
Jan 1 2023, 1:54 PM
Referenced Files
F76975480: image.png
Apr 21 2026, 3:36 AM
F76975457: image.png
Apr 21 2026, 3:36 AM
F76975432: image.png
Apr 21 2026, 3:36 AM
F76975415: image.png
Apr 21 2026, 3:36 AM
F76975395: image.png
Apr 21 2026, 3:36 AM

Description

Steps to replicate the issue (include links if applicable):

  • Go to [[Special:MediaStatistics]]
  • Right click and view source.
  • search for name= or id= attributes on or near <h2> headings.

What happens?:

There's no html anchor tags associated with the headings, so no table of contents can be generated, even though there are quite a few headings.

What should have happened instead?:

Headings should have html anchor tags.

Software version (skip for WMF-hosted wikis like Wikipedia): 1.35

Other information (browser name/version, screenshots, etc.):

Event Timeline

Reedy renamed this task from Special:Mediastatistics doesn't have anchor tags for its headings. to Special:MediaStatistics doesn't have anchor tags for its headings.Jan 1 2023, 8:15 PM
Reedy updated the task description. (Show Details)

Respectfully cc Bartosz because he fixed tables of contents in [[Special:Version]] and [[Special:SpecialPages]]

@Bugreporter2: A good first task is a self-contained, non-controversial task with a clear approach. It should be well-described with pointers to help a completely new contributor. Given the current short task description I'm removing the good first task tag. Please add details what exactly has to happen where and how for a new contributor, and then add back the good first task project tag. Thanks a lot in advance!

I think it is a relatively simple task. You could review my change for Special:SpecialPages: https://gerrit.wikimedia.org/r/c/mediawiki/core/+/891370/2/includes/specials/SpecialSpecialpages.php and make changes along these lines to SpecialMediaStatistics.php, adding id attributes and a table of contents.

@matmarex how can I populate my local database with existing data to test out if my fix is working or not?

Does something like this look correct to you

protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
			$tocData = new TOCData();
			$tocLength = 0;
			foreach ( $res as $row ) {
				$mediaStats = $this->splitFakeTitle( $row->title );
				if ( count( $mediaStats ) < 4 ) {
					continue;
				}
				[ $mediaType, $mime, $totalCount, $totalBytes ] = $mediaStats;
				if ( !str_contains( $mediaType, '/' ) ) {
					++$tocLength;
					$tocData->addSection( new SectionMetadata(
						1,
						2,
						$mediaType,
						$this->getLanguage()->formatNum( $tocLength ),
						(string)$tocLength,
						null,
						null,
						"mw-mediastatisticsgroup-$mediaType",
						"mw-mediastatisticsgroup-$mediaType"
					) );
				}
			}
			$pout = new \ParserOutput;
			$pout->setTOCData( $tocData );
			$pout->setOutputFlag( ParserOutputFlags::SHOW_TOC );
			$pout->setText( \Parser::TOC_PLACEHOLDER );
			$out->addParserOutput( $pout );
				foreach ( $res as $row ) {
			$mediaStats = $this->splitFakeTitle( $row->title );
			if ( count( $mediaStats ) < 4 ) {
				continue;
			}
			[ $mediaType, $mime, $totalCount, $totalBytes ] = $mediaStats;
			if ( $prevMediaType !== $mediaType ) {
				if ( $prevMediaType !== null ) {
					// We're not at beginning, so we have to
					// close the previous table.
					$this->outputTableEnd();
				}
				$this->outputMediaType( $mediaType );
				$this->totalPerType = 0;
				$this->countPerType = 0;
				$this->outputTableStart( $mediaType );
				$prevMediaType = $mediaType;
			}
			$this->outputTableRow( $mime, intval( $totalCount ), intval( $totalBytes ) );
		}
		if ( $prevMediaType !== null ) {
			$this->outputTableEnd();
			// add total size of all files
			$this->outputMediaType( 'total' );
			$this->getOutput()->addWikiTextAsInterface(
				$this->msg( 'mediastatistics-allbytes' )
					->numParams( $this->totalSize )
					->sizeParams( $this->totalSize )
					->numParams( $this->totalCount )
					->text()
			);
		}
	}

I tried to test this with mock data but I'm not sure if I structured my data correctly as it only worked when I removed the ' / ' check.

Change 1013002 had a related patch set uploaded (by Rockingpenny4; author: Rockingpenny4):

[mediawiki/core@master] Add anchor tag and table of contents

https://gerrit.wikimedia.org/r/1013002

@matmarex how can I populate my local database with existing data to test out if my fix is working or not?

The easiest way would probably be to just upload a few files of different types.

Hi! I’m a newcomer and would like to work on this task as my first contribution. Could I please be assigned?

@Somyaya: Welcome! Please first read the "New Developers" page on mediawiki.org and its Communication Tips section. Also see above that there is already a patch which needs rework. Thanks!

Suraj_Seth subscribed.

Hi, I would like to work on this. I see previous patches needed improvement; I will review them and submit a new patch.

Change #1227575 had a related patch set uploaded (by Suraj Seth; author: Suraj Seth):

[mediawiki/core@master] SpecialMediaStatistics: Add anchor tags to group headings

https://gerrit.wikimedia.org/r/1227575

Change #1227614 had a related patch set uploaded (by Suraj Seth; author: Suraj Seth):

[mediawiki/core@master] fix(SpecialMediaStatistics): correct headerText variable name typo

https://gerrit.wikimedia.org/r/1227614

Change #1227614 abandoned by Suraj Seth:

[mediawiki/core@master] Add anchor links to Special:MediaStatistics headings

https://gerrit.wikimedia.org/r/1227614

Change #1227614 restored by Suraj Seth:

[mediawiki/core@master] Add anchor links to Special:MediaStatistics headings

https://gerrit.wikimedia.org/r/1227614

Change #1227614 abandoned by Suraj Seth:

[mediawiki/core@master] Add anchor links to Special:MediaStatistics headings

https://gerrit.wikimedia.org/r/1227614

Change #1240837 had a related patch set uploaded (by Suraj Seth; author: Suraj Seth):

[mediawiki/core@master] SpecialMediaStatistics: Add anchor tags to group headings

https://gerrit.wikimedia.org/r/1240837

Pppery edited projects, added: Patch-Needs-Improvement; removed: Patch-For-Review.

Change #1227575 abandoned by Bartosz Dziewoński:

[mediawiki/core@master] SpecialMediaStatistics: Add anchor tags to group headings

Reason:

Replaced by https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1240837

https://gerrit.wikimedia.org/r/1227575

Change #1240837 merged by jenkins-bot:

[mediawiki/core@master] SpecialMediaStatistics: Add anchor tags to group headings

https://gerrit.wikimedia.org/r/1240837

matmarex assigned this task to Suraj_Seth.

Thanks @Suraj_Seth!

It'd be nice to also have a table of contents on this page, but maybe someone can start a new task for that, since this one got a bit messy.

Change #1013002 abandoned by Bartosz Dziewoński:

[mediawiki/core@master] Special:MediaStatistics - Add anchor tag and table of contents

Reason:

The task has been resolved, and it looks like you're not longer active. Feel free to restore this patch if you want to keep working on the table of contents. Thanks!

https://gerrit.wikimedia.org/r/1013002

I don't want to make this even messier, but...

There's something weird going on with https://en.wikipedia.org/wiki/Special:MediaStatistics

There are now five separate headings all saying "Bitmap images" when presumably these should be combined. Did this patch break something else or is it an unrelated issue?

image.png (1,147×806 px, 128 KB)

image.png (1,282×822 px, 133 KB)

image.png (1,097×757 px, 116 KB)

image.png (1,233×772 px, 112 KB)

image.png (1,097×846 px, 133 KB)

That's weird, but it can't be caused by this change.