r99962 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99961‎ | r99962 | r99963 >
Date:18:48, 16 October 2011
Author:reedy
Status:ok
Tags:
Comment:
Trim trailing whitespace

Fix mixed spaces and tabs

Fix 1 bit of documentation
Modified paths:
  • /trunk/extensions/Contest/Contest.hooks.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiContestQuery.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiDeleteContest.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiMailContestants.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiQueryChallenges.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiQueryContestComments.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiQueryContestants.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiQueryContests.php (modified) (history)
  • /trunk/extensions/Contest/includes/Contest.class.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestChallenge.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestComment.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestContestant.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestDBObject.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestReminderJob.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestUtils.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestVote.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestantPager.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContest.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestPage.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestSignup.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestWelcome.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestant.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContests.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialEditContest.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialMyContests.php (modified) (history)
  • /trunk/extensions/Contest/test/ContestValidationTests.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/test/ContestValidationTests.php
@@ -32,7 +32,7 @@
3333 'https://gitorious.org/statusnet' => true,
3434 'https://gitorious.org/statusnet/mainline/merge_requests/2224' => true,
3535 );
36 -
 36+
3737 foreach ( $tests as $test => $isValdid ) {
3838 if ( $isValdid ) {
3939 $this->assertEquals( true, SpecialMyContests::validateSubmissionField( $test ) );
@@ -48,7 +48,7 @@
4949 */
5050 public function testObjectSelectCount() {
5151 $classes = array( 'Contest', 'ContestChallenge' );
52 -
 52+
5353 foreach ( $classes as $class ) {
5454 $this->assertEquals( count( $class::s()->select() ), $class::s()->count() );
5555 }
Index: trunk/extensions/Contest/Contest.hooks.php
@@ -12,7 +12,7 @@
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 final class ContestHooks {
16 -
 16+
1717 /**
1818 * Schema update to set up the needed database tables.
1919 *
@@ -23,15 +23,13 @@
2424 * @return true
2525 */
2626 public static function onSchemaUpdate( /* DatabaseUpdater */ $updater = null ) {
27 - global $wgDBtype;
28 -
29 - $updater->addExtensionUpdate( array(
 27+ $updater->addExtensionUpdate( array(
3028 'addTable',
3129 'contests',
3230 dirname( __FILE__ ) . '/Contest.sql',
3331 true
3432 ) );
35 -
 33+
3634 $updater->addExtensionUpdate( array(
3735 'addField',
3836 'contests',
@@ -42,41 +40,41 @@
4341
4442 return true;
4543 }
46 -
 44+
4745 /**
4846 * Hook to add PHPUnit test cases.
49 - *
 47+ *
5048 * @since 0.1
51 - *
 49+ *
5250 * @param array $files
53 - *
 51+ *
5452 * @return true
5553 */
5654 public static function registerUnitTests( array &$files ) {
5755 $testDir = dirname( __FILE__ ) . '/test/';
58 -
 56+
5957 $files[] = $testDir . 'ContestValidationTests.php';
60 -
 58+
6159 return true;
6260 }
63 -
 61+
6462 /**
6563 * Called when changing user email address.
6664 * @see https://www.mediawiki.org/wiki/Manual:Hooks/UserSetEmail
67 - *
 65+ *
6866 * Checks if there are any active contests in which the user is participating,
6967 * and if so, updates the email there as well.
70 - *
 68+ *
7169 * @since 0.1
72 - *
 70+ *
7371 * @param User $user
7472 * @param string $email
75 - *
 73+ *
7674 * @return true
7775 */
7876 public static function onUserSetEmail( User $user, &$email ) {
7977 $dbr = wfGetDB( DB_SLAVE );
80 -
 78+
8179 $contestants = $dbr->select(
8280 array( 'contest_contestants', 'contests' ),
8381 array( 'contestant_id' ),
@@ -85,103 +83,103 @@
8684 array(),
8785 array( 'contests' => array( 'INNER JOIN', array( 'contest_id=contestant_contest_id' ) ) )
8886 );
89 -
 87+
9088 $contestantIds = array();
91 -
 89+
9290 foreach ( $contestants as $contestant ) {
9391 $contestantIds[] = $contestant->contestant_id;
9492 }
95 -
 93+
9694 if ( count( $contestantIds ) > 0 ) {
9795 ContestContestant::s()->update(
9896 array( 'email' => $email ),
9997 array( 'id' => $contestantIds )
10098 );
10199 }
102 -
 100+
103101 return true;
104102 }
105 -
 103+
106104 /**
107105 * Called after the personal URLs have been set up, before they are shown.
108106 * @see https://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls
109 - *
 107+ *
110108 * @since 0.1
111 - *
 109+ *
112110 * @param array $personal_urls
113111 * @param Title $title
114 - *
 112+ *
115113 * @return true
116114 */
117115 public static function onPersonalUrls( array &$personal_urls, Title &$title ) {
118116 if ( ContestSettings::get( 'enableTopLink' ) ) {
119117 global $wgUser;
120 -
 118+
121119 // Find the watchlist item and replace it by the my contests link and itself.
122120 if ( $wgUser->isLoggedIn() && $wgUser->getOption( 'contest_showtoplink' ) ) {
123121 $keys = array_keys( $personal_urls );
124122 $watchListLocation = array_search( 'watchlist', $keys );
125123 $watchListItem = $personal_urls[$keys[$watchListLocation]];
126 -
 124+
127125 $url = SpecialPage::getTitleFor( 'MyContests' )->getLinkUrl();
128126 $myContests = array(
129127 'text' => wfMsg( 'contest-toplink' ),
130128 'href' => $url,
131129 'active' => ( $url == $title->getLinkUrl() )
132130 );
133 -
134 - array_splice( $personal_urls, $watchListLocation, 1, array( $myContests, $watchListItem ) );
 131+
 132+ array_splice( $personal_urls, $watchListLocation, 1, array( $myContests, $watchListItem ) );
135133 }
136134 }
137 -
 135+
138136 return true;
139137 }
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+ */
152150 public static function onGetPreferences( User $user, array &$preferences ) {
153151 if ( ContestSettings::get( 'enableTopLink' ) ) {
154152 $preferences['contest_showtoplink'] = array(
155153 'type' => 'toggle',
156154 'label-message' => 'contest-prefs-showtoplink',
157155 'section' => 'contest',
158 - );
 156+ );
159157 }
160158
161159 return true;
162 - }
163 -
 160+ }
 161+
164162 /**
165163 * Used when generating internal and interwiki links in Linker::link(),
166164 * just before the function returns a value.
167165 * @see https://www.mediawiki.org/wiki/Manual:Hooks/LinkEnd
168 - *
 166+ *
169167 * @since 0.1
170 - *
 168+ *
171169 * @param $skin
172170 * @param Title $target
173171 * @param array $options
174172 * @param string $text
175173 * @param array $attribs
176174 * @param $ret
177 - *
 175+ *
178176 * @return true
179177 */
180178 public static function onLinkEnd( $skin, Title $target, array $options, &$text, array &$attribs, &$ret ) {
181179 if ( $GLOBALS['wgContestEmailParse'] ) {
182180 $attribs['href'] = $target->getFullURL();
183181 }
184 -
 182+
185183 return true;
186184 }
187 -
 185+
188186 }
Index: trunk/extensions/Contest/specials/SpecialMyContests.php
@@ -1,43 +1,43 @@
22 <?php
33
44 /**
5 - * List of contests for a user.
6 - *
 5+ * List of contests for a user.
 6+ *
77 * @since 0.1
8 - *
 8+ *
99 * @file SpecialMyContests.php
1010 * @ingroup Contest
11 - *
 11+ *
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 class SpecialMyContests extends SpecialContestPage {
16 -
 16+
1717 protected $submissionState = null;
18 -
 18+
1919 /**
2020 * Constructor.
21 - *
 21+ *
2222 * @since 0.1
2323 */
2424 public function __construct() {
2525 parent::__construct( 'MyContests', 'contestparticipant' );
2626 }
27 -
 27+
2828 /**
2929 * Main method.
30 - *
 30+ *
3131 * @since 0.1
32 - *
 32+ *
3333 * @param string $arg
3434 */
3535 public function execute( $subPage ) {
3636 $subPage = str_replace( '_', ' ', $subPage );
37 -
 37+
3838 if ( !parent::execute( $subPage ) ) {
3939 return;
4040 }
41 -
 41+
4242 if ( $this->getRequest()->wasPosted() ) {
4343 $contestant = ContestContestant::s()->selectRow( null, array( 'id' => $this->getRequest()->getInt( 'wpcontestant-id' ) ) );
4444 $this->showSubmissionPage( $contestant );
@@ -51,29 +51,29 @@
5252 }
5353 }
5454 }
55 -
 55+
5656 /**
5757 * On regular page view, ie no submission and no sub-page,
5858 * display a list of all contests the user is participating in,
5959 * or in case there is only one, redirect them to the submissiom
6060 * UI of it.
61 - *
 61+ *
6262 * @since 0.1
6363 */
6464 protected function displayContestsOverview() {
65 - $contestants = ContestContestant::s()->select(
 65+ $contestants = ContestContestant::s()->select(
6666 array( 'id', 'contest_id', 'challenge_id' ),
6767 array( 'user_id' => $this->getUser()->getId() )
6868 );
69 -
 69+
7070 $contestantCount = count( $contestants );
71 -
 71+
7272 if ( $contestantCount == 0 ) {
7373 $this->getOutput()->addWikiMsg( 'contest-mycontests-no-contests' );
7474 }
7575 else if ( $contestantCount == 1 ) {
7676 $contest = $contestants[0]->getContest( array( 'status', 'name' ) );
77 -
 77+
7878 if ( $contest->getField( 'status' ) == Contest::STATUS_ACTIVE ) {
7979 $this->getOutput()->redirect( $this->getTitle( $contest->getField( 'name' ) )->getLocalURL() );
8080 }
@@ -85,82 +85,82 @@
8686 $this->displayContestsTable( $contestants );
8787 }
8888 }
89 -
 89+
9090 /**
9191 * Displays a list of contests the user participates or participated in,
9292 * together with their user specific choices such as the contest challenge.
93 - *
 93+ *
9494 * @since 0.1
95 - *
 95+ *
9696 * @param array $contestants
9797 */
9898 protected function displayContestsTable( array /* of ContestContestant */ $contestants ) {
9999 $user = $this->getUser();
100 -
 100+
101101 $running = array();
102102 $passed = array();
103103 $contests = array();
104 -
 104+
105105 foreach ( $contestants as $contestant ) {
106106 $contest = $contestant->getContest();
107 -
 107+
108108 if ( $contest->getField( 'status' ) == Contest::STATUS_ACTIVE ) {
109109 $running[] = $contestant;
110110 }
111111 else if ( $contest->getField( 'status' ) == Contest::STATUS_FINISHED ) {
112112 $passed[] = $contestant;
113113 }
114 -
 114+
115115 $contests[$contest->getId()] = $contest;
116116 }
117 -
 117+
118118 if ( count( $running ) > 0 ) {
119119 $this->displayRunningContests( $running, $contests );
120120 }
121 -
 121+
122122 if ( count( $passed ) > 0 ) {
123123 //$this->displayPassedContests( $passed, $contests );
124124 }
125125 }
126 -
 126+
127127 /**
128128 * Display a table with the running (active) contests for this user.
129 - *
 129+ *
130130 * @since 0.1
131 - *
 131+ *
132132 * @param array $contestants
133133 * @param array $contests
134134 */
135135 protected function displayRunningContests( array /* of ContestContestant */ $contestants, array /* Contest */ $contests ) {
136136 $out = $this->getOutput();
137 -
 137+
138138 $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-mycontests-active-header' ) ) );
139139 $out->addHTML( Html::element( 'p', array(), wfMsg( 'contest-mycontests-active-text' ) ) );
140 -
 140+
141141 $out->addHTML( Xml::openElement(
142142 'table',
143143 array( 'class' => 'wikitable sortable' )
144144 ) );
145 -
 145+
146146 $headers = array(
147147 Html::element( 'th', array(), wfMsg( 'contest-mycontests-header-contest' ) ),
148148 Html::element( 'th', array(), wfMsg( 'contest-mycontests-header-challenge' ) ),
149149 );
150 -
 150+
151151 $out->addHTML( '<thead><tr>' . implode( '', $headers ) . '</tr></thead>' );
152 -
 152+
153153 $out->addHTML( '<tbody>' );
154 -
 154+
155155 foreach ( $contestants as $contestant ) {
156156 $contest = $contests[$contestant->getField( 'contest_id' )];
157 -
 157+
158158 $challengeTitle = ContestChallenge::s()->selectRow(
159159 'title',
160160 array( 'id' => $contestant->getField( 'challenge_id' ) )
161161 )->getField( 'title' );
162 -
 162+
163163 $fields = array();
164 -
 164+
165165 $fields[] = Html::rawElement( 'td', array( 'data-sort-value' => $contest->getField( 'name' ) ), Html::rawElement(
166166 'a',
167167 array(
@@ -168,45 +168,45 @@
169169 ),
170170 htmlspecialchars( $contest->getField( 'name' ) )
171171 ) );
172 -
 172+
173173 $fields[] = Html::element( 'td', array(), $challengeTitle );
174 -
 174+
175175 $out->addHTML( '<tr>' . implode( '', $fields ) . '</tr>' );
176176 }
177 -
 177+
178178 $out->addHTML( '</tbody>' );
179179 $out->addHTML( '</table>' );
180180 }
181 -
 181+
182182 /**
183183 * Display a table with the passed (finished) contests for this user.
184 - *
 184+ *
185185 * @since 0.1
186 - *
 186+ *
187187 * @param array $contestants
188188 * @param array $contests
189189 */
190190 protected function displayPassedContests( array /* of ContestContestant */ $contestants, array /* Contest */ $contests ) {
191191 $out = $this->getOutput();
192 -
 192+
193193 $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-mycontests-finished-header' ) ) );
194194 $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-mycontests-finished-text' ) ) );
195 -
 195+
196196 // TODO
197197 }
198 -
 198+
199199 /**
200200 * Handle view requests for the page.
201 - *
 201+ *
202202 * @since 0.1
203 - *
 203+ *
204204 * @param string $contestName
205205 */
206206 protected function handleSubmissionView( $contestName ) {
207207 $out = $this->getOutput();
208 -
 208+
209209 $contest = Contest::s()->selectRow( null, array( 'name' => $contestName ) );
210 -
 210+
211211 if ( $contest === false ) {
212212 $this->showError( 'contest-submission-unknown' );
213213 $out->addHTML( '<br /><br /><br /><br />' );
@@ -226,12 +226,12 @@
227227 }
228228 }
229229 }
230 -
 230+
231231 /**
232232 * Handle page request when the contest is enabled.
233 - *
 233+ *
234234 * @since 0.1
235 - *
 235+ *
236236 * @param Contest $contest
237237 */
238238 protected function handleEnabledPage( Contest $contest ) {
@@ -244,7 +244,7 @@
245245 'user_id' => $this->getUser()->getId()
246246 )
247247 );
248 -
 248+
249249 if ( $contestant === false ) {
250250 $this->getOutput()->redirect( SpecialPage::getTitleFor( 'ContestSignup', $contest->getField( 'name' ) )->getLocalURL() );
251251 }
@@ -253,12 +253,12 @@
254254 $this->showSubmissionPage( $contestant );
255255 }
256256 }
257 -
 257+
258258 /**
259259 * Show the page content.
260 - *
 260+ *
261261 * @since 0.1
262 - *
 262+ *
263263 * @param ContestContestant $contestant
264264 */
265265 protected function showSubmissionPage( ContestContestant $contestant ) {
@@ -275,17 +275,17 @@
276276 && !$this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) {
277277 $this->showError( 'contest-mycontests-sessionfail' );
278278 }
279 -
 279+
280280 $this->getOutput()->setPageTitle( $contestant->getContest()->getField( 'name' ) );
281 -
 281+
282282 $this->getOutput()->addHTML('<div style="clear:both;"></div>');
283283 $this->getOutput()->addWikiMsg( 'contest-submission-header', $contestant->getContest()->getField( 'name' ) );
284 -
 284+
285285 $form = new HTMLForm( $this->getFormFields( $contestant ), $this->getContext() );
286 -
 286+
287287 $form->setSubmitCallback( array( $this, 'handleSubmission' ) );
288288 $form->setSubmitText( wfMsg( 'contest-submission-submit' ) );
289 -
 289+
290290 if( $form->show() ) {
291291 $query = is_null( $this->submissionState ) ? '' : $this->submissionState;
292292 $this->getOutput()->redirect( $this->getTitle( $contestant->getContest()->getField( 'name' ) )->getLocalURL( $query ) );
@@ -294,37 +294,37 @@
295295 $this->getOutput()->addModules( 'contest.special.submission' );
296296 }
297297 }
298 -
 298+
299299 /**
300300 * Handle form submission.
301 - *
 301+ *
302302 * @since 0.1
303 - *
 303+ *
304304 * @return true|array
305305 */
306306 public function handleSubmission( array $data ) {
307307 $user = $this->getUser();
308 -
 308+
309309 $user->setEmail( $data['contestant-email'] );
310310 $user->setRealName( $data['contestant-realname'] );
311311 $user->saveSettings();
312 -
 312+
313313 $contestant = new ContestContestant( array(
314314 'id' => $data['contestant-id'],
315 -
 315+
316316 'full_name' => $data['contestant-realname'],
317317 'email' => $data['contestant-email'],
318 -
 318+
319319 'country' => $data['contestant-country'],
320320 'volunteer' => $data['contestant-volunteer'],
321321 'wmf' => $data['contestant-wmf'],
322322 'cv' => $data['contestant-cv'],
323 -
 323+
324324 'submission' => trim( $data['contestant-submission'] ),
325325 ) );
326 -
 326+
327327 $success = $contestant->writeToDB();
328 -
 328+
329329 if ( $success ) {
330330 if ( trim( $data['contestant-previous-submission'] ) === '' && trim( $data['contestant-submission'] ) !== '' ) {
331331 $this->submissionState = 'added';
@@ -333,33 +333,33 @@
334334 $this->submissionState = 'updated';
335335 }
336336 }
337 -
 337+
338338 return $success;
339339 }
340 -
 340+
341341 /**
342342 * Gets the field definitions for the form.
343 - *
 343+ *
344344 * @since 0.1
345 - *
 345+ *
346346 * @param ContestContestant $contest
347347 */
348348 protected function getFormFields( ContestContestant $contestant ) {
349349 $fields = array();
350 -
 350+
351351 $user = $this->getUser();
352 -
 352+
353353 $fields['contestant-id'] = array(
354354 'type' => 'hidden',
355355 'default' => $contestant->getId(),
356356 'id' => 'contest-id',
357357 );
358 -
 358+
359359 $fields['contestant-previous-submission'] = array(
360360 'type' => 'hidden',
361361 'default' => $contestant->getField( 'submission' ),
362362 );
363 -
 363+
364364 $fields['contestant-submission'] = array(
365365 'class' => 'ContestSubmissionField',
366366 'label-message' => 'contest-submission-submission',
@@ -369,7 +369,7 @@
370370 'value' => $contestant->getField( 'submission' )
371371 )
372372 );
373 -
 373+
374374 $fields['contestant-realname'] = array(
375375 'type' => 'text',
376376 'default' => $user->getRealName(),
@@ -377,7 +377,7 @@
378378 'required' => true,
379379 'validation-callback' => array( __CLASS__, 'validateNameField' )
380380 );
381 -
 381+
382382 $fields['contestant-email'] = array(
383383 'type' => 'email',
384384 'default' => $user->getEmail(),
@@ -385,7 +385,7 @@
386386 'required' => true,
387387 'validation-callback' => array( __CLASS__, 'validateEmailField' ),
388388 );
389 -
 389+
390390 $fields['contestant-country'] = array(
391391 'type' => 'select',
392392 'default' => $contestant->getField( 'country' ),
@@ -393,139 +393,139 @@
394394 'required' => true,
395395 'options' => ContestContestant::getCountriesForInput()
396396 );
397 -
 397+
398398 $fields['contestant-volunteer'] = array(
399399 'type' => 'check',
400400 'default' => $contestant->getField( 'volunteer' ),
401401 'label-message' => 'contest-signup-volunteer',
402402 );
403 -
 403+
404404 $fields['contestant-wmf'] = array(
405405 'type' => 'check',
406406 'default' => $contestant->getField( 'wmf' ),
407407 'label-message' => 'contest-signup-wmf',
408408 );
409 -
 409+
410410 $hasWMF = $contestant->hasField( 'wmf' );
411 -
 411+
412412 $fields['contestant-cv'] = array(
413413 'type' => $hasWMF && $contestant->getField( 'wmf' ) ? 'text' : 'hidden',
414414 'default' => $hasWMF ? $contestant->getField( 'cv' ) : '',
415415 'label-message' => 'contest-signup-cv',
416416 'validation-callback' => array( __CLASS__, 'validateCVField' ),
417417 );
418 -
 418+
419419 return $fields;
420420 }
421 -
 421+
422422 /**
423423 * HTMLForm field validation-callback for name field.
424 - *
 424+ *
425425 * @since 0.1
426 - *
 426+ *
427427 * @param $value String
428428 * @param $alldata Array
429 - *
 429+ *
430430 * @return true|string
431431 */
432432 public static function validateNameField( $value, $alldata = null ) {
433433 if ( strlen( $value ) < 2 ) {
434434 return wfMsg( 'contest-signup-invalid-name' );
435435 }
436 -
 436+
437437 return true;
438438 }
439 -
 439+
