Page MenuHomePhabricator

interwiki items are formatted as NonExistingEntityId in text/html when no label exists in requested language
Closed, ResolvedPublic


ItemPropertyIdHtmlLinkFormatter and LabelsProviderEntityIdHtmlLinkFormatter's formatEntityId functions tries to find the label.
When it can't find a label, it'll go out and check if the title even exists. If not, it'll turn to NonExistingEntityIdHtmlFormatter to format things as "(Deleted Item)".

The exists checks are easily mislead with interwiki titles, because Title::exists will not look those up and always return false.
I.e.: interwiki titles - if they have no label in the requested languages - will always render as "(Deleted Item)".

It'd probably be best to use Title::isKnown instead of Title::exists.

isKnown will always return true for external links.
Just like exists, it won't do a lookup, but I think it makes more sense to treat external links as (potentially) existing (and build a valid link), than to treat them as non-existing when they may very well exist.

An example, with mwscript eval.php --wiki=commonswiki

$wbRepo = \Wikibase\Repo\WikibaseRepo::getDefaultInstance();
$entityTitleLookup = $wbRepo->getEntityTitleLookup();
$valueFormatterFactory = $wbRepo->getValueFormatterFactory();
// id for, an item
// with only a German (no English) label
$entityId = \Wikibase\DataModel\Entity\ItemId::newFromNumber( 38622106 );
$value = new \Wikibase\DataModel\Entity\EntityIdValue( $entityId );

Trying to format it in German works just fine:

$valueFormatterFactory->getValueFormatter( 'text/html', new \ValueFormatters\FormatterOptions( [ \ValueFormatters\ValueFormatter::OPT_LANG => 'de' ] ) );
var_dump( $formatter->formatValue( $value ) );
// '<a title="d:Special:EntityPage/Q38622106" href="">Dampfwäscherei Südbahnhotel, Semmering</a>'

In English, where there is no label, it continues to validate
and finds that the title doesn't exist:

$valueFormatterFactory->getValueFormatter( 'text/html', new \ValueFormatters\FormatterOptions( [ \ValueFormatters\ValueFormatter::OPT_LANG => 'en' ] ) );
$formatter->formatValue( $value );
// 'Q38622106 <span class="wb-entity-undefinedinfo">(Deleted Item)</span>'

Note the return values for $title->isLocal, ->exists and ->isKnown here:

$title = $entityTitleLookup->getTitleForId( $entityId );
var_dump( $title->isLocal() ); // true
var_dump( $title->exists() ); // false
var_dump( $title->isKnown() ); // true

Related (SDC) ticket: T221676

Event Timeline

Restricted Application added projects: Wikidata, Multimedia. · View Herald TranscriptApr 30 2019, 7:17 AM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change 506123 had a related patch set uploaded (by Matthias Mullie; owner: Matthias Mullie):
[mediawiki/extensions/Wikibase@master] Use isKnown instead of exists to determine formatting entity as non-existing

Ramsey-WMF triaged this task as Normal priority.May 2 2019, 6:58 PM
Ramsey-WMF moved this task from Untriaged to Next up on the Multimedia board.

Change 506123 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Use isKnown instead of exists to determine formatting entity as non-existing

@matthiasmullie that code make it in, could you please confirm is the issue gone? Thanks

matthiasmullie closed this task as Resolved.May 9 2019, 11:46 AM
matthiasmullie claimed this task.

It works! Thanks