r99561 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99560‎ | r99561 | r99562 >
Date:20:37, 11 October 2011
Author:jeroendedauw
Status:ok
Tags:
Comment:
Follow up to r99560; comitted only /specials/
Modified paths:
  • /trunk/extensions/Contest/Contest.alias.php (modified) (history)
  • /trunk/extensions/Contest/Contest.hooks.php (modified) (history)
  • /trunk/extensions/Contest/Contest.i18n.php (modified) (history)
  • /trunk/extensions/Contest/Contest.php (modified) (history)
  • /trunk/extensions/Contest/Contest.settings.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestContestant.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestDBObject.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/Contest.i18n.php
@@ -20,6 +20,9 @@
2121 $messages['en'] = array(
2222 'contest-desc' => 'Contest extension that allows users to participate in admin defined contest challenges. Via a judging interface, judges can discuss and vote on submissions.',
2323
 24+ // Misc
 25+ 'contest-toplink' => 'My contests',
 26+
2427 // Rights
2528 'right-contestadmin' => 'Manage contests',
2629 'right-contestparticipant' => 'Participate in contests',
@@ -38,6 +41,10 @@
3942 'group-contestjudge-member' => 'contest judge',
4043 'grouppage-contestjudge' => 'Project:Contest_judges',
4144
 45+ // Preferences
 46+ 'prefs-contest' => 'Contests',
 47+ 'contest-prefs-showtoplink' => 'Show a link to [[Special:MyContests|My Contests]] in the top menue.',
 48+
4249 // Contest statuses
4350 'contest-status-draft' => 'Draft (disabled)',
4451 'contest-status-active' => 'Active (enabled)',
@@ -50,6 +57,7 @@
5158 'special-contestsubmission' => 'Contest submission',
5259 'special-contestwelcome' => 'Contest',
5360 'special-editcontest' => 'Edit contest',
 61+ 'special-mycontests' => 'Contests',
5462
5563 // Navigation links
5664 'contest-nav-contests' => 'Contests list',
@@ -182,9 +190,14 @@
183191 'contest-email-reminder-title' => 'Only $1 {{PLURAL:$1|day|days}} until the end of the challenge!',
184192
185193 // Special:MyContests
 194+ 'contest-mycontests-toplink' => 'My contests',
186195 'contest-mycontests-no-contests' => 'You are not participating in any contest.',
187196 'contest-mycontests-active-header' => 'Running contests',
188197 'contest-mycontests-finished-header' => 'Passed contests',
 198+ 'contest-mycontests-active-text' => 'These are the contests you are currently participating in.',
 199+ 'contest-mycontests-finished-text' => 'These are the passed contests you have participated in.',
 200+ 'contest-mycontests-header-contest' => 'Contest',
 201+ 'contest-mycontests-header-challenge' => 'Challenge',
189202 );
190203
191204 /** Message documentation (Message documentation)
@@ -240,4 +253,10 @@
241254 // Emails
242255 'contest-email-signup-title' => 'Title for signup emails',
243256 'contest-email-reminder-title' => 'Title for reminder emails',
 257+
 258+ // Special:MyContests
 259+ 'contest-mycontests-toplink' => 'Text for link in the top menue (ie where watchlist and preferences are linked)',
 260+ 'contest-mycontests-no-contests' => 'Message indicating there are no contests for the user, displayed instead of a list.',
 261+ 'contest-mycontests-active-header' => 'Page header (h2)',
 262+ 'contest-mycontests-finished-header' => 'Page header (h2)',
244263 );
Index: trunk/extensions/Contest/Contest.hooks.php
@@ -81,8 +81,8 @@
8282 $contestants = $dbr->select(
8383 array( 'contest_contestants', 'contests' ),
8484 array( 'contestant_id' ),
85 - array( 'contest_status' => Contest::STATUS_ACTIVE ),
86 - '',
 85+ array( 'contest_status' => Contest::STATUS_ACTIVE, 'contestant_user_id' => $user->getId() ),
 86+ __METHOD__,
8787 array(),
8888 array( 'contests' => array( 'INNER JOIN', array( 'contest_id=contestant_contest_id' ) ) )
8989 );
@@ -103,4 +103,62 @@
104104 return true;
105105 }
106106
 107+ /**
 108+ * Called after the personal URLs have been set up, before they are shown.
 109+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls
 110+ *
 111+ * @since 0.1
 112+ *
 113+ * @param array $personal_urls
 114+ * @param Title $title
 115+ *
 116+ * @return true
 117+ */
 118+ public static function onPersonalUrls( array &$personal_urls, Title &$title ) {
 119+ if ( ContestSettings::get( 'enableTopLink' ) ) {
 120+ global $wgUser;
 121+
 122+ // Find the watchlist item and replace it by the my contests link and itself.
 123+ if ( $wgUser->isLoggedIn() && $wgUser->getOption( 'contest_showtoplink' ) ) {
 124+ $keys = array_keys( $personal_urls );
 125+ $watchListLocation = array_search( 'watchlist', $keys );
 126+ $watchListItem = $personal_urls[$keys[$watchListLocation]];
 127+
 128+ $url = SpecialPage::getTitleFor( 'MyContests' )->getLinkUrl();
 129+ $myContests = array(
 130+ 'text' => wfMsg( 'contest-toplink' ),
 131+ 'href' => $url,
 132+ 'active' => ( $url == $title->getLinkUrl() )
 133+ );
 134+
 135+ array_splice( $personal_urls, $watchListLocation, 1, array( $myContests, $watchListItem ) );
 136+ }
 137+ }
 138+
 139+ return true;
 140+ }
 141+
 142+ /**
 143+ * Adds the preferences of Contest to the list of available ones.
 144+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
 145+ *
 146+ * @since 0.1
 147+ *
 148+ * @param User $user
 149+ * @param array $preferences
 150+ *
 151+ * @return true
 152+ */
 153+ public static function onGetPreferences( User $user, array &$preferences ) {
 154+ if ( ContestSettings::get( 'enableTopLink' ) ) {
 155+ $preferences['contest_showtoplink'] = array(
 156+ 'type' => 'toggle',
 157+ 'label-message' => 'contest-prefs-showtoplink',
 158+ 'section' => 'contest',
 159+ );
 160+ }
 161+
 162+ return true;
 163+ }
 164+