440440 /**
441441 * HTMLForm field validation-callback for email field.
442 - *
 442+ *
443443 * @since 0.1
444 - *
 444+ *
445445 * @param $value String
446446 * @param $alldata Array
447 - *
 447+ *
448448 * @return true|string
449449 */
450450 public static function validateEmailField( $value, $alldata = null ) {
451451 if ( !Sanitizer::validateEmail( $value ) ) {
452452 return wfMsg( 'contest-signup-invalid-email' );
453453 }
454 -
 454+
455455 return true;
456456 }
457 -
 457+
458458 /**
459459 * HTMLForm field validation-callback for cv field.
460 - *
 460+ *
461461 * @since 0.1
462 - *
 462+ *
463463 * @param $value String
464464 * @param $alldata Array
465 - *
 465+ *
466466 * @return true|string
467467 */
468468 public static function validateCVField( $value, $alldata = null ) {
469469 if ( trim( $value ) !== '' && filter_var( $value, FILTER_VALIDATE_URL ) === false ) {
470470 return wfMsg( 'contest-signup-invalid-cv' );
471471 }
472 -
 472+
473473 return true;
474474 }
475475
476476 /**
477477 * HTMLForm field validation-callback for the submissiom field.
478478 * Warning: regexes used! o_O
479 - *
 479+ *
480480 * @since 0.1
481 - *
 481+ *
482482 * @param $value String
483483 * @param $alldata Array
484 - *
 484+ *
485485 * @return true|string
486486 */
487487 public static function validateSubmissionField( $value, $alldata = null ) {
488488 $value = trim( $value );
489 -
 489+
490490 if ( $value == '' ) {
491491 return true;
492492 }
493 -
 493+
494494 $allowedPatterns = array(
495495 // GitHub URLs such as https://github.com/JeroenDeDauw/smwcon/tree/f9b26ec4ba1101b1f5d4ef76b7ae6ad3dabfb53b
496496 // '@^https://github\.com/[a-zA-Z0-9-]+/[a-zA-Z0-9_-]+/tree/[a-zA-Z0-9]{40}$@i'
497497 );
498 -
 498+
499499 foreach ( ContestSettings::get( 'submissionDomains' ) as $domain ) {
500500 $allowedPatterns[] = '@^https?://(([a-z0-9]+)\.)?' . str_replace( '.', '\.', $domain ) . '/.*$@i';
501501 }
502 -
 502+
503503 foreach ( $allowedPatterns as $pattern ) {
504504 if ( preg_match( $pattern, $value ) ) {
505505 return true;
506506 }
507507 }
508 -
 508+
509509 return wfMsg( 'contest-submission-invalid-url' );
510510 }
511 -
 511+
512512 }
513513
514514 class ContestSubmissionField extends HTMLFormField {
515 -
 515+
516516 public function getInputHTML( $value ) {
517517 $attribs = array(
518518 'class' => 'contest-submission',
519519 'data-name' => $this->mName
520520 );
521 -
 521+
522522 foreach ( $this->mParams['options'] as $name => $value ) {
523523 $attribs['data-' . $name] = $value;
524524 }
525 -
 525+
526526 return Html::element(
527527 'div',
528528 $attribs
529529 );
530530 }
531 -
 531+
532532 }
Index: trunk/extensions/Contest/specials/SpecialContestWelcome.php
@@ -2,50 +2,50 @@
33
44 /**
55 * Contest landing page for participants.
6 - *
 6+ *
77 * @since 0.1
8 - *
 8+ *
99 * @file SpecialContestWelcome.php
1010 * @ingroup Contest
11 - *
 11+ *
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 class SpecialContestWelcome extends SpecialContestPage {
16 -
 16+
1717 /**
1818 * Constructor.
19 - *
 19+ *
2020 * @since 0.1
2121 */
2222 public function __construct() {
2323 parent::__construct( 'ContestWelcome' );
2424 }
25 -
 25+
2626 /**
2727 * Main method.
28 - *
 28+ *
2929 * @since 0.1
30 - *
 30+ *
3131 * @param string $arg
3232 */
3333 public function execute( $subPage ) {
3434 $subPage = str_replace( '_', ' ', $subPage );
35 -
 35+
3636 if ( !parent::execute( $subPage ) ) {
3737 return;
3838 }
39 -
 39+
4040 $out = $this->getOutput();
41 -
 41+
4242 $contest = Contest::s()->selectRow( null, array( 'name' => $subPage ) );
43 -
 43+
4444 if ( $contest === false ) {
4545 $this->showError( 'contest-welcome-unknown' );
4646 $out->addHTML( '<br /><br /><br /><br />' );
4747 $out->returnToMain();
4848 }
49 - else if ( ( $contest->getStatus() == Contest::STATUS_FINISHED ) ||
 49+ else if ( ( $contest->getStatus() == Contest::STATUS_FINISHED ) ||
5050 ( $contest->getStatus() == Contest::STATUS_EXPIRED ) ) {
5151 $this->showWarning( 'contest-signup-finished' );
5252 $out->addHTML( '<br /><br /><br /><br />' );
@@ -59,12 +59,12 @@
6060 $this->showEnabledPage( $contest );
6161 }
6262 }
63 -
 63+
6464 protected function showEnabledPage( Contest $contest ) {
6565 $out = $this->getOutput();
66 -
 66+
6767 $alreadySignedup = $this->getUser()->isLoggedIn();
68 -
 68+
6969 if ( $alreadySignedup ) {
7070 // Check if the user is already a contestant in this contest.
7171 // If he is, reirect to submission page, else show signup form.
@@ -76,66 +76,66 @@
7777 )
7878 ) !== false;
7979 }
80 -
 80+
8181 if ( $alreadySignedup ) {
8282 $out->redirect( SpecialPage::getTitleFor( 'MyContests', $contest->getField( 'name' ) )->getLocalURL() );
8383 }
8484 else {
8585 $out->setPageTitle( $contest->getField( 'name' ) );
86 -
 86+
8787 $this->showIntro( $contest );
8888 $this->showChallenges( $contest );
8989 $this->showOpportunities( $contest );
9090 $this->showRules( $contest );
91 -
 91+
9292 $out->addModules( 'contest.special.welcome' );
9393 }
9494 }
95 -
 95+
9696 /**
9797 * Show the intro text for this contest.
98 - *
 98+ *
9999 * @since 0.1
100 - *
 100+ *
101101 * @param Contest $contest
102102 */
103103 protected function showIntro( Contest $contest ) {
104104 $this->getOutput()->addWikiText( ContestUtils::getArticleContent( $contest->getField( 'intro' ) ) );
105105 }
106 -
 106+
107107 /**
108108 * Show a list of the challenges part of this contest.
109 - *
 109+ *
110110 * @since 0.1
111 - *
 111+ *
112112 * @param Contest $contest
113113 */
114114 protected function showChallenges( Contest $contest ) {
115115 $this->showNoJSFallback( $contest );
116 -
 116+
117117 $this->getOutput()->addHTML( '<div id="contest-challenges"></div><div style="clear:both"></div>' );
118 -
 118+
119119 $this->addContestJS( $contest );
120120 }
121 -
 121+
122122 /**
123123 * Output the needed JS data.
124 - *
 124+ *
125125 * @since 0.1
126 - *
 126+ *
127127 * @param Contest $contest
128128 */
129129 protected function addContestJS( Contest $contest ) {
130130 $challenges = array();
131 -
 131+
132132 foreach ( $contest->getChallenges() as /* ContestChallenge */ $challenge ) {
133133 $data = $challenge->toArray();
134134 $data['target'] = $this->getSignupLink( $contest->getField( 'name' ), $challenge->getId() );
135135 $challenges[] = $data;
136136 }
137 -
138 - $this->getOutput()->addScript(
139 - Skin::makeVariablesScript(
 137+
 138+ $this->getOutput()->addScript(
 139+ Skin::makeVariablesScript(
140140 array(
141141 'ContestChallenges' => $challenges,
142142 'ContestConfig' => array()
@@ -143,39 +143,39 @@
144144 )
145145 );
146146 }
147 -
 147+
148148 /**
149149 * Output fallback code for people that have JS disabled or have a crappy browser.
150 - *
 150+ *
151151 * @since 0.1
152 - *
 152+ *
153153 * @param Contest $contest
154154 */
155155 protected function showNoJSFallback( Contest $contest ) {
156156 $out = $this->getOutput();
157 -
 157+
158158 $out->addHTML( '<noscript>' );
159159 $out->addHTML( '<p class="errorbox">' . htmlspecialchars( wfMsg( 'contest-welcome-js-off' ) ) . '</p>' );
160160 // TODO?
161161 $out->addHTML( '</noscript>' );
162162 }
163 -
 163+
164164 /**
165165 * Show the opportunities for this contest.
166 - *
 166+ *
167167 * @since 0.1
168 - *
 168+ *
169169 * @param Contest $contest
170170 */
171171 protected function showOpportunities( Contest $contest ) {
172172 $this->getOutput()->addWikiText( ContestUtils::getArticleContent( $contest->getField( 'opportunities' ) ) );
173173 }
174 -
 174+
175175 /**
176176 * Show the rules for this contest.
177 - *
 177+ *
178178 * @since 0.1
179 - *
 179+ *
180180 * @param Contest $contest
181181 */
182182 protected function showRules( Contest $contest ) {
@@ -187,26 +187,26 @@
188188 )
189189 ) );
190190 }
191 -
 191+
192192 /**
193193 * Gets the URL for the signup links.
194194 * When the user has to login, this will be to the login page,
195195 * with a retunrto to the signup page.
196 - *
 196+ *
197197 * @since 0.1
198 - *
 198+ *
199199 * @param string $contestName
200200 * @param integer|false $challengeId
201 - *
 201+ *
202202 * @return string
203203 */
204204 protected function getSignupLink( $contestName, $challengeId = false ) {
205205 if ( $challengeId !== false ) {
206206 $contestName .= '/' . $challengeId;
207207 }
208 -
 208+
209209 $signupTitle = SpecialPage::getTitleFor( 'ContestSignup', $contestName );
210 -
 210+
211211 if ( $this->getUser()->isLoggedIn() ) {
212212 return $signupTitle->getLocalURL();
213213 }
Index: trunk/extensions/Contest/specials/SpecialContestPage.php
@@ -3,31 +3,31 @@
44 /**
55 * Base special page for special pages in the Contest extension,
66 * taking care of some common stuff and providing compatibility helpers.
7 - *
 7+ *
88 * @since 0.1
9 - *
 9+ *
1010 * @file SpecialContestPage.php
1111 * @ingroup Contest
12 - *
 12+ *
1313 * @licence GNU GPL v3 or later
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 abstract class SpecialContestPage extends SpecialPage {
17 -
 17+
1818 public $subPage;
19 -
 19+
2020 /**
2121 * @see SpecialPage::getDescription
22 - *
 22+ *
2323 * @since 0.1
2424 */
2525 public function getDescription() {
2626 return wfMsg( 'special-' . strtolower( $this->getName() ) );
2727 }
28 -
 28+
2929 /**
3030 * Sets headers - this should be called from the execute() method of all derived classes!
31 - *
 31+ *
3232 * @since 0.1
3333 */
3434 public function setHeaders() {
@@ -35,35 +35,35 @@
3636 $out->setArticleRelated( false );
3737 $out->setRobotPolicy( 'noindex,nofollow' );
3838 $out->setPageTitle( $this->getDescription() );
39 - }
40 -
 39+ }
 40+
4141 /**
4242 * Main method.
43 - *
 43+ *
4444 * @since 0.1
45 - *
 45+ *
4646 * @param string $arg
4747 */
4848 public function execute( $subPage ) {
4949 $this->subPage = $subPage;
50 -
 50+
5151 $this->setHeaders();
5252 $this->outputHeader();
53 -
 53+
5454 // If the user is authorized, display the page, if not, show an error.
5555 if ( !$this->userCanExecute( $this->getUser() ) ) {
5656 $this->displayRestrictionError();
5757 return false;
5858 }
59 -
 59+
6060 return true;
6161 }
62 -
 62+
6363 /**
6464 * Show a message in an error box.
65 - *
 65+ *
6666 * @since 0.1
67 - *
 67+ *
6868 * @param string $message
6969 */
7070 protected function showError( $message ) {
@@ -71,12 +71,12 @@
7272 '<p class="visualClear errorbox">' . wfMsgExt( $message, 'parseinline' ) . '</p>'
7373 );
7474 }
75 -
 75+
7676 /**
7777 * Show a message in a warning box.
78 - *
 78+ *
7979 * @since 0.1
80 - *
 80+ *
8181 * @param string $message
8282 */
8383 protected function showWarning( $message ) {
@@ -84,12 +84,12 @@
8585 '<p class="visualClear warningbox">' . wfMsgExt( $message, 'parseinline' ) . '</p>'
8686 );
8787 }
88 -
 88+
8989 /**
9090 * Show a message in a success box.
91 - *
 91+ *
9292 * @since 0.1
93 - *
 93+ *
9494 * @param string $message
9595 */
9696 protected function showSuccess( $message ) {
@@ -97,63 +97,63 @@
9898 '<div class="successbox"><strong><p>' . wfMsgExt( $message, 'parseinline' ) . '</p></strong></div>'
9999 );
100100 }
101 -
 101+
102102 /**
103103 * Get an array of navigation links.
104 - *
 104+ *
105105 * @param string $contestName
106106 * @param User $user
107107 * @param string|false $exclude
108 - *
 108+ *
109109 * @since 0.1
110 - *
 110+ *
111111 * @return array
112112 */
113113 protected static function getNavigationLinks( $contestName, User $user, $exclude = false ) {
114114 $pages = array();
115 -
 115+
116116 $pages['contest-nav-contests'] = array( 'Contests' );
117 -
 117+
118118 if ( $user->isAllowed( 'contestjudge' ) ) {
119119 $pages['contest-nav-contest'] = array( 'Contest', $contestName );
120120 }
121 -
 121+
122122 if ( $user->isAllowed( 'contestadmin' ) ) {
123123 $pages['contest-nav-editcontest'] = array( 'EditContest', $contestName );
124124 }
125 -
 125+
126126 $pages['contest-nav-contestwelcome'] = array( 'ContestWelcome', $contestName );
127 -
 127+
128128 if ( $user->isAllowed( 'contestparticipant' ) ) {
129129 $pages['contest-nav-contestsignup'] = array( 'ContestSignup', $contestName );
130130 }
131 -
 131+
132132 $links = array();
133 -
 133+
134134 foreach ( $pages as $message => $page ) {
135135 $page = (array)$page;
136 -
 136+
137137 if ( $exclude !== false && $page[0] == $exclude ) {
138138 continue;
139139 }
140 -
 140+
141141 $subPage = count( $page ) > 1 ? $page[1] : false;
142 -
 142+
143143 $links[] = Html::element(
144144 'a',
145145 array( 'href' => SpecialPage::getTitleFor( $page[0], $subPage )->getLocalURL() ),
146146 wfMsgExt( $message, 'parseinline', $subPage )
147147 );
148148 }
149 -
 149+
150150 return $links;
151151 }
152 -
 152+
153153 /**
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+ *
156156 * @since 0.1
157 - *
 157+ *
158158 * @param string $contestName
159159 * @param User $user
160160 * @param Language $lang
@@ -163,20 +163,20 @@
164164 $links = self::getNavigationLinks( $contestName, $user, $exclude );
165165 return Html::rawElement( 'p', array(), $lang->pipeList( $links ) );
166166 }
167 -
 167+
168168 /**
169169 * Display navigation links.
170 - *
 170+ *
171171 * @since 0.1
172 - *
 172+ *
173173 * @param string|null $subPage
174174 */
175175 protected function displayNavigation( $subPage = null ) {
176176 if ( is_null( $subPage ) ) {
177177 $subPage = $this->subPage;
178178 }
179 -
 179+
180180 $this->getOutput()->addHTML( self::getNavigation( $subPage, $this->getUser(), $this->getLang(), $this->getName() ) );
181181 }
182 -
 182+
183183 }
Index: trunk/extensions/Contest/specials/SpecialContest.php
@@ -2,49 +2,49 @@
33
44 /**
55 * Contest interface for judges.
6 - *
 6+ *
77 * @since 0.1
8 - *
 8+ *
99 * @file SpecialContest.php
1010 * @ingroup Contest
11 - *
 11+ *
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 class SpecialContest extends SpecialContestPage {
16 -
 16+
1717 /**
1818 * Constructor.
19 - *
 19+ *
2020 * @since 0.1
2121 */
2222 public function __construct() {
2323 parent::__construct( 'Contest', 'contestjudge', false );
2424 }
25 -
 25+
2626 /**
2727 * Main method.
28 - *
 28+ *
2929 * @since 0.1
30 - *
 30+ *
3131 * @param string $arg
3232 */
3333 public function execute( $subPage ) {
3434 $subPage = str_replace( '_', ' ', $subPage );
35 -
 35+
3636 $subPage = explode( '/', $subPage, 2 );
3737 $challengeTitle = count( $subPage ) > 1 ? $subPage[1] : false;
38 -
 38+
3939 $subPage = $subPage[0];
40 -
 40+
4141 if ( !parent::execute( $subPage ) ) {
4242 return;
4343 }
44 -
 44+
4545 $out = $this->getOutput();
46 -
 46+
4747 $contest = Contest::s()->selectRow( null, array( 'name' => $subPage ) );
48 -
 48+
4949 if ( $contest === false ) {
5050 $out->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() );
5151 }
@@ -55,89 +55,89 @@
5656 $this->showContestants( $contest, $challengeTitle );
5757 }
5858 }
59 -
 59+
6060 /**
6161 * Display the general contest info.
62 - *
 62+ *
6363 * @since 0.1
64 - *
 64+ *
6565 * @param Contest $contest
6666 */
6767 protected function showGeneralInfo( Contest $contest ) {
6868 $out = $this->getOutput();
69 -
 69+
7070 $out->addHTML( Html::openElement( 'table', array( 'class' => 'wikitable contest-summary' ) ) );
71 -
 71+
7272 foreach ( $this->getSummaryData( $contest ) as $stat => $value ) {
7373 $out->addHTML( '<tr>' );
74 -
 74+
7575 $out->addHTML( Html::element(
7676 'th',
7777 array( 'class' => 'contest-summary-name' ),
7878 wfMsg( 'contest-contest-' . $stat )
7979 ) );
80 -
 80+
8181 $out->addHTML( Html::element(
8282 'td',
8383 array( 'class' => 'contest-summary-value' ),
8484 $value
8585 ) );
86 -
 86+
8787 $out->addHTML( '</tr>' );
8888 }
89 -
 89+
9090 $out->addHTML( Html::closeElement( 'table' ) );
9191 }
92 -
 92+
9393 /**
9494 * Gets the summary data.
95 - *
 95+ *
9696 * @since 0.1
97 - *
 97+ *
9898 * @param Contest $contest
99 - *
 99+ *
100100 * @return array
101101 */
102102 protected function getSummaryData( Contest $contest ) {
103103 $stats = array();
104 -
 104+
105105 $stats['name'] = $contest->getField( 'name' );
106106 $stats['status'] = Contest::getStatusMessage( $contest->getStatus() );
107107 $stats['submissioncount'] = $this->getLang()->formatNum( $contest->getField( 'submission_count' ) );
108 -
 108+
109109 return $stats;
110110 }
111 -
 111+
112112 /**
113113 * Show a paged list of the contestants foe this contest.
114 - *
 114+ *
115115 * @since 0.1
116 - *
 116+ *
117117 * @param Contest $contest
118118 * @param string|false $challengeTitle
119119 */
120120 protected function showContestants( Contest $contest, $challengeTitle ) {
121121 $out = $this->getOutput();
122 -
 122+
123123 $out->addHTML( Html::element( 'h3', array(), wfMsg( 'contest-contest-contestants' ) ) );
124 -
 124+
125125 $conds = array(
126126 'contestant_contest_id' => $contest->getId()
127127 );
128 -
 128+
129129 if ( $challengeTitle !== false ) {
130130 $challenge = ContestChallenge::s()->selectRow( 'id', array( 'title' => $challengeTitle ) );
131 -
 131+
132132 if ( $challenge !== false ) {
133133 $conds['contestant_challenge_id'] = $challenge->getField( 'id' );
134134 unset( $conds['contestant_contest_id'] ); // Not needed because the challenge implies the context
135135 }
136136 }
137 -
 137+
138138 $out->addWikiMsg( 'contest-contest-contestants-text' );
139 -
 139+
140140 $pager = new ContestantPager( $this, $conds );
141 -
 141+
142142 if ( $pager->getNumRows() ) {
143143 $out->addHTML(
144144 $pager->getNavigationBar() .
@@ -149,5 +149,5 @@
150150 $out->addWikiMsg( 'contest-contest-no-results' );
151151 }
152152 }
153 -
 153+
154154 }
Index: trunk/extensions/Contest/specials/SpecialContestant.php
@@ -2,40 +2,40 @@
33
44 /**
55 * Contest interface for judges.
6 - *
 6+ *
77 * @since 0.1
8 - *
 8+ *
99 * @file SpecialContest.php
1010 * @ingroup Contest
11 - *
 11+ *
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 class SpecialContestant extends SpecialContestPage {
16 -
 16+
1717 /**
1818 * Constructor.
19 - *
 19+ *
2020 * @since 0.1
2121 */
2222 public function __construct() {
2323 parent::__construct( 'Contestant', 'contestjudge', false );
2424 }
25 -
 25+
