Page MenuHomePhabricator

Expose the current mw-editform formtype as a form data attribute
Closed, ResolvedPublicFeature

Description

As a developer trying to ascertain the current mw-editform formtype (preview, diff, initial, etc.), I would like a data attribute to be added to the #editform element, so that it is much easier for the front-end to figure out the current state of the edit form.

This would be helpful in solving T355043: "Show preview" or "Show changes" twice can clear Edit Recovery data, and I have a WIP patch which I believe would achieve this here;

diff --git a/includes/editpage/EditPage.php b/includes/editpage/EditPage.php
index 8bdaab05840..3b74a5c3a4f 100644
--- a/includes/editpage/EditPage.php
+++ b/includes/editpage/EditPage.php
@@ -2998,7 +2998,8 @@ class EditPage implements IEditObject {
                                'name' => self::EDITFORM_ID,
                                'method' => 'post',
                                'action' => $this->getActionURL( $this->getContextTitle() ),
-                               'enctype' => 'multipart/form-data'
+                               'enctype' => 'multipart/form-data',
+                               'data-mw-editform-type' => $this->formtype
                        ]
                ) );

afaict data-mw-editform-type follows the data-mw-{component} standard for data attributes.

Event Timeline

Change 1005118 had a related patch set uploaded (by Samtar; author: Samtar):

[mediawiki/core@master] [WIP/DNM] Add data-mw-editform-mode to mw-editform

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

TheresNoTime renamed this task from Expose the current mw-editform formtype to Expose the current mw-editform formtype as a form data attribute.Feb 20 2024, 4:18 PM

Apologies for the unprompted subscribe @Samwilson @tstarling — I know I briefly mentioned this to you Sam, and was wondering if you/Tim would have any further comments on the idea?

Change 1005118 merged by jenkins-bot:

[mediawiki/core@master] Add data-mw-editform-type to mw-editform

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

TheresNoTime claimed this task.
TheresNoTime updated the task description. (Show Details)
TheresNoTime removed a project: Patch-For-Review.
document.getElementById('editform').getAttribute('data-mw-editform-type')

works as expected on Beta :-)