Use wfMessage() instead of wfMsgGetKey()
[lhc/web/wiklou.git] / includes / HTMLForm.php
1 <?php
2 /**
3 * Object handling generic submission, CSRF protection, layout and
4 * other logic for UI forms. in a reusable manner.
5 *
6 * In order to generate the form, the HTMLForm object takes an array
7 * structure detailing the form fields available. Each element of the
8 * array is a basic property-list, including the type of field, the
9 * label it is to be given in the form, callbacks for validation and
10 * 'filtering', and other pertinent information.
11 *
12 * Field types are implemented as subclasses of the generic HTMLFormField
13 * object, and typically implement at least getInputHTML, which generates
14 * the HTML for the input field to be placed in the table.
15 *
16 * The constructor input is an associative array of $fieldname => $info,
17 * where $info is an Associative Array with any of the following:
18 *
19 * 'class' -- the subclass of HTMLFormField that will be used
20 * to create the object. *NOT* the CSS class!
21 * 'type' -- roughly translates into the <select> type attribute.
22 * if 'class' is not specified, this is used as a map
23 * through HTMLForm::$typeMappings to get the class name.
24 * 'default' -- default value when the form is displayed
25 * 'id' -- HTML id attribute
26 * 'cssclass' -- CSS class
27 * 'options' -- varies according to the specific object.
28 * 'label-message' -- message key for a message to use as the label.
29 * can be an array of msg key and then parameters to
30 * the message.
31 * 'label' -- alternatively, a raw text message. Overridden by
32 * label-message
33 * 'help-message' -- message key for a message to use as a help text.
34 * can be an array of msg key and then parameters to
35 * the message.
36 * Overwrites 'help-messages'.
37 * 'help-messages' -- array of message key. As above, each item can
38 * be an array of msg key and then parameters.
39 * Overwrites 'help-message'.
40 * 'required' -- passed through to the object, indicating that it
41 * is a required field.
42 * 'size' -- the length of text fields
43 * 'filter-callback -- a function name to give you the chance to
44 * massage the inputted value before it's processed.
45 * @see HTMLForm::filter()
46 * 'validation-callback' -- a function name to give you the chance
47 * to impose extra validation on the field input.
48 * @see HTMLForm::validate()
49 * 'name' -- By default, the 'name' attribute of the input field
50 * is "wp{$fieldname}". If you want a different name
51 * (eg one without the "wp" prefix), specify it here and
52 * it will be used without modification.
53 *
54 * TODO: Document 'section' / 'subsection' stuff
55 */
56 class HTMLForm {
57 static $jsAdded = false;
58
59 # A mapping of 'type' inputs onto standard HTMLFormField subclasses
60 static $typeMappings = array(
61 'text' => 'HTMLTextField',
62 'textarea' => 'HTMLTextAreaField',
63 'select' => 'HTMLSelectField',
64 'radio' => 'HTMLRadioField',
65 'multiselect' => 'HTMLMultiSelectField',
66 'check' => 'HTMLCheckField',
67 'toggle' => 'HTMLCheckField',
68 'int' => 'HTMLIntField',
69 'float' => 'HTMLFloatField',
70 'info' => 'HTMLInfoField',
71 'selectorother' => 'HTMLSelectOrOtherField',
72 'submit' => 'HTMLSubmitField',
73 'hidden' => 'HTMLHiddenField',
74 'edittools' => 'HTMLEditTools',
75
76 # HTMLTextField will output the correct type="" attribute automagically.
77 # There are about four zillion other HTML5 input types, like url, but
78 # we don't use those at the moment, so no point in adding all of them.
79 'email' => 'HTMLTextField',
80 'password' => 'HTMLTextField',
81 );
82
83 protected $mMessagePrefix;
84 protected $mFlatFields;
85 protected $mFieldTree;
86 protected $mShowReset = false;
87 public $mFieldData;
88
89 protected $mSubmitCallback;
90 protected $mValidationErrorMessage;
91
92 protected $mPre = '';
93 protected $mHeader = '';
94 protected $mFooter = '';
95 protected $mSectionHeaders = array();
96 protected $mSectionFooters = array();
97 protected $mPost = '';
98 protected $mId;
99
100 protected $mSubmitID;
101 protected $mSubmitName;
102 protected $mSubmitText;
103 protected $mSubmitTooltip;
104 protected $mTitle;
105 protected $mMethod = 'post';
106
107 protected $mUseMultipart = false;
108 protected $mHiddenFields = array();
109 protected $mButtons = array();
110
111 protected $mWrapperLegend = false;
112
113 /**
114 * Build a new HTMLForm from an array of field attributes
115 * @param $descriptor Array of Field constructs, as described above
116 * @param $messagePrefix String a prefix to go in front of default messages
117 */
118 public function __construct( $descriptor, $messagePrefix = '' ) {
119 $this->mMessagePrefix = $messagePrefix;
120
121 // Expand out into a tree.
122 $loadedDescriptor = array();
123 $this->mFlatFields = array();
124
125 foreach ( $descriptor as $fieldname => $info ) {
126 $section = isset( $info['section'] )
127 ? $info['section']
128 : '';
129
130 if ( isset( $info['type'] ) && $info['type'] == 'file' ) {
131 $this->mUseMultipart = true;
132 }
133
134 $field = self::loadInputFromParameters( $fieldname, $info );
135 $field->mParent = $this;
136
137 $setSection =& $loadedDescriptor;
138 if ( $section ) {
139 $sectionParts = explode( '/', $section );
140
141 while ( count( $sectionParts ) ) {
142 $newName = array_shift( $sectionParts );
143
144 if ( !isset( $setSection[$newName] ) ) {
145 $setSection[$newName] = array();
146 }
147
148 $setSection =& $setSection[$newName];
149 }
150 }
151
152 $setSection[$fieldname] = $field;
153 $this->mFlatFields[$fieldname] = $field;
154 }
155
156 $this->mFieldTree = $loadedDescriptor;
157 }
158
159 /**
160 * Add the HTMLForm-specific JavaScript, if it hasn't been
161 * done already.
162 */
163 static function addJS() {
164 if ( self::$jsAdded ) return;
165
166 global $wgOut;
167
168 $wgOut->addModules( 'mediawiki.legacy.htmlform' );
169 }
170
171 /**
172 * Initialise a new Object for the field
173 * @param $descriptor input Descriptor, as described above
174 * @return HTMLFormField subclass
175 */
176 static function loadInputFromParameters( $fieldname, $descriptor ) {
177 if ( isset( $descriptor['class'] ) ) {
178 $class = $descriptor['class'];
179 } elseif ( isset( $descriptor['type'] ) ) {
180 $class = self::$typeMappings[$descriptor['type']];
181 $descriptor['class'] = $class;
182 }
183
184 if ( !$class ) {
185 throw new MWException( "Descriptor with no class: " . print_r( $descriptor, true ) );
186 }
187
188 $descriptor['fieldname'] = $fieldname;
189
190 $obj = new $class( $descriptor );
191
192 return $obj;
193 }
194
195 /**
196 * Prepare form for submission
197 */
198 function prepareForm() {
199 # Check if we have the info we need
200 if ( ! $this->mTitle ) {
201 throw new MWException( "You must call setTitle() on an HTMLForm" );
202 }
203
204 // FIXME shouldn't this be closer to displayForm() ?
205 self::addJS();
206
207 # Load data from the request.
208 $this->loadData();
209 }
210
211 /**
212 * Try submitting, with edit token check first
213 * @return Status|boolean
214 */
215 function tryAuthorizedSubmit() {
216 global $wgUser, $wgRequest;
217 $editToken = $wgRequest->getVal( 'wpEditToken' );
218
219 $result = false;
220 if ( $this->getMethod() != 'post' || $wgUser->matchEditToken( $editToken ) ) {
221 $result = $this->trySubmit();
222 }
223 return $result;
224 }
225
226 /**
227 * The here's-one-I-made-earlier option: do the submission if
228 * posted, or display the form with or without funky valiation
229 * errors
230 * @return Bool or Status whether submission was successful.
231 */
232 function show() {
233 $this->prepareForm();
234
235 $result = $this->tryAuthorizedSubmit();
236 if ( $result === true || ( $result instanceof Status && $result->isGood() ) ){
237 return $result;
238 }
239
240 $this->displayForm( $result );
241 return false;
242 }
243
244 /**
245 * Validate all the fields, and call the submision callback
246 * function if everything is kosher.
247 * @return Mixed Bool true == Successful submission, Bool false
248 * == No submission attempted, anything else == Error to
249 * display.
250 */
251 function trySubmit() {
252 # Check for validation
253 foreach ( $this->mFlatFields as $fieldname => $field ) {
254 if ( !empty( $field->mParams['nodata'] ) ) {
255 continue;
256 }
257 if ( $field->validate(
258 $this->mFieldData[$fieldname],
259 $this->mFieldData )
260 !== true
261 ) {
262 return isset( $this->mValidationErrorMessage )
263 ? $this->mValidationErrorMessage
264 : array( 'htmlform-invalid-input' );
265 }
266 }
267
268 $callback = $this->mSubmitCallback;
269
270 $data = $this->filterDataForSubmit( $this->mFieldData );
271
272 $res = call_user_func( $callback, $data );
273
274 return $res;
275 }
276
277 /**
278 * Set a callback to a function to do something with the form
279 * once it's been successfully validated.
280 * @param $cb String function name. The function will be passed
281 * the output from HTMLForm::filterDataForSubmit, and must
282 * return Bool true on success, Bool false if no submission
283 * was attempted, or String HTML output to display on error.
284 */
285 function setSubmitCallback( $cb ) {
286 $this->mSubmitCallback = $cb;
287 }
288
289 /**
290 * Set a message to display on a validation error.
291 * @param $msg Mixed String or Array of valid inputs to wfMsgExt()
292 * (so each entry can be either a String or Array)
293 */
294 function setValidationErrorMessage( $msg ) {
295 $this->mValidationErrorMessage = $msg;
296 }
297
298 /**
299 * Set the introductory message, overwriting any existing message.
300 * @param $msg String complete text of message to display
301 */
302 function setIntro( $msg ) { $this->mPre = $msg; }
303
304 /**
305 * Add introductory text.
306 * @param $msg String complete text of message to display
307 */
308 function addPreText( $msg ) { $this->mPre .= $msg; }
309
310 /**
311 * Add header text, inside the form.
312 * @param $msg String complete text of message to display
313 */
314 function addHeaderText( $msg, $section = null ) {
315 if ( is_null( $section ) ) {
316 $this->mHeader .= $msg;
317 } else {
318 if ( !isset( $this->mSectionHeaders[$section] ) ) {
319 $this->mSectionHeaders[$section] = '';
320 }
321 $this->mSectionHeaders[$section] .= $msg;
322 }
323 }
324
325 /**
326 * Add footer text, inside the form.
327 * @param $msg String complete text of message to display
328 */
329 function addFooterText( $msg, $section = null ) {
330 if ( is_null( $section ) ) {
331 $this->mFooter .= $msg;
332 } else {
333 if ( !isset( $this->mSectionFooters[$section] ) ) {
334 $this->mSectionFooters[$section] = '';
335 }
336 $this->mSectionFooters[$section] .= $msg;
337 }
338 }
339
340 /**
341 * Add text to the end of the display.
342 * @param $msg String complete text of message to display
343 */
344 function addPostText( $msg ) { $this->mPost .= $msg; }
345
346 /**
347 * Add a hidden field to the output
348 * @param $name String field name. This will be used exactly as entered
349 * @param $value String field value
350 * @param $attribs Array
351 */
352 public function addHiddenField( $name, $value, $attribs = array() ) {
353 $attribs += array( 'name' => $name );
354 $this->mHiddenFields[] = array( $value, $attribs );
355 }
356
357 public function addButton( $name, $value, $id = null, $attribs = null ) {
358 $this->mButtons[] = compact( 'name', 'value', 'id', 'attribs' );
359 }
360
361 /**
362 * Display the form (sending to wgOut), with an appropriate error
363 * message or stack of messages, and any validation errors, etc.
364 * @param $submitResult Mixed output from HTMLForm::trySubmit()
365 */
366 function displayForm( $submitResult ) {
367 global $wgOut;
368
369 # For good measure (it is the default)
370 $wgOut->preventClickjacking();
371
372 $html = ''
373 . $this->getErrors( $submitResult )
374 . $this->mHeader
375 . $this->getBody()
376 . $this->getHiddenFields()
377 . $this->getButtons()
378 . $this->mFooter
379 ;
380
381 $html = $this->wrapForm( $html );
382
383 $wgOut->addHTML( ''
384 . $this->mPre
385 . $html
386 . $this->mPost
387 );
388 }
389
390 /**
391 * Wrap the form innards in an actual <form> element
392 * @param $html String HTML contents to wrap.
393 * @return String wrapped HTML.
394 */
395 function wrapForm( $html ) {
396
397 # Include a <fieldset> wrapper for style, if requested.
398 if ( $this->mWrapperLegend !== false ) {
399 $html = Xml::fieldset( $this->mWrapperLegend, $html );
400 }
401 # Use multipart/form-data
402 $encType = $this->mUseMultipart
403 ? 'multipart/form-data'
404 : 'application/x-www-form-urlencoded';
405 # Attributes
406 $attribs = array(
407 'action' => $this->getTitle()->getFullURL(),
408 'method' => $this->mMethod,
409 'class' => 'visualClear',
410 'enctype' => $encType,
411 );
412 if ( !empty( $this->mId ) ) {
413 $attribs['id'] = $this->mId;
414 }
415
416 return Html::rawElement( 'form', $attribs, $html );
417 }
418
419 /**
420 * Get the hidden fields that should go inside the form.
421 * @return String HTML.
422 */
423 function getHiddenFields() {
424 global $wgUser;
425
426 $html = '';
427
428 if( $this->getMethod() == 'post' ){
429 $html .= Html::hidden( 'wpEditToken', $wgUser->editToken(), array( 'id' => 'wpEditToken' ) ) . "\n";
430 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
431 }
432
433 foreach ( $this->mHiddenFields as $data ) {
434 list( $value, $attribs ) = $data;
435 $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
436 }
437
438 return $html;
439 }
440
441 /**
442 * Get the submit and (potentially) reset buttons.
443 * @return String HTML.
444 */
445 function getButtons() {
446 $html = '';
447 $attribs = array();
448
449 if ( isset( $this->mSubmitID ) ) {
450 $attribs['id'] = $this->mSubmitID;
451 }
452
453 if ( isset( $this->mSubmitName ) ) {
454 $attribs['name'] = $this->mSubmitName;
455 }
456
457 if ( isset( $this->mSubmitTooltip ) ) {
458 global $wgUser;
459 $attribs += $wgUser->getSkin()->tooltipAndAccessKeyAttribs( $this->mSubmitTooltip );
460 }
461
462 $attribs['class'] = 'mw-htmlform-submit';
463
464 $html .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
465
466 if ( $this->mShowReset ) {
467 $html .= Html::element(
468 'input',
469 array(
470 'type' => 'reset',
471 'value' => wfMsg( 'htmlform-reset' )
472 )
473 ) . "\n";
474 }
475
476 foreach ( $this->mButtons as $button ) {
477 $attrs = array(
478 'type' => 'submit',
479 'name' => $button['name'],
480 'value' => $button['value']
481 );
482
483 if ( $button['attribs'] ) {
484 $attrs += $button['attribs'];
485 }
486
487 if ( isset( $button['id'] ) ) {
488 $attrs['id'] = $button['id'];
489 }
490
491 $html .= Html::element( 'input', $attrs );
492 }
493
494 return $html;
495 }
496
497 /**
498 * Get the whole body of the form.
499 */
500 function getBody() {
501 return $this->displaySection( $this->mFieldTree );
502 }
503
504 /**
505 * Format and display an error message stack.
506 * @param $errors Mixed String or Array of message keys
507 * @return String
508 */
509 function getErrors( $errors ) {
510 if ( $errors instanceof Status ) {
511 global $wgOut;
512 if ( $errors->isOK() ) {
513 $errorstr = '';
514 } else {
515 $errorstr = $wgOut->parse( $errors->getWikiText() );
516 }
517 } elseif ( is_array( $errors ) ) {
518 $errorstr = $this->formatErrors( $errors );
519 } else {
520 $errorstr = $errors;
521 }
522
523 return $errorstr
524 ? Html::rawElement( 'div', array( 'class' => 'error' ), $errorstr )
525 : '';
526 }
527
528 /**
529 * Format a stack of error messages into a single HTML string
530 * @param $errors Array of message keys/values
531 * @return String HTML, a <ul> list of errors
532 */
533 static function formatErrors( $errors ) {
534 $errorstr = '';
535
536 foreach ( $errors as $error ) {
537 if ( is_array( $error ) ) {
538 $msg = array_shift( $error );
539 } else {
540 $msg = $error;
541 $error = array();
542 }
543
544 $errorstr .= Html::rawElement(
545 'li',
546 null,
547 wfMsgExt( $msg, array( 'parseinline' ), $error )
548 );
549 }
550
551 $errorstr = Html::rawElement( 'ul', array(), $errorstr );
552
553 return $errorstr;
554 }
555
556 /**
557 * Set the text for the submit button
558 * @param $t String plaintext.
559 */
560 function setSubmitText( $t ) {
561 $this->mSubmitText = $t;
562 }
563
564 /**
565 * Get the text for the submit button, either customised or a default.
566 * @return unknown_type
567 */
568 function getSubmitText() {
569 return $this->mSubmitText
570 ? $this->mSubmitText
571 : wfMsg( 'htmlform-submit' );
572 }
573
574 public function setSubmitName( $name ) {
575 $this->mSubmitName = $name;
576 }
577
578 public function setSubmitTooltip( $name ) {
579 $this->mSubmitTooltip = $name;
580 }
581
582 /**
583 * Set the id for the submit button.
584 * @param $t String. FIXME: Integrity is *not* validated
585 */
586 function setSubmitID( $t ) {
587 $this->mSubmitID = $t;
588 }
589
590 public function setId( $id ) {
591 $this->mId = $id;
592 }
593 /**
594 * Prompt the whole form to be wrapped in a <fieldset>, with
595 * this text as its <legend> element.
596 * @param $legend String HTML to go inside the <legend> element.
597 * Will be escaped
598 */
599 public function setWrapperLegend( $legend ) { $this->mWrapperLegend = $legend; }
600
601 /**
602 * Set the prefix for various default messages
603 * TODO: currently only used for the <fieldset> legend on forms
604 * with multiple sections; should be used elsewhre?
605 * @param $p String
606 */
607 function setMessagePrefix( $p ) {
608 $this->mMessagePrefix = $p;
609 }
610
611 /**
612 * Set the title for form submission
613 * @param $t Title of page the form is on/should be posted to
614 */
615 function setTitle( $t ) {
616 $this->mTitle = $t;
617 }
618
619 /**
620 * Get the title
621 * @return Title
622 */
623 function getTitle() {
624 return $this->mTitle;
625 }
626
627 /**
628 * Set the method used to submit the form
629 * @param $method String
630 */
631 public function setMethod( $method='post' ){
632 $this->mMethod = $method;
633 }
634
635 public function getMethod(){
636 return $this->mMethod;
637 }
638
639 /**
640 * TODO: Document
641 * @param $fields
642 */
643 function displaySection( $fields, $sectionName = '' ) {
644 $tableHtml = '';
645 $subsectionHtml = '';
646 $hasLeftColumn = false;
647
648 foreach ( $fields as $key => $value ) {
649 if ( is_object( $value ) ) {
650 $v = empty( $value->mParams['nodata'] )
651 ? $this->mFieldData[$key]
652 : $value->getDefault();
653 $tableHtml .= $value->getTableRow( $v );
654
655 if ( $value->getLabel() != '&#160;' )
656 $hasLeftColumn = true;
657 } elseif ( is_array( $value ) ) {
658 $section = $this->displaySection( $value, $key );
659 $legend = wfMsg( "{$this->mMessagePrefix}-$key" );
660 if ( isset( $this->mSectionHeaders[$key] ) ) {
661 $section = $this->mSectionHeaders[$key] . $section;
662 }
663 if ( isset( $this->mSectionFooters[$key] ) ) {
664 $section .= $this->mSectionFooters[$key];
665 }
666 $subsectionHtml .= Xml::fieldset( $legend, $section ) . "\n";
667 }
668 }
669
670 $classes = array();
671
672 if ( !$hasLeftColumn ) { // Avoid strange spacing when no labels exist
673 $classes[] = 'mw-htmlform-nolabel';
674 }
675
676 $attribs = array(
677 'class' => implode( ' ', $classes ),
678 );
679
680 if ( $sectionName ) {
681 $attribs['id'] = Sanitizer::escapeId( "mw-htmlform-$sectionName" );
682 }
683
684 $tableHtml = Html::rawElement( 'table', $attribs,
685 Html::rawElement( 'tbody', array(), "\n$tableHtml\n" ) ) . "\n";
686
687 return $subsectionHtml . "\n" . $tableHtml;
688 }
689
690 /**
691 * Construct the form fields from the Descriptor array
692 */
693 function loadData() {
694 global $wgRequest;
695
696 $fieldData = array();
697
698 foreach ( $this->mFlatFields as $fieldname => $field ) {
699 if ( !empty( $field->mParams['nodata'] ) ) {
700 continue;
701 } elseif ( !empty( $field->mParams['disabled'] ) ) {
702 $fieldData[$fieldname] = $field->getDefault();
703 } else {
704 $fieldData[$fieldname] = $field->loadDataFromRequest( $wgRequest );
705 }
706 }
707
708 # Filter data.
709 foreach ( $fieldData as $name => &$value ) {
710 $field = $this->mFlatFields[$name];
711 $value = $field->filter( $value, $this->mFlatFields );
712 }
713
714 $this->mFieldData = $fieldData;
715 }
716
717 /**
718 * Stop a reset button being shown for this form
719 * @param $suppressReset Bool set to false to re-enable the
720 * button again
721 */
722 function suppressReset( $suppressReset = true ) {
723 $this->mShowReset = !$suppressReset;
724 }
725
726 /**
727 * Overload this if you want to apply special filtration routines
728 * to the form as a whole, after it's submitted but before it's
729 * processed.
730 * @param $data
731 * @return unknown_type
732 */
733 function filterDataForSubmit( $data ) {
734 return $data;
735 }
736 }
737
738 /**
739 * The parent class to generate form fields. Any field type should
740 * be a subclass of this.
741 */
742 abstract class HTMLFormField {
743
744 protected $mValidationCallback;
745 protected $mFilterCallback;
746 protected $mName;
747 public $mParams;
748 protected $mLabel; # String label. Set on construction
749 protected $mID;
750 protected $mClass = '';
751 protected $mDefault;
752 public $mParent;
753
754 /**
755 * This function must be implemented to return the HTML to generate
756 * the input object itself. It should not implement the surrounding
757 * table cells/rows, or labels/help messages.
758 * @param $value String the value to set the input to; eg a default
759 * text for a text input.
760 * @return String valid HTML.
761 */
762 abstract function getInputHTML( $value );
763
764 /**
765 * Override this function to add specific validation checks on the
766 * field input. Don't forget to call parent::validate() to ensure
767 * that the user-defined callback mValidationCallback is still run
768 * @param $value String the value the field was submitted with
769 * @param $alldata Array the data collected from the form
770 * @return Mixed Bool true on success, or String error to display.
771 */
772 function validate( $value, $alldata ) {
773 if ( isset( $this->mValidationCallback ) ) {
774 return call_user_func( $this->mValidationCallback, $value, $alldata );
775 }
776
777 if ( isset( $this->mParams['required'] ) && $value === '' ) {
778 return wfMsgExt( 'htmlform-required', 'parseinline' );
779 }
780
781 return true;
782 }
783
784 function filter( $value, $alldata ) {
785 if ( isset( $this->mFilterCallback ) ) {
786 $value = call_user_func( $this->mFilterCallback, $value, $alldata );
787 }
788
789 return $value;
790 }
791
792 /**
793 * Should this field have a label, or is there no input element with the
794 * appropriate id for the label to point to?
795 *
796 * @return bool True to output a label, false to suppress
797 */
798 protected function needsLabel() {
799 return true;
800 }
801
802 /**
803 * Get the value that this input has been set to from a posted form,
804 * or the input's default value if it has not been set.
805 * @param $request WebRequest
806 * @return String the value
807 */
808 function loadDataFromRequest( $request ) {
809 if ( $request->getCheck( $this->mName ) ) {
810 return $request->getText( $this->mName );
811 } else {
812 return $this->getDefault();
813 }
814 }
815
816 /**
817 * Initialise the object
818 * @param $params Associative Array. See HTMLForm doc for syntax.
819 */
820 function __construct( $params ) {
821 $this->mParams = $params;
822
823 # Generate the label from a message, if possible
824 if ( isset( $params['label-message'] ) ) {
825 $msgInfo = $params['label-message'];
826
827 if ( is_array( $msgInfo ) ) {
828 $msg = array_shift( $msgInfo );
829 } else {
830 $msg = $msgInfo;
831 $msgInfo = array();
832 }
833
834 $this->mLabel = wfMsgExt( $msg, 'parseinline', $msgInfo );
835 } elseif ( isset( $params['label'] ) ) {
836 $this->mLabel = $params['label'];
837 }
838
839 $this->mName = "wp{$params['fieldname']}";
840 if ( isset( $params['name'] ) ) {
841 $this->mName = $params['name'];
842 }
843
844 $validName = Sanitizer::escapeId( $this->mName );
845 if ( $this->mName != $validName && !isset( $params['nodata'] ) ) {
846 throw new MWException( "Invalid name '{$this->mName}' passed to " . __METHOD__ );
847 }
848
849 $this->mID = "mw-input-{$this->mName}";
850
851 if ( isset( $params['default'] ) ) {
852 $this->mDefault = $params['default'];
853 }
854
855 if ( isset( $params['id'] ) ) {
856 $id = $params['id'];
857 $validId = Sanitizer::escapeId( $id );
858
859 if ( $id != $validId ) {
860 throw new MWException( "Invalid id '$id' passed to " . __METHOD__ );
861 }
862
863 $this->mID = $id;
864 }
865
866 if ( isset( $params['cssclass'] ) ) {
867 $this->mClass = $params['cssclass'];
868 }
869
870 if ( isset( $params['validation-callback'] ) ) {
871 $this->mValidationCallback = $params['validation-callback'];
872 }
873
874 if ( isset( $params['filter-callback'] ) ) {
875 $this->mFilterCallback = $params['filter-callback'];
876 }
877 }
878
879 /**
880 * Get the complete table row for the input, including help text,
881 * labels, and whatever.
882 * @param $value String the value to set the input to.
883 * @return String complete HTML table row.
884 */
885 function getTableRow( $value ) {
886 # Check for invalid data.
887 global $wgRequest;
888
889 $errors = $this->validate( $value, $this->mParent->mFieldData );
890
891 $cellAttributes = array();
892 $verticalLabel = false;
893
894 if ( !empty($this->mParams['vertical-label']) ) {
895 $cellAttributes['colspan'] = 2;
896 $verticalLabel = true;
897 }
898
899 if ( $errors === true || ( !$wgRequest->wasPosted() && ( $this->mParent->getMethod() == 'post' ) ) ) {
900 $errors = '';
901 } else {
902 $errors = Html::rawElement( 'span', array( 'class' => 'error' ), $errors );
903 }
904
905 $label = $this->getLabelHtml( $cellAttributes );
906 $field = Html::rawElement(
907 'td',
908 array( 'class' => 'mw-input' ) + $cellAttributes,
909 $this->getInputHTML( $value ) . "\n$errors"
910 );
911
912 $fieldType = get_class( $this );
913
914 if ($verticalLabel) {
915 $html = Html::rawElement( 'tr',
916 array( 'class' => 'mw-htmlform-vertical-label' ), $label );
917 $html .= Html::rawElement( 'tr',
918 array( 'class' => "mw-htmlform-field-$fieldType {$this->mClass}" ),
919 $field );
920 } else {
921 $html = Html::rawElement( 'tr',
922 array( 'class' => "mw-htmlform-field-$fieldType {$this->mClass}" ),
923 $label . $field );
924 }
925
926 $helptext = null;
927
928 if ( isset( $this->mParams['help-message'] ) ) {
929 $msg = $this->mParams['help-message'];
930 $helptext = wfMsgExt( $msg, 'parseinline' );
931 if ( wfEmptyMsg( $msg, $helptext ) ) {
932 # Never mind
933 $helptext = null;
934 }
935 } elseif ( isset( $this->mParams['help-messages'] ) ) {
936 # help-message can be passed a message key (string) or an array containing
937 # a message key and additional parameters. This makes it impossible to pass
938 # an array of message key
939 foreach( $this->mParams['help-messages'] as $msg ) {
940 $candidate = wfMsgExt( $msg, 'parseinline' );
941 if( wfEmptyMsg( $msg ) ) {
942 $candidate = null;
943 }
944 $helptext .= $candidate; // append message
945 }
946 } elseif ( isset( $this->mParams['help'] ) ) {
947 $helptext = $this->mParams['help'];
948 }
949
950 if ( !is_null( $helptext ) ) {
951 $row = Html::rawElement( 'td', array( 'colspan' => 2, 'class' => 'htmlform-tip' ),
952 $helptext );
953 $row = Html::rawElement( 'tr', array(), $row );
954 $html .= "$row\n";
955 }
956
957 return $html;
958 }
959
960 function getLabel() {
961 return $this->mLabel;
962 }
963 function getLabelHtml( $cellAttributes = array() ) {
964 # Don't output a for= attribute for labels with no associated input.
965 # Kind of hacky here, possibly we don't want these to be <label>s at all.
966 $for = array();
967
968 if ( $this->needsLabel() ) {
969 $for['for'] = $this->mID;
970 }
971
972 return Html::rawElement( 'td', array( 'class' => 'mw-label' ) + $cellAttributes,
973 Html::rawElement( 'label', $for, $this->getLabel() )
974 );
975 }
976
977 function getDefault() {
978 if ( isset( $this->mDefault ) ) {
979 return $this->mDefault;
980 } else {
981 return null;
982 }
983 }
984
985 /**
986 * Returns the attributes required for the tooltip and accesskey.
987 *
988 * @return array Attributes
989 */
990 public function getTooltipAndAccessKey() {
991 if ( empty( $this->mParams['tooltip'] ) ) {
992 return array();
993 }
994
995 global $wgUser;
996
997 return $wgUser->getSkin()->tooltipAndAccessKeyAttribs( $this->mParams['tooltip'] );
998 }
999
1000 /**
1001 * flatten an array of options to a single array, for instance,
1002 * a set of <options> inside <optgroups>.
1003 * @param $options Associative Array with values either Strings
1004 * or Arrays
1005 * @return Array flattened input
1006 */
1007 public static function flattenOptions( $options ) {
1008 $flatOpts = array();
1009
1010 foreach ( $options as $value ) {
1011 if ( is_array( $value ) ) {
1012 $flatOpts = array_merge( $flatOpts, self::flattenOptions( $value ) );
1013 } else {
1014 $flatOpts[] = $value;
1015 }
1016 }
1017
1018 return $flatOpts;
1019 }
1020 }
1021
1022 class HTMLTextField extends HTMLFormField {
1023 function getSize() {
1024 return isset( $this->mParams['size'] )
1025 ? $this->mParams['size']
1026 : 45;
1027 }
1028
1029 function getInputHTML( $value ) {
1030 $attribs = array(
1031 'id' => $this->mID,
1032 'name' => $this->mName,
1033 'size' => $this->getSize(),
1034 'value' => $value,
1035 ) + $this->getTooltipAndAccessKey();
1036
1037 if ( isset( $this->mParams['maxlength'] ) ) {
1038 $attribs['maxlength'] = $this->mParams['maxlength'];
1039 }
1040
1041 if ( !empty( $this->mParams['disabled'] ) ) {
1042 $attribs['disabled'] = 'disabled';
1043 }
1044
1045 # TODO: Enforce pattern, step, required, readonly on the server side as
1046 # well
1047 foreach ( array( 'min', 'max', 'pattern', 'title', 'step',
1048 'placeholder' ) as $param ) {
1049 if ( isset( $this->mParams[$param] ) ) {
1050 $attribs[$param] = $this->mParams[$param];
1051 }
1052 }
1053
1054 foreach ( array( 'required', 'autofocus', 'multiple', 'readonly' ) as $param ) {
1055 if ( isset( $this->mParams[$param] ) ) {
1056 $attribs[$param] = '';
1057 }
1058 }
1059
1060 # Implement tiny differences between some field variants
1061 # here, rather than creating a new class for each one which
1062 # is essentially just a clone of this one.
1063 if ( isset( $this->mParams['type'] ) ) {
1064 switch ( $this->mParams['type'] ) {
1065 case 'email':
1066 $attribs['type'] = 'email';
1067 break;
1068 case 'int':
1069 $attribs['type'] = 'number';
1070 break;
1071 case 'float':
1072 $attribs['type'] = 'number';
1073 $attribs['step'] = 'any';
1074 break;
1075 # Pass through
1076 case 'password':
1077 case 'file':
1078 $attribs['type'] = $this->mParams['type'];
1079 break;
1080 }
1081 }
1082
1083 return Html::element( 'input', $attribs );
1084 }
1085 }
1086 class HTMLTextAreaField extends HTMLFormField {
1087 function getCols() {
1088 return isset( $this->mParams['cols'] )
1089 ? $this->mParams['cols']
1090 : 80;
1091 }
1092
1093 function getRows() {
1094 return isset( $this->mParams['rows'] )
1095 ? $this->mParams['rows']
1096 : 25;
1097 }
1098
1099 function getInputHTML( $value ) {
1100 $attribs = array(
1101 'id' => $this->mID,
1102 'name' => $this->mName,
1103 'cols' => $this->getCols(),
1104 'rows' => $this->getRows(),
1105 ) + $this->getTooltipAndAccessKey();
1106
1107
1108 if ( !empty( $this->mParams['disabled'] ) ) {
1109 $attribs['disabled'] = 'disabled';
1110 }
1111
1112 if ( !empty( $this->mParams['readonly'] ) ) {
1113 $attribs['readonly'] = 'readonly';
1114 }
1115
1116 foreach ( array( 'required', 'autofocus' ) as $param ) {
1117 if ( isset( $this->mParams[$param] ) ) {
1118 $attribs[$param] = '';
1119 }
1120 }
1121
1122 return Html::element( 'textarea', $attribs, $value );
1123 }
1124 }
1125
1126 /**
1127 * A field that will contain a numeric value
1128 */
1129 class HTMLFloatField extends HTMLTextField {
1130 function getSize() {
1131 return isset( $this->mParams['size'] )
1132 ? $this->mParams['size']
1133 : 20;
1134 }
1135
1136 function validate( $value, $alldata ) {
1137 $p = parent::validate( $value, $alldata );
1138
1139 if ( $p !== true ) {
1140 return $p;
1141 }
1142
1143 $value = trim( $value );
1144
1145 # http://dev.w3.org/html5/spec/common-microsyntaxes.html#real-numbers
1146 # with the addition that a leading '+' sign is ok.
1147 if ( !preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) {
1148 return wfMsgExt( 'htmlform-float-invalid', 'parse' );
1149 }
1150
1151 # The "int" part of these message names is rather confusing.
1152 # They make equal sense for all numbers.
1153 if ( isset( $this->mParams['min'] ) ) {
1154 $min = $this->mParams['min'];
1155
1156 if ( $min > $value ) {
1157 return wfMsgExt( 'htmlform-int-toolow', 'parse', array( $min ) );
1158 }
1159 }
1160
1161 if ( isset( $this->mParams['max'] ) ) {
1162 $max = $this->mParams['max'];
1163
1164 if ( $max < $value ) {
1165 return wfMsgExt( 'htmlform-int-toohigh', 'parse', array( $max ) );
1166 }
1167 }
1168
1169 return true;
1170 }
1171 }
1172
1173 /**
1174 * A field that must contain a number
1175 */
1176 class HTMLIntField extends HTMLFloatField {
1177 function validate( $value, $alldata ) {
1178 $p = parent::validate( $value, $alldata );
1179
1180 if ( $p !== true ) {
1181 return $p;
1182 }
1183
1184 # http://dev.w3.org/html5/spec/common-microsyntaxes.html#signed-integers
1185 # with the addition that a leading '+' sign is ok. Note that leading zeros
1186 # are fine, and will be left in the input, which is useful for things like
1187 # phone numbers when you know that they are integers (the HTML5 type=tel
1188 # input does not require its value to be numeric). If you want a tidier
1189 # value to, eg, save in the DB, clean it up with intval().
1190 if ( !preg_match( '/^((\+|\-)?\d+)?$/', trim( $value ) )
1191 ) {
1192 return wfMsgExt( 'htmlform-int-invalid', 'parse' );
1193 }
1194
1195 return true;
1196 }
1197 }
1198
1199 /**
1200 * A checkbox field
1201 */
1202 class HTMLCheckField extends HTMLFormField {
1203 function getInputHTML( $value ) {
1204 if ( !empty( $this->mParams['invert'] ) ) {
1205 $value = !$value;
1206 }
1207
1208 $attr = $this->getTooltipAndAccessKey();
1209 $attr['id'] = $this->mID;
1210
1211 if ( !empty( $this->mParams['disabled'] ) ) {
1212 $attr['disabled'] = 'disabled';
1213 }
1214
1215 return Xml::check( $this->mName, $value, $attr ) . '&#160;' .
1216 Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel );
1217 }
1218
1219 /**
1220 * For a checkbox, the label goes on the right hand side, and is
1221 * added in getInputHTML(), rather than HTMLFormField::getRow()
1222 */
1223 function getLabel() {
1224 return '&#160;';
1225 }
1226
1227 function loadDataFromRequest( $request ) {
1228 $invert = false;
1229 if ( isset( $this->mParams['invert'] ) && $this->mParams['invert'] ) {
1230 $invert = true;
1231 }
1232
1233 // GetCheck won't work like we want for checks.
1234 if ( $request->getCheck( 'wpEditToken' ) ) {
1235 // XOR has the following truth table, which is what we want
1236 // INVERT VALUE | OUTPUT
1237 // true true | false
1238 // false true | true
1239 // false false | false
1240 // true false | true
1241 return $request->getBool( $this->mName ) xor $invert;
1242 } else {
1243 return $this->getDefault();
1244 }
1245 }
1246 }
1247
1248 /**
1249 * A select dropdown field. Basically a wrapper for Xmlselect class
1250 */
1251 class HTMLSelectField extends HTMLFormField {
1252 function validate( $value, $alldata ) {
1253 $p = parent::validate( $value, $alldata );
1254
1255 if ( $p !== true ) {
1256 return $p;
1257 }
1258
1259 $validOptions = HTMLFormField::flattenOptions( $this->mParams['options'] );
1260
1261 if ( in_array( $value, $validOptions ) )
1262 return true;
1263 else
1264 return wfMsgExt( 'htmlform-select-badoption', 'parseinline' );
1265 }
1266
1267 function getInputHTML( $value ) {
1268 $select = new XmlSelect( $this->mName, $this->mID, strval( $value ) );
1269
1270 # If one of the options' 'name' is int(0), it is automatically selected.
1271 # because PHP sucks and things int(0) == 'some string'.
1272 # Working around this by forcing all of them to strings.
1273 foreach( $this->mParams['options'] as $key => &$opt ){
1274 if( is_int( $opt ) ){
1275 $opt = strval( $opt );
1276 }
1277 }
1278 unset( $opt ); # PHP keeps $opt around as a reference, which is a bit scary
1279
1280 if ( !empty( $this->mParams['disabled'] ) ) {
1281 $select->setAttribute( 'disabled', 'disabled' );
1282 }
1283
1284 $select->addOptions( $this->mParams['options'] );
1285
1286 return $select->getHTML();
1287 }
1288 }
1289
1290 /**
1291 * Select dropdown field, with an additional "other" textbox.
1292 */
1293 class HTMLSelectOrOtherField extends HTMLTextField {
1294 static $jsAdded = false;
1295
1296 function __construct( $params ) {
1297 if ( !in_array( 'other', $params['options'], true ) ) {
1298 $params['options'][wfMsg( 'htmlform-selectorother-other' )] = 'other';
1299 }
1300
1301 parent::__construct( $params );
1302 }
1303
1304 static function forceToStringRecursive( $array ) {
1305 if ( is_array( $array ) ) {
1306 return array_map( array( __CLASS__, 'forceToStringRecursive' ), $array );
1307 } else {
1308 return strval( $array );
1309 }
1310 }
1311
1312 function getInputHTML( $value ) {
1313 $valInSelect = false;
1314
1315 if ( $value !== false ) {
1316 $valInSelect = in_array(
1317 $value,
1318 HTMLFormField::flattenOptions( $this->mParams['options'] )
1319 );
1320 }
1321
1322 $selected = $valInSelect ? $value : 'other';
1323
1324 $opts = self::forceToStringRecursive( $this->mParams['options'] );
1325
1326 $select = new XmlSelect( $this->mName, $this->mID, $selected );
1327 $select->addOptions( $opts );
1328
1329 $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
1330
1331 $tbAttribs = array( 'id' => $this->mID . '-other', 'size' => $this->getSize() );
1332
1333 if ( !empty( $this->mParams['disabled'] ) ) {
1334 $select->setAttribute( 'disabled', 'disabled' );
1335 $tbAttribs['disabled'] = 'disabled';
1336 }
1337
1338 $select = $select->getHTML();
1339
1340 if ( isset( $this->mParams['maxlength'] ) ) {
1341 $tbAttribs['maxlength'] = $this->mParams['maxlength'];
1342 }
1343
1344 $textbox = Html::input(
1345 $this->mName . '-other',
1346 $valInSelect ? '' : $value,
1347 'text',
1348 $tbAttribs
1349 );
1350
1351 return "$select<br />\n$textbox";
1352 }
1353
1354 function loadDataFromRequest( $request ) {
1355 if ( $request->getCheck( $this->mName ) ) {
1356 $val = $request->getText( $this->mName );
1357
1358 if ( $val == 'other' ) {
1359 $val = $request->getText( $this->mName . '-other' );
1360 }
1361
1362 return $val;
1363 } else {
1364 return $this->getDefault();
1365 }
1366 }
1367 }
1368
1369 /**
1370 * Multi-select field
1371 */
1372 class HTMLMultiSelectField extends HTMLFormField {
1373 function validate( $value, $alldata ) {
1374 $p = parent::validate( $value, $alldata );
1375
1376 if ( $p !== true ) {
1377 return $p;
1378 }
1379
1380 if ( !is_array( $value ) ) {
1381 return false;
1382 }
1383
1384 # If all options are valid, array_intersect of the valid options
1385 # and the provided options will return the provided options.
1386 $validOptions = HTMLFormField::flattenOptions( $this->mParams['options'] );
1387
1388 $validValues = array_intersect( $value, $validOptions );
1389 if ( count( $validValues ) == count( $value ) ) {
1390 return true;
1391 } else {
1392 return wfMsgExt( 'htmlform-select-badoption', 'parseinline' );
1393 }
1394 }
1395
1396 function getInputHTML( $value ) {
1397 $html = $this->formatOptions( $this->mParams['options'], $value );
1398
1399 return $html;
1400 }
1401
1402 function formatOptions( $options, $value ) {
1403 $html = '';
1404
1405 $attribs = array();
1406
1407 if ( !empty( $this->mParams['disabled'] ) ) {
1408 $attribs['disabled'] = 'disabled';
1409 }
1410
1411 foreach ( $options as $label => $info ) {
1412 if ( is_array( $info ) ) {
1413 $html .= Html::rawElement( 'h1', array(), $label ) . "\n";
1414 $html .= $this->formatOptions( $info, $value );
1415 } else {
1416 $thisAttribs = array( 'id' => "{$this->mID}-$info", 'value' => $info );
1417
1418 $checkbox = Xml::check(
1419 $this->mName . '[]',
1420 in_array( $info, $value, true ),
1421 $attribs + $thisAttribs );
1422 $checkbox .= '&#160;' . Html::rawElement( 'label', array( 'for' => "{$this->mID}-$info" ), $label );
1423
1424 $html .= $checkbox . '<br />';
1425 }
1426 }
1427
1428 return $html;
1429 }
1430
1431 function loadDataFromRequest( $request ) {
1432 # won't work with getCheck
1433 if ( $request->getCheck( 'wpEditToken' ) ) {
1434 $arr = $request->getArray( $this->mName );
1435
1436 if ( !$arr ) {
1437 $arr = array();
1438 }
1439
1440 return $arr;
1441 } else {
1442 return $this->getDefault();
1443 }
1444 }
1445
1446 function getDefault() {
1447 if ( isset( $this->mDefault ) ) {
1448 return $this->mDefault;
1449 } else {
1450 return array();
1451 }
1452 }
1453
1454 protected function needsLabel() {
1455 return false;
1456 }
1457 }
1458
1459 /**
1460 * Radio checkbox fields.
1461 */
1462 class HTMLRadioField extends HTMLFormField {
1463 function validate( $value, $alldata ) {
1464 $p = parent::validate( $value, $alldata );
1465
1466 if ( $p !== true ) {
1467 return $p;
1468 }
1469
1470 if ( !is_string( $value ) && !is_int( $value ) ) {
1471 return false;
1472 }
1473
1474 $validOptions = HTMLFormField::flattenOptions( $this->mParams['options'] );
1475
1476 if ( in_array( $value, $validOptions ) ) {
1477 return true;
1478 } else {
1479 return wfMsgExt( 'htmlform-select-badoption', 'parseinline' );
1480 }
1481 }
1482
1483 /**
1484 * This returns a block of all the radio options, in one cell.
1485 * @see includes/HTMLFormField#getInputHTML()
1486 */
1487 function getInputHTML( $value ) {
1488 $html = $this->formatOptions( $this->mParams['options'], $value );
1489
1490 return $html;
1491 }
1492
1493 function formatOptions( $options, $value ) {
1494 $html = '';
1495
1496 $attribs = array();
1497 if ( !empty( $this->mParams['disabled'] ) ) {
1498 $attribs['disabled'] = 'disabled';
1499 }
1500
1501 # TODO: should this produce an unordered list perhaps?
1502 foreach ( $options as $label => $info ) {
1503 if ( is_array( $info ) ) {
1504 $html .= Html::rawElement( 'h1', array(), $label ) . "\n";
1505 $html .= $this->formatOptions( $info, $value );
1506 } else {
1507 $id = Sanitizer::escapeId( $this->mID . "-$info" );
1508 $html .= Xml::radio(
1509 $this->mName,
1510 $info,
1511 $info == $value,
1512 $attribs + array( 'id' => $id )
1513 );
1514 $html .= '&#160;' .
1515 Html::rawElement( 'label', array( 'for' => $id ), $label );
1516
1517 $html .= "<br />\n";
1518 }
1519 }
1520
1521 return $html;
1522 }
1523
1524 protected function needsLabel() {
1525 return false;
1526 }
1527 }
1528
1529 /**
1530 * An information field (text blob), not a proper input.
1531 */
1532 class HTMLInfoField extends HTMLFormField {
1533 function __construct( $info ) {
1534 $info['nodata'] = true;
1535
1536 parent::__construct( $info );
1537 }
1538
1539 function getInputHTML( $value ) {
1540 return !empty( $this->mParams['raw'] ) ? $value : htmlspecialchars( $value );
1541 }
1542
1543 function getTableRow( $value ) {
1544 if ( !empty( $this->mParams['rawrow'] ) ) {
1545 return $value;
1546 }
1547
1548 return parent::getTableRow( $value );
1549 }
1550
1551 protected function needsLabel() {
1552 return false;
1553 }
1554 }
1555
1556 class HTMLHiddenField extends HTMLFormField {
1557 public function __construct( $params ) {
1558 parent::__construct( $params );
1559
1560 # Per HTML5 spec, hidden fields cannot be 'required'
1561 # http://dev.w3.org/html5/spec/states-of-the-type-attribute.html#hidden-state
1562 unset( $this->mParams['required'] );
1563 }
1564
1565 public function getTableRow( $value ) {
1566 $params = array();
1567 if ( $this->mID ) {
1568 $params['id'] = $this->mID;
1569 }
1570
1571 $this->mParent->addHiddenField(
1572 $this->mName,
1573 $this->mDefault,
1574 $params
1575 );
1576
1577 return '';
1578 }
1579
1580 public function getInputHTML( $value ) { return ''; }
1581 }
1582
1583 /**
1584 * Add a submit button inline in the form (as opposed to
1585 * HTMLForm::addButton(), which will add it at the end).
1586 */
1587 class HTMLSubmitField extends HTMLFormField {
1588
1589 function __construct( $info ) {
1590 $info['nodata'] = true;
1591 parent::__construct( $info );
1592 }
1593
1594 function getInputHTML( $value ) {
1595 return Xml::submitButton(
1596 $value,
1597 array(
1598 'class' => 'mw-htmlform-submit',
1599 'name' => $this->mName,
1600 'id' => $this->mID,
1601 )
1602 );
1603 }
1604
1605 protected function needsLabel() {
1606 return false;
1607 }
1608
1609 /**
1610 * Button cannot be invalid
1611 */
1612 public function validate( $value, $alldata ){
1613 return true;
1614 }
1615 }
1616
1617 class HTMLEditTools extends HTMLFormField {
1618 public function getInputHTML( $value ) {
1619 return '';
1620 }
1621
1622 public function getTableRow( $value ) {
1623 if ( empty( $this->mParams['message'] ) ) {
1624 $msg = wfMessage( 'edittools' );
1625 } else {
1626 $msg = wfMessage( $this->mParams['message'] );
1627 if ( $msg->isDisabled() ) {
1628 $msg = wfMessage( 'edittools' );
1629 }
1630 }
1631 $msg->inContentLanguage();
1632
1633
1634 return '<tr><td></td><td class="mw-input">'
1635 . '<div class="mw-editTools">'
1636 . $msg->parseAsBlock()
1637 . "</div></td></tr>\n";
1638 }
1639 }