2626 /**
2727 * Main method.
28 - *
 28+ *
2929 * @since 0.1
30 - *
 30+ *
3131 * @param string $arg
3232 */
3333 public function execute( $subPage ) {
3434 if ( !parent::execute( $subPage ) ) {
3535 return;
3636 }
37 -
 37+
3838 $contestant = ContestContestant::s()->selectRow( null, array( 'id' => (int)$subPage ) );
39 -
 39+
4040 if ( $contestant === false ) {
4141 $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() );
4242 }
@@ -45,145 +45,145 @@
4646 {
4747 $this->handleSubmission( $contestant );
4848 }
49 -
 49+
5050 $this->showPage( $contestant );
5151 }
5252 }
53 -
 53+
5454 /**
5555 * Handle a submission by inserting/updating the vote
5656 * and (optionally) adding the comment.
57 - *
 57+ *
5858 * @since 0.1
59 - *
 59+ *
6060 * @param ContestContestant $contestant
61 - *
 61+ *
6262 * @return boolean Success indicator
6363 */
6464 protected function handleSubmission( ContestContestant $contestant ) {
6565 $success = true;
66 -
 66+
6767 if ( trim( $this->getRequest()->getText( 'new-comment-text' ) ) !== '' ) {
6868 $comment = new ContestComment( array(
6969 'user_id' => $this->getUser()->getId(),
7070 'contestant_id' => $contestant->getId(),
71 -
 71+
7272 'text' => $this->getRequest()->getText( 'new-comment-text' ),
7373 'time' => wfTimestampNow()
7474 ) );
75 -
 75+
7676 $success = $comment->writeToDB();
77 -
 77+
7878 if ( $success ) {
7979 ContestContestant::s()->addToField( 'comments', 1 );
8080 }
8181 }
82 -
 82+
8383 if ( $success && !is_null( $this->getRequest()->getVal( 'contestant-rating' ) ) ) {
8484 $attribs = array(
8585 'value' => $this->getRequest()->getInt( 'contestant-rating' ),
8686 'contestant_id' => $contestant->getId(),
8787 'user_id' => $this->getUser()->getId()
8888 );
89 -
 89+
9090 if ( !is_null( $this->getRequest()->getVal( 'contestant-vote-id' ) ) ) {
9191 $attribs['id'] = $this->getRequest()->getInt( 'contestant-vote-id' );
9292 }
93 -
 93+
9494 $vote = new ContestVote( $attribs );
9595 $success = $vote->writeToDB() && $success;
9696 }
97 -
 97+
9898 return $success;
9999 }
100 -
 100+
101101 /**
102102 * Show the actual page, conisting of the navigation, the summary and
103103 * the rating and voting controls.
104 - *
 104+ *
105105 * @since 0.1
106 - *
 106+ *
107107 * @param ContestContestant $contestant
108108 */
109109 protected function showPage( ContestContestant $contestant ) {
110110 global $wgScript;
111111 $out = $this->getOutput();
112 -
 112+
113113 $out->setPageTitle( wfMsgExt(
114114 'contest-contestant-title',
115115 'parseinline',
116116 $contestant->getField( 'id' ),
117117 $contestant->getContest()->getField( 'name' )
118118 ) );
119 -
 119+
120120 $this->displayNavigation( str_replace( ' ', '_', $contestant->getContest()->getField( 'name' ) ) );
121 -
 121+
122122 $this->showGeneralInfo( $contestant );
123 -
 123+
124124 $out->addHTML( '<form method="post" action="' . htmlspecialchars( $wgScript ) . '">' );
125125 $out->addHTML( Html::hidden( 'title', $this->getTitle( $this->subPage )->getPrefixedDBkey() ) );
126126 $out->addHTML( Html::hidden( 'wpEditToken', $this->getUser()->editToken() ) );
127 -
 127+
128128 $this->showRating( $contestant );
129129 $this->showComments( $contestant );
130 -
 130+
131131 $out->addHTML( '</form>' );
132 -
 132+
133133 $out->addModules( 'contest.special.contestant' );
134134 }
135 -
 135+
136136 /**
137137 * Display the general contestant info.
138 - *
 138+ *
139139 * @since 0.1
140 - *
 140+ *
141141 * @param ContestContestant $contestant
142142 */
143143 protected function showGeneralInfo( ContestContestant $contestant ) {
144144 $out = $this->getOutput();
145 -
 145+
146146 $out->addHTML( Html::openElement( 'table', array( 'class' => 'wikitable contestant-summary' ) ) );
147 -
 147+
148148 foreach ( $this->getSummaryData( $contestant ) as $stat => $value ) {
149149 $out->addHTML( '<tr>' );
150 -
 150+
151151 $out->addHTML( Html::element(
152152 'th',
153153 array( 'class' => 'contestant-summary-name' ),
154154 wfMsg( 'contest-contestant-header-' . $stat )
155155 ) );
156 -
 156+
157157 $out->addHTML( Html::rawElement(
158158 'td',
159159 array( 'class' => 'contestant-summary-value' ),
160160 $value
161161 ) );
162 -
 162+
163163 $out->addHTML( '</tr>' );
164164 }
165 -
 165+
166166 $out->addHTML( Html::closeElement( 'table' ) );
167167 }
168 -
 168+
169169 /**
170170 * Gets the summary data.
171171 * Values are escaped.
172 - *
 172+ *
173173 * @since 0.1
174 - *
 174+ *
175175 * @param ContestContestant $contestant
176 - *
 176+ *
177177 * @return array
178178 */
179179 protected function getSummaryData( ContestContestant $contestant ) {
180180 $stats = array();
181 -
 181+
182182 $stats['id'] = htmlspecialchars( $contestant->getField( 'id' ) );
183183 $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' ) );
186186 $stats['challenge'] = htmlspecialchars( $challengeTitles[$contestant->getField( 'challenge_id' )] );
187 -
 187+
188188 if ( $contestant->getField( 'submission' ) === '' ) {
189189 $stats['submission'] = htmlspecialchars( wfMsg( 'contest-contestant-notsubmitted' ) );
190190 }
@@ -194,58 +194,58 @@
195195 wfMsg( 'contest-contestant-submission-url' )
196196 ) . '</b>';
197197 }
198 -
 198+
199199 $countries = ContestContestant::getCountries();
200200 $stats['country'] = htmlspecialchars( $countries[$contestant->getField( 'country' )] );
201 -
 201+
202202 $stats['wmf'] = htmlspecialchars( wfMsg( 'contest-contestant-' . ( $contestant->getField( 'wmf' ) ? 'yes' : 'no' ) ) );
203203 $stats['volunteer'] = htmlspecialchars( wfMsg( 'contest-contestant-' . ( $contestant->getField( 'volunteer' ) ? 'yes' : 'no' ) ) );
204 -
 204+
205205 $stats['rating'] = htmlspecialchars( wfMsgExt(
206206 'contest-contestant-rating',
207207 'parsemag',
208208 $this->getLang()->formatNum( $contestant->getField( 'rating' ) ),
209209 $this->getLang()->formatNum( $contestant->getField( 'rating_count' ) )
210210 ) );
211 -
 211+
212212 $stats['comments'] = htmlspecialchars( $this->getLang()->formatNum( $contestant->getField( 'comments' ) ) );
213 -
 213+
214214 return $stats;
215215 }
216 -
 216+
217217 /**
218218 * Display the current rating the judge gave if any and a control to
219219 * (re)-rate.
220 - *
 220+ *
221221 * @since 0.1
222 - *
 222+ *
223223 * @param ContestContestant $contestant
224224 */
225225 protected function showRating( ContestContestant $contestant ) {
226226 $out = $this->getOutput();
227 -
 227+
228228 $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-contestant-rate' ) ) );
229 -
 229+
230230 $vote = ContestVote::s()->selectRow(
231231 array( 'value', 'id' ),
232232 array( 'user_id' => $this->getUser()->getId(), 'contestant_id' => $contestant->getId() )
233233 );
234 -
 234+
235235 if ( $vote === false ) {
236236 $message = wfMsg( 'contest-contestant-not-voted' );
237237 }
238238 else {
239239 $message = wfMsgExt(
240240 'contest-contestant-voted',
241 - 'parsemag',
 241+ 'parsemag',
242242 $this->getLang()->formatNum( $vote->getField( 'value' ) )
243243 );
244 -
 244+
245245 $out->addHTML( Html::hidden( 'contestant-vote-id', $vote->getId() ) );
246 - }
247 -
 246+ }
 247+
248248 $out->addHTML( Html::element( 'p', array(), $message ) );
249 -
 249+
250250 foreach ( ContestSettings::get( 'voteValues' ) as $value ) {
251251 $attribs = array(
252252 'type' => 'radio',
@@ -253,11 +253,11 @@
254254 'name' => 'contestant-rating',
255255 'id' => 'contestant-rating-' . $value
256256 );
257 -
 257+
258258 if ( $vote !== false && $value == $vote->getField( 'value' ) ) {
259259 $attribs['checked'] = 'checked';
260260 }
261 -
 261+
262262 $out->addHTML(
263263 Html::element(
264264 'input',
@@ -270,52 +270,52 @@
271271 )
272272 );
273273 }
274 -
 274+
275275 }
276276
277277 /**
278278 * Show the comments and a control to add additional ones.
279 - *
 279+ *
280280 * @since 0.1
281 - *
 281+ *
282282 * @param ContestContestant $contestant
283283 */
284284 protected function showComments( ContestContestant $contestant ) {
285285 $out = $this->getOutput();
286 -
 286+
287287 $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-contestant-comments' ) ) );
288 -
 288+
289289 $out->addHTML( '<div class="contestant-comments">' );
290 -
 290+
291291 foreach ( $contestant->getComments() as /* ContestComment */ $comment ) {
292292 $out->addHTML( $this->getCommentHTML( $comment ) );
293293 }
294 -
 294+
295295 $out->addHTML( '</div>' );
296 -
 296+
297297 $out->addHTML(
298298 '<div class="contestant-new-comment">
299299 <textarea cols="40" rows="10" name="new-comment-text"></textarea>
300300 </div>'
301301 );
302 -
 302+
303303 $out->addHTML( Html::input( 'submitChanges', wfMsg( 'contest-contestant-submit' ), 'submit' ) );
304304 }
305 -
 305+
306306 /**
307307 * Get the HTML for a single comment.
308 - *
 308+ *
309309 * @since 0.1
310 - *
 310+ *
311311 * @param ContestComment $comment
312 - *
 312+ *
313313 * @return string
314314 */
315315 protected function getCommentHTML( ContestComment $comment ) {
316316 $user = User::newFromId( $comment->getField( 'user_id' ) );
317 -
 317+
318318 $htmlId = 'c' . $comment->getId();
319 -
 319+
320320 $html = Html::rawElement(
321321 'div',
322322 array( 'class' => 'contestant-comment-meta' ),
@@ -333,13 +333,13 @@
334334 Linker::userToolLinks( $comment->getField( 'user_id' ), $user->getName() )
335335 ) . '&#160;&#160;&#160;' . htmlspecialchars( $this->getLang()->timeanddate( $comment->getField( 'time' ), true ) )
336336 );
337 -
 337+
338338 $html .= Html::rawElement(
339339 'div',
340340 array( 'class' => 'contestant-comment-text mw-content-' . $this->getLang()->getDir() . '' ),
341341 $this->getOutput()->parse( $comment->getField( 'text' ) )
342342 );
343 -
 343+
344344 return Html::rawElement(
345345 'div',
346346 array(
@@ -349,5 +349,5 @@
350350 $html
351351 );
352352 }
353 -
 353+
354354 }
Index: trunk/extensions/Contest/specials/SpecialContests.php
@@ -1,99 +1,99 @@
22 <?php
33
44 /**
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+ *
77 * @since 0.1
8 - *
 8+ *
99 * @file SpecialContests.php
1010 * @ingroup Contest
11 - *
 11+ *
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 class SpecialContests extends SpecialContestPage {
16 -
 16+
1717 /**
1818 * Constructor.
19 - *
 19+ *
2020 * @since 0.1
2121 */
2222 public function __construct() {
2323 parent::__construct( 'Contests' );
2424 }
25 -
 25+
2626 /**
2727 * Returns if the user can access the page or not.
28 - *
 28+ *
2929 * @return boolean
3030 */
3131 protected function userCanAccess() {
3232 $user = $this->getUser();
33 - return
 33+ return
3434 ( $user->isAllowed( 'contestadmin' ) || $user->isAllowed( 'contestjudge' ) )
3535 && !$user->isBlocked();
3636 }
37 -
 37+
3838 /**
3939 * This page is unlisted because the only way to access it is though a contest
4040 * landing page.
41 - *
 41+ *
4242 * @return false|boolean
4343 */
4444 public function isListed() {
4545 return $this->userCanAccess();
4646 }
47 -
 47+
4848 /**
4949 * Main method.
50 - *
 50+ *
5151 * @since 0.1
52 - *
 52+ *
5353 * @param string $arg
5454 */
5555 public function execute( $subPage ) {
5656 $subPage = str_replace( '_', ' ', $subPage );
57 -
 57+
5858 if ( !parent::execute( $subPage ) ) {
5959 return;
6060 }
61 -
 61+
6262 $user = $this->getUser();
63 -
 63+
6464 if ( !$this->userCanAccess() ) {
6565 $this->displayRestrictionError();
6666 }
67 -
 67+
6868 if ( $user->isAllowed( 'contestadmin' ) ) {
6969 $this->displayAddNewControl();
7070 }
71 -
 71+
7272 $this->displayContests();
7373 }
74 -
 74+
7575 /**
7676 * Displays the contests.
77 - *
 77+ *
7878 * @since 0.1
7979 */
8080 protected function displayContests() {
8181 $contests = Contest::s()->select( array( 'id', 'name', 'status', 'end', 'submission_count' ) );
82 -
 82+
8383 if ( count( $contests ) > 0 ) {
8484 $this->displayContestsTable( $contests );
8585 }
86 -
 86+
8787 $this->getOutput()->addModules( 'ext.contest.special.contests' );
8888 }
89 -
 89+
9090 /**
9191 * Displays a small form to add a new campaign.
92 - *
 92+ *
9393 * @since 0.1
9494 */
9595 protected function displayAddNewControl() {
9696 $out = $this->getOutput();
97 -
 97+
9898 $out->addHTML( Html::openElement(
9999 'form',
100100 array(
@@ -101,66 +101,66 @@
102102 'action' => SpecialPage::getTitleFor( 'EditContest' )->getLocalURL(),
103103 )
104104 ) );
105 -
 105+
106106 $out->addHTML( '<fieldset>' );
107 -
 107+
108108 $out->addHTML( '<legend>' . htmlspecialchars( wfMsg( 'contest-special-addnew' ) ) . '</legend>' );
109 -
 109+
110110 $out->addHTML( Html::element( 'p', array(), wfMsg( 'contest-special-namedoc' ) ) );
111 -
 111+
112112 $out->addHTML( Html::element( 'label', array( 'for' => 'newcontest' ), wfMsg( 'contest-special-newname' ) ) );
113 -
 113+
114114 $out->addHTML( '&#160;' . Html::input( 'newcontest' ) . '&#160;' );
115 -
 115+
116116 $out->addHTML( Html::input(
117117 'addnewcontest',
118118 wfMsg( 'contest-special-add' ),
119119 'submit'
120120 ) );
121 -
 121+
122122 $out->addHTML( Html::hidden( 'newEditToken', $this->getUser()->editToken() ) );
123 -
 123+
124124 $out->addHTML( '</fieldset></form>' );
125125 }
126 -
 126+
127127 /**
128128 * Displays a list of all contests.
129 - *
 129+ *
130130 * @since 0.1
131 - *
 131+ *
132132 * @param array $contests
133133 */
134134 protected function displayContestsTable( array /* of Contest */ $contests ) {
135135 $user = $this->getUser();
136136 $out = $this->getOutput();
137 -
 137+
138138 $out->addHTML( Html::element( 'h2', array( 'class' => 'contests-title' ), wfMsg( 'contest-special-existing' ) ) );
139 -
 139+
140140 $out->addHTML( Xml::openElement(
141141 'table',
142142 array( 'class' => 'wikitable sortable contests-table' )
143143 ) );
144 -
 144+
145145 $headers = array(
146146 Html::element( 'th', array(), wfMsg( 'contest-special-name' ) ),
147147 Html::element( 'th', array(), wfMsg( 'contest-special-status' ) ),
148148 Html::element( 'th', array(), wfMsg( 'contest-special-submissioncount' ) )
149149 );
150 -
 150+
151151 $headers[] = Html::element( 'th', array( 'class' => 'unsortable' ) );
152 -
 152+
153153 // if ( $user->isAllowed( 'contestadmin' ) ) {
154154 // $headers[] = Html::element( 'th', array( 'class' => 'unsortable' ), wfMsg( 'contest-special-edit' ) );
155155 // $headers[] = Html::element( 'th', array( 'class' => 'unsortable' ), wfMsg( 'contest-special-delete' ) );
156156 // }
157 -
 157+
158158 $out->addHTML( '<thead><tr>' . implode( '', $headers ) . '</tr></thead>' );
159 -
 159+
160160 $out->addHTML( '<tbody>' );
161 -
 161+
162162 foreach ( $contests as $contest ) {
163163 $fields = array();
164 -
 164+
165165 if ( $user->isAllowed( 'contestparticipant' ) ) {
166166 $name = Html::element(
167167 'a',
@@ -179,21 +179,21 @@
180180 array( 'data-sort-value' => $contest->getField( 'name' ) ),
181181 $name
182182 );
183 -
 183+
184184 $fields[] = Html::element(
185185 'td',
186186 array( 'data-sort-value' => $contest->getStatus() ),
187187 Contest::getStatusMessage( $contest->getStatus() )
188188 );
189 -
 189+
190190 $fields[] = Html::element(
191191 'td',
192192 array(),
193193 $this->getLang()->formatNum( $contest->getField( 'submission_count' ) )
194194 );
195 -
 195+
196196 $links = array();
197 -
 197+
198198 if ( $user->isAllowed( 'contestjudge' ) ) {
199199 $links[] = Html::element(
200200 'a',
@@ -203,7 +203,7 @@
204204 wfMsg( 'contest-nav-contest' )
205205 );
206206 }
207 -
 207+
208208 if ( $user->isAllowed( 'contestadmin' ) ) {
209209 $links[] = Html::element(
210210 'a',
@@ -212,7 +212,7 @@
213213 ),
214214 wfMsg( 'contest-special-edit' )
215215 );
216 -
 216+
217217 $links[] = Html::element(
218218 'a',
219219 array(
@@ -224,7 +224,7 @@
225225 wfMsg( 'contest-special-delete' )
226226 );
227227 }
228 -
 228+
229229 $links[] = Html::element(
230230 'a',
231231 array(
@@ -232,7 +232,7 @@
233233 ),
234234 wfMsg( 'contest-nav-contestwelcome' )
235235 );
236 -
 236+
237237 if ( $user->isAllowed( 'contestparticipant' ) ) {
238238 $links[] = Html::element(
239239 'a',
@@ -242,20 +242,20 @@
243243 wfMsg( 'contest-nav-contestsignup' )
244244 );
245245 }
246 -
 246+
247247 $fields[] = Html::rawElement(
248248 'td',
249249 array(),
250250 $this->getLang()->pipeList( $links )
251251 );
252 -
 252+
253253 $out->addHTML( '<tr>' . implode( '', $fields ) . '</tr>' );
254254 }
255 -
 255+
256256 $out->addHTML( '</tbody>' );
257257 $out->addHTML( '</table>' );
258 -
 258+
259259 $out->addModules( 'contest.special.contests' );
260 - }
261 -
 260+ }
 261+
262262 }
Index: trunk/extensions/Contest/specials/SpecialContestSignup.php
@@ -2,40 +2,40 @@
33
44 /**
55 * Contest signup interface for participants.
6 - *
 6+ *
77 * @since 0.1
8 - *
 8+ *
99 * @file SpecialContestSignup.php
1010 * @ingroup Contest
11 - *
 11+ *
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 class SpecialContestSignup extends SpecialContestPage {
16 -
 16+
1717 /**
1818 * Constructor.
19 - *
 19+ *
2020 * @since 0.1
2121 */
2222 public function __construct() {
2323 parent::__construct( 'ContestSignup' );
2424 }
25 -
 25+
