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 HTMLForm 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 HTMLForm, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 123 | class HTMLForm extends ContextSource { |
||
| 124 | // A mapping of 'type' inputs onto standard HTMLFormField subclasses |
||
| 125 | public static $typeMappings = [ |
||
| 126 | 'api' => 'HTMLApiField', |
||
| 127 | 'text' => 'HTMLTextField', |
||
| 128 | 'textwithbutton' => 'HTMLTextFieldWithButton', |
||
| 129 | 'textarea' => 'HTMLTextAreaField', |
||
| 130 | 'select' => 'HTMLSelectField', |
||
| 131 | 'combobox' => 'HTMLComboboxField', |
||
| 132 | 'radio' => 'HTMLRadioField', |
||
| 133 | 'multiselect' => 'HTMLMultiSelectField', |
||
| 134 | 'limitselect' => 'HTMLSelectLimitField', |
||
| 135 | 'check' => 'HTMLCheckField', |
||
| 136 | 'toggle' => 'HTMLCheckField', |
||
| 137 | 'int' => 'HTMLIntField', |
||
| 138 | 'float' => 'HTMLFloatField', |
||
| 139 | 'info' => 'HTMLInfoField', |
||
| 140 | 'selectorother' => 'HTMLSelectOrOtherField', |
||
| 141 | 'selectandother' => 'HTMLSelectAndOtherField', |
||
| 142 | 'namespaceselect' => 'HTMLSelectNamespace', |
||
| 143 | 'namespaceselectwithbutton' => 'HTMLSelectNamespaceWithButton', |
||
| 144 | 'tagfilter' => 'HTMLTagFilter', |
||
| 145 | 'submit' => 'HTMLSubmitField', |
||
| 146 | 'hidden' => 'HTMLHiddenField', |
||
| 147 | 'edittools' => 'HTMLEditTools', |
||
| 148 | 'checkmatrix' => 'HTMLCheckMatrix', |
||
| 149 | 'cloner' => 'HTMLFormFieldCloner', |
||
| 150 | 'autocompleteselect' => 'HTMLAutoCompleteSelectField', |
||
| 151 | // HTMLTextField will output the correct type="" attribute automagically. |
||
| 152 | // There are about four zillion other HTML5 input types, like range, but |
||
| 153 | // we don't use those at the moment, so no point in adding all of them. |
||
| 154 | 'email' => 'HTMLTextField', |
||
| 155 | 'password' => 'HTMLTextField', |
||
| 156 | 'url' => 'HTMLTextField', |
||
| 157 | 'title' => 'HTMLTitleTextField', |
||
| 158 | 'user' => 'HTMLUserTextField', |
||
| 159 | ]; |
||
| 160 | |||
| 161 | public $mFieldData; |
||
| 162 | |||
| 163 | protected $mMessagePrefix; |
||
| 164 | |||
| 165 | /** @var HTMLFormField[] */ |
||
| 166 | protected $mFlatFields; |
||
| 167 | |||
| 168 | protected $mFieldTree; |
||
| 169 | protected $mShowReset = false; |
||
| 170 | protected $mShowSubmit = true; |
||
| 171 | protected $mSubmitFlags = [ 'constructive', 'primary' ]; |
||
| 172 | |||
| 173 | protected $mSubmitCallback; |
||
| 174 | protected $mValidationErrorMessage; |
||
| 175 | |||
| 176 | protected $mPre = ''; |
||
| 177 | protected $mHeader = ''; |
||
| 178 | protected $mFooter = ''; |
||
| 179 | protected $mSectionHeaders = []; |
||
| 180 | protected $mSectionFooters = []; |
||
| 181 | protected $mPost = ''; |
||
| 182 | protected $mId; |
||
| 183 | protected $mName; |
||
| 184 | protected $mTableId = ''; |
||
| 185 | |||
| 186 | protected $mSubmitID; |
||
| 187 | protected $mSubmitName; |
||
| 188 | protected $mSubmitText; |
||
| 189 | protected $mSubmitTooltip; |
||
| 190 | |||
| 191 | protected $mTitle; |
||
| 192 | protected $mMethod = 'post'; |
||
| 193 | protected $mWasSubmitted = false; |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Form action URL. false means we will use the URL to set Title |
||
| 197 | * @since 1.19 |
||
| 198 | * @var bool|string |
||
| 199 | */ |
||
| 200 | protected $mAction = false; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Form attribute autocomplete. false does not set the attribute |
||
| 204 | * @since 1.27 |
||
| 205 | * @var bool|string |
||
| 206 | */ |
||
| 207 | protected $mAutocomplete = false; |
||
| 208 | |||
| 209 | protected $mUseMultipart = false; |
||
| 210 | protected $mHiddenFields = []; |
||
| 211 | protected $mButtons = []; |
||
| 212 | |||
| 213 | protected $mWrapperLegend = false; |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Salt for the edit token. |
||
| 217 | * @var string|array |
||
| 218 | */ |
||
| 219 | protected $mTokenSalt = ''; |
||
| 220 | |||
| 221 | /** |
||
| 222 | * If true, sections that contain both fields and subsections will |
||
| 223 | * render their subsections before their fields. |
||
| 224 | * |
||
| 225 | * Subclasses may set this to false to render subsections after fields |
||
| 226 | * instead. |
||
| 227 | */ |
||
| 228 | protected $mSubSectionBeforeFields = true; |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Format in which to display form. For viable options, |
||
| 232 | * @see $availableDisplayFormats |
||
| 233 | * @var string |
||
| 234 | */ |
||
| 235 | protected $displayFormat = 'table'; |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Available formats in which to display the form |
||
| 239 | * @var array |
||
| 240 | */ |
||
| 241 | protected $availableDisplayFormats = [ |
||
| 242 | 'table', |
||
| 243 | 'div', |
||
| 244 | 'raw', |
||
| 245 | 'inline', |
||
| 246 | ]; |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Available formats in which to display the form |
||
| 250 | * @var array |
||
| 251 | */ |
||
| 252 | protected $availableSubclassDisplayFormats = [ |
||
| 253 | 'vform', |
||
| 254 | 'ooui', |
||
| 255 | ]; |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Construct a HTMLForm object for given display type. May return a HTMLForm subclass. |
||
| 259 | * |
||
| 260 | * @param string $displayFormat |
||
| 261 | * @param mixed $arguments... Additional arguments to pass to the constructor. |
||
|
|
|||
| 262 | * @return HTMLForm |
||
| 263 | */ |
||
| 264 | public static function factory( $displayFormat/*, $arguments...*/ ) { |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Build a new HTMLForm from an array of field attributes |
||
| 285 | * |
||
| 286 | * @param array $descriptor Array of Field constructs, as described above |
||
| 287 | * @param IContextSource $context Available since 1.18, will become compulsory in 1.18. |
||
| 288 | * Obviates the need to call $form->setTitle() |
||
| 289 | * @param string $messagePrefix A prefix to go in front of default messages |
||
| 290 | */ |
||
| 291 | public function __construct( $descriptor, /*IContextSource*/ $context = null, |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Set format in which to display the form |
||
| 353 | * |
||
| 354 | * @param string $format The name of the format to use, must be one of |
||
| 355 | * $this->availableDisplayFormats |
||
| 356 | * |
||
| 357 | * @throws MWException |
||
| 358 | * @since 1.20 |
||
| 359 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 360 | */ |
||
| 361 | public function setDisplayFormat( $format ) { |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Getter for displayFormat |
||
| 387 | * @since 1.20 |
||
| 388 | * @return string |
||
| 389 | */ |
||
| 390 | public function getDisplayFormat() { |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Test if displayFormat is 'vform' |
||
| 396 | * @since 1.22 |
||
| 397 | * @deprecated since 1.25 |
||
| 398 | * @return bool |
||
| 399 | */ |
||
| 400 | public function isVForm() { |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Get the HTMLFormField subclass for this descriptor. |
||
| 407 | * |
||
| 408 | * The descriptor can be passed either 'class' which is the name of |
||
| 409 | * a HTMLFormField subclass, or a shorter 'type' which is an alias. |
||
| 410 | * This makes sure the 'class' is always set, and also is returned by |
||
| 411 | * this function for ease. |
||
| 412 | * |
||
| 413 | * @since 1.23 |
||
| 414 | * |
||
| 415 | * @param string $fieldname Name of the field |
||
| 416 | * @param array $descriptor Input Descriptor, as described above |
||
| 417 | * |
||
| 418 | * @throws MWException |
||
| 419 | * @return string Name of a HTMLFormField subclass |
||
| 420 | */ |
||
| 421 | public static function getClassFromDescriptor( $fieldname, &$descriptor ) { |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Initialise a new Object for the field |
||
| 441 | * |
||
| 442 | * @param string $fieldname Name of the field |
||
| 443 | * @param array $descriptor Input Descriptor, as described above |
||
| 444 | * @param HTMLForm|null $parent Parent instance of HTMLForm |
||
| 445 | * |
||
| 446 | * @throws MWException |
||
| 447 | * @return HTMLFormField Instance of a subclass of HTMLFormField |
||
| 448 | */ |
||
| 449 | public static function loadInputFromParameters( $fieldname, $descriptor, |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Prepare form for submission. |
||
| 467 | * |
||
| 468 | * @attention When doing method chaining, that should be the very last |
||
| 469 | * method call before displayForm(). |
||
| 470 | * |
||
| 471 | * @throws MWException |
||
| 472 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 473 | */ |
||
| 474 | public function prepareForm() { |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Try submitting, with edit token check first |
||
| 488 | * @return Status|bool |
||
| 489 | */ |
||
| 490 | public function tryAuthorizedSubmit() { |
||
| 515 | |||
| 516 | /** |
||
| 517 | * The here's-one-I-made-earlier option: do the submission if |
||
| 518 | * posted, or display the form with or without funky validation |
||
| 519 | * errors |
||
| 520 | * @return bool|Status Whether submission was successful. |
||
| 521 | */ |
||
| 522 | public function show() { |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Same as self::show with the difference, that the form will be |
||
| 537 | * added to the output, no matter, if the validation was good or not. |
||
| 538 | * @return bool|Status Whether submission was successful. |
||
| 539 | */ |
||
| 540 | public function showAlways() { |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Validate all the fields, and call the submission callback |
||
| 552 | * function if everything is kosher. |
||
| 553 | * @throws MWException |
||
| 554 | * @return bool|string|array|Status |
||
| 555 | * - Bool true or a good Status object indicates success, |
||
| 556 | * - Bool false indicates no submission was attempted, |
||
| 557 | * - Anything else indicates failure. The value may be a fatal Status |
||
| 558 | * object, an HTML string, or an array of arrays (message keys and |
||
| 559 | * params) or strings (message keys) |
||
| 560 | */ |
||
| 561 | public function trySubmit() { |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Test whether the form was considered to have been submitted or not, i.e. |
||
| 623 | * whether the last call to tryAuthorizedSubmit or trySubmit returned |
||
| 624 | * non-false. |
||
| 625 | * |
||
| 626 | * This will return false until HTMLForm::tryAuthorizedSubmit or |
||
| 627 | * HTMLForm::trySubmit is called. |
||
| 628 | * |
||
| 629 | * @since 1.23 |
||
| 630 | * @return bool |
||
| 631 | */ |
||
| 632 | public function wasSubmitted() { |
||
| 635 | |||
| 636 | /** |
||
| 637 | * Set a callback to a function to do something with the form |
||
| 638 | * once it's been successfully validated. |
||
| 639 | * |
||
| 640 | * @param callable $cb The function will be passed the output from |
||
| 641 | * HTMLForm::filterDataForSubmit and this HTMLForm object, and must |
||
| 642 | * return as documented for HTMLForm::trySubmit |
||
| 643 | * |
||
| 644 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 645 | */ |
||
| 646 | public function setSubmitCallback( $cb ) { |
||
| 651 | |||
| 652 | /** |
||
| 653 | * Set a message to display on a validation error. |
||
| 654 | * |
||
| 655 | * @param string|array $msg String or Array of valid inputs to wfMessage() |
||
| 656 | * (so each entry can be either a String or Array) |
||
| 657 | * |
||
| 658 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 659 | */ |
||
| 660 | public function setValidationErrorMessage( $msg ) { |
||
| 665 | |||
| 666 | /** |
||
| 667 | * Set the introductory message, overwriting any existing message. |
||
| 668 | * |
||
| 669 | * @param string $msg Complete text of message to display |
||
| 670 | * |
||
| 671 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 672 | */ |
||
| 673 | public function setIntro( $msg ) { |
||
| 678 | |||
| 679 | /** |
||
| 680 | * Set the introductory message HTML, overwriting any existing message. |
||
| 681 | * @since 1.19 |
||
| 682 | * |
||
| 683 | * @param string $msg Complete HTML of message to display |
||
| 684 | * |
||
| 685 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 686 | */ |
||
| 687 | public function setPreText( $msg ) { |
||
| 692 | |||
| 693 | /** |
||
| 694 | * Add HTML to introductory message. |
||
| 695 | * |
||
| 696 | * @param string $msg Complete HTML of message to display |
||
| 697 | * |
||
| 698 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 699 | */ |
||
| 700 | public function addPreText( $msg ) { |
||
| 705 | |||
| 706 | /** |
||
| 707 | * Add HTML to the header, inside the form. |
||
| 708 | * |
||
| 709 | * @param string $msg Additional HTML to display in header |
||
| 710 | * @param string|null $section The section to add the header to |
||
| 711 | * |
||
| 712 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 713 | */ |
||
| 714 | View Code Duplication | public function addHeaderText( $msg, $section = null ) { |
|
| 726 | |||
| 727 | /** |
||
| 728 | * Set header text, inside the form. |
||
| 729 | * @since 1.19 |
||
| 730 | * |
||
| 731 | * @param string $msg Complete HTML of header to display |
||
| 732 | * @param string|null $section The section to add the header to |
||
| 733 | * |
||
| 734 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 735 | */ |
||
| 736 | public function setHeaderText( $msg, $section = null ) { |
||
| 745 | |||
| 746 | /** |
||
| 747 | * Get header text. |
||
| 748 | * |
||
| 749 | * @param string|null $section The section to get the header text for |
||
| 750 | * @since 1.26 |
||
| 751 | * @return string HTML |
||
| 752 | */ |
||
| 753 | public function getHeaderText( $section = null ) { |
||
| 760 | |||
| 761 | /** |
||
| 762 | * Add footer text, inside the form. |
||
| 763 | * |
||
| 764 | * @param string $msg Complete text of message to display |
||
| 765 | * @param string|null $section The section to add the footer text to |
||
| 766 | * |
||
| 767 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 768 | */ |
||
| 769 | View Code Duplication | public function addFooterText( $msg, $section = null ) { |
|
| 781 | |||
| 782 | /** |
||
| 783 | * Set footer text, inside the form. |
||
| 784 | * @since 1.19 |
||
| 785 | * |
||
| 786 | * @param string $msg Complete text of message to display |
||
| 787 | * @param string|null $section The section to add the footer text to |
||
| 788 | * |
||
| 789 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 790 | */ |
||
| 791 | public function setFooterText( $msg, $section = null ) { |
||
| 800 | |||
| 801 | /** |
||
| 802 | * Get footer text. |
||
| 803 | * |
||
| 804 | * @param string|null $section The section to get the footer text for |
||
| 805 | * @since 1.26 |
||
| 806 | * @return string |
||
| 807 | */ |
||
| 808 | public function getFooterText( $section = null ) { |
||
| 815 | |||
| 816 | /** |
||
| 817 | * Add text to the end of the display. |
||
| 818 | * |
||
| 819 | * @param string $msg Complete text of message to display |
||
| 820 | * |
||
| 821 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 822 | */ |
||
| 823 | public function addPostText( $msg ) { |
||
| 828 | |||
| 829 | /** |
||
| 830 | * Set text at the end of the display. |
||
| 831 | * |
||
| 832 | * @param string $msg Complete text of message to display |
||
| 833 | * |
||
| 834 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 835 | */ |
||
| 836 | public function setPostText( $msg ) { |
||
| 841 | |||
| 842 | /** |
||
| 843 | * Add a hidden field to the output |
||
| 844 | * |
||
| 845 | * @param string $name Field name. This will be used exactly as entered |
||
| 846 | * @param string $value Field value |
||
| 847 | * @param array $attribs |
||
| 848 | * |
||
| 849 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 850 | */ |
||
| 851 | public function addHiddenField( $name, $value, array $attribs = [] ) { |
||
| 857 | |||
| 858 | /** |
||
| 859 | * Add an array of hidden fields to the output |
||
| 860 | * |
||
| 861 | * @since 1.22 |
||
| 862 | * |
||
| 863 | * @param array $fields Associative array of fields to add; |
||
| 864 | * mapping names to their values |
||
| 865 | * |
||
| 866 | * @return HTMLForm $this for chaining calls |
||
| 867 | */ |
||
| 868 | public function addHiddenFields( array $fields ) { |
||
| 875 | |||
| 876 | /** |
||
| 877 | * Add a button to the form |
||
| 878 | * |
||
| 879 | * @since 1.27 takes an array as shown. Earlier versions accepted |
||
| 880 | * 'name', 'value', 'id', and 'attribs' as separate parameters in that |
||
| 881 | * order. |
||
| 882 | * @note Custom labels ('label', 'label-message', 'label-raw') are not |
||
| 883 | * supported for IE6 and IE7 due to bugs in those browsers. If detected, |
||
| 884 | * they will be served buttons using 'value' as the button label. |
||
| 885 | * @param array $data Data to define the button: |
||
| 886 | * - name: (string) Button name. |
||
| 887 | * - value: (string) Button value. |
||
| 888 | * - label-message: (string, optional) Button label message key to use |
||
| 889 | * instead of 'value'. Overrides 'label' and 'label-raw'. |
||
| 890 | * - label: (string, optional) Button label text to use instead of |
||
| 891 | * 'value'. Overrides 'label-raw'. |
||
| 892 | * - label-raw: (string, optional) Button label HTML to use instead of |
||
| 893 | * 'value'. |
||
| 894 | * - id: (string, optional) DOM id for the button. |
||
| 895 | * - attribs: (array, optional) Additional HTML attributes. |
||
| 896 | * - flags: (string|string[], optional) OOUI flags. |
||
| 897 | * - framed: (boolean=true, optional) OOUI framed attribute. |
||
| 898 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 899 | */ |
||
| 900 | public function addButton( $data ) { |
||
| 931 | |||
| 932 | /** |
||
| 933 | * Set the salt for the edit token. |
||
| 934 | * |
||
| 935 | * Only useful when the method is "post". |
||
| 936 | * |
||
| 937 | * @since 1.24 |
||
| 938 | * @param string|array $salt Salt to use |
||
| 939 | * @return HTMLForm $this For chaining calls |
||
| 940 | */ |
||
| 941 | public function setTokenSalt( $salt ) { |
||
| 946 | |||
| 947 | /** |
||
| 948 | * Display the form (sending to the context's OutputPage object), with an |
||
| 949 | * appropriate error message or stack of messages, and any validation errors, etc. |
||
| 950 | * |
||
| 951 | * @attention You should call prepareForm() before calling this function. |
||
| 952 | * Moreover, when doing method chaining this should be the very last method |
||
| 953 | * call just after prepareForm(). |
||
| 954 | * |
||
| 955 | * @param bool|string|array|Status $submitResult Output from HTMLForm::trySubmit() |
||
| 956 | * |
||
| 957 | * @return void Nothing, should be last call |
||
| 958 | */ |
||
| 959 | public function displayForm( $submitResult ) { |
||
| 962 | |||
| 963 | /** |
||
| 964 | * Returns the raw HTML generated by the form |
||
| 965 | * |
||
| 966 | * @param bool|string|array|Status $submitResult Output from HTMLForm::trySubmit() |
||
| 967 | * |
||
| 968 | * @return string HTML |
||
| 969 | */ |
||
| 970 | public function getHTML( $submitResult ) { |
||
| 988 | |||
| 989 | /** |
||
| 990 | * Get HTML attributes for the `<form>` tag. |
||
| 991 | * @return array |
||
| 992 | */ |
||
| 993 | protected function getFormAttributes() { |
||
| 1015 | |||
| 1016 | /** |
||
| 1017 | * Wrap the form innards in an actual "<form>" element |
||
| 1018 | * |
||
| 1019 | * @param string $html HTML contents to wrap. |
||
| 1020 | * |
||
| 1021 | * @return string Wrapped HTML. |
||
| 1022 | */ |
||
| 1023 | public function wrapForm( $html ) { |
||
| 1036 | |||
| 1037 | /** |
||
| 1038 | * Get the hidden fields that should go inside the form. |
||
| 1039 | * @return string HTML. |
||
| 1040 | */ |
||
| 1041 | public function getHiddenFields() { |
||
| 1064 | |||
| 1065 | /** |
||
| 1066 | * Get the submit and (potentially) reset buttons. |
||
| 1067 | * @return string HTML. |
||
| 1068 | */ |
||
| 1069 | public function getButtons() { |
||
| 1158 | |||
| 1159 | /** |
||
| 1160 | * Get the whole body of the form. |
||
| 1161 | * @return string |
||
| 1162 | */ |
||
| 1163 | public function getBody() { |
||
| 1166 | |||
| 1167 | /** |
||
| 1168 | * Format and display an error message stack. |
||
| 1169 | * |
||
| 1170 | * @param string|array|Status $errors |
||
| 1171 | * |
||
| 1172 | * @return string |
||
| 1173 | */ |
||
| 1174 | public function getErrors( $errors ) { |
||
| 1191 | |||
| 1192 | /** |
||
| 1193 | * Format a stack of error messages into a single HTML string |
||
| 1194 | * |
||
| 1195 | * @param array $errors Array of message keys/values |
||
| 1196 | * |
||
| 1197 | * @return string HTML, a "<ul>" list of errors |
||
| 1198 | */ |
||
| 1199 | public function formatErrors( $errors ) { |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * Set the text for the submit button |
||
| 1217 | * |
||
| 1218 | * @param string $t Plaintext |
||
| 1219 | * |
||
| 1220 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1221 | */ |
||
| 1222 | public function setSubmitText( $t ) { |
||
| 1227 | |||
| 1228 | /** |
||
| 1229 | * Identify that the submit button in the form has a destructive action |
||
| 1230 | * @since 1.24 |
||
| 1231 | * |
||
| 1232 | * @return HTMLForm $this for chaining calls (since 1.28) |
||
| 1233 | */ |
||
| 1234 | public function setSubmitDestructive() { |
||
| 1239 | |||
| 1240 | /** |
||
| 1241 | * Identify that the submit button in the form has a progressive action |
||
| 1242 | * @since 1.25 |
||
| 1243 | * |
||
| 1244 | * @return HTMLForm $this for chaining calls (since 1.28) |
||
| 1245 | */ |
||
| 1246 | public function setSubmitProgressive() { |
||
| 1251 | |||
| 1252 | /** |
||
| 1253 | * Set the text for the submit button to a message |
||
| 1254 | * @since 1.19 |
||
| 1255 | * |
||
| 1256 | * @param string|Message $msg Message key or Message object |
||
| 1257 | * |
||
| 1258 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1259 | */ |
||
| 1260 | public function setSubmitTextMsg( $msg ) { |
||
| 1268 | |||
| 1269 | /** |
||
| 1270 | * Get the text for the submit button, either customised or a default. |
||
| 1271 | * @return string |
||
| 1272 | */ |
||
| 1273 | public function getSubmitText() { |
||
| 1276 | |||
| 1277 | /** |
||
| 1278 | * @param string $name Submit button name |
||
| 1279 | * |
||
| 1280 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1281 | */ |
||
| 1282 | public function setSubmitName( $name ) { |
||
| 1287 | |||
| 1288 | /** |
||
| 1289 | * @param string $name Tooltip for the submit button |
||
| 1290 | * |
||
| 1291 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1292 | */ |
||
| 1293 | public function setSubmitTooltip( $name ) { |
||
| 1298 | |||
| 1299 | /** |
||
| 1300 | * Set the id for the submit button. |
||
| 1301 | * |
||
| 1302 | * @param string $t |
||
| 1303 | * |
||
| 1304 | * @todo FIXME: Integrity of $t is *not* validated |
||
| 1305 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1306 | */ |
||
| 1307 | public function setSubmitID( $t ) { |
||
| 1312 | |||
| 1313 | /** |
||
| 1314 | * Stop a default submit button being shown for this form. This implies that an |
||
| 1315 | * alternate submit method must be provided manually. |
||
| 1316 | * |
||
| 1317 | * @since 1.22 |
||
| 1318 | * |
||
| 1319 | * @param bool $suppressSubmit Set to false to re-enable the button again |
||
| 1320 | * |
||
| 1321 | * @return HTMLForm $this for chaining calls |
||
| 1322 | */ |
||
| 1323 | public function suppressDefaultSubmit( $suppressSubmit = true ) { |
||
| 1328 | |||
| 1329 | /** |
||
| 1330 | * Set the id of the \<table\> or outermost \<div\> element. |
||
| 1331 | * |
||
| 1332 | * @since 1.22 |
||
| 1333 | * |
||
| 1334 | * @param string $id New value of the id attribute, or "" to remove |
||
| 1335 | * |
||
| 1336 | * @return HTMLForm $this for chaining calls |
||
| 1337 | */ |
||
| 1338 | public function setTableId( $id ) { |
||
| 1343 | |||
| 1344 | /** |
||
| 1345 | * @param string $id DOM id for the form |
||
| 1346 | * |
||
| 1347 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1348 | */ |
||
| 1349 | public function setId( $id ) { |
||
| 1354 | |||
| 1355 | /** |
||
| 1356 | * @param string $name 'name' attribute for the form |
||
| 1357 | * @return HTMLForm $this for chaining calls |
||
| 1358 | */ |
||
| 1359 | public function setName( $name ) { |
||
| 1364 | |||
| 1365 | /** |
||
| 1366 | * Prompt the whole form to be wrapped in a "<fieldset>", with |
||
| 1367 | * this text as its "<legend>" element. |
||
| 1368 | * |
||
| 1369 | * @param string|bool $legend If false, no wrapper or legend will be displayed. |
||
| 1370 | * If true, a wrapper will be displayed, but no legend. |
||
| 1371 | * If a string, a wrapper will be displayed with that string as a legend. |
||
| 1372 | * The string will be escaped before being output (this doesn't support HTML). |
||
| 1373 | * |
||
| 1374 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1375 | */ |
||
| 1376 | public function setWrapperLegend( $legend ) { |
||
| 1381 | |||
| 1382 | /** |
||
| 1383 | * Prompt the whole form to be wrapped in a "<fieldset>", with |
||
| 1384 | * this message as its "<legend>" element. |
||
| 1385 | * @since 1.19 |
||
| 1386 | * |
||
| 1387 | * @param string|Message $msg Message key or Message object |
||
| 1388 | * |
||
| 1389 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1390 | */ |
||
| 1391 | public function setWrapperLegendMsg( $msg ) { |
||
| 1399 | |||
| 1400 | /** |
||
| 1401 | * Set the prefix for various default messages |
||
| 1402 | * @todo Currently only used for the "<fieldset>" legend on forms |
||
| 1403 | * with multiple sections; should be used elsewhere? |
||
| 1404 | * |
||
| 1405 | * @param string $p |
||
| 1406 | * |
||
| 1407 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1408 | */ |
||
| 1409 | public function setMessagePrefix( $p ) { |
||
| 1414 | |||
| 1415 | /** |
||
| 1416 | * Set the title for form submission |
||
| 1417 | * |
||
| 1418 | * @param Title $t Title of page the form is on/should be posted to |
||
| 1419 | * |
||
| 1420 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1421 | */ |
||
| 1422 | public function setTitle( $t ) { |
||
| 1427 | |||
| 1428 | /** |
||
| 1429 | * Get the title |
||
| 1430 | * @return Title |
||
| 1431 | */ |
||
| 1432 | public function getTitle() { |
||
| 1437 | |||
| 1438 | /** |
||
| 1439 | * Set the method used to submit the form |
||
| 1440 | * |
||
| 1441 | * @param string $method |
||
| 1442 | * |
||
| 1443 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1444 | */ |
||
| 1445 | public function setMethod( $method = 'post' ) { |
||
| 1450 | |||
| 1451 | /** |
||
| 1452 | * @return string Always lowercase |
||
| 1453 | */ |
||
| 1454 | public function getMethod() { |
||
| 1457 | |||
| 1458 | /** |
||
| 1459 | * Wraps the given $section into an user-visible fieldset. |
||
| 1460 | * |
||
| 1461 | * @param string $legend Legend text for the fieldset |
||
| 1462 | * @param string $section The section content in plain Html |
||
| 1463 | * @param array $attributes Additional attributes for the fieldset |
||
| 1464 | * @return string The fieldset's Html |
||
| 1465 | */ |
||
| 1466 | protected function wrapFieldSetSection( $legend, $section, $attributes ) { |
||
| 1469 | |||
| 1470 | /** |
||
| 1471 | * @todo Document |
||
| 1472 | * |
||
| 1473 | * @param array[]|HTMLFormField[] $fields Array of fields (either arrays or |
||
| 1474 | * objects). |
||
| 1475 | * @param string $sectionName ID attribute of the "<table>" tag for this |
||
| 1476 | * section, ignored if empty. |
||
| 1477 | * @param string $fieldsetIDPrefix ID prefix for the "<fieldset>" tag of |
||
| 1478 | * each subsection, ignored if empty. |
||
| 1479 | * @param bool &$hasUserVisibleFields Whether the section had user-visible fields. |
||
| 1480 | * @throws LogicException When called on uninitialized field data, e.g. When |
||
| 1481 | * HTMLForm::displayForm was called without calling HTMLForm::prepareForm |
||
| 1482 | * first. |
||
| 1483 | * |
||
| 1484 | * @return string |
||
| 1485 | */ |
||
| 1486 | public function displaySection( $fields, |
||
| 1569 | |||
| 1570 | /** |
||
| 1571 | * Put a form section together from the individual fields' HTML, merging it and wrapping. |
||
| 1572 | * @param array $fieldsHtml |
||
| 1573 | * @param string $sectionName |
||
| 1574 | * @param bool $anyFieldHasLabel |
||
| 1575 | * @return string HTML |
||
| 1576 | */ |
||
| 1577 | protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) { |
||
| 1609 | |||
| 1610 | /** |
||
| 1611 | * Construct the form fields from the Descriptor array |
||
| 1612 | */ |
||
| 1613 | public function loadData() { |
||
| 1635 | |||
| 1636 | /** |
||
| 1637 | * Stop a reset button being shown for this form |
||
| 1638 | * |
||
| 1639 | * @param bool $suppressReset Set to false to re-enable the button again |
||
| 1640 | * |
||
| 1641 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1642 | */ |
||
| 1643 | public function suppressReset( $suppressReset = true ) { |
||
| 1648 | |||
| 1649 | /** |
||
| 1650 | * Overload this if you want to apply special filtration routines |
||
| 1651 | * to the form as a whole, after it's submitted but before it's |
||
| 1652 | * processed. |
||
| 1653 | * |
||
| 1654 | * @param array $data |
||
| 1655 | * |
||
| 1656 | * @return array |
||
| 1657 | */ |
||
| 1658 | public function filterDataForSubmit( $data ) { |
||
| 1661 | |||
| 1662 | /** |
||
| 1663 | * Get a string to go in the "<legend>" of a section fieldset. |
||
| 1664 | * Override this if you want something more complicated. |
||
| 1665 | * |
||
| 1666 | * @param string $key |
||
| 1667 | * |
||
| 1668 | * @return string |
||
| 1669 | */ |
||
| 1670 | public function getLegend( $key ) { |
||
| 1673 | |||
| 1674 | /** |
||
| 1675 | * Set the value for the action attribute of the form. |
||
| 1676 | * When set to false (which is the default state), the set title is used. |
||
| 1677 | * |
||
| 1678 | * @since 1.19 |
||
| 1679 | * |
||
| 1680 | * @param string|bool $action |
||
| 1681 | * |
||
| 1682 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1683 | */ |
||
| 1684 | public function setAction( $action ) { |
||
| 1689 | |||
| 1690 | /** |
||
| 1691 | * Get the value for the action attribute of the form. |
||
| 1692 | * |
||
| 1693 | * @since 1.22 |
||
| 1694 | * |
||
| 1695 | * @return string |
||
| 1696 | */ |
||
| 1697 | public function getAction() { |
||
| 1715 | |||
| 1716 | /** |
||
| 1717 | * Set the value for the autocomplete attribute of the form. |
||
| 1718 | * When set to false (which is the default state), the attribute get not set. |
||
| 1719 | * |
||
| 1720 | * @since 1.27 |
||
| 1721 | * |
||
| 1722 | * @param string|bool $autocomplete |
||
| 1723 | * |
||
| 1724 | * @return HTMLForm $this for chaining calls |
||
| 1725 | */ |
||
| 1726 | public function setAutocomplete( $autocomplete ) { |
||
| 1731 | |||
| 1732 | /** |
||
| 1733 | * Turns a *-message parameter (which could be a MessageSpecifier, or a message name, or a |
||
| 1734 | * name + parameters array) into a Message. |
||
| 1735 | * @param mixed $value |
||
| 1736 | * @return Message |
||
| 1737 | */ |
||
| 1738 | protected function getMessage( $value ) { |
||
| 1741 | } |
||
| 1742 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.