Apply vform styling to HTMLForm buttons
[lhc/web/wiklou.git] / includes / htmlform / HTMLForm.php
index 6cf8d0a..c810f68 100644 (file)
@@ -107,6 +107,7 @@ class HTMLForm extends ContextSource {
                'select' => 'HTMLSelectField',
                'radio' => 'HTMLRadioField',
                'multiselect' => 'HTMLMultiSelectField',
+               'limitselect' => 'HTMLSelectLimitField',
                'check' => 'HTMLCheckField',
                'toggle' => 'HTMLCheckField',
                'int' => 'HTMLIntField',
@@ -119,6 +120,7 @@ class HTMLForm extends ContextSource {
                'edittools' => 'HTMLEditTools',
                'checkmatrix' => 'HTMLCheckMatrix',
                'cloner' => 'HTMLFormFieldCloner',
+               'autocompleteselect' => 'HTMLAutoCompleteSelectField',
                // HTMLTextField will output the correct type="" attribute automagically.
                // There are about four zillion other HTML5 input types, like range, but
                // we don't use those at the moment, so no point in adding all of them.
@@ -299,7 +301,11 @@ class HTMLForm extends ContextSource {
         * @return string
         */
        public function getDisplayFormat() {
-               return $this->displayFormat;
+               $format = $this->displayFormat;
+               if ( !$this->getConfig()->get( 'HTMLFormAllowTableFormat' ) && $format === 'table' ) {
+                       $format = 'div';
+               }
+               return $format;
        }
 
        /**
@@ -839,8 +845,6 @@ class HTMLForm extends ContextSource {
         * @return string HTML.
         */
        function getHiddenFields() {
-               global $wgArticlePath;
-
                $html = '';
                if ( $this->getMethod() == 'post' ) {
                        $html .= Html::hidden(
@@ -851,7 +855,8 @@ class HTMLForm extends ContextSource {
                        $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
                }
 
-               if ( strpos( $wgArticlePath, '?' ) !== false && $this->getMethod() == 'get' ) {
+               $articlePath = $this->getConfig()->get( 'ArticlePath' );
+               if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() == 'get' ) {
                        $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
                }
 
@@ -869,6 +874,7 @@ class HTMLForm extends ContextSource {
         */
        function getButtons() {
                $buttons = '';
+               $useMediaWikiUIEverywhere = $this->getConfig()->get( 'UseMediaWikiUIEverywhere' );
 
                if ( $this->mShowSubmit ) {
                        $attribs = array();
@@ -887,15 +893,17 @@ class HTMLForm extends ContextSource {
 
                        $attribs['class'] = array( 'mw-htmlform-submit' );
 
+                       if ( $this->isVForm() || $useMediaWikiUIEverywhere ) {
+                               array_push( $attribs['class'], 'mw-ui-button', 'mw-ui-constructive' );
+                       }
+
                        if ( $this->isVForm() ) {
                                // mw-ui-block is necessary because the buttons aren't necessarily in an
                                // immediate child div of the vform.
                                // @todo Let client specify if the primary submit button is progressive or destructive
                                array_push(
                                        $attribs['class'],
-                                       'mw-ui-button',
                                        'mw-ui-big',
-                                       'mw-ui-constructive',
                                        'mw-ui-block'
                                );
                        }
@@ -928,6 +936,17 @@ class HTMLForm extends ContextSource {
                                $attrs['id'] = $button['id'];
                        }
 
+                       if ( $this->isVForm() || $useMediaWikiUIEverywhere ) {
+                               if ( isset( $attrs['class'] ) ) {
+                                       $attrs['class'] .= ' mw-ui-button';
+                               } else {
+                                       $attrs['class'] = 'mw-ui-button';
+                               }
+                               if ( $this->isVForm() ) {
+                                       $attrs['class'] .= ' mw-ui-big mw-ui-block';
+                               }
+                       }
+
                        $buttons .= Html::element( 'input', $attrs ) . "\n";
                }
 
@@ -1245,6 +1264,9 @@ class HTMLForm extends ContextSource {
                                // Close enough to a div.
                                $getFieldHtmlMethod = 'getDiv';
                                break;
+                       case 'div':
+                               $getFieldHtmlMethod = 'getDiv';
+                               break;
                        default:
                                $getFieldHtmlMethod = 'get' . ucfirst( $displayFormat );
                }
@@ -1418,20 +1440,19 @@ class HTMLForm extends ContextSource {
         * @return string
         */
        public function getAction() {
-               global $wgScript, $wgArticlePath;
-
                // If an action is alredy provided, return it
                if ( $this->mAction !== false ) {
                        return $this->mAction;
                }
 
-               // Check whether we are in GET mode and $wgArticlePath contains a "?"
+               $articlePath = $this->getConfig()->get( 'ArticlePath' );
+               // Check whether we are in GET mode and the ArticlePath contains a "?"
                // meaning that getLocalURL() would return something like "index.php?title=...".
                // As browser remove the query string before submitting GET forms,
-               // it means that the title would be lost. In such case use $wgScript instead
+               // it means that the title would be lost. In such case use wfScript() instead
                // and put title in an hidden field (see getHiddenFields()).
-               if ( strpos( $wgArticlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
-                       return $wgScript;
+               if ( strpos( $articlePath, '?' ) !== false && $this->getMethod() === 'get' ) {
+                       return wfScript();
                }
 
                return $this->getTitle()->getLocalURL();