2626 /**
2727 * Main method.
28 - *
 28+ *
2929 * @since 0.1
30 - *
 30+ *
3131 * @param string $arg
3232 */
3333 public function execute( $subPage ) {
3434 $subPage = str_replace( '_', ' ', $subPage );
35 -
 35+
3636 if ( !parent::execute( $subPage ) ) {
3737 return;
3838 }
39 -
 39+
4040 if ( $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) {
4141 $this->showSignupForm( Contest::s()->selectRow( null, array( 'id' => $this->getRequest()->getInt( 'wpcontest-id' ) ) ) );
4242 }
@@ -47,7 +47,7 @@
4848 /**
4949 * This page is unlisted because the only way to access it is though a contest
5050 * landing page.
51 - *
 51+ *
5252 * @return false|boolean
5353 */
5454 public function isListed() {
@@ -56,51 +56,51 @@
5757
5858 /**
5959 * Handle form submission.
60 - *
 60+ *
6161 * @since 0.1
62 - *
 62+ *
6363 * @return true|array
6464 */
6565 public function handleSubmission( array $data ) {
6666 $user = $this->getUser();
67 -
 67+
6868 $user->setEmail( $data['contestant-email'] );
6969 $user->setRealName( $data['contestant-realname'] );
7070 $user->saveSettings();
71 -
 71+
7272 $contestant = new ContestContestant( array(
7373 'contest_id' => $data['contest-id'],
7474 'user_id' => $user->getId(),
7575 'challenge_id' => $data['contestant-challengeid'],
76 -
 76+
7777 'full_name' => $data['contestant-realname'],
7878 'user_name' => $user->getName(),
7979 'email' => $data['contestant-email'],
80 -
 80+
8181 'country' => $data['contestant-country'],
8282 'volunteer' => $data['contestant-volunteer'],
8383 'wmf' => $data['contestant-wmf'],
8484 ) );
85 -
 85+
8686 return $contestant->writeToDB();
8787 }
88 -
 88+
8989 /**
9090 * Show the page.
91 - *
 91+ *
9292 * @since 0.1
93 - *
 93+ *
9494 * @param string $subPage
9595 */
9696 protected function showPage( $subPage ) {
9797 $out = $this->getOutput();
98 -
 98+
9999 $subPage = explode( '/', $subPage );
100100 $contestName = $subPage[0];
101101 $challengeId = count( $subPage ) > 1 ? $subPage[1] : false;
102 -
 102+
103103 $contest = Contest::s()->selectRow( null, array( 'name' => $contestName ) );
104 -
 104+
105105 if ( $contest === false ) {
106106 $this->showError( 'contest-signup-unknown' );
107107 $out->addHTML( '<br /><br /><br /><br />' );
@@ -109,34 +109,34 @@
110110 else {
111111 switch ( $contest->getStatus() ) {
112112 case Contest::STATUS_ACTIVE:
113 - $this->showEnabledPage( $contest, $challengeId );
 113+ $this->showEnabledPage( $contest, $challengeId );
114114 break;
115115 case Contest::STATUS_DRAFT:
116116 $this->showWarning( 'contest-signup-draft' );
117117 $out->addHTML( '<br /><br /><br /><br />' );
118 - $out->returnToMain();
 118+ $out->returnToMain();
119119 break;
120120 case Contest::STATUS_FINISHED:
121121 case Contest::STATUS_EXPIRED:
122122 $this->showWarning( 'contest-signup-finished' );
123123 $out->addHTML( '<br /><br /><br /><br />' );
124 - $out->returnToMain();
 124+ $out->returnToMain();
125125 break;
126126 }
127127 }
128128 }
129 -
 129+
130130 /**
131131 * Handle page request when the contest is enabled.
132 - *
 132+ *
133133 * @since 0.1
134 - *
 134+ *
135135 * @param Contest $contest
136136 * @param integer|false $challengeId
137137 */
138138 protected function showEnabledPage( Contest $contest, $challengeId ) {
139139 $out = $this->getOutput();
140 -
 140+
141141 // Check if the user is already a contestant in this contest.
142142 // If he is, reirect to submission page, else show signup form.
143143 $contestant = ContestContestant::s()->selectRow(
@@ -146,80 +146,80 @@
147147 'user_id' => $this->getUser()->getId()
148148 )
149149 );
150 -
 150+
151151 if ( $contestant === false ) {
152152 $out->setPageTitle( $contest->getField( 'name' ) );
153153 $out->addWikiMsg( 'contest-signup-header', $contest->getField( 'name' ) );
154 -
 154+
155155 $this->showSignupForm( $contest, $challengeId );
156156 }
157157 else {
158158 $out->redirect( SpecialPage::getTitleFor( 'MyContests', $contest->getField( 'name' ) )->getLocalURL() );
159159 }
160160 }
161 -
 161+
162162 /**
163163 * Display the signup form for this contest.
164 - *
 164+ *
165165 * @since 0.1
166 - *
 166+ *
167167 * @param Contest $contest
168168 * @param integer|false $challengeId
169169 */
170170 protected function showSignupForm( Contest $contest, $challengeId = false ) {
171171 $form = new HTMLForm( $this->getFormFields( $contest, $challengeId ), $this->getContext() );
172 -
 172+
173173 $form->setSubmitCallback( array( $this, 'handleSubmission' ) );
174174 $form->setSubmitText( wfMsg( 'contest-signup-submit' ) );
175 -
 175+
176176 if( $form->show() ) {
177177 $this->showSucess( $contest );
178178 }
179179 else {
180180 $this->getOutput()->addModules( 'contest.special.signup' );
181181 }
182 -
183 - $this->getOutput()->addScript(
184 - Skin::makeVariablesScript(
 182+
 183+ $this->getOutput()->addScript(
 184+ Skin::makeVariablesScript(
185185 array(
186186 'ContestConfig' => array( 'rules_page' => ContestUtils::getParsedArticleContent( $contest->getField( 'rules_page' ) ) )
187187 )
188188 )
189189 );
190190 }
191 -
 191+
192192 /**
193193 * 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+ *
196196 * @since 0.1
197 - *
 197+ *
198198 * @param Contest $contest
199199 */
200200 protected function showSucess( Contest $contest ) {
201201 $url = SpecialPage::getTitleFor( 'MyContests', $contest->getField( 'name' ) )->getLocalURL( 'new' );
202202 $this->getOutput()->redirect( $url );
203203 }
204 -
 204+
205205 /**
206206 * Gets the field definitions for the form.
207 - *
 207+ *
208208 * @since 0.1
209 - *
 209+ *
210210 * @param Contest $contest
211211 * @param integer|false $challengeId
212212 */
213213 protected function getFormFields( Contest $contest, $challengeId ) {
214214 $fields = array();
215 -
 215+
216216 $user = $this->getUser();
217 -
 217+
218218 $fields['contest-id'] = array(
219219 'type' => 'hidden',
220220 'default' => $contest->getId(),
221221 'id' => 'contest-id',
222222 );
223 -
 223+
224224 $fields['contestant-realname'] = array(
225225 'type' => 'text',
226226 'default' => $user->getRealName(),
@@ -227,7 +227,7 @@
228228 'required' => true,
229229 'validation-callback' => array( __CLASS__, 'validateNameField' )
230230 );
231 -
 231+
232232 $fields['contestant-email'] = array(
233233 'type' => 'text',
234234 'default' => $user->getEmail(),
@@ -235,7 +235,7 @@
236236 'required' => true,
237237 'validation-callback' => array( __CLASS__, 'validateEmailField' )
238238 );
239 -
 239+
240240 $fields['contestant-country'] = array(
241241 'type' => 'select',
242242 'label-message' => 'contest-signup-country',
@@ -243,7 +243,7 @@
244244 'options' => ContestContestant::getCountriesForInput( true ),
245245 'validation-callback' => array( __CLASS__, 'validateCountryField' )
246246 );
247 -
 247+
248248 $fields['contestant-challengeid'] = array(
249249 'type' => 'radio',
250250 'label-message' => 'contest-signup-challenge',
@@ -251,23 +251,23 @@
252252 'required' => true,
253253 'validation-callback' => array( __CLASS__, 'validateChallengeField' )
254254 );
255 -
 255+
256256 if ( $challengeId !== false ) {
257257 $fields['contestant-challengeid']['default'] = $challengeId;
258258 }
259 -
 259+
260260 $fields['contestant-volunteer'] = array(
261261 'type' => 'check',
262262 'default' => '0',
263263 'label-message' => 'contest-signup-volunteer',
264264 );
265 -
 265+
266266 $fields['contestant-wmf'] = array(
267267 'type' => 'check',
268268 'default' => '0',
269269 'label-message' => 'contest-signup-wmf',
270270 );
271 -
 271+
272272 $fields['contestant-readrules'] = array(
273273 'type' => 'check',
274274 'default' => '0',
@@ -276,118 +276,118 @@
277277 'id' => 'contest-rules',
278278 'data-foo' => 'bar'
279279 );
280 -
 280+
281281 return $fields;
282282 }
283 -
 283+
284284 /**
285285 * Gets a list of contests that can be fed directly to the options field of
286286 * an HTMLForm radio input.
287287 * challenge title => challenge id
288 - *
 288+ *
289289 * @since 0.1
290 - *
 290+ *
291291 * @param Contest $contest
292 - *
 292+ *
293293 * @return array
294294 */
295295 protected function getChallengesList( Contest $contest ) {
296296 $list = array();
297 -
 297+
298298 foreach ( $contest->getChallenges() as /* ContestChallenge */ $challenge ) {
299299 $list[$challenge->getField( 'title' )] = $challenge->getId();
300300 }
301 -
 301+
302302 return $list;
303303 }
304 -
 304+
305305 /**
306306 * HTMLForm field validation-callback for name field.
307307 * 1
308308 * @since 0.1
309 - *
 309+ *
310310 * @param $value String
311311 * @param $alldata Array
312 - *
 312+ *
313313 * @return true|string
314314 */
315315 public static function validateNameField( $value, $alldata = null ) {
316316 if ( strlen( $value ) < 2 ) {
317317 return wfMsg( 'contest-signup-invalid-name' );
318318 }
319 -
 319+
320320 return true;
321321 }
322 -
 322+
323323 /**
324324 * HTMLForm field validation-callback for email field.
325 - *
 325+ *
326326 * @since 0.1
327 - *
 327+ *
328328 * @param $value String
329329 * @param $alldata Array
330 - *
 330+ *
331331 * @return true|string
332332 */
333333 public static function validateEmailField( $value, $alldata = null ) {
334334 if ( !Sanitizer::validateEmail( $value ) ) {
335335 return wfMsg( 'contest-signup-invalid-email' );
336336 }
337 -
 337+
338338 return true;
339339 }
340 -
 340+
341341 /**
342342 * HTMLForm field validation-callback for country field.
343 - *
 343+ *
344344 * @since 0.1
345 - *
 345+ *
346346 * @param $value String
347347 * @param $alldata Array
348 - *
 348+ *
349349 * @return true|string
350350 */
351351 public static function validateCountryField( $value, $alldata = null ) {
352352 if ( $value === '' ) {
353353 return wfMsg( 'contest-signup-require-country' );
354354 }
355 -
 355+
356356 return true;
357357 }
358 -
 358+
359359 /**
360360 * HTMLForm field validation-callback for rules field.
361 - *
 361+ *
362362 * @since 0.1
363 - *
 363+ *
364364 * @param $value String
365365 * @param $alldata Array
366 - *
 366+ *
367367 * @return true|string
368368 */
369369 public static function validateRulesField( $value, $alldata = null ) {
370370 if ( !$value ) {
371371 return wfMsg( 'contest-signup-require-rules' );
372372 }
373 -
 373+
374374 return true;
375375 }
376 -
 376+
377377 /**
378378 * HTMLForm field validation-callback for challenge field.
379 - *
 379+ *
380380 * @since 0.1
381 - *
 381+ *
382382 * @param $value String
383383 * @param $alldata Array
384 - *
 384+ *
385385 * @return true|string
386386 */
387387 public static function validateChallengeField( $value, $alldata = null ) {
388388 if ( is_null( $value ) ) {
389389 return wfMsg( 'contest-signup-require-challenge' );
390390 }
391 -
 391+
392392 return true;
393393 }
394394
Index: trunk/extensions/Contest/specials/SpecialEditContest.php
@@ -2,41 +2,41 @@
33
44 /**
55 * Contest editing interface for contest admins.
6 - *
 6+ *
77 * @since 0.1
8 - *
 8+ *
99 * @file SpecialEditContest.php
1010 * @ingroup Contest
11 - *
 11+ *
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 class SpecialEditContest extends FormSpecialPage {
16 -
 16+
1717 protected $contest = false;
1818 protected $isNewPost = false;
19 -
 19+
2020 /**
2121 * Constructor.
22 - *
 22+ *
2323 * @since 0.1
2424 */
2525 public function __construct() {
2626 parent::__construct( 'EditContest', 'contestadmin', false );
2727 }
28 -
 28+
2929 /**
3030 * @see SpecialPage::getDescription
31 - *
 31+ *
3232 * @since 0.1
3333 */
3434 public function getDescription() {
3535 return wfMsg( 'special-' . strtolower( $this->getName() ) );
3636 }
37 -
 37+
3838 /**
3939 * Sets headers - this should be called from the execute() method of all derived classes!
40 - *
 40+ *
4141 * @since 0.1
4242 */
4343 public function setHeaders() {
@@ -44,25 +44,25 @@
4545 $out->setArticleRelated( false );
4646 $out->setRobotPolicy( 'noindex,nofollow' );
4747 $out->setPageTitle( $this->getDescription() );
48 - }
49 -
 48+ }
 49+
5050 /**
5151 * Main method.
52 - *
 52+ *
5353 * @since 0.1
54 - *
 54+ *
5555 * @param string $subPage
5656 */
5757 public function execute( $subPage ) {
5858 $subPage = str_replace( '_', ' ', $subPage );
59 -
 59+
6060 $this->setParameter( $subPage );
6161 $this->setHeaders();
6262 $this->outputHeader();
6363
6464 // This will throw exceptions if there's a problem
6565 $this->userCanExecute( $this->getUser() );
66 -
 66+
6767 if ( $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) {
6868 $this->showForm();
6969 }
@@ -70,36 +70,36 @@
7171 $this->showContent( $subPage );
7272 }
7373 }
74 -
 74+
7575 /**
7676 * Show the form.
77 - *
 77+ *
7878 * @since 0.1
7979 */
8080 protected function showForm() {
8181 $form = $this->getForm();
82 -
 82+
8383 if ( $form->show() ) {
8484 $this->onSuccess();
8585 }
8686 }
87 -
 87+
8888 /**
8989 * Attempt to get the contest to be edited or create the one to be added.
9090 * If this works, show the form, if not, redirect to special:contests.
91 - *
 91+ *
9292 * @since 0.1
93 - *
 93+ *
9494 * @param string $subPage
9595 */
9696 protected function showContent( $subPage ) {
9797 $isNew = $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'newEditToken' ) );
98 -
 98+
9999 if ( $isNew ) {
100100 $data = array( 'name' => $this->getRequest()->getVal( 'newcontest' ) );
101 -
 101+
102102 $contest = Contest::s()->selectRow( null, $data );
103 -
 103+
104104 if ( $contest === false ) {
105105 $contest = new Contest( $data, true );
106106 }
@@ -110,7 +110,7 @@
111111 else {
112112 $contest = Contest::s()->selectRow( null, array( 'name' => $subPage ) );
113113 }
114 -
 114+
115115 if ( $contest === false ) {
116116 $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() );
117117 }
@@ -120,20 +120,20 @@
121121 SpecialContestPage::getNavigation( $contest->getField( 'name' ), $this->getUser(), $this->getLang(), $this->getName() )
122122 );
123123 }
124 -
 124+
125125 $this->contest = $contest;
126126 $this->showForm();
127127 $this->getOutput()->addModules( 'contest.special.editcontest' );
128128 }
129129 }
130 -
 130+
131131 /**
132132 * (non-PHPdoc)
133133 * @see FormSpecialPage::getForm()
134134 */
135135 protected function getForm() {
136136 $form = parent::getForm();
137 -
 137+
138138 $form->addButton(
139139 'cancelEdit',
140140 wfMsg( 'cancel' ),
@@ -142,7 +142,7 @@
143143 'target-url' => SpecialPage::getTitleFor( 'Contests' )->getFullURL()
144144 )
145145 );
146 -
 146+
147147 // $form->addButton(
148148 // 'deleteEdit',
149149 // wfMsg( 'delete' ),
@@ -151,85 +151,85 @@
152152
153153 return $form;
154154 }
155 -
 155+
156156 /**
157157 * (non-PHPdoc)
158158 * @see FormSpecialPage::getFormFields()
159159 */
160160 protected function getFormFields() {
161161 $contest = $this->contest;
162 -
 162+
163163 $fields = array();
164164
165165 $fields['id'] = array ( 'type' => 'hidden' );
166 -
 166+
167167 $fields['name'] = array (
168168 'type' => 'text',
169169 'label-message' => 'contest-edit-name',
170170 'id' => 'contest-name-field',
171171 );
172 -
 172+
173173 $fields['status'] = array (
174174 'type' => 'radio',
175175 'label-message' => 'contest-edit-status',
176176 'options' => Contest::getStatusMessages( $onlySettable = true )
177177 );
178 -
 178+
179179 $fields['intro'] = array (
180180 'type' => 'text',
181181 'label-message' => 'contest-edit-intro',
182182 );
183 -
 183+
184184 $fields['opportunities'] = array (
185185 'type' => 'text',
186186 'label-message' => 'contest-edit-opportunities',
187187 );
188 -
 188+
189189 $fields['rules_page'] = array (
190190 'type' => 'text',
191191 'label-message' => 'contest-edit-rulespage',
192192 );
193 -
 193+
194194 $fields['help'] = array (
195195 'type' => 'text',
196196 'label-message' => 'contest-edit-help',
197197 );
198 -
 198+
199199 $fields['signup_email'] = array (
200200 'type' => 'text',
201201 'label-message' => 'contest-edit-signup',
202202 );
203 -
 203+
204204 $fields['reminder_email'] = array (
205205 'type' => 'text',
206206 'label-message' => 'contest-edit-reminder',
207207 );
208 -
 208+
209209 $fields['end'] = array (
210210 'type' => 'text',
211211 'label-message' => 'contest-edit-end',
212212 'id' => 'contest-edit-end',
213213 'size' => 15
214214 );
215 -
 215+
216216 if ( $contest !== false ) {
217217 foreach ( $fields as $name => $data ) {
218218 $default = $contest->getField( $name );
219 -
 219+
220220 if ( $name == 'end' ) {
221221 $default = wfTimestamp( TS_DB, $default );
222222 }
223 -
 223+
224224 $fields[$name]['default'] = $default;
225225 }
226226 }
227 -
 227+
228228 $mappedFields = array();
229 -
 229+
230230 foreach ( $fields as $name => $field ) {
231231 $mappedFields['contest-' . $name] = $field;
232232 }
233 -
 233+
234234 if ( $contest !== false ) {
235235 foreach ( $contest->getChallenges() as /* ContestChallenge */ $challenge ) {
236236 $mappedFields[] = array(
@@ -238,36 +238,36 @@
239239 );
240240 }
241241 }
242 -
 242+
243243 $mappedFields['delete-challenges'] = array ( 'type' => 'hidden', 'id' => 'delete-challenges' );
244 -
 244+
245245 return $mappedFields;
246246 }
247 -
 247+
248248 /**
249249 * Process the form. At this point we know that the user passes all the criteria in
250250 * userCanExecute(), and if the data array contains 'Username', etc, then Username
251251 * resets are allowed.
252 - *
 252+ *
253253 * @param array $data
254 - *
 254+ *
255255 * @return Bool|Array
256256 */
257257 public function onSubmit( array $data ) {
258258 $fields = array();
259 -
 259+
260260 foreach ( $data as $name => $value ) {
261261 $matches = array();
262 -
 262+
263263 if ( preg_match( '/contest-(.+)/', $name, $matches ) ) {
264264 if ( $matches[1] == 'end' ) {
265265 $value = wfTimestamp( TS_MW, strtotime( $value ) );
266266 }
267 -
 267+
268268 $fields[$matches[1]] = $value;
269269 }
270270 }
271 -
 271+
272272 // If no ID is set, this means it's a new contest, so set the ID to null for an insert.
273273 // However, the user can have hot the back button after creation of a new contest,
274274 // re-submitting the form. In this case, get the ID of the already existing item for an update.
@@ -275,12 +275,12 @@
276276 $contest = Contest::s()->selectRow( 'id', array( 'name' => $fields['name'] ) );
277277 $fields['id'] = $contest === false ? null : $contest->getField( 'id' );
278278 }
279 -
 279+
280280 $contest = new Contest( $fields, true );
281281
282282 $contest->setChallenges( $this->getSubmittedChallenges() );
283283 $success = $contest->writeAllToDB();
284 -
 284+
285285 $success = $this->removeDeletedChallenges( $data['delete-challenges'] ) && $success;
286286
287287 if ( $success ) {
@@ -290,57 +290,57 @@
291291 return array(); // TODO
292292 }
293293 }
294 -
 294+
295295 /**
296296 * The UI keeps track of 'removed' challenges by storing them into a
297297 * hidden HTML input, pipe-separated. On submission, this method
298298 * takes this string and actually deletes them.
299 - *
 299+ *
300300 * @since 0.1
301 - *
 301+ *
302302 * @param string $idString
303 - *
 303+ *
304304 * @return boolean Success indicator
305305 */
306306 protected function removeDeletedChallenges( $idString ) {
307307 if ( $idString == '' ) {
308308 return true;
309309 }
310 -
311 - return ContestChallenge::s()->delete( array( 'id' => explode( '|', $idString ) ) );
 310+
 311+ return ContestChallenge::s()->delete( array( 'id' => explode( '|', $idString ) ) );
312312 }
313 -
 313+
