Index: trunk/extensions/Contest/specials/SpecialContests.php |
— | — | @@ -54,7 +54,7 @@ |
55 | 55 | * @since 0.1 |
56 | 56 | */ |
57 | 57 | 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' ) ); |
59 | 59 | |
60 | 60 | if ( count( $contests ) > 0 ) { |
61 | 61 | $this->displayContestsTable( $contests ); |
— | — | @@ -157,14 +157,14 @@ |
158 | 158 | |
159 | 159 | $fields[] = Html::element( |
160 | 160 | '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' ) ) |
163 | 163 | ); |
164 | 164 | |
165 | 165 | $fields[] = Html::element( |
166 | 166 | 'td', |
167 | 167 | array(), |
168 | | - $this->getLang()->formatNum( $contest->getField( 'submissioncount' ) ) |
| 168 | + $this->getLang()->formatNum( $contest->getField( 'submission_count' ) ) |
169 | 169 | ); |
170 | 170 | |
171 | 171 | if ( $user->isAllowed( 'contestadmin' ) ) { |
— | — | @@ -195,6 +195,8 @@ |
196 | 196 | ) |
197 | 197 | ); |
198 | 198 | } |
| 199 | + |
| 200 | + $out->addHTML( '<tr>' . implode( '', $fields ) . '</tr>' ); |
199 | 201 | } |
200 | 202 | |
201 | 203 | $out->addHTML( '</tbody>' ); |
Index: trunk/extensions/Contest/specials/SpecialEditContest.php |
— | — | @@ -61,6 +61,19 @@ |
62 | 62 | // This will throw exceptions if there's a problem |
63 | 63 | $this->userCanExecute( $this->getUser() ); |
64 | 64 | |
| 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() { |
65 | 78 | if ( $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'newEditToken' ) ) ) { |
66 | 79 | $data = array( 'name' => $this->getRequest()->getVal( 'newcontest' ) ); |
67 | 80 | |
— | — | @@ -119,21 +132,22 @@ |
120 | 133 | protected function getFormFields() { |
121 | 134 | $contest = $this->contest; |
122 | 135 | |
123 | | - if ( $contest === false ) { |
124 | | - return array(); |
125 | | - } |
126 | | - |
127 | 136 | $fields = array(); |
128 | 137 | |
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' ); |
131 | 140 | $fields['status'] = array ( |
132 | 141 | 'type' => 'radio', |
133 | | - 'default' => $contest->getField( 'status' ), |
134 | 142 | 'label-message' => 'contest-edit-status', |
135 | 143 | 'options' => Contest::getStatusMessages() |
136 | 144 | ); |
137 | 145 | |
| 146 | + if ( $contest !== false ) { |
| 147 | + foreach ( $fields as $name => $data ) { |
| 148 | + $fields[$name]['default'] = $contest->getField( $name ); |
| 149 | + } |
| 150 | + } |
| 151 | + |
138 | 152 | // TODO |
139 | 153 | |
140 | 154 | $mappedFields = array(); |
— | — | @@ -158,7 +172,7 @@ |
159 | 173 | foreach ( $data as $name => $value ) { |
160 | 174 | $matches = array(); |
161 | 175 | |
162 | | - if ( preg_match( '/contest-(\.+)/', $name, $matches ) ) { |
| 176 | + if ( preg_match( '/contest-(.+)/', $name, $matches ) ) { |
163 | 177 | $fields[$matches[1]] = $value; |
164 | 178 | } |
165 | 179 | } |
— | — | @@ -169,11 +183,11 @@ |
170 | 184 | |
171 | 185 | $sessionField = 'contestid-' . $fields['name']; |
172 | 186 | |
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 ) ); |
175 | 189 | } |
176 | 190 | |
177 | | - $contest = new Contest( $fields ); |
| 191 | + $contest = new Contest( $fields, true ); |
178 | 192 | |
179 | 193 | $success = $contest->writeToDB(); |
180 | 194 | |
Index: trunk/extensions/Contest/includes/ContestDBObject.php |
— | — | @@ -479,20 +479,6 @@ |
480 | 480 | |
481 | 481 | return $this->newFromArray( $data ); |
482 | 482 | } |
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 | | - } |
497 | 483 | |
498 | 484 | /** |
499 | 485 | * Selects the the specified fields of the records matching the provided |
Index: trunk/extensions/Contest/includes/Contest.class.php |
— | — | @@ -38,6 +38,20 @@ |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
| 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 | + /** |
42 | 56 | * @see parent::getFieldTypes |
43 | 57 | * |
44 | 58 | * @since 0.1 |