Page MenuHomePhabricator

Add page properties from ParserOutput to OutputPage metadata by default
Open, Needs TriagePublic

Description

Background

The "main" ParserOutput object of a pageview is not exposed to skins or extensions via OutputPage. I believe this is because there can be more than one. Instead, this metadata is internally accumulated/collected via OutputPage::addParserOutputMetadata, and then exposed either via OutputPage itself (e.g. indicators, categories, modules, jsconfigvars) or via OutputPage::getMetadata (language links, template links, image links).

This avoids incurring database queries to link tables in skins or extensions to retreive this (and, consequently, avoids the problem of the page and the data disagreeing, e.g. due to oldid pageviews, poolcounter stale fallback, database replag, or when when page content varies by a user preference or query parameter, such as uselang or useparsoid).

Impact

"Page properties" are stored through the LinkTable component and retreived from the ParserCache in the ParserOutput object, but the mostly unused and not exposed in OutputPage.

This leads to extension developers adding database queries to retreive page properties for the current page, such as (Codesearch):

Besides those three current issues, the following are past issues that have worked around this in various ways, usually by deploying a magic monkey that manually carries the page property from ParserOutput to OutputPage via a onOutputPageParserOutput hook (Codesearch)

  • Wikibase: wikibase_item
  • Disambiguator: disambiguation
  • GeoCrumbs: geocrumb-is-in (kind of)
  • PageTriage: noindex (kind of)
  • Wikisource: disambiguation (kind of)

Goal

Extensions developers should be able to write this ...

After
	public function onBeforePageDisplay( $outputPage ): void {
		$isDisambig = $outputPage->getProperty( 'disambiguation' ) !== null;
	}

... instead of this:

Before (okay but rare)
	public function onOutputPageParserOutput( $outputPage, $parserOutput ): void {
		$isDisambig = $parserOutput->getPageProperty( 'disambiguation' );
		if ( $isDisambig !== null ) {
			$outputPage->setProperty( 'disambiguation', $isDisambig );
		}
	}

	public function onBeforePageDisplay( $outputPage ): void {
		$isDisambig = $outputPage->getProperty( 'disambiguation' ) !== null;
	}
Before (worse due to DB queries but common)
	public function onBeforePageDisplay( $outputPage ): void {
		$isDisambig = MediaWikiServices::getInstance()
			->getPageProps()
			->getProperties( $outputPage->getTitle() );
	}

Event Timeline

cscott subscribed.

See T301020: Reduce redundancy between OutputPage and ParserOutput for context. The page properties should be accessible via OutputPage::getMetadata()->getPageProperty().

Note that OutputPage::getProperty() is a different set of properties than the page properties used in ParserOutput.

Krinkle renamed this task from Add ParserOutput page properties in OutputPage metadata by default to Add page properties from ParserOutput to OutputPage metadata by default.Oct 2 2026, 4:11 PM

Change #1352326 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/core@master] OutputPage: Use ParserOutput::collectMetadata() in addParserOutputMetadata()

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

Change #1352326 merged by jenkins-bot:

[mediawiki/core@master] OutputPage: Use ParserOutput::collectMetadata() in addParserOutputMetadata()

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

Change #1357262 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/extensions/DiscussionTools@master] PageHooks: Avoid isAvailableForTitle DB queries via PageProps

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