From 44141e3a72fa8270a0b8af2216727a4b536bcd9d Mon Sep 17 00:00:00 2001 From: "This, that and the other" Date: Sat, 11 Mar 2017 16:48:17 +1100 Subject: [PATCH] Convert various FormActions to OOUI Support for OOUI is added to FormAction, and subclasses can enable it as required. PurgeAction, RevertAction, WatchAction and UnwatchAction are converted to OOUI, with minor changes to the forms to give them a neater appearance. Bug: T160236 Change-Id: I5294e5d886e8641e9b63eabc9d7fa8ea93e0df96 --- includes/actions/FormAction.php | 14 +++++++++++++- includes/actions/PurgeAction.php | 20 ++++++++++++++++---- includes/actions/RevertAction.php | 4 ++++ includes/actions/UnwatchAction.php | 21 +++++++++++++-------- includes/actions/WatchAction.php | 25 +++++++++++++++++-------- languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + 7 files changed, 65 insertions(+), 21 deletions(-) diff --git a/includes/actions/FormAction.php b/includes/actions/FormAction.php index e94a18880e..0141b9ec16 100644 --- a/includes/actions/FormAction.php +++ b/includes/actions/FormAction.php @@ -58,6 +58,14 @@ abstract class FormAction extends Action { protected function alterForm( HTMLForm $form ) { } + /** + * Whether the form should use OOUI + * @return bool + */ + protected function usesOOUI() { + return false; + } + /** * Get the HTMLForm to control behavior * @return HTMLForm|null @@ -68,7 +76,11 @@ abstract class FormAction extends Action { // Give hooks a chance to alter the form, adding extra fields or text etc Hooks::run( 'ActionModifyFormFields', [ $this->getName(), &$this->fields, $this->page ] ); - $form = new HTMLForm( $this->fields, $this->getContext(), $this->getName() ); + if ( $this->usesOOUI() ) { + $form = HTMLForm::factory( 'ooui', $this->fields, $this->getContext(), $this->getName() ); + } else { + $form = new HTMLForm( $this->fields, $this->getContext(), $this->getName() ); + } $form->setSubmitCallback( [ $this, 'onSubmit' ] ); $title = $this->getTitle(); diff --git a/includes/actions/PurgeAction.php b/includes/actions/PurgeAction.php index 942b731634..210751af90 100644 --- a/includes/actions/PurgeAction.php +++ b/includes/actions/PurgeAction.php @@ -75,12 +75,24 @@ class PurgeAction extends FormAction { } } - protected function alterForm( HTMLForm $form ) { - $form->setSubmitTextMsg( 'confirm_purge_button' ); + protected function usesOOUI() { + return true; } - protected function preText() { - return $this->msg( 'confirm-purge-top' )->parse(); + protected function getFormFields() { + return [ + 'intro' => [ + 'type' => 'info', + 'vertical-label' => true, + 'raw' => true, + 'default' => $this->msg( 'confirm-purge-top' )->parse() + ] + ]; + } + + protected function alterForm( HTMLForm $form ) { + $form->setWrapperLegendMsg( 'confirm-purge-title' ); + $form->setSubmitTextMsg( 'confirm_purge_button' ); } protected function postText() { diff --git a/includes/actions/RevertAction.php b/includes/actions/RevertAction.php index e466e6549a..a914c9b2b3 100644 --- a/includes/actions/RevertAction.php +++ b/includes/actions/RevertAction.php @@ -66,6 +66,10 @@ class RevertAction extends FormAction { } } + protected function usesOOUI() { + return true; + } + protected function alterForm( HTMLForm $form ) { $form->setWrapperLegendMsg( 'filerevert-legend' ); $form->setSubmitTextMsg( 'filerevert-submit' ); diff --git a/includes/actions/UnwatchAction.php b/includes/actions/UnwatchAction.php index 7f043e4676..aa17b89c8d 100644 --- a/includes/actions/UnwatchAction.php +++ b/includes/actions/UnwatchAction.php @@ -31,22 +31,27 @@ class UnwatchAction extends WatchAction { return 'unwatch'; } - protected function getDescription() { - return $this->msg( 'removewatch' )->escaped(); - } - public function onSubmit( $data ) { self::doUnwatch( $this->getTitle(), $this->getUser() ); return true; } - protected function alterForm( HTMLForm $form ) { - $form->setSubmitTextMsg( 'confirm-unwatch-button' ); + protected function getFormFields() { + return [ + 'intro' => [ + 'type' => 'info', + 'vertical-label' => true, + 'raw' => true, + 'default' => $this->msg( 'confirm-unwatch-top' )->parse() + ] + ]; } - protected function preText() { - return $this->msg( 'confirm-unwatch-top' )->parse(); + protected function alterForm( HTMLForm $form ) { + parent::alterForm( $form ); + $form->setWrapperLegendMsg( 'removewatch' ); + $form->setSubmitTextMsg( 'confirm-unwatch-button' ); } public function onSuccess() { diff --git a/includes/actions/WatchAction.php b/includes/actions/WatchAction.php index 23505c020d..e12a727633 100644 --- a/includes/actions/WatchAction.php +++ b/includes/actions/WatchAction.php @@ -35,11 +35,8 @@ class WatchAction extends FormAction { return false; } - /** - * @return string HTML - */ protected function getDescription() { - return $this->msg( 'addwatch' )->escaped(); + return ''; } public function onSubmit( $data ) { @@ -57,15 +54,27 @@ class WatchAction extends FormAction { parent::checkCanExecute( $user ); } + protected function usesOOUI() { + return true; + } + + protected function getFormFields() { + return [ + 'intro' => [ + 'type' => 'info', + 'vertical-label' => true, + 'raw' => true, + 'default' => $this->msg( 'confirm-watch-top' )->parse() + ] + ]; + } + protected function alterForm( HTMLForm $form ) { + $form->setWrapperLegendMsg( 'addwatch' ); $form->setSubmitTextMsg( 'confirm-watch-button' ); $form->setTokenSalt( 'watch' ); } - protected function preText() { - return $this->msg( 'confirm-watch-top' )->parse(); - } - public function onSuccess() { $msgKey = $this->getTitle()->isTalkPage() ? 'addedwatchtext-talk' : 'addedwatchtext'; $this->getOutput()->addWikiMsg( $msgKey, $this->getTitle()->getPrefixedText() ); diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 18e75b489d..22d3a2b7bf 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3484,6 +3484,7 @@ "confirmrecreate-noreason": "User [[User:$1|$1]] ([[User talk:$1|talk]]) {{GENDER:$1|deleted}} this page after you started editing. Please confirm that you really want to recreate this page.", "recreate": "Recreate", "unit-pixel": "px", + "confirm-purge-title": "Purge this page", "confirm_purge_button": "OK", "confirm-purge-top": "Clear the cache of this page?", "confirm-purge-bottom": "Purging a page clears the cache and forces the most current revision to appear.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index e2dfa9abe2..48d7248e19 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -3671,6 +3671,7 @@ "confirmrecreate-noreason": "Followed by the checkbox which has the label {{msg-mw|Recreate}}.\n\nParameters:\n* $1 - username, also used for GENDER support\n* $2 - (Unused) reason\nSee also:\n* {{msg-mw|Confirmrecreate}}", "recreate": "Text shown when the editor fails to save the page due to it having been deleted since they opened VE. $1 is the message {{msg-mw|ooui-dialog-process-continue}}.", "unit-pixel": "{{optional}}\npx is the abbreviation for \"pixel\".", + "confirm-purge-title": "Title for the confirmation form that appears when the user is about to purge the page.", "confirm_purge_button": "Used as Submit button text.\n{{Identical|OK}}", "confirm-purge-top": "Used as confirmation message.", "confirm-purge-bottom": "Additional description for Purge form.", -- 2.20.1