Index: trunk/extensions/Contest/test/ContestValidationTests.php |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | 'https://gitorious.org/statusnet' => true, |
34 | 34 | 'https://gitorious.org/statusnet/mainline/merge_requests/2224' => true, |
35 | 35 | ); |
36 | | - |
| 36 | + |
37 | 37 | foreach ( $tests as $test => $isValdid ) { |
38 | 38 | if ( $isValdid ) { |
39 | 39 | $this->assertEquals( true, SpecialMyContests::validateSubmissionField( $test ) ); |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | */ |
50 | 50 | public function testObjectSelectCount() { |
51 | 51 | $classes = array( 'Contest', 'ContestChallenge' ); |
52 | | - |
| 52 | + |
53 | 53 | foreach ( $classes as $class ) { |
54 | 54 | $this->assertEquals( count( $class::s()->select() ), $class::s()->count() ); |
55 | 55 | } |
Index: trunk/extensions/Contest/Contest.hooks.php |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | 15 | final class ContestHooks { |
16 | | - |
| 16 | + |
17 | 17 | /** |
18 | 18 | * Schema update to set up the needed database tables. |
19 | 19 | * |
— | — | @@ -23,15 +23,13 @@ |
24 | 24 | * @return true |
25 | 25 | */ |
26 | 26 | public static function onSchemaUpdate( /* DatabaseUpdater */ $updater = null ) { |
27 | | - global $wgDBtype; |
28 | | - |
29 | | - $updater->addExtensionUpdate( array( |
| 27 | + $updater->addExtensionUpdate( array( |
30 | 28 | 'addTable', |
31 | 29 | 'contests', |
32 | 30 | dirname( __FILE__ ) . '/Contest.sql', |
33 | 31 | true |
34 | 32 | ) ); |
35 | | - |
| 33 | + |
36 | 34 | $updater->addExtensionUpdate( array( |
37 | 35 | 'addField', |
38 | 36 | 'contests', |
— | — | @@ -42,41 +40,41 @@ |
43 | 41 | |
44 | 42 | return true; |
45 | 43 | } |
46 | | - |
| 44 | + |
47 | 45 | /** |
48 | 46 | * Hook to add PHPUnit test cases. |
49 | | - * |
| 47 | + * |
50 | 48 | * @since 0.1 |
51 | | - * |
| 49 | + * |
52 | 50 | * @param array $files |
53 | | - * |
| 51 | + * |
54 | 52 | * @return true |
55 | 53 | */ |
56 | 54 | public static function registerUnitTests( array &$files ) { |
57 | 55 | $testDir = dirname( __FILE__ ) . '/test/'; |
58 | | - |
| 56 | + |
59 | 57 | $files[] = $testDir . 'ContestValidationTests.php'; |
60 | | - |
| 58 | + |
61 | 59 | return true; |
62 | 60 | } |
63 | | - |
| 61 | + |
64 | 62 | /** |
65 | 63 | * Called when changing user email address. |
66 | 64 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/UserSetEmail |
67 | | - * |
| 65 | + * |
68 | 66 | * Checks if there are any active contests in which the user is participating, |
69 | 67 | * and if so, updates the email there as well. |
70 | | - * |
| 68 | + * |
71 | 69 | * @since 0.1 |
72 | | - * |
| 70 | + * |
73 | 71 | * @param User $user |
74 | 72 | * @param string $email |
75 | | - * |
| 73 | + * |
76 | 74 | * @return true |
77 | 75 | */ |
78 | 76 | public static function onUserSetEmail( User $user, &$email ) { |
79 | 77 | $dbr = wfGetDB( DB_SLAVE ); |
80 | | - |
| 78 | + |
81 | 79 | $contestants = $dbr->select( |
82 | 80 | array( 'contest_contestants', 'contests' ), |
83 | 81 | array( 'contestant_id' ), |
— | — | @@ -85,103 +83,103 @@ |
86 | 84 | array(), |
87 | 85 | array( 'contests' => array( 'INNER JOIN', array( 'contest_id=contestant_contest_id' ) ) ) |
88 | 86 | ); |
89 | | - |
| 87 | + |
90 | 88 | $contestantIds = array(); |
91 | | - |
| 89 | + |
92 | 90 | foreach ( $contestants as $contestant ) { |
93 | 91 | $contestantIds[] = $contestant->contestant_id; |
94 | 92 | } |
95 | | - |
| 93 | + |
96 | 94 | if ( count( $contestantIds ) > 0 ) { |
97 | 95 | ContestContestant::s()->update( |
98 | 96 | array( 'email' => $email ), |
99 | 97 | array( 'id' => $contestantIds ) |
100 | 98 | ); |
101 | 99 | } |
102 | | - |
| 100 | + |
103 | 101 | return true; |
104 | 102 | } |
105 | | - |
| 103 | + |
106 | 104 | /** |
107 | 105 | * Called after the personal URLs have been set up, before they are shown. |
108 | 106 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls |
109 | | - * |
| 107 | + * |
110 | 108 | * @since 0.1 |
111 | | - * |
| 109 | + * |
112 | 110 | * @param array $personal_urls |
113 | 111 | * @param Title $title |
114 | | - * |
| 112 | + * |
115 | 113 | * @return true |
116 | 114 | */ |
117 | 115 | public static function onPersonalUrls( array &$personal_urls, Title &$title ) { |
118 | 116 | if ( ContestSettings::get( 'enableTopLink' ) ) { |
119 | 117 | global $wgUser; |
120 | | - |
| 118 | + |
121 | 119 | // Find the watchlist item and replace it by the my contests link and itself. |
122 | 120 | if ( $wgUser->isLoggedIn() && $wgUser->getOption( 'contest_showtoplink' ) ) { |
123 | 121 | $keys = array_keys( $personal_urls ); |
124 | 122 | $watchListLocation = array_search( 'watchlist', $keys ); |
125 | 123 | $watchListItem = $personal_urls[$keys[$watchListLocation]]; |
126 | | - |
| 124 | + |
127 | 125 | $url = SpecialPage::getTitleFor( 'MyContests' )->getLinkUrl(); |
128 | 126 | $myContests = array( |
129 | 127 | 'text' => wfMsg( 'contest-toplink' ), |
130 | 128 | 'href' => $url, |
131 | 129 | 'active' => ( $url == $title->getLinkUrl() ) |
132 | 130 | ); |
133 | | - |
134 | | - array_splice( $personal_urls, $watchListLocation, 1, array( $myContests, $watchListItem ) ); |
| 131 | + |
| 132 | + array_splice( $personal_urls, $watchListLocation, 1, array( $myContests, $watchListItem ) ); |
135 | 133 | } |
136 | 134 | } |
137 | | - |
| 135 | + |
138 | 136 | return true; |
139 | 137 | } |
140 | | - |
141 | | - /** |
142 | | - * Adds the preferences of Contest to the list of available ones. |
143 | | - * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences |
144 | | - * |
145 | | - * @since 0.1 |
146 | | - * |
147 | | - * @param User $user |
148 | | - * @param array $preferences |
149 | | - * |
150 | | - * @return true |
151 | | - */ |
| 138 | + |
| 139 | + /** |
| 140 | + * Adds the preferences of Contest to the list of available ones. |
| 141 | + * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences |
| 142 | + * |
| 143 | + * @since 0.1 |
| 144 | + * |
| 145 | + * @param User $user |
| 146 | + * @param array $preferences |
| 147 | + * |
| 148 | + * @return true |
| 149 | + */ |
152 | 150 | public static function onGetPreferences( User $user, array &$preferences ) { |
153 | 151 | if ( ContestSettings::get( 'enableTopLink' ) ) { |
154 | 152 | $preferences['contest_showtoplink'] = array( |
155 | 153 | 'type' => 'toggle', |
156 | 154 | 'label-message' => 'contest-prefs-showtoplink', |
157 | 155 | 'section' => 'contest', |
158 | | - ); |
| 156 | + ); |
159 | 157 | } |
160 | 158 | |
161 | 159 | return true; |
162 | | - } |
163 | | - |
| 160 | + } |
| 161 | + |
164 | 162 | /** |
165 | 163 | * Used when generating internal and interwiki links in Linker::link(), |
166 | 164 | * just before the function returns a value. |
167 | 165 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/LinkEnd |
168 | | - * |
| 166 | + * |
169 | 167 | * @since 0.1 |
170 | | - * |
| 168 | + * |
171 | 169 | * @param $skin |
172 | 170 | * @param Title $target |
173 | 171 | * @param array $options |
174 | 172 | * @param string $text |
175 | 173 | * @param array $attribs |
176 | 174 | * @param $ret |
177 | | - * |
| 175 | + * |
178 | 176 | * @return true |
179 | 177 | */ |
180 | 178 | public static function onLinkEnd( $skin, Title $target, array $options, &$text, array &$attribs, &$ret ) { |
181 | 179 | if ( $GLOBALS['wgContestEmailParse'] ) { |
182 | 180 | $attribs['href'] = $target->getFullURL(); |
183 | 181 | } |
184 | | - |
| 182 | + |
185 | 183 | return true; |
186 | 184 | } |
187 | | - |
| 185 | + |
188 | 186 | } |
Index: trunk/extensions/Contest/specials/SpecialMyContests.php |
— | — | @@ -1,43 +1,43 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * List of contests for a user. |
6 | | - * |
| 5 | + * List of contests for a user. |
| 6 | + * |
7 | 7 | * @since 0.1 |
8 | | - * |
| 8 | + * |
9 | 9 | * @file SpecialMyContests.php |
10 | 10 | * @ingroup Contest |
11 | | - * |
| 11 | + * |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | 15 | class SpecialMyContests extends SpecialContestPage { |
16 | | - |
| 16 | + |
17 | 17 | protected $submissionState = null; |
18 | | - |
| 18 | + |
19 | 19 | /** |
20 | 20 | * Constructor. |
21 | | - * |
| 21 | + * |
22 | 22 | * @since 0.1 |
23 | 23 | */ |
24 | 24 | public function __construct() { |
25 | 25 | parent::__construct( 'MyContests', 'contestparticipant' ); |
26 | 26 | } |
27 | | - |
| 27 | + |
28 | 28 | /** |
29 | 29 | * Main method. |
30 | | - * |
| 30 | + * |
31 | 31 | * @since 0.1 |
32 | | - * |
| 32 | + * |
33 | 33 | * @param string $arg |
34 | 34 | */ |
35 | 35 | public function execute( $subPage ) { |
36 | 36 | $subPage = str_replace( '_', ' ', $subPage ); |
37 | | - |
| 37 | + |
38 | 38 | if ( !parent::execute( $subPage ) ) { |
39 | 39 | return; |
40 | 40 | } |
41 | | - |
| 41 | + |
42 | 42 | if ( $this->getRequest()->wasPosted() ) { |
43 | 43 | $contestant = ContestContestant::s()->selectRow( null, array( 'id' => $this->getRequest()->getInt( 'wpcontestant-id' ) ) ); |
44 | 44 | $this->showSubmissionPage( $contestant ); |
— | — | @@ -51,29 +51,29 @@ |
52 | 52 | } |
53 | 53 | } |
54 | 54 | } |
55 | | - |
| 55 | + |
56 | 56 | /** |
57 | 57 | * On regular page view, ie no submission and no sub-page, |
58 | 58 | * display a list of all contests the user is participating in, |
59 | 59 | * or in case there is only one, redirect them to the submissiom |
60 | 60 | * UI of it. |
61 | | - * |
| 61 | + * |
62 | 62 | * @since 0.1 |
63 | 63 | */ |
64 | 64 | protected function displayContestsOverview() { |
65 | | - $contestants = ContestContestant::s()->select( |
| 65 | + $contestants = ContestContestant::s()->select( |
66 | 66 | array( 'id', 'contest_id', 'challenge_id' ), |
67 | 67 | array( 'user_id' => $this->getUser()->getId() ) |
68 | 68 | ); |
69 | | - |
| 69 | + |
70 | 70 | $contestantCount = count( $contestants ); |
71 | | - |
| 71 | + |
72 | 72 | if ( $contestantCount == 0 ) { |
73 | 73 | $this->getOutput()->addWikiMsg( 'contest-mycontests-no-contests' ); |
74 | 74 | } |
75 | 75 | else if ( $contestantCount == 1 ) { |
76 | 76 | $contest = $contestants[0]->getContest( array( 'status', 'name' ) ); |
77 | | - |
| 77 | + |
78 | 78 | if ( $contest->getField( 'status' ) == Contest::STATUS_ACTIVE ) { |
79 | 79 | $this->getOutput()->redirect( $this->getTitle( $contest->getField( 'name' ) )->getLocalURL() ); |
80 | 80 | } |
— | — | @@ -85,82 +85,82 @@ |
86 | 86 | $this->displayContestsTable( $contestants ); |
87 | 87 | } |
88 | 88 | } |
89 | | - |
| 89 | + |
90 | 90 | /** |
91 | 91 | * Displays a list of contests the user participates or participated in, |
92 | 92 | * together with their user specific choices such as the contest challenge. |
93 | | - * |
| 93 | + * |
94 | 94 | * @since 0.1 |
95 | | - * |
| 95 | + * |
96 | 96 | * @param array $contestants |
97 | 97 | */ |
98 | 98 | protected function displayContestsTable( array /* of ContestContestant */ $contestants ) { |
99 | 99 | $user = $this->getUser(); |
100 | | - |
| 100 | + |
101 | 101 | $running = array(); |
102 | 102 | $passed = array(); |
103 | 103 | $contests = array(); |
104 | | - |
| 104 | + |
105 | 105 | foreach ( $contestants as $contestant ) { |
106 | 106 | $contest = $contestant->getContest(); |
107 | | - |
| 107 | + |
108 | 108 | if ( $contest->getField( 'status' ) == Contest::STATUS_ACTIVE ) { |
109 | 109 | $running[] = $contestant; |
110 | 110 | } |
111 | 111 | else if ( $contest->getField( 'status' ) == Contest::STATUS_FINISHED ) { |
112 | 112 | $passed[] = $contestant; |
113 | 113 | } |
114 | | - |
| 114 | + |
115 | 115 | $contests[$contest->getId()] = $contest; |
116 | 116 | } |
117 | | - |
| 117 | + |
118 | 118 | if ( count( $running ) > 0 ) { |
119 | 119 | $this->displayRunningContests( $running, $contests ); |
120 | 120 | } |
121 | | - |
| 121 | + |
122 | 122 | if ( count( $passed ) > 0 ) { |
123 | 123 | //$this->displayPassedContests( $passed, $contests ); |
124 | 124 | } |
125 | 125 | } |
126 | | - |
| 126 | + |
127 | 127 | /** |
128 | 128 | * Display a table with the running (active) contests for this user. |
129 | | - * |
| 129 | + * |
130 | 130 | * @since 0.1 |
131 | | - * |
| 131 | + * |
132 | 132 | * @param array $contestants |
133 | 133 | * @param array $contests |
134 | 134 | */ |
135 | 135 | protected function displayRunningContests( array /* of ContestContestant */ $contestants, array /* Contest */ $contests ) { |
136 | 136 | $out = $this->getOutput(); |
137 | | - |
| 137 | + |
138 | 138 | $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-mycontests-active-header' ) ) ); |
139 | 139 | $out->addHTML( Html::element( 'p', array(), wfMsg( 'contest-mycontests-active-text' ) ) ); |
140 | | - |
| 140 | + |
141 | 141 | $out->addHTML( Xml::openElement( |
142 | 142 | 'table', |
143 | 143 | array( 'class' => 'wikitable sortable' ) |
144 | 144 | ) ); |
145 | | - |
| 145 | + |
146 | 146 | $headers = array( |
147 | 147 | Html::element( 'th', array(), wfMsg( 'contest-mycontests-header-contest' ) ), |
148 | 148 | Html::element( 'th', array(), wfMsg( 'contest-mycontests-header-challenge' ) ), |
149 | 149 | ); |
150 | | - |
| 150 | + |
151 | 151 | $out->addHTML( '<thead><tr>' . implode( '', $headers ) . '</tr></thead>' ); |
152 | | - |
| 152 | + |
153 | 153 | $out->addHTML( '<tbody>' ); |
154 | | - |
| 154 | + |
155 | 155 | foreach ( $contestants as $contestant ) { |
156 | 156 | $contest = $contests[$contestant->getField( 'contest_id' )]; |
157 | | - |
| 157 | + |
158 | 158 | $challengeTitle = ContestChallenge::s()->selectRow( |
159 | 159 | 'title', |
160 | 160 | array( 'id' => $contestant->getField( 'challenge_id' ) ) |
161 | 161 | )->getField( 'title' ); |
162 | | - |
| 162 | + |
163 | 163 | $fields = array(); |
164 | | - |
| 164 | + |
165 | 165 | $fields[] = Html::rawElement( 'td', array( 'data-sort-value' => $contest->getField( 'name' ) ), Html::rawElement( |
166 | 166 | 'a', |
167 | 167 | array( |
— | — | @@ -168,45 +168,45 @@ |
169 | 169 | ), |
170 | 170 | htmlspecialchars( $contest->getField( 'name' ) ) |
171 | 171 | ) ); |
172 | | - |
| 172 | + |
173 | 173 | $fields[] = Html::element( 'td', array(), $challengeTitle ); |
174 | | - |
| 174 | + |
175 | 175 | $out->addHTML( '<tr>' . implode( '', $fields ) . '</tr>' ); |
176 | 176 | } |
177 | | - |
| 177 | + |
178 | 178 | $out->addHTML( '</tbody>' ); |
179 | 179 | $out->addHTML( '</table>' ); |
180 | 180 | } |
181 | | - |
| 181 | + |
182 | 182 | /** |
183 | 183 | * Display a table with the passed (finished) contests for this user. |
184 | | - * |
| 184 | + * |
185 | 185 | * @since 0.1 |
186 | | - * |
| 186 | + * |
187 | 187 | * @param array $contestants |
188 | 188 | * @param array $contests |
189 | 189 | */ |
190 | 190 | protected function displayPassedContests( array /* of ContestContestant */ $contestants, array /* Contest */ $contests ) { |
191 | 191 | $out = $this->getOutput(); |
192 | | - |
| 192 | + |
193 | 193 | $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-mycontests-finished-header' ) ) ); |
194 | 194 | $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-mycontests-finished-text' ) ) ); |
195 | | - |
| 195 | + |
196 | 196 | // TODO |
197 | 197 | } |
198 | | - |
| 198 | + |
199 | 199 | /** |
200 | 200 | * Handle view requests for the page. |
201 | | - * |
| 201 | + * |
202 | 202 | * @since 0.1 |
203 | | - * |
| 203 | + * |
204 | 204 | * @param string $contestName |
205 | 205 | */ |
206 | 206 | protected function handleSubmissionView( $contestName ) { |
207 | 207 | $out = $this->getOutput(); |
208 | | - |
| 208 | + |
209 | 209 | $contest = Contest::s()->selectRow( null, array( 'name' => $contestName ) ); |
210 | | - |
| 210 | + |
211 | 211 | if ( $contest === false ) { |
212 | 212 | $this->showError( 'contest-submission-unknown' ); |
213 | 213 | $out->addHTML( '<br /><br /><br /><br />' ); |
— | — | @@ -226,12 +226,12 @@ |
227 | 227 | } |
228 | 228 | } |
229 | 229 | } |
230 | | - |
| 230 | + |
231 | 231 | /** |
232 | 232 | * Handle page request when the contest is enabled. |
233 | | - * |
| 233 | + * |
234 | 234 | * @since 0.1 |
235 | | - * |
| 235 | + * |
236 | 236 | * @param Contest $contest |
237 | 237 | */ |
238 | 238 | protected function handleEnabledPage( Contest $contest ) { |
— | — | @@ -244,7 +244,7 @@ |
245 | 245 | 'user_id' => $this->getUser()->getId() |
246 | 246 | ) |
247 | 247 | ); |
248 | | - |
| 248 | + |
249 | 249 | if ( $contestant === false ) { |
250 | 250 | $this->getOutput()->redirect( SpecialPage::getTitleFor( 'ContestSignup', $contest->getField( 'name' ) )->getLocalURL() ); |
251 | 251 | } |
— | — | @@ -253,12 +253,12 @@ |
254 | 254 | $this->showSubmissionPage( $contestant ); |
255 | 255 | } |
256 | 256 | } |
257 | | - |
| 257 | + |
258 | 258 | /** |
259 | 259 | * Show the page content. |
260 | | - * |
| 260 | + * |
261 | 261 | * @since 0.1 |
262 | | - * |
| 262 | + * |
263 | 263 | * @param ContestContestant $contestant |
264 | 264 | */ |
265 | 265 | protected function showSubmissionPage( ContestContestant $contestant ) { |
— | — | @@ -275,17 +275,17 @@ |
276 | 276 | && !$this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) { |
277 | 277 | $this->showError( 'contest-mycontests-sessionfail' ); |
278 | 278 | } |
279 | | - |
| 279 | + |
280 | 280 | $this->getOutput()->setPageTitle( $contestant->getContest()->getField( 'name' ) ); |
281 | | - |
| 281 | + |
282 | 282 | $this->getOutput()->addHTML('<div style="clear:both;"></div>'); |
283 | 283 | $this->getOutput()->addWikiMsg( 'contest-submission-header', $contestant->getContest()->getField( 'name' ) ); |
284 | | - |
| 284 | + |
285 | 285 | $form = new HTMLForm( $this->getFormFields( $contestant ), $this->getContext() ); |
286 | | - |
| 286 | + |
287 | 287 | $form->setSubmitCallback( array( $this, 'handleSubmission' ) ); |
288 | 288 | $form->setSubmitText( wfMsg( 'contest-submission-submit' ) ); |
289 | | - |
| 289 | + |
290 | 290 | if( $form->show() ) { |
291 | 291 | $query = is_null( $this->submissionState ) ? '' : $this->submissionState; |
292 | 292 | $this->getOutput()->redirect( $this->getTitle( $contestant->getContest()->getField( 'name' ) )->getLocalURL( $query ) ); |
— | — | @@ -294,37 +294,37 @@ |
295 | 295 | $this->getOutput()->addModules( 'contest.special.submission' ); |
296 | 296 | } |
297 | 297 | } |
298 | | - |
| 298 | + |
299 | 299 | /** |
300 | 300 | * Handle form submission. |
301 | | - * |
| 301 | + * |
302 | 302 | * @since 0.1 |
303 | | - * |
| 303 | + * |
304 | 304 | * @return true|array |
305 | 305 | */ |
306 | 306 | public function handleSubmission( array $data ) { |
307 | 307 | $user = $this->getUser(); |
308 | | - |
| 308 | + |
309 | 309 | $user->setEmail( $data['contestant-email'] ); |
310 | 310 | $user->setRealName( $data['contestant-realname'] ); |
311 | 311 | $user->saveSettings(); |
312 | | - |
| 312 | + |
313 | 313 | $contestant = new ContestContestant( array( |
314 | 314 | 'id' => $data['contestant-id'], |
315 | | - |
| 315 | + |
316 | 316 | 'full_name' => $data['contestant-realname'], |
317 | 317 | 'email' => $data['contestant-email'], |
318 | | - |
| 318 | + |
319 | 319 | 'country' => $data['contestant-country'], |
320 | 320 | 'volunteer' => $data['contestant-volunteer'], |
321 | 321 | 'wmf' => $data['contestant-wmf'], |
322 | 322 | 'cv' => $data['contestant-cv'], |
323 | | - |
| 323 | + |
324 | 324 | 'submission' => trim( $data['contestant-submission'] ), |
325 | 325 | ) ); |
326 | | - |
| 326 | + |
327 | 327 | $success = $contestant->writeToDB(); |
328 | | - |
| 328 | + |
329 | 329 | if ( $success ) { |
330 | 330 | if ( trim( $data['contestant-previous-submission'] ) === '' && trim( $data['contestant-submission'] ) !== '' ) { |
331 | 331 | $this->submissionState = 'added'; |
— | — | @@ -333,33 +333,33 @@ |
334 | 334 | $this->submissionState = 'updated'; |
335 | 335 | } |
336 | 336 | } |
337 | | - |
| 337 | + |
338 | 338 | return $success; |
339 | 339 | } |
340 | | - |
| 340 | + |
341 | 341 | /** |
342 | 342 | * Gets the field definitions for the form. |
343 | | - * |
| 343 | + * |
344 | 344 | * @since 0.1 |
345 | | - * |
| 345 | + * |
346 | 346 | * @param ContestContestant $contest |
347 | 347 | */ |
348 | 348 | protected function getFormFields( ContestContestant $contestant ) { |
349 | 349 | $fields = array(); |
350 | | - |
| 350 | + |
351 | 351 | $user = $this->getUser(); |
352 | | - |
| 352 | + |
353 | 353 | $fields['contestant-id'] = array( |
354 | 354 | 'type' => 'hidden', |
355 | 355 | 'default' => $contestant->getId(), |
356 | 356 | 'id' => 'contest-id', |
357 | 357 | ); |
358 | | - |
| 358 | + |
359 | 359 | $fields['contestant-previous-submission'] = array( |
360 | 360 | 'type' => 'hidden', |
361 | 361 | 'default' => $contestant->getField( 'submission' ), |
362 | 362 | ); |
363 | | - |
| 363 | + |
364 | 364 | $fields['contestant-submission'] = array( |
365 | 365 | 'class' => 'ContestSubmissionField', |
366 | 366 | 'label-message' => 'contest-submission-submission', |
— | — | @@ -369,7 +369,7 @@ |
370 | 370 | 'value' => $contestant->getField( 'submission' ) |
371 | 371 | ) |
372 | 372 | ); |
373 | | - |
| 373 | + |
374 | 374 | $fields['contestant-realname'] = array( |
375 | 375 | 'type' => 'text', |
376 | 376 | 'default' => $user->getRealName(), |
— | — | @@ -377,7 +377,7 @@ |
378 | 378 | 'required' => true, |
379 | 379 | 'validation-callback' => array( __CLASS__, 'validateNameField' ) |
380 | 380 | ); |
381 | | - |
| 381 | + |
382 | 382 | $fields['contestant-email'] = array( |
383 | 383 | 'type' => 'email', |
384 | 384 | 'default' => $user->getEmail(), |
— | — | @@ -385,7 +385,7 @@ |
386 | 386 | 'required' => true, |
387 | 387 | 'validation-callback' => array( __CLASS__, 'validateEmailField' ), |
388 | 388 | ); |
389 | | - |
| 389 | + |
390 | 390 | $fields['contestant-country'] = array( |
391 | 391 | 'type' => 'select', |
392 | 392 | 'default' => $contestant->getField( 'country' ), |
— | — | @@ -393,139 +393,139 @@ |
394 | 394 | 'required' => true, |
395 | 395 | 'options' => ContestContestant::getCountriesForInput() |
396 | 396 | ); |
397 | | - |
| 397 | + |
398 | 398 | $fields['contestant-volunteer'] = array( |
399 | 399 | 'type' => 'check', |
400 | 400 | 'default' => $contestant->getField( 'volunteer' ), |
401 | 401 | 'label-message' => 'contest-signup-volunteer', |
402 | 402 | ); |
403 | | - |
| 403 | + |
404 | 404 | $fields['contestant-wmf'] = array( |
405 | 405 | 'type' => 'check', |
406 | 406 | 'default' => $contestant->getField( 'wmf' ), |
407 | 407 | 'label-message' => 'contest-signup-wmf', |
408 | 408 | ); |
409 | | - |
| 409 | + |
410 | 410 | $hasWMF = $contestant->hasField( 'wmf' ); |
411 | | - |
| 411 | + |
412 | 412 | $fields['contestant-cv'] = array( |
413 | 413 | 'type' => $hasWMF && $contestant->getField( 'wmf' ) ? 'text' : 'hidden', |
414 | 414 | 'default' => $hasWMF ? $contestant->getField( 'cv' ) : '', |
415 | 415 | 'label-message' => 'contest-signup-cv', |
416 | 416 | 'validation-callback' => array( __CLASS__, 'validateCVField' ), |
417 | 417 | ); |
418 | | - |
| 418 | + |
419 | 419 | return $fields; |
420 | 420 | } |
421 | | - |
| 421 | + |
422 | 422 | /** |
423 | 423 | * HTMLForm field validation-callback for name field. |
424 | | - * |
| 424 | + * |
425 | 425 | * @since 0.1 |
426 | | - * |
| 426 | + * |
427 | 427 | * @param $value String |
428 | 428 | * @param $alldata Array |
429 | | - * |
| 429 | + * |
430 | 430 | * @return true|string |
431 | 431 | */ |
432 | 432 | public static function validateNameField( $value, $alldata = null ) { |
433 | 433 | if ( strlen( $value ) < 2 ) { |
434 | 434 | return wfMsg( 'contest-signup-invalid-name' ); |
435 | 435 | } |
436 | | - |
| 436 | + |
437 | 437 | return true; |
438 | 438 | } |
439 | | - |
| 439 | + |
440 | 440 | /** |
441 | 441 | * HTMLForm field validation-callback for email field. |
442 | | - * |
| 442 | + * |
443 | 443 | * @since 0.1 |
444 | | - * |
| 444 | + * |
445 | 445 | * @param $value String |
446 | 446 | * @param $alldata Array |
447 | | - * |
| 447 | + * |
448 | 448 | * @return true|string |
449 | 449 | */ |
450 | 450 | public static function validateEmailField( $value, $alldata = null ) { |
451 | 451 | if ( !Sanitizer::validateEmail( $value ) ) { |
452 | 452 | return wfMsg( 'contest-signup-invalid-email' ); |
453 | 453 | } |
454 | | - |
| 454 | + |
455 | 455 | return true; |
456 | 456 | } |
457 | | - |
| 457 | + |
458 | 458 | /** |
459 | 459 | * HTMLForm field validation-callback for cv field. |
460 | | - * |
| 460 | + * |
461 | 461 | * @since 0.1 |
462 | | - * |
| 462 | + * |
463 | 463 | * @param $value String |
464 | 464 | * @param $alldata Array |
465 | | - * |
| 465 | + * |
466 | 466 | * @return true|string |
467 | 467 | */ |
468 | 468 | public static function validateCVField( $value, $alldata = null ) { |
469 | 469 | if ( trim( $value ) !== '' && filter_var( $value, FILTER_VALIDATE_URL ) === false ) { |
470 | 470 | return wfMsg( 'contest-signup-invalid-cv' ); |
471 | 471 | } |
472 | | - |
| 472 | + |
473 | 473 | return true; |
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
477 | 477 | * HTMLForm field validation-callback for the submissiom field. |
478 | 478 | * Warning: regexes used! o_O |
479 | | - * |
| 479 | + * |
480 | 480 | * @since 0.1 |
481 | | - * |
| 481 | + * |
482 | 482 | * @param $value String |
483 | 483 | * @param $alldata Array |
484 | | - * |
| 484 | + * |
485 | 485 | * @return true|string |
486 | 486 | */ |
487 | 487 | public static function validateSubmissionField( $value, $alldata = null ) { |
488 | 488 | $value = trim( $value ); |
489 | | - |
| 489 | + |
490 | 490 | if ( $value == '' ) { |
491 | 491 | return true; |
492 | 492 | } |
493 | | - |
| 493 | + |
494 | 494 | $allowedPatterns = array( |
495 | 495 | // GitHub URLs such as https://github.com/JeroenDeDauw/smwcon/tree/f9b26ec4ba1101b1f5d4ef76b7ae6ad3dabfb53b |
496 | 496 | // '@^https://github\.com/[a-zA-Z0-9-]+/[a-zA-Z0-9_-]+/tree/[a-zA-Z0-9]{40}$@i' |
497 | 497 | ); |
498 | | - |
| 498 | + |
499 | 499 | foreach ( ContestSettings::get( 'submissionDomains' ) as $domain ) { |
500 | 500 | $allowedPatterns[] = '@^https?://(([a-z0-9]+)\.)?' . str_replace( '.', '\.', $domain ) . '/.*$@i'; |
501 | 501 | } |
502 | | - |
| 502 | + |
503 | 503 | foreach ( $allowedPatterns as $pattern ) { |
504 | 504 | if ( preg_match( $pattern, $value ) ) { |
505 | 505 | return true; |
506 | 506 | } |
507 | 507 | } |
508 | | - |
| 508 | + |
509 | 509 | return wfMsg( 'contest-submission-invalid-url' ); |
510 | 510 | } |
511 | | - |
| 511 | + |
512 | 512 | } |
513 | 513 | |
514 | 514 | class ContestSubmissionField extends HTMLFormField { |
515 | | - |
| 515 | + |
516 | 516 | public function getInputHTML( $value ) { |
517 | 517 | $attribs = array( |
518 | 518 | 'class' => 'contest-submission', |
519 | 519 | 'data-name' => $this->mName |
520 | 520 | ); |
521 | | - |
| 521 | + |
522 | 522 | foreach ( $this->mParams['options'] as $name => $value ) { |
523 | 523 | $attribs['data-' . $name] = $value; |
524 | 524 | } |
525 | | - |
| 525 | + |
526 | 526 | return Html::element( |
527 | 527 | 'div', |
528 | 528 | $attribs |
529 | 529 | ); |
530 | 530 | } |
531 | | - |
| 531 | + |
532 | 532 | } |
Index: trunk/extensions/Contest/specials/SpecialContestWelcome.php |
— | — | @@ -2,50 +2,50 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Contest landing page for participants. |
6 | | - * |
| 6 | + * |
7 | 7 | * @since 0.1 |
8 | | - * |
| 8 | + * |
9 | 9 | * @file SpecialContestWelcome.php |
10 | 10 | * @ingroup Contest |
11 | | - * |
| 11 | + * |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | 15 | class SpecialContestWelcome extends SpecialContestPage { |
16 | | - |
| 16 | + |
17 | 17 | /** |
18 | 18 | * Constructor. |
19 | | - * |
| 19 | + * |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | 23 | parent::__construct( 'ContestWelcome' ); |
24 | 24 | } |
25 | | - |
| 25 | + |
26 | 26 | /** |
27 | 27 | * Main method. |
28 | | - * |
| 28 | + * |
29 | 29 | * @since 0.1 |
30 | | - * |
| 30 | + * |
31 | 31 | * @param string $arg |
32 | 32 | */ |
33 | 33 | public function execute( $subPage ) { |
34 | 34 | $subPage = str_replace( '_', ' ', $subPage ); |
35 | | - |
| 35 | + |
36 | 36 | if ( !parent::execute( $subPage ) ) { |
37 | 37 | return; |
38 | 38 | } |
39 | | - |
| 39 | + |
40 | 40 | $out = $this->getOutput(); |
41 | | - |
| 41 | + |
42 | 42 | $contest = Contest::s()->selectRow( null, array( 'name' => $subPage ) ); |
43 | | - |
| 43 | + |
44 | 44 | if ( $contest === false ) { |
45 | 45 | $this->showError( 'contest-welcome-unknown' ); |
46 | 46 | $out->addHTML( '<br /><br /><br /><br />' ); |
47 | 47 | $out->returnToMain(); |
48 | 48 | } |
49 | | - else if ( ( $contest->getStatus() == Contest::STATUS_FINISHED ) || |
| 49 | + else if ( ( $contest->getStatus() == Contest::STATUS_FINISHED ) || |
50 | 50 | ( $contest->getStatus() == Contest::STATUS_EXPIRED ) ) { |
51 | 51 | $this->showWarning( 'contest-signup-finished' ); |
52 | 52 | $out->addHTML( '<br /><br /><br /><br />' ); |
— | — | @@ -59,12 +59,12 @@ |
60 | 60 | $this->showEnabledPage( $contest ); |
61 | 61 | } |
62 | 62 | } |
63 | | - |
| 63 | + |
64 | 64 | protected function showEnabledPage( Contest $contest ) { |
65 | 65 | $out = $this->getOutput(); |
66 | | - |
| 66 | + |
67 | 67 | $alreadySignedup = $this->getUser()->isLoggedIn(); |
68 | | - |
| 68 | + |
69 | 69 | if ( $alreadySignedup ) { |
70 | 70 | // Check if the user is already a contestant in this contest. |
71 | 71 | // If he is, reirect to submission page, else show signup form. |
— | — | @@ -76,66 +76,66 @@ |
77 | 77 | ) |
78 | 78 | ) !== false; |
79 | 79 | } |
80 | | - |
| 80 | + |
81 | 81 | if ( $alreadySignedup ) { |
82 | 82 | $out->redirect( SpecialPage::getTitleFor( 'MyContests', $contest->getField( 'name' ) )->getLocalURL() ); |
83 | 83 | } |
84 | 84 | else { |
85 | 85 | $out->setPageTitle( $contest->getField( 'name' ) ); |
86 | | - |
| 86 | + |
87 | 87 | $this->showIntro( $contest ); |
88 | 88 | $this->showChallenges( $contest ); |
89 | 89 | $this->showOpportunities( $contest ); |
90 | 90 | $this->showRules( $contest ); |
91 | | - |
| 91 | + |
92 | 92 | $out->addModules( 'contest.special.welcome' ); |
93 | 93 | } |
94 | 94 | } |
95 | | - |
| 95 | + |
96 | 96 | /** |
97 | 97 | * Show the intro text for this contest. |
98 | | - * |
| 98 | + * |
99 | 99 | * @since 0.1 |
100 | | - * |
| 100 | + * |
101 | 101 | * @param Contest $contest |
102 | 102 | */ |
103 | 103 | protected function showIntro( Contest $contest ) { |
104 | 104 | $this->getOutput()->addWikiText( ContestUtils::getArticleContent( $contest->getField( 'intro' ) ) ); |
105 | 105 | } |
106 | | - |
| 106 | + |
107 | 107 | /** |
108 | 108 | * Show a list of the challenges part of this contest. |
109 | | - * |
| 109 | + * |
110 | 110 | * @since 0.1 |
111 | | - * |
| 111 | + * |
112 | 112 | * @param Contest $contest |
113 | 113 | */ |
114 | 114 | protected function showChallenges( Contest $contest ) { |
115 | 115 | $this->showNoJSFallback( $contest ); |
116 | | - |
| 116 | + |
117 | 117 | $this->getOutput()->addHTML( '<div id="contest-challenges"></div><div style="clear:both"></div>' ); |
118 | | - |
| 118 | + |
119 | 119 | $this->addContestJS( $contest ); |
120 | 120 | } |
121 | | - |
| 121 | + |
122 | 122 | /** |
123 | 123 | * Output the needed JS data. |
124 | | - * |
| 124 | + * |
125 | 125 | * @since 0.1 |
126 | | - * |
| 126 | + * |
127 | 127 | * @param Contest $contest |
128 | 128 | */ |
129 | 129 | protected function addContestJS( Contest $contest ) { |
130 | 130 | $challenges = array(); |
131 | | - |
| 131 | + |
132 | 132 | foreach ( $contest->getChallenges() as /* ContestChallenge */ $challenge ) { |
133 | 133 | $data = $challenge->toArray(); |
134 | 134 | $data['target'] = $this->getSignupLink( $contest->getField( 'name' ), $challenge->getId() ); |
135 | 135 | $challenges[] = $data; |
136 | 136 | } |
137 | | - |
138 | | - $this->getOutput()->addScript( |
139 | | - Skin::makeVariablesScript( |
| 137 | + |
| 138 | + $this->getOutput()->addScript( |
| 139 | + Skin::makeVariablesScript( |
140 | 140 | array( |
141 | 141 | 'ContestChallenges' => $challenges, |
142 | 142 | 'ContestConfig' => array() |
— | — | @@ -143,39 +143,39 @@ |
144 | 144 | ) |
145 | 145 | ); |
146 | 146 | } |
147 | | - |
| 147 | + |
148 | 148 | /** |
149 | 149 | * Output fallback code for people that have JS disabled or have a crappy browser. |
150 | | - * |
| 150 | + * |
151 | 151 | * @since 0.1 |
152 | | - * |
| 152 | + * |
153 | 153 | * @param Contest $contest |
154 | 154 | */ |
155 | 155 | protected function showNoJSFallback( Contest $contest ) { |
156 | 156 | $out = $this->getOutput(); |
157 | | - |
| 157 | + |
158 | 158 | $out->addHTML( '<noscript>' ); |
159 | 159 | $out->addHTML( '<p class="errorbox">' . htmlspecialchars( wfMsg( 'contest-welcome-js-off' ) ) . '</p>' ); |
160 | 160 | // TODO? |
161 | 161 | $out->addHTML( '</noscript>' ); |
162 | 162 | } |
163 | | - |
| 163 | + |
164 | 164 | /** |
165 | 165 | * Show the opportunities for this contest. |
166 | | - * |
| 166 | + * |
167 | 167 | * @since 0.1 |
168 | | - * |
| 168 | + * |
169 | 169 | * @param Contest $contest |
170 | 170 | */ |
171 | 171 | protected function showOpportunities( Contest $contest ) { |
172 | 172 | $this->getOutput()->addWikiText( ContestUtils::getArticleContent( $contest->getField( 'opportunities' ) ) ); |
173 | 173 | } |
174 | | - |
| 174 | + |
175 | 175 | /** |
176 | 176 | * Show the rules for this contest. |
177 | | - * |
| 177 | + * |
178 | 178 | * @since 0.1 |
179 | | - * |
| 179 | + * |
180 | 180 | * @param Contest $contest |
181 | 181 | */ |
182 | 182 | protected function showRules( Contest $contest ) { |
— | — | @@ -187,26 +187,26 @@ |
188 | 188 | ) |
189 | 189 | ) ); |
190 | 190 | } |
191 | | - |
| 191 | + |
192 | 192 | /** |
193 | 193 | * Gets the URL for the signup links. |
194 | 194 | * When the user has to login, this will be to the login page, |
195 | 195 | * with a retunrto to the signup page. |
196 | | - * |
| 196 | + * |
197 | 197 | * @since 0.1 |
198 | | - * |
| 198 | + * |
199 | 199 | * @param string $contestName |
200 | 200 | * @param integer|false $challengeId |
201 | | - * |
| 201 | + * |
202 | 202 | * @return string |
203 | 203 | */ |
204 | 204 | protected function getSignupLink( $contestName, $challengeId = false ) { |
205 | 205 | if ( $challengeId !== false ) { |
206 | 206 | $contestName .= '/' . $challengeId; |
207 | 207 | } |
208 | | - |
| 208 | + |
209 | 209 | $signupTitle = SpecialPage::getTitleFor( 'ContestSignup', $contestName ); |
210 | | - |
| 210 | + |
211 | 211 | if ( $this->getUser()->isLoggedIn() ) { |
212 | 212 | return $signupTitle->getLocalURL(); |
213 | 213 | } |
Index: trunk/extensions/Contest/specials/SpecialContestPage.php |
— | — | @@ -3,31 +3,31 @@ |
4 | 4 | /** |
5 | 5 | * Base special page for special pages in the Contest extension, |
6 | 6 | * taking care of some common stuff and providing compatibility helpers. |
7 | | - * |
| 7 | + * |
8 | 8 | * @since 0.1 |
9 | | - * |
| 9 | + * |
10 | 10 | * @file SpecialContestPage.php |
11 | 11 | * @ingroup Contest |
12 | | - * |
| 12 | + * |
13 | 13 | * @licence GNU GPL v3 or later |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | 16 | abstract class SpecialContestPage extends SpecialPage { |
17 | | - |
| 17 | + |
18 | 18 | public $subPage; |
19 | | - |
| 19 | + |
20 | 20 | /** |
21 | 21 | * @see SpecialPage::getDescription |
22 | | - * |
| 22 | + * |
23 | 23 | * @since 0.1 |
24 | 24 | */ |
25 | 25 | public function getDescription() { |
26 | 26 | return wfMsg( 'special-' . strtolower( $this->getName() ) ); |
27 | 27 | } |
28 | | - |
| 28 | + |
29 | 29 | /** |
30 | 30 | * Sets headers - this should be called from the execute() method of all derived classes! |
31 | | - * |
| 31 | + * |
32 | 32 | * @since 0.1 |
33 | 33 | */ |
34 | 34 | public function setHeaders() { |
— | — | @@ -35,35 +35,35 @@ |
36 | 36 | $out->setArticleRelated( false ); |
37 | 37 | $out->setRobotPolicy( 'noindex,nofollow' ); |
38 | 38 | $out->setPageTitle( $this->getDescription() ); |
39 | | - } |
40 | | - |
| 39 | + } |
| 40 | + |
41 | 41 | /** |
42 | 42 | * Main method. |
43 | | - * |
| 43 | + * |
44 | 44 | * @since 0.1 |
45 | | - * |
| 45 | + * |
46 | 46 | * @param string $arg |
47 | 47 | */ |
48 | 48 | public function execute( $subPage ) { |
49 | 49 | $this->subPage = $subPage; |
50 | | - |
| 50 | + |
51 | 51 | $this->setHeaders(); |
52 | 52 | $this->outputHeader(); |
53 | | - |
| 53 | + |
54 | 54 | // If the user is authorized, display the page, if not, show an error. |
55 | 55 | if ( !$this->userCanExecute( $this->getUser() ) ) { |
56 | 56 | $this->displayRestrictionError(); |
57 | 57 | return false; |
58 | 58 | } |
59 | | - |
| 59 | + |
60 | 60 | return true; |
61 | 61 | } |
62 | | - |
| 62 | + |
63 | 63 | /** |
64 | 64 | * Show a message in an error box. |
65 | | - * |
| 65 | + * |
66 | 66 | * @since 0.1 |
67 | | - * |
| 67 | + * |
68 | 68 | * @param string $message |
69 | 69 | */ |
70 | 70 | protected function showError( $message ) { |
— | — | @@ -71,12 +71,12 @@ |
72 | 72 | '<p class="visualClear errorbox">' . wfMsgExt( $message, 'parseinline' ) . '</p>' |
73 | 73 | ); |
74 | 74 | } |
75 | | - |
| 75 | + |
76 | 76 | /** |
77 | 77 | * Show a message in a warning box. |
78 | | - * |
| 78 | + * |
79 | 79 | * @since 0.1 |
80 | | - * |
| 80 | + * |
81 | 81 | * @param string $message |
82 | 82 | */ |
83 | 83 | protected function showWarning( $message ) { |
— | — | @@ -84,12 +84,12 @@ |
85 | 85 | '<p class="visualClear warningbox">' . wfMsgExt( $message, 'parseinline' ) . '</p>' |
86 | 86 | ); |
87 | 87 | } |
88 | | - |
| 88 | + |
89 | 89 | /** |
90 | 90 | * Show a message in a success box. |
91 | | - * |
| 91 | + * |
92 | 92 | * @since 0.1 |
93 | | - * |
| 93 | + * |
94 | 94 | * @param string $message |
95 | 95 | */ |
96 | 96 | protected function showSuccess( $message ) { |
— | — | @@ -97,63 +97,63 @@ |
98 | 98 | '<div class="successbox"><strong><p>' . wfMsgExt( $message, 'parseinline' ) . '</p></strong></div>' |
99 | 99 | ); |
100 | 100 | } |
101 | | - |
| 101 | + |
102 | 102 | /** |
103 | 103 | * Get an array of navigation links. |
104 | | - * |
| 104 | + * |
105 | 105 | * @param string $contestName |
106 | 106 | * @param User $user |
107 | 107 | * @param string|false $exclude |
108 | | - * |
| 108 | + * |
109 | 109 | * @since 0.1 |
110 | | - * |
| 110 | + * |
111 | 111 | * @return array |
112 | 112 | */ |
113 | 113 | protected static function getNavigationLinks( $contestName, User $user, $exclude = false ) { |
114 | 114 | $pages = array(); |
115 | | - |
| 115 | + |
116 | 116 | $pages['contest-nav-contests'] = array( 'Contests' ); |
117 | | - |
| 117 | + |
118 | 118 | if ( $user->isAllowed( 'contestjudge' ) ) { |
119 | 119 | $pages['contest-nav-contest'] = array( 'Contest', $contestName ); |
120 | 120 | } |
121 | | - |
| 121 | + |
122 | 122 | if ( $user->isAllowed( 'contestadmin' ) ) { |
123 | 123 | $pages['contest-nav-editcontest'] = array( 'EditContest', $contestName ); |
124 | 124 | } |
125 | | - |
| 125 | + |
126 | 126 | $pages['contest-nav-contestwelcome'] = array( 'ContestWelcome', $contestName ); |
127 | | - |
| 127 | + |
128 | 128 | if ( $user->isAllowed( 'contestparticipant' ) ) { |
129 | 129 | $pages['contest-nav-contestsignup'] = array( 'ContestSignup', $contestName ); |
130 | 130 | } |
131 | | - |
| 131 | + |
132 | 132 | $links = array(); |
133 | | - |
| 133 | + |
134 | 134 | foreach ( $pages as $message => $page ) { |
135 | 135 | $page = (array)$page; |
136 | | - |
| 136 | + |
137 | 137 | if ( $exclude !== false && $page[0] == $exclude ) { |
138 | 138 | continue; |
139 | 139 | } |
140 | | - |
| 140 | + |
141 | 141 | $subPage = count( $page ) > 1 ? $page[1] : false; |
142 | | - |
| 142 | + |
143 | 143 | $links[] = Html::element( |
144 | 144 | 'a', |
145 | 145 | array( 'href' => SpecialPage::getTitleFor( $page[0], $subPage )->getLocalURL() ), |
146 | 146 | wfMsgExt( $message, 'parseinline', $subPage ) |
147 | 147 | ); |
148 | 148 | } |
149 | | - |
| 149 | + |
150 | 150 | return $links; |
151 | 151 | } |
152 | | - |
| 152 | + |
153 | 153 | /** |
154 | | - * Get the navigation links for the specified contest in a pipe-separated list. |
155 | | - * |
| 154 | + * Get the navigation links for the specified contest in a pipe-separated list. |
| 155 | + * |
156 | 156 | * @since 0.1 |
157 | | - * |
| 157 | + * |
158 | 158 | * @param string $contestName |
159 | 159 | * @param User $user |
160 | 160 | * @param Language $lang |
— | — | @@ -163,20 +163,20 @@ |
164 | 164 | $links = self::getNavigationLinks( $contestName, $user, $exclude ); |
165 | 165 | return Html::rawElement( 'p', array(), $lang->pipeList( $links ) ); |
166 | 166 | } |
167 | | - |
| 167 | + |
168 | 168 | /** |
169 | 169 | * Display navigation links. |
170 | | - * |
| 170 | + * |
171 | 171 | * @since 0.1 |
172 | | - * |
| 172 | + * |
173 | 173 | * @param string|null $subPage |
174 | 174 | */ |
175 | 175 | protected function displayNavigation( $subPage = null ) { |
176 | 176 | if ( is_null( $subPage ) ) { |
177 | 177 | $subPage = $this->subPage; |
178 | 178 | } |
179 | | - |
| 179 | + |
180 | 180 | $this->getOutput()->addHTML( self::getNavigation( $subPage, $this->getUser(), $this->getLang(), $this->getName() ) ); |
181 | 181 | } |
182 | | - |
| 182 | + |
183 | 183 | } |
Index: trunk/extensions/Contest/specials/SpecialContest.php |
— | — | @@ -2,49 +2,49 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Contest interface for judges. |
6 | | - * |
| 6 | + * |
7 | 7 | * @since 0.1 |
8 | | - * |
| 8 | + * |
9 | 9 | * @file SpecialContest.php |
10 | 10 | * @ingroup Contest |
11 | | - * |
| 11 | + * |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | 15 | class SpecialContest extends SpecialContestPage { |
16 | | - |
| 16 | + |
17 | 17 | /** |
18 | 18 | * Constructor. |
19 | | - * |
| 19 | + * |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | 23 | parent::__construct( 'Contest', 'contestjudge', false ); |
24 | 24 | } |
25 | | - |
| 25 | + |
26 | 26 | /** |
27 | 27 | * Main method. |
28 | | - * |
| 28 | + * |
29 | 29 | * @since 0.1 |
30 | | - * |
| 30 | + * |
31 | 31 | * @param string $arg |
32 | 32 | */ |
33 | 33 | public function execute( $subPage ) { |
34 | 34 | $subPage = str_replace( '_', ' ', $subPage ); |
35 | | - |
| 35 | + |
36 | 36 | $subPage = explode( '/', $subPage, 2 ); |
37 | 37 | $challengeTitle = count( $subPage ) > 1 ? $subPage[1] : false; |
38 | | - |
| 38 | + |
39 | 39 | $subPage = $subPage[0]; |
40 | | - |
| 40 | + |
41 | 41 | if ( !parent::execute( $subPage ) ) { |
42 | 42 | return; |
43 | 43 | } |
44 | | - |
| 44 | + |
45 | 45 | $out = $this->getOutput(); |
46 | | - |
| 46 | + |
47 | 47 | $contest = Contest::s()->selectRow( null, array( 'name' => $subPage ) ); |
48 | | - |
| 48 | + |
49 | 49 | if ( $contest === false ) { |
50 | 50 | $out->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() ); |
51 | 51 | } |
— | — | @@ -55,89 +55,89 @@ |
56 | 56 | $this->showContestants( $contest, $challengeTitle ); |
57 | 57 | } |
58 | 58 | } |
59 | | - |
| 59 | + |
60 | 60 | /** |
61 | 61 | * Display the general contest info. |
62 | | - * |
| 62 | + * |
63 | 63 | * @since 0.1 |
64 | | - * |
| 64 | + * |
65 | 65 | * @param Contest $contest |
66 | 66 | */ |
67 | 67 | protected function showGeneralInfo( Contest $contest ) { |
68 | 68 | $out = $this->getOutput(); |
69 | | - |
| 69 | + |
70 | 70 | $out->addHTML( Html::openElement( 'table', array( 'class' => 'wikitable contest-summary' ) ) ); |
71 | | - |
| 71 | + |
72 | 72 | foreach ( $this->getSummaryData( $contest ) as $stat => $value ) { |
73 | 73 | $out->addHTML( '<tr>' ); |
74 | | - |
| 74 | + |
75 | 75 | $out->addHTML( Html::element( |
76 | 76 | 'th', |
77 | 77 | array( 'class' => 'contest-summary-name' ), |
78 | 78 | wfMsg( 'contest-contest-' . $stat ) |
79 | 79 | ) ); |
80 | | - |
| 80 | + |
81 | 81 | $out->addHTML( Html::element( |
82 | 82 | 'td', |
83 | 83 | array( 'class' => 'contest-summary-value' ), |
84 | 84 | $value |
85 | 85 | ) ); |
86 | | - |
| 86 | + |
87 | 87 | $out->addHTML( '</tr>' ); |
88 | 88 | } |
89 | | - |
| 89 | + |
90 | 90 | $out->addHTML( Html::closeElement( 'table' ) ); |
91 | 91 | } |
92 | | - |
| 92 | + |
93 | 93 | /** |
94 | 94 | * Gets the summary data. |
95 | | - * |
| 95 | + * |
96 | 96 | * @since 0.1 |
97 | | - * |
| 97 | + * |
98 | 98 | * @param Contest $contest |
99 | | - * |
| 99 | + * |
100 | 100 | * @return array |
101 | 101 | */ |
102 | 102 | protected function getSummaryData( Contest $contest ) { |
103 | 103 | $stats = array(); |
104 | | - |
| 104 | + |
105 | 105 | $stats['name'] = $contest->getField( 'name' ); |
106 | 106 | $stats['status'] = Contest::getStatusMessage( $contest->getStatus() ); |
107 | 107 | $stats['submissioncount'] = $this->getLang()->formatNum( $contest->getField( 'submission_count' ) ); |
108 | | - |
| 108 | + |
109 | 109 | return $stats; |
110 | 110 | } |
111 | | - |
| 111 | + |
112 | 112 | /** |
113 | 113 | * Show a paged list of the contestants foe this contest. |
114 | | - * |
| 114 | + * |
115 | 115 | * @since 0.1 |
116 | | - * |
| 116 | + * |
117 | 117 | * @param Contest $contest |
118 | 118 | * @param string|false $challengeTitle |
119 | 119 | */ |
120 | 120 | protected function showContestants( Contest $contest, $challengeTitle ) { |
121 | 121 | $out = $this->getOutput(); |
122 | | - |
| 122 | + |
123 | 123 | $out->addHTML( Html::element( 'h3', array(), wfMsg( 'contest-contest-contestants' ) ) ); |
124 | | - |
| 124 | + |
125 | 125 | $conds = array( |
126 | 126 | 'contestant_contest_id' => $contest->getId() |
127 | 127 | ); |
128 | | - |
| 128 | + |
129 | 129 | if ( $challengeTitle !== false ) { |
130 | 130 | $challenge = ContestChallenge::s()->selectRow( 'id', array( 'title' => $challengeTitle ) ); |
131 | | - |
| 131 | + |
132 | 132 | if ( $challenge !== false ) { |
133 | 133 | $conds['contestant_challenge_id'] = $challenge->getField( 'id' ); |
134 | 134 | unset( $conds['contestant_contest_id'] ); // Not needed because the challenge implies the context |
135 | 135 | } |
136 | 136 | } |
137 | | - |
| 137 | + |
138 | 138 | $out->addWikiMsg( 'contest-contest-contestants-text' ); |
139 | | - |
| 139 | + |
140 | 140 | $pager = new ContestantPager( $this, $conds ); |
141 | | - |
| 141 | + |
142 | 142 | if ( $pager->getNumRows() ) { |
143 | 143 | $out->addHTML( |
144 | 144 | $pager->getNavigationBar() . |
— | — | @@ -149,5 +149,5 @@ |
150 | 150 | $out->addWikiMsg( 'contest-contest-no-results' ); |
151 | 151 | } |
152 | 152 | } |
153 | | - |
| 153 | + |
154 | 154 | } |
Index: trunk/extensions/Contest/specials/SpecialContestant.php |
— | — | @@ -2,40 +2,40 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Contest interface for judges. |
6 | | - * |
| 6 | + * |
7 | 7 | * @since 0.1 |
8 | | - * |
| 8 | + * |
9 | 9 | * @file SpecialContest.php |
10 | 10 | * @ingroup Contest |
11 | | - * |
| 11 | + * |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | 15 | class SpecialContestant extends SpecialContestPage { |
16 | | - |
| 16 | + |
17 | 17 | /** |
18 | 18 | * Constructor. |
19 | | - * |
| 19 | + * |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | 23 | parent::__construct( 'Contestant', 'contestjudge', false ); |
24 | 24 | } |
25 | | - |
| 25 | + |
26 | 26 | /** |
27 | 27 | * Main method. |
28 | | - * |
| 28 | + * |
29 | 29 | * @since 0.1 |
30 | | - * |
| 30 | + * |
31 | 31 | * @param string $arg |
32 | 32 | */ |
33 | 33 | public function execute( $subPage ) { |
34 | 34 | if ( !parent::execute( $subPage ) ) { |
35 | 35 | return; |
36 | 36 | } |
37 | | - |
| 37 | + |
38 | 38 | $contestant = ContestContestant::s()->selectRow( null, array( 'id' => (int)$subPage ) ); |
39 | | - |
| 39 | + |
40 | 40 | if ( $contestant === false ) { |
41 | 41 | $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() ); |
42 | 42 | } |
— | — | @@ -45,145 +45,145 @@ |
46 | 46 | { |
47 | 47 | $this->handleSubmission( $contestant ); |
48 | 48 | } |
49 | | - |
| 49 | + |
50 | 50 | $this->showPage( $contestant ); |
51 | 51 | } |
52 | 52 | } |
53 | | - |
| 53 | + |
54 | 54 | /** |
55 | 55 | * Handle a submission by inserting/updating the vote |
56 | 56 | * and (optionally) adding the comment. |
57 | | - * |
| 57 | + * |
58 | 58 | * @since 0.1 |
59 | | - * |
| 59 | + * |
60 | 60 | * @param ContestContestant $contestant |
61 | | - * |
| 61 | + * |
62 | 62 | * @return boolean Success indicator |
63 | 63 | */ |
64 | 64 | protected function handleSubmission( ContestContestant $contestant ) { |
65 | 65 | $success = true; |
66 | | - |
| 66 | + |
67 | 67 | if ( trim( $this->getRequest()->getText( 'new-comment-text' ) ) !== '' ) { |
68 | 68 | $comment = new ContestComment( array( |
69 | 69 | 'user_id' => $this->getUser()->getId(), |
70 | 70 | 'contestant_id' => $contestant->getId(), |
71 | | - |
| 71 | + |
72 | 72 | 'text' => $this->getRequest()->getText( 'new-comment-text' ), |
73 | 73 | 'time' => wfTimestampNow() |
74 | 74 | ) ); |
75 | | - |
| 75 | + |
76 | 76 | $success = $comment->writeToDB(); |
77 | | - |
| 77 | + |
78 | 78 | if ( $success ) { |
79 | 79 | ContestContestant::s()->addToField( 'comments', 1 ); |
80 | 80 | } |
81 | 81 | } |
82 | | - |
| 82 | + |
83 | 83 | if ( $success && !is_null( $this->getRequest()->getVal( 'contestant-rating' ) ) ) { |
84 | 84 | $attribs = array( |
85 | 85 | 'value' => $this->getRequest()->getInt( 'contestant-rating' ), |
86 | 86 | 'contestant_id' => $contestant->getId(), |
87 | 87 | 'user_id' => $this->getUser()->getId() |
88 | 88 | ); |
89 | | - |
| 89 | + |
90 | 90 | if ( !is_null( $this->getRequest()->getVal( 'contestant-vote-id' ) ) ) { |
91 | 91 | $attribs['id'] = $this->getRequest()->getInt( 'contestant-vote-id' ); |
92 | 92 | } |
93 | | - |
| 93 | + |
94 | 94 | $vote = new ContestVote( $attribs ); |
95 | 95 | $success = $vote->writeToDB() && $success; |
96 | 96 | } |
97 | | - |
| 97 | + |
98 | 98 | return $success; |
99 | 99 | } |
100 | | - |
| 100 | + |
101 | 101 | /** |
102 | 102 | * Show the actual page, conisting of the navigation, the summary and |
103 | 103 | * the rating and voting controls. |
104 | | - * |
| 104 | + * |
105 | 105 | * @since 0.1 |
106 | | - * |
| 106 | + * |
107 | 107 | * @param ContestContestant $contestant |
108 | 108 | */ |
109 | 109 | protected function showPage( ContestContestant $contestant ) { |
110 | 110 | global $wgScript; |
111 | 111 | $out = $this->getOutput(); |
112 | | - |
| 112 | + |
113 | 113 | $out->setPageTitle( wfMsgExt( |
114 | 114 | 'contest-contestant-title', |
115 | 115 | 'parseinline', |
116 | 116 | $contestant->getField( 'id' ), |
117 | 117 | $contestant->getContest()->getField( 'name' ) |
118 | 118 | ) ); |
119 | | - |
| 119 | + |
120 | 120 | $this->displayNavigation( str_replace( ' ', '_', $contestant->getContest()->getField( 'name' ) ) ); |
121 | | - |
| 121 | + |
122 | 122 | $this->showGeneralInfo( $contestant ); |
123 | | - |
| 123 | + |
124 | 124 | $out->addHTML( '<form method="post" action="' . htmlspecialchars( $wgScript ) . '">' ); |
125 | 125 | $out->addHTML( Html::hidden( 'title', $this->getTitle( $this->subPage )->getPrefixedDBkey() ) ); |
126 | 126 | $out->addHTML( Html::hidden( 'wpEditToken', $this->getUser()->editToken() ) ); |
127 | | - |
| 127 | + |
128 | 128 | $this->showRating( $contestant ); |
129 | 129 | $this->showComments( $contestant ); |
130 | | - |
| 130 | + |
131 | 131 | $out->addHTML( '</form>' ); |
132 | | - |
| 132 | + |
133 | 133 | $out->addModules( 'contest.special.contestant' ); |
134 | 134 | } |
135 | | - |
| 135 | + |
136 | 136 | /** |
137 | 137 | * Display the general contestant info. |
138 | | - * |
| 138 | + * |
139 | 139 | * @since 0.1 |
140 | | - * |
| 140 | + * |
141 | 141 | * @param ContestContestant $contestant |
142 | 142 | */ |
143 | 143 | protected function showGeneralInfo( ContestContestant $contestant ) { |
144 | 144 | $out = $this->getOutput(); |
145 | | - |
| 145 | + |
146 | 146 | $out->addHTML( Html::openElement( 'table', array( 'class' => 'wikitable contestant-summary' ) ) ); |
147 | | - |
| 147 | + |
148 | 148 | foreach ( $this->getSummaryData( $contestant ) as $stat => $value ) { |
149 | 149 | $out->addHTML( '<tr>' ); |
150 | | - |
| 150 | + |
151 | 151 | $out->addHTML( Html::element( |
152 | 152 | 'th', |
153 | 153 | array( 'class' => 'contestant-summary-name' ), |
154 | 154 | wfMsg( 'contest-contestant-header-' . $stat ) |
155 | 155 | ) ); |
156 | | - |
| 156 | + |
157 | 157 | $out->addHTML( Html::rawElement( |
158 | 158 | 'td', |
159 | 159 | array( 'class' => 'contestant-summary-value' ), |
160 | 160 | $value |
161 | 161 | ) ); |
162 | | - |
| 162 | + |
163 | 163 | $out->addHTML( '</tr>' ); |
164 | 164 | } |
165 | | - |
| 165 | + |
166 | 166 | $out->addHTML( Html::closeElement( 'table' ) ); |
167 | 167 | } |
168 | | - |
| 168 | + |
169 | 169 | /** |
170 | 170 | * Gets the summary data. |
171 | 171 | * Values are escaped. |
172 | | - * |
| 172 | + * |
173 | 173 | * @since 0.1 |
174 | | - * |
| 174 | + * |
175 | 175 | * @param ContestContestant $contestant |
176 | | - * |
| 176 | + * |
177 | 177 | * @return array |
178 | 178 | */ |
179 | 179 | protected function getSummaryData( ContestContestant $contestant ) { |
180 | 180 | $stats = array(); |
181 | | - |
| 181 | + |
182 | 182 | $stats['id'] = htmlspecialchars( $contestant->getField( 'id' ) ); |
183 | 183 | $stats['contest'] = htmlspecialchars( $contestant->getContest()->getField( 'name' ) ); |
184 | | - |
185 | | - $challengeTitles = ContestChallenge::getTitlesForIds( $contestant->getField( 'challenge_id' ) ); |
| 184 | + |
| 185 | + $challengeTitles = ContestChallenge::getTitlesForIds( $contestant->getField( 'challenge_id' ) ); |
186 | 186 | $stats['challenge'] = htmlspecialchars( $challengeTitles[$contestant->getField( 'challenge_id' )] ); |
187 | | - |
| 187 | + |
188 | 188 | if ( $contestant->getField( 'submission' ) === '' ) { |
189 | 189 | $stats['submission'] = htmlspecialchars( wfMsg( 'contest-contestant-notsubmitted' ) ); |
190 | 190 | } |
— | — | @@ -194,58 +194,58 @@ |
195 | 195 | wfMsg( 'contest-contestant-submission-url' ) |
196 | 196 | ) . '</b>'; |
197 | 197 | } |
198 | | - |
| 198 | + |
199 | 199 | $countries = ContestContestant::getCountries(); |
200 | 200 | $stats['country'] = htmlspecialchars( $countries[$contestant->getField( 'country' )] ); |
201 | | - |
| 201 | + |
202 | 202 | $stats['wmf'] = htmlspecialchars( wfMsg( 'contest-contestant-' . ( $contestant->getField( 'wmf' ) ? 'yes' : 'no' ) ) ); |
203 | 203 | $stats['volunteer'] = htmlspecialchars( wfMsg( 'contest-contestant-' . ( $contestant->getField( 'volunteer' ) ? 'yes' : 'no' ) ) ); |
204 | | - |
| 204 | + |
205 | 205 | $stats['rating'] = htmlspecialchars( wfMsgExt( |
206 | 206 | 'contest-contestant-rating', |
207 | 207 | 'parsemag', |
208 | 208 | $this->getLang()->formatNum( $contestant->getField( 'rating' ) ), |
209 | 209 | $this->getLang()->formatNum( $contestant->getField( 'rating_count' ) ) |
210 | 210 | ) ); |
211 | | - |
| 211 | + |
212 | 212 | $stats['comments'] = htmlspecialchars( $this->getLang()->formatNum( $contestant->getField( 'comments' ) ) ); |
213 | | - |
| 213 | + |
214 | 214 | return $stats; |
215 | 215 | } |
216 | | - |
| 216 | + |
217 | 217 | /** |
218 | 218 | * Display the current rating the judge gave if any and a control to |
219 | 219 | * (re)-rate. |
220 | | - * |
| 220 | + * |
221 | 221 | * @since 0.1 |
222 | | - * |
| 222 | + * |
223 | 223 | * @param ContestContestant $contestant |
224 | 224 | */ |
225 | 225 | protected function showRating( ContestContestant $contestant ) { |
226 | 226 | $out = $this->getOutput(); |
227 | | - |
| 227 | + |
228 | 228 | $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-contestant-rate' ) ) ); |
229 | | - |
| 229 | + |
230 | 230 | $vote = ContestVote::s()->selectRow( |
231 | 231 | array( 'value', 'id' ), |
232 | 232 | array( 'user_id' => $this->getUser()->getId(), 'contestant_id' => $contestant->getId() ) |
233 | 233 | ); |
234 | | - |
| 234 | + |
235 | 235 | if ( $vote === false ) { |
236 | 236 | $message = wfMsg( 'contest-contestant-not-voted' ); |
237 | 237 | } |
238 | 238 | else { |
239 | 239 | $message = wfMsgExt( |
240 | 240 | 'contest-contestant-voted', |
241 | | - 'parsemag', |
| 241 | + 'parsemag', |
242 | 242 | $this->getLang()->formatNum( $vote->getField( 'value' ) ) |
243 | 243 | ); |
244 | | - |
| 244 | + |
245 | 245 | $out->addHTML( Html::hidden( 'contestant-vote-id', $vote->getId() ) ); |
246 | | - } |
247 | | - |
| 246 | + } |
| 247 | + |
248 | 248 | $out->addHTML( Html::element( 'p', array(), $message ) ); |
249 | | - |
| 249 | + |
250 | 250 | foreach ( ContestSettings::get( 'voteValues' ) as $value ) { |
251 | 251 | $attribs = array( |
252 | 252 | 'type' => 'radio', |
— | — | @@ -253,11 +253,11 @@ |
254 | 254 | 'name' => 'contestant-rating', |
255 | 255 | 'id' => 'contestant-rating-' . $value |
256 | 256 | ); |
257 | | - |
| 257 | + |
258 | 258 | if ( $vote !== false && $value == $vote->getField( 'value' ) ) { |
259 | 259 | $attribs['checked'] = 'checked'; |
260 | 260 | } |
261 | | - |
| 261 | + |
262 | 262 | $out->addHTML( |
263 | 263 | Html::element( |
264 | 264 | 'input', |
— | — | @@ -270,52 +270,52 @@ |
271 | 271 | ) |
272 | 272 | ); |
273 | 273 | } |
274 | | - |
| 274 | + |
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
278 | 278 | * Show the comments and a control to add additional ones. |
279 | | - * |
| 279 | + * |
280 | 280 | * @since 0.1 |
281 | | - * |
| 281 | + * |
282 | 282 | * @param ContestContestant $contestant |
283 | 283 | */ |
284 | 284 | protected function showComments( ContestContestant $contestant ) { |
285 | 285 | $out = $this->getOutput(); |
286 | | - |
| 286 | + |
287 | 287 | $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-contestant-comments' ) ) ); |
288 | | - |
| 288 | + |
289 | 289 | $out->addHTML( '<div class="contestant-comments">' ); |
290 | | - |
| 290 | + |
291 | 291 | foreach ( $contestant->getComments() as /* ContestComment */ $comment ) { |
292 | 292 | $out->addHTML( $this->getCommentHTML( $comment ) ); |
293 | 293 | } |
294 | | - |
| 294 | + |
295 | 295 | $out->addHTML( '</div>' ); |
296 | | - |
| 296 | + |
297 | 297 | $out->addHTML( |
298 | 298 | '<div class="contestant-new-comment"> |
299 | 299 | <textarea cols="40" rows="10" name="new-comment-text"></textarea> |
300 | 300 | </div>' |
301 | 301 | ); |
302 | | - |
| 302 | + |
303 | 303 | $out->addHTML( Html::input( 'submitChanges', wfMsg( 'contest-contestant-submit' ), 'submit' ) ); |
304 | 304 | } |
305 | | - |
| 305 | + |
306 | 306 | /** |
307 | 307 | * Get the HTML for a single comment. |
308 | | - * |
| 308 | + * |
309 | 309 | * @since 0.1 |
310 | | - * |
| 310 | + * |
311 | 311 | * @param ContestComment $comment |
312 | | - * |
| 312 | + * |
313 | 313 | * @return string |
314 | 314 | */ |
315 | 315 | protected function getCommentHTML( ContestComment $comment ) { |
316 | 316 | $user = User::newFromId( $comment->getField( 'user_id' ) ); |
317 | | - |
| 317 | + |
318 | 318 | $htmlId = 'c' . $comment->getId(); |
319 | | - |
| 319 | + |
320 | 320 | $html = Html::rawElement( |
321 | 321 | 'div', |
322 | 322 | array( 'class' => 'contestant-comment-meta' ), |
— | — | @@ -333,13 +333,13 @@ |
334 | 334 | Linker::userToolLinks( $comment->getField( 'user_id' ), $user->getName() ) |
335 | 335 | ) . '   ' . htmlspecialchars( $this->getLang()->timeanddate( $comment->getField( 'time' ), true ) ) |
336 | 336 | ); |
337 | | - |
| 337 | + |
338 | 338 | $html .= Html::rawElement( |
339 | 339 | 'div', |
340 | 340 | array( 'class' => 'contestant-comment-text mw-content-' . $this->getLang()->getDir() . '' ), |
341 | 341 | $this->getOutput()->parse( $comment->getField( 'text' ) ) |
342 | 342 | ); |
343 | | - |
| 343 | + |
344 | 344 | return Html::rawElement( |
345 | 345 | 'div', |
346 | 346 | array( |
— | — | @@ -349,5 +349,5 @@ |
350 | 350 | $html |
351 | 351 | ); |
352 | 352 | } |
353 | | - |
| 353 | + |
354 | 354 | } |
Index: trunk/extensions/Contest/specials/SpecialContests.php |
— | — | @@ -1,99 +1,99 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * List of contests, with admin and judge links depending on user rights. |
6 | | - * |
| 5 | + * List of contests, with admin and judge links depending on user rights. |
| 6 | + * |
7 | 7 | * @since 0.1 |
8 | | - * |
| 8 | + * |
9 | 9 | * @file SpecialContests.php |
10 | 10 | * @ingroup Contest |
11 | | - * |
| 11 | + * |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | 15 | class SpecialContests extends SpecialContestPage { |
16 | | - |
| 16 | + |
17 | 17 | /** |
18 | 18 | * Constructor. |
19 | | - * |
| 19 | + * |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | 23 | parent::__construct( 'Contests' ); |
24 | 24 | } |
25 | | - |
| 25 | + |
26 | 26 | /** |
27 | 27 | * Returns if the user can access the page or not. |
28 | | - * |
| 28 | + * |
29 | 29 | * @return boolean |
30 | 30 | */ |
31 | 31 | protected function userCanAccess() { |
32 | 32 | $user = $this->getUser(); |
33 | | - return |
| 33 | + return |
34 | 34 | ( $user->isAllowed( 'contestadmin' ) || $user->isAllowed( 'contestjudge' ) ) |
35 | 35 | && !$user->isBlocked(); |
36 | 36 | } |
37 | | - |
| 37 | + |
38 | 38 | /** |
39 | 39 | * This page is unlisted because the only way to access it is though a contest |
40 | 40 | * landing page. |
41 | | - * |
| 41 | + * |
42 | 42 | * @return false|boolean |
43 | 43 | */ |
44 | 44 | public function isListed() { |
45 | 45 | return $this->userCanAccess(); |
46 | 46 | } |
47 | | - |
| 47 | + |
48 | 48 | /** |
49 | 49 | * Main method. |
50 | | - * |
| 50 | + * |
51 | 51 | * @since 0.1 |
52 | | - * |
| 52 | + * |
53 | 53 | * @param string $arg |
54 | 54 | */ |
55 | 55 | public function execute( $subPage ) { |
56 | 56 | $subPage = str_replace( '_', ' ', $subPage ); |
57 | | - |
| 57 | + |
58 | 58 | if ( !parent::execute( $subPage ) ) { |
59 | 59 | return; |
60 | 60 | } |
61 | | - |
| 61 | + |
62 | 62 | $user = $this->getUser(); |
63 | | - |
| 63 | + |
64 | 64 | if ( !$this->userCanAccess() ) { |
65 | 65 | $this->displayRestrictionError(); |
66 | 66 | } |
67 | | - |
| 67 | + |
68 | 68 | if ( $user->isAllowed( 'contestadmin' ) ) { |
69 | 69 | $this->displayAddNewControl(); |
70 | 70 | } |
71 | | - |
| 71 | + |
72 | 72 | $this->displayContests(); |
73 | 73 | } |
74 | | - |
| 74 | + |
75 | 75 | /** |
76 | 76 | * Displays the contests. |
77 | | - * |
| 77 | + * |
78 | 78 | * @since 0.1 |
79 | 79 | */ |
80 | 80 | protected function displayContests() { |
81 | 81 | $contests = Contest::s()->select( array( 'id', 'name', 'status', 'end', 'submission_count' ) ); |
82 | | - |
| 82 | + |
83 | 83 | if ( count( $contests ) > 0 ) { |
84 | 84 | $this->displayContestsTable( $contests ); |
85 | 85 | } |
86 | | - |
| 86 | + |
87 | 87 | $this->getOutput()->addModules( 'ext.contest.special.contests' ); |
88 | 88 | } |
89 | | - |
| 89 | + |
90 | 90 | /** |
91 | 91 | * Displays a small form to add a new campaign. |
92 | | - * |
| 92 | + * |
93 | 93 | * @since 0.1 |
94 | 94 | */ |
95 | 95 | protected function displayAddNewControl() { |
96 | 96 | $out = $this->getOutput(); |
97 | | - |
| 97 | + |
98 | 98 | $out->addHTML( Html::openElement( |
99 | 99 | 'form', |
100 | 100 | array( |
— | — | @@ -101,66 +101,66 @@ |
102 | 102 | 'action' => SpecialPage::getTitleFor( 'EditContest' )->getLocalURL(), |
103 | 103 | ) |
104 | 104 | ) ); |
105 | | - |
| 105 | + |
106 | 106 | $out->addHTML( '<fieldset>' ); |
107 | | - |
| 107 | + |
108 | 108 | $out->addHTML( '<legend>' . htmlspecialchars( wfMsg( 'contest-special-addnew' ) ) . '</legend>' ); |
109 | | - |
| 109 | + |
110 | 110 | $out->addHTML( Html::element( 'p', array(), wfMsg( 'contest-special-namedoc' ) ) ); |
111 | | - |
| 111 | + |
112 | 112 | $out->addHTML( Html::element( 'label', array( 'for' => 'newcontest' ), wfMsg( 'contest-special-newname' ) ) ); |
113 | | - |
| 113 | + |
114 | 114 | $out->addHTML( ' ' . Html::input( 'newcontest' ) . ' ' ); |
115 | | - |
| 115 | + |
116 | 116 | $out->addHTML( Html::input( |
117 | 117 | 'addnewcontest', |
118 | 118 | wfMsg( 'contest-special-add' ), |
119 | 119 | 'submit' |
120 | 120 | ) ); |
121 | | - |
| 121 | + |
122 | 122 | $out->addHTML( Html::hidden( 'newEditToken', $this->getUser()->editToken() ) ); |
123 | | - |
| 123 | + |
124 | 124 | $out->addHTML( '</fieldset></form>' ); |
125 | 125 | } |
126 | | - |
| 126 | + |
127 | 127 | /** |
128 | 128 | * Displays a list of all contests. |
129 | | - * |
| 129 | + * |
130 | 130 | * @since 0.1 |
131 | | - * |
| 131 | + * |
132 | 132 | * @param array $contests |
133 | 133 | */ |
134 | 134 | protected function displayContestsTable( array /* of Contest */ $contests ) { |
135 | 135 | $user = $this->getUser(); |
136 | 136 | $out = $this->getOutput(); |
137 | | - |
| 137 | + |
138 | 138 | $out->addHTML( Html::element( 'h2', array( 'class' => 'contests-title' ), wfMsg( 'contest-special-existing' ) ) ); |
139 | | - |
| 139 | + |
140 | 140 | $out->addHTML( Xml::openElement( |
141 | 141 | 'table', |
142 | 142 | array( 'class' => 'wikitable sortable contests-table' ) |
143 | 143 | ) ); |
144 | | - |
| 144 | + |
145 | 145 | $headers = array( |
146 | 146 | Html::element( 'th', array(), wfMsg( 'contest-special-name' ) ), |
147 | 147 | Html::element( 'th', array(), wfMsg( 'contest-special-status' ) ), |
148 | 148 | Html::element( 'th', array(), wfMsg( 'contest-special-submissioncount' ) ) |
149 | 149 | ); |
150 | | - |
| 150 | + |
151 | 151 | $headers[] = Html::element( 'th', array( 'class' => 'unsortable' ) ); |
152 | | - |
| 152 | + |
153 | 153 | // if ( $user->isAllowed( 'contestadmin' ) ) { |
154 | 154 | // $headers[] = Html::element( 'th', array( 'class' => 'unsortable' ), wfMsg( 'contest-special-edit' ) ); |
155 | 155 | // $headers[] = Html::element( 'th', array( 'class' => 'unsortable' ), wfMsg( 'contest-special-delete' ) ); |
156 | 156 | // } |
157 | | - |
| 157 | + |
158 | 158 | $out->addHTML( '<thead><tr>' . implode( '', $headers ) . '</tr></thead>' ); |
159 | | - |
| 159 | + |
160 | 160 | $out->addHTML( '<tbody>' ); |
161 | | - |
| 161 | + |
162 | 162 | foreach ( $contests as $contest ) { |
163 | 163 | $fields = array(); |
164 | | - |
| 164 | + |
165 | 165 | if ( $user->isAllowed( 'contestparticipant' ) ) { |
166 | 166 | $name = Html::element( |
167 | 167 | 'a', |
— | — | @@ -179,21 +179,21 @@ |
180 | 180 | array( 'data-sort-value' => $contest->getField( 'name' ) ), |
181 | 181 | $name |
182 | 182 | ); |
183 | | - |
| 183 | + |
184 | 184 | $fields[] = Html::element( |
185 | 185 | 'td', |
186 | 186 | array( 'data-sort-value' => $contest->getStatus() ), |
187 | 187 | Contest::getStatusMessage( $contest->getStatus() ) |
188 | 188 | ); |
189 | | - |
| 189 | + |
190 | 190 | $fields[] = Html::element( |
191 | 191 | 'td', |
192 | 192 | array(), |
193 | 193 | $this->getLang()->formatNum( $contest->getField( 'submission_count' ) ) |
194 | 194 | ); |
195 | | - |
| 195 | + |
196 | 196 | $links = array(); |
197 | | - |
| 197 | + |
198 | 198 | if ( $user->isAllowed( 'contestjudge' ) ) { |
199 | 199 | $links[] = Html::element( |
200 | 200 | 'a', |
— | — | @@ -203,7 +203,7 @@ |
204 | 204 | wfMsg( 'contest-nav-contest' ) |
205 | 205 | ); |
206 | 206 | } |
207 | | - |
| 207 | + |
208 | 208 | if ( $user->isAllowed( 'contestadmin' ) ) { |
209 | 209 | $links[] = Html::element( |
210 | 210 | 'a', |
— | — | @@ -212,7 +212,7 @@ |
213 | 213 | ), |
214 | 214 | wfMsg( 'contest-special-edit' ) |
215 | 215 | ); |
216 | | - |
| 216 | + |
217 | 217 | $links[] = Html::element( |
218 | 218 | 'a', |
219 | 219 | array( |
— | — | @@ -224,7 +224,7 @@ |
225 | 225 | wfMsg( 'contest-special-delete' ) |
226 | 226 | ); |
227 | 227 | } |
228 | | - |
| 228 | + |
229 | 229 | $links[] = Html::element( |
230 | 230 | 'a', |
231 | 231 | array( |
— | — | @@ -232,7 +232,7 @@ |
233 | 233 | ), |
234 | 234 | wfMsg( 'contest-nav-contestwelcome' ) |
235 | 235 | ); |
236 | | - |
| 236 | + |
237 | 237 | if ( $user->isAllowed( 'contestparticipant' ) ) { |
238 | 238 | $links[] = Html::element( |
239 | 239 | 'a', |
— | — | @@ -242,20 +242,20 @@ |
243 | 243 | wfMsg( 'contest-nav-contestsignup' ) |
244 | 244 | ); |
245 | 245 | } |
246 | | - |
| 246 | + |
247 | 247 | $fields[] = Html::rawElement( |
248 | 248 | 'td', |
249 | 249 | array(), |
250 | 250 | $this->getLang()->pipeList( $links ) |
251 | 251 | ); |
252 | | - |
| 252 | + |
253 | 253 | $out->addHTML( '<tr>' . implode( '', $fields ) . '</tr>' ); |
254 | 254 | } |
255 | | - |
| 255 | + |
256 | 256 | $out->addHTML( '</tbody>' ); |
257 | 257 | $out->addHTML( '</table>' ); |
258 | | - |
| 258 | + |
259 | 259 | $out->addModules( 'contest.special.contests' ); |
260 | | - } |
261 | | - |
| 260 | + } |
| 261 | + |
262 | 262 | } |
Index: trunk/extensions/Contest/specials/SpecialContestSignup.php |
— | — | @@ -2,40 +2,40 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Contest signup interface for participants. |
6 | | - * |
| 6 | + * |
7 | 7 | * @since 0.1 |
8 | | - * |
| 8 | + * |
9 | 9 | * @file SpecialContestSignup.php |
10 | 10 | * @ingroup Contest |
11 | | - * |
| 11 | + * |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | 15 | class SpecialContestSignup extends SpecialContestPage { |
16 | | - |
| 16 | + |
17 | 17 | /** |
18 | 18 | * Constructor. |
19 | | - * |
| 19 | + * |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | 23 | parent::__construct( 'ContestSignup' ); |
24 | 24 | } |
25 | | - |
| 25 | + |
26 | 26 | /** |
27 | 27 | * Main method. |
28 | | - * |
| 28 | + * |
29 | 29 | * @since 0.1 |
30 | | - * |
| 30 | + * |
31 | 31 | * @param string $arg |
32 | 32 | */ |
33 | 33 | public function execute( $subPage ) { |
34 | 34 | $subPage = str_replace( '_', ' ', $subPage ); |
35 | | - |
| 35 | + |
36 | 36 | if ( !parent::execute( $subPage ) ) { |
37 | 37 | return; |
38 | 38 | } |
39 | | - |
| 39 | + |
40 | 40 | if ( $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) { |
41 | 41 | $this->showSignupForm( Contest::s()->selectRow( null, array( 'id' => $this->getRequest()->getInt( 'wpcontest-id' ) ) ) ); |
42 | 42 | } |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | /** |
49 | 49 | * This page is unlisted because the only way to access it is though a contest |
50 | 50 | * landing page. |
51 | | - * |
| 51 | + * |
52 | 52 | * @return false|boolean |
53 | 53 | */ |
54 | 54 | public function isListed() { |
— | — | @@ -56,51 +56,51 @@ |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * Handle form submission. |
60 | | - * |
| 60 | + * |
61 | 61 | * @since 0.1 |
62 | | - * |
| 62 | + * |
63 | 63 | * @return true|array |
64 | 64 | */ |
65 | 65 | public function handleSubmission( array $data ) { |
66 | 66 | $user = $this->getUser(); |
67 | | - |
| 67 | + |
68 | 68 | $user->setEmail( $data['contestant-email'] ); |
69 | 69 | $user->setRealName( $data['contestant-realname'] ); |
70 | 70 | $user->saveSettings(); |
71 | | - |
| 71 | + |
72 | 72 | $contestant = new ContestContestant( array( |
73 | 73 | 'contest_id' => $data['contest-id'], |
74 | 74 | 'user_id' => $user->getId(), |
75 | 75 | 'challenge_id' => $data['contestant-challengeid'], |
76 | | - |
| 76 | + |
77 | 77 | 'full_name' => $data['contestant-realname'], |
78 | 78 | 'user_name' => $user->getName(), |
79 | 79 | 'email' => $data['contestant-email'], |
80 | | - |
| 80 | + |
81 | 81 | 'country' => $data['contestant-country'], |
82 | 82 | 'volunteer' => $data['contestant-volunteer'], |
83 | 83 | 'wmf' => $data['contestant-wmf'], |
84 | 84 | ) ); |
85 | | - |
| 85 | + |
86 | 86 | return $contestant->writeToDB(); |
87 | 87 | } |
88 | | - |
| 88 | + |
89 | 89 | /** |
90 | 90 | * Show the page. |
91 | | - * |
| 91 | + * |
92 | 92 | * @since 0.1 |
93 | | - * |
| 93 | + * |
94 | 94 | * @param string $subPage |
95 | 95 | */ |
96 | 96 | protected function showPage( $subPage ) { |
97 | 97 | $out = $this->getOutput(); |
98 | | - |
| 98 | + |
99 | 99 | $subPage = explode( '/', $subPage ); |
100 | 100 | $contestName = $subPage[0]; |
101 | 101 | $challengeId = count( $subPage ) > 1 ? $subPage[1] : false; |
102 | | - |
| 102 | + |
103 | 103 | $contest = Contest::s()->selectRow( null, array( 'name' => $contestName ) ); |
104 | | - |
| 104 | + |
105 | 105 | if ( $contest === false ) { |
106 | 106 | $this->showError( 'contest-signup-unknown' ); |
107 | 107 | $out->addHTML( '<br /><br /><br /><br />' ); |
— | — | @@ -109,34 +109,34 @@ |
110 | 110 | else { |
111 | 111 | switch ( $contest->getStatus() ) { |
112 | 112 | case Contest::STATUS_ACTIVE: |
113 | | - $this->showEnabledPage( $contest, $challengeId ); |
| 113 | + $this->showEnabledPage( $contest, $challengeId ); |
114 | 114 | break; |
115 | 115 | case Contest::STATUS_DRAFT: |
116 | 116 | $this->showWarning( 'contest-signup-draft' ); |
117 | 117 | $out->addHTML( '<br /><br /><br /><br />' ); |
118 | | - $out->returnToMain(); |
| 118 | + $out->returnToMain(); |
119 | 119 | break; |
120 | 120 | case Contest::STATUS_FINISHED: |
121 | 121 | case Contest::STATUS_EXPIRED: |
122 | 122 | $this->showWarning( 'contest-signup-finished' ); |
123 | 123 | $out->addHTML( '<br /><br /><br /><br />' ); |
124 | | - $out->returnToMain(); |
| 124 | + $out->returnToMain(); |
125 | 125 | break; |
126 | 126 | } |
127 | 127 | } |
128 | 128 | } |
129 | | - |
| 129 | + |
130 | 130 | /** |
131 | 131 | * Handle page request when the contest is enabled. |
132 | | - * |
| 132 | + * |
133 | 133 | * @since 0.1 |
134 | | - * |
| 134 | + * |
135 | 135 | * @param Contest $contest |
136 | 136 | * @param integer|false $challengeId |
137 | 137 | */ |
138 | 138 | protected function showEnabledPage( Contest $contest, $challengeId ) { |
139 | 139 | $out = $this->getOutput(); |
140 | | - |
| 140 | + |
141 | 141 | // Check if the user is already a contestant in this contest. |
142 | 142 | // If he is, reirect to submission page, else show signup form. |
143 | 143 | $contestant = ContestContestant::s()->selectRow( |
— | — | @@ -146,80 +146,80 @@ |
147 | 147 | 'user_id' => $this->getUser()->getId() |
148 | 148 | ) |
149 | 149 | ); |
150 | | - |
| 150 | + |
151 | 151 | if ( $contestant === false ) { |
152 | 152 | $out->setPageTitle( $contest->getField( 'name' ) ); |
153 | 153 | $out->addWikiMsg( 'contest-signup-header', $contest->getField( 'name' ) ); |
154 | | - |
| 154 | + |
155 | 155 | $this->showSignupForm( $contest, $challengeId ); |
156 | 156 | } |
157 | 157 | else { |
158 | 158 | $out->redirect( SpecialPage::getTitleFor( 'MyContests', $contest->getField( 'name' ) )->getLocalURL() ); |
159 | 159 | } |
160 | 160 | } |
161 | | - |
| 161 | + |
162 | 162 | /** |
163 | 163 | * Display the signup form for this contest. |
164 | | - * |
| 164 | + * |
165 | 165 | * @since 0.1 |
166 | | - * |
| 166 | + * |
167 | 167 | * @param Contest $contest |
168 | 168 | * @param integer|false $challengeId |
169 | 169 | */ |
170 | 170 | protected function showSignupForm( Contest $contest, $challengeId = false ) { |
171 | 171 | $form = new HTMLForm( $this->getFormFields( $contest, $challengeId ), $this->getContext() ); |
172 | | - |
| 172 | + |
173 | 173 | $form->setSubmitCallback( array( $this, 'handleSubmission' ) ); |
174 | 174 | $form->setSubmitText( wfMsg( 'contest-signup-submit' ) ); |
175 | | - |
| 175 | + |
176 | 176 | if( $form->show() ) { |
177 | 177 | $this->showSucess( $contest ); |
178 | 178 | } |
179 | 179 | else { |
180 | 180 | $this->getOutput()->addModules( 'contest.special.signup' ); |
181 | 181 | } |
182 | | - |
183 | | - $this->getOutput()->addScript( |
184 | | - Skin::makeVariablesScript( |
| 182 | + |
| 183 | + $this->getOutput()->addScript( |
| 184 | + Skin::makeVariablesScript( |
185 | 185 | array( |
186 | 186 | 'ContestConfig' => array( 'rules_page' => ContestUtils::getParsedArticleContent( $contest->getField( 'rules_page' ) ) ) |
187 | 187 | ) |
188 | 188 | ) |
189 | 189 | ); |
190 | 190 | } |
191 | | - |
| 191 | + |
192 | 192 | /** |
193 | 193 | * Redirect the user to the contest page and add the "new" argument to the URL |
194 | | - * so they get a success message. |
195 | | - * |
| 194 | + * so they get a success message. |
| 195 | + * |
196 | 196 | * @since 0.1 |
197 | | - * |
| 197 | + * |
198 | 198 | * @param Contest $contest |
199 | 199 | */ |
200 | 200 | protected function showSucess( Contest $contest ) { |
201 | 201 | $url = SpecialPage::getTitleFor( 'MyContests', $contest->getField( 'name' ) )->getLocalURL( 'new' ); |
202 | 202 | $this->getOutput()->redirect( $url ); |
203 | 203 | } |
204 | | - |
| 204 | + |
205 | 205 | /** |
206 | 206 | * Gets the field definitions for the form. |
207 | | - * |
| 207 | + * |
208 | 208 | * @since 0.1 |
209 | | - * |
| 209 | + * |
210 | 210 | * @param Contest $contest |
211 | 211 | * @param integer|false $challengeId |
212 | 212 | */ |
213 | 213 | protected function getFormFields( Contest $contest, $challengeId ) { |
214 | 214 | $fields = array(); |
215 | | - |
| 215 | + |
216 | 216 | $user = $this->getUser(); |
217 | | - |
| 217 | + |
218 | 218 | $fields['contest-id'] = array( |
219 | 219 | 'type' => 'hidden', |
220 | 220 | 'default' => $contest->getId(), |
221 | 221 | 'id' => 'contest-id', |
222 | 222 | ); |
223 | | - |
| 223 | + |
224 | 224 | $fields['contestant-realname'] = array( |
225 | 225 | 'type' => 'text', |
226 | 226 | 'default' => $user->getRealName(), |
— | — | @@ -227,7 +227,7 @@ |
228 | 228 | 'required' => true, |
229 | 229 | 'validation-callback' => array( __CLASS__, 'validateNameField' ) |
230 | 230 | ); |
231 | | - |
| 231 | + |
232 | 232 | $fields['contestant-email'] = array( |
233 | 233 | 'type' => 'text', |
234 | 234 | 'default' => $user->getEmail(), |
— | — | @@ -235,7 +235,7 @@ |
236 | 236 | 'required' => true, |
237 | 237 | 'validation-callback' => array( __CLASS__, 'validateEmailField' ) |
238 | 238 | ); |
239 | | - |
| 239 | + |
240 | 240 | $fields['contestant-country'] = array( |
241 | 241 | 'type' => 'select', |
242 | 242 | 'label-message' => 'contest-signup-country', |
— | — | @@ -243,7 +243,7 @@ |
244 | 244 | 'options' => ContestContestant::getCountriesForInput( true ), |
245 | 245 | 'validation-callback' => array( __CLASS__, 'validateCountryField' ) |
246 | 246 | ); |
247 | | - |
| 247 | + |
248 | 248 | $fields['contestant-challengeid'] = array( |
249 | 249 | 'type' => 'radio', |
250 | 250 | 'label-message' => 'contest-signup-challenge', |
— | — | @@ -251,23 +251,23 @@ |
252 | 252 | 'required' => true, |
253 | 253 | 'validation-callback' => array( __CLASS__, 'validateChallengeField' ) |
254 | 254 | ); |
255 | | - |
| 255 | + |
256 | 256 | if ( $challengeId !== false ) { |
257 | 257 | $fields['contestant-challengeid']['default'] = $challengeId; |
258 | 258 | } |
259 | | - |
| 259 | + |
260 | 260 | $fields['contestant-volunteer'] = array( |
261 | 261 | 'type' => 'check', |
262 | 262 | 'default' => '0', |
263 | 263 | 'label-message' => 'contest-signup-volunteer', |
264 | 264 | ); |
265 | | - |
| 265 | + |
266 | 266 | $fields['contestant-wmf'] = array( |
267 | 267 | 'type' => 'check', |
268 | 268 | 'default' => '0', |
269 | 269 | 'label-message' => 'contest-signup-wmf', |
270 | 270 | ); |
271 | | - |
| 271 | + |
272 | 272 | $fields['contestant-readrules'] = array( |
273 | 273 | 'type' => 'check', |
274 | 274 | 'default' => '0', |
— | — | @@ -276,118 +276,118 @@ |
277 | 277 | 'id' => 'contest-rules', |
278 | 278 | 'data-foo' => 'bar' |
279 | 279 | ); |
280 | | - |
| 280 | + |
281 | 281 | return $fields; |
282 | 282 | } |
283 | | - |
| 283 | + |
284 | 284 | /** |
285 | 285 | * Gets a list of contests that can be fed directly to the options field of |
286 | 286 | * an HTMLForm radio input. |
287 | 287 | * challenge title => challenge id |
288 | | - * |
| 288 | + * |
289 | 289 | * @since 0.1 |
290 | | - * |
| 290 | + * |
291 | 291 | * @param Contest $contest |
292 | | - * |
| 292 | + * |
293 | 293 | * @return array |
294 | 294 | */ |
295 | 295 | protected function getChallengesList( Contest $contest ) { |
296 | 296 | $list = array(); |
297 | | - |
| 297 | + |
298 | 298 | foreach ( $contest->getChallenges() as /* ContestChallenge */ $challenge ) { |
299 | 299 | $list[$challenge->getField( 'title' )] = $challenge->getId(); |
300 | 300 | } |
301 | | - |
| 301 | + |
302 | 302 | return $list; |
303 | 303 | } |
304 | | - |
| 304 | + |
305 | 305 | /** |
306 | 306 | * HTMLForm field validation-callback for name field. |
307 | 307 | * 1 |
308 | 308 | * @since 0.1 |
309 | | - * |
| 309 | + * |
310 | 310 | * @param $value String |
311 | 311 | * @param $alldata Array |
312 | | - * |
| 312 | + * |
313 | 313 | * @return true|string |
314 | 314 | */ |
315 | 315 | public static function validateNameField( $value, $alldata = null ) { |
316 | 316 | if ( strlen( $value ) < 2 ) { |
317 | 317 | return wfMsg( 'contest-signup-invalid-name' ); |
318 | 318 | } |
319 | | - |
| 319 | + |
320 | 320 | return true; |
321 | 321 | } |
322 | | - |
| 322 | + |
323 | 323 | /** |
324 | 324 | * HTMLForm field validation-callback for email field. |
325 | | - * |
| 325 | + * |
326 | 326 | * @since 0.1 |
327 | | - * |
| 327 | + * |
328 | 328 | * @param $value String |
329 | 329 | * @param $alldata Array |
330 | | - * |
| 330 | + * |
331 | 331 | * @return true|string |
332 | 332 | */ |
333 | 333 | public static function validateEmailField( $value, $alldata = null ) { |
334 | 334 | if ( !Sanitizer::validateEmail( $value ) ) { |
335 | 335 | return wfMsg( 'contest-signup-invalid-email' ); |
336 | 336 | } |
337 | | - |
| 337 | + |
338 | 338 | return true; |
339 | 339 | } |
340 | | - |
| 340 | + |
341 | 341 | /** |
342 | 342 | * HTMLForm field validation-callback for country field. |
343 | | - * |
| 343 | + * |
344 | 344 | * @since 0.1 |
345 | | - * |
| 345 | + * |
346 | 346 | * @param $value String |
347 | 347 | * @param $alldata Array |
348 | | - * |
| 348 | + * |
349 | 349 | * @return true|string |
350 | 350 | */ |
351 | 351 | public static function validateCountryField( $value, $alldata = null ) { |
352 | 352 | if ( $value === '' ) { |
353 | 353 | return wfMsg( 'contest-signup-require-country' ); |
354 | 354 | } |
355 | | - |
| 355 | + |
356 | 356 | return true; |
357 | 357 | } |
358 | | - |
| 358 | + |
359 | 359 | /** |
360 | 360 | * HTMLForm field validation-callback for rules field. |
361 | | - * |
| 361 | + * |
362 | 362 | * @since 0.1 |
363 | | - * |
| 363 | + * |
364 | 364 | * @param $value String |
365 | 365 | * @param $alldata Array |
366 | | - * |
| 366 | + * |
367 | 367 | * @return true|string |
368 | 368 | */ |
369 | 369 | public static function validateRulesField( $value, $alldata = null ) { |
370 | 370 | if ( !$value ) { |
371 | 371 | return wfMsg( 'contest-signup-require-rules' ); |
372 | 372 | } |
373 | | - |
| 373 | + |
374 | 374 | return true; |
375 | 375 | } |
376 | | - |
| 376 | + |
377 | 377 | /** |
378 | 378 | * HTMLForm field validation-callback for challenge field. |
379 | | - * |
| 379 | + * |
380 | 380 | * @since 0.1 |
381 | | - * |
| 381 | + * |
382 | 382 | * @param $value String |
383 | 383 | * @param $alldata Array |
384 | | - * |
| 384 | + * |
385 | 385 | * @return true|string |
386 | 386 | */ |
387 | 387 | public static function validateChallengeField( $value, $alldata = null ) { |
388 | 388 | if ( is_null( $value ) ) { |
389 | 389 | return wfMsg( 'contest-signup-require-challenge' ); |
390 | 390 | } |
391 | | - |
| 391 | + |
392 | 392 | return true; |
393 | 393 | } |
394 | 394 | |
Index: trunk/extensions/Contest/specials/SpecialEditContest.php |
— | — | @@ -2,41 +2,41 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Contest editing interface for contest admins. |
6 | | - * |
| 6 | + * |
7 | 7 | * @since 0.1 |
8 | | - * |
| 8 | + * |
9 | 9 | * @file SpecialEditContest.php |
10 | 10 | * @ingroup Contest |
11 | | - * |
| 11 | + * |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | 15 | class SpecialEditContest extends FormSpecialPage { |
16 | | - |
| 16 | + |
17 | 17 | protected $contest = false; |
18 | 18 | protected $isNewPost = false; |
19 | | - |
| 19 | + |
20 | 20 | /** |
21 | 21 | * Constructor. |
22 | | - * |
| 22 | + * |
23 | 23 | * @since 0.1 |
24 | 24 | */ |
25 | 25 | public function __construct() { |
26 | 26 | parent::__construct( 'EditContest', 'contestadmin', false ); |
27 | 27 | } |
28 | | - |
| 28 | + |
29 | 29 | /** |
30 | 30 | * @see SpecialPage::getDescription |
31 | | - * |
| 31 | + * |
32 | 32 | * @since 0.1 |
33 | 33 | */ |
34 | 34 | public function getDescription() { |
35 | 35 | return wfMsg( 'special-' . strtolower( $this->getName() ) ); |
36 | 36 | } |
37 | | - |
| 37 | + |
38 | 38 | /** |
39 | 39 | * Sets headers - this should be called from the execute() method of all derived classes! |
40 | | - * |
| 40 | + * |
41 | 41 | * @since 0.1 |
42 | 42 | */ |
43 | 43 | public function setHeaders() { |
— | — | @@ -44,25 +44,25 @@ |
45 | 45 | $out->setArticleRelated( false ); |
46 | 46 | $out->setRobotPolicy( 'noindex,nofollow' ); |
47 | 47 | $out->setPageTitle( $this->getDescription() ); |
48 | | - } |
49 | | - |
| 48 | + } |
| 49 | + |
50 | 50 | /** |
51 | 51 | * Main method. |
52 | | - * |
| 52 | + * |
53 | 53 | * @since 0.1 |
54 | | - * |
| 54 | + * |
55 | 55 | * @param string $subPage |
56 | 56 | */ |
57 | 57 | public function execute( $subPage ) { |
58 | 58 | $subPage = str_replace( '_', ' ', $subPage ); |
59 | | - |
| 59 | + |
60 | 60 | $this->setParameter( $subPage ); |
61 | 61 | $this->setHeaders(); |
62 | 62 | $this->outputHeader(); |
63 | 63 | |
64 | 64 | // This will throw exceptions if there's a problem |
65 | 65 | $this->userCanExecute( $this->getUser() ); |
66 | | - |
| 66 | + |
67 | 67 | if ( $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) { |
68 | 68 | $this->showForm(); |
69 | 69 | } |
— | — | @@ -70,36 +70,36 @@ |
71 | 71 | $this->showContent( $subPage ); |
72 | 72 | } |
73 | 73 | } |
74 | | - |
| 74 | + |
75 | 75 | /** |
76 | 76 | * Show the form. |
77 | | - * |
| 77 | + * |
78 | 78 | * @since 0.1 |
79 | 79 | */ |
80 | 80 | protected function showForm() { |
81 | 81 | $form = $this->getForm(); |
82 | | - |
| 82 | + |
83 | 83 | if ( $form->show() ) { |
84 | 84 | $this->onSuccess(); |
85 | 85 | } |
86 | 86 | } |
87 | | - |
| 87 | + |
88 | 88 | /** |
89 | 89 | * Attempt to get the contest to be edited or create the one to be added. |
90 | 90 | * If this works, show the form, if not, redirect to special:contests. |
91 | | - * |
| 91 | + * |
92 | 92 | * @since 0.1 |
93 | | - * |
| 93 | + * |
94 | 94 | * @param string $subPage |
95 | 95 | */ |
96 | 96 | protected function showContent( $subPage ) { |
97 | 97 | $isNew = $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'newEditToken' ) ); |
98 | | - |
| 98 | + |
99 | 99 | if ( $isNew ) { |
100 | 100 | $data = array( 'name' => $this->getRequest()->getVal( 'newcontest' ) ); |
101 | | - |
| 101 | + |
102 | 102 | $contest = Contest::s()->selectRow( null, $data ); |
103 | | - |
| 103 | + |
104 | 104 | if ( $contest === false ) { |
105 | 105 | $contest = new Contest( $data, true ); |
106 | 106 | } |
— | — | @@ -110,7 +110,7 @@ |
111 | 111 | else { |
112 | 112 | $contest = Contest::s()->selectRow( null, array( 'name' => $subPage ) ); |
113 | 113 | } |
114 | | - |
| 114 | + |
115 | 115 | if ( $contest === false ) { |
116 | 116 | $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() ); |
117 | 117 | } |
— | — | @@ -120,20 +120,20 @@ |
121 | 121 | SpecialContestPage::getNavigation( $contest->getField( 'name' ), $this->getUser(), $this->getLang(), $this->getName() ) |
122 | 122 | ); |
123 | 123 | } |
124 | | - |
| 124 | + |
125 | 125 | $this->contest = $contest; |
126 | 126 | $this->showForm(); |
127 | 127 | $this->getOutput()->addModules( 'contest.special.editcontest' ); |
128 | 128 | } |
129 | 129 | } |
130 | | - |
| 130 | + |
131 | 131 | /** |
132 | 132 | * (non-PHPdoc) |
133 | 133 | * @see FormSpecialPage::getForm() |
134 | 134 | */ |
135 | 135 | protected function getForm() { |
136 | 136 | $form = parent::getForm(); |
137 | | - |
| 137 | + |
138 | 138 | $form->addButton( |
139 | 139 | 'cancelEdit', |
140 | 140 | wfMsg( 'cancel' ), |
— | — | @@ -142,7 +142,7 @@ |
143 | 143 | 'target-url' => SpecialPage::getTitleFor( 'Contests' )->getFullURL() |
144 | 144 | ) |
145 | 145 | ); |
146 | | - |
| 146 | + |
147 | 147 | // $form->addButton( |
148 | 148 | // 'deleteEdit', |
149 | 149 | // wfMsg( 'delete' ), |
— | — | @@ -151,85 +151,85 @@ |
152 | 152 | |
153 | 153 | return $form; |
154 | 154 | } |
155 | | - |
| 155 | + |
156 | 156 | /** |
157 | 157 | * (non-PHPdoc) |
158 | 158 | * @see FormSpecialPage::getFormFields() |
159 | 159 | */ |
160 | 160 | protected function getFormFields() { |
161 | 161 | $contest = $this->contest; |
162 | | - |
| 162 | + |
163 | 163 | $fields = array(); |
164 | 164 | |
165 | 165 | $fields['id'] = array ( 'type' => 'hidden' ); |
166 | | - |
| 166 | + |
167 | 167 | $fields['name'] = array ( |
168 | 168 | 'type' => 'text', |
169 | 169 | 'label-message' => 'contest-edit-name', |
170 | 170 | 'id' => 'contest-name-field', |
171 | 171 | ); |
172 | | - |
| 172 | + |
173 | 173 | $fields['status'] = array ( |
174 | 174 | 'type' => 'radio', |
175 | 175 | 'label-message' => 'contest-edit-status', |
176 | 176 | 'options' => Contest::getStatusMessages( $onlySettable = true ) |
177 | 177 | ); |
178 | | - |
| 178 | + |
179 | 179 | $fields['intro'] = array ( |
180 | 180 | 'type' => 'text', |
181 | 181 | 'label-message' => 'contest-edit-intro', |
182 | 182 | ); |
183 | | - |
| 183 | + |
184 | 184 | $fields['opportunities'] = array ( |
185 | 185 | 'type' => 'text', |
186 | 186 | 'label-message' => 'contest-edit-opportunities', |
187 | 187 | ); |
188 | | - |
| 188 | + |
189 | 189 | $fields['rules_page'] = array ( |
190 | 190 | 'type' => 'text', |
191 | 191 | 'label-message' => 'contest-edit-rulespage', |
192 | 192 | ); |
193 | | - |
| 193 | + |
194 | 194 | $fields['help'] = array ( |
195 | 195 | 'type' => 'text', |
196 | 196 | 'label-message' => 'contest-edit-help', |
197 | 197 | ); |
198 | | - |
| 198 | + |
199 | 199 | $fields['signup_email'] = array ( |
200 | 200 | 'type' => 'text', |
201 | 201 | 'label-message' => 'contest-edit-signup', |
202 | 202 | ); |
203 | | - |
| 203 | + |
204 | 204 | $fields['reminder_email'] = array ( |
205 | 205 | 'type' => 'text', |
206 | 206 | 'label-message' => 'contest-edit-reminder', |
207 | 207 | ); |
208 | | - |
| 208 | + |
209 | 209 | $fields['end'] = array ( |
210 | 210 | 'type' => 'text', |
211 | 211 | 'label-message' => 'contest-edit-end', |
212 | 212 | 'id' => 'contest-edit-end', |
213 | 213 | 'size' => 15 |
214 | 214 | ); |
215 | | - |
| 215 | + |
216 | 216 | if ( $contest !== false ) { |
217 | 217 | foreach ( $fields as $name => $data ) { |
218 | 218 | $default = $contest->getField( $name ); |
219 | | - |
| 219 | + |
220 | 220 | if ( $name == 'end' ) { |
221 | 221 | $default = wfTimestamp( TS_DB, $default ); |
222 | 222 | } |
223 | | - |
| 223 | + |
224 | 224 | $fields[$name]['default'] = $default; |
225 | 225 | } |
226 | 226 | } |
227 | | - |
| 227 | + |
228 | 228 | $mappedFields = array(); |
229 | | - |
| 229 | + |
230 | 230 | foreach ( $fields as $name => $field ) { |
231 | 231 | $mappedFields['contest-' . $name] = $field; |
232 | 232 | } |
233 | | - |
| 233 | + |
234 | 234 | if ( $contest !== false ) { |
235 | 235 | foreach ( $contest->getChallenges() as /* ContestChallenge */ $challenge ) { |
236 | 236 | $mappedFields[] = array( |
— | — | @@ -238,36 +238,36 @@ |
239 | 239 | ); |
240 | 240 | } |
241 | 241 | } |
242 | | - |
| 242 | + |
243 | 243 | $mappedFields['delete-challenges'] = array ( 'type' => 'hidden', 'id' => 'delete-challenges' ); |
244 | | - |
| 244 | + |
245 | 245 | return $mappedFields; |
246 | 246 | } |
247 | | - |
| 247 | + |
248 | 248 | /** |
249 | 249 | * Process the form. At this point we know that the user passes all the criteria in |
250 | 250 | * userCanExecute(), and if the data array contains 'Username', etc, then Username |
251 | 251 | * resets are allowed. |
252 | | - * |
| 252 | + * |
253 | 253 | * @param array $data |
254 | | - * |
| 254 | + * |
255 | 255 | * @return Bool|Array |
256 | 256 | */ |
257 | 257 | public function onSubmit( array $data ) { |
258 | 258 | $fields = array(); |
259 | | - |
| 259 | + |
260 | 260 | foreach ( $data as $name => $value ) { |
261 | 261 | $matches = array(); |
262 | | - |
| 262 | + |
263 | 263 | if ( preg_match( '/contest-(.+)/', $name, $matches ) ) { |
264 | 264 | if ( $matches[1] == 'end' ) { |
265 | 265 | $value = wfTimestamp( TS_MW, strtotime( $value ) ); |
266 | 266 | } |
267 | | - |
| 267 | + |
268 | 268 | $fields[$matches[1]] = $value; |
269 | 269 | } |
270 | 270 | } |
271 | | - |
| 271 | + |
272 | 272 | // If no ID is set, this means it's a new contest, so set the ID to null for an insert. |
273 | 273 | // However, the user can have hot the back button after creation of a new contest, |
274 | 274 | // re-submitting the form. In this case, get the ID of the already existing item for an update. |
— | — | @@ -275,12 +275,12 @@ |
276 | 276 | $contest = Contest::s()->selectRow( 'id', array( 'name' => $fields['name'] ) ); |
277 | 277 | $fields['id'] = $contest === false ? null : $contest->getField( 'id' ); |
278 | 278 | } |
279 | | - |
| 279 | + |
280 | 280 | $contest = new Contest( $fields, true ); |
281 | 281 | |
282 | 282 | $contest->setChallenges( $this->getSubmittedChallenges() ); |
283 | 283 | $success = $contest->writeAllToDB(); |
284 | | - |
| 284 | + |
285 | 285 | $success = $this->removeDeletedChallenges( $data['delete-challenges'] ) && $success; |
286 | 286 | |
287 | 287 | if ( $success ) { |
— | — | @@ -290,57 +290,57 @@ |
291 | 291 | return array(); // TODO |
292 | 292 | } |
293 | 293 | } |
294 | | - |
| 294 | + |
295 | 295 | /** |
296 | 296 | * The UI keeps track of 'removed' challenges by storing them into a |
297 | 297 | * hidden HTML input, pipe-separated. On submission, this method |
298 | 298 | * takes this string and actually deletes them. |
299 | | - * |
| 299 | + * |
300 | 300 | * @since 0.1 |
301 | | - * |
| 301 | + * |
302 | 302 | * @param string $idString |
303 | | - * |
| 303 | + * |
304 | 304 | * @return boolean Success indicator |
305 | 305 | */ |
306 | 306 | protected function removeDeletedChallenges( $idString ) { |
307 | 307 | if ( $idString == '' ) { |
308 | 308 | return true; |
309 | 309 | } |
310 | | - |
311 | | - return ContestChallenge::s()->delete( array( 'id' => explode( '|', $idString ) ) ); |
| 310 | + |
| 311 | + return ContestChallenge::s()->delete( array( 'id' => explode( '|', $idString ) ) ); |
312 | 312 | } |
313 | | - |
| 313 | + |
314 | 314 | /** |
315 | 315 | * Finds the submitted challanges and returns them as a list of |
316 | 316 | * ContestChallenge objects. |
317 | | - * |
| 317 | + * |
318 | 318 | * @since 0.1 |
319 | | - * |
| 319 | + * |
320 | 320 | * @return array of ContestChallenge |
321 | 321 | */ |
322 | 322 | protected function getSubmittedChallenges() { |
323 | 323 | $challenges = array(); |
324 | | - |
| 324 | + |
325 | 325 | foreach ( $this->getrequest()->getValues() as $name => $value ) { |
326 | 326 | $matches = array(); |
327 | | - |
| 327 | + |
328 | 328 | if ( preg_match( '/contest-challenge-(\d+)/', $name, $matches ) ) { |
329 | 329 | $challenges[] = $this->getSubmittedChallenge( $matches[1] ); |
330 | 330 | } elseif ( preg_match( '/contest-challenge-new-(\d+)/', $name, $matches ) ) { |
331 | 331 | $challenges[] = $this->getSubmittedChallenge( $matches[1], true ); |
332 | 332 | } |
333 | 333 | } |
334 | | - |
| 334 | + |
335 | 335 | return $challenges; |
336 | 336 | } |
337 | | - |
| 337 | + |
338 | 338 | /** |
339 | | - * Create and return a contest challenge object from the submitted data. |
340 | | - * |
| 339 | + * Create and return a contest challenge object from the submitted data. |
| 340 | + * |
341 | 341 | * @since 0.1 |
342 | | - * |
| 342 | + * |
343 | 343 | * @param integer|null $challengeId |
344 | | - * |
| 344 | + * |
345 | 345 | * @return ContestChallenge |
346 | 346 | */ |
347 | 347 | protected function getSubmittedChallenge( $challengeId, $isNewChallenge = false ) { |
— | — | @@ -350,9 +350,9 @@ |
351 | 351 | } else { |
352 | 352 | $challengeDbId = $challengeId; |
353 | 353 | } |
354 | | - |
| 354 | + |
355 | 355 | $request = $this->getRequest(); |
356 | | - |
| 356 | + |
357 | 357 | return new ContestChallenge( array( |
358 | 358 | 'id' => $challengeDbId, |
359 | 359 | 'text' => $request->getText( "challenge-text-$challengeId" ), |
— | — | @@ -360,16 +360,16 @@ |
361 | 361 | 'oneline' => $request->getText( "challenge-oneline-$challengeId" ), |
362 | 362 | ) ); |
363 | 363 | } |
364 | | - |
| 364 | + |
365 | 365 | public function onSuccess() { |
366 | 366 | $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() ); |
367 | 367 | } |
368 | 368 | |
369 | 369 | /** |
370 | 370 | * Show a message in a warning box. |
371 | | - * |
| 371 | + * |
372 | 372 | * @since 0.1 |
373 | | - * |
| 373 | + * |
374 | 374 | * @param string $message |
375 | 375 | */ |
376 | 376 | protected function showWarning( $message ) { |
— | — | @@ -377,24 +377,24 @@ |
378 | 378 | '<p class="visualClear warningbox">' . wfMsgExt( $message, 'parseinline' ) . '</p>' |
379 | 379 | ); |
380 | 380 | } |
381 | | - |
| 381 | + |
382 | 382 | } |
383 | 383 | |
384 | 384 | class ContestChallengeField extends HTMLFormField { |
385 | | - |
| 385 | + |
386 | 386 | public function getInputHTML( $value ) { |
387 | 387 | $attribs = array( |
388 | 388 | 'class' => 'contest-challenge' |
389 | 389 | ); |
390 | | - |
| 390 | + |
391 | 391 | foreach ( $this->mParams['options'] as $name => $value ) { |
392 | 392 | $attribs['data-challenge-' . $name] = $value; |
393 | 393 | } |
394 | | - |
| 394 | + |
395 | 395 | return Html::element( |
396 | 396 | 'div', |
397 | 397 | $attribs |
398 | 398 | ); |
399 | 399 | } |
400 | | - |
| 400 | + |
401 | 401 | } |
Index: trunk/extensions/Contest/includes/ContestDBObject.php |
— | — | @@ -4,31 +4,31 @@ |
5 | 5 | * Abstract base class for representing objects that are stored in some DB table. |
6 | 6 | * This is a modified copy of SurveyDBClass, backported to work with PHP 5.2, |
7 | 7 | * and therefore missing all the awesome you get with late static binding. |
8 | | - * |
| 8 | + * |
9 | 9 | * @since 0.1 |
10 | | - * |
| 10 | + * |
11 | 11 | * @file ContestDBObject.php |
12 | 12 | * @ingroup Contest |
13 | | - * |
| 13 | + * |
14 | 14 | * @licence GNU GPL v3 or later |
15 | 15 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
16 | 16 | */ |
17 | 17 | abstract class ContestDBObject { |
18 | | - |
| 18 | + |
19 | 19 | /** |
20 | 20 | * The fields of the object. |
21 | 21 | * field name (w/o prefix) => value |
22 | | - * |
| 22 | + * |
23 | 23 | * @since 0.1 |
24 | 24 | * @var array |
25 | 25 | */ |
26 | 26 | protected $fields = array( 'id' => null ); |
27 | | - |
| 27 | + |
28 | 28 | /** |
29 | 29 | * Constructor. |
30 | | - * |
| 30 | + * |
31 | 31 | * @since 0.1 |
32 | | - * |
| 32 | + * |
33 | 33 | * @param array|null $fields |
34 | 34 | * @param boolean $loadDefaults |
35 | 35 | */ |
— | — | @@ -36,39 +36,39 @@ |
37 | 37 | if ( !is_array( $fields ) ) { |
38 | 38 | $fields = array(); |
39 | 39 | } |
40 | | - |
| 40 | + |
41 | 41 | if ( $loadDefaults ) { |
42 | 42 | $fields = array_merge( $this->getDefaults(), $fields ); |
43 | 43 | } |
44 | | - |
| 44 | + |
45 | 45 | $this->setFields( $fields ); |
46 | 46 | } |
47 | | - |
| 47 | + |
48 | 48 | /** |
49 | 49 | * Returns the name of the database table objects of this type are stored in. |
50 | | - * |
| 50 | + * |
51 | 51 | * @since 0.1 |
52 | | - * |
| 52 | + * |
53 | 53 | * @return string |
54 | 54 | */ |
55 | 55 | public abstract function getDBTable(); |
56 | 56 | |
57 | 57 | /** |
58 | | - * Gets the db field prefix. |
59 | | - * |
| 58 | + * Gets the db field prefix. |
| 59 | + * |
60 | 60 | * @since 0.1 |
61 | | - * |
| 61 | + * |
62 | 62 | * @return string |
63 | 63 | */ |
64 | 64 | protected abstract function getFieldPrefix(); |
65 | | - |
| 65 | + |
66 | 66 | /** |
67 | 67 | * Gets the value of a field. |
68 | | - * |
| 68 | + * |
69 | 69 | * @since 0.1 |
70 | | - * |
| 70 | + * |
71 | 71 | * @param string $name |
72 | | - * |
| 72 | + * |
73 | 73 | * @throws MWException |
74 | 74 | * @return mixed |
75 | 75 | */ |
— | — | @@ -79,23 +79,23 @@ |
80 | 80 | throw new MWException( 'Attempted to get not-set field ' . $name ); |
81 | 81 | } |
82 | 82 | } |
83 | | - |
| 83 | + |
84 | 84 | /** |
85 | 85 | * Remove a field. |
86 | | - * |
| 86 | + * |
87 | 87 | * @since 0.1 |
88 | | - * |
| 88 | + * |
89 | 89 | * @param string $name |
90 | 90 | */ |
91 | 91 | public function removeField( $name ) { |
92 | 92 | unset( $this->fields[$name] ); |
93 | 93 | } |
94 | | - |
| 94 | + |
95 | 95 | /** |
96 | 96 | * Returns the objects database id. |
97 | | - * |
| 97 | + * |
98 | 98 | * @since 0.1 |
99 | | - * |
| 99 | + * |
100 | 100 | * @return integer|null |
101 | 101 | */ |
102 | 102 | public function getId() { |
— | — | @@ -104,45 +104,45 @@ |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * Sets the objects database id. |
108 | | - * |
| 108 | + * |
109 | 109 | * @since 0.1 |
110 | | - * |
| 110 | + * |
111 | 111 | * @param integere|null $id |
112 | 112 | */ |
113 | 113 | public function setId( $id ) { |
114 | 114 | return $this->setField( 'id', $id ); |
115 | 115 | } |
116 | | - |
| 116 | + |
117 | 117 | /** |
118 | 118 | * Gets if a certain field is set. |
119 | | - * |
| 119 | + * |
120 | 120 | * @since 0.1 |
121 | | - * |
| 121 | + * |
122 | 122 | * @param string $name |
123 | | - * |
| 123 | + * |
124 | 124 | * @return boolean |
125 | 125 | */ |
126 | 126 | public function hasField( $name ) { |
127 | 127 | return array_key_exists( $name, $this->fields ); |
128 | 128 | } |
129 | | - |
| 129 | + |
130 | 130 | /** |
131 | 131 | * Gets if the id field is set. |
132 | | - * |
| 132 | + * |
133 | 133 | * @since 0.1 |
134 | | - * |
| 134 | + * |
135 | 135 | * @return boolean |
136 | 136 | */ |
137 | 137 | public function hasIdField() { |
138 | | - return $this->hasField( 'id' ) |
| 138 | + return $this->hasField( 'id' ) |
139 | 139 | && !is_null( $this->getField( 'id' ) ); |
140 | 140 | } |
141 | | - |
| 141 | + |
142 | 142 | /** |
143 | 143 | * Sets multiple fields. |
144 | | - * |
| 144 | + * |
145 | 145 | * @since 0.1 |
146 | | - * |
| 146 | + * |
147 | 147 | * @param array $fields The fields to set |
148 | 148 | * @param boolean $override Override already set fields with the provided values? |
149 | 149 | */ |
— | — | @@ -153,48 +153,48 @@ |
154 | 154 | } |
155 | 155 | } |
156 | 156 | } |
157 | | - |
| 157 | + |
158 | 158 | /** |
159 | | - * Gets the fields => values to write to the table. |
160 | | - * |
| 159 | + * Gets the fields => values to write to the table. |
| 160 | + * |
161 | 161 | * @since 0.1 |
162 | | - * |
| 162 | + * |
163 | 163 | * @return array |
164 | 164 | */ |
165 | 165 | protected function getWriteValues() { |
166 | 166 | $values = array(); |
167 | | - |
| 167 | + |
168 | 168 | foreach ( $this->getFieldTypes() as $name => $type ) { |
169 | 169 | if ( array_key_exists( $name, $this->fields ) ) { |
170 | 170 | $value = $this->fields[$name]; |
171 | | - |
| 171 | + |
172 | 172 | switch ( $type ) { |
173 | 173 | case 'array': |
174 | 174 | $value = serialize( (array)$value ); |
175 | 175 | } |
176 | | - |
| 176 | + |
177 | 177 | $values[$this->getFieldPrefix() . $name] = $value; |
178 | 178 | } |
179 | 179 | } |
180 | | - |
| 180 | + |
181 | 181 | return $values; |
182 | 182 | } |
183 | | - |
| 183 | + |
184 | 184 | /** |
185 | 185 | * Serializes the object to an associative array which |
186 | 186 | * can then easily be converted into JSON or similar. |
187 | | - * |
| 187 | + * |
188 | 188 | * @since 0.1 |
189 | | - * |
| 189 | + * |
190 | 190 | * @param null|array $props |
191 | 191 | * @param boolean $incNullId |
192 | | - * |
| 192 | + * |
193 | 193 | * @return array |
194 | 194 | */ |
195 | 195 | public function toArray( $fields = null, $incNullId = false ) { |
196 | 196 | $data = array(); |
197 | 197 | $setFields = array(); |
198 | | - |
| 198 | + |
199 | 199 | if ( !is_array( $fields ) ) { |
200 | 200 | $setFields = $this->getSetFieldNames(); |
201 | 201 | } else { |
— | — | @@ -204,33 +204,33 @@ |
205 | 205 | } |
206 | 206 | } |
207 | 207 | } |
208 | | - |
| 208 | + |
209 | 209 | foreach ( $setFields as $field ) { |
210 | 210 | if ( $incNullId || $field != 'id' || $this->hasIdField() ) { |
211 | 211 | $data[$field] = $this->getField( $field ); |
212 | 212 | } |
213 | 213 | } |
214 | | - |
| 214 | + |
215 | 215 | return $data; |
216 | 216 | } |
217 | | - |
| 217 | + |
218 | 218 | /** |
219 | 219 | * Load the default values, via getDefaults. |
220 | | - * |
| 220 | + * |
221 | 221 | * @since 0.1 |
222 | | - * |
| 222 | + * |
223 | 223 | * @param boolean $override |
224 | 224 | */ |
225 | 225 | public function loadDefaults( $override = true ) { |
226 | 226 | $this->setFields( $this->getDefaults(), $override ); |
227 | 227 | } |
228 | | - |
| 228 | + |
229 | 229 | /** |
230 | 230 | * Writes the answer to the database, either updating it |
231 | 231 | * when it already exists, or inserting it when it doesn't. |
232 | | - * |
| 232 | + * |
233 | 233 | * @since 0.1 |
234 | | - * |
| 234 | + * |
235 | 235 | * @return boolean Success indicator |
236 | 236 | */ |
237 | 237 | public function writeToDB() { |
— | — | @@ -240,98 +240,98 @@ |
241 | 241 | return $this->insertIntoDB(); |
242 | 242 | } |
243 | 243 | } |
244 | | - |
| 244 | + |
245 | 245 | /** |
246 | 246 | * Updates the object in the database. |
247 | | - * |
| 247 | + * |
248 | 248 | * @since 0.1 |
249 | | - * |
| 249 | + * |
250 | 250 | * @return boolean Success indicator |
251 | 251 | */ |
252 | 252 | protected function updateInDB() { |
253 | 253 | $dbw = wfGetDB( DB_MASTER ); |
254 | | - |
| 254 | + |
255 | 255 | return $dbw->update( |
256 | 256 | $this->getDBTable(), |
257 | 257 | $this->getWriteValues(), |
258 | 258 | array( $this->getFieldPrefix() . 'id' => $this->getId() ) |
259 | 259 | ); |
260 | 260 | } |
261 | | - |
| 261 | + |
262 | 262 | /** |
263 | 263 | * Inserts the object into the database. |
264 | | - * |
| 264 | + * |
265 | 265 | * @since 0.1 |
266 | | - * |
| 266 | + * |
267 | 267 | * @return boolean Success indicator |
268 | 268 | */ |
269 | 269 | protected function insertIntoDB() { |
270 | 270 | $dbw = wfGetDB( DB_MASTER ); |
271 | | - |
| 271 | + |
272 | 272 | $result = $dbw->insert( |
273 | 273 | $this->getDBTable(), |
274 | 274 | $this->getWriteValues() |
275 | 275 | ); |
276 | | - |
| 276 | + |
277 | 277 | $this->setField( 'id', $dbw->insertId() ); |
278 | | - |
| 278 | + |
279 | 279 | return $result; |
280 | 280 | } |
281 | | - |
| 281 | + |
282 | 282 | /** |
283 | 283 | * Removes the object from the database. |
284 | | - * |
| 284 | + * |
285 | 285 | * @since 0.1 |
286 | | - * |
| 286 | + * |
287 | 287 | * @return boolean Success indicator |
288 | 288 | */ |
289 | 289 | public function removeFromDB() { |
290 | 290 | $sucecss = $this->delete( array( 'id' => $this->getId() ) ); |
291 | | - |
| 291 | + |
292 | 292 | if ( $sucecss ) { |
293 | 293 | $this->setField( 'id', null ); |
294 | 294 | } |
295 | | - |
| 295 | + |
296 | 296 | return $sucecss; |
297 | 297 | } |
298 | | - |
| 298 | + |
299 | 299 | /** |
300 | 300 | * Return the names of the fields. |
301 | | - * |
| 301 | + * |
302 | 302 | * @since 0.1 |
303 | | - * |
| 303 | + * |
304 | 304 | * @return array |
305 | 305 | */ |
306 | 306 | public function getFields() { |
307 | 307 | return $this->fields; |
308 | 308 | } |
309 | | - |
| 309 | + |
310 | 310 | /** |
311 | 311 | * Return the names of the fields. |
312 | | - * |
| 312 | + * |
313 | 313 | * @since 0.1 |
314 | | - * |
| 314 | + * |
315 | 315 | * @return array |
316 | 316 | */ |
317 | 317 | public function getSetFieldNames() { |
318 | 318 | return array_keys( $this->fields ); |
319 | 319 | } |
320 | | - |
| 320 | + |
321 | 321 | /** |
322 | 322 | * Sets the value of a field. |
323 | 323 | * Strings can be provided for other types, |
324 | 324 | * so this method can be called from unserialization handlers. |
325 | | - * |
| 325 | + * |
326 | 326 | * @since 0.1 |
327 | | - * |
| 327 | + * |
328 | 328 | * @param string $name |
329 | 329 | * @param mixed $value |
330 | | - * |
| 330 | + * |
331 | 331 | * @throws MWException |
332 | 332 | */ |
333 | 333 | public function setField( $name, $value ) { |
334 | 334 | $fields = $this->getFieldTypes(); |
335 | | - |
| 335 | + |
336 | 336 | if ( array_key_exists( $name, $fields ) ) { |
337 | 337 | switch ( $fields[$name] ) { |
338 | 338 | case 'int': |
— | — | @@ -358,19 +358,19 @@ |
359 | 359 | } |
360 | 360 | break; |
361 | 361 | } |
362 | | - |
| 362 | + |
363 | 363 | $this->fields[$name] = $value; |
364 | 364 | } else { |
365 | 365 | throw new MWException( 'Attempted to set unknown field ' . $name ); |
366 | 366 | } |
367 | 367 | } |
368 | | - |
| 368 | + |
369 | 369 | /** |
370 | 370 | * Returns an array with the fields and their types this object contains. |
371 | 371 | * This corresponds directly to the fields in the database, without prefix. |
372 | | - * |
| 372 | + * |
373 | 373 | * field name => type |
374 | | - * |
| 374 | + * |
375 | 375 | * Allowed types: |
376 | 376 | * * id |
377 | 377 | * * str |
— | — | @@ -378,9 +378,9 @@ |
379 | 379 | * * float |
380 | 380 | * * bool |
381 | 381 | * * array |
382 | | - * |
| 382 | + * |
383 | 383 | * @since 0.1 |
384 | | - * |
| 384 | + * |
385 | 385 | * @return array |
386 | 386 | */ |
387 | 387 | protected abstract function getFieldTypes(); |
— | — | @@ -388,114 +388,114 @@ |
389 | 389 | /** |
390 | 390 | * Returns a list of default field values. |
391 | 391 | * field name => field value |
392 | | - * |
| 392 | + * |
393 | 393 | * @since 0.1 |
394 | | - * |
| 394 | + * |
395 | 395 | * @return array |
396 | 396 | */ |
397 | 397 | public abstract function getDefaults(); |
398 | | - |
| 398 | + |
399 | 399 | // |
400 | 400 | // |
401 | 401 | // All below methods ought to be static, but can't be since this would require LSB introduced in PHP 5.3. |
402 | 402 | // |
403 | 403 | // |
404 | | - |
| 404 | + |
405 | 405 | /** |
406 | 406 | * Gets if the object can take a certain field. |
407 | | - * |
| 407 | + * |
408 | 408 | * @since 0.1 |
409 | | - * |
| 409 | + * |
410 | 410 | * @param string $name |
411 | | - * |
| 411 | + * |
412 | 412 | * @return boolean |
413 | 413 | */ |
414 | 414 | public function canHasField( $name ) { |
415 | 415 | return array_key_exists( $name, $this->getFieldTypes() ); |
416 | 416 | } |
417 | | - |
| 417 | + |
418 | 418 | /** |
419 | 419 | * Takes in a field or array of fields and returns an |
420 | 420 | * array with their prefixed versions, ready for db usage. |
421 | | - * |
| 421 | + * |
422 | 422 | * @since 0.1 |
423 | | - * |
| 423 | + * |
424 | 424 | * @param array|string $fields |
425 | | - * |
| 425 | + * |
426 | 426 | * @return array |
427 | 427 | */ |
428 | 428 | public function getPrefixedFields( $fields ) { |
429 | 429 | $fields = (array)$fields; |
430 | | - |
| 430 | + |
431 | 431 | foreach ( $fields as &$field ) { |
432 | 432 | $field = $this->getFieldPrefix() . $field; |
433 | 433 | } |
434 | | - |
| 434 | + |
435 | 435 | return $fields; |
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
439 | 439 | * Takes in a field and returns an it's prefixed version, ready for db usage. |
440 | | - * |
| 440 | + * |
441 | 441 | * @since 0.1 |
442 | | - * |
| 442 | + * |
443 | 443 | * @param string $field |
444 | | - * |
| 444 | + * |
445 | 445 | * @return string |
446 | 446 | */ |
447 | 447 | public function getPrefixedField( $field ) { |
448 | 448 | return $this->getFieldPrefix() . $field; |
449 | 449 | } |
450 | | - |
| 450 | + |
451 | 451 | /** |
452 | 452 | * Takes in an associative array with field names as keys and |
453 | 453 | * their values as value. The field names are prefixed with the |
454 | 454 | * db field prefix. |
455 | | - * |
| 455 | + * |
456 | 456 | * @since 0.1 |
457 | | - * |
| 457 | + * |
458 | 458 | * @param array $values |
459 | | - * |
| 459 | + * |
460 | 460 | * @return array |
461 | 461 | */ |
462 | 462 | public function getPrefixedValues( array $values ) { |
463 | 463 | $prefixedValues = array(); |
464 | | - |
| 464 | + |
465 | 465 | foreach ( $values as $field => $value ) { |
466 | 466 | $prefixedValues[$this->getFieldPrefix() . $field] = $value; |
467 | 467 | } |
468 | | - |
| 468 | + |
469 | 469 | return $prefixedValues; |
470 | 470 | } |
471 | 471 | |
472 | 472 | /** |
473 | | - * Get a new instance of the class from a database result. |
474 | | - * |
| 473 | + * Get a new instance of the class from a database result. |
| 474 | + * |
475 | 475 | * @since 0.1 |
476 | | - * |
| 476 | + * |
477 | 477 | * @param object $result |
478 | | - * |
| 478 | + * |
479 | 479 | * @return ContestDBObject |
480 | 480 | */ |
481 | 481 | public function newFromDBResult( $result ) { |
482 | 482 | $result = (array)$result; |
483 | 483 | $data = array(); |
484 | 484 | $idFieldLength = strlen( $this->getFieldPrefix() ); |
485 | | - |
| 485 | + |
486 | 486 | foreach ( $result as $name => $value ) { |
487 | 487 | $data[substr( $name, $idFieldLength )] = $value; |
488 | 488 | } |
489 | | - |
| 489 | + |
490 | 490 | return $this->newFromArray( $data ); |
491 | 491 | } |
492 | 492 | |
493 | 493 | /** |
494 | 494 | * Removes the object from the database. |
495 | | - * |
| 495 | + * |
496 | 496 | * @since 0.1 |
497 | | - * |
| 497 | + * |
498 | 498 | * @param array $conditions |
499 | | - * |
| 499 | + * |
500 | 500 | * @return boolean Success indicator |
501 | 501 | */ |
502 | 502 | public function delete( array $conditions ) { |
— | — | @@ -504,121 +504,121 @@ |
505 | 505 | $this->getPrefixedValues( $conditions ) |
506 | 506 | ); |
507 | 507 | } |
508 | | - |
| 508 | + |
509 | 509 | /** |
510 | 510 | * Add an amount (can be negative) to the specified field (needs to be numeric). |
511 | | - * |
| 511 | + * |
512 | 512 | * @since 0.1 |
513 | | - * |
| 513 | + * |
514 | 514 | * @param string $field |
515 | 515 | * @param integer $amount |
516 | | - * |
| 516 | + * |
517 | 517 | * @return boolean Success indicator |
518 | 518 | */ |
519 | 519 | public function addToField( $field, $amount ) { |
520 | 520 | if ( $amount == 0 ) { |
521 | 521 | return true; |
522 | 522 | } |
523 | | - |
| 523 | + |
524 | 524 | if ( !$this->hasIdField() ) { |
525 | 525 | return false; |
526 | 526 | } |
527 | | - |
| 527 | + |
528 | 528 | $absoluteAmount = abs( $amount ); |
529 | 529 | $isNegative = $amount < 0; |
530 | | - |
| 530 | + |
531 | 531 | $dbw = wfGetDB( DB_MASTER ); |
532 | | - |
| 532 | + |
533 | 533 | $fullField = $this->getPrefixedField( $field ); |
534 | | - |
| 534 | + |
535 | 535 | $success = $dbw->update( |
536 | 536 | $this->getDBTable(), |
537 | 537 | array( "$fullField=$fullField" . ( $isNegative ? '-' : '+' ) . $absoluteAmount ), |
538 | 538 | array( $this->getPrefixedField( 'id' ) => $this->getId() ) |
539 | 539 | ); |
540 | | - |
| 540 | + |
541 | 541 | if ( $success && $this->hasField( $field ) ) { |
542 | 542 | $this->setField( $field, $this->getField( $field ) + $amount ); |
543 | 543 | } |
544 | | - |
| 544 | + |
545 | 545 | return $success; |
546 | 546 | } |
547 | | - |
| 547 | + |
548 | 548 | /** |
549 | 549 | * Selects the the specified fields of the records matching the provided |
550 | 550 | * conditions. Field names get prefixed. |
551 | | - * |
| 551 | + * |
552 | 552 | * @since 0.1 |
553 | | - * |
| 553 | + * |
554 | 554 | * @param array|string|null $fields |
555 | 555 | * @param array $conditions |
556 | 556 | * @param array $options |
557 | | - * |
| 557 | + * |
558 | 558 | * @return array of self |
559 | 559 | */ |
560 | 560 | public function select( $fields = null, array $conditions = array(), array $options = array() ) { |
561 | 561 | if ( is_null( $fields ) ) { |
562 | 562 | $fields = array_keys( $this->getFieldTypes() ); |
563 | 563 | } |
564 | | - |
| 564 | + |
565 | 565 | $result = $this->rawSelect( |
566 | 566 | $this->getPrefixedFields( $fields ), |
567 | 567 | $this->getPrefixedValues( $conditions ), |
568 | 568 | $options |
569 | 569 | ); |
570 | | - |
| 570 | + |
571 | 571 | $objects = array(); |
572 | | - |
| 572 | + |
573 | 573 | foreach ( $result as $record ) { |
574 | 574 | $objects[] = $this->newFromDBResult( $record ); |
575 | 575 | } |
576 | | - |
| 576 | + |
577 | 577 | return $objects; |
578 | 578 | } |
579 | | - |
| 579 | + |
580 | 580 | /** |
581 | 581 | * Selects the the specified fields of the first matching record. |
582 | 582 | * Field names get prefixed. |
583 | | - * |
| 583 | + * |
584 | 584 | * @since 0.1 |
585 | | - * |
| 585 | + * |
586 | 586 | * @param array|string|null $fields |
587 | 587 | * @param array $conditions |
588 | 588 | * @param array $options |
589 | | - * |
| 589 | + * |
590 | 590 | * @return self|false |
591 | 591 | */ |
592 | 592 | public function selectRow( $fields = null, array $conditions = array(), array $options = array() ) { |
593 | 593 | $options['LIMIT'] = 1; |
594 | | - |
| 594 | + |
595 | 595 | $objects = $this->select( $fields, $conditions, $options ); |
596 | | - |
| 596 | + |
597 | 597 | return count( $objects ) > 0 ? $objects[0] : false; |
598 | 598 | } |
599 | | - |
| 599 | + |
600 | 600 | /** |
601 | 601 | * Returns if there is at least one record matching the provided conditions. |
602 | 602 | * Condition field names get prefixed. |
603 | | - * |
| 603 | + * |
604 | 604 | * @since 0.1 |
605 | | - * |
| 605 | + * |
606 | 606 | * @param array $conditions |
607 | | - * |
| 607 | + * |
608 | 608 | * @return boolean |
609 | 609 | */ |
610 | 610 | public function has( array $conditions = array() ) { |
611 | 611 | return $this->selectRow( array( 'id' ), $conditions ) !== false; |
612 | 612 | } |
613 | | - |
| 613 | + |
614 | 614 | /** |
615 | 615 | * Returns the amount of matching records. |
616 | 616 | * Condition field names get prefixed. |
617 | | - * |
| 617 | + * |
618 | 618 | * @since 0.1 |
619 | | - * |
| 619 | + * |
620 | 620 | * @param array $conditions |
621 | 621 | * @param array $options |
622 | | - * |
| 622 | + * |
623 | 623 | * @return integer |
624 | 624 | */ |
625 | 625 | public function count( array $conditions = array(), array $options = array() ) { |
— | — | @@ -627,25 +627,25 @@ |
628 | 628 | $this->getPrefixedValues( $conditions ), |
629 | 629 | $options |
630 | 630 | )->fetchObject(); |
631 | | - |
| 631 | + |
632 | 632 | return $res->rowcount; |
633 | 633 | } |
634 | | - |
| 634 | + |
635 | 635 | /** |
636 | 636 | * Selects the the specified fields of the records matching the provided |
637 | | - * conditions. Field names do NOT get prefixed. |
638 | | - * |
| 637 | + * conditions. Field names do NOT get prefixed. |
| 638 | + * |
639 | 639 | * @since 0.1 |
640 | | - * |
| 640 | + * |
641 | 641 | * @param array|null $fields |
642 | 642 | * @param array $conditions |
643 | 643 | * @param array $options |
644 | | - * |
| 644 | + * |
645 | 645 | * @return ResultWrapper |
646 | 646 | */ |
647 | | - public function rawSelect( $fields = null, array $conditions = array(), array $options = array() ) { |
| 647 | + public function rawSelect( $fields = null, array $conditions = array(), array $options = array() ) { |
648 | 648 | $dbr = wfGetDB( DB_SLAVE ); |
649 | | - |
| 649 | + |
650 | 650 | return $dbr->select( |
651 | 651 | $this->getDBTable(), |
652 | 652 | $fields, |
— | — | @@ -656,45 +656,45 @@ |
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
660 | | - * Update the records matching the provided conditions by |
| 660 | + * Update the records matching the provided conditions by |
661 | 661 | * setting the fields that are keys in the $values patam to |
662 | 662 | * their corresponding values. |
663 | | - * |
| 663 | + * |
664 | 664 | * @since 0.1 |
665 | | - * |
| 665 | + * |
666 | 666 | * @param array $values |
667 | 667 | * @param array $conditions |
668 | | - * |
| 668 | + * |
669 | 669 | * @return boolean Success indicator |
670 | 670 | */ |
671 | 671 | public function update( array $values, array $conditions = array() ) { |
672 | 672 | $dbw = wfGetDB( DB_MASTER ); |
673 | | - |
| 673 | + |
674 | 674 | return $dbw->update( |
675 | 675 | $this->getDBTable(), |
676 | 676 | $this->getPrefixedValues( $values ), |
677 | 677 | $this->getPrefixedValues( $conditions ) |
678 | 678 | ); |
679 | 679 | } |
680 | | - |
| 680 | + |
681 | 681 | /** |
682 | 682 | * Return the names of the fields. |
683 | | - * |
| 683 | + * |
684 | 684 | * @since 0.1 |
685 | | - * |
| 685 | + * |
686 | 686 | * @return array |
687 | 687 | */ |
688 | 688 | public function getFieldNames() { |
689 | 689 | return array_keys( $this->getFieldTypes() ); |
690 | 690 | } |
691 | | - |
| 691 | + |
692 | 692 | /** |
693 | 693 | * Returns an array with the fields and their descriptions. |
694 | | - * |
| 694 | + * |
695 | 695 | * field name => field description |
696 | | - * |
| 696 | + * |
697 | 697 | * @since 0.1 |
698 | | - * |
| 698 | + * |
699 | 699 | * @return array |
700 | 700 | */ |
701 | 701 | public function getFieldDescriptions() { |
— | — | @@ -703,12 +703,12 @@ |
704 | 704 | |
705 | 705 | /** |
706 | 706 | * Get API parameters for the fields supported by this object. |
707 | | - * |
| 707 | + * |
708 | 708 | * @since 0.1 |
709 | | - * |
| 709 | + * |
710 | 710 | * @param boolean $requireParams |
711 | 711 | * @param boolean $setDefaults |
712 | | - * |
| 712 | + * |
713 | 713 | * @return array |
714 | 714 | */ |
715 | 715 | public function getAPIParams( $requireParams = false, $setDefaults = false ) { |
— | — | @@ -720,33 +720,33 @@ |
721 | 721 | 'bool' => 'integer', |
722 | 722 | 'array' => 'string' |
723 | 723 | ); |
724 | | - |
| 724 | + |
725 | 725 | $params = array(); |
726 | 726 | $defaults = $this->getDefaults(); |
727 | | - |
| 727 | + |
728 | 728 | foreach ( $this->getFieldTypes() as $field => $type ) { |
729 | 729 | if ( $field == 'id' ) { |
730 | 730 | continue; |
731 | 731 | } |
732 | | - |
| 732 | + |
733 | 733 | $hasDefault = array_key_exists( $field, $defaults ); |
734 | | - |
| 734 | + |
735 | 735 | $params[$field] = array( |
736 | 736 | ApiBase::PARAM_TYPE => $typeMap[$type], |
737 | 737 | ApiBase::PARAM_REQUIRED => $requireParams && !$hasDefault |
738 | 738 | ); |
739 | | - |
| 739 | + |
740 | 740 | if ( $type == 'array' ) { |
741 | 741 | $params[$field][ApiBase::PARAM_ISMULTI] = true; |
742 | 742 | } |
743 | | - |
| 743 | + |
744 | 744 | if ( $setDefaults && $hasDefault ) { |
745 | 745 | $default = is_array( $defaults[$field] ) ? implode( '|', $defaults[$field] ) : $defaults[$field]; |
746 | 746 | $params[$field][ApiBase::PARAM_DFLT] = $default; |
747 | 747 | } |
748 | 748 | } |
749 | | - |
| 749 | + |
750 | 750 | return $params; |
751 | 751 | } |
752 | | - |
| 752 | + |
753 | 753 | } |
Index: trunk/extensions/Contest/includes/ContestVote.php |
— | — | @@ -2,59 +2,59 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Class representing a single contest vote. |
6 | | - * Votes can be made by judges on (submissions of) contestants. |
7 | | - * |
| 6 | + * Votes can be made by judges on (submissions of) contestants. |
| 7 | + * |
8 | 8 | * @since 0.1 |
9 | | - * |
| 9 | + * |
10 | 10 | * @file ContestComment.php |
11 | 11 | * @ingroup Contest |
12 | | - * |
| 12 | + * |
13 | 13 | * @licence GNU GPL v3 or later |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | 16 | class ContestVote extends ContestDBObject { |
17 | | - |
| 17 | + |
18 | 18 | /** |
19 | 19 | * Method to get an instance so methods that ought to be static, |
20 | 20 | * but can't be due to PHP 5.2 not having LSB, can be called on |
21 | 21 | * it. This also allows easy identifying of code that needs to |
22 | | - * be changed once PHP 5.3 becomes an acceptable requirement. |
23 | | - * |
| 22 | + * be changed once PHP 5.3 becomes an acceptable requirement. |
| 23 | + * |
24 | 24 | * @since 0.1 |
25 | | - * |
| 25 | + * |
26 | 26 | * @return ContestDBObject |
27 | 27 | */ |
28 | 28 | public static function s() { |
29 | 29 | static $instance = false; |
30 | | - |
| 30 | + |
31 | 31 | if ( $instance === false ) { |
32 | 32 | $instance = new self( array() ); |
33 | 33 | } |
34 | | - |
| 34 | + |
35 | 35 | return $instance; |
36 | 36 | } |
37 | | - |
| 37 | + |
38 | 38 | /** |
39 | 39 | * Get a new instance of the class from an array. |
40 | 40 | * This method ought to be in the basic class and |
41 | 41 | * return a new static(), but this requires LSB/PHP>=5.3. |
42 | | - * |
| 42 | + * |
43 | 43 | * @since 0.1 |
44 | | - * |
| 44 | + * |
45 | 45 | * @param array $data |
46 | 46 | * @param boolean $loadDefaults |
47 | | - * |
| 47 | + * |
48 | 48 | * @return ContestDBObject |
49 | | - */ |
| 49 | + */ |
50 | 50 | public function newFromArray( array $data, $loadDefaults = false ) { |
51 | 51 | return new self( $data, $loadDefaults ); |
52 | 52 | } |
53 | | - |
| 53 | + |
54 | 54 | /** |
55 | 55 | * @see parent::getFieldTypes |
56 | | - * |
| 56 | + * |
57 | 57 | * @since 0.1 |
58 | | - * |
| 58 | + * |
59 | 59 | * @return string |
60 | 60 | */ |
61 | 61 | public function getDBTable() { |
— | — | @@ -63,20 +63,20 @@ |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * @see parent::getFieldTypes |
67 | | - * |
| 67 | + * |
68 | 68 | * @since 0.1 |
69 | | - * |
| 69 | + * |
70 | 70 | * @return string |
71 | 71 | */ |
72 | 72 | protected function getFieldPrefix() { |
73 | 73 | return 'vote_'; |
74 | 74 | } |
75 | | - |
| 75 | + |
76 | 76 | /** |
77 | 77 | * @see parent::getFieldTypes |
78 | | - * |
| 78 | + * |
79 | 79 | * @since 0.1 |
80 | | - * |
| 80 | + * |
81 | 81 | * @return array |
82 | 82 | */ |
83 | 83 | protected function getFieldTypes() { |
— | — | @@ -84,37 +84,37 @@ |
85 | 85 | 'id' => 'id', |
86 | 86 | 'contestant_id' => 'id', |
87 | 87 | 'user_id' => 'id', |
88 | | - |
| 88 | + |
89 | 89 | 'value' => 'int', |
90 | 90 | ); |
91 | 91 | } |
92 | | - |
| 92 | + |
93 | 93 | /** |
94 | 94 | * @see parent::getDefaults |
95 | | - * |
| 95 | + * |
96 | 96 | * @since 0.1 |
97 | | - * |
| 97 | + * |
98 | 98 | * @return array |
99 | 99 | */ |
100 | 100 | public function getDefaults() { |
101 | 101 | return array( |
102 | 102 | ); |
103 | 103 | } |
104 | | - |
| 104 | + |
105 | 105 | /** |
106 | 106 | * (non-PHPdoc) |
107 | 107 | * @see ContestDBObject::writeToDB() |
108 | 108 | */ |
109 | 109 | public function writeToDB() { |
110 | 110 | $success = parent::writeToDB(); |
111 | | - |
| 111 | + |
112 | 112 | if ( $success ) { |
113 | 113 | $contestant = new ContestContestant( array( 'id' => $this->getField( 'contestant_id' ) ) ); |
114 | 114 | $contestant->updateVotes(); |
115 | 115 | $contestant->writeToDB(); |
116 | 116 | } |
117 | | - |
| 117 | + |
118 | 118 | return $success; |
119 | 119 | } |
120 | | - |
| 120 | + |
121 | 121 | } |
Index: trunk/extensions/Contest/includes/ContestReminderJob.php |
— | — | @@ -2,20 +2,20 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Contest reminder job for email reminders. |
6 | | - * |
| 6 | + * |
7 | 7 | * @since 0.1 |
8 | | - * |
| 8 | + * |
9 | 9 | * @file ContestReminderJob.php |
10 | 10 | * @ingroup Contest |
11 | | - * |
| 11 | + * |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | 15 | class ContestReminderJob extends Job { |
16 | | - |
| 16 | + |
17 | 17 | /** |
18 | 18 | * Constructor. |
19 | | - * |
| 19 | + * |
20 | 20 | * @param Title $title |
21 | 21 | * @param array $params |
22 | 22 | * * contestants, array of ContestContestant, required |
— | — | @@ -41,5 +41,5 @@ |
42 | 42 | |
43 | 43 | return true; |
44 | 44 | } |
45 | | - |
| 45 | + |
46 | 46 | } |
Index: trunk/extensions/Contest/includes/ContestUtils.php |
— | — | @@ -2,70 +2,70 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Utility functions for the Contest extension. |
6 | | - * |
| 6 | + * |
7 | 7 | * @since 0.1 |
8 | | - * |
| 8 | + * |
9 | 9 | * @file ContestUtils.php |
10 | 10 | * @ingroup Contest |
11 | | - * |
| 11 | + * |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | 15 | class ContestUtils { |
16 | | - |
| 16 | + |
17 | 17 | /** |
18 | 18 | * Gets the content of the article with the provided page name, |
19 | 19 | * or an empty string when there is no such article. |
20 | | - * |
| 20 | + * |
21 | 21 | * @since 0.1 |
22 | | - * |
| 22 | + * |
23 | 23 | * @param string $pageName |
24 | | - * |
| 24 | + * |
25 | 25 | * @return string |
26 | 26 | */ |
27 | 27 | public static function getArticleContent( $pageName ) { |
28 | 28 | $title = Title::newFromText( $pageName ); |
29 | | - |
| 29 | + |
30 | 30 | if ( is_null( $title ) ) { |
31 | 31 | return ''; |
32 | 32 | } |
33 | | - |
| 33 | + |
34 | 34 | $article = new Article( $title, 0 ); |
35 | 35 | return $article->fetchContent(); |
36 | 36 | } |
37 | | - |
| 37 | + |
38 | 38 | /** |
39 | 39 | * Gets the content of the article with the provided page name, |
40 | 40 | * or an empty string when there is no such article. |
41 | | - * |
| 41 | + * |
42 | 42 | * @since 0.1 |
43 | | - * |
| 43 | + * |
44 | 44 | * @param string $pageName |
45 | | - * |
| 45 | + * |
46 | 46 | * @return string |
47 | 47 | */ |
48 | 48 | public static function getParsedArticleContent( $pageName ) { |
49 | 49 | $title = Title::newFromText( $pageName ); |
50 | | - |
| 50 | + |
51 | 51 | if ( is_null( $title ) ) { |
52 | 52 | return ''; |
53 | 53 | } |
54 | | - |
| 54 | + |
55 | 55 | $article = new Article( $title, 0 ); |
56 | | - |
| 56 | + |
57 | 57 | global $wgParser, $wgContestEmailParse; |
58 | | - |
| 58 | + |
59 | 59 | $wgContestEmailParse = true; |
60 | | - |
| 60 | + |
61 | 61 | $text = $wgParser->parse( |
62 | 62 | $article->fetchContent(), |
63 | 63 | $article->getTitle(), |
64 | 64 | $article->getParserOptions() |
65 | 65 | )->getText(); |
66 | | - |
| 66 | + |
67 | 67 | $wgContestEmailParse = false; |
68 | | - |
| 68 | + |
69 | 69 | return $text; |
70 | 70 | } |
71 | | - |
| 71 | + |
72 | 72 | } |
Index: trunk/extensions/Contest/includes/ContestantPager.php |
— | — | @@ -2,29 +2,29 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Contestant pager, for on Special:Contest |
6 | | - * |
| 6 | + * |
7 | 7 | * @since 0.1 |
8 | | - * |
| 8 | + * |
9 | 9 | * @file ContestantPager.php |
10 | 10 | * @ingroup Contest |
11 | | - * |
| 11 | + * |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | 15 | class ContestantPager extends TablePager { |
16 | | - |
| 16 | + |
17 | 17 | /** |
18 | 18 | * Query conditions, full field names (ie inc prefix). |
19 | 19 | * @var array |
20 | 20 | */ |
21 | 21 | protected $conds; |
22 | | - |
| 22 | + |
23 | 23 | /** |
24 | 24 | * Special page on which the pager is displayed. |
25 | 25 | * @var SpecialContestPage |
26 | 26 | */ |
27 | 27 | protected $page; |
28 | | - |
| 28 | + |
29 | 29 | /** |
30 | 30 | * Cache for challenge titles. |
31 | 31 | * challenge id => challenge title |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Constructor. |
38 | | - * |
| 38 | + * |
39 | 39 | * @param SpecialContestPage $page |
40 | 40 | * @param array $conds |
41 | 41 | */ |
— | — | @@ -42,45 +42,45 @@ |
43 | 43 | $this->page = $page; |
44 | 44 | $this->conds = $conds; |
45 | 45 | $this->mDefaultDirection = true; |
46 | | - |
| 46 | + |
47 | 47 | $this->queryChallengeTitles( $conds ); |
48 | | - |
49 | | - // when MW 1.19 becomes min, we want to pass an IContextSource $context here. |
| 48 | + |
| 49 | + // when MW 1.19 becomes min, we want to pass an IContextSource $context here. |
50 | 50 | parent::__construct(); |
51 | | - |
| 51 | + |
52 | 52 | $this->getOutput()->addModules( 'contest.contestant.pager' ); |
53 | 53 | } |
54 | | - |
| 54 | + |
55 | 55 | /** |
56 | 56 | * Query all challenge names we might need, |
57 | 57 | * based on the queries conditions, and set them |
58 | 58 | * to the challengeTitles field. |
59 | | - * |
| 59 | + * |
60 | 60 | * @since 0.1 |
61 | | - * |
| 61 | + * |
62 | 62 | * @param array $allConds |
63 | 63 | */ |
64 | 64 | protected function queryChallengeTitles( array $allConds ) { |
65 | 65 | $conds = array(); |
66 | | - |
| 66 | + |
67 | 67 | if ( array_key_exists( 'contestant_contest_id', $allConds ) ) { |
68 | 68 | $conds['contest_id'] = $allConds['contestant_contest_id']; |
69 | 69 | } |
70 | | - |
| 70 | + |
71 | 71 | if ( array_key_exists( 'contestant_challenge_id', $allConds ) ) { |
72 | 72 | $conds['id'] = $allConds['contestant_challenge_id']; |
73 | 73 | } |
74 | | - |
| 74 | + |
75 | 75 | foreach ( ContestChallenge::s()->select( array( 'id', 'title' ), $conds ) as /* ContestChallenge */ $challenge ) { |
76 | 76 | $this->challengeTitles[$challenge->getId()] = $challenge->getField( 'title' ); |
77 | 77 | } |
78 | 78 | } |
79 | | - |
| 79 | + |
80 | 80 | /** |
81 | 81 | * Gets the title of a challenge given it's id. |
82 | | - * |
| 82 | + * |
83 | 83 | * @since 0.1 |
84 | | - * |
| 84 | + * |
85 | 85 | * @param integer $challengeId |
86 | 86 | * @throws MWException |
87 | 87 | */ |
— | — | @@ -91,11 +91,11 @@ |
92 | 92 | else { |
93 | 93 | throw new MWException( 'Attempt to get non-set challenge title' ); |
94 | 94 | } |
95 | | - } |
96 | | - |
| 95 | + } |
| 96 | + |
97 | 97 | /** |
98 | 98 | * Get the OutputPage being used for this instance. |
99 | | - * IndexPager extends ContextSource as of 1.19. |
| 99 | + * IndexPager extends ContextSource as of 1.19. |
100 | 100 | * |
101 | 101 | * @since 0.1 |
102 | 102 | * |
— | — | @@ -104,10 +104,10 @@ |
105 | 105 | public function getOutput() { |
106 | 106 | return version_compare( $GLOBALS['wgVersion'], '1.18', '>' ) ? parent::getOutput() : $GLOBALS['wgOut']; |
107 | 107 | } |
108 | | - |
| 108 | + |
109 | 109 | /** |
110 | 110 | * Get the Language being used for this instance. |
111 | | - * IndexPager extends ContextSource as of 1.19. |
| 111 | + * IndexPager extends ContextSource as of 1.19. |
112 | 112 | * |
113 | 113 | * @since 0.1 |
114 | 114 | * |
— | — | @@ -129,7 +129,7 @@ |
130 | 130 | 'contestant_comments' => 'contest-contestant-commentcount', |
131 | 131 | 'contestant_rating' => 'contest-contestant-overallrating', |
132 | 132 | ); |
133 | | - |
| 133 | + |
134 | 134 | $headers = array_map( 'wfMsg', $headers ); |
135 | 135 | } |
136 | 136 | |
— | — | @@ -139,32 +139,32 @@ |
140 | 140 | function formatRow( $row ) { |
141 | 141 | $this->mCurrentRow = $row; # In case formatValue etc need to know |
142 | 142 | $s = Xml::openElement( 'tr', $this->getRowAttrs($row) ); |
143 | | - |
| 143 | + |
144 | 144 | foreach ( $this->getFieldNames() as $field => $name ) { |
145 | 145 | $value = isset( $row->$field ) ? $row->$field : null; |
146 | 146 | $formatted = strval( $this->formatValue( $field, $value ) ); |
147 | | - |
| 147 | + |
148 | 148 | if ( $formatted == '' ) { |
149 | 149 | $formatted = ' '; |
150 | 150 | } |
151 | 151 | $s .= Xml::tags( 'td', $this->getCellAttrs( $field, $value ), $formatted ); |
152 | 152 | } |
153 | 153 | $s .= "</tr>\n"; |
154 | | - |
| 154 | + |
155 | 155 | return $s; |
156 | 156 | } |
157 | | - |
| 157 | + |
158 | 158 | function getRowAttrs( $row ) { |
159 | 159 | return array_merge( |
160 | 160 | parent::getRowAttrs( $row ), |
161 | 161 | array( 'data-contestant-target' => SpecialPage::getTitleFor( 'Contestant', $row->contestant_id )->getLocalURL() ) |
162 | 162 | ); |
163 | 163 | } |
164 | | - |
| 164 | + |
165 | 165 | function getRowClass( $row ) { |
166 | 166 | return 'contestant-row'; |
167 | 167 | } |
168 | | - |
| 168 | + |
169 | 169 | public function formatValue( $name, $value ) { |
170 | 170 | switch ( $name ) { |
171 | 171 | case 'contestant_id': |
— | — | @@ -205,7 +205,7 @@ |
206 | 206 | ) ); |
207 | 207 | break; |
208 | 208 | } |
209 | | - |
| 209 | + |
210 | 210 | return $value; |
211 | 211 | } |
212 | 212 | |
— | — | @@ -256,5 +256,5 @@ |
257 | 257 | function getTitle() { |
258 | 258 | return $this->page->getFullTitle(); |
259 | 259 | } |
260 | | - |
| 260 | + |
261 | 261 | } |
Index: trunk/extensions/Contest/includes/ContestChallenge.php |
— | — | @@ -2,59 +2,59 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Class representing a single contest challenge object. |
6 | | - * Each contest (can) has a list of associated challenges. |
7 | | - * |
| 6 | + * Each contest (can) has a list of associated challenges. |
| 7 | + * |
8 | 8 | * @since 0.1 |
9 | | - * |
| 9 | + * |
10 | 10 | * @file ContestChallenge.php |
11 | 11 | * @ingroup Contest |
12 | | - * |
| 12 | + * |
13 | 13 | * @licence GNU GPL v3 or later |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | 16 | class ContestChallenge extends ContestDBObject { |
17 | | - |
| 17 | + |
18 | 18 | /** |
19 | 19 | * Method to get an instance so methods that ought to be static, |
20 | 20 | * but can't be due to PHP 5.2 not having LSB, can be called on |
21 | 21 | * it. This also allows easy identifying of code that needs to |
22 | | - * be changed once PHP 5.3 becomes an acceptable requirement. |
23 | | - * |
| 22 | + * be changed once PHP 5.3 becomes an acceptable requirement. |
| 23 | + * |
24 | 24 | * @since 0.1 |
25 | | - * |
| 25 | + * |
26 | 26 | * @return ContestDBObject |
27 | 27 | */ |
28 | 28 | public static function s() { |
29 | 29 | static $instance = false; |
30 | | - |
| 30 | + |
31 | 31 | if ( $instance === false ) { |
32 | 32 | $instance = new self( array() ); |
33 | 33 | } |
34 | | - |
| 34 | + |
35 | 35 | return $instance; |
36 | 36 | } |
37 | | - |
| 37 | + |
38 | 38 | /** |
39 | 39 | * Get a new instance of the class from an array. |
40 | 40 | * This method ought to be in the basic class and |
41 | 41 | * return a new static(), but this requires LSB/PHP>=5.3. |
42 | | - * |
| 42 | + * |
43 | 43 | * @since 0.1 |
44 | | - * |
| 44 | + * |
45 | 45 | * @param array $data |
46 | 46 | * @param boolean $loadDefaults |
47 | | - * |
| 47 | + * |
48 | 48 | * @return ContestDBObject |
49 | | - */ |
| 49 | + */ |
50 | 50 | public function newFromArray( array $data, $loadDefaults = false ) { |
51 | 51 | return new self( $data, $loadDefaults ); |
52 | 52 | } |
53 | | - |
| 53 | + |
54 | 54 | /** |
55 | 55 | * @see parent::getFieldTypes |
56 | | - * |
| 56 | + * |
57 | 57 | * @since 0.1 |
58 | | - * |
| 58 | + * |
59 | 59 | * @return string |
60 | 60 | */ |
61 | 61 | public function getDBTable() { |
— | — | @@ -63,20 +63,20 @@ |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * @see parent::getFieldTypes |
67 | | - * |
| 67 | + * |
68 | 68 | * @since 0.1 |
69 | | - * |
| 69 | + * |
70 | 70 | * @return string |
71 | 71 | */ |
72 | 72 | protected function getFieldPrefix() { |
73 | 73 | return 'challenge_'; |
74 | 74 | } |
75 | | - |
| 75 | + |
76 | 76 | /** |
77 | 77 | * @see parent::getFieldTypes |
78 | | - * |
| 78 | + * |
79 | 79 | * @since 0.1 |
80 | | - * |
| 80 | + * |
81 | 81 | * @return array |
82 | 82 | */ |
83 | 83 | protected function getFieldTypes() { |
— | — | @@ -88,12 +88,12 @@ |
89 | 89 | 'oneline' => 'str', |
90 | 90 | ); |
91 | 91 | } |
92 | | - |
| 92 | + |
93 | 93 | /** |
94 | 94 | * @see parent::getDefaults |
95 | | - * |
| 95 | + * |
96 | 96 | * @since 0.1 |
97 | | - * |
| 97 | + * |
98 | 98 | * @return array |
99 | 99 | */ |
100 | 100 | public function getDefaults() { |
— | — | @@ -103,24 +103,24 @@ |
104 | 104 | 'oneline' => '', |
105 | 105 | ); |
106 | 106 | } |
107 | | - |
| 107 | + |
108 | 108 | /** |
109 | 109 | * Returns an array with challenge IDs (keys) and their associated titles (values) |
110 | | - * for the provided list of IDs. |
111 | | - * |
| 110 | + * for the provided list of IDs. |
| 111 | + * |
112 | 112 | * @param array|integer $ids |
113 | | - * |
| 113 | + * |
114 | 114 | * @return array( id => title ) |
115 | 115 | */ |
116 | 116 | public static function getTitlesForIds( $ids ) { |
117 | 117 | $challenges = self::s()->select( array( 'id', 'title' ), array( 'id' => $ids ) ); |
118 | 118 | $results = array(); |
119 | | - |
| 119 | + |
120 | 120 | foreach ( $challenges as /* ContestChallenge */ $challenge ) { |
121 | 121 | $results[$challenge->getId()] = $challenge->getField( 'title' ); |
122 | 122 | } |
123 | | - |
| 123 | + |
124 | 124 | return $results; |
125 | 125 | } |
126 | | - |
| 126 | + |
127 | 127 | } |
Index: trunk/extensions/Contest/includes/ContestComment.php |
— | — | @@ -2,59 +2,59 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Class representing a single contest comment. |
6 | | - * Comments can be made by judges on (submissions of) contestants. |
7 | | - * |
| 6 | + * Comments can be made by judges on (submissions of) contestants. |
| 7 | + * |
8 | 8 | * @since 0.1 |
9 | | - * |
| 9 | + * |
10 | 10 | * @file ContestComment.php |
11 | 11 | * @ingroup Contest |
12 | | - * |
| 12 | + * |
13 | 13 | * @licence GNU GPL v3 or later |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | 16 | class ContestComment extends ContestDBObject { |
17 | | - |
| 17 | + |
18 | 18 | /** |
19 | 19 | * Method to get an instance so methods that ought to be static, |
20 | 20 | * but can't be due to PHP 5.2 not having LSB, can be called on |
21 | 21 | * it. This also allows easy identifying of code that needs to |
22 | | - * be changed once PHP 5.3 becomes an acceptable requirement. |
23 | | - * |
| 22 | + * be changed once PHP 5.3 becomes an acceptable requirement. |
| 23 | + * |
24 | 24 | * @since 0.1 |
25 | | - * |
| 25 | + * |
26 | 26 | * @return ContestDBObject |
27 | 27 | */ |
28 | 28 | public static function s() { |
29 | 29 | static $instance = false; |
30 | | - |
| 30 | + |
31 | 31 | if ( $instance === false ) { |
32 | 32 | $instance = new self( array() ); |
33 | 33 | } |
34 | | - |
| 34 | + |
35 | 35 | return $instance; |
36 | 36 | } |
37 | | - |
| 37 | + |
38 | 38 | /** |
39 | 39 | * Get a new instance of the class from an array. |
40 | 40 | * This method ought to be in the basic class and |
41 | 41 | * return a new static(), but this requires LSB/PHP>=5.3. |
42 | | - * |
| 42 | + * |
43 | 43 | * @since 0.1 |
44 | | - * |
| 44 | + * |
45 | 45 | * @param array $data |
46 | 46 | * @param boolean $loadDefaults |
47 | | - * |
| 47 | + * |
48 | 48 | * @return ContestDBObject |
49 | | - */ |
| 49 | + */ |
50 | 50 | public function newFromArray( array $data, $loadDefaults = false ) { |
51 | 51 | return new self( $data, $loadDefaults ); |
52 | 52 | } |
53 | | - |
| 53 | + |
54 | 54 | /** |
55 | 55 | * @see parent::getFieldTypes |
56 | | - * |
| 56 | + * |
57 | 57 | * @since 0.1 |
58 | | - * |
| 58 | + * |
59 | 59 | * @return string |
60 | 60 | */ |
61 | 61 | public function getDBTable() { |
— | — | @@ -63,20 +63,20 @@ |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * @see parent::getFieldTypes |
67 | | - * |
| 67 | + * |
68 | 68 | * @since 0.1 |
69 | | - * |
| 69 | + * |
70 | 70 | * @return string |
71 | 71 | */ |
72 | 72 | protected function getFieldPrefix() { |
73 | 73 | return 'comment_'; |
74 | 74 | } |
75 | | - |
| 75 | + |
76 | 76 | /** |
77 | 77 | * @see parent::getFieldTypes |
78 | | - * |
| 78 | + * |
79 | 79 | * @since 0.1 |
80 | | - * |
| 80 | + * |
81 | 81 | * @return array |
82 | 82 | */ |
83 | 83 | protected function getFieldTypes() { |
— | — | @@ -84,17 +84,17 @@ |
85 | 85 | 'id' => 'id', |
86 | 86 | 'contestant_id' => 'id', |
87 | 87 | 'user_id' => 'id', |
88 | | - |
| 88 | + |
89 | 89 | 'text' => 'str', |
90 | 90 | 'time' => 'int', |
91 | 91 | ); |
92 | 92 | } |
93 | | - |
| 93 | + |
94 | 94 | /** |
95 | 95 | * @see parent::getDefaults |
96 | | - * |
| 96 | + * |
97 | 97 | * @since 0.1 |
98 | | - * |
| 98 | + * |
99 | 99 | * @return array |
100 | 100 | */ |
101 | 101 | public function getDefaults() { |
— | — | @@ -103,20 +103,20 @@ |
104 | 104 | 'time' => 0, |
105 | 105 | ); |
106 | 106 | } |
107 | | - |
| 107 | + |
108 | 108 | /** |
109 | 109 | * (non-PHPdoc) |
110 | 110 | * @see ContestDBObject::insertIntoDB() |
111 | 111 | */ |
112 | 112 | protected function insertIntoDB() { |
113 | 113 | $success = parent::insertIntoDB(); |
114 | | - |
| 114 | + |
115 | 115 | if ( $success ) { |
116 | 116 | $contestant = new ContestContestant( array( 'id' => $this->getField( 'contestant_id' ) ) ); |
117 | 117 | $contestant->addToField( 'comments', 1 ); |
118 | 118 | } |
119 | | - |
| 119 | + |
120 | 120 | return $success; |
121 | 121 | } |
122 | | - |
| 122 | + |
123 | 123 | } |
Index: trunk/extensions/Contest/includes/ContestContestant.php |
— | — | @@ -2,69 +2,69 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Class representing a single contest contestant. |
6 | | - * A contestant is a unique user + contest combination. |
7 | | - * |
| 6 | + * A contestant is a unique user + contest combination. |
| 7 | + * |
8 | 8 | * @since 0.1 |
9 | | - * |
| 9 | + * |
10 | 10 | * @file ContestContestant.php |
11 | 11 | * @ingroup Contest |
12 | | - * |
| 12 | + * |
13 | 13 | * @licence GNU GPL v3 or later |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | 16 | class ContestContestant extends ContestDBObject { |
17 | | - |
| 17 | + |
18 | 18 | protected $contest = null; |
19 | | - |
| 19 | + |
20 | 20 | /** |
21 | 21 | * Cached user object, created from the user_id field. |
22 | | - * |
| 22 | + * |
23 | 23 | * @since 0.1 |
24 | 24 | * @var USer |
25 | 25 | */ |
26 | 26 | protected $user = null; |
27 | | - |
| 27 | + |
28 | 28 | /** |
29 | 29 | * Method to get an instance so methods that ought to be static, |
30 | 30 | * but can't be due to PHP 5.2 not having LSB, can be called on |
31 | 31 | * it. This also allows easy identifying of code that needs to |
32 | | - * be changed once PHP 5.3 becomes an acceptable requirement. |
33 | | - * |
| 32 | + * be changed once PHP 5.3 becomes an acceptable requirement. |
| 33 | + * |
34 | 34 | * @since 0.1 |
35 | | - * |
| 35 | + * |
36 | 36 | * @return ContestDBObject |
37 | 37 | */ |
38 | 38 | public static function s() { |
39 | 39 | static $instance = false; |
40 | | - |
| 40 | + |
41 | 41 | if ( $instance === false ) { |
42 | 42 | $instance = new self( array() ); |
43 | 43 | } |
44 | | - |
| 44 | + |
45 | 45 | return $instance; |
46 | 46 | } |
47 | | - |
| 47 | + |
48 | 48 | /** |
49 | 49 | * Get a new instance of the class from an array. |
50 | 50 | * This method ought to be in the basic class and |
51 | 51 | * return a new static(), but this requires LSB/PHP>=5.3. |
52 | | - * |
| 52 | + * |
53 | 53 | * @since 0.1 |
54 | | - * |
| 54 | + * |
55 | 55 | * @param array $data |
56 | 56 | * @param boolean $loadDefaults |
57 | | - * |
| 57 | + * |
58 | 58 | * @return ContestDBObject |
59 | | - */ |
| 59 | + */ |
60 | 60 | public function newFromArray( array $data, $loadDefaults = false ) { |
61 | 61 | return new self( $data, $loadDefaults ); |
62 | 62 | } |
63 | | - |
| 63 | + |
64 | 64 | /** |
65 | 65 | * @see parent::getFieldTypes |
66 | | - * |
| 66 | + * |
67 | 67 | * @since 0.1 |
68 | | - * |
| 68 | + * |
69 | 69 | * @return string |
70 | 70 | */ |
71 | 71 | public function getDBTable() { |
— | — | @@ -73,20 +73,20 @@ |
74 | 74 | |
75 | 75 | /** |
76 | 76 | * @see parent::getFieldTypes |
77 | | - * |
| 77 | + * |
78 | 78 | * @since 0.1 |
79 | | - * |
| 79 | + * |
80 | 80 | * @return string |
81 | 81 | */ |
82 | 82 | protected function getFieldPrefix() { |
83 | 83 | return 'contestant_'; |
84 | 84 | } |
85 | | - |
| 85 | + |
86 | 86 | /** |
87 | 87 | * @see parent::getFieldTypes |
88 | | - * |
| 88 | + * |
89 | 89 | * @since 0.1 |
90 | | - * |
| 90 | + * |
91 | 91 | * @return array |
92 | 92 | */ |
93 | 93 | protected function getFieldTypes() { |
— | — | @@ -95,29 +95,29 @@ |
96 | 96 | 'contest_id' => 'id', |
97 | 97 | 'challenge_id' => 'id', |
98 | 98 | 'user_id' => 'id', |
99 | | - |
| 99 | + |
100 | 100 | 'full_name' => 'str', |
101 | 101 | 'user_name' => 'str', |
102 | 102 | 'email' => 'str', |
103 | | - |
| 103 | + |
104 | 104 | 'country' => 'str', |
105 | 105 | 'volunteer' => 'bool', |
106 | 106 | 'wmf' => 'bool', |
107 | 107 | 'cv' => 'str', |
108 | | - |
| 108 | + |
109 | 109 | 'submission' => 'str', |
110 | | - |
| 110 | + |
111 | 111 | 'rating' => 'float', |
112 | 112 | 'rating_count' => 'int', |
113 | 113 | 'comments' => 'int', |
114 | 114 | ); |
115 | 115 | } |
116 | | - |
| 116 | + |
117 | 117 | /** |
118 | 118 | * @see parent::getDefaults |
119 | | - * |
| 119 | + * |
120 | 120 | * @since 0.1 |
121 | | - * |
| 121 | + * |
122 | 122 | * @return array |
123 | 123 | */ |
124 | 124 | public function getDefaults() { |
— | — | @@ -125,87 +125,87 @@ |
126 | 126 | 'full_name' => '', |
127 | 127 | 'user_name' => '', |
128 | 128 | 'email' => '', |
129 | | - |
| 129 | + |
130 | 130 | 'country' => '', |
131 | 131 | 'volunteer' => false, |
132 | 132 | 'wmf' => false, |
133 | 133 | 'cv' => false, |
134 | | - |
| 134 | + |
135 | 135 | 'submission' => '', |
136 | | - |
| 136 | + |
137 | 137 | 'rating' => 0, |
138 | 138 | 'rating_count' => 0, |
139 | 139 | 'comments' => 0, |
140 | 140 | ); |
141 | 141 | } |
142 | | - |
| 142 | + |
143 | 143 | /** |
144 | 144 | * Gets the contest for this participant. |
145 | | - * |
| 145 | + * |
146 | 146 | * @since 0.1 |
147 | | - * |
| 147 | + * |
148 | 148 | * @param array|string|null $fields The fields to load, null for all fields. |
149 | | - * |
| 149 | + * |
150 | 150 | * @return Contest |
151 | 151 | */ |
152 | 152 | public function getContest( $fields = null ) { |
153 | 153 | if ( !is_null( $this->contest ) ) { |
154 | 154 | return $this->contest; |
155 | 155 | } |
156 | | - |
| 156 | + |
157 | 157 | $contest = Contest::s()->selectRow( $fields, array( 'id' => $this->getField( 'contest_id' ) ) ); |
158 | | - |
| 158 | + |
159 | 159 | if ( is_null( $this->contest ) && is_null( $fields ) ) { |
160 | 160 | $this->contest = $contest; |
161 | 161 | } |
162 | | - |
| 162 | + |
163 | 163 | return $contest; |
164 | 164 | } |
165 | | - |
| 165 | + |
166 | 166 | /** |
167 | 167 | * Sets the contest for this participant. |
168 | | - * |
| 168 | + * |
169 | 169 | * @since 0.1 |
170 | | - * |
| 170 | + * |
171 | 171 | * @param Contest $contest |
172 | 172 | */ |
173 | 173 | public function setContest( Contest $contest ) { |
174 | 174 | $this->contest = $contest; |
175 | 175 | } |
176 | | - |
| 176 | + |
177 | 177 | /** |
178 | 178 | * Returns a list of countries and their corresponding country |
179 | 179 | * codes that can be fed directly into an HTML input. |
180 | | - * |
| 180 | + * |
181 | 181 | * @since 0.1 |
182 | | - * |
| 182 | + * |
183 | 183 | * @param booolean $addEmptyItem |
184 | | - * |
| 184 | + * |
185 | 185 | * @return array |
186 | 186 | */ |
187 | 187 | public static function getCountriesForInput( $addEmptyItem = false ) { |
188 | 188 | $countries = array(); |
189 | | - |
| 189 | + |
190 | 190 | if ( $addEmptyItem ) { |
191 | 191 | $countries[''] = ''; |
192 | 192 | } |
193 | | - |
| 193 | + |
194 | 194 | foreach ( self::getCountries() as $code => $name ) { |
195 | 195 | $countries["$code - $name"] = $code; |
196 | 196 | } |
197 | | - |
| 197 | + |
198 | 198 | return $countries; |
199 | 199 | } |
200 | | - |
| 200 | + |
201 | 201 | /** |
202 | 202 | * Returns a list of ISO 3166-1-alpha-2 country codes (keys) and their corresponding country (values). |
203 | | - * |
| 203 | + * |
204 | 204 | * @since 0.1 |
205 | | - * |
| 205 | + * |
206 | 206 | * @return array |
207 | 207 | */ |
208 | 208 | public static function getCountries() { |
209 | | - return array( |
| 209 | + return array( |
210 | 210 | 'AF' => 'Afghanistan', |
211 | 211 | 'AL' => 'Albania', |
212 | 212 | 'DZ' => 'Algeria', |
— | — | @@ -447,58 +447,58 @@ |
448 | 448 | 'ZW' => 'Zimbabwe' |
449 | 449 | ); |
450 | 450 | } |
451 | | - |
| 451 | + |
452 | 452 | /** |
453 | 453 | * (non-PHPdoc) |
454 | 454 | * @see ContestDBObject::insertIntoDB() |
455 | 455 | */ |
456 | 456 | protected function insertIntoDB() { |
457 | 457 | wfRunHooks( 'ContestBeforeContestantInsert', array( &$this ) ); |
458 | | - |
| 458 | + |
459 | 459 | $success = parent::insertIntoDB(); |
460 | | - |
| 460 | + |
461 | 461 | if ( $success ) { |
462 | 462 | $this->onUserSignup(); |
463 | 463 | } |
464 | | - |
| 464 | + |
465 | 465 | return $success; |
466 | 466 | } |
467 | | - |
| 467 | + |
468 | 468 | /** |
469 | 469 | * Handles successfull user signup for a contest. |
470 | | - * |
| 470 | + * |
471 | 471 | * @since 0.1 |
472 | 472 | */ |
473 | 473 | protected function onUserSignup() { |
474 | 474 | $this->getContest( array( 'id' ) )->addToSubmissionCount( 1 ); |
475 | | - |
| 475 | + |
476 | 476 | $this->getUser()->setOption( 'contest_showtoplink', true ); |
477 | 477 | $this->getUser()->saveSettings(); // TODO: can't we just save this single option instead of everything? |
478 | | - |
| 478 | + |
479 | 479 | $this->sendSignupEmail(); |
480 | | - |
| 480 | + |
481 | 481 | wfRunHooks( 'ContestAfterContestantInsert', array( &$this ) ); |
482 | 482 | } |
483 | | - |
| 483 | + |
484 | 484 | /** |
485 | 485 | * Send the signup email. |
486 | | - * |
| 486 | + * |
487 | 487 | * @since 0.1 |
488 | | - * |
| 488 | + * |
489 | 489 | * @return Status |
490 | 490 | */ |
491 | 491 | public function sendSignupEmail() { |
492 | 492 | global $wgPasswordSender, $wgPasswordSenderName; |
493 | | - |
| 493 | + |
494 | 494 | $title = wfMsg( 'contest-email-signup-title' ); |
495 | 495 | $emailText = ContestUtils::getParsedArticleContent( $this->getContest()->getField( 'signup_email' ) ); |
496 | 496 | $user = $this->getUser(); |
497 | 497 | $sender = $wgPasswordSender; |
498 | 498 | $senderName = $wgPasswordSenderName; |
499 | | - |
| 499 | + |
500 | 500 | wfRunHooks( 'ContestBeforeSignupEmail', array( &$this, &$title, &$emailText, &$user, &$sender, &$senderName ) ); |
501 | | - |
502 | | - return UserMailer::send( |
| 501 | + |
| 502 | + return UserMailer::send( |
503 | 503 | new MailAddress( $user ), |
504 | 504 | new MailAddress( $sender, $senderName ), |
505 | 505 | $title, |
— | — | @@ -507,29 +507,29 @@ |
508 | 508 | 'text/html; charset=ISO-8859-1' |
509 | 509 | ); |
510 | 510 | } |
511 | | - |
| 511 | + |
512 | 512 | /** |
513 | 513 | * Send a reminder email. |
514 | | - * |
| 514 | + * |
515 | 515 | * @since 0.1 |
516 | | - * |
| 516 | + * |
517 | 517 | * @return Status |
518 | 518 | */ |
519 | 519 | public function sendReminderEmail( $emailText, array $params = array() ) { |
520 | 520 | global $wgPasswordSender, $wgPasswordSenderName; |
521 | | - |
| 521 | + |
522 | 522 | if ( !array_key_exists( 'daysLeft', $params ) ) { |
523 | 523 | $params['daysLeft'] = $this->getContest()->getDaysLeft(); |
524 | 524 | } |
525 | | - |
| 525 | + |
526 | 526 | $title = wfMsgExt( 'contest-email-reminder-title', 'parsemag', $params['daysLeft'] ); |
527 | 527 | $user = $this->getUser(); |
528 | 528 | $sender = $wgPasswordSender; |
529 | 529 | $senderName = $wgPasswordSenderName; |
530 | | - |
| 530 | + |
531 | 531 | wfRunHooks( 'ContestBeforeReminderEmail', array( &$this, &$title, &$emailText, &$user, &$sender, &$senderName ) ); |
532 | | - |
533 | | - return UserMailer::send( |
| 532 | + |
| 533 | + return UserMailer::send( |
534 | 534 | new MailAddress( $user ), |
535 | 535 | new MailAddress( $sender, $senderName ), |
536 | 536 | $title, |
— | — | @@ -538,64 +538,64 @@ |
539 | 539 | 'text/html; charset=ISO-8859-1' |
540 | 540 | ); |
541 | 541 | } |
542 | | - |
| 542 | + |
543 | 543 | /** |
544 | 544 | * Update the vote count and avarage vote fields. |
545 | 545 | * This does not write the changes to the database, |
546 | 546 | * if this is required, call writeToDB. |
547 | | - * |
| 547 | + * |
548 | 548 | * @since 0.1 |
549 | 549 | */ |
550 | 550 | public function updateVotes() { |
551 | 551 | $votes = $this->getVotes(); |
552 | | - |
| 552 | + |
553 | 553 | $amount = count( $votes ); |
554 | 554 | $total = 0; |
555 | | - |
| 555 | + |
556 | 556 | foreach ( $votes as /* ContestVote */ $vote ) { |
557 | 557 | $total += $vote->getField( 'value' ); |
558 | 558 | } |
559 | | - |
| 559 | + |
560 | 560 | $this->setField( 'rating_count', $amount ); |
561 | 561 | $this->setField( 'rating', $amount > 0 ? $total / $amount : 0 ); |
562 | 562 | } |
563 | | - |
| 563 | + |
564 | 564 | /** |
565 | 565 | * Returns the user object for this contestant, created |
566 | 566 | * from the user_id field and cached in $this->user. |
567 | | - * |
| 567 | + * |
568 | 568 | * @since 0.1 |
569 | | - * |
| 569 | + * |
570 | 570 | * @return User |
571 | 571 | */ |
572 | 572 | public function getUser() { |
573 | 573 | if ( is_null( $this->user ) ) { |
574 | 574 | $this->user = User::newFromId( $this->getField( 'user_id' ) ); |
575 | 575 | } |
576 | | - |
| 576 | + |
577 | 577 | return $this->user; |
578 | 578 | } |
579 | | - |
| 579 | + |
580 | 580 | /** |
581 | 581 | * Get the votes for this contestant. |
582 | | - * |
| 582 | + * |
583 | 583 | * @since 0.1 |
584 | | - * |
| 584 | + * |
585 | 585 | * @return array of ContestVote |
586 | 586 | */ |
587 | 587 | public function getVotes() { |
588 | 588 | return ContestVote::s()->select( null, array( 'contestant_id' => $this->getId() ) ); |
589 | 589 | } |
590 | | - |
| 590 | + |
591 | 591 | /** |
592 | 592 | * Get the comments for this contestant. |
593 | | - * |
| 593 | + * |
594 | 594 | * @since 0.1 |
595 | | - * |
| 595 | + * |
596 | 596 | * @return array of ContestComment |
597 | 597 | */ |
598 | 598 | public function getComments() { |
599 | 599 | return ContestComment::s()->select( null, array( 'contestant_id' => $this->getId() ) ); |
600 | 600 | } |
601 | | - |
| 601 | + |
602 | 602 | } |
Index: trunk/extensions/Contest/includes/Contest.class.php |
— | — | @@ -2,91 +2,91 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Class representing a single contest. |
6 | | - * |
| 6 | + * |
7 | 7 | * @since 0.1 |
8 | | - * |
| 8 | + * |
9 | 9 | * @file Contest.class.php |
10 | 10 | * @ingroup Contest |
11 | | - * |
| 11 | + * |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | 15 | class Contest extends ContestDBObject { |
16 | | - |
| 16 | + |
17 | 17 | // Constants representing the states a contest can have. |
18 | 18 | const STATUS_DRAFT = 0; |
19 | 19 | const STATUS_ACTIVE = 1; |
20 | 20 | const STATUS_FINISHED = 2; // manually stopped by contest manager |
21 | 21 | const STATUS_EXPIRED = 3; // past configured contest end date |
22 | | - |
| 22 | + |
23 | 23 | /** |
24 | 24 | * List of challenges for this contest. |
25 | 25 | * @see loadChallenges, setChallenges and writeChallengesToDB |
26 | | - * |
| 26 | + * |
27 | 27 | * @since 0.1 |
28 | 28 | * @var array of ContestChallenge |
29 | 29 | */ |
30 | 30 | protected $challenges = null; |
31 | | - |
| 31 | + |
32 | 32 | /** |
33 | 33 | * List of contestants for this contest. |
34 | 34 | * @see loadContestants, setContestants and writeContestantsToDB |
35 | | - * |
| 35 | + * |
36 | 36 | * @since 0.1 |
37 | 37 | * @var array of ContestContestant |
38 | 38 | */ |
39 | 39 | protected $contestants = null; |
40 | | - |
| 40 | + |
41 | 41 | /** |
42 | 42 | * Indicates if the contest was set from non-finished to finished. |
43 | 43 | * This is used to take further action on save of the object. |
44 | | - * |
| 44 | + * |
45 | 45 | * @since 0.1 |
46 | 46 | * @var boolean |
47 | 47 | */ |
48 | 48 | protected $wasSetToFinished = false; |
49 | | - |
| 49 | + |
50 | 50 | /** |
51 | 51 | * Method to get an instance so methods that ought to be static, |
52 | 52 | * but can't be due to PHP 5.2 not having LSB, can be called on |
53 | 53 | * it. This also allows easy identifying of code that needs to |
54 | | - * be changed once PHP 5.3 becomes an acceptable requirement. |
55 | | - * |
| 54 | + * be changed once PHP 5.3 becomes an acceptable requirement. |
| 55 | + * |
56 | 56 | * @since 0.1 |
57 | | - * |
| 57 | + * |
58 | 58 | * @return ContestDBObject |
59 | 59 | */ |
60 | 60 | public static function s() { |
61 | 61 | static $instance = false; |
62 | | - |
| 62 | + |
63 | 63 | if ( $instance === false ) { |
64 | 64 | $instance = new self( array() ); |
65 | 65 | } |
66 | | - |
| 66 | + |
67 | 67 | return $instance; |
68 | 68 | } |
69 | | - |
| 69 | + |
70 | 70 | /** |
71 | | - * Get a new instance of the class from an array. |
| 71 | + * Get a new instance of the class from an array. |
72 | 72 | * This method ought to be in the basic class and |
73 | 73 | * return a new static(), but this requires LSB/PHP>=5.3. |
74 | | - * |
| 74 | + * |
75 | 75 | * @since 0.1 |
76 | | - * |
| 76 | + * |
77 | 77 | * @param array $data |
78 | 78 | * @param boolean $loadDefaults |
79 | | - * |
| 79 | + * |
80 | 80 | * @return ContestDBObject |
81 | | - */ |
| 81 | + */ |
82 | 82 | public function newFromArray( array $data, $loadDefaults = false ) { |
83 | 83 | return new self( $data, $loadDefaults ); |
84 | 84 | } |
85 | | - |
| 85 | + |
86 | 86 | /** |
87 | 87 | * @see parent::getFieldTypes |
88 | | - * |
| 88 | + * |
89 | 89 | * @since 0.1 |
90 | | - * |
| 90 | + * |
91 | 91 | * @return string |
92 | 92 | */ |
93 | 93 | public function getDBTable() { |
— | — | @@ -95,20 +95,20 @@ |
96 | 96 | |
97 | 97 | /** |
98 | 98 | * @see parent::getFieldTypes |
99 | | - * |
| 99 | + * |
100 | 100 | * @since 0.1 |
101 | | - * |
| 101 | + * |
102 | 102 | * @return string |
103 | 103 | */ |
104 | 104 | protected function getFieldPrefix() { |
105 | 105 | return 'contest_'; |
106 | 106 | } |
107 | | - |
| 107 | + |
108 | 108 | /** |
109 | 109 | * @see parent::getFieldTypes |
110 | | - * |
| 110 | + * |
111 | 111 | * @since 0.1 |
112 | | - * |
| 112 | + * |
113 | 113 | * @return array |
114 | 114 | */ |
115 | 115 | protected function getFieldTypes() { |
— | — | @@ -117,23 +117,23 @@ |
118 | 118 | 'name' => 'str', |
119 | 119 | 'status' => 'int', |
120 | 120 | 'end' => 'str', // TS_MW |
121 | | - |
| 121 | + |
122 | 122 | 'rules_page' => 'str', |
123 | 123 | 'opportunities' => 'str', |
124 | 124 | 'intro' => 'str', |
125 | 125 | 'help' => 'str', |
126 | 126 | 'signup_email' => 'str', |
127 | 127 | 'reminder_email' => 'str', |
128 | | - |
| 128 | + |
129 | 129 | 'submission_count' => 'int', |
130 | 130 | ); |
131 | 131 | } |
132 | | - |
| 132 | + |
133 | 133 | /** |
134 | 134 | * @see parent::getDefaults |
135 | | - * |
| 135 | + * |
136 | 136 | * @since 0.1 |
137 | | - * |
| 137 | + * |
138 | 138 | * @return array |
139 | 139 | */ |
140 | 140 | public function getDefaults() { |
— | — | @@ -141,47 +141,47 @@ |
142 | 142 | 'name' => '', |
143 | 143 | 'status' => self::STATUS_DRAFT, |
144 | 144 | 'end' => '', |
145 | | - |
| 145 | + |
146 | 146 | 'rules_page' => 'MediaWiki:Contests/', |
147 | 147 | 'opportunities' => 'MediaWiki:Contests/', |
148 | 148 | 'intro' => 'MediaWiki:Contests/', |
149 | 149 | 'help' => '', |
150 | 150 | 'signup_email' => 'MediaWiki:Contests/', |
151 | 151 | 'reminder_email' => 'MediaWiki:Contests/', |
152 | | - |
| 152 | + |
153 | 153 | 'submission_count' => 0, |
154 | 154 | ); |
155 | 155 | } |
156 | | - |
| 156 | + |
157 | 157 | /** |
158 | 158 | * Gets the message for the provided status. |
159 | | - * |
| 159 | + * |
160 | 160 | * @param Contest::STATUS_ $status |
161 | | - * |
| 161 | + * |
162 | 162 | * @return string |
163 | 163 | */ |
164 | 164 | public static function getStatusMessage( $status ) { |
165 | 165 | static $map = false; |
166 | | - |
| 166 | + |
167 | 167 | if ( $map === false ) { |
168 | 168 | $map = array_flip( self::getStatusMessages() ); |
169 | 169 | } |
170 | | - |
| 170 | + |
171 | 171 | return $map[$status]; |
172 | 172 | } |
173 | | - |
| 173 | + |
174 | 174 | /** |
175 | 175 | * Returns a list of status messages and their corresponding constants. |
176 | | - * |
| 176 | + * |
177 | 177 | * @param boolean $onlySettable Whether to return only messages for modifiable status. |
178 | | - * |
| 178 | + * |
179 | 179 | * @since 0.1 |
180 | | - * |
| 180 | + * |
181 | 181 | * @return array |
182 | 182 | */ |
183 | 183 | public static function getStatusMessages( $onlySettable = false ) { |
184 | 184 | static $map = false; |
185 | | - |
| 185 | + |
186 | 186 | if ( $map === false ) { |
187 | 187 | $map = array( |
188 | 188 | wfMsg( 'contest-status-draft' ) => self::STATUS_DRAFT, |
— | — | @@ -192,11 +192,11 @@ |
193 | 193 | if (!$onlySettable) $map[wfMsg( 'contest-status-expired')] = self::STATUS_EXPIRED; |
194 | 194 | return $map; |
195 | 195 | } |
196 | | - |
| 196 | + |
197 | 197 | /** |
198 | 198 | * Load the challenges from the database. |
199 | 199 | * Any set challenges will be lost. |
200 | | - * |
| 200 | + * |
201 | 201 | * @since 0.1 |
202 | 202 | */ |
203 | 203 | public function loadChallenges() { |
— | — | @@ -205,26 +205,26 @@ |
206 | 206 | array( 'contest_id' => $this->getId() ) |
207 | 207 | ); |
208 | 208 | } |
209 | | - |
| 209 | + |
210 | 210 | /** |
211 | 211 | * Gets the challenges that are part of this contest. |
212 | | - * |
| 212 | + * |
213 | 213 | * @since 0.1 |
214 | | - * |
| 214 | + * |
215 | 215 | * @return array of ContestChallenge |
216 | 216 | */ |
217 | 217 | public function getChallenges( $forceLoad = false ) { |
218 | 218 | if ( is_null( $this->challenges ) || $forceLoad ) { |
219 | 219 | $this->loadChallenges(); |
220 | 220 | } |
221 | | - |
| 221 | + |
222 | 222 | return $this->challenges; |
223 | 223 | } |
224 | | - |
| 224 | + |
225 | 225 | /** |
226 | 226 | * Load the contestants from the database. |
227 | 227 | * Any set contestants will be lost. |
228 | | - * |
| 228 | + * |
229 | 229 | * @since 0.1 |
230 | 230 | */ |
231 | 231 | public function loadContestants() { |
— | — | @@ -233,153 +233,153 @@ |
234 | 234 | array( 'contest_id' => $this->getId() ) |
235 | 235 | ); |
236 | 236 | } |
237 | | - |
| 237 | + |
238 | 238 | /** |
239 | 239 | * Gets the contestants for this contest. |
240 | | - * |
| 240 | + * |
241 | 241 | * @since 0.1 |
242 | | - * |
| 242 | + * |
243 | 243 | * @return array of ContestContestant |
244 | 244 | */ |
245 | 245 | public function getContestants( $forceLoad = false ) { |
246 | 246 | if ( is_null( $this->contestants ) || $forceLoad ) { |
247 | 247 | $this->loadContestants(); |
248 | 248 | } |
249 | | - |
| 249 | + |
250 | 250 | return $this->contestants; |
251 | 251 | } |
252 | | - |
| 252 | + |
253 | 253 | /** |
254 | 254 | * Set the contestants for this contest. |
255 | | - * |
| 255 | + * |
256 | 256 | * @since 0.1 |
257 | | - * |
| 257 | + * |
258 | 258 | * @param array $contestants |
259 | 259 | */ |
260 | 260 | public function setContestants( array /* of ContestContestant */ $contestants ) { |
261 | 261 | $this->contestants = $contestants; |
262 | 262 | } |
263 | | - |
| 263 | + |
264 | 264 | /** |
265 | 265 | * Set the challenges for this contest. |
266 | | - * |
| 266 | + * |
267 | 267 | * @since 0.1 |
268 | | - * |
| 268 | + * |
269 | 269 | * @param array $challenges |
270 | 270 | */ |
271 | 271 | public function setChallenges( array /* of ContestChallenge */ $challenges ) { |
272 | 272 | $this->challenges = $challenges; |
273 | 273 | } |
274 | | - |
| 274 | + |
275 | 275 | /** |
276 | 276 | * (non-PHPdoc) |
277 | 277 | * @see ContestDBObject::writeToDB() |
278 | 278 | */ |
279 | 279 | public function writeToDB() { |
280 | 280 | $success = parent::writeToDB(); |
281 | | - |
| 281 | + |
282 | 282 | if ( $success && $this->wasSetToFinished ) { |
283 | 283 | $this->doFinishActions(); |
284 | 284 | $this->wasSetToFinished = false; |
285 | 285 | } |
286 | | - |
| 286 | + |
287 | 287 | return $success; |
288 | 288 | } |
289 | | - |
| 289 | + |
290 | 290 | /** |
291 | 291 | * Write the contest and all set challenges and participants to the database. |
292 | | - * |
| 292 | + * |
293 | 293 | * @since 0.1 |
294 | | - * |
| 294 | + * |
295 | 295 | * @return boolean Success indicator |
296 | 296 | */ |
297 | 297 | public function writeAllToDB() { |
298 | 298 | $success = self::writeToDB(); |
299 | | - |
| 299 | + |
300 | 300 | if ( $success ) { |
301 | 301 | $success = $this->writeChallengesToDB(); |
302 | 302 | } |
303 | | - |
| 303 | + |
304 | 304 | if ( $success ) { |
305 | 305 | $success = $this->writeContestantsToDB(); |
306 | 306 | } |
307 | | - |
| 307 | + |
308 | 308 | return $success; |
309 | 309 | } |
310 | | - |
| 310 | + |
311 | 311 | /** |
312 | 312 | * Write the challenges to the database. |
313 | | - * |
| 313 | + * |
314 | 314 | * @since 0.1 |
315 | | - * |
| 315 | + * |
316 | 316 | * @return boolean Success indicator |
317 | 317 | */ |
318 | 318 | public function writeChallengesToDB() { |
319 | 319 | if ( is_null( $this->challenges ) || count( $this->challenges ) == 0 ) { |
320 | 320 | return true; |
321 | 321 | } |
322 | | - |
| 322 | + |
323 | 323 | $dbw = wfGetDB( DB_MASTER ); |
324 | 324 | $success = true; |
325 | | - |
| 325 | + |
326 | 326 | $dbw->begin(); |
327 | | - |
| 327 | + |
328 | 328 | foreach ( $this->challenges as /* ContestChallenge */ $challenge ) { |
329 | 329 | $challenge->setField( 'contest_id', $this->getId() ); |
330 | 330 | $success &= $challenge->writeToDB(); |
331 | 331 | } |
332 | | - |
| 332 | + |
333 | 333 | $dbw->commit(); |
334 | | - |
| 334 | + |
335 | 335 | return $success; |
336 | 336 | } |
337 | | - |
| 337 | + |
338 | 338 | /** |
339 | 339 | * Write the contestants to the database. |
340 | | - * |
| 340 | + * |
341 | 341 | * @since 0.1 |
342 | | - * |
| 342 | + * |
343 | 343 | * @return boolean Success indicator |
344 | 344 | */ |
345 | 345 | public function writeContestantsToDB() { |
346 | 346 | if ( is_null( $this->contestants ) || count( $this->contestants ) == 0 ) { |
347 | 347 | return true; |
348 | 348 | } |
349 | | - |
| 349 | + |
350 | 350 | $dbw = wfGetDB( DB_MASTER ); |
351 | 351 | $success = true; |
352 | 352 | $nr = 0; |
353 | | - |
| 353 | + |
354 | 354 | $dbw->begin(); |
355 | | - |
| 355 | + |
356 | 356 | foreach ( $this->contestants as /* ContestContestant */ $contestant ) { |
357 | 357 | $contestant->setField( 'contest_id', $this->getId() ); |
358 | 358 | $success &= $contestant->writeToDB(); |
359 | | - |
| 359 | + |
360 | 360 | if ( ++$nr % 500 == 0 ) { |
361 | 361 | $dbw->commit(); |
362 | 362 | $dbw->begin(); |
363 | 363 | } |
364 | 364 | } |
365 | | - |
| 365 | + |
366 | 366 | $dbw->commit(); |
367 | | - |
| 367 | + |
368 | 368 | return $success; |
369 | 369 | } |
370 | | - |
| 370 | + |
371 | 371 | /** |
372 | 372 | * Add an amount (can be negative) to the total submissions for this contest. |
373 | | - * |
| 373 | + * |
374 | 374 | * @since 0.1 |
375 | | - * |
| 375 | + * |
376 | 376 | * @param integer $amount |
377 | | - * |
| 377 | + * |
378 | 378 | * @return boolean Success indicator |
379 | 379 | */ |
380 | 380 | public function addToSubmissionCount( $amount ) { |
381 | 381 | return parent::addToField( 'submission_count', $amount ); |
382 | 382 | } |
383 | | - |
| 383 | + |
384 | 384 | /** |
385 | 385 | * (non-PHPdoc) |
386 | 386 | * @see ContestDBObject::setField() |
— | — | @@ -389,87 +389,87 @@ |
390 | 390 | && $this->hasField( $name ) && $this->getField( $name ) != self::STATUS_FINISHED ) { |
391 | 391 | $this->wasSetToFinished = true; |
392 | 392 | } |
393 | | - |
| 393 | + |
394 | 394 | parent::setField( $name, $value ); |
395 | 395 | } |
396 | | - |
| 396 | + |
397 | 397 | /** |
398 | 398 | * Remove the contest and all it's linked data from the database. |
399 | | - * |
| 399 | + * |
400 | 400 | * @since 0.1 |
401 | | - * |
| 401 | + * |
402 | 402 | * @return boolean Success indicator |
403 | 403 | */ |
404 | 404 | public function removeAllFromDB() { |
405 | 405 | $condition = array( 'contest_id' => $this->getId() ); |
406 | | - |
| 406 | + |
407 | 407 | $success = ContestChallenge::s()->delete( $condition ); |
408 | | - |
| 408 | + |
409 | 409 | if ( $success ) { |
410 | 410 | $contestantIds = array(); |
411 | | - |
| 411 | + |
412 | 412 | foreach ( ContestContestant::s()->select( 'id', $condition ) as /* ContestContestant */ $contestant ) { |
413 | 413 | $contestantIds[] = $contestant->getId(); |
414 | 414 | } |
415 | | - |
| 415 | + |
416 | 416 | if ( count( $contestantIds ) > 0 ) { |
417 | 417 | $success = ContestComment::s()->delete( array( 'contestant_id' => $contestantIds ) ) && $success; |
418 | 418 | $success = ContestVote::s()->delete( array( 'contestant_id' => $contestantIds ) ) && $success; |
419 | 419 | } |
420 | | - |
| 420 | + |
421 | 421 | $success = ContestContestant::s()->delete( $condition ) && $success; |
422 | 422 | } |
423 | | - |
| 423 | + |
424 | 424 | if ( $success ) { |
425 | 425 | $success = parent::removeFromDB(); |
426 | 426 | } |
427 | | - |
| 427 | + |
428 | 428 | return $success; |
429 | | - } |
430 | | - |
| 429 | + } |
| 430 | + |
431 | 431 | /** |
432 | 432 | * Do all actions that need to be done on contest finish. |
433 | | - * |
| 433 | + * |
434 | 434 | * @since 0.1 |
435 | 435 | */ |
436 | 436 | public function doFinishActions() { |
437 | 437 | // TODO |
438 | 438 | } |
439 | | - |
| 439 | + |
440 | 440 | /** |
441 | 441 | * Gets the amount of time left, in seconds. |
442 | | - * |
| 442 | + * |
443 | 443 | * @since 0.1 |
444 | | - * |
| 444 | + * |
445 | 445 | * @return integer |
446 | 446 | */ |
447 | 447 | public function getTimeLeft() { |
448 | 448 | return wfTimestamp( TS_UNIX, $this->getField( 'end' ) ) - time(); |
449 | 449 | } |
450 | | - |
| 450 | + |
451 | 451 | /** |
452 | 452 | * Gets the amount of days left, rounded up to the nearest integer. |
453 | | - * |
| 453 | + * |
454 | 454 | * @since 0.1 |
455 | | - * |
| 455 | + * |
456 | 456 | * @return integer |
457 | 457 | */ |
458 | 458 | public function getDaysLeft() { |
459 | 459 | return (int)ceil( $this->getTimeLeft() / ( 60 * 60 * 24 ) ); |
460 | 460 | } |
461 | | - |
| 461 | + |
462 | 462 | /* |
463 | | - * Gets the contest status, which is either expired, or whatever the |
| 463 | + * Gets the contest status, which is either expired, or whatever the |
464 | 464 | * contest administrator has manually set it to. Only active contests will |
465 | 465 | * be evaluated for expiry. |
466 | | - * |
| 466 | + * |
467 | 467 | * @return integer status constant |
468 | | - * |
| 468 | + * |
469 | 469 | **/ |
470 | 470 | public function getStatus() { |
471 | | - |
| 471 | + |
472 | 472 | $dbStatus = $this->getField('status'); |
473 | | - |
| 473 | + |
474 | 474 | if ( $dbStatus === self::STATUS_ACTIVE && $this->getTimeLeft() <= 0 ) { |
475 | 475 | return self::STATUS_EXPIRED; |
476 | 476 | } else { |
Index: trunk/extensions/Contest/api/ApiDeleteContest.php |
— | — | @@ -13,47 +13,47 @@ |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | 16 | class ApiDeleteContest extends ApiBase { |
17 | | - |
| 17 | + |
18 | 18 | public function __construct( $main, $action ) { |
19 | 19 | parent::__construct( $main, $action ); |
20 | 20 | } |
21 | | - |
| 21 | + |
22 | 22 | public function execute() { |
23 | 23 | global $wgUser; |
24 | | - |
| 24 | + |
25 | 25 | if ( !$wgUser->isAllowed( 'contestadmin' ) || $wgUser->isBlocked() ) { |
26 | 26 | $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
27 | 27 | } |
28 | | - |
| 28 | + |
29 | 29 | $params = $this->extractRequestParams(); |
30 | | - |
| 30 | + |
31 | 31 | $everythingOk = true; |
32 | | - |
| 32 | + |
33 | 33 | foreach ( $params['ids'] as $id ) { |
34 | 34 | $contest = new Contest( array( 'id' => $id ) ); |
35 | 35 | $everythingOk = $contest->removeAllFromDB() && $everythingOk; |
36 | 36 | } |
37 | | - |
| 37 | + |
38 | 38 | $this->getResult()->addValue( |
39 | 39 | null, |
40 | 40 | 'success', |
41 | 41 | $everythingOk |
42 | 42 | ); |
43 | 43 | } |
44 | | - |
| 44 | + |
45 | 45 | public function needsToken() { |
46 | 46 | return true; |
47 | 47 | } |
48 | | - |
| 48 | + |
49 | 49 | public function getTokenSalt() { |
50 | 50 | $params = $this->extractRequestParams(); |
51 | 51 | return 'deletecontest' . implode( '|', $params['ids'] ); |
52 | 52 | } |
53 | | - |
| 53 | + |
54 | 54 | public function mustBePosted() { |
55 | 55 | return true; |
56 | 56 | } |
57 | | - |
| 57 | + |
58 | 58 | public function getAllowedParams() { |
59 | 59 | return array( |
60 | 60 | 'ids' => array( |
— | — | @@ -64,20 +64,20 @@ |
65 | 65 | 'token' => null, |
66 | 66 | ); |
67 | 67 | } |
68 | | - |
| 68 | + |
69 | 69 | public function getParamDescription() { |
70 | 70 | return array( |
71 | 71 | 'ids' => 'The IDs of the contests to delete', |
72 | 72 | 'token' => 'Edit token, salted with the contest id', |
73 | 73 | ); |
74 | 74 | } |
75 | | - |
| 75 | + |
76 | 76 | public function getDescription() { |
77 | 77 | return array( |
78 | 78 | 'API module for deleting contests.' |
79 | 79 | ); |
80 | 80 | } |
81 | | - |
| 81 | + |
82 | 82 | public function getPossibleErrors() { |
83 | 83 | return array_merge( parent::getPossibleErrors(), array( |
84 | 84 | array( 'missingparam', 'ids' ), |
— | — | @@ -89,10 +89,10 @@ |
90 | 90 | 'api.php?action=deletecontest&ids=42', |
91 | 91 | 'api.php?action=deletecontest&ids=4|2', |
92 | 92 | ); |
93 | | - } |
94 | | - |
| 93 | + } |
| 94 | + |
95 | 95 | public function getVersion() { |
96 | 96 | return __CLASS__ . ': $Id$'; |
97 | | - } |
98 | | - |
| 97 | + } |
| 98 | + |
99 | 99 | } |
Index: trunk/extensions/Contest/api/ApiContestQuery.php |
— | — | @@ -14,28 +14,28 @@ |
15 | 15 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
16 | 16 | */ |
17 | 17 | abstract class ApiContestQuery extends ApiQueryBase { |
18 | | - |
| 18 | + |
19 | 19 | /** |
20 | | - * Returns the class specific info. |
| 20 | + * Returns the class specific info. |
21 | 21 | * * class: name of the ContestDBObject deriving class (ie Contest) |
22 | 22 | * * item: item name (ie contest) |
23 | 23 | * * set: item set name (ie contests) |
24 | | - * |
| 24 | + * |
25 | 25 | * @since 0.1 |
26 | | - * |
| 26 | + * |
27 | 27 | * @return array of string |
28 | 28 | */ |
29 | 29 | protected abstract function getClassInfo(); |
30 | | - |
| 30 | + |
31 | 31 | /** |
32 | 32 | * Returns an instance of the ContestDBObject deriving class. |
33 | 33 | * Once PHP 5.3 becomes an acceptable requirement, we |
34 | 34 | * can get rid of this silly hack and simply return the class |
35 | | - * name (since all methods we need ought to be static in PHP >= 5.3). |
36 | | - * |
| 35 | + * name (since all methods we need ought to be static in PHP >= 5.3). |
| 36 | + * |
37 | 37 | * @since 0.1 |
38 | | - * |
39 | | - * @return ContestDBClass |
| 38 | + * |
| 39 | + * @return ContestDBObject |
40 | 40 | */ |
41 | 41 | protected function getClass() { |
42 | 42 | $className = $this->getClassInfo(); |
— | — | @@ -46,71 +46,71 @@ |
47 | 47 | /** |
48 | 48 | * Get the parameters, find out what the conditions for the query are, |
49 | 49 | * run it, and add the results. |
50 | | - * |
| 50 | + * |
51 | 51 | * @since 0.1 |
52 | 52 | */ |
53 | 53 | public function execute() { |
54 | 54 | $params = $this->getParams(); |
55 | | - |
| 55 | + |
56 | 56 | if ( count( $params['props'] ) > 0 ) { |
57 | 57 | $results = $this->getResults( $params, $this->getConditions( $params ) ); |
58 | 58 | $this->addResults( $params, $results ); |
59 | 59 | } |
60 | 60 | } |
61 | | - |
| 61 | + |
62 | 62 | /** |
63 | 63 | * Get the request parameters, handle the * value for the props param |
64 | 64 | * and remove all params set to null (ie those that are not actually provided). |
65 | | - * |
| 65 | + * |
66 | 66 | * @since 0.1 |
67 | | - * |
| 67 | + * |
68 | 68 | * @return array |
69 | 69 | */ |
70 | 70 | protected function getParams() { |
71 | 71 | // Get the requests parameters. |
72 | 72 | $params = $this->extractRequestParams(); |
73 | | - |
| 73 | + |
74 | 74 | $starPropPosition = array_search( '*', $params['props'] ); |
75 | | - |
| 75 | + |
76 | 76 | if ( $starPropPosition !== false ) { |
77 | 77 | unset( $params['props'][$starPropPosition] ); |
78 | 78 | $params['props'] = array_merge( $params['props'], $this->getClass()->getFieldNames() ); |
79 | 79 | } |
80 | | - |
| 80 | + |
81 | 81 | return array_filter( $params, create_function( '$p', 'return isset( $p );' ) ); |
82 | 82 | } |
83 | | - |
| 83 | + |
84 | 84 | /** |
85 | 85 | * Get the conditions for the query. These will be provided as |
86 | 86 | * regular parameters, together with limit, props, continue, |
87 | 87 | * and possibly others which we need to get rid off. |
88 | | - * |
| 88 | + * |
89 | 89 | * @since 0.1 |
90 | | - * |
| 90 | + * |
91 | 91 | * @param array $params |
92 | | - * |
| 92 | + * |
93 | 93 | * @return array |
94 | 94 | */ |
95 | 95 | protected function getConditions( array $params ) { |
96 | 96 | $conditions = array(); |
97 | | - |
| 97 | + |
98 | 98 | foreach ( $params as $name => $value ) { |
99 | 99 | if ( $this->getClass()->canHasField( $name ) ) { |
100 | 100 | $conditions[$name] = $value; |
101 | 101 | } |
102 | 102 | } |
103 | | - |
| 103 | + |
104 | 104 | return $conditions; |
105 | 105 | } |
106 | | - |
| 106 | + |
107 | 107 | /** |
108 | 108 | * Get the actual results. |
109 | | - * |
| 109 | + * |
110 | 110 | * @since 0.1 |
111 | | - * |
| 111 | + * |
112 | 112 | * @param array $params |
113 | 113 | * @param array $conditions |
114 | | - * |
| 114 | + * |
115 | 115 | * @return array of ContestDBClass |
116 | 116 | */ |
117 | 117 | protected function getResults( array $params, array $conditions ) { |
— | — | @@ -123,19 +123,19 @@ |
124 | 124 | ) |
125 | 125 | ); |
126 | 126 | } |
127 | | - |
| 127 | + |
128 | 128 | /** |
129 | 129 | * Serialize the results and add them to the result object. |
130 | | - * |
| 130 | + * |
131 | 131 | * @since 0.1 |
132 | | - * |
| 132 | + * |
133 | 133 | * @param array $params |
134 | 134 | * @param array $results |
135 | 135 | */ |
136 | 136 | protected function addResults( array $params, array /* of ContestDBObject */ $results ) { |
137 | 137 | $serializedResults = array(); |
138 | 138 | $count = 0; |
139 | | - |
| 139 | + |
140 | 140 | foreach ( $results as $result ) { |
141 | 141 | if ( ++$count > $params['limit'] ) { |
142 | 142 | // We've reached the one extra which shows that |
— | — | @@ -143,43 +143,43 @@ |
144 | 144 | $this->setContinueEnumParameter( 'continue', $result->getId() ); |
145 | 145 | break; |
146 | 146 | } |
147 | | - |
| 147 | + |
148 | 148 | $serializedResults[] = $result->toArray( $params['props'] ); |
149 | 149 | } |
150 | | - |
| 150 | + |
151 | 151 | $this->setIndexedTagNames( $serializedResults ); |
152 | | - $this->addSerializedResults( $serializedResults ); |
| 152 | + $this->addSerializedResults( $serializedResults ); |
153 | 153 | } |
154 | | - |
| 154 | + |
155 | 155 | /** |
156 | 156 | * Set the tag names for formats such as XML. |
157 | | - * |
| 157 | + * |
158 | 158 | * @since 0.1 |
159 | | - * |
| 159 | + * |
160 | 160 | * @param array $serializedResults |
161 | 161 | */ |
162 | 162 | protected function setIndexedTagNames( array &$serializedResults ) { |
163 | 163 | $classInfo = $this->getClassInfo(); |
164 | 164 | $this->getResult()->setIndexedTagName( $serializedResults, $classInfo['item'] ); |
165 | 165 | } |
166 | | - |
| 166 | + |
167 | 167 | /** |
168 | 168 | * Add the serialized results to the result object. |
169 | | - * |
| 169 | + * |
170 | 170 | * @since 0.1 |
171 | | - * |
| 171 | + * |
172 | 172 | * @param array $serializedResults |
173 | 173 | */ |
174 | 174 | protected function addSerializedResults( array $serializedResults ) { |
175 | 175 | $classInfo = $this->getClassInfo(); |
176 | | - |
| 176 | + |
177 | 177 | $this->getResult()->addValue( |
178 | 178 | null, |
179 | 179 | $classInfo['set'], |
180 | 180 | $serializedResults |
181 | 181 | ); |
182 | 182 | } |
183 | | - |
| 183 | + |
184 | 184 | /** |
185 | 185 | * (non-PHPdoc) |
186 | 186 | * @see includes/api/ApiBase#getAllowedParams() |
— | — | @@ -200,7 +200,7 @@ |
201 | 201 | ), |
202 | 202 | 'continue' => null, |
203 | 203 | ); |
204 | | - |
| 204 | + |
205 | 205 | return array_merge( $this->getClass()->getAPIParams(), $params ); |
206 | 206 | } |
207 | 207 | |
— | — | @@ -214,7 +214,7 @@ |
215 | 215 | 'continue' => 'Offset number from where to continue the query', |
216 | 216 | 'limit' => 'Max amount of rows to return', |
217 | 217 | ); |
218 | | - |
| 218 | + |
219 | 219 | return array_merge( $this->getClass()->getFieldDescriptions(), $descs ); |
220 | 220 | } |
221 | 221 | |
— | — | @@ -225,6 +225,6 @@ |
226 | 226 | public function getPossibleErrors() { |
227 | 227 | return array_merge( parent::getPossibleErrors(), array( |
228 | 228 | ) ); |
229 | | - } |
230 | | - |
| 229 | + } |
| 230 | + |
231 | 231 | } |
Index: trunk/extensions/Contest/api/ApiMailContestants.php |
— | — | @@ -13,70 +13,70 @@ |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | 16 | class ApiMailContestants extends ApiBase { |
17 | | - |
| 17 | + |
18 | 18 | public function __construct( $main, $action ) { |
19 | 19 | parent::__construct( $main, $action ); |
20 | 20 | } |
21 | | - |
| 21 | + |
22 | 22 | // TODO |
23 | 23 | public function execute() { |
24 | 24 | global $wgUser; |
25 | | - |
| 25 | + |
26 | 26 | if ( !$wgUser->isAllowed( 'contestadmin' ) || $wgUser->isBlocked() ) { |
27 | 27 | $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
28 | 28 | } |
29 | | - |
| 29 | + |
30 | 30 | $params = $this->extractRequestParams(); |
31 | | - |
| 31 | + |
32 | 32 | $everythingOk = true; |
33 | | - |
| 33 | + |
34 | 34 | $contestIds = is_null( $params['contestids'] ) ? array() : $params['contestids']; |
35 | 35 | $challengeIds = is_null( $params['challengeids'] ) ? array() : $params['challengeids']; |
36 | | - |
| 36 | + |
37 | 37 | if ( !is_null( $params['challengetitles'] ) ) { |
38 | 38 | $challenges = ContestChallenge::s()->select( 'id', array( 'title' => $params['challengetitles'] ) ); |
39 | | - |
| 39 | + |
40 | 40 | if ( $challenges === false ) { |
41 | 41 | // TODO: error |
42 | 42 | } |
43 | | - |
| 43 | + |
44 | 44 | foreach ( $challenges as /* ContestChallenge */ $challenge ) { |
45 | 45 | $challengeIds[] = $challenge->getId(); |
46 | 46 | } |
47 | 47 | } |
48 | | - |
| 48 | + |
49 | 49 | if ( !is_null( $params['contestnames'] ) ) { |
50 | 50 | $contests = Contest::s()->select( 'id', array( 'name' => $params['contestnames'] ) ); |
51 | | - |
| 51 | + |
52 | 52 | if ( $contests === false ) { |
53 | 53 | // TODO: error |
54 | 54 | } |
55 | | - |
| 55 | + |
56 | 56 | foreach ( $contests as /* Contest */ $contest ) { |
57 | 57 | $contestIds[] = $contest->getId(); |
58 | 58 | } |
59 | 59 | } |
60 | | - |
| 60 | + |
61 | 61 | $conditions = array(); |
62 | | - |
| 62 | + |
63 | 63 | if ( count( $contestIds ) > 0 ) { |
64 | 64 | $conditions['contest_id'] = $contestIds; |
65 | 65 | } |
66 | | - |
| 66 | + |
67 | 67 | if ( count( $challengeIds ) > 0 ) { |
68 | 68 | $conditions['challenge_id'] = $challengeIds; |
69 | 69 | } |
70 | | - |
| 70 | + |
71 | 71 | if ( !is_null( $params['ids'] ) && count( $params['ids'] ) > 0 ) { |
72 | 72 | $conditions['id'] = $params['ids']; |
73 | 73 | } |
74 | | - |
| 74 | + |
75 | 75 | $contestants = ContestContestant::s()->select( 'email', $conditions ); |
76 | | - |
| 76 | + |
77 | 77 | if ( $contestants !== false && count( $contestants ) > 0 ) { |
78 | 78 | $setSize = ContestSettings::get( 'reminderJobSize' ); |
79 | 79 | $limit = count( $contestants ) - $setSize; |
80 | | - |
| 80 | + |
81 | 81 | for ( $i = 0; $i <= $limit; $i += $setSize ) { |
82 | 82 | $this->createReminderJob( array_splice( $contestants, $i, $setSize ) ); |
83 | 83 | } |
— | — | @@ -84,13 +84,13 @@ |
85 | 85 | else { |
86 | 86 | $everythingOk = false; |
87 | 87 | } |
88 | | - |
| 88 | + |
89 | 89 | $this->getResult()->addValue( |
90 | 90 | null, |
91 | 91 | 'success', |
92 | 92 | $everythingOk |
93 | 93 | ); |
94 | | - |
| 94 | + |
95 | 95 | if ( $everythingOk ) { |
96 | 96 | $this->getResult()->addValue( |
97 | 97 | null, |
— | — | @@ -99,7 +99,7 @@ |
100 | 100 | ); |
101 | 101 | } |
102 | 102 | } |
103 | | - |
| 103 | + |
104 | 104 | protected function createReminderJob( array /* of ContestContestant */ $contestants ) { |
105 | 105 | $job = new ContestReminderJob( |
106 | 106 | Title::newMainPage(), // WTF does this require a title for?? |
— | — | @@ -108,17 +108,17 @@ |
109 | 109 | 'contestants' => $contestants |
110 | 110 | ) |
111 | 111 | ); |
112 | | - $job->insert(); |
| 112 | + $job->insert(); |
113 | 113 | } |
114 | | - |
| 114 | + |
115 | 115 | public function needsToken() { |
116 | 116 | return true; |
117 | 117 | } |
118 | | - |
| 118 | + |
119 | 119 | public function mustBePosted() { |
120 | 120 | return true; |
121 | 121 | } |
122 | | - |
| 122 | + |
123 | 123 | public function getAllowedParams() { |
124 | 124 | return array( |
125 | 125 | // 'page' => array( |
— | — | @@ -154,7 +154,7 @@ |
155 | 155 | 'token' => null, |
156 | 156 | ); |
157 | 157 | } |
158 | | - |
| 158 | + |
159 | 159 | public function getParamDescription() { |
160 | 160 | return array( |
161 | 161 | // 'page' => 'Name of the page from which to pull content for the email body', |
— | — | @@ -166,14 +166,14 @@ |
167 | 167 | 'token' => 'Edit token', |
168 | 168 | ); |
169 | 169 | } |
170 | | - |
| 170 | + |
171 | 171 | public function getDescription() { |
172 | 172 | return array( |
173 | 173 | 'API module for mailing contestants. Selection criteria will be joined with AND, |
174 | 174 | except for the challange ids/titles and contest ids/names pairs, which will be joined wit OR.' |
175 | 175 | ); |
176 | 176 | } |
177 | | - |
| 177 | + |
178 | 178 | public function getPossibleErrors() { |
179 | 179 | return array_merge( parent::getPossibleErrors(), array( |
180 | 180 | array( 'missingparam', 'ids' ), |
— | — | @@ -188,10 +188,10 @@ |
189 | 189 | 'api.php?action=mailcontestants&contestnames=Weekend of Code', |
190 | 190 | 'api.php?action=mailcontestants&challengetitles=foo|bar|baz', |
191 | 191 | ); |
192 | | - } |
193 | | - |
| 192 | + } |
| 193 | + |
194 | 194 | public function getVersion() { |
195 | 195 | return __CLASS__ . ': $Id$'; |
196 | | - } |
197 | | - |
| 196 | + } |
| 197 | + |
198 | 198 | } |
Index: trunk/extensions/Contest/api/ApiQueryContests.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | 16 | class ApiQueryContests extends ApiContestQuery { |
17 | | - |
| 17 | + |
18 | 18 | /** |
19 | 19 | * (non-PHPdoc) |
20 | 20 | * @see ApiContestQuery::getClassInfo() |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | 'set' => 'contests', |
27 | 27 | ); |
28 | 28 | } |
29 | | - |
| 29 | + |
30 | 30 | public function __construct( $main, $action ) { |
31 | 31 | parent::__construct( $main, $action, 'co' ); |
32 | 32 | } |
— | — | @@ -36,14 +36,14 @@ |
37 | 37 | */ |
38 | 38 | public function execute() { |
39 | 39 | global $wgUser; |
40 | | - |
| 40 | + |
41 | 41 | if ( !$wgUser->isAllowed( 'contestadmin' ) || $wgUser->isBlocked() ) { |
42 | 42 | $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
43 | 43 | } |
44 | 44 | |
45 | 45 | parent::execute(); |
46 | 46 | } |
47 | | - |
| 47 | + |
48 | 48 | /** |
49 | 49 | * (non-PHPdoc) |
50 | 50 | * @see includes/api/ApiBase#getDescription() |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | public function getDescription() { |
53 | 53 | return 'API module for querying contests'; |
54 | 54 | } |
55 | | - |
| 55 | + |
56 | 56 | /** |
57 | 57 | * (non-PHPdoc) |
58 | 58 | * @see includes/api/ApiBase#getExamples() |
— | — | @@ -70,5 +70,5 @@ |
71 | 71 | public function getVersion() { |
72 | 72 | return __CLASS__ . ': $Id$'; |
73 | 73 | } |
74 | | - |
| 74 | + |
75 | 75 | } |
Index: trunk/extensions/Contest/api/ApiQueryChallenges.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | 16 | class ApiQueryChallenges extends ApiContestQuery { |
17 | | - |
| 17 | + |
18 | 18 | /** |
19 | 19 | * (non-PHPdoc) |
20 | 20 | * @see ApiContestQuery::getClassInfo() |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | 'set' => 'challenges', |
27 | 27 | ); |
28 | 28 | } |
29 | | - |
| 29 | + |
30 | 30 | public function __construct( $main, $action ) { |
31 | 31 | parent::__construct( $main, $action, 'ch' ); |
32 | 32 | } |
— | — | @@ -36,14 +36,14 @@ |
37 | 37 | */ |
38 | 38 | public function execute() { |
39 | 39 | global $wgUser; |
40 | | - |
| 40 | + |
41 | 41 | if ( !$wgUser->isAllowed( 'contestadmin' ) || $wgUser->isBlocked() ) { |
42 | 42 | $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
43 | 43 | } |
44 | 44 | |
45 | 45 | parent::execute(); |
46 | 46 | } |
47 | | - |
| 47 | + |
48 | 48 | /** |
49 | 49 | * (non-PHPdoc) |
50 | 50 | * @see includes/api/ApiBase#getDescription() |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | public function getDescription() { |
53 | 53 | return 'API module for querying contest challenges'; |
54 | 54 | } |
55 | | - |
| 55 | + |
56 | 56 | /** |
57 | 57 | * (non-PHPdoc) |
58 | 58 | * @see includes/api/ApiBase#getExamples() |
— | — | @@ -70,5 +70,5 @@ |
71 | 71 | public function getVersion() { |
72 | 72 | return __CLASS__ . ': $Id$'; |
73 | 73 | } |
74 | | - |
| 74 | + |
75 | 75 | } |
Index: trunk/extensions/Contest/api/ApiQueryContestComments.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | 16 | class ApiQueryContestComments extends ApiContestQuery { |
17 | | - |
| 17 | + |
18 | 18 | /** |
19 | 19 | * (non-PHPdoc) |
20 | 20 | * @see ApiContestQuery::getClassInfo() |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | 'set' => 'comments', |
27 | 27 | ); |
28 | 28 | } |
29 | | - |
| 29 | + |
30 | 30 | public function __construct( $main, $action ) { |
31 | 31 | parent::__construct( $main, $action, 'coco' ); |
32 | 32 | } |
— | — | @@ -36,14 +36,14 @@ |
37 | 37 | */ |
38 | 38 | public function execute() { |
39 | 39 | global $wgUser; |
40 | | - |
| 40 | + |
41 | 41 | if ( !$wgUser->isAllowed( 'contestjudge' ) || $wgUser->isBlocked() ) { |
42 | 42 | $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
43 | 43 | } |
44 | 44 | |
45 | 45 | parent::execute(); |
46 | 46 | } |
47 | | - |
| 47 | + |
48 | 48 | /** |
49 | 49 | * (non-PHPdoc) |
50 | 50 | * @see includes/api/ApiBase#getDescription() |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | public function getDescription() { |
53 | 53 | return 'API module for querying contest comments'; |
54 | 54 | } |
55 | | - |
| 55 | + |
56 | 56 | /** |
57 | 57 | * (non-PHPdoc) |
58 | 58 | * @see includes/api/ApiBase#getExamples() |
— | — | @@ -70,5 +70,5 @@ |
71 | 71 | public function getVersion() { |
72 | 72 | return __CLASS__ . ': $Id$'; |
73 | 73 | } |
74 | | - |
| 74 | + |
75 | 75 | } |
Index: trunk/extensions/Contest/api/ApiQueryContestants.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
15 | 15 | */ |
16 | 16 | class ApiQueryContestants extends ApiContestQuery { |
17 | | - |
| 17 | + |
18 | 18 | /** |
19 | 19 | * (non-PHPdoc) |
20 | 20 | * @see ApiContestQuery::getClassInfo() |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | 'set' => 'contestants', |
27 | 27 | ); |
28 | 28 | } |
29 | | - |
| 29 | + |
30 | 30 | public function __construct( $main, $action ) { |
31 | 31 | parent::__construct( $main, $action, 'ct' ); |
32 | 32 | } |
— | — | @@ -36,14 +36,14 @@ |
37 | 37 | */ |
38 | 38 | public function execute() { |
39 | 39 | global $wgUser; |
40 | | - |
| 40 | + |
41 | 41 | if ( !$wgUser->isAllowed( 'contestadmin' ) || $wgUser->isBlocked() ) { |
42 | 42 | $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
43 | 43 | } |
44 | 44 | |
45 | 45 | parent::execute(); |
46 | 46 | } |
47 | | - |
| 47 | + |
48 | 48 | /** |
49 | 49 | * (non-PHPdoc) |
50 | 50 | * @see includes/api/ApiBase#getDescription() |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | public function getDescription() { |
53 | 53 | return 'API module for querying contestants'; |
54 | 54 | } |
55 | | - |
| 55 | + |
56 | 56 | /** |
57 | 57 | * (non-PHPdoc) |
58 | 58 | * @see includes/api/ApiBase#getExamples() |
— | — | @@ -70,5 +70,5 @@ |
71 | 71 | public function getVersion() { |
72 | 72 | return __CLASS__ . ': $Id$'; |
73 | 73 | } |
74 | | - |
| 74 | + |
75 | 75 | } |