314314 /**
315315 * Finds the submitted challanges and returns them as a list of
316316 * ContestChallenge objects.
317 - *
 317+ *
318318 * @since 0.1
319 - *
 319+ *
320320 * @return array of ContestChallenge
321321 */
322322 protected function getSubmittedChallenges() {
323323 $challenges = array();
324 -
 324+
325325 foreach ( $this->getrequest()->getValues() as $name => $value ) {
326326 $matches = array();
327 -
 327+
328328 if ( preg_match( '/contest-challenge-(\d+)/', $name, $matches ) ) {
329329 $challenges[] = $this->getSubmittedChallenge( $matches[1] );
330330 } elseif ( preg_match( '/contest-challenge-new-(\d+)/', $name, $matches ) ) {
331331 $challenges[] = $this->getSubmittedChallenge( $matches[1], true );
332332 }
333333 }
334 -
 334+
335335 return $challenges;
336336 }
337 -
 337+
338338 /**
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+ *
341341 * @since 0.1
342 - *
 342+ *
343343 * @param integer|null $challengeId
344 - *
 344+ *
345345 * @return ContestChallenge
346346 */
347347 protected function getSubmittedChallenge( $challengeId, $isNewChallenge = false ) {
@@ -350,9 +350,9 @@
351351 } else {
352352 $challengeDbId = $challengeId;
353353 }
354 -
 354+
355355 $request = $this->getRequest();
356 -
 356+
357357 return new ContestChallenge( array(
358358 'id' => $challengeDbId,
359359 'text' => $request->getText( "challenge-text-$challengeId" ),
@@ -360,16 +360,16 @@
361361 'oneline' => $request->getText( "challenge-oneline-$challengeId" ),
362362 ) );
363363 }
364 -
 364+
365365 public function onSuccess() {
366366 $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() );
367367 }
368368
369369 /**
370370 * Show a message in a warning box.
371 - *
 371+ *
372372 * @since 0.1
373 - *
 373+ *
374374 * @param string $message
375375 */
376376 protected function showWarning( $message ) {
@@ -377,24 +377,24 @@
378378 '<p class="visualClear warningbox">' . wfMsgExt( $message, 'parseinline' ) . '</p>'
379379 );
380380 }
381 -
 381+
382382 }
383383
384384 class ContestChallengeField extends HTMLFormField {
385 -
 385+
386386 public function getInputHTML( $value ) {
387387 $attribs = array(
388388 'class' => 'contest-challenge'
389389 );
390 -
 390+
391391 foreach ( $this->mParams['options'] as $name => $value ) {
392392 $attribs['data-challenge-' . $name] = $value;
393393 }
394 -
 394+
395395 return Html::element(
396396 'div',
397397 $attribs
398398 );
399399 }
400 -
 400+
401401 }
Index: trunk/extensions/Contest/includes/ContestDBObject.php
@@ -4,31 +4,31 @@
55 * Abstract base class for representing objects that are stored in some DB table.
66 * This is a modified copy of SurveyDBClass, backported to work with PHP 5.2,
77 * and therefore missing all the awesome you get with late static binding.
8 - *
 8+ *
99 * @since 0.1
10 - *
 10+ *
1111 * @file ContestDBObject.php
1212 * @ingroup Contest
13 - *
 13+ *
1414 * @licence GNU GPL v3 or later
1515 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1616 */
1717 abstract class ContestDBObject {
18 -
 18+
1919 /**
2020 * The fields of the object.
2121 * field name (w/o prefix) => value
22 - *
 22+ *
2323 * @since 0.1
2424 * @var array
2525 */
2626 protected $fields = array( 'id' => null );
27 -
 27+
2828 /**
2929 * Constructor.
30 - *
 30+ *
3131 * @since 0.1
32 - *
 32+ *
3333 * @param array|null $fields
3434 * @param boolean $loadDefaults
3535 */
@@ -36,39 +36,39 @@
3737 if ( !is_array( $fields ) ) {
3838 $fields = array();
3939 }
40 -
 40+
4141 if ( $loadDefaults ) {
4242 $fields = array_merge( $this->getDefaults(), $fields );
4343 }
44 -
 44+
4545 $this->setFields( $fields );
4646 }
47 -
 47+
4848 /**
4949 * Returns the name of the database table objects of this type are stored in.
50 - *
 50+ *
5151 * @since 0.1
52 - *
 52+ *
5353 * @return string
5454 */
5555 public abstract function getDBTable();
5656
5757 /**
58 - * Gets the db field prefix.
59 - *
 58+ * Gets the db field prefix.
 59+ *
6060 * @since 0.1
61 - *
 61+ *
6262 * @return string
6363 */
6464 protected abstract function getFieldPrefix();
65 -
 65+
6666 /**
6767 * Gets the value of a field.
68 - *
 68+ *
6969 * @since 0.1
70 - *
 70+ *
7171 * @param string $name
72 - *
 72+ *
7373 * @throws MWException
7474 * @return mixed
7575 */
@@ -79,23 +79,23 @@
8080 throw new MWException( 'Attempted to get not-set field ' . $name );
8181 }
8282 }
83 -
 83+
8484 /**
8585 * Remove a field.
86 - *
 86+ *
8787 * @since 0.1
88 - *
 88+ *
8989 * @param string $name
9090 */
9191 public function removeField( $name ) {
9292 unset( $this->fields[$name] );
9393 }
94 -
 94+
9595 /**
9696 * Returns the objects database id.
97 - *
 97+ *
9898 * @since 0.1
99 - *
 99+ *
100100 * @return integer|null
101101 */
102102 public function getId() {
@@ -104,45 +104,45 @@
105105
106106 /**
107107 * Sets the objects database id.
108 - *
 108+ *
109109 * @since 0.1
110 - *
 110+ *
111111 * @param integere|null $id
112112 */
113113 public function setId( $id ) {
114114 return $this->setField( 'id', $id );
115115 }
116 -
 116+
117117 /**
118118 * Gets if a certain field is set.
119 - *
 119+ *
120120 * @since 0.1
121 - *
 121+ *
122122 * @param string $name
123 - *
 123+ *
124124 * @return boolean
125125 */
126126 public function hasField( $name ) {
127127 return array_key_exists( $name, $this->fields );
128128 }
129 -
 129+
130130 /**
131131 * Gets if the id field is set.
132 - *
 132+ *
133133 * @since 0.1
134 - *
 134+ *
135135 * @return boolean
136136 */
137137 public function hasIdField() {
138 - return $this->hasField( 'id' )
 138+ return $this->hasField( 'id' )
139139 && !is_null( $this->getField( 'id' ) );
140140 }
141 -
 141+
142142 /**
143143 * Sets multiple fields.
144 - *
 144+ *
145145 * @since 0.1
146 - *
 146+ *
147147 * @param array $fields The fields to set
148148 * @param boolean $override Override already set fields with the provided values?
149149 */
@@ -153,48 +153,48 @@
154154 }
155155 }
156156 }
157 -
 157+
158158 /**
159 - * Gets the fields => values to write to the table.
160 - *
 159+ * Gets the fields => values to write to the table.
 160+ *
161161 * @since 0.1
162 - *
 162+ *
163163 * @return array
164164 */
165165 protected function getWriteValues() {
166166 $values = array();
167 -
 167+
168168 foreach ( $this->getFieldTypes() as $name => $type ) {
169169 if ( array_key_exists( $name, $this->fields ) ) {
170170 $value = $this->fields[$name];
171 -
 171+
172172 switch ( $type ) {
173173 case 'array':
174174 $value = serialize( (array)$value );
175175 }
176 -
 176+
177177 $values[$this->getFieldPrefix() . $name] = $value;
178178 }
179179 }
180 -
 180+
181181 return $values;
182182 }
183 -
 183+
184184 /**
185185 * Serializes the object to an associative array which
186186 * can then easily be converted into JSON or similar.
187 - *
 187+ *
188188 * @since 0.1
189 - *
 189+ *
190190 * @param null|array $props
191191 * @param boolean $incNullId
192 - *
 192+ *
193193 * @return array
194194 */
195195 public function toArray( $fields = null, $incNullId = false ) {
196196 $data = array();
197197 $setFields = array();
198 -
 198+
199199 if ( !is_array( $fields ) ) {
200200 $setFields = $this->getSetFieldNames();
201201 } else {
@@ -204,33 +204,33 @@
205205 }
206206 }
207207 }
208 -
 208+
209209 foreach ( $setFields as $field ) {
210210 if ( $incNullId || $field != 'id' || $this->hasIdField() ) {
211211 $data[$field] = $this->getField( $field );
212212 }
213213 }
214 -
 214+
215215 return $data;
216216 }
217 -
 217+
218218 /**
219219 * Load the default values, via getDefaults.
220 - *
 220+ *
221221 * @since 0.1
222 - *
 222+ *
223223 * @param boolean $override
224224 */
225225 public function loadDefaults( $override = true ) {
226226 $this->setFields( $this->getDefaults(), $override );
227227 }
228 -
 228+
229229 /**
230230 * Writes the answer to the database, either updating it
231231 * when it already exists, or inserting it when it doesn't.
232 - *
 232+ *
233233 * @since 0.1
234 - *
 234+ *
235235 * @return boolean Success indicator
236236 */
237237 public function writeToDB() {
@@ -240,98 +240,98 @@
241241 return $this->insertIntoDB();
242242 }
243243 }
244 -
 244+
245245 /**
246246 * Updates the object in the database.
247 - *
 247+ *
248248 * @since 0.1
249 - *
 249+ *
250250 * @return boolean Success indicator
251251 */
252252 protected function updateInDB() {
253253 $dbw = wfGetDB( DB_MASTER );
254 -
 254+
255255 return $dbw->update(
256256 $this->getDBTable(),
257257 $this->getWriteValues(),
258258 array( $this->getFieldPrefix() . 'id' => $this->getId() )
259259 );
260260 }
261 -
 261+
262262 /**
263263 * Inserts the object into the database.
264 - *
 264+ *
265265 * @since 0.1
266 - *
 266+ *
267267 * @return boolean Success indicator
268268 */
269269 protected function insertIntoDB() {
270270 $dbw = wfGetDB( DB_MASTER );
271 -
 271+
272272 $result = $dbw->insert(
273273 $this->getDBTable(),
274274 $this->getWriteValues()
275275 );
276 -
 276+
277277 $this->setField( 'id', $dbw->insertId() );
278 -
 278+
279279 return $result;
280280 }
281 -
 281+
282282 /**
283283 * Removes the object from the database.
284 - *
 284+ *
285285 * @since 0.1
286 - *
 286+ *
287287 * @return boolean Success indicator
288288 */
289289 public function removeFromDB() {
290290 $sucecss = $this->delete( array( 'id' => $this->getId() ) );
291 -
 291+
292292 if ( $sucecss ) {
293293 $this->setField( 'id', null );
294294 }
295 -
 295+
296296 return $sucecss;
297297 }
298 -
 298+
299299 /**
300300 * Return the names of the fields.
301 - *
 301+ *
302302 * @since 0.1
303 - *
 303+ *
304304 * @return array
305305 */
306306 public function getFields() {
307307 return $this->fields;
308308 }
309 -
 309+
310310 /**
311311 * Return the names of the fields.
312 - *
 312+ *
313313 * @since 0.1
314 - *
 314+ *
315315 * @return array
316316 */
317317 public function getSetFieldNames() {
318318 return array_keys( $this->fields );
319319 }
320 -
 320+
321321 /**
322322 * Sets the value of a field.
323323 * Strings can be provided for other types,
324324 * so this method can be called from unserialization handlers.
325 - *
 325+ *
326326 * @since 0.1
327 - *
 327+ *
328328 * @param string $name
329329 * @param mixed $value
330 - *
 330+ *
331331 * @throws MWException
332332 */
333333 public function setField( $name, $value ) {
334334 $fields = $this->getFieldTypes();
335 -
 335+
336336 if ( array_key_exists( $name, $fields ) ) {
337337 switch ( $fields[$name] ) {
338338 case 'int':
@@ -358,19 +358,19 @@
359359 }
360360 break;
361361 }
362 -
 362+
363363 $this->fields[$name] = $value;
364364 } else {
365365 throw new MWException( 'Attempted to set unknown field ' . $name );
366366 }
367367 }
368 -
 368+
369369 /**
370370 * Returns an array with the fields and their types this object contains.
371371 * This corresponds directly to the fields in the database, without prefix.
372 - *
 372+ *
373373 * field name => type
374 - *
 374+ *
375375 * Allowed types:
376376 * * id
377377 * * str
@@ -378,9 +378,9 @@
379379 * * float
380380 * * bool
381381 * * array
382 - *
 382+ *
383383 * @since 0.1
384 - *
 384+ *
385385 * @return array
386386 */
387387 protected abstract function getFieldTypes();
@@ -388,114 +388,114 @@
389389 /**
390390 * Returns a list of default field values.
391391 * field name => field value
392 - *
 392+ *
393393 * @since 0.1
394 - *
 394+ *
395395 * @return array
396396 */
397397 public abstract function getDefaults();
398 -
 398+
399399 //
400400 //
401401 // All below methods ought to be static, but can't be since this would require LSB introduced in PHP 5.3.
402402 //
403403 //
404 -
 404+
405405 /**
406406 * Gets if the object can take a certain field.
407 - *
 407+ *
408408 * @since 0.1
409 - *
 409+ *
410410 * @param string $name
411 - *
 411+ *
412412 * @return boolean
413413 */
414414 public function canHasField( $name ) {
415415 return array_key_exists( $name, $this->getFieldTypes() );
416416 }
417 -
 417+
418418 /**
419419 * Takes in a field or array of fields and returns an
420420 * array with their prefixed versions, ready for db usage.
421 - *
 421+ *
422422 * @since 0.1
423 - *
 423+ *
424424 * @param array|string $fields
425 - *
 425+ *
426426 * @return array
427427 */
428428 public function getPrefixedFields( $fields ) {
429429 $fields = (array)$fields;
430 -
 430+
431431 foreach ( $fields as &$field ) {
432432 $field = $this->getFieldPrefix() . $field;
433433 }
434 -
 434+
435435 return $fields;
436436 }
437437
438438 /**
439439 * Takes in a field and returns an it's prefixed version, ready for db usage.
440 - *
 440+ *
441441 * @since 0.1
442 - *
 442+ *
443443 * @param string $field
444 - *
 444+ *
445445 * @return string
446446 */
447447 public function getPrefixedField( $field ) {
448448 return $this->getFieldPrefix() . $field;
449449 }
450 -
 450+
451451 /**
452452 * Takes in an associative array with field names as keys and
453453 * their values as value. The field names are prefixed with the
454454 * db field prefix.
455 - *
 455+ *
456456 * @since 0.1
457 - *
 457+ *
458458 * @param array $values
459 - *
 459+ *
460460 * @return array
461461 */
462462 public function getPrefixedValues( array $values ) {
463463 $prefixedValues = array();
464 -
 464+
465465 foreach ( $values as $field => $value ) {
466466 $prefixedValues[$this->getFieldPrefix() . $field] = $value;
467467 }
468 -
 468+
469469 return $prefixedValues;
470470 }
471471
472472 /**
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+ *
475475 * @since 0.1
476 - *
 476+ *
477477 * @param object $result
478 - *
 478+ *
479479 * @return ContestDBObject
480480 */
481481 public function newFromDBResult( $result ) {
482482 $result = (array)$result;
483483 $data = array();
484484 $idFieldLength = strlen( $this->getFieldPrefix() );
485 -
 485+
486486 foreach ( $result as $name => $value ) {
487487 $data[substr( $name, $idFieldLength )] = $value;
488488 }
489 -
 489+
490490 return $this->newFromArray( $data );
491491 }
492492
493493 /**
494494 * Removes the object from the database.
495 - *
 495+ *
496496 * @since 0.1
497 - *
 497+ *
498498 * @param array $conditions
499 - *
 499+ *
500500 * @return boolean Success indicator
501501 */
502502 public function delete( array $conditions ) {
@@ -504,121 +504,121 @@
505505 $this->getPrefixedValues( $conditions )
506506 );
507507 }
508 -
 508+
509509 /**
510510 * Add an amount (can be negative) to the specified field (needs to be numeric).
511 - *
 511+ *
512512 * @since 0.1
513 - *
 513+ *
514514 * @param string $field
515515 * @param integer $amount
516 - *
 516+ *
517517 * @return boolean Success indicator
518518 */
519519 public function addToField( $field, $amount ) {
520520 if ( $amount == 0 ) {
521521 return true;
522522 }
523 -
 523+
524524 if ( !$this->hasIdField() ) {
525525 return false;
526526 }
527 -
 527+
528528 $absoluteAmount = abs( $amount );
529529 $isNegative = $amount < 0;
530 -
 530+
531531 $dbw = wfGetDB( DB_MASTER );
532 -
 532+
533533 $fullField = $this->getPrefixedField( $field );
534 -
 534+
535535 $success = $dbw->update(
536536 $this->getDBTable(),
537537 array( "$fullField=$fullField" . ( $isNegative ? '-' : '+' ) . $absoluteAmount ),
538538 array( $this->getPrefixedField( 'id' ) => $this->getId() )
539539 );
540 -
 540+
541541 if ( $success && $this->hasField( $field ) ) {
542542 $this->setField( $field, $this->getField( $field ) + $amount );
543543 }
544 -
 544+
545545 return $success;
546546 }
547 -
 547+
548548 /**
549549 * Selects the the specified fields of the records matching the provided
550550 * conditions. Field names get prefixed.
551 - *
 551+ *
552552 * @since 0.1
553 - *
 553+ *
554554 * @param array|string|null $fields
555555 * @param array $conditions
556556 * @param array $options
557 - *
 557+ *
558558 * @return array of self
559559 */
560560 public function select( $fields = null, array $conditions = array(), array $options = array() ) {
561561 if ( is_null( $fields ) ) {
562562 $fields = array_keys( $this->getFieldTypes() );
563563 }
564 -
 564+
565565 $result = $this->rawSelect(
566566 $this->getPrefixedFields( $fields ),
567567 $this->getPrefixedValues( $conditions ),
568568 $options
569569 );
570 -
 570+
571571 $objects = array();
572 -
 572+
573573 foreach ( $result as $record ) {
574574 $objects[] = $this->newFromDBResult( $record );
575575 }
576 -
 576+
577577 return $objects;
578578 }
579 -
 579+
580580 /**
581581 * Selects the the specified fields of the first matching record.
582582 * Field names get prefixed.
583 - *
 583+ *
584584 * @since 0.1
585 - *
 585+ *
586586 * @param array|string|null $fields
587587 * @param array $conditions
588588 * @param array $options
589 - *
 589+ *
590590 * @return self|false
591591 */
592592 public function selectRow( $fields = null, array $conditions = array(), array $options = array() ) {
593593 $options['LIMIT'] = 1;
594 -
 594+
595595 $objects = $this->select( $fields, $conditions, $options );
596 -
 596+
597597 return count( $objects ) > 0 ? $objects[0] : false;
598598 }
599 -
 599+
600600 /**
601601 * Returns if there is at least one record matching the provided conditions.
602602 * Condition field names get prefixed.
603 - *
 603+ *
604604 * @since 0.1
605 - *
 605+ *
606606 * @param array $conditions
607 - *
 607+ *
608608 * @return boolean
609609 */
610610 public function has( array $conditions = array() ) {
611611 return $this->selectRow( array( 'id' ), $conditions ) !== false;
612612 }
613 -
 613+
614614 /**
615615 * Returns the amount of matching records.
616616 * Condition field names get prefixed.
617 - *
 617+ *
618618 * @since 0.1
619 - *
 619+ *
620620 * @param array $conditions
621621 * @param array $options
622 - *
 622+ *
623623 * @return integer
624624 */
625625 public function count( array $conditions = array(), array $options = array() ) {
@@ -627,25 +627,25 @@
628628 $this->getPrefixedValues( $conditions ),
629629 $options
630630 )->fetchObject();
631 -
 631+
632632 return $res->rowcount;
633633 }
634 -
 634+