107165 }
Index: trunk/extensions/Contest/Contest.alias.php
@@ -20,8 +20,7 @@
2121 'Contestant' => array( 'Contestant' ),
2222 'Contests' => array( 'Contests' ),
2323 'ContestSignup' => array( 'ContestSignup' ),
24 - 'ContestSubmission' => array( 'ContestSubmission' ),
2524 'ContestWelcome' => array( 'ContestWelcome' ),
2625 'EditContest' => array( 'EditContest' ),
27 - 'MyContests' => array( 'MyContests' ),
 26+ 'MyContests' => array( 'MyContests', 'ContestSubmission', 'My contests' ),
2827 );
Index: trunk/extensions/Contest/Contest.settings.php
@@ -28,7 +28,8 @@
2929 */
3030 protected static function getDefaultSettings() {
3131 return array(
32 - 'votevalues' => range( 0, 5 )
 32+ 'votevalues' => range( 0, 5 ),
 33+ 'enableTopLink' => true,
3334 );
3435 }
3536
Index: trunk/extensions/Contest/Contest.php
@@ -70,7 +70,6 @@
7171 $wgAutoloadClasses['SpecialContestPage'] = dirname( __FILE__ ) . '/specials/SpecialContestPage.php';
7272 $wgAutoloadClasses['SpecialContests'] = dirname( __FILE__ ) . '/specials/SpecialContests.php';
7373 $wgAutoloadClasses['SpecialContestSignup'] = dirname( __FILE__ ) . '/specials/SpecialContestSignup.php';
74 -$wgAutoloadClasses['SpecialContestSubmission'] = dirname( __FILE__ ) . '/specials/SpecialContestSubmission.php';
7574 $wgAutoloadClasses['SpecialContestWelcome'] = dirname( __FILE__ ) . '/specials/SpecialContestWelcome.php';
7675 $wgAutoloadClasses['SpecialEditContest'] = dirname( __FILE__ ) . '/specials/SpecialEditContest.php';
7776 $wgAutoloadClasses['SpecialMyContests'] = dirname( __FILE__ ) . '/specials/SpecialMyContests.php';
@@ -80,7 +79,6 @@
8180 $wgSpecialPages['Contestant'] = 'SpecialContestant';
8281 $wgSpecialPages['Contests'] = 'SpecialContests';
8382 $wgSpecialPages['ContestSignup'] = 'SpecialContestSignup';
84 -$wgSpecialPages['ContestSubmission'] = 'SpecialContestSubmission';
8583 $wgSpecialPages['ContestWelcome'] = 'SpecialContestWelcome';
8684 $wgSpecialPages['EditContest'] = 'SpecialEditContest';
8785 $wgSpecialPages['MyContests'] = 'SpecialMyContests';
@@ -89,7 +87,6 @@
9088 $wgSpecialPageGroups['Contestant'] = 'other';
9189 $wgSpecialPageGroups['Contests'] = 'other';
9290 $wgSpecialPageGroups['ContestSignup'] = 'other';
93 -$wgSpecialPageGroups['ContestSubmission'] = 'other';
9491 $wgSpecialPageGroups['ContestWelcome'] = 'other';
9592 $wgSpecialPageGroups['EditContest'] = 'other';
9693 $wgSpecialPageGroups['MyContests'] = 'other';
@@ -105,6 +102,8 @@
106103 $wgHooks['LoadExtensionSchemaUpdates'][] = 'ContestHooks::onSchemaUpdate';
107104 $wgHooks['UnitTestsList'][] = 'ContestHooks::registerUnitTests';
108105 $wgHooks['UserSetEmail'][] = 'ContestHooks::onUserSetEmail';
 106+$wgHooks['PersonalUrls'][] = 'ContestHooks::onPersonalUrls';
 107+$wgHooks['GetPreferences'][] = 'ContestHooks::onGetPreferences';
