Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like HTMLFormField often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use HTMLFormField, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | abstract class HTMLFormField { |
||
| 8 | public $mParams; |
||
| 9 | |||
| 10 | protected $mValidationCallback; |
||
| 11 | protected $mFilterCallback; |
||
| 12 | protected $mName; |
||
| 13 | protected $mDir; |
||
| 14 | protected $mLabel; # String label, as HTML. Set on construction. |
||
| 15 | protected $mID; |
||
| 16 | protected $mClass = ''; |
||
| 17 | protected $mVFormClass = ''; |
||
| 18 | protected $mHelpClass = false; |
||
| 19 | protected $mDefault; |
||
| 20 | protected $mOptions = false; |
||
| 21 | protected $mOptionsLabelsNotFromMessage = false; |
||
| 22 | protected $mHideIf = null; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var bool If true will generate an empty div element with no label |
||
| 26 | * @since 1.22 |
||
| 27 | */ |
||
| 28 | protected $mShowEmptyLabels = true; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var HTMLForm|null |
||
| 32 | */ |
||
| 33 | public $mParent; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * This function must be implemented to return the HTML to generate |
||
| 37 | * the input object itself. It should not implement the surrounding |
||
| 38 | * table cells/rows, or labels/help messages. |
||
| 39 | * |
||
| 40 | * @param string $value The value to set the input to; eg a default |
||
| 41 | * text for a text input. |
||
| 42 | * |
||
| 43 | * @return string Valid HTML. |
||
| 44 | */ |
||
| 45 | abstract public function getInputHTML( $value ); |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Same as getInputHTML, but returns an OOUI object. |
||
| 49 | * Defaults to false, which getOOUI will interpret as "use the HTML version" |
||
| 50 | * |
||
| 51 | * @param string $value |
||
| 52 | * @return OOUI\Widget|false |
||
| 53 | */ |
||
| 54 | public function getInputOOUI( $value ) { |
||
| 57 | |||
| 58 | /** |
||
| 59 | * True if this field type is able to display errors; false if validation errors need to be |
||
| 60 | * displayed in the main HTMLForm error area. |
||
| 61 | * @return bool |
||
| 62 | */ |
||
| 63 | public function canDisplayErrors() { |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Get a translated interface message |
||
| 69 | * |
||
| 70 | * This is a wrapper around $this->mParent->msg() if $this->mParent is set |
||
| 71 | * and wfMessage() otherwise. |
||
| 72 | * |
||
| 73 | * Parameters are the same as wfMessage(). |
||
| 74 | * |
||
| 75 | * @return Message |
||
| 76 | */ |
||
| 77 | public function msg() { |
||
| 88 | |||
| 89 | /** |
||
| 90 | * If this field has a user-visible output or not. If not, |
||
| 91 | * it will not be rendered |
||
| 92 | * |
||
| 93 | * @return bool |
||
| 94 | */ |
||
| 95 | public function hasVisibleOutput() { |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Fetch a field value from $alldata for the closest field matching a given |
||
| 101 | * name. |
||
| 102 | * |
||
| 103 | * This is complex because it needs to handle array fields like the user |
||
| 104 | * would expect. The general algorithm is to look for $name as a sibling |
||
| 105 | * of $this, then a sibling of $this's parent, and so on. Keeping in mind |
||
| 106 | * that $name itself might be referencing an array. |
||
| 107 | * |
||
| 108 | * @param array $alldata |
||
| 109 | * @param string $name |
||
| 110 | * @return string |
||
| 111 | */ |
||
| 112 | protected function getNearestFieldByName( $alldata, $name ) { |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Helper function for isHidden to handle recursive data structures. |
||
| 156 | * |
||
| 157 | * @param array $alldata |
||
| 158 | * @param array $params |
||
| 159 | * @return bool |
||
| 160 | * @throws MWException |
||
| 161 | */ |
||
| 162 | protected function isHiddenRecurse( array $alldata, array $params ) { |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Test whether this field is supposed to be hidden, based on the values of |
||
| 263 | * the other form fields. |
||
| 264 | * |
||
| 265 | * @since 1.23 |
||
| 266 | * @param array $alldata The data collected from the form |
||
| 267 | * @return bool |
||
| 268 | */ |
||
| 269 | public function isHidden( $alldata ) { |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Override this function if the control can somehow trigger a form |
||
| 279 | * submission that shouldn't actually submit the HTMLForm. |
||
| 280 | * |
||
| 281 | * @since 1.23 |
||
| 282 | * @param string|array $value The value the field was submitted with |
||
| 283 | * @param array $alldata The data collected from the form |
||
| 284 | * |
||
| 285 | * @return bool True to cancel the submission |
||
| 286 | */ |
||
| 287 | public function cancelSubmit( $value, $alldata ) { |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Override this function to add specific validation checks on the |
||
| 293 | * field input. Don't forget to call parent::validate() to ensure |
||
| 294 | * that the user-defined callback mValidationCallback is still run |
||
| 295 | * |
||
| 296 | * @param string|array $value The value the field was submitted with |
||
| 297 | * @param array $alldata The data collected from the form |
||
| 298 | * |
||
| 299 | * @return bool|string True on success, or String error to display, or |
||
| 300 | * false to fail validation without displaying an error. |
||
| 301 | */ |
||
| 302 | public function validate( $value, $alldata ) { |
||
| 320 | |||
| 321 | public function filter( $value, $alldata ) { |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Should this field have a label, or is there no input element with the |
||
| 331 | * appropriate id for the label to point to? |
||
| 332 | * |
||
| 333 | * @return bool True to output a label, false to suppress |
||
| 334 | */ |
||
| 335 | protected function needsLabel() { |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Tell the field whether to generate a separate label element if its label |
||
| 341 | * is blank. |
||
| 342 | * |
||
| 343 | * @since 1.22 |
||
| 344 | * |
||
| 345 | * @param bool $show Set to false to not generate a label. |
||
| 346 | * @return void |
||
| 347 | */ |
||
| 348 | public function setShowEmptyLabel( $show ) { |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Can we assume that the request is an attempt to submit a HTMLForm, as opposed to an attempt to |
||
| 354 | * just view it? This can't normally be distinguished for e.g. checkboxes. |
||
| 355 | * |
||
| 356 | * Returns true if the request has a field for a CSRF token (wpEditToken) or a form identifier |
||
| 357 | * (wpFormIdentifier). |
||
| 358 | * |
||
| 359 | * @param WebRequest $request |
||
| 360 | * @return boolean |
||
| 361 | */ |
||
| 362 | protected function isSubmitAttempt( WebRequest $request ) { |
||
| 363 | return $request->getCheck( 'wpEditToken' ) || $request->getCheck( 'wpFormIdentifier' ); |
||
| 364 | } |
||
| 365 | |||
| 366 | /** |
||
| 367 | * Get the value that this input has been set to from a posted form, |
||
| 368 | * or the input's default value if it has not been set. |
||
| 369 | * |
||
| 370 | * @param WebRequest $request |
||
| 371 | * @return string The value |
||
| 372 | */ |
||
| 373 | public function loadDataFromRequest( $request ) { |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Initialise the object |
||
| 383 | * |
||
| 384 | * @param array $params Associative Array. See HTMLForm doc for syntax. |
||
| 385 | * |
||
| 386 | * @since 1.22 The 'label' attribute no longer accepts raw HTML, use 'label-raw' instead |
||
| 387 | * @throws MWException |
||
| 388 | */ |
||
| 389 | public function __construct( $params ) { |
||
| 390 | $this->mParams = $params; |
||
| 391 | |||
| 392 | if ( isset( $params['parent'] ) && $params['parent'] instanceof HTMLForm ) { |
||
| 393 | $this->mParent = $params['parent']; |
||
| 394 | } |
||
| 395 | |||
| 396 | # Generate the label from a message, if possible |
||
| 397 | if ( isset( $params['label-message'] ) ) { |
||
| 398 | $this->mLabel = $this->getMessage( $params['label-message'] )->parse(); |
||
| 399 | } elseif ( isset( $params['label'] ) ) { |
||
| 400 | if ( $params['label'] === ' ' ) { |
||
| 401 | // Apparently some things set   directly and in an odd format |
||
| 402 | $this->mLabel = ' '; |
||
| 403 | } else { |
||
| 404 | $this->mLabel = htmlspecialchars( $params['label'] ); |
||
| 405 | } |
||
| 406 | } elseif ( isset( $params['label-raw'] ) ) { |
||
| 407 | $this->mLabel = $params['label-raw']; |
||
| 408 | } |
||
| 409 | |||
| 410 | $this->mName = "wp{$params['fieldname']}"; |
||
| 411 | if ( isset( $params['name'] ) ) { |
||
| 412 | $this->mName = $params['name']; |
||
| 413 | } |
||
| 414 | |||
| 415 | if ( isset( $params['dir'] ) ) { |
||
| 416 | $this->mDir = $params['dir']; |
||
| 417 | } |
||
| 418 | |||
| 419 | $validName = Sanitizer::escapeId( $this->mName ); |
||
| 420 | $validName = str_replace( [ '.5B', '.5D' ], [ '[', ']' ], $validName ); |
||
| 421 | if ( $this->mName != $validName && !isset( $params['nodata'] ) ) { |
||
| 422 | throw new MWException( "Invalid name '{$this->mName}' passed to " . __METHOD__ ); |
||
| 423 | } |
||
| 424 | |||
| 425 | $this->mID = "mw-input-{$this->mName}"; |
||
| 426 | |||
| 427 | if ( isset( $params['default'] ) ) { |
||
| 428 | $this->mDefault = $params['default']; |
||
| 429 | } |
||
| 430 | |||
| 431 | if ( isset( $params['id'] ) ) { |
||
| 432 | $id = $params['id']; |
||
| 433 | $validId = Sanitizer::escapeId( $id ); |
||
| 434 | |||
| 435 | if ( $id != $validId ) { |
||
| 436 | throw new MWException( "Invalid id '$id' passed to " . __METHOD__ ); |
||
| 437 | } |
||
| 438 | |||
| 439 | $this->mID = $id; |
||
| 440 | } |
||
| 441 | |||
| 442 | if ( isset( $params['cssclass'] ) ) { |
||
| 443 | $this->mClass = $params['cssclass']; |
||
| 444 | } |
||
| 445 | |||
| 446 | if ( isset( $params['csshelpclass'] ) ) { |
||
| 447 | $this->mHelpClass = $params['csshelpclass']; |
||
| 448 | } |
||
| 449 | |||
| 450 | if ( isset( $params['validation-callback'] ) ) { |
||
| 451 | $this->mValidationCallback = $params['validation-callback']; |
||
| 452 | } |
||
| 453 | |||
| 454 | if ( isset( $params['filter-callback'] ) ) { |
||
| 455 | $this->mFilterCallback = $params['filter-callback']; |
||
| 456 | } |
||
| 457 | |||
| 458 | if ( isset( $params['hidelabel'] ) ) { |
||
| 459 | $this->mShowEmptyLabels = false; |
||
| 460 | } |
||
| 461 | |||
| 462 | if ( isset( $params['hide-if'] ) ) { |
||
| 463 | $this->mHideIf = $params['hide-if']; |
||
| 464 | } |
||
| 465 | } |
||
| 466 | |||
| 467 | /** |
||
| 468 | * Get the complete table row for the input, including help text, |
||
| 469 | * labels, and whatever. |
||
| 470 | * |
||
| 471 | * @param string $value The value to set the input to. |
||
| 472 | * |
||
| 473 | * @return string Complete HTML table row. |
||
| 474 | */ |
||
| 475 | public function getTableRow( $value ) { |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Get the complete div for the input, including help text, |
||
| 526 | * labels, and whatever. |
||
| 527 | * @since 1.20 |
||
| 528 | * |
||
| 529 | * @param string $value The value to set the input to. |
||
| 530 | * |
||
| 531 | * @return string Complete HTML table row. |
||
| 532 | */ |
||
| 533 | public function getDiv( $value ) { |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Get the OOUI version of the div. Falls back to getDiv by default. |
||
| 576 | * @since 1.26 |
||
| 577 | * |
||
| 578 | * @param string $value The value to set the input to. |
||
| 579 | * |
||
| 580 | * @return OOUI\FieldLayout|OOUI\ActionFieldLayout |
||
| 581 | */ |
||
| 582 | public function getOOUI( $value ) { |
||
| 583 | $inputField = $this->getInputOOUI( $value ); |
||
| 584 | |||
| 585 | if ( !$inputField ) { |
||
| 586 | // This field doesn't have an OOUI implementation yet at all. Fall back to getDiv() to |
||
| 587 | // generate the whole field, label and errors and all, then wrap it in a Widget. |
||
| 588 | // It might look weird, but it'll work OK. |
||
| 589 | return $this->getFieldLayoutOOUI( |
||
| 590 | new OOUI\Widget( [ 'content' => new OOUI\HtmlSnippet( $this->getDiv( $value ) ) ] ), |
||
| 591 | [ 'infusable' => false, 'align' => 'top' ] |
||
| 592 | ); |
||
| 593 | } |
||
| 594 | |||
| 595 | $infusable = true; |
||
| 596 | if ( is_string( $inputField ) ) { |
||
| 597 | // We have an OOUI implementation, but it's not proper, and we got a load of HTML. |
||
| 598 | // Cheat a little and wrap it in a widget. It won't be infusable, though, since client-side |
||
| 599 | // JavaScript doesn't know how to rebuilt the contents. |
||
| 600 | $inputField = new OOUI\Widget( [ 'content' => new OOUI\HtmlSnippet( $inputField ) ] ); |
||
| 601 | $infusable = false; |
||
| 602 | } |
||
| 603 | |||
| 604 | $fieldType = get_class( $this ); |
||
| 605 | $help = $this->getHelpText(); |
||
| 606 | $errors = $this->getErrorsRaw( $value ); |
||
| 607 | foreach ( $errors as &$error ) { |
||
| 608 | $error = new OOUI\HtmlSnippet( $error ); |
||
| 609 | } |
||
| 610 | |||
| 611 | $notices = $this->getNotices(); |
||
| 612 | foreach ( $notices as &$notice ) { |
||
| 613 | $notice = new OOUI\HtmlSnippet( $notice ); |
||
| 614 | } |
||
| 615 | |||
| 616 | $config = [ |
||
| 617 | 'classes' => [ "mw-htmlform-field-$fieldType", $this->mClass ], |
||
| 618 | 'align' => $this->getLabelAlignOOUI(), |
||
| 619 | 'help' => ( $help !== null && $help !== '' ) ? new OOUI\HtmlSnippet( $help ) : null, |
||
| 620 | 'errors' => $errors, |
||
| 621 | 'notices' => $notices, |
||
| 622 | 'infusable' => $infusable, |
||
| 623 | ]; |
||
| 624 | |||
| 625 | $preloadModules = false; |
||
| 626 | |||
| 627 | if ( $infusable && $this->shouldInfuseOOUI() ) { |
||
| 628 | $preloadModules = true; |
||
| 629 | $config['classes'][] = 'mw-htmlform-field-autoinfuse'; |
||
| 630 | } |
||
| 631 | |||
| 632 | // the element could specify, that the label doesn't need to be added |
||
| 633 | $label = $this->getLabel(); |
||
| 634 | if ( $label ) { |
||
| 635 | $config['label'] = new OOUI\HtmlSnippet( $label ); |
||
| 636 | } |
||
| 637 | |||
| 638 | if ( $this->mHideIf ) { |
||
| 639 | $preloadModules = true; |
||
| 640 | $config['hideIf'] = $this->mHideIf; |
||
| 641 | } |
||
| 642 | |||
| 643 | $config['modules'] = $this->getOOUIModules(); |
||
| 644 | |||
| 645 | if ( $preloadModules ) { |
||
| 646 | $this->mParent->getOutput()->addModules( 'mediawiki.htmlform.ooui' ); |
||
| 647 | $this->mParent->getOutput()->addModules( $this->getOOUIModules() ); |
||
| 648 | } |
||
| 649 | |||
| 650 | return $this->getFieldLayoutOOUI( $inputField, $config ); |
||
| 651 | } |
||
| 652 | |||
| 653 | /** |
||
| 654 | * Get label alignment when generating field for OOUI. |
||
| 655 | * @return string 'left', 'right', 'top' or 'inline' |
||
| 656 | */ |
||
| 657 | protected function getLabelAlignOOUI() { |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Get a FieldLayout (or subclass thereof) to wrap this field in when using OOUI output. |
||
| 663 | * @return OOUI\FieldLayout|OOUI\ActionFieldLayout |
||
| 664 | */ |
||
| 665 | protected function getFieldLayoutOOUI( $inputField, $config ) { |
||
| 666 | if ( isset( $this->mClassWithButton ) ) { |
||
| 667 | $buttonWidget = $this->mClassWithButton->getInputOOUI( '' ); |
||
| 668 | return new HTMLFormActionFieldLayout( $inputField, $buttonWidget, $config ); |
||
| 669 | } |
||
| 670 | return new HTMLFormFieldLayout( $inputField, $config ); |
||
| 671 | } |
||
| 672 | |||
| 673 | /** |
||
| 674 | * Whether the field should be automatically infused. Note that all OOjs UI HTMLForm fields are |
||
| 675 | * infusable (you can call OO.ui.infuse() on them), but not all are infused by default, since |
||
| 676 | * there is no benefit in doing it e.g. for buttons and it's a small performance hit on page load. |
||
| 677 | * |
||
| 678 | * @return bool |
||
| 679 | */ |
||
| 680 | protected function shouldInfuseOOUI() { |
||
| 681 | // Always infuse fields with help text, since the interface for it is nicer with JS |
||
| 682 | return $this->getHelpText() !== null; |
||
| 683 | } |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Get the list of extra ResourceLoader modules which must be loaded client-side before it's |
||
| 687 | * possible to infuse this field's OOjs UI widget. |
||
| 688 | * |
||
| 689 | * @return string[] |
||
| 690 | */ |
||
| 691 | protected function getOOUIModules() { |
||
| 692 | return []; |
||
| 693 | } |
||
| 694 | |||
| 695 | /** |
||
| 696 | * Get the complete raw fields for the input, including help text, |
||
| 697 | * labels, and whatever. |
||
| 698 | * @since 1.20 |
||
| 699 | * |
||
| 700 | * @param string $value The value to set the input to. |
||
| 701 | * |
||
| 702 | * @return string Complete HTML table row. |
||
| 703 | */ |
||
| 704 | public function getRaw( $value ) { |
||
| 718 | |||
| 719 | /** |
||
| 720 | * Get the complete field for the input, including help text, |
||
| 721 | * labels, and whatever. Fall back from 'vform' to 'div' when not overridden. |
||
| 722 | * |
||
| 723 | * @since 1.25 |
||
| 724 | * @param string $value The value to set the input to. |
||
| 725 | * @return string Complete HTML field. |
||
| 726 | */ |
||
| 727 | public function getVForm( $value ) { |
||
| 732 | |||
| 733 | /** |
||
| 734 | * Get the complete field as an inline element. |
||
| 735 | * @since 1.25 |
||
| 736 | * @param string $value The value to set the input to. |
||
| 737 | * @return string Complete HTML inline element |
||
| 738 | */ |
||
| 739 | public function getInline( $value ) { |
||
| 753 | |||
| 754 | /** |
||
| 755 | * Generate help text HTML in table format |
||
| 756 | * @since 1.20 |
||
| 757 | * |
||
| 758 | * @param string|null $helptext |
||
| 759 | * @return string |
||
| 760 | */ |
||
| 761 | public function getHelpTextHtmlTable( $helptext ) { |
||
| 781 | |||
| 782 | /** |
||
| 783 | * Generate help text HTML in div format |
||
| 784 | * @since 1.20 |
||
| 785 | * |
||
| 786 | * @param string|null $helptext |
||
| 787 | * |
||
| 788 | * @return string |
||
| 789 | */ |
||
| 790 | public function getHelpTextHtmlDiv( $helptext ) { |
||
| 809 | |||
| 810 | /** |
||
| 811 | * Generate help text HTML formatted for raw output |
||
| 812 | * @since 1.20 |
||
| 813 | * |
||
| 814 | * @param string|null $helptext |
||
| 815 | * @return string |
||
| 816 | */ |
||
| 817 | public function getHelpTextHtmlRaw( $helptext ) { |
||
| 820 | |||
| 821 | /** |
||
| 822 | * Determine the help text to display |
||
| 823 | * @since 1.20 |
||
| 824 | * @return string|null HTML |
||
| 825 | */ |
||
| 826 | public function getHelpText() { |
||
| 852 | |||
| 853 | /** |
||
| 854 | * Determine form errors to display and their classes |
||
| 855 | * @since 1.20 |
||
| 856 | * |
||
| 857 | * @param string $value The value of the input |
||
| 858 | * @return array array( $errors, $errorClass ) |
||
| 859 | */ |
||
| 860 | public function getErrorsAndErrorClass( $value ) { |
||
| 873 | |||
| 874 | /** |
||
| 875 | * Determine form errors to display, returning them in an array. |
||
| 876 | * |
||
| 877 | * @since 1.26 |
||
| 878 | * @param string $value The value of the input |
||
| 879 | * @return string[] Array of error HTML strings |
||
| 880 | */ |
||
| 881 | public function getErrorsRaw( $value ) { |
||
| 899 | |||
| 900 | /** |
||
| 901 | * Determine notices to display for the field. |
||
| 902 | * |
||
| 903 | * @since 1.28 |
||
| 904 | * @return string[] |
||
| 905 | */ |
||
| 906 | public function getNotices() { |
||
| 923 | |||
| 924 | /** |
||
| 925 | * @return string HTML |
||
| 926 | */ |
||
| 927 | public function getLabel() { |
||
| 930 | |||
| 931 | public function getLabelHtml( $cellAttributes = [] ) { |
||
| 969 | |||
| 970 | public function getDefault() { |
||
| 977 | |||
| 978 | /** |
||
| 979 | * Returns the attributes required for the tooltip and accesskey. |
||
| 980 | * |
||
| 981 | * @return array Attributes |
||
| 982 | */ |
||
| 983 | public function getTooltipAndAccessKey() { |
||
| 990 | |||
| 991 | /** |
||
| 992 | * Returns the given attributes from the parameters |
||
| 993 | * |
||
| 994 | * @param array $list List of attributes to get |
||
| 995 | * @return array Attributes |
||
| 996 | */ |
||
| 997 | public function getAttributes( array $list ) { |
||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * Given an array of msg-key => value mappings, returns an array with keys |
||
| 1016 | * being the message texts. It also forces values to strings. |
||
| 1017 | * |
||
| 1018 | * @param array $options |
||
| 1019 | * @return array |
||
| 1020 | */ |
||
| 1021 | private function lookupOptionsKeys( $options ) { |
||
| 1031 | |||
| 1032 | /** |
||
| 1033 | * Recursively forces values in an array to strings, because issues arise |
||
| 1034 | * with integer 0 as a value. |
||
| 1035 | * |
||
| 1036 | * @param array $array |
||
| 1037 | * @return array |
||
| 1038 | */ |
||
| 1039 | public static function forceToStringRecursive( $array ) { |
||
| 1046 | |||
| 1047 | /** |
||
| 1048 | * Fetch the array of options from the field's parameters. In order, this |
||
| 1049 | * checks 'options-messages', 'options', then 'options-message'. |
||
| 1050 | * |
||
| 1051 | * @return array|null Options array |
||
| 1052 | */ |
||
| 1053 | public function getOptions() { |
||
| 1095 | |||
| 1096 | /** |
||
| 1097 | * Get options and make them into arrays suitable for OOUI. |
||
| 1098 | * @return array Options for inclusion in a select or whatever. |
||
| 1099 | */ |
||
| 1100 | public function getOptionsOOUI() { |
||
| 1118 | |||
| 1119 | /** |
||
| 1120 | * flatten an array of options to a single array, for instance, |
||
| 1121 | * a set of "<options>" inside "<optgroups>". |
||
| 1122 | * |
||
| 1123 | * @param array $options Associative Array with values either Strings or Arrays |
||
| 1124 | * @return array Flattened input |
||
| 1125 | */ |
||
| 1126 | public static function flattenOptions( $options ) { |
||
| 1139 | |||
| 1140 | /** |
||
| 1141 | * Formats one or more errors as accepted by field validation-callback. |
||
| 1142 | * |
||
| 1143 | * @param string|Message|array $errors Array of strings or Message instances |
||
| 1144 | * @return string HTML |
||
| 1145 | * @since 1.18 |
||
| 1146 | */ |
||
| 1147 | protected static function formatErrors( $errors ) { |
||
| 1171 | |||
| 1172 | /** |
||
| 1173 | * Turns a *-message parameter (which could be a MessageSpecifier, or a message name, or a |
||
| 1174 | * name + parameters array) into a Message. |
||
| 1175 | * @param mixed $value |
||
| 1176 | * @return Message |
||
| 1177 | */ |
||
| 1178 | protected function getMessage( $value ) { |
||
| 1187 | |||
| 1188 | /** |
||
| 1189 | * Skip this field when collecting data. |
||
| 1190 | * @param WebRequest $request |
||
| 1191 | * @return bool |
||
| 1192 | * @since 1.27 |
||
| 1193 | */ |
||
| 1194 | public function skipLoadData( $request ) { |
||
| 1197 | } |
||
| 1198 |