635635 /**
636636 * 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+ *
639639 * @since 0.1
640 - *
 640+ *
641641 * @param array|null $fields
642642 * @param array $conditions
643643 * @param array $options
644 - *
 644+ *
645645 * @return ResultWrapper
646646 */
647 - public function rawSelect( $fields = null, array $conditions = array(), array $options = array() ) {
 647+ public function rawSelect( $fields = null, array $conditions = array(), array $options = array() ) {
648648 $dbr = wfGetDB( DB_SLAVE );
649 -
 649+
650650 return $dbr->select(
651651 $this->getDBTable(),
652652 $fields,
@@ -656,45 +656,45 @@
657657 }
658658
659659 /**
660 - * Update the records matching the provided conditions by
 660+ * Update the records matching the provided conditions by
661661 * setting the fields that are keys in the $values patam to
662662 * their corresponding values.
663 - *
 663+ *
664664 * @since 0.1
665 - *
 665+ *
666666 * @param array $values
667667 * @param array $conditions
668 - *
 668+ *
669669 * @return boolean Success indicator
670670 */
671671 public function update( array $values, array $conditions = array() ) {
672672 $dbw = wfGetDB( DB_MASTER );
673 -
 673+
674674 return $dbw->update(
675675 $this->getDBTable(),
676676 $this->getPrefixedValues( $values ),
677677 $this->getPrefixedValues( $conditions )
678678 );
679679 }
680 -
 680+
681681 /**
682682 * Return the names of the fields.
683 - *
 683+ *
684684 * @since 0.1
685 - *
 685+ *
686686 * @return array
687687 */
688688 public function getFieldNames() {
689689 return array_keys( $this->getFieldTypes() );
690690 }
691 -
 691+
692692 /**
693693 * Returns an array with the fields and their descriptions.
694 - *
 694+ *
695695 * field name => field description
696 - *
 696+ *
697697 * @since 0.1
698 - *
 698+ *
699699 * @return array
700700 */
701701 public function getFieldDescriptions() {
@@ -703,12 +703,12 @@
704704
705705 /**
706706 * Get API parameters for the fields supported by this object.
707 - *
 707+ *
708708 * @since 0.1
709 - *
 709+ *
710710 * @param boolean $requireParams
711711 * @param boolean $setDefaults
712 - *
 712+ *
713713 * @return array
714714 */
715715 public function getAPIParams( $requireParams = false, $setDefaults = false ) {
@@ -720,33 +720,33 @@
721721 'bool' => 'integer',
722722 'array' => 'string'
723723 );
724 -
 724+
725725 $params = array();
726726 $defaults = $this->getDefaults();
727 -
 727+
728728 foreach ( $this->getFieldTypes() as $field => $type ) {
729729 if ( $field == 'id' ) {
730730 continue;
731731 }
732 -
 732+
733733 $hasDefault = array_key_exists( $field, $defaults );
734 -
 734+
735735 $params[$field] = array(
736736 ApiBase::PARAM_TYPE => $typeMap[$type],
737737 ApiBase::PARAM_REQUIRED => $requireParams && !$hasDefault
738738 );
739 -
 739+
740740 if ( $type == 'array' ) {
741741 $params[$field][ApiBase::PARAM_ISMULTI] = true;
742742 }
743 -
 743+
744744 if ( $setDefaults && $hasDefault ) {
745745 $default = is_array( $defaults[$field] ) ? implode( '|', $defaults[$field] ) : $defaults[$field];
746746 $params[$field][ApiBase::PARAM_DFLT] = $default;
747747 }
748748 }
749 -
 749+
750750 return $params;
751751 }
752 -
 752+
753753 }
Index: trunk/extensions/Contest/includes/ContestVote.php
@@ -2,59 +2,59 @@
33
44 /**
55 * 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+ *
88 * @since 0.1
9 - *
 9+ *
1010 * @file ContestComment.php
1111 * @ingroup Contest
12 - *
 12+ *
1313 * @licence GNU GPL v3 or later
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class ContestVote extends ContestDBObject {
17 -
 17+
1818 /**
1919 * Method to get an instance so methods that ought to be static,
2020 * but can't be due to PHP 5.2 not having LSB, can be called on
2121 * 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+ *
2424 * @since 0.1
25 - *
 25+ *
2626 * @return ContestDBObject
2727 */
2828 public static function s() {
2929 static $instance = false;
30 -
 30+
3131 if ( $instance === false ) {
3232 $instance = new self( array() );
3333 }
34 -
 34+
3535 return $instance;
3636 }
37 -
 37+
3838 /**
3939 * Get a new instance of the class from an array.
4040 * This method ought to be in the basic class and
4141 * return a new static(), but this requires LSB/PHP>=5.3.
42 - *
 42+ *
4343 * @since 0.1
44 - *
 44+ *
4545 * @param array $data
4646 * @param boolean $loadDefaults
47 - *
 47+ *
4848 * @return ContestDBObject
49 - */
 49+ */
5050 public function newFromArray( array $data, $loadDefaults = false ) {
5151 return new self( $data, $loadDefaults );
5252 }
53 -
 53+
5454 /**
5555 * @see parent::getFieldTypes
56 - *
 56+ *
5757 * @since 0.1
58 - *
 58+ *
5959 * @return string
6060 */
6161 public function getDBTable() {
@@ -63,20 +63,20 @@
6464
6565 /**
6666 * @see parent::getFieldTypes
67 - *
 67+ *
6868 * @since 0.1
69 - *
 69+ *
7070 * @return string
7171 */
7272 protected function getFieldPrefix() {
7373 return 'vote_';
7474 }
75 -
 75+
7676 /**
7777 * @see parent::getFieldTypes
78 - *
 78+ *
7979 * @since 0.1
80 - *
 80+ *
8181 * @return array
8282 */
8383 protected function getFieldTypes() {
@@ -84,37 +84,37 @@
8585 'id' => 'id',
8686 'contestant_id' => 'id',
8787 'user_id' => 'id',
88 -
 88+
8989 'value' => 'int',
9090 );
9191 }
92 -
 92+
9393 /**
9494 * @see parent::getDefaults
95 - *
 95+ *
9696 * @since 0.1
97 - *
 97+ *
9898 * @return array
9999 */
100100 public function getDefaults() {
101101 return array(
102102 );
103103 }
104 -
 104+
105105 /**
106106 * (non-PHPdoc)
107107 * @see ContestDBObject::writeToDB()
108108 */
109109 public function writeToDB() {
110110 $success = parent::writeToDB();
111 -
 111+
112112 if ( $success ) {
113113 $contestant = new ContestContestant( array( 'id' => $this->getField( 'contestant_id' ) ) );
114114 $contestant->updateVotes();
115115 $contestant->writeToDB();
116116 }
117 -
 117+
118118 return $success;
119119 }
120 -
 120+
121121 }
Index: trunk/extensions/Contest/includes/ContestReminderJob.php
@@ -2,20 +2,20 @@
33
44 /**
55 * Contest reminder job for email reminders.
6 - *
 6+ *
77 * @since 0.1
8 - *
 8+ *
99 * @file ContestReminderJob.php
1010 * @ingroup Contest
11 - *
 11+ *
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 class ContestReminderJob extends Job {
16 -
 16+
1717 /**
1818 * Constructor.
19 - *
 19+ *
2020 * @param Title $title
2121 * @param array $params
2222 * * contestants, array of ContestContestant, required
@@ -41,5 +41,5 @@
4242
4343 return true;
4444 }
45 -
 45+
4646 }
Index: trunk/extensions/Contest/includes/ContestUtils.php
@@ -2,70 +2,70 @@
33
44 /**
55 * Utility functions for the Contest extension.
6 - *
 6+ *
77 * @since 0.1
8 - *
 8+ *
99 * @file ContestUtils.php
1010 * @ingroup Contest
11 - *
 11+ *
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 class ContestUtils {
16 -
 16+
1717 /**
1818 * Gets the content of the article with the provided page name,
1919 * or an empty string when there is no such article.
20 - *
 20+ *
2121 * @since 0.1
22 - *
 22+ *
2323 * @param string $pageName
24 - *
 24+ *
2525 * @return string
2626 */
2727 public static function getArticleContent( $pageName ) {
2828 $title = Title::newFromText( $pageName );
29 -
 29+
3030 if ( is_null( $title ) ) {
3131 return '';
3232 }
33 -
 33+
3434 $article = new Article( $title, 0 );
3535 return $article->fetchContent();
3636 }
37 -
 37+
3838 /**
3939 * Gets the content of the article with the provided page name,
4040 * or an empty string when there is no such article.
41 - *
 41+ *
4242 * @since 0.1
43 - *
 43+ *
4444 * @param string $pageName
45 - *
 45+ *
4646 * @return string
4747 */
4848 public static function getParsedArticleContent( $pageName ) {
4949 $title = Title::newFromText( $pageName );
50 -
 50+
5151 if ( is_null( $title ) ) {
5252 return '';
5353 }
54 -
 54+
5555 $article = new Article( $title, 0 );
56 -
 56+
5757 global $wgParser, $wgContestEmailParse;
58 -
 58+
5959 $wgContestEmailParse = true;
60 -
 60+
6161 $text = $wgParser->parse(
6262 $article->fetchContent(),
6363 $article->getTitle(),
6464 $article->getParserOptions()
6565 )->getText();
66 -
 66+
6767 $wgContestEmailParse = false;
68 -
 68+
6969 return $text;
7070 }
71 -
 71+
7272 }
Index: trunk/extensions/Contest/includes/ContestantPager.php
@@ -2,29 +2,29 @@
33
44 /**
55 * Contestant pager, for on Special:Contest
6 - *
 6+ *
77 * @since 0.1
8 - *
 8+ *
99 * @file ContestantPager.php
1010 * @ingroup Contest
11 - *
 11+ *
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 class ContestantPager extends TablePager {
16 -
 16+
1717 /**
1818 * Query conditions, full field names (ie inc prefix).
1919 * @var array
2020 */
2121 protected $conds;
22 -
 22+
2323 /**
2424 * Special page on which the pager is displayed.
2525 * @var SpecialContestPage
2626 */
2727 protected $page;
28 -
 28+
2929 /**
3030 * Cache for challenge titles.
3131 * challenge id => challenge title
@@ -34,7 +34,7 @@
3535
3636 /**
3737 * Constructor.
38 - *
 38+ *
3939 * @param SpecialContestPage $page
4040 * @param array $conds
4141 */
@@ -42,45 +42,45 @@
4343 $this->page = $page;
4444 $this->conds = $conds;
4545 $this->mDefaultDirection = true;
46 -
 46+
4747 $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.
5050 parent::__construct();
51 -
 51+
5252 $this->getOutput()->addModules( 'contest.contestant.pager' );
5353 }
54 -
 54+
5555 /**
5656 * Query all challenge names we might need,
5757 * based on the queries conditions, and set them
5858 * to the challengeTitles field.
59 - *
 59+ *
6060 * @since 0.1
61 - *
 61+ *
6262 * @param array $allConds
6363 */
6464 protected function queryChallengeTitles( array $allConds ) {
6565 $conds = array();
66 -
 66+
6767 if ( array_key_exists( 'contestant_contest_id', $allConds ) ) {
6868 $conds['contest_id'] = $allConds['contestant_contest_id'];
6969 }
70 -
 70+
7171 if ( array_key_exists( 'contestant_challenge_id', $allConds ) ) {
7272 $conds['id'] = $allConds['contestant_challenge_id'];
7373 }
74 -
 74+
7575 foreach ( ContestChallenge::s()->select( array( 'id', 'title' ), $conds ) as /* ContestChallenge */ $challenge ) {
7676 $this->challengeTitles[$challenge->getId()] = $challenge->getField( 'title' );
7777 }
7878 }
79 -
 79+
8080 /**
8181 * Gets the title of a challenge given it's id.
82 - *
 82+ *
8383 * @since 0.1
84 - *
 84+ *
8585 * @param integer $challengeId
8686 * @throws MWException
8787 */
@@ -91,11 +91,11 @@
9292 else {
9393 throw new MWException( 'Attempt to get non-set challenge title' );
9494 }
95 - }
96 -
 95+ }
 96+
9797 /**
9898 * Get the OutputPage being used for this instance.
99 - * IndexPager extends ContextSource as of 1.19.
 99+ * IndexPager extends ContextSource as of 1.19.
100100 *
101101 * @since 0.1
102102 *
@@ -104,10 +104,10 @@
105105 public function getOutput() {
106106 return version_compare( $GLOBALS['wgVersion'], '1.18', '>' ) ? parent::getOutput() : $GLOBALS['wgOut'];
107107 }
108 -
 108+
109109 /**
110110 * Get the Language being used for this instance.
111 - * IndexPager extends ContextSource as of 1.19.
 111+ * IndexPager extends ContextSource as of 1.19.
112112 *
113113 * @since 0.1
114114 *
@@ -129,7 +129,7 @@
130130 'contestant_comments' => 'contest-contestant-commentcount',
131131 'contestant_rating' => 'contest-contestant-overallrating',
132132 );
133 -
 133+
134134 $headers = array_map( 'wfMsg', $headers );
135135 }
136136
@@ -139,32 +139,32 @@
140140 function formatRow( $row ) {
141141 $this->mCurrentRow = $row; # In case formatValue etc need to know
142142 $s = Xml::openElement( 'tr', $this->getRowAttrs($row) );
143 -
 143+
144144 foreach ( $this->getFieldNames() as $field => $name ) {
145145 $value = isset( $row->$field ) ? $row->$field : null;
146146 $formatted = strval( $this->formatValue( $field, $value ) );
147 -
 147+
148148 if ( $formatted == '' ) {
149149 $formatted = '&#160;';
150150 }
151151 $s .= Xml::tags( 'td', $this->getCellAttrs( $field, $value ), $formatted );
152152 }
153153 $s .= "</tr>\n";
154 -
 154+
155155 return $s;
156156 }
157 -
 157+
158158 function getRowAttrs( $row ) {
159159 return array_merge(
160160 parent::getRowAttrs( $row ),
161161 array( 'data-contestant-target' => SpecialPage::getTitleFor( 'Contestant', $row->contestant_id )->getLocalURL() )
162162 );
163163 }
164 -
 164+
165165 function getRowClass( $row ) {
166166 return 'contestant-row';
167167 }
168 -
 168+
169169 public function formatValue( $name, $value ) {
170170 switch ( $name ) {
171171 case 'contestant_id':
@@ -205,7 +205,7 @@
206206 ) );
207207 break;
208208 }
209 -
 209+
210210 return $value;
211211 }
212212
@@ -256,5 +256,5 @@
257257 function getTitle() {
258258 return $this->page->getFullTitle();
259259 }
260 -
 260+
261261 }
Index: trunk/extensions/Contest/includes/ContestChallenge.php
@@ -2,59 +2,59 @@
33
44 /**
55 * 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+ *
88 * @since 0.1
9 - *
 9+ *
1010 * @file ContestChallenge.php
1111 * @ingroup Contest
12 - *
 12+ *
1313 * @licence GNU GPL v3 or later
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class ContestChallenge extends ContestDBObject {
17 -
 17+
1818 /**
1919 * Method to get an instance so methods that ought to be static,
2020 * but can't be due to PHP 5.2 not having LSB, can be called on
2121 * 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+ *
2424 * @since 0.1
25 - *
 25+ *
2626 * @return ContestDBObject
2727 */
2828 public static function s() {
2929 static $instance = false;
30 -
 30+
3131 if ( $instance === false ) {
3232 $instance = new self( array() );
3333 }
34 -
 34+
3535 return $instance;
3636 }
37 -
 37+
3838 /**
3939 * Get a new instance of the class from an array.
4040 * This method ought to be in the basic class and
4141 * return a new static(), but this requires LSB/PHP>=5.3.
42 - *
 42+ *
4343 * @since 0.1
44 - *
 44+ *
4545 * @param array $data
4646 * @param boolean $loadDefaults
47 - *
 47+ *
4848 * @return ContestDBObject
49 - */
 49+ */
5050 public function newFromArray( array $data, $loadDefaults = false ) {
5151 return new self( $data, $loadDefaults );
5252 }
53 -
 53+
5454 /**
5555 * @see parent::getFieldTypes
56 - *
 56+ *
5757 * @since 0.1
58 - *
 58+ *
5959 * @return string
6060 */
6161 public function getDBTable() {
@@ -63,20 +63,20 @@
6464
6565 /**
6666 * @see parent::getFieldTypes
67 - *
 67+ *
6868 * @since 0.1
69 - *
 69+ *
7070 * @return string
7171 */
7272 protected function getFieldPrefix() {
7373 return 'challenge_';
7474 }
75 -
 75+
7676 /**
7777 * @see parent::getFieldTypes
78 - *
 78+ *
7979 * @since 0.1
80 - *
 80+ *
8181 * @return array
8282 */
8383 protected function getFieldTypes() {
@@ -88,12 +88,12 @@
8989 'oneline' => 'str',
9090 );
9191 }
92 -
 92+
9393 /**
9494 * @see parent::getDefaults
95 - *
 95+ *
9696 * @since 0.1
97 - *
 97+ *
9898 * @return array
9999 */
100100 public function getDefaults() {
@@ -103,24 +103,24 @@
104104 'oneline' => '',
105105 );
106106 }
107 -
 107+
108108 /**
109109 * 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+ *
112112 * @param array|integer $ids
113 - *
 113+ *
114114 * @return array( id => title )
115115 */
116116 public static function getTitlesForIds( $ids ) {
117117 $challenges = self::s()->select( array( 'id', 'title' ), array( 'id' => $ids ) );
118118 $results = array();
119 -
 119+
120120 foreach ( $challenges as /* ContestChallenge */ $challenge ) {
121121 $results[$challenge->getId()] = $challenge->getField( 'title' );
122122 }
123 -
 123+
124124 return $results;
125125 }
126 -
 126+
127127 }
Index: trunk/extensions/Contest/includes/ContestComment.php
@@ -2,59 +2,59 @@
33
44 /**
55 * 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+ *
88 * @since 0.1
9 - *
 9+ *
1010 * @file ContestComment.php
1111 * @ingroup Contest
12 - *
 12+ *
1313 * @licence GNU GPL v3 or later
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class ContestComment extends ContestDBObject {
17 -
 17+
1818 /**
1919 * Method to get an instance so methods that ought to be static,
2020 * but can't be due to PHP 5.2 not having LSB, can be called on
2121 * 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+ *
2424 * @since 0.1
25 - *
 25+ *
2626 * @return ContestDBObject
2727 */
2828 public static function s() {
2929 static $instance = false;
30 -
 30+
3131 if ( $instance === false ) {
3232 $instance = new self( array() );
3333 }
34 -
 34+
3535 return $instance;
3636 }
37 -
 37+
3838 /**
3939 * Get a new instance of the class from an array.
4040 * This method ought to be in the basic class and
4141 * return a new static(), but this requires LSB/PHP>=5.3.
42 - *
 42+ *
4343 * @since 0.1
44 - *
 44+ *
4545 * @param array $data
4646 * @param boolean $loadDefaults
47 - *
 47+ *
4848 * @return ContestDBObject
49 - */
 49+ */
5050 public function newFromArray( array $data, $loadDefaults = false ) {
5151 return new self( $data, $loadDefaults );
5252 }
53 -
 53+
5454 /**
5555 * @see parent::getFieldTypes
56 - *
 56+ *
5757 * @since 0.1
58 - *
 58+ *
5959 * @return string
6060 */
6161 public function getDBTable() {
@@ -63,20 +63,20 @@
6464
6565 /**
6666 * @see parent::getFieldTypes
67 - *
 67+ *
6868 * @since 0.1
69 - *
 69+ *
7070 * @return string
7171 */
7272 protected function getFieldPrefix() {
7373 return 'comment_';
7474 }
75 -
 75+
7676 /**
7777 * @see parent::getFieldTypes
78 - *
 78+ *
7979 * @since 0.1
80 - *
 80+ *
8181 * @return array
8282 */
8383 protected function getFieldTypes() {
@@ -84,17 +84,17 @@
8585 'id' => 'id',
8686 'contestant_id' => 'id',
8787 'user_id' => 'id',
88 -
 88+
8989 'text' => 'str',
9090 'time' => 'int',
9191 );
9292 }
93 -
 93+
9494 /**
9595 * @see parent::getDefaults
96 - *
 96+ *
9797 * @since 0.1
98 - *
 98+ *
9999 * @return array
100100 */
101101 public function getDefaults() {
@@ -103,20 +103,20 @@
104104 'time' => 0,
105105 );
106106 }
107 -
 107+
108108 /**
109109 * (non-PHPdoc)
110110 * @see ContestDBObject::insertIntoDB()
111111 */
112112 protected function insertIntoDB() {
113113 $success = parent::insertIntoDB();
114 -
 114+
115115 if ( $success ) {
116116 $contestant = new ContestContestant( array( 'id' => $this->getField( 'contestant_id' ) ) );
117117 $contestant->addToField( 'comments', 1 );
118118 }
119 -
 119+
120120 return $success;
121121 }
122 -
 122+
123123 }
Index: trunk/extensions/Contest/includes/ContestContestant.php
@@ -2,69 +2,69 @@
33
44 /**
55 * 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+ *
88 * @since 0.1
9 - *
 9+ *
1010 * @file ContestContestant.php
1111 * @ingroup Contest
12 - *
 12+ *
1313 * @licence GNU GPL v3 or later
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class ContestContestant extends ContestDBObject {
17 -
 17+
1818 protected $contest = null;
19 -
 19+
2020 /**
2121 * Cached user object, created from the user_id field.
22 - *
 22+ *
2323 * @since 0.1
2424 * @var USer
2525 */
2626 protected $user = null;
27 -
 27+
2828 /**
2929 * Method to get an instance so methods that ought to be static,
3030 * but can't be due to PHP 5.2 not having LSB, can be called on
3131 * 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+ *
3434 * @since 0.1
35 - *
 35+ *
3636 * @return ContestDBObject
3737 */
3838 public static function s() {
3939 static $instance = false;
40 -
 40+
4141 if ( $instance === false ) {
4242 $instance = new self( array() );
4343 }
44 -
 44+
4545 return $instance;
4646 }
47 -
 47+
4848 /**
4949 * Get a new instance of the class from an array.
5050 * This method ought to be in the basic class and
5151 * return a new static(), but this requires LSB/PHP>=5.3.
52 - *
 52+ *
5353 * @since 0.1
54 - *
 54+ *
5555 * @param array $data
5656 * @param boolean $loadDefaults
57 - *
 57+ *
5858 * @return ContestDBObject
59 - */
 59+ */
6060 public function newFromArray( array $data, $loadDefaults = false ) {
6161 return new self( $data, $loadDefaults );
6262 }
63 -
 63+
