From: Florian Date: Fri, 17 Apr 2015 16:56:32 +0000 (+0200) Subject: Use HTMLForm for Special:Export X-Git-Tag: 1.31.0-rc.0~11047^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=fd10cd5b95d5bd6e6c91e38ae5af59effe0ec870;p=lhc%2Fweb%2Fwiklou.git Use HTMLForm for Special:Export * Transform all input fields to use HtmlForm as preparation for enabling MediaWiki UI eveywhere. * Remove protected whitespace for HTMLCheckField (adds empty line to div-layout) * Add a new HTMLForm input field "Text with Button" and "Namespaceselector with Button" Bug: T73434 Change-Id: I53cc019c3ca94cec8f3c05500d0c604c1af7f688 --- diff --git a/autoload.php b/autoload.php index 26d954a9d1..504eaf22e2 100644 --- a/autoload.php +++ b/autoload.php @@ -489,6 +489,7 @@ $wgAutoloadLocalClasses = array( 'HTMLFileCache' => __DIR__ . '/includes/cache/HTMLFileCache.php', 'HTMLFloatField' => __DIR__ . '/includes/htmlform/HTMLFloatField.php', 'HTMLForm' => __DIR__ . '/includes/htmlform/HTMLForm.php', + 'HTMLFormFieldWithButton' => __DIR__ . '/includes/htmlform/HTMLFormFieldWithButton.php', 'HTMLFormField' => __DIR__ . '/includes/htmlform/HTMLFormField.php', 'HTMLFormFieldCloner' => __DIR__ . '/includes/htmlform/HTMLFormFieldCloner.php', 'HTMLFormFieldRequiredOptionsException' => __DIR__ . '/includes/htmlform/HTMLFormFieldRequiredOptionsException.php', @@ -502,11 +503,13 @@ $wgAutoloadLocalClasses = array( 'HTMLSelectField' => __DIR__ . '/includes/htmlform/HTMLSelectField.php', 'HTMLSelectLimitField' => __DIR__ . '/includes/htmlform/HTMLSelectLimitField.php', 'HTMLSelectNamespace' => __DIR__ . '/includes/htmlform/HTMLSelectNamespace.php', + 'HTMLSelectNamespaceWithButton' => __DIR__ . '/includes/htmlform/HTMLSelectNamespaceWithButton.php', 'HTMLSelectOrOtherField' => __DIR__ . '/includes/htmlform/HTMLSelectOrOtherField.php', 'HTMLSubmitField' => __DIR__ . '/includes/htmlform/HTMLSubmitField.php', 'HTMLTagFilter' => __DIR__ . '/includes/htmlform/HTMLTagFilter.php', 'HTMLTextAreaField' => __DIR__ . '/includes/htmlform/HTMLTextAreaField.php', 'HTMLTextField' => __DIR__ . '/includes/htmlform/HTMLTextField.php', + 'HTMLTextFieldWithButton' => __DIR__ . '/includes/htmlform/HTMLTextFieldWithButton.php', 'HWLDFWordAccumulator' => __DIR__ . '/includes/diff/DairikiDiff.php', 'HashBagOStuff' => __DIR__ . '/includes/libs/objectcache/HashBagOStuff.php', 'HashConfig' => __DIR__ . '/includes/config/HashConfig.php', diff --git a/includes/htmlform/HTMLCheckField.php b/includes/htmlform/HTMLCheckField.php index ede30dd37b..90293f460f 100644 --- a/includes/htmlform/HTMLCheckField.php +++ b/includes/htmlform/HTMLCheckField.php @@ -74,6 +74,11 @@ class HTMLCheckField extends HTMLFormField { function getLabel() { if ( $this->mParent instanceof OOUIHTMLForm ) { return $this->mLabel; + } elseif ( + $this->mParent instanceof HTMLForm && + $this->mParent->getDisplayFormat() === 'div' + ) { + return ''; } else { return ' '; } diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index cb4bba29b8..65fc0e885c 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -125,6 +125,7 @@ class HTMLForm extends ContextSource { public static $typeMappings = array( 'api' => 'HTMLApiField', 'text' => 'HTMLTextField', + 'textwithbutton' => 'HTMLTextFieldWithButton', 'textarea' => 'HTMLTextAreaField', 'select' => 'HTMLSelectField', 'radio' => 'HTMLRadioField', @@ -138,6 +139,7 @@ class HTMLForm extends ContextSource { 'selectorother' => 'HTMLSelectOrOtherField', 'selectandother' => 'HTMLSelectAndOtherField', 'namespaceselect' => 'HTMLSelectNamespace', + 'namespaceselectwithbutton' => 'HTMLSelectNamespaceWithButton', 'tagfilter' => 'HTMLTagFilter', 'submit' => 'HTMLSubmitField', 'hidden' => 'HTMLHiddenField', diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php index 49478fbf1c..e19273bba5 100644 --- a/includes/htmlform/HTMLFormField.php +++ b/includes/htmlform/HTMLFormField.php @@ -524,12 +524,20 @@ abstract class HTMLFormField { 'mw-htmlform-nolabel' => ( $label === '' ) ); - $field = Html::rawElement( - 'div', - array( 'class' => $outerDivClass ) + $cellAttributes, - $inputHtml . "\n$errors" - ); - $divCssClasses = array( "mw-htmlform-field-$fieldType", $this->mClass, $this->mVFormClass, $errorClass ); + $horizontalLabel = isset( $this->mParams['horizontal-label'] ) + ? $this->mParams['horizontal-label'] : false; + + if ( $horizontalLabel ) { + $field = ' ' . $inputHtml . "\n$errors"; + } else { + $field = Html::rawElement( + 'div', + array( 'class' => $outerDivClass ) + $cellAttributes, + $inputHtml . "\n$errors" + ); + } + $divCssClasses = array( "mw-htmlform-field-$fieldType", + $this->mClass, $this->mVFormClass, $errorClass ); $wrapperAttributes = array( 'class' => $divCssClasses, @@ -796,6 +804,8 @@ abstract class HTMLFormField { $displayFormat = $this->mParent->getDisplayFormat(); $html = ''; + $horizontalLabel = isset( $this->mParams['horizontal-label'] ) + ? $this->mParams['horizontal-label'] : false; if ( $displayFormat === 'table' ) { $html = @@ -803,7 +813,7 @@ abstract class HTMLFormField { array( 'class' => 'mw-label' ) + $cellAttributes, Html::rawElement( 'label', $for, $labelValue ) ); } elseif ( $hasLabel || $this->mShowEmptyLabels ) { - if ( $displayFormat === 'div' ) { + if ( $displayFormat === 'div' && !$horizontalLabel ) { $html = Html::rawElement( 'div', array( 'class' => 'mw-label' ) + $cellAttributes, diff --git a/includes/htmlform/HTMLFormFieldWithButton.php b/includes/htmlform/HTMLFormFieldWithButton.php new file mode 100644 index 0000000000..3c8910f843 --- /dev/null +++ b/includes/htmlform/HTMLFormFieldWithButton.php @@ -0,0 +1,57 @@ +mButtonClass = $info['buttonclass']; + } + if ( isset( $info['buttonid'] ) ) { + $this->mButtonId = $info['buttonid']; + } + if ( isset( $info['buttonname'] ) ) { + $this->mButtonName = $info['buttonname']; + } + if ( isset( $info['buttondefault'] ) ) { + $this->mButtonValue = $info['buttondefault']; + } + if ( isset( $info['buttontype'] ) ) { + $this->mButtonType = $info['buttontype']; + } + parent::__construct( $info ); + } + + public function getInputHTML( $value ) { + $attr = array( + 'class' => 'mw-htmlform-submit ' . $this->mButtonClass, + 'id' => $this->mButtonId, + ) + $this->getAttributes( array( 'disabled', 'tabindex' ) ); + + return Html::input( $this->mButtonName, $this->mButtonValue, $this->mButtonType, $attr ); + } + + /** + * Combines the passed element with a button. + * @param String $element Element to combine the button with. + * @return String + */ + public function getElement( $element ) { + return $element . ' ' . $this->getInputHTML( '' ); + } +} \ No newline at end of file diff --git a/includes/htmlform/HTMLSelectNamespaceWithButton.php b/includes/htmlform/HTMLSelectNamespaceWithButton.php new file mode 100644 index 0000000000..5ab57a335a --- /dev/null +++ b/includes/htmlform/HTMLSelectNamespaceWithButton.php @@ -0,0 +1,17 @@ +mClassWithButton = new HTMLFormFieldWithButton( $info ); + parent::__construct( $info ); + } + + public function getInputHTML( $value ) { + return $this->mClassWithButton->getElement( parent::getInputHTML( $value ) ); + } +} \ No newline at end of file diff --git a/includes/htmlform/HTMLTextFieldWithButton.php b/includes/htmlform/HTMLTextFieldWithButton.php new file mode 100644 index 0000000000..00c05170d6 --- /dev/null +++ b/includes/htmlform/HTMLTextFieldWithButton.php @@ -0,0 +1,17 @@ +mClassWithButton = new HTMLFormFieldWithButton( $info ); + parent::__construct( $info ); + } + + public function getInputHTML( $value ) { + return $this->mClassWithButton->getElement( parent::getInputHTML( $value ) ); + } +} \ No newline at end of file diff --git a/includes/specials/SpecialExport.php b/includes/specials/SpecialExport.php index 47884eb191..920d34b881 100644 --- a/includes/specials/SpecialExport.php +++ b/includes/specials/SpecialExport.php @@ -188,113 +188,128 @@ class SpecialExport extends SpecialPage { $categoryName = ''; } - $form = Xml::openElement( 'form', array( 'method' => 'post', - 'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ) ) ); - $form .= Xml::inputLabel( - $this->msg( 'export-addcattext' )->text(), - 'catname', - 'catname', - 40, - $categoryName - ) . ' '; - $form .= Xml::submitButton( - $this->msg( 'export-addcat' )->text(), - array( 'name' => 'addcat' ) - ) . '
'; - + $formDescriptor = array( + 'catname' => array( + 'type' => 'textwithbutton', + 'name' => 'catname', + 'horizontal-label' => true, + 'label-message' => 'export-addcattext', + 'default' => $categoryName, + 'size' => 40, + 'buttontype' => 'submit', + 'buttonname' => 'addcat', + 'buttondefault' => $this->msg( 'export-addcat' )->text(), + ), + ); if ( $config->get( 'ExportFromNamespaces' ) ) { - $form .= Html::namespaceSelector( - array( - 'selected' => $nsindex, - 'label' => $this->msg( 'export-addnstext' )->text() - ), array( + $formDescriptor += array( + 'nsindex' => array( + 'type' => 'namespaceselectwithbutton', + 'default' => $nsindex, + 'label-message' => 'export-addnstext', + 'horizontal-label' => true, 'name' => 'nsindex', 'id' => 'namespace', - 'class' => 'namespaceselector', - ) - ) . ' '; - $form .= Xml::submitButton( - $this->msg( 'export-addns' )->text(), - array( 'name' => 'addns' ) - ) . '
'; + 'cssclass' => 'namespaceselector', + 'buttontype' => 'submit', + 'buttonname' => 'addns', + 'buttondefault' => $this->msg( 'export-addns' )->text(), + ), + ); } if ( $config->get( 'ExportAllowAll' ) ) { - $form .= Xml::checkLabel( - $this->msg( 'exportall' )->text(), - 'exportall', - 'exportall', - $request->wasPosted() ? $request->getCheck( 'exportall' ) : false - ) . '
'; + $formDescriptor += array( + 'exportall' => array( + 'type' => 'check', + 'label-message' => 'exportall', + 'name' => 'exportall', + 'id' => 'exportall', + 'default' => $request->wasPosted() ? $request->getCheck( 'exportall' ) : false, + ), + ); } - $form .= Xml::element( - 'textarea', - array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ), - $page, - false + $formDescriptor += array( + 'textarea' => array( + 'class' => 'HTMLTextAreaField', + 'name' => 'pages', + 'nodata' => true, + 'cols' => 40, + 'rows' => 10, + 'default' => $page, + ), ); - $form .= '
'; if ( $config->get( 'ExportAllowHistory' ) ) { - $form .= Xml::checkLabel( - $this->msg( 'exportcuronly' )->text(), - 'curonly', - 'curonly', - $request->wasPosted() ? $request->getCheck( 'curonly' ) : true - ) . '
'; + $formDescriptor += array( + 'curonly' => array( + 'type' => 'check', + 'label-message' => 'exportcuronly', + 'name' => 'curonly', + 'id' => 'curonly', + 'default' => $request->wasPosted() ? $request->getCheck( 'curonly' ) : true, + ), + ); } else { $out->addWikiMsg( 'exportnohistory' ); } - $form .= Xml::checkLabel( - $this->msg( 'export-templates' )->text(), - 'templates', - 'wpExportTemplates', - $request->wasPosted() ? $request->getCheck( 'templates' ) : false - ) . '
'; + $formDescriptor += array( + 'templates' => array( + 'type' => 'check', + 'label-message' => 'export-templates', + 'name' => 'templates', + 'id' => 'wpExportTemplates', + 'default' => $request->wasPosted() ? $request->getCheck( 'templates' ) : false, + ), + ); if ( $config->get( 'ExportMaxLinkDepth' ) || $this->userCanOverrideExportDepth() ) { - $form .= Xml::inputLabel( - $this->msg( 'export-pagelinks' )->text(), - 'pagelink-depth', - 'pagelink-depth', - 20, - 0 - ) . '
'; + $formDescriptor += array( + 'pagelink-depth' => array( + 'type' => 'text', + 'name' => 'pagelink-depth', + 'id' => 'pagelink-depth', + 'label-message' => 'export-pagelinks', + 'default' => '0', + 'size' => 20, + ), + ); } - /* Enable this when we can do something useful exporting/importing image information. - $form .= Xml::checkLabel( - $this->msg( 'export-images' )->text(), - 'images', - 'wpExportImages', - false - ) . '
'; - */ - $form .= Xml::checkLabel( - $this->msg( 'export-download' )->text(), - 'wpDownload', - 'wpDownload', - $request->wasPosted() ? $request->getCheck( 'wpDownload' ) : true - ) . '
'; + $formDescriptor += array( + /* Enable this when we can do something useful exporting/importing image information. + 'images' => array( + 'type' => 'check', + 'name' => 'images', + 'id' => 'wpExportImages', + 'default' => false, + ),*/ + 'wpDownload' => array( + 'type' => 'check', + 'name' =>'wpDownload', + 'id' => 'wpDownload', + 'default' => $request->wasPosted() ? $request->getCheck( 'wpDownload' ) : true, + 'label-message' => 'export-download', + ), + ); if ( $config->get( 'ExportAllowListContributors' ) ) { - $form .= Xml::checkLabel( - $this->msg( 'exportlistauthors' )->text(), - 'listauthors', - 'listauthors', - $request->wasPosted() ? $request->getCheck( 'listauthors' ) : false - ) . '
'; + $formDescriptor += array( + 'listauthors' => array( + 'type' => 'check', + 'label-message' => 'exportlistauthors', + 'default' => $request->wasPosted() ? $request->getCheck( 'listauthors' ) : false, + 'name' => 'listauthors', + 'id' => 'listauthors', + ), + ); } - $form .= Xml::submitButton( - $this->msg( 'export-submit' )->text(), - Linker::tooltipAndAccesskeyAttribs( 'export' ) - ); - $form .= Xml::closeElement( 'form' ); - - $out->addHTML( $form ); + $htmlForm = HTMLForm::factory( 'div', $formDescriptor, $this->getContext() ); + $htmlForm->setSubmitTextMsg( 'export-submit' ); + $htmlForm->prepareForm()->displayForm( false ); $this->addHelpLink( 'Help:Export' ); }