Index: trunk/extensions/EducationProgram/specials/SpecialInstitutions.php |
— | — | @@ -94,7 +94,7 @@ |
95 | 95 | |
96 | 96 | $out->addHTML( '<fieldset>' ); |
97 | 97 | |
98 | | - $out->addHTML( '<legend>' . htmlspecialchars( wfMsg( 'ep-institutions-addnew' ) ) . '</legend>' ); |
| 98 | + $out->addHTML( '<legend>' . wfMsgHtml( 'ep-institutions-addnew' ) . '</legend>' ); |
99 | 99 | |
100 | 100 | $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-institutions-namedoc' ) ) ); |
101 | 101 | |
Index: trunk/extensions/EducationProgram/specials/SpecialEditInstitution.php |
— | — | @@ -33,8 +33,27 @@ |
34 | 34 | $fields['name'] = array ( |
35 | 35 | 'type' => 'text', |
36 | 36 | 'label-message' => 'educationprogram-org-edit-name', |
37 | | - 'id' => 'org-name-field', |
| 37 | + 'required' => true, |
| 38 | + 'validation-callback' => function ( $value, array $alldata = null ) { |
| 39 | + return strlen( $value ) < 2 ? wfMsg( 'educationprogram-org-invalid-name' ) : true; |
| 40 | + }, |
38 | 41 | ); |
| 42 | + |
| 43 | + $fields['city'] = array ( |
| 44 | + 'type' => 'text', |
| 45 | + 'label-message' => 'educationprogram-org-edit-city', |
| 46 | + 'required' => true, |
| 47 | + 'validation-callback' => function ( $value, array $alldata = null ) { |
| 48 | + return strlen( $value ) < 2 ? wfMsg( 'educationprogram-org-invalid-city' ) : true; |
| 49 | + }, |
| 50 | + ); |
| 51 | + |
| 52 | + $fields['country'] = array ( |
| 53 | + 'type' => 'select', |
| 54 | + 'label-message' => 'educationprogram-org-edit-country', |
| 55 | + 'required' => true, |
| 56 | + 'options' => array( 'foo' => 'foo', 'bar' => 'bar' ), // TODO |
| 57 | + ); |
39 | 58 | |
40 | 59 | return $this->processFormFields( $fields ); |
41 | 60 | } |
Index: trunk/extensions/EducationProgram/specials/SpecialEPFormPage.php |
— | — | @@ -11,18 +11,9 @@ |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | | -abstract class SpecialEPFormPage extends FormSpecialPage { |
| 15 | +abstract class SpecialEPFormPage extends SpecialEPPage { |
16 | 16 | |
17 | 17 | /** |
18 | | - * The subpage, ie the part after Special:PageName/ |
19 | | - * Emptry string if none is provided. |
20 | | - * |
21 | | - * @since 0.1 |
22 | | - * @var string |
23 | | - */ |
24 | | - protected $subPage; |
25 | | - |
26 | | - /** |
27 | 18 | * Instance of the object being edited or created. |
28 | 19 | * |
29 | 20 | * @since 0.1 |
— | — | @@ -94,15 +85,8 @@ |
95 | 86 | * @param string $subPage |
96 | 87 | */ |
97 | 88 | public function execute( $subPage ) { |
98 | | - $subPage = is_null( $subPage ) ? '' : $subPage; |
99 | | - $this->subPage = trim( str_replace( '_', ' ', $subPage ) ); |
100 | | - |
101 | | - $this->setHeaders(); |
102 | | - $this->outputHeader(); |
103 | | - |
104 | | - // This will throw exceptions if there's a problem. |
105 | | - $this->checkExecutePermissions( $this->getUser() ); |
106 | | - |
| 89 | + parent::execute( $subPage ); |
| 90 | + |
107 | 91 | if ( $this->isNew() ) { |
108 | 92 | $this->showForm(); |
109 | 93 | } |
— | — | @@ -127,15 +111,6 @@ |
128 | 112 | |
129 | 113 | return $isNew; |
130 | 114 | } |
131 | | - |
132 | | - /** |
133 | | - * (non-PHPdoc) |
134 | | - * @see FormSpecialPage::alterForm() |
135 | | - */ |
136 | | - protected function alterForm( HTMLForm $form ) { |
137 | | - $action = $this->isNew() ? 'add' : 'edit'; |
138 | | - $form->setWrapperLegend( $this->msg( strtolower( $this->getName() ) . '-' . $action . '-legend' ) ); |
139 | | - } |
140 | 115 | |
141 | 116 | /** |
142 | 117 | * Show the form. |
— | — | @@ -145,9 +120,15 @@ |
146 | 121 | protected function showForm() { |
147 | 122 | $form = $this->getForm(); |
148 | 123 | |
149 | | - if ( $form->show() ) { |
150 | | - $this->onSuccess(); |
| 124 | + if ( $this->isNew() ) { |
| 125 | + $form->prepareForm(); |
| 126 | + $form->displayForm( Status::newGood() ); |
151 | 127 | } |
| 128 | + else { |
| 129 | + if ( $form->show() ) { |
| 130 | + $this->onSuccess(); |
| 131 | + } |
| 132 | + } |
152 | 133 | } |
153 | 134 | |
154 | 135 | /** |
— | — | @@ -209,8 +190,14 @@ |
210 | 191 | * @return HTMLForm|null |
211 | 192 | */ |
212 | 193 | protected function getForm() { |
213 | | - $form = parent::getForm(); |
| 194 | + $form = new HTMLForm( $this->getFormFields(), $this->getContext() ); |
214 | 195 | |
| 196 | + $form->setSubmitCallback( array( $this, 'handleSubmission' ) ); |
| 197 | + $form->setSubmitText( wfMsg( 'educationprogram-org-submit' ) ); |
| 198 | + |
| 199 | + $action = $this->isNew() ? 'add' : 'edit'; |
| 200 | + $form->setWrapperLegend( $this->msg( strtolower( $this->getName() ) . '-' . $action . '-legend' ) ); |
| 201 | + |
215 | 202 | $form->addButton( |
216 | 203 | 'cancelEdit', |
217 | 204 | wfMsg( 'cancel' ), |
— | — | @@ -252,36 +239,26 @@ |
253 | 240 | */ |
254 | 241 | protected function processFormFields( array $fields ) { |
255 | 242 | if ( $this->item !== false ) { |
256 | | - foreach ( $fields as $name => $data ) { |
| 243 | + foreach ( $fields as $name => &$data ) { |
257 | 244 | $default = $this->item->getField( $name ); |
258 | | - $fields[$name]['default'] = $default; |
| 245 | + $data['default'] = $default; |
259 | 246 | } |
260 | 247 | } |
261 | | - |
| 248 | + |
262 | 249 | $mappedFields = array(); |
263 | 250 | |
264 | 251 | foreach ( $fields as $name => $field ) { |
| 252 | + if ( $this->isNew() ) { |
| 253 | + // HTML form is being a huge pain in running the validation on post, |
| 254 | + // so just remove it if when not appropriate. |
| 255 | + unset( $field['validation-callback'] ); |
| 256 | + } |
| 257 | + |
265 | 258 | $mappedFields['item-' . $name] = $field; |
266 | 259 | } |
267 | 260 | |
268 | 261 | return $mappedFields; |
269 | 262 | } |
270 | | - |
271 | | - /** |
272 | | - * Show a message in a warning box. |
273 | | - * |
274 | | - * @since 0.1 |
275 | | - * |
276 | | - * @param string $message Message key |
277 | | - * @param array|string $args Message arguments |
278 | | - */ |
279 | | - protected function showWarning( $message, $args = array() ) { |
280 | | - $message = call_user_func_array( 'wfMsgExt', array_merge( array( $message ), (array)$args ) ); |
281 | | - $this->getOutput()->addHTML( |
282 | | - '<p class="visualClear warningbox">' . $message . '</p>' |
283 | | - . '<hr style="display: block; clear: both; visibility: hidden;" />' |
284 | | - ); |
285 | | - } |
286 | 263 | |
287 | 264 | /** |
288 | 265 | * Gets called after the form is saved. |