Page MenuHomePhabricator

mw.message(...).parseDom() should be available even if jqueryMsg isn't loaded
Closed, ResolvedPublicFeature

Description

Feature summary:

mw.message(...).parseDom() should be available if mediawiki.jqueryMsg isn't loaded and return a text node with the unparsed message contents by default.

Use case(s):

It's possible to use .parse() without jqueryMsg, but it isn't possible to use .parseDom(). However, .parseDom() is faster than .parse() if the result is used with jQuery since .parse() serializes it to HTML.
In mediawiki.notification for example, the following is used:

$notificationContent.html( message.parse() );

This is suboptimal because .parse() creates a jQuery object, serializes it to HTML and passes it to .html(), which will parse the HTML again. The issue is that it's not possible to use .parseDom() instead since mediawiki.notification does not currently depend on jqueryMsg, and if it did, it could have a negative performance impact. If .parseDom() was always available it could be used here.

Benefits:

.parseDom() could be used more often, which would increase performance and avoid unnecessary (de-)serialization.

Event Timeline

Change #1238824 had a related patch set uploaded (by SomeRandomDeveloper; author: SomeRandomDeveloper):

[mediawiki/core@master] mediawiki.base: Add a stub for parseDom() to mw.message

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

Change #1238824 merged by jenkins-bot:

[mediawiki/core@master] mediawiki.base: Add a stub for parseDom() to mw.message

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

Change #1239414 had a related patch set uploaded (by SomeRandomDeveloper; author: SomeRandomDeveloper):

[mediawiki/core@master] Use .parseDom() instead of .parse() where applicable

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

Closing since the follow-up patch is not directly related to the main goal of this task.

I went to update https://www.mediawiki.org/wiki/Manual:Messages_API for this change, and discovered that it never documented this peculiar behavior of parseDom, so it's already correct. I guess it's not worth explaining how it worked on older MediaWiki versions.

Come to think of it, it might be worth a mention in release notes?

Change #1239447 had a related patch set uploaded (by SomeRandomDeveloper; author: SomeRandomDeveloper):

[mediawiki/core@master] Add release note for mw.message( ... ).parseDom() change

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

I went to update https://www.mediawiki.org/wiki/Manual:Messages_API for this change, and discovered that it never documented this peculiar behavior of parseDom, so it's already correct. I guess it's not worth explaining how it worked on older MediaWiki versions.

That's convenient; thanks for checking!

Come to think of it, it might be worth a mention in release notes?

Good idea; done in a separate patch

Change #1239414 merged by jenkins-bot:

[mediawiki/core@master] Use .parseDom() instead of .parse() where applicable

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

Change #1239447 merged by jenkins-bot:

[mediawiki/core@master] Add release note for mw.message( ... ).parseDom() change

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