6464 /**
6565 * @see parent::getFieldTypes
66 - *
 66+ *
6767 * @since 0.1
68 - *
 68+ *
6969 * @return string
7070 */
7171 public function getDBTable() {
@@ -73,20 +73,20 @@
7474
7575 /**
7676 * @see parent::getFieldTypes
77 - *
 77+ *
7878 * @since 0.1
79 - *
 79+ *
8080 * @return string
8181 */
8282 protected function getFieldPrefix() {
8383 return 'contestant_';
8484 }
85 -
 85+
8686 /**
8787 * @see parent::getFieldTypes
88 - *
 88+ *
8989 * @since 0.1
90 - *
 90+ *
9191 * @return array
9292 */
9393 protected function getFieldTypes() {
@@ -95,29 +95,29 @@
9696 'contest_id' => 'id',
9797 'challenge_id' => 'id',
9898 'user_id' => 'id',
99 -
 99+
100100 'full_name' => 'str',
101101 'user_name' => 'str',
102102 'email' => 'str',
103 -
 103+
104104 'country' => 'str',
105105 'volunteer' => 'bool',
106106 'wmf' => 'bool',
107107 'cv' => 'str',
108 -
 108+
109109 'submission' => 'str',
110 -
 110+
111111 'rating' => 'float',
112112 'rating_count' => 'int',
113113 'comments' => 'int',
114114 );
115115 }
116 -
 116+
117117 /**
118118 * @see parent::getDefaults
119 - *
 119+ *
120120 * @since 0.1
121 - *
 121+ *
122122 * @return array
123123 */
124124 public function getDefaults() {
@@ -125,87 +125,87 @@
126126 'full_name' => '',
127127 'user_name' => '',
128128 'email' => '',
129 -
 129+
130130 'country' => '',
131131 'volunteer' => false,
132132 'wmf' => false,
133133 'cv' => false,
134 -
 134+
135135 'submission' => '',
136 -
 136+
137137 'rating' => 0,
138138 'rating_count' => 0,
139139 'comments' => 0,
140140 );
141141 }
142 -
 142+
143143 /**
144144 * Gets the contest for this participant.
145 - *
 145+ *
146146 * @since 0.1
147 - *
 147+ *
148148 * @param array|string|null $fields The fields to load, null for all fields.
149 - *
 149+ *
150150 * @return Contest
151151 */
152152 public function getContest( $fields = null ) {
153153 if ( !is_null( $this->contest ) ) {
154154 return $this->contest;
155155 }
156 -
 156+
157157 $contest = Contest::s()->selectRow( $fields, array( 'id' => $this->getField( 'contest_id' ) ) );
158 -
 158+
159159 if ( is_null( $this->contest ) && is_null( $fields ) ) {
160160 $this->contest = $contest;
161161 }
162 -
 162+
163163 return $contest;
164164 }
165 -
 165+
166166 /**
167167 * Sets the contest for this participant.
168 - *
 168+ *
169169 * @since 0.1
170 - *
 170+ *
171171 * @param Contest $contest
172172 */
173173 public function setContest( Contest $contest ) {
174174 $this->contest = $contest;
175175 }
176 -
 176+
177177 /**
178178 * Returns a list of countries and their corresponding country
179179 * codes that can be fed directly into an HTML input.
180 - *
 180+ *
181181 * @since 0.1
182 - *
 182+ *
183183 * @param booolean $addEmptyItem
184 - *
 184+ *
185185 * @return array
186186 */
187187 public static function getCountriesForInput( $addEmptyItem = false ) {
188188 $countries = array();
189 -
 189+
190190 if ( $addEmptyItem ) {
191191 $countries[''] = '';
192192 }
193 -
 193+
194194 foreach ( self::getCountries() as $code => $name ) {
195195 $countries["$code - $name"] = $code;
196196 }
197 -
 197+
198198 return $countries;
199199 }
200 -
 200+
201201 /**
202202 * Returns a list of ISO 3166-1-alpha-2 country codes (keys) and their corresponding country (values).
203 - *
 203+ *
204204 * @since 0.1
205 - *
 205+ *
206206 * @return array
207207 */
208208 public static function getCountries() {
209 - return array(
 209+ return array(
210210 'AF' => 'Afghanistan',
211211 'AL' => 'Albania',
212212 'DZ' => 'Algeria',
@@ -447,58 +447,58 @@
448448 'ZW' => 'Zimbabwe'
449449 );
450450 }
451 -
 451+
452452 /**
453453 * (non-PHPdoc)
454454 * @see ContestDBObject::insertIntoDB()
455455 */
456456 protected function insertIntoDB() {
457457 wfRunHooks( 'ContestBeforeContestantInsert', array( &$this ) );
458 -
 458+
459459 $success = parent::insertIntoDB();
460 -
 460+
461461 if ( $success ) {
462462 $this->onUserSignup();
463463 }
464 -
 464+
465465 return $success;
466466 }
467 -
 467+
468468 /**
469469 * Handles successfull user signup for a contest.
470 - *
 470+ *
471471 * @since 0.1
472472 */
473473 protected function onUserSignup() {
474474 $this->getContest( array( 'id' ) )->addToSubmissionCount( 1 );
475 -
 475+
476476 $this->getUser()->setOption( 'contest_showtoplink', true );
477477 $this->getUser()->saveSettings(); // TODO: can't we just save this single option instead of everything?
478 -
 478+
479479 $this->sendSignupEmail();
480 -
 480+
481481 wfRunHooks( 'ContestAfterContestantInsert', array( &$this ) );
482482 }
483 -
 483+
484484 /**
485485 * Send the signup email.
486 - *
 486+ *
487487 * @since 0.1
488 - *
 488+ *
489489 * @return Status
490490 */
491491 public function sendSignupEmail() {
492492 global $wgPasswordSender, $wgPasswordSenderName;
493 -
 493+
494494 $title = wfMsg( 'contest-email-signup-title' );
495495 $emailText = ContestUtils::getParsedArticleContent( $this->getContest()->getField( 'signup_email' ) );
496496 $user = $this->getUser();
497497 $sender = $wgPasswordSender;
498498 $senderName = $wgPasswordSenderName;
499 -
 499+
500500 wfRunHooks( 'ContestBeforeSignupEmail', array( &$this, &$title, &$emailText, &$user, &$sender, &$senderName ) );
501 -
502 - return UserMailer::send(
 501+
 502+ return UserMailer::send(
503503 new MailAddress( $user ),
504504 new MailAddress( $sender, $senderName ),
505505 $title,
@@ -507,29 +507,29 @@
508508 'text/html; charset=ISO-8859-1'
509509 );
510510 }
511 -
 511+
512512 /**
513513 * Send a reminder email.
514 - *
 514+ *
515515 * @since 0.1
516 - *
 516+ *
517517 * @return Status
518518 */
519519 public function sendReminderEmail( $emailText, array $params = array() ) {
520520 global $wgPasswordSender, $wgPasswordSenderName;
521 -
 521+
522522 if ( !array_key_exists( 'daysLeft', $params ) ) {
523523 $params['daysLeft'] = $this->getContest()->getDaysLeft();
524524 }
525 -
 525+
526526 $title = wfMsgExt( 'contest-email-reminder-title', 'parsemag', $params['daysLeft'] );
527527 $user = $this->getUser();
528528 $sender = $wgPasswordSender;
529529 $senderName = $wgPasswordSenderName;
530 -
 530+
531531 wfRunHooks( 'ContestBeforeReminderEmail', array( &$this, &$title, &$emailText, &$user, &$sender, &$senderName ) );
532 -
533 - return UserMailer::send(
 532+
 533+ return UserMailer::send(
534534 new MailAddress( $user ),
535535 new MailAddress( $sender, $senderName ),
536536 $title,
@@ -538,64 +538,64 @@
539539 'text/html; charset=ISO-8859-1'
540540 );
541541 }
542 -
 542+
543543 /**
544544 * Update the vote count and avarage vote fields.
545545 * This does not write the changes to the database,
546546 * if this is required, call writeToDB.
547 - *
 547+ *
548548 * @since 0.1
549549 */
550550 public function updateVotes() {
551551 $votes = $this->getVotes();
552 -
 552+
553553 $amount = count( $votes );
554554 $total = 0;
555 -
 555+
556556 foreach ( $votes as /* ContestVote */ $vote ) {
557557 $total += $vote->getField( 'value' );
558558 }
559 -
 559+
560560 $this->setField( 'rating_count', $amount );
561561 $this->setField( 'rating', $amount > 0 ? $total / $amount : 0 );
562562 }
563 -
 563+
564564 /**
565565 * Returns the user object for this contestant, created
566566 * from the user_id field and cached in $this->user.
567 - *
 567+ *
568568 * @since 0.1
569 - *
 569+ *
570570 * @return User
571571 */
572572 public function getUser() {
573573 if ( is_null( $this->user ) ) {
574574 $this->user = User::newFromId( $this->getField( 'user_id' ) );
575575 }
576 -
 576+
577577 return $this->user;
578578 }
579 -
 579+
580580 /**
581581 * Get the votes for this contestant.
582 - *
 582+ *
583583 * @since 0.1
584 - *
 584+ *
585585 * @return array of ContestVote
586586 */
587587 public function getVotes() {
588588 return ContestVote::s()->select( null, array( 'contestant_id' => $this->getId() ) );
589589 }
590 -
 590+
591591 /**
592592 * Get the comments for this contestant.
593 - *
 593+ *
594594 * @since 0.1
595 - *
 595+ *
596596 * @return array of ContestComment
597597 */
598598 public function getComments() {
599599 return ContestComment::s()->select( null, array( 'contestant_id' => $this->getId() ) );
600600 }
601 -
 601+
602602 }
Index: trunk/extensions/Contest/includes/Contest.class.php
@@ -2,91 +2,91 @@
33
44 /**
55 * Class representing a single contest.
6 - *
 6+ *
77 * @since 0.1
8 - *
 8+ *
99 * @file Contest.class.php
1010 * @ingroup Contest
11 - *
 11+ *
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
1515 class Contest extends ContestDBObject {
16 -
 16+
1717 // Constants representing the states a contest can have.
1818 const STATUS_DRAFT = 0;
1919 const STATUS_ACTIVE = 1;
2020 const STATUS_FINISHED = 2; // manually stopped by contest manager
2121 const STATUS_EXPIRED = 3; // past configured contest end date
22 -
 22+
2323 /**
2424 * List of challenges for this contest.
2525 * @see loadChallenges, setChallenges and writeChallengesToDB
26 - *
 26+ *
2727 * @since 0.1
2828 * @var array of ContestChallenge
2929 */
3030 protected $challenges = null;
31 -
 31+
3232 /**
3333 * List of contestants for this contest.
3434 * @see loadContestants, setContestants and writeContestantsToDB
35 - *
 35+ *
3636 * @since 0.1
3737 * @var array of ContestContestant
3838 */
3939 protected $contestants = null;
40 -
 40+
4141 /**
4242 * Indicates if the contest was set from non-finished to finished.
4343 * This is used to take further action on save of the object.
44 - *
 44+ *
4545 * @since 0.1
4646 * @var boolean
4747 */
4848 protected $wasSetToFinished = false;
49 -
 49+
5050 /**
5151 * Method to get an instance so methods that ought to be static,
5252 * but can't be due to PHP 5.2 not having LSB, can be called on
5353 * 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+ *
5656 * @since 0.1
57 - *
 57+ *
5858 * @return ContestDBObject
5959 */
6060 public static function s() {
6161 static $instance = false;
62 -
 62+
6363 if ( $instance === false ) {
6464 $instance = new self( array() );
6565 }
66 -
 66+
6767 return $instance;
6868 }
69 -
 69+
7070 /**
71 - * Get a new instance of the class from an array.
 71+ * Get a new instance of the class from an array.
7272 * This method ought to be in the basic class and
7373 * return a new static(), but this requires LSB/PHP>=5.3.
74 - *
 74+ *
7575 * @since 0.1
76 - *
 76+ *
7777 * @param array $data
7878 * @param boolean $loadDefaults
79 - *
 79+ *
8080 * @return ContestDBObject
81 - */
 81+ */
8282 public function newFromArray( array $data, $loadDefaults = false ) {
8383 return new self( $data, $loadDefaults );
8484 }
85 -
 85+
8686 /**
8787 * @see parent::getFieldTypes
88 - *
 88+ *
8989 * @since 0.1
90 - *
 90+ *
9191 * @return string
9292 */
9393 public function getDBTable() {
@@ -95,20 +95,20 @@
9696
9797 /**
9898 * @see parent::getFieldTypes
99 - *
 99+ *
100100 * @since 0.1
101 - *
 101+ *
102102 * @return string
103103 */
104104 protected function getFieldPrefix() {
105105 return 'contest_';
106106 }
107 -
 107+
108108 /**
109109 * @see parent::getFieldTypes
110 - *
 110+ *
111111 * @since 0.1
112 - *
 112+ *
113113 * @return array
114114 */
115115 protected function getFieldTypes() {
@@ -117,23 +117,23 @@
118118 'name' => 'str',
119119 'status' => 'int',
120120 'end' => 'str', // TS_MW
121 -
 121+
122122 'rules_page' => 'str',
123123 'opportunities' => 'str',
124124 'intro' => 'str',
125125 'help' => 'str',
126126 'signup_email' => 'str',
127127 'reminder_email' => 'str',
128 -
 128+
129129 'submission_count' => 'int',
130130 );
131131 }
132 -
 132+
133133 /**
134134 * @see parent::getDefaults
135 - *
 135+ *
136136 * @since 0.1
137 - *
 137+ *
138138 * @return array
139139 */
140140 public function getDefaults() {
@@ -141,47 +141,47 @@
142142 'name' => '',
143143 'status' => self::STATUS_DRAFT,
144144 'end' => '',
145 -
 145+
146146 'rules_page' => 'MediaWiki:Contests/',
147147 'opportunities' => 'MediaWiki:Contests/',
148148 'intro' => 'MediaWiki:Contests/',
149149 'help' => '',
150150 'signup_email' => 'MediaWiki:Contests/',
151151 'reminder_email' => 'MediaWiki:Contests/',
152 -
 152+
153153 'submission_count' => 0,
154154 );
155155 }
156 -
 156+
157157 /**
158158 * Gets the message for the provided status.
159 - *
 159+ *
160160 * @param Contest::STATUS_ $status
161 - *
 161+ *
162162 * @return string
163163 */
164164 public static function getStatusMessage( $status ) {
165165 static $map = false;
166 -
 166+
167167 if ( $map === false ) {
168168 $map = array_flip( self::getStatusMessages() );
169169 }
170 -
 170+
171171 return $map[$status];
172172 }
173 -
 173+
174174 /**
175175 * Returns a list of status messages and their corresponding constants.
176 - *
 176+ *
177177 * @param boolean $onlySettable Whether to return only messages for modifiable status.
178 - *
 178+ *
179179 * @since 0.1
180 - *
 180+ *
181181 * @return array
182182 */
183183 public static function getStatusMessages( $onlySettable = false ) {
184184 static $map = false;
185 -
 185+
186186 if ( $map === false ) {
187187 $map = array(
188188 wfMsg( 'contest-status-draft' ) => self::STATUS_DRAFT,
@@ -192,11 +192,11 @@
193193 if (!$onlySettable) $map[wfMsg( 'contest-status-expired')] = self::STATUS_EXPIRED;
194194 return $map;
195195 }
196 -
 196+
197197 /**
198198 * Load the challenges from the database.
199199 * Any set challenges will be lost.
200 - *
 200+ *
201201 * @since 0.1
202202 */
203203 public function loadChallenges() {
@@ -205,26 +205,26 @@
206206 array( 'contest_id' => $this->getId() )
207207 );
208208 }
209 -
 209+
210210 /**
211211 * Gets the challenges that are part of this contest.
212 - *
 212+ *
213213 * @since 0.1
214 - *
 214+ *
215215 * @return array of ContestChallenge
216216 */
217217 public function getChallenges( $forceLoad = false ) {
218218 if ( is_null( $this->challenges ) || $forceLoad ) {
219219 $this->loadChallenges();
220220 }
221 -
 221+
222222 return $this->challenges;
223223 }
224 -
 224+
225225 /**
226226 * Load the contestants from the database.
227227 * Any set contestants will be lost.
228 - *
 228+ *
229229 * @since 0.1
230230 */
231231 public function loadContestants() {
@@ -233,153 +233,153 @@
234234 array( 'contest_id' => $this->getId() )
235235 );
236236 }
237 -
 237+
238238 /**
239239 * Gets the contestants for this contest.
240 - *
 240+ *
241241 * @since 0.1
242 - *
 242+ *
243243 * @return array of ContestContestant
244244 */
245245 public function getContestants( $forceLoad = false ) {
246246 if ( is_null( $this->contestants ) || $forceLoad ) {
247247 $this->loadContestants();
248248 }
249 -
 249+
250250 return $this->contestants;
251251 }
252 -
 252+
253253 /**
254254 * Set the contestants for this contest.
255 - *
 255+ *
256256 * @since 0.1
257 - *
 257+ *
258258 * @param array $contestants
259259 */
260260 public function setContestants( array /* of ContestContestant */ $contestants ) {
261261 $this->contestants = $contestants;
262262 }
263 -
 263+
264264 /**
265265 * Set the challenges for this contest.
266 - *
 266+ *
267267 * @since 0.1
268 - *
 268+ *
269269 * @param array $challenges
270270 */
271271 public function setChallenges( array /* of ContestChallenge */ $challenges ) {
272272 $this->challenges = $challenges;
273273 }
274 -
 274+
275275 /**
276276 * (non-PHPdoc)
277277 * @see ContestDBObject::writeToDB()
278278 */
279279 public function writeToDB() {
280280 $success = parent::writeToDB();
281 -
 281+
282282 if ( $success && $this->wasSetToFinished ) {
283283 $this->doFinishActions();
284284 $this->wasSetToFinished = false;
285285 }
286 -
 286+
287287 return $success;
288288 }
289 -
 289+
290290 /**
291291 * Write the contest and all set challenges and participants to the database.
292 - *
 292+ *
293293 * @since 0.1
294 - *
 294+ *
295295 * @return boolean Success indicator
296296 */
297297 public function writeAllToDB() {
298298 $success = self::writeToDB();
299 -
 299+
300300 if ( $success ) {
301301 $success = $this->writeChallengesToDB();
302302 }
303 -
 303+
304304 if ( $success ) {
305305 $success = $this->writeContestantsToDB();
306306 }
307 -
 307+
308308 return $success;
309309 }
310 -
 310+
311311 /**
312312 * Write the challenges to the database.
313 - *
 313+ *
314314 * @since 0.1
315 - *
 315+ *
316316 * @return boolean Success indicator
317317 */
318318 public function writeChallengesToDB() {
319319 if ( is_null( $this->challenges ) || count( $this->challenges ) == 0 ) {
320320 return true;
321321 }
322 -
 322+
323323 $dbw = wfGetDB( DB_MASTER );
324324 $success = true;
325 -
 325+
326326 $dbw->begin();
327 -
 327+
328328 foreach ( $this->challenges as /* ContestChallenge */ $challenge ) {
329329 $challenge->setField( 'contest_id', $this->getId() );
330330 $success &= $challenge->writeToDB();
331331 }
332 -
 332+
333333 $dbw->commit();
334 -
 334+
335335 return $success;
336336 }
337 -
 337+
338338 /**
339339 * Write the contestants to the database.
340 - *
 340+ *
341341 * @since 0.1
342 - *
 342+ *
343343 * @return boolean Success indicator
344344 */
345345 public function writeContestantsToDB() {
346346 if ( is_null( $this->contestants ) || count( $this->contestants ) == 0 ) {
347347 return true;
348348 }
349 -
 349+
350350 $dbw = wfGetDB( DB_MASTER );
351351 $success = true;
352352 $nr = 0;
353 -
 353+
354354 $dbw->begin();
355 -
 355+
356356 foreach ( $this->contestants as /* ContestContestant */ $contestant ) {
357357 $contestant->setField( 'contest_id', $this->getId() );
358358 $success &= $contestant->writeToDB();
359 -
 359+
360360 if ( ++$nr % 500 == 0 ) {
361361 $dbw->commit();
362362 $dbw->begin();
363363 }
364364 }
365 -
 365+
366366 $dbw->commit();
367 -
 367+
368368 return $success;
369369 }
370 -
 370+
371371 /**
372372 * Add an amount (can be negative) to the total submissions for this contest.
373 - *
 373+ *
374374 * @since 0.1
375 - *
 375+ *
376376 * @param integer $amount
377 - *
 377+ *
378378 * @return boolean Success indicator
379379 */
380380 public function addToSubmissionCount( $amount ) {
381381 return parent::addToField( 'submission_count', $amount );
382382 }
383 -
 383+
384384 /**
385385 * (non-PHPdoc)
386386 * @see ContestDBObject::setField()
@@ -389,87 +389,87 @@
390390 && $this->hasField( $name ) && $this->getField( $name ) != self::STATUS_FINISHED ) {
391391 $this->wasSetToFinished = true;
392392 }
393 -
 393+
394394 parent::setField( $name, $value );
395395 }
396 -
 396+
397397 /**
398398 * Remove the contest and all it's linked data from the database.
399 - *
 399+ *
400400 * @since 0.1
401 - *
 401+ *
402402 * @return boolean Success indicator
403403 */
404404 public function removeAllFromDB() {
405405 $condition = array( 'contest_id' => $this->getId() );
406 -
 406+
407407 $success = ContestChallenge::s()->delete( $condition );
408 -
 408+
409409 if ( $success ) {
410410 $contestantIds = array();
411 -
 411+
412412 foreach ( ContestContestant::s()->select( 'id', $condition ) as /* ContestContestant */ $contestant ) {
413413 $contestantIds[] = $contestant->getId();
414414 }
415 -
 415+
416416 if ( count( $contestantIds ) > 0 ) {
417417 $success = ContestComment::s()->delete( array( 'contestant_id' => $contestantIds ) ) && $success;
418418 $success = ContestVote::s()->delete( array( 'contestant_id' => $contestantIds ) ) && $success;
419419 }
420 -
 420+
421421 $success = ContestContestant::s()->delete( $condition ) && $success;
422422 }
423 -
 423+
424424 if ( $success ) {
425425 $success = parent::removeFromDB();
426426 }
427 -
 427+
428428 return $success;
429 - }
430 -
 429+ }
 430+
