r98249 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98248‎ | r98249 | r98250 >
Date:20:23, 27 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
made contest editing form work
Modified paths:
  • /trunk/extensions/Contest/includes/Contest.class.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestDBObject.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContests.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialEditContest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/specials/SpecialContests.php
@@ -54,7 +54,7 @@
5555 * @since 0.1
5656 */
5757 protected function displayContests() {
58 - $contests = Contest::s()->select( array( 'id', 'name', 'enabled', 'submission_count' ) );
 58+ $contests = Contest::s()->select( array( 'id', 'name', 'status', 'submission_count' ) );
5959
6060 if ( count( $contests ) > 0 ) {
6161 $this->displayContestsTable( $contests );
@@ -157,14 +157,14 @@
158158
159159 $fields[] = Html::element(
160160 'td',
161 - array(),
162 - wfMsg( 'contest-special-' . ( $contest->getField( 'enabled' ) ? 'enabled' : 'disabled' ) )
 161+ array( 'data-sort-value' => $contest->getField( 'status' ) ),
 162+ Contest::getStatusMessage( $contest->getField( 'status' ) )
163163 );
164164
165165 $fields[] = Html::element(
166166 'td',
167167 array(),
168 - $this->getLang()->formatNum( $contest->getField( 'submissioncount' ) )
 168+ $this->getLang()->formatNum( $contest->getField( 'submission_count' ) )
169169 );
170170
171171 if ( $user->isAllowed( 'contestadmin' ) ) {
@@ -195,6 +195,8 @@
196196 )
197197 );
198198 }
 199+
 200+ $out->addHTML( '<tr>' . implode( '', $fields ) . '</tr>' );
199201 }
200202
201203 $out->addHTML( '</tbody>' );
Index: trunk/extensions/Contest/specials/SpecialEditContest.php
@@ -61,6 +61,19 @@
6262 // This will throw exceptions if there's a problem
6363 $this->userCanExecute( $this->getUser() );
6464
 65+ if ( $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) {
 66+ $form = $this->getForm();
 67+
 68+ if ( $form->show() ) {
 69+ $this->onSuccess();
 70+ }
 71+ }
 72+ else {
 73+ $this->showContent();
 74+ }
 75+ }
 76+
 77+ protected function showContent() {
6578 if ( $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'newEditToken' ) ) ) {
6679 $data = array( 'name' => $this->getRequest()->getVal( 'newcontest' ) );
6780
@@ -119,21 +132,22 @@
120133 protected function getFormFields() {
121134 $contest = $this->contest;
122135
123 - if ( $contest === false ) {
124 - return array();
125 - }
126 -
127136 $fields = array();
128137
129 - $fields['id'] = array ( 'type' => 'hidden', 'default' => $contest->getId() );
130 - $fields['name'] = array ( 'type' => 'text', 'default' => $contest->getField( 'name' ), 'label-message' => 'contest-edit-name' );
 138+ $fields['id'] = array ( 'type' => 'hidden' );
 139+ $fields['name'] = array ( 'type' => 'text', 'label-message' => 'contest-edit-name' );
131140 $fields['status'] = array (
132141 'type' => 'radio',
133 - 'default' => $contest->getField( 'status' ),
134142 'label-message' => 'contest-edit-status',
135143 'options' => Contest::getStatusMessages()
136144 );
137145
 146+ if ( $contest !== false ) {
 147+ foreach ( $fields as $name => $data ) {
 148+ $fields[$name]['default'] = $contest->getField( $name );
 149+ }
 150+ }
 151+
138152 // TODO
139153
140154 $mappedFields = array();
@@ -158,7 +172,7 @@
159173 foreach ( $data as $name => $value ) {
160174 $matches = array();
161175
162 - if ( preg_match( '/contest-(\.+)/', $name, $matches ) ) {
 176+ if ( preg_match( '/contest-(.+)/', $name, $matches ) ) {
163177 $fields[$matches[1]] = $value;
164178 }
165179 }
@@ -169,11 +183,11 @@
170184
171185 $sessionField = 'contestid-' . $fields['name'];
172186
173 - if ( is_null( $fields['id'] ) && !is_null( $wgRequest->getSessionData( $sessionField ) ) ) {
174 - $contest->setId( $wgRequest->getSessionData( $sessionField ) );
 187+ if ( is_null( $fields['id'] ) && !is_null( $this->getRequest()->getSessionData( $sessionField ) ) ) {
 188+ $contest->setId( $this->getRequest()->getSessionData( $sessionField ) );
175189 }
176190
177 - $contest = new Contest( $fields );
 191+ $contest = new Contest( $fields, true );
178192
179193 $success = $contest->writeToDB();
180194
Index: trunk/extensions/Contest/includes/ContestDBObject.php
@@ -479,20 +479,6 @@
480480
481481 return $this->newFromArray( $data );
482482 }
483 -
484 - /**
485 - * Get a new instance of the class from an array.
486 - *
487 - * @since 0.1
488 - *
489 - * @param array $data
490 - * @param boolean $loadDefaults
491 - *
492 - * @return ContestDBObject
493 - */
494 - public function newFromArray( array $data, $loadDefaults = false ) {
495 - return new self( $data, $loadDefaults );
496 - }
497483
498484 /**
499485 * Selects the the specified fields of the records matching the provided
Index: trunk/extensions/Contest/includes/Contest.class.php
@@ -38,6 +38,20 @@
3939 }
4040
4141 /**
 42+ * Get a new instance of the class from an array.
 43+ *
 44+ * @since 0.1
 45+ *
 46+ * @param array $data
 47+ * @param boolean $loadDefaults
 48+ *
 49+ * @return ContestDBObject
 50+ */
 51+ public function newFromArray( array $data, $loadDefaults = false ) {
 52+ return new self( $data, $loadDefaults );
 53+ }
 54+
 55+ /**
4256 * @see parent::getFieldTypes
4357 *
4458 * @since 0.1

Status & tagging log