http://www.mediawiki.org/wiki/Special:Code/MediaWiki/83747

Revision: 83747
Author:   happy-melon
Date:     2011-03-12 11:08:20 +0000 (Sat, 12 Mar 2011)
Log Message:
-----------
Follow-up r83298: keep the two elements of the message separate in an array in 
HTMLSelectAndOtherField::loadDataFromRequest(), fixes various bugs with 
validation, defaults, and normalisation.

Modified Paths:
--------------
    trunk/phase3/includes/HTMLForm.php

Modified: trunk/phase3/includes/HTMLForm.php
===================================================================
--- trunk/phase3/includes/HTMLForm.php  2011-03-12 03:29:34 UTC (rev 83746)
+++ trunk/phase3/includes/HTMLForm.php  2011-03-12 11:08:20 UTC (rev 83747)
@@ -1533,9 +1533,8 @@
        }
 
        function getInputHTML( $value ) {
+               $select = parent::getInputHTML( $value[1] );
 
-               $select = parent::getInputHTML( $value );
-
                $textAttribs = array(
                        'id' => $this->mID . '-other',
                        'size' => $this->getSize(),
@@ -1549,7 +1548,7 @@
 
                $textbox = Html::input(
                        $this->mName . '-other',
-                       '',
+                       $value[2],
                        'text',
                        $textAttribs
                );
@@ -1557,6 +1556,10 @@
                return "$select<br />\n$textbox";
        }
 
+       /**
+        * @param  $request WebRequest
+        * @return Array( <overall message>, <select value>, <text field value> 
)
+        */
        function loadDataFromRequest( $request ) {
                if ( $request->getCheck( $this->mName ) ) {
 
@@ -1564,27 +1567,22 @@
                        $text = $request->getText( $this->mName . '-other' );
 
                        if ( $list == 'other' ) {
-                               return $text;
+                               $final = $text;
+                       } elseif( !in_array( $list, $this->mFlatOptions ) ){
+                               # User has spoofed the select form to give an 
option which wasn't
+                               # in the original offer.  Sulk...
+                               $final = $text;
+                       } elseif( $text == '' ) {
+                               $final = $list;
                        } else {
-                               # Need to get the value from the key
-                               if( in_array( $list, $this->mFlatOptions ) ){
-                                       $list = $this->mFlatOptions[$list];
-                               } else {
-                                       # User has spoofed the select form to 
give an option which wasn't
-                                       # in the original offer.  Sulk...
-                                       return $text;
-                               }
+                               $final = $list . wfMsgForContent( 
'colon-separator' ) . $text;
                        }
 
-                       if( $text == '' ) {
-                               return $list;
-                       } else {
-                               return $list . wfMsgForContent( 
'colon-separator' ) . $text;
-                       }
-
                } else {
-                       return $this->getDefault();
+                       $final = $this->getDefault();
+                       $list = $text = '';
                }
+               return array( $final, $list, $text );
        }
 
        function getSize() {
@@ -1592,6 +1590,23 @@
                        ? $this->mParams['size']
                        : 45;
        }
+
+       function validate( $value, $alldata ) {
+               # HTMLSelectField forces $value to be one of the options in the 
select
+               # field, which is not useful here.  But we do want the 
validation further up
+               # the chain
+               $p = parent::validate( $value[1], $alldata );
+
+               if ( $p !== true ) {
+                       return $p;
+               }
+
+               if( isset( $this->mParams['required'] ) && $value[1] === '' ){
+                       return wfMsgExt( 'htmlform-required', 'parseinline' );
+               }
+
+               return true;
+       }
 }
 
 /**


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to