r106479 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106478‎ | r106479 | r106480 >
Date:21:08, 16 December 2011
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
work on insittution edit form. htmlform is a serious pain sometimes >_>
Modified paths:
  • /trunk/extensions/EducationProgram/specials/SpecialEPFormPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEditInstitution.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialInstitutions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialInstitutions.php
@@ -94,7 +94,7 @@
9595
9696 $out->addHTML( '<fieldset>' );
9797
98 - $out->addHTML( '<legend>' . htmlspecialchars( wfMsg( 'ep-institutions-addnew' ) ) . '</legend>' );
 98+ $out->addHTML( '<legend>' . wfMsgHtml( 'ep-institutions-addnew' ) . '</legend>' );
9999
100100 $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-institutions-namedoc' ) ) );
101101
Index: trunk/extensions/EducationProgram/specials/SpecialEditInstitution.php
@@ -33,8 +33,27 @@
3434 $fields['name'] = array (
3535 'type' => 'text',
3636 '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+ },
3841 );
 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+ );
3958
4059 return $this->processFormFields( $fields );
4160 }
Index: trunk/extensions/EducationProgram/specials/SpecialEPFormPage.php
@@ -11,18 +11,9 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -abstract class SpecialEPFormPage extends FormSpecialPage {
 15+abstract class SpecialEPFormPage extends SpecialEPPage {
1616
1717 /**
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 - /**
2718 * Instance of the object being edited or created.
2819 *
2920 * @since 0.1
@@ -94,15 +85,8 @@
9586 * @param string $subPage
9687 */
9788 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+
10791 if ( $this->isNew() ) {
10892 $this->showForm();
10993 }
@@ -127,15 +111,6 @@
128112
129113 return $isNew;
130114 }
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 - }
140115
141116 /**
142117 * Show the form.
@@ -145,9 +120,15 @@
146121 protected function showForm() {
147122 $form = $this->getForm();
148123
149 - if ( $form->show() ) {
150 - $this->onSuccess();
 124+ if ( $this->isNew() ) {
 125+ $form->prepareForm();
 126+ $form->displayForm( Status::newGood() );
151127 }
 128+ else {
 129+ if ( $form->show() ) {
 130+ $this->onSuccess();
 131+ }
 132+ }
152133 }
153134
154135 /**
@@ -209,8 +190,14 @@
210191 * @return HTMLForm|null
211192 */
212193 protected function getForm() {
213 - $form = parent::getForm();
 194+ $form = new HTMLForm( $this->getFormFields(), $this->getContext() );
214195
 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+
215202 $form->addButton(
216203 'cancelEdit',
217204 wfMsg( 'cancel' ),
@@ -252,36 +239,26 @@
253240 */
254241 protected function processFormFields( array $fields ) {
255242 if ( $this->item !== false ) {
256 - foreach ( $fields as $name => $data ) {
 243+ foreach ( $fields as $name => &$data ) {
257244 $default = $this->item->getField( $name );
258 - $fields[$name]['default'] = $default;
 245+ $data['default'] = $default;
259246 }
260247 }
261 -
 248+
262249 $mappedFields = array();
263250
264251 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+
265258 $mappedFields['item-' . $name] = $field;
266259 }
267260
268261 return $mappedFields;
269262 }
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 - }
286263
287264 /**
288265 * Gets called after the form is saved.

Status & tagging log