r99488 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99487‎ | r99488 | r99489 >
Date:16:14, 11 October 2011
Author:jeroendedauw
Status:resolved
Tags:
Comment:
work on handling of email and real/user names
Modified paths:
  • /trunk/extensions/Contest/Contest.hooks.php (modified) (history)
  • /trunk/extensions/Contest/Contest.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestSignup.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestSubmission.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/Contest.hooks.php
@@ -177,4 +177,44 @@
178178 return true;
179179 }
180180
181 -}
\ No newline at end of file
 181+ /**
 182+ * Called when changing user email address.
 183+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/UserSetEmail
 184+ *
 185+ * Checks if there are any active contests in which the user is participating,
 186+ * and if so, updates the email there as well.
 187+ *
 188+ * @since 0.1
 189+ *
 190+ * @param User $user
 191+ * @param string $email
 192+ *
 193+ * @return true
 194+ */
 195+ public static function onUserSetEmail( User $user, &$email ) {
 196+ $dbr = wfGetDB( DB_SLAVE );
 197+
 198+ $contestants = $dbr->select(
 199+ array( 'contest_contestants', 'contests' ),
 200+ array( 'contestant_id' ),
 201+ array( 'contest_status' => Contest::STATUS_ACTIVE ),
 202+ '',
 203+ array(),
 204+ array( 'contest_id=contestant_contest_id' )
 205+ );
 206+
 207+ $contestantIds = array();
 208+
 209+ foreach ( $contestants as $contestant ) {
 210+ $contestantIds[] = $contestant->contestant_id;
 211+ }
 212+
 213+ ContestContestant::s()->update(
 214+ array( 'email' => $email ),
 215+ array( 'id' => $contestantIds )
 216+ );
 217+
 218+ return true;
 219+ }
 220+
 221+}
Index: trunk/extensions/Contest/specials/SpecialContestSubmission.php
@@ -144,8 +144,10 @@
145145 $contestant = new ContestContestant( array(
146146 'id' => $data['contestant-id'],
147147
 148+ 'full_name' => $data['contestant-realname'],
 149+ 'email' => $data['contestant-email'],
 150+
148151 'country' => $data['contestant-country'],
149 -
150152 'volunteer' => $data['contestant-volunteer'],
151153 'wmf' => $data['contestant-wmf'],
152154 'cv' => $data['contestant-cv'],
Index: trunk/extensions/Contest/specials/SpecialContestSignup.php
@@ -51,8 +51,8 @@
5252 *
5353 * @return true|array
5454 */
55 - public static function handleSubmission( array $data ) {
56 - $user = $GLOBALS['wgUser']; //$this->getUser();
 55+ public function handleSubmission( array $data ) {
 56+ $user = $this->getUser();
5757
5858 $user->setEmail( $data['contestant-email'] );
5959 $user->setRealName( $data['contestant-realname'] );
@@ -63,8 +63,11 @@
6464 'user_id' => $user->getId(),
6565 'challenge_id' => $data['contestant-challengeid'],
6666
 67+ 'full_name' => $data['contestant-realname'],
 68+ 'user_name' => $user->getName(),
 69+ 'email' => $data['contestant-email'],
 70+
6771 'country' => $data['contestant-country'],
68 -
6972 'volunteer' => $data['contestant-volunteer'],
7073 'wmf' => $data['contestant-wmf'],
7174 ) );
@@ -156,7 +159,7 @@
157160 protected function showSignupForm( Contest $contest, $challengeId = false ) {
158161 $form = new HTMLForm( $this->getFormFields( $contest, $challengeId ), $this->getContext() );
159162
160 - $form->setSubmitCallback( array( __CLASS__, 'handleSubmission' ) );
 163+ $form->setSubmitCallback( array( $this, 'handleSubmission' ) );
161164 $form->setSubmitText( wfMsg( 'contest-signup-submit' ) );
162165
163166 if( $form->show() ){
Index: trunk/extensions/Contest/Contest.php
@@ -101,6 +101,7 @@
102102 // Hooks
103103 $wgHooks['LoadExtensionSchemaUpdates'][] = 'ContestHooks::onSchemaUpdate';
104104 $wgHooks['UnitTestsList'][] = 'ContestHooks::registerUnitTests';
 105+$wgHooks['UserSetEmail'][] = 'ContestHooks::onUserSetEmail';
105106
106107 // Rights
107108

Follow-up revisions

RevisionCommit summaryAuthorDate
r99513Follow up to r99488;jeroendedauw18:09, 11 October 2011
r99519Follow up to r99488;jeroendedauw18:26, 11 October 2011

Status & tagging log