From: Florianschmidtwelzow Date: Fri, 31 Oct 2014 12:05:32 +0000 (+0100) Subject: Use HTMLForm for Special:FileDuplicateSearch X-Git-Tag: 1.31.0-rc.0~11924^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/?a=commitdiff_plain;h=e4f5c506522505dc39b37b906062ecdabce4a736;p=lhc%2Fweb%2Fwiklou.git Use HTMLForm for Special:FileDuplicateSearch * Prepare the usage of MediaWiki UI. * Add new HTMLForm output mode "inline" (very close to "raw") Bug: 71436 Change-Id: I12240aaf624dff5219b344648b20373594b5ec46 --- diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index 908fdf27fb..39ed24f6f7 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -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" ); } diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php index 645b507fa5..9576c77c2a 100644 --- a/includes/htmlform/HTMLFormField.php +++ b/includes/htmlform/HTMLFormField.php @@ -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 . ' ' . + $inputHtml . + $helptext; + + return $html; + } + /** * Generate help text HTML in table format * @since 1.20 diff --git a/includes/specials/SpecialFileDuplicateSearch.php b/includes/specials/SpecialFileDuplicateSearch.php index 606f83777a..da79bb8153 100644 --- a/includes/specials/SpecialFileDuplicateSearch.php +++ b/includes/specials/SpecialFileDuplicateSearch.php @@ -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();