109108
110109 // Rights
111110
Index: trunk/extensions/Contest/includes/ContestDBObject.php
@@ -643,7 +643,7 @@
644644 $this->getDBTable(),
645645 $fields,
646646 count( $conditions ) == 0 ? '' : $conditions,
647 - '',
 647+ __METHOD__,
648648 $options
649649 );
650650 }
Index: trunk/extensions/Contest/includes/ContestContestant.php
@@ -458,16 +458,29 @@
459459 $success = parent::insertIntoDB();
460460
461461 if ( $success ) {
462 - $this->getContest( array( 'id' ) )->addToSubmissionCount( 1 );
463 - $this->sendSignupEmail();
464 -
465 - wfRunHooks( 'ContestAfterContestantInsert', array( &$this ) );
 462+ $this->onUserSignup();
466463 }
467464
468465 return $success;
469466 }
470467
471468 /**
 469+ * Handles successfull user signup for a contest.
 470+ *
 471+ * @since 0.1
 472+ */
 473+ protected function onUserSignup() {
 474+ $this->getContest( array( 'id' ) )->addToSubmissionCount( 1 );
 475+
 476+ $this->getUser()->setOption( 'contest_showtoplink', true );
 477+ $this->getUser()->saveSettings(); // TODO: can't we just save this single option instead of everything?
 478+
 479+ $this->sendSignupEmail();
 480+
 481+ wfRunHooks( 'ContestAfterContestantInsert', array( &$this ) );
 482+ }
 483+
 484+ /**
472485 * Send the signup email.
473486 *
474487 * @since 0.1

Follow-up revisions

RevisionCommit summaryAuthorDate
r99566Follow up to r99561; more work on mycontestsjeroendedauw20:50, 11 October 2011
r99749Fix indentation for r99561catrope00:17, 14 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99560moved over code from contestsignup to mycontests (still needs cleanup) and ad...jeroendedauw20:35, 11 October 2011

Status & tagging log