Page MenuHomePhabricator

JavaScript building message boxes should now use mw.util.messageBox
Closed, ResolvedPublic

Description

Background

The new mw.util.messageBox method provides a stable API for building message boxes instead of resorting to string stitching. Using this API means you do not need to change markup whenever Codex changes its markup. I've identified codebases impacted by this issue.
https://codesearch.wmcloud.org/deployed/?q=mw-message-box%7Ccdx-message&files=.*%5C.js%24&excludeFiles=%28tests%2F.*%7Cmodules%2Fflow%7Cmodules%2Fgraph.sandbox.js%29&repos=

User story

As a developer I don't want to update code markup every time Codex HTML changes.

Requirements

  • Replace code in the form $( '<div>' ).addClass( 'cdx-message cdx-message--block cdx-message--warning' ) with a call to mw.util.messageBox (example)
  • Make sure you are loading the associated Codex styles, with the CdxMessage component

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change #1071968 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/extensions/TwoColConflict@master] Use Codex markup for warning message

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

Change #1076233 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/core@master] Messages: Add support for inline messages and default to polite

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

Change #1076233 merged by jenkins-bot:

[mediawiki/core@master] mediawiki.util: Use appropriate Codex classes and attributes for Messages

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

Change #1071968 merged by jenkins-bot:

[mediawiki/extensions/TwoColConflict@master] Use Codex markup for warning message

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

Tacsipacsi subscribed.

Thanks for finally creating this function! I wish it happened during the messageboxmw-message-box migration, but it’s better late than never.

Some code relies on finding message boxes by class name, eg: ConfirmEmail.js. Is there a non-Codex class that we could use for this? And if not, can we add one?

Change #1076791 had a related patch set uploaded (by Sergio Gimeno; author: Sergio Gimeno):

[mediawiki/extensions/GrowthExperiments@master] refactor(ConfirmEmail): use mw.util.messageBox

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

Change #1076791 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] refactor(ConfirmEmail): use mw.util.messageBox

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

Some code relies on finding message boxes by class name, eg: ConfirmEmail.js. Is there a non-Codex class that we could use for this? And if not, can we add one?

@Sgs the Html::messageBox class does support the addition of a custom className - so you'd need to add it there (this would be a non-Codex class). For JS you can add a class by doing the following:

const warning = mw.util.messageBox('my warning', 'warning' );
warning.classList.add( 'mywarningclass' );

Change #1078359 had a related patch set uploaded (by Sergio Gimeno; author: Sergio Gimeno):

[mediawiki/extensions/GrowthExperiments@master] refactor(ConfirmEmail): avoid using Codex classes

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

Change #1078364 had a related patch set uploaded (by Sergio Gimeno; author: Sergio Gimeno):

[mediawiki/extensions/GrowthExperiments@master] refactor(SpecialManageMentors): avoid using Codex classes

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

Change #1078359 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] refactor(ConfirmEmail): avoid using Codex classes

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

Change #1078364 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] refactor(SpecialManageMentors): avoid using Codex classes

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

Some code relies on finding message boxes by class name, eg: ConfirmEmail.js. Is there a non-Codex class that we could use for this? And if not, can we add one?

@Sgs the Html::messageBox class does support the addition of a custom className - so you'd need to add it there (this would be a non-Codex class). For JS you can add a class by doing the following:

const warning = mw.util.messageBox('my warning', 'warning' );
warning.classList.add( 'mywarningclass' );

Thank you, GrowthExperiments is free of cdx-message classes now.

Change #1078974 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/extensions/MassMessage@master] Simplify MassMessage warning

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

Change #1078974 merged by jenkins-bot:

[mediawiki/extensions/MassMessage@master] Simplify MassMessage warning

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

Change #1079031 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/extensions/ParserMigration@master] Use newer messageBox function

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

Screenshot of MassMessage after above merged change:

Screenshot 2024-10-09 at 8.52.37 AM.png (464×1 px, 81 KB)

This leaves 3 extensions.

Screenshot of MassMessage after above merged change:

I don’t see the screenshot, please attach it to the task.

AKanji-WMF triaged this task as Medium priority.Oct 15 2024, 8:03 PM
AKanji-WMF moved this task from Triage to DRI Backlog on the Fundraising-Backlog board.

Change #1080720 had a related patch set uploaded (by Ejegg; author: Ejegg):

[mediawiki/extensions/CentralNotice@master] Use mw.util.messageBox

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

Nikerabbit subscribed.

FYI: I've spun off Translate into a sub task.

Change #1080720 merged by jenkins-bot:

[mediawiki/extensions/CentralNotice@master] Use mw.util.messageBox

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

Change #1079031 merged by jenkins-bot:

[mediawiki/extensions/ParserMigration@master] Use newer messageBox function

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

Jdlrobson claimed this task.

Thanks all!

I still see rEMFR src/mobile.startup/MessageBox.js and rECNO resources/infrastructure/campaignManager.js:559 (at b0a196822c54b931f08b6a8ff403345ad418badb) in the search results, shouldn’t they also be updated before we can call this done? (The other three extensions are probably fine: CommunityConfiguration only references the class in tests, Translate has its own subtask, and Flow is about to be undeployed.)

  • CentralNotice was fixed in https://gerrit.wikimedia.org/r/c/mediawiki/extensions/CentralNotice/+/1080720 - they have a release process so it's not yet reflected in master.
  • MobileFrontend's uses templates for managing all Codex design components, so it makes sense to manage this without mw.util.messageBox consistently with other components e.g. Button. As a maintainer preserving that and updating it as needed is fine.