Convert various FormActions to OOUI
authorThis, that and the other <at.light@live.com.au>
Sat, 11 Mar 2017 05:48:17 +0000 (16:48 +1100)
committerThis, that and the other <at.light@live.com.au>
Sat, 11 Mar 2017 05:48:17 +0000 (16:48 +1100)
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
includes/actions/PurgeAction.php
includes/actions/RevertAction.php
includes/actions/UnwatchAction.php
includes/actions/WatchAction.php
languages/i18n/en.json
languages/i18n/qqq.json

index e94a188..0141b9e 100644 (file)
@@ -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();
index 942b731..210751a 100644 (file)
@@ -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() {
index e466e65..a914c9b 100644 (file)
@@ -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' );
index 7f043e4..aa17b89 100644 (file)
@@ -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() {
index 23505c0..e12a727 100644 (file)
@@ -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() );
index 18e75b4..22d3a2b 100644 (file)
        "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.",
index e2dfa9a..48d7248 100644 (file)
        "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.",