Fix regression in r53316, some more intelligent handling.
[lhc/web/wiklou.git] / includes / HTMLForm.php
1 <?php
2
3 class HTMLForm {
4
5 static $jsAdded = false;
6
7 /* The descriptor is an array of arrays.
8 i.e. array(
9 'fieldname' => array( 'section' => 'section/subsection',
10 properties... ),
11 ...
12 )
13 */
14
15 static $typeMappings = array(
16 'text' => 'HTMLTextField',
17 'select' => 'HTMLSelectField',
18 'radio' => 'HTMLRadioField',
19 'multiselect' => 'HTMLMultiSelectField',
20 'check' => 'HTMLCheckField',
21 'toggle' => 'HTMLCheckField',
22 'int' => 'HTMLIntField',
23 'float' => 'HTMLFloatField',
24 'info' => 'HTMLInfoField',
25 'selectorother' => 'HTMLSelectOrOtherField',
26 );
27
28 function __construct( $descriptor, $messagePrefix ) {
29 $this->mMessagePrefix = $messagePrefix;
30
31 // Expand out into a tree.
32 $loadedDescriptor = array();
33 $this->mFlatFields = array();
34
35 foreach( $descriptor as $fieldname => $info ) {
36 $section = '';
37 if ( isset( $info['section'] ) )
38 $section = $info['section'];
39
40 $info['name'] = $fieldname;
41
42 $field = $this->loadInputFromParameters( $info );
43 $field->mParent = $this;
44
45 $setSection =& $loadedDescriptor;
46 if( $section ) {
47 $sectionParts = explode( '/', $section );
48
49 while( count( $sectionParts ) ) {
50 $newName = array_shift( $sectionParts );
51
52 if ( !isset( $setSection[$newName] ) ) {
53 $setSection[$newName] = array();
54 }
55
56 $setSection =& $setSection[$newName];
57 }
58 }
59
60 $setSection[$fieldname] = $field;
61 $this->mFlatFields[$fieldname] = $field;
62 }
63
64 $this->mFieldTree = $loadedDescriptor;
65
66 $this->mShowReset = true;
67 }
68
69 static function addJS() {
70 if( self::$jsAdded ) return;
71
72 global $wgOut, $wgStylePath;
73
74 $wgOut->addScriptFile( "$wgStylePath/common/htmlform.js" );
75 }
76
77 static function loadInputFromParameters( $descriptor ) {
78 if ( isset( $descriptor['class'] ) ) {
79 $class = $descriptor['class'];
80 } elseif ( isset( $descriptor['type'] ) ) {
81 $class = self::$typeMappings[$descriptor['type']];
82 $descriptor['class'] = $class;
83 }
84
85 if( !$class ) {
86 throw new MWException( "Descriptor with no class: " . print_r( $descriptor, true ) );
87 }
88
89 $obj = new $class( $descriptor );
90
91 return $obj;
92 }
93
94 function show() {
95 $html = '';
96
97 self::addJS();
98
99 // Load data from the request.
100 $this->loadData();
101
102 // Try a submission
103 global $wgUser, $wgRequest;
104 $editToken = $wgRequest->getVal( 'wpEditToken' );
105
106 $result = false;
107 if ( $wgUser->matchEditToken( $editToken ) )
108 $result = $this->trySubmit();
109
110 if( $result === true )
111 return $result;
112
113 // Display form.
114 $this->displayForm( $result );
115 }
116
117 /** Return values:
118 * TRUE == Successful submission
119 * FALSE == No submission attempted
120 * Anything else == Error to display.
121 */
122 function trySubmit() {
123 // Check for validation
124 foreach( $this->mFlatFields as $fieldname => $field ) {
125 if ( !empty( $field->mParams['nodata'] ) ) continue;
126 if ( $field->validate( $this->mFieldData[$fieldname],
127 $this->mFieldData ) !== true ) {
128 return isset( $this->mValidationErrorMessage ) ?
129 $this->mValidationErrorMessage : array( 'htmlform-invalid-input' );
130 }
131 }
132
133 $callback = $this->mSubmitCallback;
134
135 $data = $this->filterDataForSubmit( $this->mFieldData );
136
137 $res = call_user_func( $callback, $data );
138
139 return $res;
140 }
141
142 function setSubmitCallback( $cb ) {
143 $this->mSubmitCallback = $cb;
144 }
145
146 function setValidationErrorMessage( $msg ) {
147 $this->mValidationErrorMessage = $msg;
148 }
149
150 function setIntro( $msg ) {
151 $this->mIntro = $msg;
152 }
153
154 function displayForm( $submitResult ) {
155 global $wgOut;
156
157 if ( $submitResult !== false ) {
158 $this->displayErrors( $submitResult );
159 }
160
161 if ( isset( $this->mIntro ) ) {
162 $wgOut->addHTML( $this->mIntro );
163 }
164
165 $html = $this->getBody();
166
167 // Hidden fields
168 $html .= $this->getHiddenFields();
169
170 // Buttons
171 $html .= $this->getButtons();
172
173 $html = $this->wrapForm( $html );
174
175 $wgOut->addHTML( $html );
176 }
177
178 function wrapForm( $html ) {
179 return Xml::tags(
180 'form',
181 array(
182 'action' => $this->getTitle()->getFullURL(),
183 'method' => 'post',
184 ),
185 $html
186 );
187 }
188
189 function getHiddenFields() {
190 global $wgUser;
191 $html = '';
192
193 $html .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n";
194 $html .= Xml::hidden( 'title', $this->getTitle() ) . "\n";
195
196 return $html;
197 }
198
199 function getButtons() {
200 $html = '';
201
202 $attribs = array();
203
204 if ( isset( $this->mSubmitID ) )
205 $attribs['id'] = $this->mSubmitID;
206
207 $attribs['class'] = 'mw-htmlform-submit';
208
209 $html .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
210
211 if( $this->mShowReset ) {
212 $html .= Xml::element(
213 'input',
214 array(
215 'type' => 'reset',
216 'value' => wfMsg( 'htmlform-reset' )
217 )
218 ) . "\n";
219 }
220
221 return $html;
222 }
223
224 function getBody() {
225 return $this->displaySection( $this->mFieldTree );
226 }
227
228 function displayErrors( $errors ) {
229 if ( is_array( $errors ) ) {
230 $errorstr = $this->formatErrors( $errors );
231 } else {
232 $errorstr = $errors;
233 }
234
235 $errorstr = Xml::tags( 'div', array( 'class' => 'error' ), $errorstr );
236
237 global $wgOut;
238 $wgOut->addHTML( $errorstr );
239 }
240
241 static function formatErrors( $errors ) {
242 $errorstr = '';
243 foreach ( $errors as $error ) {
244 if( is_array( $error ) ) {
245 $msg = array_shift( $error );
246 } else {
247 $msg = $error;
248 $error = array();
249 }
250 $errorstr .= Xml::tags(
251 'li',
252 null,
253 wfMsgExt( $msg, array( 'parseinline' ), $error )
254 );
255 }
256
257 $errorstr = Xml::tags( 'ul', null, $errorstr );
258
259 return $errorstr;
260 }
261
262 function setSubmitText( $t ) {
263 $this->mSubmitText = $t;
264 }
265
266 function getSubmitText() {
267 return isset( $this->mSubmitText ) ? $this->mSubmitText : wfMsg( 'htmlform-submit' );
268 }
269
270 function setSubmitID( $t ) {
271 $this->mSubmitID = $t;
272 }
273
274 function setMessagePrefix( $p ) {
275 $this->mMessagePrefix = $p;
276 }
277
278 function setTitle( $t ) {
279 $this->mTitle = $t;
280 }
281
282 function getTitle() {
283 return $this->mTitle;
284 }
285
286 function displaySection( $fields ) {
287 $tableHtml = '';
288 $subsectionHtml = '';
289 $hasLeftColumn = false;
290
291 foreach( $fields as $key => $value ) {
292 if ( is_object( $value ) ) {
293 $v = empty( $value->mParams['nodata'] )
294 ? $this->mFieldData[$key]
295 : $value->getDefault();
296 $tableHtml .= $value->getTableRow( $v );
297
298 if( $value->getLabel() != '&nbsp;' )
299 $hasLeftColumn = true;
300 } elseif ( is_array( $value ) ) {
301 $section = $this->displaySection( $value );
302 $legend = wfMsg( "{$this->mMessagePrefix}-$key" );
303 $subsectionHtml .= Xml::fieldset( $legend, $section ) . "\n";
304 }
305 }
306
307 $classes = array();
308 if( !$hasLeftColumn ) // Avoid strange spacing when no labels exist
309 $classes[] = 'mw-htmlform-nolabel';
310 $classes = implode( ' ', $classes );
311
312 $tableHtml = "<table class='$classes'><tbody>\n$tableHtml\n</tbody></table>\n";
313
314 return $subsectionHtml . "\n" . $tableHtml;
315 }
316
317 function loadData() {
318 global $wgRequest;
319
320 $fieldData = array();
321
322 foreach( $this->mFlatFields as $fieldname => $field ) {
323 if ( !empty( $field->mParams['nodata'] ) ) continue;
324 if ( !empty( $field->mParams['disabled'] ) ) {
325 $fieldData[$fieldname] = $field->getDefault();
326 } else {
327 $fieldData[$fieldname] = $field->loadDataFromRequest( $wgRequest );
328 }
329 }
330
331 // Filter data.
332 foreach( $fieldData as $name => &$value ) {
333 $field = $this->mFlatFields[$name];
334 $value = $field->filter( $value, $this->mFlatFields );
335 }
336
337 $this->mFieldData = $fieldData;
338 }
339
340 function importData( $fieldData ) {
341 // Filter data.
342 foreach( $fieldData as $name => &$value ) {
343 $field = $this->mFlatFields[$name];
344 $value = $field->filter( $value, $this->mFlatFields );
345 }
346
347 foreach( $this->mFlatFields as $fieldname => $field ) {
348 if ( !isset( $fieldData[$fieldname] ) )
349 $fieldData[$fieldname] = $field->getDefault();
350 }
351
352 $this->mFieldData = $fieldData;
353 }
354
355 function suppressReset( $suppressReset = true ) {
356 $this->mShowReset = !$suppressReset;
357 }
358
359 function filterDataForSubmit( $data ) {
360 return $data;
361 }
362 }
363
364 abstract class HTMLFormField {
365 abstract function getInputHTML( $value );
366
367 function validate( $value, $alldata ) {
368 if ( isset( $this->mValidationCallback ) ) {
369 return call_user_func( $this->mValidationCallback, $value, $alldata );
370 }
371
372 return true;
373 }
374
375 function filter( $value, $alldata ) {
376 if( isset( $this->mFilterCallback ) ) {
377 $value = call_user_func( $this->mFilterCallback, $value, $alldata );
378 }
379
380 return $value;
381 }
382
383 function loadDataFromRequest( $request ) {
384 if( $request->getCheck( $this->mName ) ) {
385 return $request->getText( $this->mName );
386 } else {
387 return $this->getDefault();
388 }
389 }
390
391 function __construct( $params ) {
392 $this->mParams = $params;
393
394 if( isset( $params['label-message'] ) ) {
395 $msgInfo = $params['label-message'];
396
397 if ( is_array( $msgInfo ) ) {
398 $msg = array_shift( $msgInfo );
399 } else {
400 $msg = $msgInfo;
401 $msgInfo = array();
402 }
403
404 $this->mLabel = wfMsgExt( $msg, 'parseinline', $msgInfo );
405 } elseif ( isset( $params['label'] ) ) {
406 $this->mLabel = $params['label'];
407 }
408
409 if ( isset( $params['name'] ) ) {
410 $name = $params['name'];
411 $validName = Sanitizer::escapeId( $name );
412 if( $name != $validName ) {
413 throw new MWException("Invalid name '$name' passed to " . __METHOD__ );
414 }
415 $this->mName = 'wp'.$name;
416 $this->mID = 'mw-input-'.$name;
417 }
418
419 if ( isset( $params['default'] ) ) {
420 $this->mDefault = $params['default'];
421 }
422
423 if ( isset( $params['id'] ) ) {
424 $id = $params['id'];
425 $validId = Sanitizer::escapeId( $id );
426 if( $id != $validId ) {
427 throw new MWException("Invalid id '$id' passed to " . __METHOD__ );
428 }
429 $this->mID = $id;
430 }
431
432 if ( isset( $params['validation-callback'] ) ) {
433 $this->mValidationCallback = $params['validation-callback'];
434 }
435
436 if ( isset( $params['filter-callback'] ) ) {
437 $this->mFilterCallback = $params['filter-callback'];
438 }
439 }
440
441 function getTableRow( $value ) {
442 // Check for invalid data.
443 global $wgRequest;
444
445 $errors = $this->validate( $value, $this->mParent->mFieldData );
446 if ( $errors === true || !$wgRequest->wasPosted() ) {
447 $errors = '';
448 } else {
449 $errors = Xml::tags( 'span', array( 'class' => 'error' ), $errors );
450 }
451
452 $html = '';
453
454 $html .= Xml::tags( 'td', array( 'class' => 'mw-label' ),
455 Xml::tags( 'label', array( 'for' => $this->mID ), $this->getLabel() )
456 );
457 $html .= Xml::tags( 'td', array( 'class' => 'mw-input' ),
458 $this->getInputHTML( $value ) ."\n$errors" );
459
460 $fieldType = get_class( $this );
461
462 $html = Xml::tags( 'tr', array( 'class' => "mw-htmlform-field-$fieldType" ),
463 $html ) . "\n";
464
465 $helptext = null;
466 if ( isset( $this->mParams['help-message'] ) ) {
467 $msg = $this->mParams['help-message'];
468 $helptext = wfMsgExt( $msg, 'parseinline' );
469 if ( wfEmptyMsg( $msg, $helptext ) ) {
470 # Never mind
471 $helptext = null;
472 }
473 } elseif ( isset( $this->mParams['help'] ) ) {
474 $helptext = $this->mParams['help'];
475 }
476
477 if ( !is_null( $helptext ) ) {
478 $row = Xml::tags( 'td', array( 'colspan' => 2, 'class' => 'htmlform-tip' ),
479 $helptext );
480 $row = Xml::tags( 'tr', null, $row );
481 $html .= "$row\n";
482 }
483
484 return $html;
485 }
486
487 function getLabel() {
488 return $this->mLabel;
489 }
490
491 function getDefault() {
492 if ( isset( $this->mDefault ) ) {
493 return $this->mDefault;
494 } else {
495 return null;
496 }
497 }
498
499 static function flattenOptions( $options ) {
500 $flatOpts = array();
501
502 foreach( $options as $key => $value ) {
503 if ( is_array( $value ) ) {
504 $flatOpts = array_merge( $flatOpts, self::flattenOptions( $value ) );
505 } else {
506 $flatOpts[] = $value;
507 }
508 }
509
510 return $flatOpts;
511 }
512 }
513
514 class HTMLTextField extends HTMLFormField {
515
516 function getSize() {
517 return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45;
518 }
519
520 function getInputHTML( $value ) {
521 $attribs = array( 'id' => $this->mID );
522
523 if ( isset( $this->mParams['maxlength'] ) ) {
524 $attribs['maxlength'] = $this->mParams['maxlength'];
525 }
526
527 if( !empty( $this->mParams['disabled'] ) ) {
528 $attribs['disabled'] = 'disabled';
529 }
530
531 return Xml::input(
532 $this->mName,
533 $this->getSize(),
534 $value,
535 $attribs
536 );
537 }
538
539 }
540
541 class HTMLFloatField extends HTMLTextField {
542 function getSize() {
543 return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 20;
544 }
545
546 function validate( $value, $alldata ) {
547 $p = parent::validate( $value, $alldata );
548
549 if ( $p !== true ) return $p;
550
551 if ( floatval( $value ) != $value ) {
552 return wfMsgExt( 'htmlform-float-invalid', 'parse' );
553 }
554
555 $in_range = true;
556
557 # The "int" part of these message names is rather confusing. They make
558 # equal sense for all numbers.
559 if ( isset( $this->mParams['min'] ) ) {
560 $min = $this->mParams['min'];
561 if ( $min > $value )
562 return wfMsgExt( 'htmlform-int-toolow', 'parse', array( $min ) );
563 }
564
565 if ( isset( $this->mParams['max'] ) ) {
566 $max = $this->mParams['max'];
567 if( $max < $value )
568 return wfMsgExt( 'htmlform-int-toohigh', 'parse', array( $max ) );
569 }
570
571 return true;
572 }
573 }
574
575 class HTMLIntField extends HTMLFloatField {
576 function validate( $value, $alldata ) {
577 $p = parent::validate( $value, $alldata );
578
579 if ( $p !== true ) return $p;
580
581 if ( intval( $value ) != $value ) {
582 return wfMsgExt( 'htmlform-int-invalid', 'parse' );
583 }
584
585 return true;
586 }
587 }
588
589 class HTMLCheckField extends HTMLFormField {
590 function getInputHTML( $value ) {
591 if ( !empty( $this->mParams['invert'] ) )
592 $value = !$value;
593
594 $attr = array( 'id' => $this->mID );
595 if( !empty( $this->mParams['disabled'] ) ) {
596 $attr['disabled'] = 'disabled';
597 }
598
599 return Xml::check( $this->mName, $value, $attr ) . '&nbsp;' .
600 Xml::tags( 'label', array( 'for' => $this->mID ), $this->mLabel );
601 }
602
603 function getLabel() {
604 return '&nbsp;'; // In the right-hand column.
605 }
606
607 function loadDataFromRequest( $request ) {
608 $invert = false;
609 if ( isset( $this->mParams['invert'] ) && $this->mParams['invert'] ) {
610 $invert = true;
611 }
612
613 // GetCheck won't work like we want for checks.
614 if( $request->getCheck( 'wpEditToken' ) ) {
615 // XOR has the following truth table, which is what we want
616 // INVERT VALUE | OUTPUT
617 // true true | false
618 // false true | true
619 // false false | false
620 // true false | true
621 return $request->getBool( $this->mName ) xor $invert;
622 } else {
623 return $this->getDefault();
624 }
625 }
626 }
627
628 class HTMLSelectField extends HTMLFormField {
629
630 function validate( $value, $alldata ) {
631 $p = parent::validate( $value, $alldata );
632 if( $p !== true ) return $p;
633
634 $validOptions = HTMLFormField::flattenOptions( $this->mParams['options'] );
635 if ( in_array( $value, $validOptions ) )
636 return true;
637 else
638 return wfMsgExt( 'htmlform-select-badoption', 'parseinline' );
639 }
640
641 function getInputHTML( $value ) {
642 $select = new XmlSelect( $this->mName, $this->mID, strval( $value ) );
643
644 // If one of the options' 'name' is int(0), it is automatically selected.
645 // because PHP sucks and things int(0) == 'some string'.
646 // Working around this by forcing all of them to strings.
647 $options = array_map( 'strval', $this->mParams['options'] );
648
649 if( !empty( $this->mParams['disabled'] ) ) {
650 $select->setAttribute( 'disabled', 'disabled' );
651 }
652
653 $select->addOptions( $options );
654
655 return $select->getHTML();
656 }
657 }
658
659 class HTMLSelectOrOtherField extends HTMLTextField {
660 static $jsAdded = false;
661
662 function __construct( $params ) {
663 if( !in_array( 'other', $params['options'] ) ) {
664 $params['options'][wfMsg( 'htmlform-selectorother-other' )] = 'other';
665 }
666
667 parent::__construct( $params );
668 }
669
670 static function forceToStringRecursive( $array ) {
671 if ( is_array($array) ) {
672 return array_map( array( __CLASS__, 'forceToStringRecursive' ), $array);
673 } else {
674 return strval($array);
675 }
676 }
677
678 function getInputHTML( $value ) {
679 $valInSelect = false;
680
681 if( $value !== false )
682 $valInSelect = in_array( $value,
683 HTMLFormField::flattenOptions( $this->mParams['options'] ) );
684
685 $selected = $valInSelect ? $value : 'other';
686
687 $opts = self::forceToStringRecursive( $this->mParams['options'] );
688
689 $select = new XmlSelect( $this->mName, $this->mID, $selected );
690 $select->addOptions( $opts );
691
692 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
693
694 $tbAttribs = array( 'id' => $this->mID . '-other' );
695 if( !empty( $this->mParams['disabled'] ) ) {
696 $select->setAttribute( 'disabled', 'disabled' );
697 $tbAttribs['disabled'] = 'disabled';
698 }
699
700 $select = $select->getHTML();
701
702 if ( isset( $this->mParams['maxlength'] ) ) {
703 $tbAttribs['maxlength'] = $this->mParams['maxlength'];
704 }
705
706 $textbox = Xml::input( $this->mName . '-other',
707 $this->getSize(),
708 $valInSelect ? '' : $value,
709 $tbAttribs );
710
711 return "$select<br/>\n$textbox";
712 }
713
714 function loadDataFromRequest( $request ) {
715 if( $request->getCheck( $this->mName ) ) {
716 $val = $request->getText( $this->mName );
717
718 if( $val == 'other' ) {
719 $val = $request->getText( $this->mName . '-other' );
720 }
721
722 return $val;
723 } else {
724 return $this->getDefault();
725 }
726 }
727 }
728
729 class HTMLMultiSelectField extends HTMLFormField {
730 function validate( $value, $alldata ) {
731 $p = parent::validate( $value, $alldata );
732 if( $p !== true ) return $p;
733
734 if( !is_array( $value ) ) return false;
735
736 // If all options are valid, array_intersect of the valid options and the provided
737 // options will return the provided options.
738 $validOptions = HTMLFormField::flattenOptions( $this->mParams['options'] );
739
740 $validValues = array_intersect( $value, $validOptions );
741 if ( count( $validValues ) == count( $value ) )
742 return true;
743 else
744 return wfMsgExt( 'htmlform-select-badoption', 'parseinline' );
745 }
746
747 function getInputHTML( $value ) {
748 $html = $this->formatOptions( $this->mParams['options'], $value );
749
750 return $html;
751 }
752
753 function formatOptions( $options, $value ) {
754 $html = '';
755
756 $attribs = array();
757 if ( !empty( $this->mParams['disabled'] ) ) {
758 $attribs['disabled'] = 'disabled';
759 }
760
761 foreach( $options as $label => $info ) {
762 if( is_array( $info ) ) {
763 $html .= Xml::tags( 'h1', null, $label ) . "\n";
764 $html .= $this->formatOptions( $info, $value );
765 } else {
766 $thisAttribs = array( 'id' => $this->mID . "-$info", 'value' => $info );
767
768 $checkbox = Xml::check( $this->mName . '[]', in_array( $info, $value ),
769 $attribs + $thisAttribs );
770 $checkbox .= '&nbsp;' . Xml::tags( 'label', array( 'for' => $this->mID . "-$info" ), $label );
771
772 $html .= $checkbox . '<br />';
773 }
774 }
775
776 return $html;
777 }
778
779 function loadDataFromRequest( $request ) {
780 // won't work with getCheck
781 if( $request->getCheck( 'wpEditToken' ) ) {
782 $arr = $request->getArray( $this->mName );
783
784 if( !$arr )
785 $arr = array();
786
787 return $arr;
788 } else {
789 return $this->getDefault();
790 }
791 }
792
793 function getDefault() {
794 if ( isset( $this->mDefault ) ) {
795 return $this->mDefault;
796 } else {
797 return array();
798 }
799 }
800 }
801
802 class HTMLRadioField extends HTMLFormField {
803 function validate( $value, $alldata ) {
804 $p = parent::validate( $value, $alldata );
805 if( $p !== true ) return $p;
806
807 if( !is_string( $value ) && !is_int( $value ) )
808 return false;
809
810 $validOptions = HTMLFormField::flattenOptions( $this->mParams['options'] );
811
812 if ( in_array( $value, $validOptions ) )
813 return true;
814 else
815 return wfMsgExt( 'htmlform-select-badoption', 'parseinline' );
816 }
817
818 function getInputHTML( $value ) {
819 $html = $this->formatOptions( $this->mParams['options'], $value );
820
821 return $html;
822 }
823
824 function formatOptions( $options, $value ) {
825 $html = '';
826
827 $attribs = array();
828 if ( !empty( $this->mParams['disabled'] ) ) {
829 $attribs['disabled'] = 'disabled';
830 }
831
832 foreach( $options as $label => $info ) {
833 if( is_array( $info ) ) {
834 $html .= Xml::tags( 'h1', null, $label ) . "\n";
835 $html .= $this->formatOptions( $info, $value );
836 } else {
837 $id = Sanitizer::escapeId( $this->mID . "-$info" );
838 $html .= Xml::radio( $this->mName, $info, $info == $value,
839 $attribs + array( 'id' => $id ) );
840 $html .= '&nbsp;' .
841 Xml::tags( 'label', array( 'for' => $id ), $label );
842
843 $html .= "<br/>\n";
844 }
845 }
846
847 return $html;
848 }
849 }
850
851 class HTMLInfoField extends HTMLFormField {
852 function __construct( $info ) {
853 $info['nodata'] = true;
854
855 parent::__construct( $info );
856 }
857
858 function getInputHTML( $value ) {
859 return !empty( $this->mParams['raw'] ) ? $value : htmlspecialchars( $value );
860 }
861
862 function getTableRow( $value ) {
863 if ( !empty( $this->mParams['rawrow'] ) ) {
864 return $value;
865 }
866
867 return parent::getTableRow( $value );
868 }
869 }