* (bug 33967) "Previous revision" and "Newer revision" links now display the correct...
[lhc/web/wiklou.git] / includes / HTMLForm.php
index 85b5038..3999e67 100644 (file)
@@ -55,7 +55,7 @@
  */
 class HTMLForm extends ContextSource {
 
-       # A mapping of 'type' inputs onto standard HTMLFormField subclasses
+       // A mapping of 'type' inputs onto standard HTMLFormField subclasses
        static $typeMappings = array(
                'text' => 'HTMLTextField',
                'textarea' => 'HTMLTextAreaField',
@@ -72,12 +72,10 @@ class HTMLForm extends ContextSource {
                'submit' => 'HTMLSubmitField',
                'hidden' => 'HTMLHiddenField',
                'edittools' => 'HTMLEditTools',
-               'namespaces' => 'HTMLNamespacesField',
-               'restrictionlevels' => 'HTMLRestrictionLevelsField',
 
-               # HTMLTextField will output the correct type="" attribute automagically.
-               # There are about four zillion other HTML5 input types, like url, but
-               # we don't use those at the moment, so no point in adding all of them.
+               // HTMLTextField will output the correct type="" attribute automagically.
+               // There are about four zillion other HTML5 input types, like url, but
+               // we don't use those at the moment, so no point in adding all of them.
                'email' => 'HTMLTextField',
                'password' => 'HTMLTextField',
        );
@@ -109,6 +107,12 @@ class HTMLForm extends ContextSource {
 
        protected $mTitle;
        protected $mMethod = 'post';
+       
+       /**
+        * @since 1.19
+        * @var false|string
+        */
+       protected $mAction = false;
 
        protected $mUseMultipart = false;
        protected $mHiddenFields = array();
@@ -188,7 +192,7 @@ class HTMLForm extends ContextSource {
         * done already.
         * @deprecated since 1.18 load modules with ResourceLoader instead
         */
-       static function addJS() { }
+       static function addJS() { wfDeprecated( __METHOD__, '1.18' ); }
 
        /**
         * Initialise a new Object for the field
@@ -340,7 +344,7 @@ class HTMLForm extends ContextSource {
        /**
         * Add header text, inside the form.
         * @param $msg String complete text of message to display
-        * @param $section The section to add the header to
+        * @param $section string The section to add the header to
         */
        function addHeaderText( $msg, $section = null ) {
                if ( is_null( $section ) ) {
@@ -425,7 +429,7 @@ class HTMLForm extends ContextSource {
        }
 
        /**
-        * Display the form (sending to wgOut), with an appropriate error
+        * Display the form (sending to $wgOut), with an appropriate error
         * message or stack of messages, and any validation errors, etc.
         * @param $submitResult Mixed output from HTMLForm::trySubmit()
         */
@@ -474,7 +478,7 @@ class HTMLForm extends ContextSource {
                        : 'application/x-www-form-urlencoded';
                # Attributes
                $attribs = array(
-                       'action'  => $this->getTitle()->getFullURL(),
+                       'action'  => $this->mAction === false ? $this->getTitle()->getFullURL() : $this->mAction,
                        'method'  => $this->mMethod,
                        'class'   => 'visualClear',
                        'enctype' => $encType,
@@ -847,25 +851,19 @@ class HTMLForm extends ContextSource {
        public function getLegend( $key ) {
                return wfMsg( "{$this->mMessagePrefix}-$key" );
        }
-
-       /**
-        * Returns an array of fields in the form
-        *
-        * @return HTMLFormField[]
-        */
-       public function getFlatFields() {
-               return $this->mFlatFields;
-       }
-
+       
        /**
-        * Returns a value of a field
-        *
-        * @param $field string Field name
-        * @return mixed
+        * Set the value for the action attribute of the form.
+        * When set to false (which is the default state), the set title is used. 
+        * 
+        * @since 1.19
+        * 
+        * @param string|false $action
         */
-       public function getVal( $field ) {
-               return $this->mFieldData[$field];
+       public function setAction( $action ) {
+               $this->mAction = $action;
        }
+       
 }
 
 /**
@@ -1011,6 +1009,10 @@ abstract class HTMLFormField {
                if ( isset( $params['filter-callback'] ) ) {
                        $this->mFilterCallback = $params['filter-callback'];
                }
+
+               if ( isset( $params['flatlist'] ) ){
+                       $this->mClass .= ' mw-htmlform-flatlist';
+               }
        }
 
        /**
@@ -1092,15 +1094,6 @@ abstract class HTMLFormField {
                return $html;
        }
 
-       /**
-        * Returns the HTML name of the Field
-        *
-        * @return string
-        */
-       public function getName() {
-               return $this->mName;
-       }
-
        function getLabel() {
                return $this->mLabel;
        }
@@ -1141,7 +1134,7 @@ abstract class HTMLFormField {
        /**
         * flatten an array of options to a single array, for instance,
         * a set of <options> inside <optgroups>.
-        * @param $options Associative Array with values either Strings
+        * @param $options array Associative Array with values either Strings
         *       or Arrays
         * @return Array flattened input
         */
@@ -1204,6 +1197,10 @@ class HTMLTextField extends HTMLFormField {
                        'value' => $value,
                ) + $this->getTooltipAndAccessKey();
 
+               if ( $this->mClass !== '' ) {
+                       $attribs['class'] = $this->mClass;
+               }
+               
                if ( isset( $this->mParams['maxlength'] ) ) {
                        $attribs['maxlength'] = $this->mParams['maxlength'];
                }
@@ -1274,7 +1271,10 @@ class HTMLTextAreaField extends HTMLFormField {
                        'rows' => $this->getRows(),
                ) + $this->getTooltipAndAccessKey();
 
-
+               if ( $this->mClass !== '' ) {
+                       $attribs['class'] = $this->mClass;
+               }
+               
                if ( !empty( $this->mParams['disabled'] ) ) {
                        $attribs['disabled'] = 'disabled';
                }
@@ -1381,6 +1381,10 @@ class HTMLCheckField extends HTMLFormField {
                if ( !empty( $this->mParams['disabled'] ) ) {
                        $attr['disabled'] = 'disabled';
                }
+               
+               if ( $this->mClass !== '' ) {
+                       $attr['class'] = $this->mClass;
+               }
 
                return Xml::check( $this->mName, $value, $attr ) . '&#160;' .
                        Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel );
@@ -1458,6 +1462,10 @@ class HTMLSelectField extends HTMLFormField {
                if ( !empty( $this->mParams['disabled'] ) ) {
                        $select->setAttribute( 'disabled', 'disabled' );
                }
+               
+               if ( $this->mClass !== '' ) {
+                       $select->setAttribute( 'class', $this->mClass );
+               }
 
                $select->addOptions( $this->mParams['options'] );
 
@@ -1519,6 +1527,10 @@ class HTMLSelectOrOtherField extends HTMLTextField {
                if ( isset( $this->mParams['maxlength'] ) ) {
                        $tbAttribs['maxlength'] = $this->mParams['maxlength'];
                }
+               
+               if ( $this->mClass !== '' ) {
+                       $tbAttribs['class'] = $this->mClass;
+               }
 
                $textbox = Html::input(
                        $this->mName . '-other',
@@ -1554,13 +1566,6 @@ class HTMLSelectOrOtherField extends HTMLTextField {
  */
 class HTMLMultiSelectField extends HTMLFormField {
 
-       public function __construct( $params ){
-               parent::__construct( $params );
-               if( isset( $params['flatlist'] ) ){
-                       $this->mClass .= ' mw-htmlform-multiselect-flatlist';
-               }
-       }
-
        function validate( $value, $alldata ) {
                $p = parent::validate( $value, $alldata );
 
@@ -1612,7 +1617,7 @@ class HTMLMultiSelectField extends HTMLFormField {
                                        $attribs + $thisAttribs );
                                $checkbox .= '&#160;' . Html::rawElement( 'label', array( 'for' => "{$this->mID}-$info" ), $label );
 
-                               $html .= ' ' . Html::rawElement( 'div', array( 'class' => 'mw-htmlform-multiselect-item' ), $checkbox );
+                               $html .= ' ' . Html::rawElement( 'div', array( 'class' => 'mw-htmlform-flatlist-item' ), $checkbox );
                        }
                }
 
@@ -1742,6 +1747,10 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
                        'id' => $this->mID . '-other',
                        'size' => $this->getSize(),
                );
+               
+               if ( $this->mClass !== '' ) {
+                       $textAttribs['class'] = $this->mClass;
+               }
 
                foreach ( array( 'required', 'autofocus', 'multiple', 'disabled' ) as $param ) {
                        if ( isset( $this->mParams[$param] ) ) {
@@ -1826,12 +1835,6 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
  * Radio checkbox fields.
  */
 class HTMLRadioField extends HTMLFormField {
-       function __construct( $params ) {
-               parent::__construct( $params );
-               if ( isset( $params['flatlist'] ) ) {
-                       $this->mClass .= ' mw-htmlform-radio-flatlist';
-               }
-       }
 
 
        function validate( $value, $alldata ) {
@@ -1890,7 +1893,7 @@ class HTMLRadioField extends HTMLFormField {
                                $radio .= '&#160;' .
                                                Html::rawElement( 'label', array( 'for' => $id ), $label );
 
-                               $html .= ' ' . Html::rawElement( 'div', array( 'class' => 'mw-htmlform-radio-item' ), $radio );
+                               $html .= ' ' . Html::rawElement( 'div', array( 'class' => 'mw-htmlform-flatlist-item' ), $radio );
                        }
                }
 
@@ -1971,7 +1974,7 @@ class HTMLSubmitField extends HTMLFormField {
                return Xml::submitButton(
                        $value,
                        array(
-                               'class' => 'mw-htmlform-submit',
+                               'class' => 'mw-htmlform-submit ' . $this->mClass,
                                'name' => $this->mName,
                                'id' => $this->mID,
                        )
@@ -2016,84 +2019,3 @@ class HTMLEditTools extends HTMLFormField {
                        . "</div></td></tr>\n";
        }
 }
-
-/**
- * Dropdown for namespaces
- */
-class HTMLNamespacesField extends HTMLSelectField {
-       function __construct( $params ) {
-               global $wgContLang;
-               parent::__construct( $params );
-
-               $namespaces = $wgContLang->getFormattedNamespaces();
-
-               $options = array();
-               $options[ wfMessage( 'namespacesall' )->escaped() ] = ''; // TODO: Make an option
-
-               foreach ( $namespaces as $index => $name ) {
-                       // Don't include things like SpecialPages
-                       if ( $index < NS_MAIN ) {
-                               continue;
-                       }
-
-                       if ( $index === 0 ) {
-                               $name = wfMessage( 'blanknamespace' )->escaped();
-                       }
-
-                       $options[$name] = $index;
-               }
-
-               $this->mParams['options'] = $options;
-       }
-}
-
-/**
- * Dropdown for protection levels
- */
-class HTMLRestrictionLevelsField extends HTMLSelectField {
-
-       /**
-        * Should this field be displayed? If it hits a condition where it should
-        * be hidden, set this to false.
-        *
-        * @var bool
-        */
-       protected $enabled = true;
-
-       function __construct( $params ) {
-               global $wgRestrictionLevels;
-               parent::__construct( $params );
-
-               $options = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
-
-               // First pass to load the level names
-               foreach( $wgRestrictionLevels as $type ) {
-                       if ( $type != '' && $type != '*' ) {
-                               $text = wfMsg("restriction-level-$type");
-                               $options[$text] = $type;
-                       }
-               }
-
-               // Is there only one level (aside from "all")?
-               if( count($options) <= 2 ) {
-                       $this->enabled = false;
-                       return;
-               }
-
-               $this->mParams['options'] = $options;
-       }
-
-       /**
-        * Returns false where
-        *
-        * @param $value
-        * @return String
-        */
-       function getTableRow( $value ) {
-               if ( $this->enabled ) {
-                       return parent::getTableRow( $value );
-               }
-
-               return '';
-       }
-}
\ No newline at end of file