Merge "Change "included" to "transcluded" in messages about cascading"
[lhc/web/wiklou.git] / includes / htmlform / OOUIHTMLForm.php
1 <?php
2
3 /**
4 * HTML form generation and submission handling, OOUI style.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @file
22 */
23
24 /**
25 * Compact stacked vertical format for forms, implemented using OOUI widgets.
26 */
27 class OOUIHTMLForm extends HTMLForm {
28 public function __construct( $descriptor, $context = null, $messagePrefix = '' ) {
29 parent::__construct( $descriptor, $context, $messagePrefix );
30 $this->getOutput()->enableOOUI();
31 $this->getOutput()->addModuleStyles( 'mediawiki.htmlform.ooui.styles' );
32 }
33
34 /**
35 * Symbolic display format name.
36 * @var string
37 */
38 protected $displayFormat = 'ooui';
39
40 public static function loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent = null ) {
41 $field = parent::loadInputFromParameters( $fieldname, $descriptor, $parent );
42 $field->setShowEmptyLabel( false );
43 return $field;
44 }
45
46 function getButtons() {
47 $buttons = '';
48
49 if ( $this->mShowSubmit ) {
50 $attribs = array( 'infusable' => true );
51
52 if ( isset( $this->mSubmitID ) ) {
53 $attribs['id'] = $this->mSubmitID;
54 }
55
56 if ( isset( $this->mSubmitName ) ) {
57 $attribs['name'] = $this->mSubmitName;
58 }
59
60 if ( isset( $this->mSubmitTooltip ) ) {
61 $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
62 }
63
64 $attribs['classes'] = array( 'mw-htmlform-submit' );
65 $attribs['type'] = 'submit';
66 $attribs['label'] = $this->getSubmitText();
67 $attribs['value'] = $this->getSubmitText();
68 $attribs['flags'] = array( $this->mSubmitFlag );
69
70 $buttons .= new OOUI\ButtonInputWidget( $attribs );
71 }
72
73 if ( $this->mShowReset ) {
74 $buttons .= new OOUI\ButtonInputWidget( array(
75 'type' => 'reset',
76 'label' => $this->msg( 'htmlform-reset' )->text(),
77 ) );
78 }
79
80 foreach ( $this->mButtons as $button ) {
81 $attrs = array();
82
83 if ( $button['attribs'] ) {
84 $attrs += $button['attribs'];
85 }
86
87 if ( isset( $button['id'] ) ) {
88 $attrs['id'] = $button['id'];
89 }
90
91 $attrs['classes'] = isset( $attrs['class'] ) ? (array)$attrs['class'] : array();
92
93 $buttons .= new OOUI\ButtonInputWidget( array(
94 'type' => 'submit',
95 'name' => $button['name'],
96 'value' => $button['value'],
97 'label' => $button['value'],
98 ) + $attrs );
99 }
100
101 $html = Html::rawElement( 'div',
102 array( 'class' => 'mw-htmlform-submit-buttons' ), "\n$buttons" ) . "\n";
103
104 return $html;
105 }
106
107 function getBody() {
108 $fieldset = parent::getBody();
109 // FIXME This only works for forms with no subsections
110 if ( $fieldset instanceof OOUI\FieldsetLayout ) {
111 $fieldset->group->prependContent( new OOUI\HtmlSnippet( $this->mHeader ) );
112 }
113 return $fieldset;
114 }
115
116 function wrapForm( $html ) {
117 $form = new OOUI\FormLayout( $this->getFormAttributes() + array(
118 'classes' => array( 'mw-htmlform-ooui' ),
119 'content' => new OOUI\HtmlSnippet( $html ),
120 ) );
121
122 // Include a wrapper for style, if requested.
123 $form = new OOUI\PanelLayout( array(
124 'classes' => array( 'mw-htmlform-ooui-wrapper' ),
125 'expanded' => false,
126 'padded' => $this->mWrapperLegend !== false,
127 'framed' => $this->mWrapperLegend !== false,
128 'content' => $form,
129 ) );
130
131 return $form;
132 }
133 }