Use HTMLForm for Special:Export
authorFlorian <florian.schmidt.welzow@t-online.de>
Fri, 17 Apr 2015 16:56:32 +0000 (18:56 +0200)
committerFlorianschmidtwelzow <florian.schmidt.welzow@t-online.de>
Sun, 14 Jun 2015 16:48:26 +0000 (16:48 +0000)
* 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

autoload.php
includes/htmlform/HTMLCheckField.php
includes/htmlform/HTMLForm.php
includes/htmlform/HTMLFormField.php
includes/htmlform/HTMLFormFieldWithButton.php [new file with mode: 0644]
includes/htmlform/HTMLSelectNamespaceWithButton.php [new file with mode: 0644]
includes/htmlform/HTMLTextFieldWithButton.php [new file with mode: 0644]
includes/specials/SpecialExport.php

index 26d954a..504eaf2 100644 (file)
@@ -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',
index ede30dd..90293f4 100644 (file)
@@ -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 '&#160;';
                }
index cb4bba2..65fc0e8 100644 (file)
@@ -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',
index 49478fb..e19273b 100644 (file)
@@ -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 = '&#160;' . $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 (file)
index 0000000..3c8910f
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Enables HTMLFormField elements to be build with a button.
+ */
+class HTMLFormFieldWithButton extends HTMLFormField {
+       /** @var string $mButtonClass CSS class for the button in this field */
+       protected $mButtonClass = '';
+
+       /** @var string|integer $mButtonId Element ID for the button in this field */
+       protected $mButtonId = '';
+
+       /** @var string $mButtonName Name the button in this field */
+       protected $mButtonName = '';
+
+       /** @var string $mButtonType Type of the button in this field (e.g. button or submit) */
+       protected $mButtonType = 'submit';
+
+       /** @var string $mButtonType Value for the button in this field */
+       protected $mButtonValue;
+
+       public function __construct( $info ) {
+               if ( isset( $info['buttonclass'] ) ) {
+                       $this->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 . '&#160;' . $this->getInputHTML( '' );
+       }
+}
\ No newline at end of file
diff --git a/includes/htmlform/HTMLSelectNamespaceWithButton.php b/includes/htmlform/HTMLSelectNamespaceWithButton.php
new file mode 100644 (file)
index 0000000..5ab57a3
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+/**
+ * Creates a Html::namespaceSelector input field with a button assigned to the input field.
+ */
+class HTMLSelectNamespaceWithButton extends HTMLSelectNamespace {
+       /** @var HTMLFormClassWithButton $mClassWithButton */
+       protected $mClassWithButton = null;
+
+       public function __construct( $info ) {
+               $this->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 (file)
index 0000000..00c0517
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+/**
+ * Creates a text input field with a button assigned to the input field.
+ */
+class HTMLTextFieldWithButton extends HTMLTextField {
+       /** @var HTMLFormClassWithButton $mClassWithButton */
+       protected $mClassWithButton = null;
+
+       public function __construct( $info ) {
+               $this->mClassWithButton = new HTMLFormFieldWithButton( $info );
+               parent::__construct( $info );
+       }
+
+       public function getInputHTML( $value ) {
+               return $this->mClassWithButton->getElement( parent::getInputHTML( $value ) );
+       }
+}
\ No newline at end of file
index 47884eb..920d34b 100644 (file)
@@ -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
-               ) . '&#160;';
-               $form .= Xml::submitButton(
-                       $this->msg( 'export-addcat' )->text(),
-                       array( 'name' => 'addcat' )
-               ) . '<br />';
-
+               $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',
-                               )
-                       ) . '&#160;';
-                       $form .= Xml::submitButton(
-                               $this->msg( 'export-addns' )->text(),
-                               array( 'name' => 'addns' )
-                       ) . '<br />';
+                                       '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
-                       ) . '<br />';
+                       $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 .= '<br />';
 
                if ( $config->get( 'ExportAllowHistory' ) ) {
-                       $form .= Xml::checkLabel(
-                               $this->msg( 'exportcuronly' )->text(),
-                               'curonly',
-                               'curonly',
-                               $request->wasPosted() ? $request->getCheck( 'curonly' ) : true
-                       ) . '<br />';
+                       $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
-               ) . '<br />';
+               $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
-                       ) . '<br />';
+                       $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
-                       ) . '<br />';
-               */
-               $form .= Xml::checkLabel(
-                       $this->msg( 'export-download' )->text(),
-                       'wpDownload',
-                       'wpDownload',
-                       $request->wasPosted() ? $request->getCheck( 'wpDownload' ) : true
-               ) . '<br />';
+               $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
-                       ) . '<br />';
+                       $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' );
        }