431431 /**
432432 * Do all actions that need to be done on contest finish.
433 - *
 433+ *
434434 * @since 0.1
435435 */
436436 public function doFinishActions() {
437437 // TODO
438438 }
439 -
 439+
440440 /**
441441 * Gets the amount of time left, in seconds.
442 - *
 442+ *
443443 * @since 0.1
444 - *
 444+ *
445445 * @return integer
446446 */
447447 public function getTimeLeft() {
448448 return wfTimestamp( TS_UNIX, $this->getField( 'end' ) ) - time();
449449 }
450 -
 450+
451451 /**
452452 * Gets the amount of days left, rounded up to the nearest integer.
453 - *
 453+ *
454454 * @since 0.1
455 - *
 455+ *
456456 * @return integer
457457 */
458458 public function getDaysLeft() {
459459 return (int)ceil( $this->getTimeLeft() / ( 60 * 60 * 24 ) );
460460 }
461 -
 461+
462462 /*
463 - * Gets the contest status, which is either expired, or whatever the
 463+ * Gets the contest status, which is either expired, or whatever the
464464 * contest administrator has manually set it to. Only active contests will
465465 * be evaluated for expiry.
466 - *
 466+ *
467467 * @return integer status constant
468 - *
 468+ *
469469 **/
470470 public function getStatus() {
471 -
 471+
472472 $dbStatus = $this->getField('status');
473 -
 473+
474474 if ( $dbStatus === self::STATUS_ACTIVE && $this->getTimeLeft() <= 0 ) {
475475 return self::STATUS_EXPIRED;
476476 } else {
Index: trunk/extensions/Contest/api/ApiDeleteContest.php
@@ -13,47 +13,47 @@
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class ApiDeleteContest extends ApiBase {
17 -
 17+
1818 public function __construct( $main, $action ) {
1919 parent::__construct( $main, $action );
2020 }
21 -
 21+
2222 public function execute() {
2323 global $wgUser;
24 -
 24+
2525 if ( !$wgUser->isAllowed( 'contestadmin' ) || $wgUser->isBlocked() ) {
2626 $this->dieUsageMsg( array( 'badaccess-groups' ) );
2727 }
28 -
 28+
2929 $params = $this->extractRequestParams();
30 -
 30+
3131 $everythingOk = true;
32 -
 32+
3333 foreach ( $params['ids'] as $id ) {
3434 $contest = new Contest( array( 'id' => $id ) );
3535 $everythingOk = $contest->removeAllFromDB() && $everythingOk;
3636 }
37 -
 37+
3838 $this->getResult()->addValue(
3939 null,
4040 'success',
4141 $everythingOk
4242 );
4343 }
44 -
 44+
4545 public function needsToken() {
4646 return true;
4747 }
48 -
 48+
4949 public function getTokenSalt() {
5050 $params = $this->extractRequestParams();
5151 return 'deletecontest' . implode( '|', $params['ids'] );
5252 }
53 -
 53+
5454 public function mustBePosted() {
5555 return true;
5656 }
57 -
 57+
5858 public function getAllowedParams() {
5959 return array(
6060 'ids' => array(
@@ -64,20 +64,20 @@
6565 'token' => null,
6666 );
6767 }
68 -
 68+
6969 public function getParamDescription() {
7070 return array(
7171 'ids' => 'The IDs of the contests to delete',
7272 'token' => 'Edit token, salted with the contest id',
7373 );
7474 }
75 -
 75+
7676 public function getDescription() {
7777 return array(
7878 'API module for deleting contests.'
7979 );
8080 }
81 -
 81+
8282 public function getPossibleErrors() {
8383 return array_merge( parent::getPossibleErrors(), array(
8484 array( 'missingparam', 'ids' ),
@@ -89,10 +89,10 @@
9090 'api.php?action=deletecontest&ids=42',
9191 'api.php?action=deletecontest&ids=4|2',
9292 );
93 - }
94 -
 93+ }
 94+
9595 public function getVersion() {
9696 return __CLASS__ . ': $Id$';
97 - }
98 -
 97+ }
 98+
9999 }
Index: trunk/extensions/Contest/api/ApiContestQuery.php
@@ -14,28 +14,28 @@
1515 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1616 */
1717 abstract class ApiContestQuery extends ApiQueryBase {
18 -
 18+
1919 /**
20 - * Returns the class specific info.
 20+ * Returns the class specific info.
2121 * * class: name of the ContestDBObject deriving class (ie Contest)
2222 * * item: item name (ie contest)
2323 * * set: item set name (ie contests)
24 - *
 24+ *
2525 * @since 0.1
26 - *
 26+ *
2727 * @return array of string
2828 */
2929 protected abstract function getClassInfo();
30 -
 30+
3131 /**
3232 * Returns an instance of the ContestDBObject deriving class.
3333 * Once PHP 5.3 becomes an acceptable requirement, we
3434 * 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+ *
3737 * @since 0.1
38 - *
39 - * @return ContestDBClass
 38+ *
 39+ * @return ContestDBObject
4040 */
4141 protected function getClass() {
4242 $className = $this->getClassInfo();
@@ -46,71 +46,71 @@
4747 /**
4848 * Get the parameters, find out what the conditions for the query are,
4949 * run it, and add the results.
50 - *
 50+ *
5151 * @since 0.1
5252 */
5353 public function execute() {
5454 $params = $this->getParams();
55 -
 55+
5656 if ( count( $params['props'] ) > 0 ) {
5757 $results = $this->getResults( $params, $this->getConditions( $params ) );
5858 $this->addResults( $params, $results );
5959 }
6060 }
61 -
 61+
6262 /**
6363 * Get the request parameters, handle the * value for the props param
6464 * and remove all params set to null (ie those that are not actually provided).
65 - *
 65+ *
6666 * @since 0.1
67 - *
 67+ *
6868 * @return array
6969 */
7070 protected function getParams() {
7171 // Get the requests parameters.
7272 $params = $this->extractRequestParams();
73 -
 73+
7474 $starPropPosition = array_search( '*', $params['props'] );
75 -
 75+
7676 if ( $starPropPosition !== false ) {
7777 unset( $params['props'][$starPropPosition] );
7878 $params['props'] = array_merge( $params['props'], $this->getClass()->getFieldNames() );
7979 }
80 -
 80+
8181 return array_filter( $params, create_function( '$p', 'return isset( $p );' ) );
8282 }
83 -
 83+
8484 /**
8585 * Get the conditions for the query. These will be provided as
8686 * regular parameters, together with limit, props, continue,
8787 * and possibly others which we need to get rid off.
88 - *
 88+ *
8989 * @since 0.1
90 - *
 90+ *
9191 * @param array $params
92 - *
 92+ *
9393 * @return array
9494 */
9595 protected function getConditions( array $params ) {
9696 $conditions = array();
97 -
 97+
9898 foreach ( $params as $name => $value ) {
9999 if ( $this->getClass()->canHasField( $name ) ) {
100100 $conditions[$name] = $value;
101101 }
102102 }
103 -
 103+
104104 return $conditions;
105105 }
106 -
 106+
107107 /**
108108 * Get the actual results.
109 - *
 109+ *
110110 * @since 0.1
111 - *
 111+ *
112112 * @param array $params
113113 * @param array $conditions
114 - *
 114+ *
115115 * @return array of ContestDBClass
116116 */
117117 protected function getResults( array $params, array $conditions ) {
@@ -123,19 +123,19 @@
124124 )
125125 );
126126 }
127 -
 127+
128128 /**
129129 * Serialize the results and add them to the result object.
130 - *
 130+ *
131131 * @since 0.1
132 - *
 132+ *
133133 * @param array $params
134134 * @param array $results
135135 */
136136 protected function addResults( array $params, array /* of ContestDBObject */ $results ) {
137137 $serializedResults = array();
138138 $count = 0;
139 -
 139+
140140 foreach ( $results as $result ) {
141141 if ( ++$count > $params['limit'] ) {
142142 // We've reached the one extra which shows that
@@ -143,43 +143,43 @@
144144 $this->setContinueEnumParameter( 'continue', $result->getId() );
145145 break;
146146 }
147 -
 147+
148148 $serializedResults[] = $result->toArray( $params['props'] );
149149 }
150 -
 150+
151151 $this->setIndexedTagNames( $serializedResults );
152 - $this->addSerializedResults( $serializedResults );
 152+ $this->addSerializedResults( $serializedResults );
153153 }
154 -
 154+
155155 /**
156156 * Set the tag names for formats such as XML.
157 - *
 157+ *
158158 * @since 0.1
159 - *
 159+ *
160160 * @param array $serializedResults
161161 */
162162 protected function setIndexedTagNames( array &$serializedResults ) {
163163 $classInfo = $this->getClassInfo();
164164 $this->getResult()->setIndexedTagName( $serializedResults, $classInfo['item'] );
165165 }
166 -
 166+
167167 /**
168168 * Add the serialized results to the result object.
169 - *
 169+ *
170170 * @since 0.1
171 - *
 171+ *
172172 * @param array $serializedResults
173173 */
174174 protected function addSerializedResults( array $serializedResults ) {
175175 $classInfo = $this->getClassInfo();
176 -
 176+
177177 $this->getResult()->addValue(
178178 null,
179179 $classInfo['set'],
180180 $serializedResults
181181 );
182182 }
183 -
 183+
184184 /**
185185 * (non-PHPdoc)
186186 * @see includes/api/ApiBase#getAllowedParams()
@@ -200,7 +200,7 @@
201201 ),
202202 'continue' => null,
203203 );
204 -
 204+
205205 return array_merge( $this->getClass()->getAPIParams(), $params );
206206 }
207207
@@ -214,7 +214,7 @@
215215 'continue' => 'Offset number from where to continue the query',
216216 'limit' => 'Max amount of rows to return',
217217 );
218 -
 218+
219219 return array_merge( $this->getClass()->getFieldDescriptions(), $descs );
220220 }
221221
@@ -225,6 +225,6 @@
226226 public function getPossibleErrors() {
227227 return array_merge( parent::getPossibleErrors(), array(
228228 ) );
229 - }
230 -
 229+ }
 230+
231231 }
Index: trunk/extensions/Contest/api/ApiMailContestants.php
@@ -13,70 +13,70 @@
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class ApiMailContestants extends ApiBase {
17 -
 17+
1818 public function __construct( $main, $action ) {
1919 parent::__construct( $main, $action );
2020 }
21 -
 21+
2222 // TODO
2323 public function execute() {
2424 global $wgUser;
25 -
 25+
2626 if ( !$wgUser->isAllowed( 'contestadmin' ) || $wgUser->isBlocked() ) {
2727 $this->dieUsageMsg( array( 'badaccess-groups' ) );
2828 }
29 -
 29+
3030 $params = $this->extractRequestParams();
31 -
 31+
3232 $everythingOk = true;
33 -
 33+
3434 $contestIds = is_null( $params['contestids'] ) ? array() : $params['contestids'];
3535 $challengeIds = is_null( $params['challengeids'] ) ? array() : $params['challengeids'];
36 -
 36+
3737 if ( !is_null( $params['challengetitles'] ) ) {
3838 $challenges = ContestChallenge::s()->select( 'id', array( 'title' => $params['challengetitles'] ) );
39 -
 39+
4040 if ( $challenges === false ) {
4141 // TODO: error
4242 }
43 -
 43+
4444 foreach ( $challenges as /* ContestChallenge */ $challenge ) {
4545 $challengeIds[] = $challenge->getId();
4646 }
4747 }
48 -
 48+
4949 if ( !is_null( $params['contestnames'] ) ) {
5050 $contests = Contest::s()->select( 'id', array( 'name' => $params['contestnames'] ) );
51 -
 51+
5252 if ( $contests === false ) {
5353 // TODO: error
5454 }
55 -
 55+
5656 foreach ( $contests as /* Contest */ $contest ) {
5757 $contestIds[] = $contest->getId();
5858 }
5959 }
60 -
 60+
6161 $conditions = array();
62 -
 62+
6363 if ( count( $contestIds ) > 0 ) {
6464 $conditions['contest_id'] = $contestIds;
6565 }
66 -
 66+
6767 if ( count( $challengeIds ) > 0 ) {
6868 $conditions['challenge_id'] = $challengeIds;
6969 }
70 -
 70+
7171 if ( !is_null( $params['ids'] ) && count( $params['ids'] ) > 0 ) {
7272 $conditions['id'] = $params['ids'];
7373 }
74 -
 74+
7575 $contestants = ContestContestant::s()->select( 'email', $conditions );
76 -
 76+
7777 if ( $contestants !== false && count( $contestants ) > 0 ) {
7878 $setSize = ContestSettings::get( 'reminderJobSize' );
7979 $limit = count( $contestants ) - $setSize;
80 -
 80+
8181 for ( $i = 0; $i <= $limit; $i += $setSize ) {
8282 $this->createReminderJob( array_splice( $contestants, $i, $setSize ) );
8383 }
@@ -84,13 +84,13 @@
8585 else {
8686 $everythingOk = false;
8787 }
88 -
 88+
8989 $this->getResult()->addValue(
9090 null,
9191 'success',
9292 $everythingOk
9393 );
94 -
 94+
9595 if ( $everythingOk ) {
9696 $this->getResult()->addValue(
9797 null,
@@ -99,7 +99,7 @@
100100 );
101101 }
102102 }
103 -
 103+
104104 protected function createReminderJob( array /* of ContestContestant */ $contestants ) {
105105 $job = new ContestReminderJob(
106106 Title::newMainPage(), // WTF does this require a title for??
@@ -108,17 +108,17 @@
109109 'contestants' => $contestants
110110 )
111111 );
112 - $job->insert();
 112+ $job->insert();
113113 }
114 -
 114+
115115 public function needsToken() {
116116 return true;
117117 }
118 -
 118+
119119 public function mustBePosted() {
120120 return true;
121121 }
122 -
 122+
123123 public function getAllowedParams() {
124124 return array(
125125 // 'page' => array(
@@ -154,7 +154,7 @@
155155 'token' => null,
156156 );
157157 }
158 -
 158+
159159 public function getParamDescription() {
160160 return array(
161161 // 'page' => 'Name of the page from which to pull content for the email body',
@@ -166,14 +166,14 @@
167167 'token' => 'Edit token',
168168 );
169169 }
170 -
 170+
171171 public function getDescription() {
172172 return array(
173173 'API module for mailing contestants. Selection criteria will be joined with AND,
174174 except for the challange ids/titles and contest ids/names pairs, which will be joined wit OR.'
175175 );
176176 }
177 -
 177+
178178 public function getPossibleErrors() {
179179 return array_merge( parent::getPossibleErrors(), array(
180180 array( 'missingparam', 'ids' ),
@@ -188,10 +188,10 @@
189189 'api.php?action=mailcontestants&contestnames=Weekend of Code',
190190 'api.php?action=mailcontestants&challengetitles=foo|bar|baz',
191191 );
192 - }
193 -
 192+ }
 193+
194194 public function getVersion() {
195195 return __CLASS__ . ': $Id$';
196 - }
197 -
 196+ }
 197+
198198 }
Index: trunk/extensions/Contest/api/ApiQueryContests.php
@@ -13,7 +13,7 @@
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class ApiQueryContests extends ApiContestQuery {
17 -
 17+
1818 /**
1919 * (non-PHPdoc)
2020 * @see ApiContestQuery::getClassInfo()
@@ -25,7 +25,7 @@
2626 'set' => 'contests',
2727 );
2828 }
29 -
 29+
3030 public function __construct( $main, $action ) {
3131 parent::__construct( $main, $action, 'co' );
3232 }
@@ -36,14 +36,14 @@
3737 */
3838 public function execute() {
3939 global $wgUser;
40 -
 40+
4141 if ( !$wgUser->isAllowed( 'contestadmin' ) || $wgUser->isBlocked() ) {
4242 $this->dieUsageMsg( array( 'badaccess-groups' ) );
4343 }
4444
4545 parent::execute();
4646 }
47 -
 47+
4848 /**
4949 * (non-PHPdoc)
5050 * @see includes/api/ApiBase#getDescription()
@@ -51,7 +51,7 @@
5252 public function getDescription() {
5353 return 'API module for querying contests';
5454 }
55 -
 55+
5656 /**
5757 * (non-PHPdoc)
5858 * @see includes/api/ApiBase#getExamples()
@@ -70,5 +70,5 @@
7171 public function getVersion() {
7272 return __CLASS__ . ': $Id$';
7373 }
74 -
 74+
7575 }
Index: trunk/extensions/Contest/api/ApiQueryChallenges.php
@@ -13,7 +13,7 @@
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class ApiQueryChallenges extends ApiContestQuery {
17 -
 17+
1818 /**
1919 * (non-PHPdoc)
2020 * @see ApiContestQuery::getClassInfo()
@@ -25,7 +25,7 @@
2626 'set' => 'challenges',
2727 );
2828 }
29 -
 29+
3030 public function __construct( $main, $action ) {
3131 parent::__construct( $main, $action, 'ch' );
3232 }
@@ -36,14 +36,14 @@
3737 */
3838 public function execute() {
3939 global $wgUser;
40 -
 40+
4141 if ( !$wgUser->isAllowed( 'contestadmin' ) || $wgUser->isBlocked() ) {
4242 $this->dieUsageMsg( array( 'badaccess-groups' ) );
4343 }
4444
4545 parent::execute();
4646 }
47 -
 47+
4848 /**
4949 * (non-PHPdoc)
5050 * @see includes/api/ApiBase#getDescription()
@@ -51,7 +51,7 @@
5252 public function getDescription() {
5353 return 'API module for querying contest challenges';
5454 }
55 -
 55+
5656 /**
5757 * (non-PHPdoc)
5858 * @see includes/api/ApiBase#getExamples()
@@ -70,5 +70,5 @@
7171 public function getVersion() {
7272 return __CLASS__ . ': $Id$';
7373 }
74 -
 74+
7575 }
Index: trunk/extensions/Contest/api/ApiQueryContestComments.php
@@ -13,7 +13,7 @@
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class ApiQueryContestComments extends ApiContestQuery {
17 -
 17+
1818 /**
1919 * (non-PHPdoc)
2020 * @see ApiContestQuery::getClassInfo()
@@ -25,7 +25,7 @@
2626 'set' => 'comments',
2727 );
2828 }
29 -
 29+
3030 public function __construct( $main, $action ) {
3131 parent::__construct( $main, $action, 'coco' );
3232 }
@@ -36,14 +36,14 @@
3737 */
3838 public function execute() {
3939 global $wgUser;
40 -
 40+
4141 if ( !$wgUser->isAllowed( 'contestjudge' ) || $wgUser->isBlocked() ) {
4242 $this->dieUsageMsg( array( 'badaccess-groups' ) );
4343 }
4444
4545 parent::execute();
4646 }
47 -
 47+
4848 /**
4949 * (non-PHPdoc)
5050 * @see includes/api/ApiBase#getDescription()
@@ -51,7 +51,7 @@
5252 public function getDescription() {
5353 return 'API module for querying contest comments';
5454 }
55 -
 55+
5656 /**
5757 * (non-PHPdoc)
5858 * @see includes/api/ApiBase#getExamples()
@@ -70,5 +70,5 @@
7171 public function getVersion() {
7272 return __CLASS__ . ': $Id$';
7373 }
74 -
 74+
7575 }
Index: trunk/extensions/Contest/api/ApiQueryContestants.php
@@ -13,7 +13,7 @@
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
1616 class ApiQueryContestants extends ApiContestQuery {
17 -
 17+
1818 /**
1919 * (non-PHPdoc)
2020 * @see ApiContestQuery::getClassInfo()
@@ -25,7 +25,7 @@
2626 'set' => 'contestants',
2727 );
2828 }
29 -
 29+
3030 public function __construct( $main, $action ) {
3131 parent::__construct( $main, $action, 'ct' );
3232 }
@@ -36,14 +36,14 @@
3737 */
3838 public function execute() {
3939 global $wgUser;
40 -
 40+
4141 if ( !$wgUser->isAllowed( 'contestadmin' ) || $wgUser->isBlocked() ) {
4242 $this->dieUsageMsg( array( 'badaccess-groups' ) );
4343 }
4444
4545 parent::execute();
4646 }
47 -
 47+
4848 /**
4949 * (non-PHPdoc)
5050 * @see includes/api/ApiBase#getDescription()
@@ -51,7 +51,7 @@
5252 public function getDescription() {
5353 return 'API module for querying contestants';
5454 }
55 -
 55+
5656 /**
5757 * (non-PHPdoc)
5858 * @see includes/api/ApiBase#getExamples()
@@ -70,5 +70,5 @@
7171 public function getVersion() {
7272 return __CLASS__ . ': $Id$';
7373 }
74 -
 74+
7575 }

Status & tagging log