Page MenuHomePhabricator

Edit summary entity links using namespace aliases are not formatted using label
Open, Needs TriagePublic

Description

When an edit summary is formatted, Wikibase replaces links to entities with their label in the user language: for example, [[Property:P31]] turns into instance of (P31). However, this doesn’t seem to happen for links that use a namespace alias – [[P:P31]] just becomes P:P31. (This test revision has both cases in the summary.) It would be convenient if those links were also formatted using the label.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMay 20 2019, 12:22 PM

It looks like this happens in this condition in HtmlPageLinkRendererBeginHookHandler::doHtmlPageLinkRendererBegin:

// if custom link text is given, there is no point in overwriting it
// but not if it is similar to the plain title
if ( $text !== null && $target->getFullText() !== HtmlArmor::getHtml( $text ) ) {
	return true;
}

$target->getFullText() is Property:P31, but HtmlArmor::getHtml( $text ) is P:P31. So we think the user has set some custom text that we don’t want to override.

Looking at the $target object (a Title) in the debugger, I don’t see any trace of the original namespace in there, so I think the price to pay for this feature will be that even [[Property:P31|P:P31]] will be formatted just like [[Property:P31]] or [[P:P31]], ignoring the custom text the user specified. I suppose that’s acceptable, though.

So I think the way to fix this will be to refine that condition – perhaps instead of comparing the title’s text with the link text, parse the link text back into a title and see if it’s the same as the title?