Page MenuHomePhabricator

MediaWiki:Protectedpagetext leaks "Spécial:Badtitle/ApiErrorFormatter::getDummyTitle" text on mobile
Open, MediumPublicBUG REPORT

Description

I just noticed the following text leaking into a page on French Wikipedia: Spécial:Badtitle/MediaWiki\Api\ApiErrorFormatter::getDummyTitle, here:
diff showing the leaked string

A search on the wiki shows a few other occurrences:
insource:"getDummyTitle"

Steps to reproduce:

  1. On frwiki, be logged out (you need to lack edit rights on the following page), and use the mobile site (desktop is not affected).
  2. Go to a page with extended confirmed protection, e.g. Lionel Messi.
  3. Try to edit the page, navigate until you reach the "Cette page est en semi-protection étendue" modal dialog.

Two issues observed:

  1. "Proposer une modification en [[|page de discussion]]" — displayed as-is; the wikilink target is missing (should point to the article's talk page).
  2. In the URL of the "à un administrateur" link, the preloadtitle query parameter unexpectedly contains that "getDummyTitle" string.
    • expected: {{a'|Lionel_Messi}}
    • current: {{a'|Spécial:Badtitle/MediaWiki\Api\ApiErrorFormatter::getDummyTitle}}

Tracked down to:
This comes from our system message MediaWiki:Protectedpagetext. It looks like the magic words {{TALKPAGENAME}} and {{FULLPAGENAMEE}} don't resolve as expected in mobile context.

Event Timeline

Od1n triaged this task as Medium priority.Sep 13 2026, 4:44 PM

This looks very similar to T247661, which is marked as Resolved — the underlying issue must have regressed since then.

Also worth noting: this doesn't appear to be related to AbuseFilter. I have access to the AbuseFilter logs and checked them; no filter was triggered in connection with the bug I noticed here.

Tacsipacsi removed a project: I18n.
Tacsipacsi subscribed.

This has nothing to do with i18n, it would be just as broken in English as well.

Did an excimer and a xhgui profile:
https://performance.wikimedia.org/excimer/profile/6708f20fab99a9e5
https://performance.wikimedia.org/xhgui/run/symbol?id=6aad768ffa350a47e25d9402&symbol=MediaWiki%5CApi%5CApiErrorFormatter%3A%3AgetContextTitle

The call chain is ApiErrorFormatter::getDummyTitle <- ApiErrorFormatter::getContextTitle <- ApiErrorFormatter::addMessagesFromStatus. I guess the caller did not set the title for ApiErrorFormatter.

I looked it up in the meantime, but I didn’t find a solution as straightforward as in T247661 yet. ApiQueryInfo does this:

			$errorFormatter = $this->getErrorFormatter();
			if ( $errorFormatter->getFormat() === 'bc' ) {
				// Eew, no. Use a more modern format here.
				$errorFormatter = $errorFormatter->newWithFormat( 'plaintext' );
			}

			// ... uninteresting code ...

					$pageInfo['actions'][$action] = $errorFormatter->arrayFromStatus( $status );

The mobile editor uses an error format other than bc, so we don’t enter the if; but entering the if wouldn’t change anything – neither path sets the context. And it would change even less anything because ApiErrorFormatter::arrayFromStatus() does this:

		$formatter = new self(
			$result, $this->lang, $format ?: $this->format, $this->useDB
		);
		$formatter->addMessagesFromStatus( null, $status, [ $type ] );

– it makes a copy of itself and uses that copy to format the messages. It doesn’t set the context title on that copy, so even if the object referenced by $errorFormatter in ApiQueryInfo would have a correctly set title, it would be ignored.

We should also take care not to leak the title – unlike the endpoints fixed in T247661, ApiQueryInfo can operate on multiple pages, and error messages generated in other parts of the endpoint shouldn’t use an arbitrary title of the chosen ones.

Some options:

  • More elegant: add a method ApiErrorFormatter::newWithContextTitle(), which makes a copy with the specified context title, similarly to what ApiErrorFormatter::newWithFormat() does with the format; make sure that both ApiErrorFormatter::newWithFormat() and ApiErrorFormatter::arrayFromStatus() forward the context title; and change the call in ApiQueryInfo from $errorFormatter = $this->getErrorFormatter() to $errorFormatter = $this->getErrorFormatter()->newWithContextTitle( $page ).
  • Fewer code changes and micro-optimized: add a new $contextTitle parameter to ApiErrorFormatter::arrayFromStatus(), which is only set on the copy it makes, and specify $page only there, not making unnecessary copies.

Of the two options, the first one (newWithContextTitle()) seems like the clear choice:

  • extractPageInfo() is already called once per $page in the outer loop, so $errorFormatter->newWithContextTitle( $page ) only needs to happen once per page, not once per tested action — no extra allocation cost that the "micro-optimized" option is trying to avoid.
  • It mirrors the existing newWithFormat() pattern the class already uses, so it's more discoverable/consistent for future callers.
  • It keeps the context title opt-in and self-documenting, rather than adding a parameter to arrayFromStatus() that would become part of its public API surface (it's used elsewhere in core, e.g. plain status-to-array conversions).

For the implementation, a few things need to happen together:

1. Add newWithContextTitle() to ApiErrorFormatter, mirroring newWithFormat():

/**
 * Return a formatter like this one but with a different context title
 *
 * @since 1.XX
 * @param PageReference $title New context title.
 * @return self
 */
public function newWithContextTitle( PageReference $title ) {
	$formatter = new self( $this->result, $this->lang, $this->format, $this->useDB );
	$formatter->setContextTitle( $title );
	return $formatter;
}

2. Make newWithFormat() propagate $this->title to the copy it creates, since right now that copy always starts with $title === null:

public function newWithFormat( $format ) {
	$formatter = new self( $this->result, $this->lang, $format, $this->useDB );
	if ( $this->title !== null ) {
		$formatter->setContextTitle( $this->title );
	}
	return $formatter;
}

This matters because ApiQueryInfo chains newWithContextTitle( $page ) then newWithFormat( 'plaintext' ) when the format is bc — without this fix, the title set by the first call would be silently dropped by the second.

3. Make arrayFromStatus() propagate $this->title the same way, for the same reason:

$formatter = new self(
	$result, $this->lang, $format ?: $this->format, $this->useDB
);
if ( $this->title !== null ) {
	$formatter->setContextTitle( $this->title );
}
$formatter->addMessagesFromStatus( null, $status, [ $type ] );

Note that (2) and (3) are really pre-existing bugs in their own right — any caller that sets a context title and then goes through newWithFormat() or arrayFromStatus() already loses it today, independently of this ticket.

All three changes are needed together: without (1), ApiQueryInfo has no clean way to derive a per-page formatter without mutating the shared module-level one (which risks leaking one page's title onto another page's or module's messages). Without (2) or (3), even a correctly-titled formatter's title is silently dropped somewhere along the newWithContextTitle() → newWithFormat() → arrayFromStatus() chain.

Given ApiQueryInfo can process a batch of titles in one request, it'd be worth adding a test with two+ titles (e.g. one protected, one not) that asserts error messages generated for page A never carry page B's title — not just that *a* title is now present — to guard against a "wrong title" regression replacing the current "no title" bug.

For the record: on frwiki's Wikipédia:Demande d'intervention sur une page protégée (the page where users, mostly non-autoconfirmed ones, request that admins make an edit to a protected page on their behalf), this erroneous section title appears quite frequently, and several other users are beginning to complain (see this discussion).

These erroneous section titles are most of the time associated with very low-quality requests, since the submitter didn't notice and fix the title. That makes them even more tedious to handle, as we have to figure out which page the request is actually about.