Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / includes / specials / SpecialExpandTemplates.php
index b7582e6..ca0d139 100644 (file)
@@ -95,8 +95,8 @@ class SpecialExpandTemplates extends SpecialPage {
                }
 
                $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 ) {
@@ -107,14 +107,14 @@ class SpecialExpandTemplates extends SpecialPage {
 
                        if ( $this->removeNowiki ) {
                                $tmp = preg_replace(
-                                       array( '_<nowiki>_', '_</nowiki>_', '_<nowiki */>_' ),
+                                       [ '_<nowiki>_', '_</nowiki>_', '_<nowiki */>_' ],
                                        '',
                                        $tmp
                                );
                        }
 
                        $config = $this->getConfig();
-                       if ( ( $config->get( 'UseTidy' ) && $options->getTidy() ) || $config->get( 'AlwaysUseTidy' ) ) {
+                       if ( $config->get( 'UseTidy' ) && $options->getTidy() ) {
                                $tmp = MWTidy::tidy( $tmp );
                        }
 
@@ -130,6 +130,22 @@ class SpecialExpandTemplates extends SpecialPage {
                }
        }
 
+       /**
+        * 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
         *
@@ -138,69 +154,62 @@ class SpecialExpandTemplates extends SpecialPage {
         * @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' )
-               );
-
-               $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;
+               $fields = [
+                       'contexttitle' => [
+                               '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' => [
+                               'type' => 'textarea',
+                               'name' => 'wpInput',
+                               'label' => $this->msg( 'expand_templates_input' )->text(),
+                               'rows' => 10,
+                               'default' => $input,
+                               'id' => 'input',
+                       ],
+                       'removecomments' => [
+                               'type' => 'check',
+                               'label' => $this->msg( 'expand_templates_remove_comments' )->text(),
+                               'name' => 'wpRemoveComments',
+                               'id' => 'removecomments',
+                               'default' => $this->removeComments,
+                       ],
+                       'removenowiki' => [
+                               'type' => 'check',
+                               'label' => $this->msg( 'expand_templates_remove_nowiki' )->text(),
+                               'name' => 'wpRemoveNowiki',
+                               'id' => 'removenowiki',
+                               'default' => $this->removeNowiki,
+                       ],
+                       'generate_xml' => [
+                               'type' => 'check',
+                               'label' => $this->msg( 'expand_templates_generate_xml' )->text(),
+                               'name' => 'wpGenerateXml',
+                               'id' => 'generate_xml',
+                               'default' => $this->generateXML,
+                       ],
+                       'generate_rawhtml' => [
+                               'type' => 'check',
+                               'label' => $this->msg( 'expand_templates_generate_rawhtml' )->text(),
+                               'name' => 'wpGenerateRawHtml',
+                               'id' => 'generate_rawhtml',
+                               'default' => $this->generateRawHtml,
+                       ],
+               ];
+
+               $form = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
+               $form
+                       ->setSubmitTextMsg( 'expand_templates_ok' )
+                       ->setWrapperLegendMsg( 'expandtemplates' )
+                       ->setHeaderText( $this->msg( 'expand_templates_intro' )->parse() )
+                       ->setSubmitCallback( [ $this, 'onSubmitInput' ] )
+                       ->showAlways();
        }
 
        /**
@@ -217,7 +226,7 @@ class SpecialExpandTemplates extends SpecialPage {
                        $output,
                        10,
                        10,
-                       array( 'id' => 'output', 'readonly' => 'readonly' )
+                       [ 'id' => 'output', 'readonly' => 'readonly' ]
                );
 
                return $out;
@@ -258,9 +267,9 @@ class SpecialExpandTemplates extends SpecialPage {
                        // does not currently provide logged-out users with CSRF protection; in that case,
                        // do not show the preview unless anonymous editing is allowed.
                        if ( $user->isAnon() && !$user->isAllowed( 'edit' ) ) {
-                               $error = array( 'expand_templates_preview_fail_html_anon' );
+                               $error = [ 'expand_templates_preview_fail_html_anon' ];
                        } elseif ( !$user->matchEditToken( $request->getVal( 'wpEditToken' ), '', $request ) ) {
-                               $error = array( 'expand_templates_preview_fail_html' );
+                               $error = [ 'expand_templates_preview_fail_html' ];
                        } else {
                                $error = false;
                        }
@@ -271,11 +280,11 @@ class SpecialExpandTemplates extends SpecialPage {
                        }
                }
 
-               $out->addHTML( Html::openElement( 'div', array(
+               $out->addHTML( Html::openElement( 'div', [
                        'class' => 'mw-content-' . $lang->getDir(),
                        'dir' => $lang->getDir(),
                        'lang' => $lang->getHtmlCode(),
-               ) ) );
+               ] ) );
                $out->addParserOutputContent( $pout );
                $out->addHTML( Html::closeElement( 'div' ) );
                $out->setCategoryLinks( $pout->getCategories() );