Page MenuHomePhabricator

Special:MediaStatistics doesn't have anchor tags for its headings
Open, Needs TriagePublicBUG REPORT

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.