Page MenuHomePhabricator

Improve ParserOutput::setLanguageLinks() / ::addLanguageLink()
Open, Needs TriagePublic

Description

From core perspective, ParserOutput::setLanguageLinks() should accept an array of LinkTargets. What happens now is that Parser has a LinkTarget, formats it to prefixed text, then Skin/Api (basically all usages of it) parses it again into Title, or even worse implements its own custom parsing, like LinksUpdate.

Currently accepts an array of the form:

		$languageLinks[$languageCode] = $languageCode . ':' . $siteLink->getPageName();

(see https://gerrit.wikimedia.org/g/mediawiki/extensions/ArticlePlaceholder/+/18e4f52cc53b0ad6d9954c58c36df9f97f3c97ad/includes/AboutTopicRenderer.php#293)

Should probably have an API like:

public function addLanguageLink(string $langCode, LinkTarget page);

Note that core does not seem to use ::setLanguageLinks() at all any more. Perhaps this entire method should be deprecated and removed instead?

The ::addLanguageLink() method, on the other hand, is significantly used. It should also take a LinkTarget argument.

Note also that includes/deferred/LinksUpdate/LangLinksTable.php in mediawiki-core also has its own ideas about the ParserOuput format for language links.

*UPDATE* The ParserOutput::addLanguageLink function looks like this:

	public function addLanguageLink( $t ): void {
		if ( $t instanceof ParsoidLinkTarget ) {
			// language links are unusual in using 'text' rather than 'db key'
			$t = Title::newfromLinkTarget( $t )->getFullText();
		}
		$this->mLanguageLinks[] = $t;
	}

Note that most link-related metadata is stored like:

	$this->mTemplates[$ns][$dbk] = ....;

By using a numeric namespace as the first-level array key we don't have to use a TitleFormatter or Title to convert the namespace ID to a string. And then the second-level array key is the *db key* form of the title, not the *full text* form (ie, it uses underscores instead of spaces).

We should make the storage representation of language links consistent with the [$ns][$dbkey] = .... style of the other metadata properties, which will avoid needing a TitleFormatter and/or to convert the LinkTarget into a full Title before we can store it in the ParserOutput.

Related Objects

StatusSubtypeAssignedTask
OpenReleaseNone
OpenNone
OpenNone
OpenNone
OpenNone
OpenFeatureNone
OpenNone
OpenNone
OpenNone
OpenNone
OpenBUG REPORTNone
OpenNone
OpenNone
OpenNone
OpenNone
OpenNone
Resolvedcscott

Event Timeline

cscott renamed this task from Improve ParserOutput::setLanguageLinks() to Improve ParserOutput::setLanguageLinks() / ::addLanguageLink().Nov 18 2021, 9:10 PM
cscott updated the task description. (Show Details)
cscott updated the task description. (Show Details)

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

[mediawiki/services/parsoid@master] Add comments about maintaining language link metadata

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

Change 888058 merged by jenkins-bot:

[mediawiki/services/parsoid@master] Add comments about maintaining language link metadata

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

Change 901245 had a related patch set uploaded (by Arlolra; author: Arlolra):

[mediawiki/vendor@master] Bump parsoid to 0.18.0-a2

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

Change 901245 merged by jenkins-bot:

[mediawiki/vendor@master] Bump parsoid to 0.18.0-a2

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

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

[mediawiki/core@master] Deprecate ParserOutput::setLanguageLinks()

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

Change 971275 merged by jenkins-bot:

[mediawiki/core@master] Deprecate ParserOutput::setLanguageLinks()

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

@cscott: Removing task assignee as this open task has been assigned for more than two years - see the email sent to all task assignees on 2024-04-15.
Please assign this task to yourself again if you still realistically [plan to] work on this task - it would be welcome! :)
If this task has been resolved in the meantime, or should not be worked on by anybody ("declined"), please update its task status via "Add Action… 🡒 Change Status".
Also see https://www.mediawiki.org/wiki/Bug_management/Assignee_cleanup for tips how to best manage your individual work in Phabricator. Thanks!

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

[mediawiki/core@master] ParserOutput::addLanguageLink: Avoid a full Title parse

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

Change #1077117 merged by jenkins-bot:

[mediawiki/core@master] ParserOutput::addLanguageLink: Avoid a full Title parse

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