Florianschmidtwelzow has uploaded a new change for review.

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

Change subject: Convert Special:ExpandTemplates to OOUI
......................................................................

Convert Special:ExpandTemplates to OOUI

Extra points:
 * Add error message, when $input was not fiven (previous behaviour was, that
   the form was simply displayed again.

Bug: T117748
Change-Id: Ibe4e010fe9d0b2520c2d6964bd66cb2bca3b0bc7
---
M includes/htmlform/HTMLForm.php
M includes/specials/SpecialExpandTemplates.php
M languages/i18n/en.json
M languages/i18n/qqq.json
4 files changed, 89 insertions(+), 63 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/12/255912/1

diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php
index b0d90af..f276646 100644
--- a/includes/htmlform/HTMLForm.php
+++ b/includes/htmlform/HTMLForm.php
@@ -527,6 +527,21 @@
        }
 
        /**
+        * Same as self::show with the difference, that the form will be
+        * added to the output, no matter, if the validation was good or not.
+        * @return bool|Status Whether submission was successful.
+        */
+       function showAlways() {
+               $this->prepareForm();
+
+               $result = $this->tryAuthorizedSubmit();
+
+               $this->displayForm( $result );
+
+               return $result;
+       }
+
+       /**
         * Validate all the fields, and call the submission callback
         * function if everything is kosher.
         * @throws MWException
diff --git a/includes/specials/SpecialExpandTemplates.php 
b/includes/specials/SpecialExpandTemplates.php
index 06eb276..17c224c 100644
--- a/includes/specials/SpecialExpandTemplates.php
+++ b/includes/specials/SpecialExpandTemplates.php
@@ -95,8 +95,8 @@
                }
 
                $out = $this->getOutput();
-               $out->addWikiMsg( 'expand_templates_intro' );
-               $out->addHTML( $this->makeForm( $titleStr, $input ) );
+
+               $this->makeForm( $titleStr, $input );
 
                if ( $output !== false ) {
                        if ( $this->generateXML && strlen( $output ) > 0 ) {
@@ -131,6 +131,22 @@
        }
 
        /**
+        * Callback for the HTMLForm used in self::makeForm.
+        * Checks, if the input was given, and if not, returns a fatal Status
+        * object with an error message.
+        *
+        * @param array $values The values submitted to the HTMLForm
+        * @return Status
+        */
+       public function onSubmitInput( array $values ) {
+               $status = Status::newGood();
+               if ( !strlen( $values['input'] ) ) {
+                       $status = Status::newFatal( 
'expand_templates_input_missing' );
+               }
+               return $status;
+       }
+
+       /**
         * Generate a form allowing users to enter information
         *
         * @param string $title Value for context title field
@@ -138,69 +154,62 @@
         * @return string
         */
        private function makeForm( $title, $input ) {
-               $self = $this->getPageTitle();
-               $request = $this->getRequest();
-               $user = $this->getUser();
-
-               $form = Xml::openElement(
-                       'form',
-                       array( 'method' => 'post', 'action' => 
$self->getLocalUrl() )
-               );
-               $form .= "<fieldset><legend>" . $this->msg( 'expandtemplates' 
)->escaped() . "</legend>\n";
-
-               $form .= '<p>' . Xml::inputLabel(
-                       $this->msg( 'expand_templates_title' )->plain(),
-                       'wpContextTitle',
-                       'contexttitle',
-                       60,
-                       $title,
-                       array( 'autofocus' => '', 'class' => 
'mw-ui-input-inline' )
-               ) . '</p>';
-               $form .= '<p>' . Xml::label(
-                       $this->msg( 'expand_templates_input' )->text(),
-                       'input'
-               ) . '</p>';
-               $form .= Xml::textarea(
-                       'wpInput',
-                       $input,
-                       10,
-                       10,
-                       array( 'id' => 'input' )
+               $fields = array(
+                       'contexttitle' => array(
+                               'type' => 'text',
+                               'label' => $this->msg( 'expand_templates_title' 
)->plain(),
+                               'name' => 'wpContextTitle',
+                               'id' => 'contexttitle',
+                               'size' => 60,
+                               'default' => $title,
+                               'autofocus' => true,
+                               'cssclass' => 'mw-ui-input-inline',
+                       ),
+                       'input' => array(
+                               'type' => 'textarea',
+                               'name' => 'wpInput',
+                               'label-message' => 'expand_templates_input',
+                               'rows' => 10,
+                               'default' => $input,
+                               'id' => 'input',
+                       ),
+                       'removecomments' => array(
+                               'type' => 'check',
+                               'label-message' => 
'expand_templates_remove_comments',
+                               'name' => 'wpRemoveComments',
+                               'id' => 'removecomments',
+                               'default' => $this->removeComments,
+                       ),
+                       'removenowiki' => array(
+                               'type' => 'check',
+                               'label-message' => 
'expand_templates_remove_nowiki',
+                               'name' => 'wpRemoveNowiki',
+                               'id' => 'removenowiki',
+                               'default' => $this->removeNowiki,
+                       ),
+                       'generate_xml' => array(
+                               'type' => 'check',
+                               'label-message' => 
'expand_templates_generate_xml',
+                               'name' => 'wpGenerateXml',
+                               'id' => 'generate_xml',
+                               'default' => $this->generateXML,
+                       ),
+                       'generate_rawhtml' => array(
+                               'type' => 'check',
+                               'label-message' => 
'expand_templates_generate_rawhtml',
+                               'name' => 'wpGenerateRawHtml',
+                               'id' => 'generate_rawhtml',
+                               'default' => $this->generateRawHtml,
+                       ),
                );
 
-               $form .= '<p>' . Xml::checkLabel(
-                       $this->msg( 'expand_templates_remove_comments' 
)->text(),
-                       'wpRemoveComments',
-                       'removecomments',
-                       $this->removeComments
-               ) . '</p>';
-               $form .= '<p>' . Xml::checkLabel(
-                       $this->msg( 'expand_templates_remove_nowiki' )->text(),
-                       'wpRemoveNowiki',
-                       'removenowiki',
-                       $this->removeNowiki
-               ) . '</p>';
-               $form .= '<p>' . Xml::checkLabel(
-                       $this->msg( 'expand_templates_generate_xml' )->text(),
-                       'wpGenerateXml',
-                       'generate_xml',
-                       $this->generateXML
-               ) . '</p>';
-               $form .= '<p>' . Xml::checkLabel(
-                       $this->msg( 'expand_templates_generate_rawhtml' 
)->text(),
-                       'wpGenerateRawHtml',
-                       'generate_rawhtml',
-                       $this->generateRawHtml
-               ) . '</p>';
-               $form .= '<p>' . Xml::submitButton(
-                       $this->msg( 'expand_templates_ok' )->text(),
-                       array( 'accesskey' => 's' )
-               ) . '</p>';
-               $form .= "</fieldset>\n";
-               $form .= Html::hidden( 'wpEditToken', $user->getEditToken( '', 
$request ) );
-               $form .= Xml::closeElement( 'form' );
-
-               return $form;
+               $form = HTMLForm::factory( 'ooui', $fields, $this->getContext() 
);
+               $form
+                       ->setSubmitTextMsg( 'expand_templates_ok' )
+                       ->setWrapperLegendMsg( 'expandtemplates' )
+                       ->setHeaderText( $this->msg( 'expand_templates_intro' 
)->text() )
+                       ->setSubmitCallback( array( $this, 'onSubmitInput' ) )
+                       ->showAlways();
        }
 
        /**
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index a274fac..8fa6410 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -3798,6 +3798,7 @@
        "expand_templates_preview": "Preview",
        "expand_templates_preview_fail_html": "<em>Because {{SITENAME}} has raw 
HTML enabled and there was a loss of session data, the preview is hidden as a 
precaution against JavaScript attacks.</em>\n\n<strong>If this is a legitimate 
preview attempt, please try again.</strong>\nIf it still does not work, try 
[[Special:UserLogout|logging out]] and logging back in.",
        "expand_templates_preview_fail_html_anon": "<em>Because {{SITENAME}} 
has raw HTML enabled and you are not logged in, the preview is hidden as a 
precaution against JavaScript attacks.</em>\n\n<strong>If this is a legitimate 
preview attempt, please [[Special:UserLogin|log in]] and try again.</strong>",
+       "expand_templates_input_missing": "You need to provide at least some 
input text.",
        "pagelanguage": "Page language selector",
        "pagelang-name": "Page",
        "pagelang-language": "Language",
diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json
index bd3776e..fb67af7 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -3971,6 +3971,7 @@
        "expand_templates_preview": "{{Identical|Preview}}",
        "expand_templates_preview_fail_html": "Used as error message in Preview 
section of [[Special:ExpandTemplates]] page.",
        "expand_templates_preview_fail_html_anon": "Used as error message in 
Preview section of [[Special:ExpandTemplates]] page.",
+       "expand_templates_input_missing": "Used on [[Special:ExpandTemplates]] 
as an error message, if no input text was provided.",
        "pagelanguage": "Title for page Special:PageLanguage",
        "pagelang-name": "Input label for page name on 
Special:PageLanguage\n{{Identical|Page}}",
        "pagelang-language": "Language selector label for 
Special:PageLanguage\n{{Identical|Language}}",

-- 
To view, visit https://gerrit.wikimedia.org/r/255912
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibe4e010fe9d0b2520c2d6964bd66cb2bca3b0bc7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to