Use HTMLForm for Special:FileDuplicateSearch
authorFlorianschmidtwelzow <florian.schmidt.welzow@t-online.de>
Fri, 31 Oct 2014 12:05:32 +0000 (13:05 +0100)
committerFlorian <florian.schmidt.welzow@t-online.de>
Sun, 29 Mar 2015 15:23:12 +0000 (17:23 +0200)
* Prepare the usage of MediaWiki UI.
* Add new HTMLForm output mode "inline" (very close to "raw")

Bug: 71436
Change-Id: I12240aaf624dff5219b344648b20373594b5ec46

includes/htmlform/HTMLForm.php
includes/htmlform/HTMLFormField.php
includes/specials/SpecialFileDuplicateSearch.php

index 908fdf2..39ed24f 100644 (file)
@@ -207,6 +207,7 @@ class HTMLForm extends ContextSource {
                'table',
                'div',
                'raw',
+               'inline',
        );
 
        /**
@@ -1366,6 +1367,8 @@ class HTMLForm extends ContextSource {
                                $html = Html::rawElement( 'table',
                                                $attribs,
                                                Html::rawElement( 'tbody', array(), "\n$html\n" ) ) . "\n";
+                       } elseif ( $displayFormat === 'inline' ) {
+                               $html = Html::rawElement( 'span', $attribs, "\n$html\n" );
                        } else {
                                $html = Html::rawElement( 'div', $attribs, "\n$html\n" );
                        }
index 645b507..9576c77 100644 (file)
@@ -566,6 +566,27 @@ abstract class HTMLFormField {
                return $this->getDiv( $value );
        }
 
+       /**
+        * Get the complete field as an inline element.
+        * @since 1.25
+        * @param string $value The value to set the input to.
+        * @return string Complete HTML inline element
+        */
+       public function getInline( $value ) {
+               list( $errors, $errorClass ) = $this->getErrorsAndErrorClass( $value );
+               $inputHtml = $this->getInputHTML( $value );
+               $helptext = $this->getHelpTextHtmlDiv( $this->getHelpText() );
+               $cellAttributes = array();
+               $label = $this->getLabelHtml( $cellAttributes );
+
+               $html = "\n" . $errors .
+                       $label . '&#160;' .
+                       $inputHtml .
+                       $helptext;
+
+               return $html;
+       }
+
        /**
         * Generate help text HTML in table format
         * @since 1.20
index 606f837..da79bb8 100644 (file)
@@ -110,25 +110,31 @@ class FileDuplicateSearchPage extends QueryPage {
                $out = $this->getOutput();
 
                # Create the input form
-               $out->addHTML(
-                       Html::openElement(
-                               'form',
-                               array( 'id' => 'fileduplicatesearch', 'method' => 'get', 'action' => wfScript() )
-                       ) . "\n" .
-                               Html::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) . "\n" .
-                               Html::openElement( 'fieldset' ) . "\n" .
-                               Html::element( 'legend', null, $this->msg( 'fileduplicatesearch-legend' )->text() ) . "\n" .
-                               Xml::inputLabel(
-                                       $this->msg( 'fileduplicatesearch-filename' )->text(),
-                                       'filename',
-                                       'filename',
-                                       50,
-                                       $this->filename
-                               ) . "\n" .
-                               Xml::submitButton( $this->msg( 'fileduplicatesearch-submit' )->text() ) . "\n" .
-                               Html::closeElement( 'fieldset' ) . "\n" .
-                               Html::closeElement( 'form' )
+               $formFields = array(
+                       'filename' => array(
+                               'type' => 'text',
+                               'name' => 'filename',
+                               'label-message' => 'fileduplicatesearch-filename',
+                               'id' => 'filename',
+                               'size' => 50,
+                               'value' => $this->filename,
+                               'cssclass' => 'mw-ui-input-inline'
+                       ),
+               );
+               $hiddenFields = array(
+                       'title' => $this->getPageTitle()->getPrefixedDBKey(),
                );
+               $htmlForm = HTMLForm::factory( 'inline', $formFields, $this->getContext() );
+               $htmlForm->addHiddenFields( $hiddenFields );
+               $htmlForm->setAction( wfScript() );
+               $htmlForm->setMethod( 'get' );
+               $htmlForm->setSubmitProgressive();
+               $htmlForm->setSubmitTextMsg( $this->msg( 'fileduplicatesearch-submit' ) );
+               $htmlForm->setWrapperLegendMsg( 'fileduplicatesearch-legend' );
+
+               // The form should be visible always, even if it was submitted (e.g. to perform another action).
+               // To bypass the callback validation of HTMLForm, use prepareForm() and displayForm().
+               $htmlForm->prepareForm()->displayForm( false );
 
                if ( $this->file ) {
                        $this->hash = $this->file->getSha1();