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 |
||
| 128 | class HTMLForm extends ContextSource { |
||
| 129 | // A mapping of 'type' inputs onto standard HTMLFormField subclasses |
||
| 130 | public static $typeMappings = [ |
||
| 131 | 'api' => 'HTMLApiField', |
||
| 132 | 'text' => 'HTMLTextField', |
||
| 133 | 'textwithbutton' => 'HTMLTextFieldWithButton', |
||
| 134 | 'textarea' => 'HTMLTextAreaField', |
||
| 135 | 'select' => 'HTMLSelectField', |
||
| 136 | 'combobox' => 'HTMLComboboxField', |
||
| 137 | 'radio' => 'HTMLRadioField', |
||
| 138 | 'multiselect' => 'HTMLMultiSelectField', |
||
| 139 | 'limitselect' => 'HTMLSelectLimitField', |
||
| 140 | 'check' => 'HTMLCheckField', |
||
| 141 | 'toggle' => 'HTMLCheckField', |
||
| 142 | 'int' => 'HTMLIntField', |
||
| 143 | 'float' => 'HTMLFloatField', |
||
| 144 | 'info' => 'HTMLInfoField', |
||
| 145 | 'selectorother' => 'HTMLSelectOrOtherField', |
||
| 146 | 'selectandother' => 'HTMLSelectAndOtherField', |
||
| 147 | 'namespaceselect' => 'HTMLSelectNamespace', |
||
| 148 | 'namespaceselectwithbutton' => 'HTMLSelectNamespaceWithButton', |
||
| 149 | 'tagfilter' => 'HTMLTagFilter', |
||
| 150 | 'sizefilter' => 'HTMLSizeFilterField', |
||
| 151 | 'submit' => 'HTMLSubmitField', |
||
| 152 | 'hidden' => 'HTMLHiddenField', |
||
| 153 | 'edittools' => 'HTMLEditTools', |
||
| 154 | 'checkmatrix' => 'HTMLCheckMatrix', |
||
| 155 | 'cloner' => 'HTMLFormFieldCloner', |
||
| 156 | 'autocompleteselect' => 'HTMLAutoCompleteSelectField', |
||
| 157 | 'date' => 'HTMLDateTimeField', |
||
| 158 | 'time' => 'HTMLDateTimeField', |
||
| 159 | 'datetime' => 'HTMLDateTimeField', |
||
| 160 | // HTMLTextField will output the correct type="" attribute automagically. |
||
| 161 | // There are about four zillion other HTML5 input types, like range, but |
||
| 162 | // we don't use those at the moment, so no point in adding all of them. |
||
| 163 | 'email' => 'HTMLTextField', |
||
| 164 | 'password' => 'HTMLTextField', |
||
| 165 | 'url' => 'HTMLTextField', |
||
| 166 | 'title' => 'HTMLTitleTextField', |
||
| 167 | 'user' => 'HTMLUserTextField', |
||
| 168 | ]; |
||
| 169 | |||
| 170 | public $mFieldData; |
||
| 171 | |||
| 172 | protected $mMessagePrefix; |
||
| 173 | |||
| 174 | /** @var HTMLFormField[] */ |
||
| 175 | protected $mFlatFields; |
||
| 176 | |||
| 177 | protected $mFieldTree; |
||
| 178 | protected $mShowReset = false; |
||
| 179 | protected $mShowSubmit = true; |
||
| 180 | protected $mSubmitFlags = [ 'primary', 'progressive' ]; |
||
| 181 | protected $mShowCancel = false; |
||
| 182 | protected $mCancelTarget; |
||
| 183 | |||
| 184 | protected $mSubmitCallback; |
||
| 185 | protected $mValidationErrorMessage; |
||
| 186 | |||
| 187 | protected $mPre = ''; |
||
| 188 | protected $mHeader = ''; |
||
| 189 | protected $mFooter = ''; |
||
| 190 | protected $mSectionHeaders = []; |
||
| 191 | protected $mSectionFooters = []; |
||
| 192 | protected $mPost = ''; |
||
| 193 | protected $mId; |
||
| 194 | protected $mName; |
||
| 195 | protected $mTableId = ''; |
||
| 196 | |||
| 197 | protected $mSubmitID; |
||
| 198 | protected $mSubmitName; |
||
| 199 | protected $mSubmitText; |
||
| 200 | protected $mSubmitTooltip; |
||
| 201 | |||
| 202 | protected $mFormIdentifier; |
||
| 203 | protected $mTitle; |
||
| 204 | protected $mMethod = 'post'; |
||
| 205 | protected $mWasSubmitted = false; |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Form action URL. false means we will use the URL to set Title |
||
| 209 | * @since 1.19 |
||
| 210 | * @var bool|string |
||
| 211 | */ |
||
| 212 | protected $mAction = false; |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Form attribute autocomplete. false does not set the attribute |
||
| 216 | * @since 1.27 |
||
| 217 | * @var bool|string |
||
| 218 | */ |
||
| 219 | protected $mAutocomplete = false; |
||
| 220 | |||
| 221 | protected $mUseMultipart = false; |
||
| 222 | protected $mHiddenFields = []; |
||
| 223 | protected $mButtons = []; |
||
| 224 | |||
| 225 | protected $mWrapperLegend = false; |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Salt for the edit token. |
||
| 229 | * @var string|array |
||
| 230 | */ |
||
| 231 | protected $mTokenSalt = ''; |
||
| 232 | |||
| 233 | /** |
||
| 234 | * If true, sections that contain both fields and subsections will |
||
| 235 | * render their subsections before their fields. |
||
| 236 | * |
||
| 237 | * Subclasses may set this to false to render subsections after fields |
||
| 238 | * instead. |
||
| 239 | */ |
||
| 240 | protected $mSubSectionBeforeFields = true; |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Format in which to display form. For viable options, |
||
| 244 | * @see $availableDisplayFormats |
||
| 245 | * @var string |
||
| 246 | */ |
||
| 247 | protected $displayFormat = 'table'; |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Available formats in which to display the form |
||
| 251 | * @var array |
||
| 252 | */ |
||
| 253 | protected $availableDisplayFormats = [ |
||
| 254 | 'table', |
||
| 255 | 'div', |
||
| 256 | 'raw', |
||
| 257 | 'inline', |
||
| 258 | ]; |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Available formats in which to display the form |
||
| 262 | * @var array |
||
| 263 | */ |
||
| 264 | protected $availableSubclassDisplayFormats = [ |
||
| 265 | 'vform', |
||
| 266 | 'ooui', |
||
| 267 | ]; |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Construct a HTMLForm object for given display type. May return a HTMLForm subclass. |
||
| 271 | * |
||
| 272 | * @param string $displayFormat |
||
| 273 | * @param mixed $arguments... Additional arguments to pass to the constructor. |
||
|
|
|||
| 274 | * @return HTMLForm |
||
| 275 | */ |
||
| 276 | public static function factory( $displayFormat/*, $arguments...*/ ) { |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Build a new HTMLForm from an array of field attributes |
||
| 295 | * |
||
| 296 | * @param array $descriptor Array of Field constructs, as described above |
||
| 297 | * @param IContextSource $context Available since 1.18, will become compulsory in 1.18. |
||
| 298 | * Obviates the need to call $form->setTitle() |
||
| 299 | * @param string $messagePrefix A prefix to go in front of default messages |
||
| 300 | */ |
||
| 301 | public function __construct( $descriptor, /*IContextSource*/ $context = null, |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @param string $fieldname |
||
| 363 | * @return bool |
||
| 364 | */ |
||
| 365 | public function hasField( $fieldname ) { |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @param string $fieldname |
||
| 371 | * @return HTMLFormField |
||
| 372 | * @throws DomainException on invalid field name |
||
| 373 | */ |
||
| 374 | public function getField( $fieldname ) { |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Set format in which to display the form |
||
| 383 | * |
||
| 384 | * @param string $format The name of the format to use, must be one of |
||
| 385 | * $this->availableDisplayFormats |
||
| 386 | * |
||
| 387 | * @throws MWException |
||
| 388 | * @since 1.20 |
||
| 389 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 390 | */ |
||
| 391 | public function setDisplayFormat( $format ) { |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Getter for displayFormat |
||
| 417 | * @since 1.20 |
||
| 418 | * @return string |
||
| 419 | */ |
||
| 420 | public function getDisplayFormat() { |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Test if displayFormat is 'vform' |
||
| 426 | * @since 1.22 |
||
| 427 | * @deprecated since 1.25 |
||
| 428 | * @return bool |
||
| 429 | */ |
||
| 430 | public function isVForm() { |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Get the HTMLFormField subclass for this descriptor. |
||
| 437 | * |
||
| 438 | * The descriptor can be passed either 'class' which is the name of |
||
| 439 | * a HTMLFormField subclass, or a shorter 'type' which is an alias. |
||
| 440 | * This makes sure the 'class' is always set, and also is returned by |
||
| 441 | * this function for ease. |
||
| 442 | * |
||
| 443 | * @since 1.23 |
||
| 444 | * |
||
| 445 | * @param string $fieldname Name of the field |
||
| 446 | * @param array $descriptor Input Descriptor, as described above |
||
| 447 | * |
||
| 448 | * @throws MWException |
||
| 449 | * @return string Name of a HTMLFormField subclass |
||
| 450 | */ |
||
| 451 | public static function getClassFromDescriptor( $fieldname, &$descriptor ) { |
||
| 468 | |||
| 469 | /** |
||
| 470 | * Initialise a new Object for the field |
||
| 471 | * |
||
| 472 | * @param string $fieldname Name of the field |
||
| 473 | * @param array $descriptor Input Descriptor, as described above |
||
| 474 | * @param HTMLForm|null $parent Parent instance of HTMLForm |
||
| 475 | * |
||
| 476 | * @throws MWException |
||
| 477 | * @return HTMLFormField Instance of a subclass of HTMLFormField |
||
| 478 | */ |
||
| 479 | public static function loadInputFromParameters( $fieldname, $descriptor, |
||
| 494 | |||
| 495 | /** |
||
| 496 | * Prepare form for submission. |
||
| 497 | * |
||
| 498 | * @attention When doing method chaining, that should be the very last |
||
| 499 | * method call before displayForm(). |
||
| 500 | * |
||
| 501 | * @throws MWException |
||
| 502 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 503 | */ |
||
| 504 | public function prepareForm() { |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Try submitting, with edit token check first |
||
| 525 | * @return Status|bool |
||
| 526 | */ |
||
| 527 | public function tryAuthorizedSubmit() { |
||
| 559 | |||
| 560 | /** |
||
| 561 | * The here's-one-I-made-earlier option: do the submission if |
||
| 562 | * posted, or display the form with or without funky validation |
||
| 563 | * errors |
||
| 564 | * @return bool|Status Whether submission was successful. |
||
| 565 | */ |
||
| 566 | public function show() { |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Same as self::show with the difference, that the form will be |
||
| 581 | * added to the output, no matter, if the validation was good or not. |
||
| 582 | * @return bool|Status Whether submission was successful. |
||
| 583 | */ |
||
| 584 | public function showAlways() { |
||
| 593 | |||
| 594 | /** |
||
| 595 | * Validate all the fields, and call the submission callback |
||
| 596 | * function if everything is kosher. |
||
| 597 | * @throws MWException |
||
| 598 | * @return bool|string|array|Status |
||
| 599 | * - Bool true or a good Status object indicates success, |
||
| 600 | * - Bool false indicates no submission was attempted, |
||
| 601 | * - Anything else indicates failure. The value may be a fatal Status |
||
| 602 | * object, an HTML string, or an array of arrays (message keys and |
||
| 603 | * params) or strings (message keys) |
||
| 604 | */ |
||
| 605 | public function trySubmit() { |
||
| 664 | |||
| 665 | /** |
||
| 666 | * Test whether the form was considered to have been submitted or not, i.e. |
||
| 667 | * whether the last call to tryAuthorizedSubmit or trySubmit returned |
||
| 668 | * non-false. |
||
| 669 | * |
||
| 670 | * This will return false until HTMLForm::tryAuthorizedSubmit or |
||
| 671 | * HTMLForm::trySubmit is called. |
||
| 672 | * |
||
| 673 | * @since 1.23 |
||
| 674 | * @return bool |
||
| 675 | */ |
||
| 676 | public function wasSubmitted() { |
||
| 679 | |||
| 680 | /** |
||
| 681 | * Set a callback to a function to do something with the form |
||
| 682 | * once it's been successfully validated. |
||
| 683 | * |
||
| 684 | * @param callable $cb The function will be passed the output from |
||
| 685 | * HTMLForm::filterDataForSubmit and this HTMLForm object, and must |
||
| 686 | * return as documented for HTMLForm::trySubmit |
||
| 687 | * |
||
| 688 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 689 | */ |
||
| 690 | public function setSubmitCallback( $cb ) { |
||
| 695 | |||
| 696 | /** |
||
| 697 | * Set a message to display on a validation error. |
||
| 698 | * |
||
| 699 | * @param string|array $msg String or Array of valid inputs to wfMessage() |
||
| 700 | * (so each entry can be either a String or Array) |
||
| 701 | * |
||
| 702 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 703 | */ |
||
| 704 | public function setValidationErrorMessage( $msg ) { |
||
| 709 | |||
| 710 | /** |
||
| 711 | * Set the introductory message, overwriting any existing message. |
||
| 712 | * |
||
| 713 | * @param string $msg Complete text of message to display |
||
| 714 | * |
||
| 715 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 716 | */ |
||
| 717 | public function setIntro( $msg ) { |
||
| 722 | |||
| 723 | /** |
||
| 724 | * Set the introductory message HTML, overwriting any existing message. |
||
| 725 | * @since 1.19 |
||
| 726 | * |
||
| 727 | * @param string $msg Complete HTML of message to display |
||
| 728 | * |
||
| 729 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 730 | */ |
||
| 731 | public function setPreText( $msg ) { |
||
| 736 | |||
| 737 | /** |
||
| 738 | * Add HTML to introductory message. |
||
| 739 | * |
||
| 740 | * @param string $msg Complete HTML of message to display |
||
| 741 | * |
||
| 742 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 743 | */ |
||
| 744 | public function addPreText( $msg ) { |
||
| 749 | |||
| 750 | /** |
||
| 751 | * Add HTML to the header, inside the form. |
||
| 752 | * |
||
| 753 | * @param string $msg Additional HTML to display in header |
||
| 754 | * @param string|null $section The section to add the header to |
||
| 755 | * |
||
| 756 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 757 | */ |
||
| 758 | View Code Duplication | public function addHeaderText( $msg, $section = null ) { |
|
| 770 | |||
| 771 | /** |
||
| 772 | * Set header text, inside the form. |
||
| 773 | * @since 1.19 |
||
| 774 | * |
||
| 775 | * @param string $msg Complete HTML of header to display |
||
| 776 | * @param string|null $section The section to add the header to |
||
| 777 | * |
||
| 778 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 779 | */ |
||
| 780 | public function setHeaderText( $msg, $section = null ) { |
||
| 789 | |||
| 790 | /** |
||
| 791 | * Get header text. |
||
| 792 | * |
||
| 793 | * @param string|null $section The section to get the header text for |
||
| 794 | * @since 1.26 |
||
| 795 | * @return string HTML |
||
| 796 | */ |
||
| 797 | public function getHeaderText( $section = null ) { |
||
| 804 | |||
| 805 | /** |
||
| 806 | * Add footer text, inside the form. |
||
| 807 | * |
||
| 808 | * @param string $msg Complete text of message to display |
||
| 809 | * @param string|null $section The section to add the footer text to |
||
| 810 | * |
||
| 811 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 812 | */ |
||
| 813 | View Code Duplication | public function addFooterText( $msg, $section = null ) { |
|
| 825 | |||
| 826 | /** |
||
| 827 | * Set footer text, inside the form. |
||
| 828 | * @since 1.19 |
||
| 829 | * |
||
| 830 | * @param string $msg Complete text of message to display |
||
| 831 | * @param string|null $section The section to add the footer text to |
||
| 832 | * |
||
| 833 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 834 | */ |
||
| 835 | public function setFooterText( $msg, $section = null ) { |
||
| 844 | |||
| 845 | /** |
||
| 846 | * Get footer text. |
||
| 847 | * |
||
| 848 | * @param string|null $section The section to get the footer text for |
||
| 849 | * @since 1.26 |
||
| 850 | * @return string |
||
| 851 | */ |
||
| 852 | public function getFooterText( $section = null ) { |
||
| 859 | |||
| 860 | /** |
||
| 861 | * Add text to the end of the display. |
||
| 862 | * |
||
| 863 | * @param string $msg Complete text of message to display |
||
| 864 | * |
||
| 865 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 866 | */ |
||
| 867 | public function addPostText( $msg ) { |
||
| 872 | |||
| 873 | /** |
||
| 874 | * Set text at the end of the display. |
||
| 875 | * |
||
| 876 | * @param string $msg Complete text of message to display |
||
| 877 | * |
||
| 878 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 879 | */ |
||
| 880 | public function setPostText( $msg ) { |
||
| 885 | |||
| 886 | /** |
||
| 887 | * Add a hidden field to the output |
||
| 888 | * |
||
| 889 | * @param string $name Field name. This will be used exactly as entered |
||
| 890 | * @param string $value Field value |
||
| 891 | * @param array $attribs |
||
| 892 | * |
||
| 893 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 894 | */ |
||
| 895 | public function addHiddenField( $name, $value, array $attribs = [] ) { |
||
| 901 | |||
| 902 | /** |
||
| 903 | * Add an array of hidden fields to the output |
||
| 904 | * |
||
| 905 | * @since 1.22 |
||
| 906 | * |
||
| 907 | * @param array $fields Associative array of fields to add; |
||
| 908 | * mapping names to their values |
||
| 909 | * |
||
| 910 | * @return HTMLForm $this for chaining calls |
||
| 911 | */ |
||
| 912 | public function addHiddenFields( array $fields ) { |
||
| 919 | |||
| 920 | /** |
||
| 921 | * Add a button to the form |
||
| 922 | * |
||
| 923 | * @since 1.27 takes an array as shown. Earlier versions accepted |
||
| 924 | * 'name', 'value', 'id', and 'attribs' as separate parameters in that |
||
| 925 | * order. |
||
| 926 | * @note Custom labels ('label', 'label-message', 'label-raw') are not |
||
| 927 | * supported for IE6 and IE7 due to bugs in those browsers. If detected, |
||
| 928 | * they will be served buttons using 'value' as the button label. |
||
| 929 | * @param array $data Data to define the button: |
||
| 930 | * - name: (string) Button name. |
||
| 931 | * - value: (string) Button value. |
||
| 932 | * - label-message: (string, optional) Button label message key to use |
||
| 933 | * instead of 'value'. Overrides 'label' and 'label-raw'. |
||
| 934 | * - label: (string, optional) Button label text to use instead of |
||
| 935 | * 'value'. Overrides 'label-raw'. |
||
| 936 | * - label-raw: (string, optional) Button label HTML to use instead of |
||
| 937 | * 'value'. |
||
| 938 | * - id: (string, optional) DOM id for the button. |
||
| 939 | * - attribs: (array, optional) Additional HTML attributes. |
||
| 940 | * - flags: (string|string[], optional) OOUI flags. |
||
| 941 | * - framed: (boolean=true, optional) OOUI framed attribute. |
||
| 942 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 943 | */ |
||
| 944 | public function addButton( $data ) { |
||
| 975 | |||
| 976 | /** |
||
| 977 | * Set the salt for the edit token. |
||
| 978 | * |
||
| 979 | * Only useful when the method is "post". |
||
| 980 | * |
||
| 981 | * @since 1.24 |
||
| 982 | * @param string|array $salt Salt to use |
||
| 983 | * @return HTMLForm $this For chaining calls |
||
| 984 | */ |
||
| 985 | public function setTokenSalt( $salt ) { |
||
| 990 | |||
| 991 | /** |
||
| 992 | * Display the form (sending to the context's OutputPage object), with an |
||
| 993 | * appropriate error message or stack of messages, and any validation errors, etc. |
||
| 994 | * |
||
| 995 | * @attention You should call prepareForm() before calling this function. |
||
| 996 | * Moreover, when doing method chaining this should be the very last method |
||
| 997 | * call just after prepareForm(). |
||
| 998 | * |
||
| 999 | * @param bool|string|array|Status $submitResult Output from HTMLForm::trySubmit() |
||
| 1000 | * |
||
| 1001 | * @return void Nothing, should be last call |
||
| 1002 | */ |
||
| 1003 | public function displayForm( $submitResult ) { |
||
| 1006 | |||
| 1007 | /** |
||
| 1008 | * Returns the raw HTML generated by the form |
||
| 1009 | * |
||
| 1010 | * @param bool|string|array|Status $submitResult Output from HTMLForm::trySubmit() |
||
| 1011 | * |
||
| 1012 | * @return string HTML |
||
| 1013 | */ |
||
| 1014 | public function getHTML( $submitResult ) { |
||
| 1033 | |||
| 1034 | /** |
||
| 1035 | * Get HTML attributes for the `<form>` tag. |
||
| 1036 | * @return array |
||
| 1037 | */ |
||
| 1038 | protected function getFormAttributes() { |
||
| 1060 | |||
| 1061 | /** |
||
| 1062 | * Wrap the form innards in an actual "<form>" element |
||
| 1063 | * |
||
| 1064 | * @param string $html HTML contents to wrap. |
||
| 1065 | * |
||
| 1066 | * @return string Wrapped HTML. |
||
| 1067 | */ |
||
| 1068 | public function wrapForm( $html ) { |
||
| 1081 | |||
| 1082 | /** |
||
| 1083 | * Get the hidden fields that should go inside the form. |
||
| 1084 | * @return string HTML. |
||
| 1085 | */ |
||
| 1086 | public function getHiddenFields() { |
||
| 1115 | |||
| 1116 | /** |
||
| 1117 | * Get the submit and (potentially) reset buttons. |
||
| 1118 | * @return string HTML. |
||
| 1119 | */ |
||
| 1120 | public function getButtons() { |
||
| 1224 | |||
| 1225 | /** |
||
| 1226 | * Get the whole body of the form. |
||
| 1227 | * @return string |
||
| 1228 | */ |
||
| 1229 | public function getBody() { |
||
| 1232 | |||
| 1233 | /** |
||
| 1234 | * Format and display an error message stack. |
||
| 1235 | * |
||
| 1236 | * @param string|array|Status $errors |
||
| 1237 | * |
||
| 1238 | * @deprecated since 1.28, use getErrorsOrWarnings() instead |
||
| 1239 | * |
||
| 1240 | * @return string |
||
| 1241 | */ |
||
| 1242 | public function getErrors( $errors ) { |
||
| 1246 | |||
| 1247 | /** |
||
| 1248 | * Returns a formatted list of errors or warnings from the given elements. |
||
| 1249 | * |
||
| 1250 | * @param string|array|Status $elements The set of errors/warnings to process. |
||
| 1251 | * @param string $elementsType Should warnings or errors be returned. This is meant |
||
| 1252 | * for Status objects, all other valid types are always considered as errors. |
||
| 1253 | * @return string |
||
| 1254 | */ |
||
| 1255 | public function getErrorsOrWarnings( $elements, $elementsType ) { |
||
| 1280 | |||
| 1281 | /** |
||
| 1282 | * Format a stack of error messages into a single HTML string |
||
| 1283 | * |
||
| 1284 | * @param array $errors Array of message keys/values |
||
| 1285 | * |
||
| 1286 | * @return string HTML, a "<ul>" list of errors |
||
| 1287 | */ |
||
| 1288 | public function formatErrors( $errors ) { |
||
| 1303 | |||
| 1304 | /** |
||
| 1305 | * Set the text for the submit button |
||
| 1306 | * |
||
| 1307 | * @param string $t Plaintext |
||
| 1308 | * |
||
| 1309 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1310 | */ |
||
| 1311 | public function setSubmitText( $t ) { |
||
| 1316 | |||
| 1317 | /** |
||
| 1318 | * Identify that the submit button in the form has a destructive action |
||
| 1319 | * @since 1.24 |
||
| 1320 | * |
||
| 1321 | * @return HTMLForm $this for chaining calls (since 1.28) |
||
| 1322 | */ |
||
| 1323 | public function setSubmitDestructive() { |
||
| 1328 | |||
| 1329 | /** |
||
| 1330 | * Identify that the submit button in the form has a progressive action |
||
| 1331 | * @since 1.25 |
||
| 1332 | * |
||
| 1333 | * @return HTMLForm $this for chaining calls (since 1.28) |
||
| 1334 | */ |
||
| 1335 | public function setSubmitProgressive() { |
||
| 1340 | |||
| 1341 | /** |
||
| 1342 | * Set the text for the submit button to a message |
||
| 1343 | * @since 1.19 |
||
| 1344 | * |
||
| 1345 | * @param string|Message $msg Message key or Message object |
||
| 1346 | * |
||
| 1347 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1348 | */ |
||
| 1349 | public function setSubmitTextMsg( $msg ) { |
||
| 1357 | |||
| 1358 | /** |
||
| 1359 | * Get the text for the submit button, either customised or a default. |
||
| 1360 | * @return string |
||
| 1361 | */ |
||
| 1362 | public function getSubmitText() { |
||
| 1365 | |||
| 1366 | /** |
||
| 1367 | * @param string $name Submit button name |
||
| 1368 | * |
||
| 1369 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1370 | */ |
||
| 1371 | public function setSubmitName( $name ) { |
||
| 1376 | |||
| 1377 | /** |
||
| 1378 | * @param string $name Tooltip for the submit button |
||
| 1379 | * |
||
| 1380 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1381 | */ |
||
| 1382 | public function setSubmitTooltip( $name ) { |
||
| 1387 | |||
| 1388 | /** |
||
| 1389 | * Set the id for the submit button. |
||
| 1390 | * |
||
| 1391 | * @param string $t |
||
| 1392 | * |
||
| 1393 | * @todo FIXME: Integrity of $t is *not* validated |
||
| 1394 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1395 | */ |
||
| 1396 | public function setSubmitID( $t ) { |
||
| 1401 | |||
| 1402 | /** |
||
| 1403 | * Set an internal identifier for this form. It will be submitted as a hidden form field, allowing |
||
| 1404 | * HTMLForm to determine whether the form was submitted (or merely viewed). Setting this serves |
||
| 1405 | * two purposes: |
||
| 1406 | * |
||
| 1407 | * - If you use two or more forms on one page, it allows HTMLForm to identify which of the forms |
||
| 1408 | * was submitted, and not attempt to validate the other ones. |
||
| 1409 | * - If you use checkbox or multiselect fields inside a form using the GET method, it allows |
||
| 1410 | * HTMLForm to distinguish between the initial page view and a form submission with all |
||
| 1411 | * checkboxes or select options unchecked. |
||
| 1412 | * |
||
| 1413 | * @since 1.28 |
||
| 1414 | * @param string $ident |
||
| 1415 | * @return $this |
||
| 1416 | */ |
||
| 1417 | public function setFormIdentifier( $ident ) { |
||
| 1422 | |||
| 1423 | /** |
||
| 1424 | * Stop a default submit button being shown for this form. This implies that an |
||
| 1425 | * alternate submit method must be provided manually. |
||
| 1426 | * |
||
| 1427 | * @since 1.22 |
||
| 1428 | * |
||
| 1429 | * @param bool $suppressSubmit Set to false to re-enable the button again |
||
| 1430 | * |
||
| 1431 | * @return HTMLForm $this for chaining calls |
||
| 1432 | */ |
||
| 1433 | public function suppressDefaultSubmit( $suppressSubmit = true ) { |
||
| 1438 | |||
| 1439 | /** |
||
| 1440 | * Show a cancel button (or prevent it). The button is not shown by default. |
||
| 1441 | * @param bool $show |
||
| 1442 | * @return HTMLForm $this for chaining calls |
||
| 1443 | * @since 1.27 |
||
| 1444 | */ |
||
| 1445 | public function showCancel( $show = true ) { |
||
| 1449 | |||
| 1450 | /** |
||
| 1451 | * Sets the target where the user is redirected to after clicking cancel. |
||
| 1452 | * @param Title|string $target Target as a Title object or an URL |
||
| 1453 | * @return HTMLForm $this for chaining calls |
||
| 1454 | * @since 1.27 |
||
| 1455 | */ |
||
| 1456 | public function setCancelTarget( $target ) { |
||
| 1460 | |||
| 1461 | /** |
||
| 1462 | * Set the id of the \<table\> or outermost \<div\> element. |
||
| 1463 | * |
||
| 1464 | * @since 1.22 |
||
| 1465 | * |
||
| 1466 | * @param string $id New value of the id attribute, or "" to remove |
||
| 1467 | * |
||
| 1468 | * @return HTMLForm $this for chaining calls |
||
| 1469 | */ |
||
| 1470 | public function setTableId( $id ) { |
||
| 1475 | |||
| 1476 | /** |
||
| 1477 | * @param string $id DOM id for the form |
||
| 1478 | * |
||
| 1479 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1480 | */ |
||
| 1481 | public function setId( $id ) { |
||
| 1486 | |||
| 1487 | /** |
||
| 1488 | * @param string $name 'name' attribute for the form |
||
| 1489 | * @return HTMLForm $this for chaining calls |
||
| 1490 | */ |
||
| 1491 | public function setName( $name ) { |
||
| 1496 | |||
| 1497 | /** |
||
| 1498 | * Prompt the whole form to be wrapped in a "<fieldset>", with |
||
| 1499 | * this text as its "<legend>" element. |
||
| 1500 | * |
||
| 1501 | * @param string|bool $legend If false, no wrapper or legend will be displayed. |
||
| 1502 | * If true, a wrapper will be displayed, but no legend. |
||
| 1503 | * If a string, a wrapper will be displayed with that string as a legend. |
||
| 1504 | * The string will be escaped before being output (this doesn't support HTML). |
||
| 1505 | * |
||
| 1506 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1507 | */ |
||
| 1508 | public function setWrapperLegend( $legend ) { |
||
| 1513 | |||
| 1514 | /** |
||
| 1515 | * Prompt the whole form to be wrapped in a "<fieldset>", with |
||
| 1516 | * this message as its "<legend>" element. |
||
| 1517 | * @since 1.19 |
||
| 1518 | * |
||
| 1519 | * @param string|Message $msg Message key or Message object |
||
| 1520 | * |
||
| 1521 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1522 | */ |
||
| 1523 | public function setWrapperLegendMsg( $msg ) { |
||
| 1531 | |||
| 1532 | /** |
||
| 1533 | * Set the prefix for various default messages |
||
| 1534 | * @todo Currently only used for the "<fieldset>" legend on forms |
||
| 1535 | * with multiple sections; should be used elsewhere? |
||
| 1536 | * |
||
| 1537 | * @param string $p |
||
| 1538 | * |
||
| 1539 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1540 | */ |
||
| 1541 | public function setMessagePrefix( $p ) { |
||
| 1546 | |||
| 1547 | /** |
||
| 1548 | * Set the title for form submission |
||
| 1549 | * |
||
| 1550 | * @param Title $t Title of page the form is on/should be posted to |
||
| 1551 | * |
||
| 1552 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1553 | */ |
||
| 1554 | public function setTitle( $t ) { |
||
| 1559 | |||
| 1560 | /** |
||
| 1561 | * Get the title |
||
| 1562 | * @return Title |
||
| 1563 | */ |
||
| 1564 | public function getTitle() { |
||
| 1569 | |||
| 1570 | /** |
||
| 1571 | * Set the method used to submit the form |
||
| 1572 | * |
||
| 1573 | * @param string $method |
||
| 1574 | * |
||
| 1575 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1576 | */ |
||
| 1577 | public function setMethod( $method = 'post' ) { |
||
| 1582 | |||
| 1583 | /** |
||
| 1584 | * @return string Always lowercase |
||
| 1585 | */ |
||
| 1586 | public function getMethod() { |
||
| 1589 | |||
| 1590 | /** |
||
| 1591 | * Wraps the given $section into an user-visible fieldset. |
||
| 1592 | * |
||
| 1593 | * @param string $legend Legend text for the fieldset |
||
| 1594 | * @param string $section The section content in plain Html |
||
| 1595 | * @param array $attributes Additional attributes for the fieldset |
||
| 1596 | * @return string The fieldset's Html |
||
| 1597 | */ |
||
| 1598 | protected function wrapFieldSetSection( $legend, $section, $attributes ) { |
||
| 1601 | |||
| 1602 | /** |
||
| 1603 | * @todo Document |
||
| 1604 | * |
||
| 1605 | * @param array[]|HTMLFormField[] $fields Array of fields (either arrays or |
||
| 1606 | * objects). |
||
| 1607 | * @param string $sectionName ID attribute of the "<table>" tag for this |
||
| 1608 | * section, ignored if empty. |
||
| 1609 | * @param string $fieldsetIDPrefix ID prefix for the "<fieldset>" tag of |
||
| 1610 | * each subsection, ignored if empty. |
||
| 1611 | * @param bool &$hasUserVisibleFields Whether the section had user-visible fields. |
||
| 1612 | * @throws LogicException When called on uninitialized field data, e.g. When |
||
| 1613 | * HTMLForm::displayForm was called without calling HTMLForm::prepareForm |
||
| 1614 | * first. |
||
| 1615 | * |
||
| 1616 | * @return string |
||
| 1617 | */ |
||
| 1618 | public function displaySection( $fields, |
||
| 1701 | |||
| 1702 | /** |
||
| 1703 | * Put a form section together from the individual fields' HTML, merging it and wrapping. |
||
| 1704 | * @param array $fieldsHtml |
||
| 1705 | * @param string $sectionName |
||
| 1706 | * @param bool $anyFieldHasLabel |
||
| 1707 | * @return string HTML |
||
| 1708 | */ |
||
| 1709 | protected function formatSection( array $fieldsHtml, $sectionName, $anyFieldHasLabel ) { |
||
| 1741 | |||
| 1742 | /** |
||
| 1743 | * Construct the form fields from the Descriptor array |
||
| 1744 | */ |
||
| 1745 | public function loadData() { |
||
| 1767 | |||
| 1768 | /** |
||
| 1769 | * Stop a reset button being shown for this form |
||
| 1770 | * |
||
| 1771 | * @param bool $suppressReset Set to false to re-enable the button again |
||
| 1772 | * |
||
| 1773 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1774 | */ |
||
| 1775 | public function suppressReset( $suppressReset = true ) { |
||
| 1780 | |||
| 1781 | /** |
||
| 1782 | * Overload this if you want to apply special filtration routines |
||
| 1783 | * to the form as a whole, after it's submitted but before it's |
||
| 1784 | * processed. |
||
| 1785 | * |
||
| 1786 | * @param array $data |
||
| 1787 | * |
||
| 1788 | * @return array |
||
| 1789 | */ |
||
| 1790 | public function filterDataForSubmit( $data ) { |
||
| 1793 | |||
| 1794 | /** |
||
| 1795 | * Get a string to go in the "<legend>" of a section fieldset. |
||
| 1796 | * Override this if you want something more complicated. |
||
| 1797 | * |
||
| 1798 | * @param string $key |
||
| 1799 | * |
||
| 1800 | * @return string |
||
| 1801 | */ |
||
| 1802 | public function getLegend( $key ) { |
||
| 1805 | |||
| 1806 | /** |
||
| 1807 | * Set the value for the action attribute of the form. |
||
| 1808 | * When set to false (which is the default state), the set title is used. |
||
| 1809 | * |
||
| 1810 | * @since 1.19 |
||
| 1811 | * |
||
| 1812 | * @param string|bool $action |
||
| 1813 | * |
||
| 1814 | * @return HTMLForm $this for chaining calls (since 1.20) |
||
| 1815 | */ |
||
| 1816 | public function setAction( $action ) { |
||
| 1821 | |||
| 1822 | /** |
||
| 1823 | * Get the value for the action attribute of the form. |
||
| 1824 | * |
||
| 1825 | * @since 1.22 |
||
| 1826 | * |
||
| 1827 | * @return string |
||
| 1828 | */ |
||
| 1829 | public function getAction() { |
||
| 1847 | |||
| 1848 | /** |
||
| 1849 | * Set the value for the autocomplete attribute of the form. |
||
| 1850 | * When set to false (which is the default state), the attribute get not set. |
||
| 1851 | * |
||
| 1852 | * @since 1.27 |
||
| 1853 | * |
||
| 1854 | * @param string|bool $autocomplete |
||
| 1855 | * |
||
| 1856 | * @return HTMLForm $this for chaining calls |
||
| 1857 | */ |
||
| 1858 | public function setAutocomplete( $autocomplete ) { |
||
| 1863 | |||
| 1864 | /** |
||
| 1865 | * Turns a *-message parameter (which could be a MessageSpecifier, or a message name, or a |
||
| 1866 | * name + parameters array) into a Message. |
||
| 1867 | * @param mixed $value |
||
| 1868 | * @return Message |
||
| 1869 | */ |
||
| 1870 | protected function getMessage( $value ) { |
||
| 1873 | } |
||
| 1874 |
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.