Index: branches/preferences-work/phase3/includes/specials/SpecialPreferences.php |
— | — | @@ -6,9 +6,21 @@ |
7 | 7 | } |
8 | 8 | |
9 | 9 | function execute( $par ) { |
10 | | - global $wgOut, $wgUser; |
| 10 | + global $wgOut, $wgUser, $wgRequest; |
11 | 11 | |
12 | 12 | $wgOut->setPageTitle( wfMsg( 'preferences' ) ); |
| 13 | + $wgOut->setArticleRelated( false ); |
| 14 | + $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
| 15 | + $wgOut->addScriptFile( 'prefs.js' ); |
| 16 | + |
| 17 | + $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc. |
| 18 | + |
| 19 | + if ( $wgRequest->getCheck( 'success' ) ) { |
| 20 | + $wgOut->wrapWikiMsg( |
| 21 | + '<div class="successbox"><strong>$1</strong></div>', |
| 22 | + 'savedprefs' |
| 23 | + ); |
| 24 | + } |
13 | 25 | |
14 | 26 | $formDescriptor = Preferences::getPreferences( $wgUser ); |
15 | 27 | |
— | — | @@ -22,7 +34,7 @@ |
23 | 35 | } |
24 | 36 | |
25 | 37 | static function trySubmit( $formData ) { |
26 | | - global $wgUser; |
| 38 | + global $wgUser, $wgEmailAuthentication, $wgEnableEmail; |
27 | 39 | |
28 | 40 | // Stuff that shouldn't be saved as a preference. |
29 | 41 | $saveBlacklist = array( |
— | — | @@ -30,6 +42,41 @@ |
31 | 43 | 'emailaddress', |
32 | 44 | ); |
33 | 45 | |
| 46 | + if( $wgEnableEmail ) { |
| 47 | + $newadr = $formData['emailaddress']; |
| 48 | + $oldadr = $wgUser->getEmail(); |
| 49 | + if( ($newadr != '') && ($newadr != $oldadr) ) { |
| 50 | + # the user has supplied a new email address on the login page |
| 51 | + # new behaviour: set this new emailaddr from login-page into user database record |
| 52 | + $wgUser->setEmail( $newadr ); |
| 53 | + # but flag as "dirty" = unauthenticated |
| 54 | + $wgUser->invalidateEmail(); |
| 55 | + if ($wgEmailAuthentication) { |
| 56 | + # Mail a temporary password to the dirty address. |
| 57 | + # User can come back through the confirmation URL to re-enable email. |
| 58 | + $result = $wgUser->sendConfirmationMail(); |
| 59 | + if( WikiError::isError( $result ) ) { |
| 60 | + return wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) ); |
| 61 | + } else { |
| 62 | + // TODO return this somehow |
| 63 | +# wfMsg( 'eauthentsent', $wgUser->getName() ); |
| 64 | + } |
| 65 | + } |
| 66 | + } else { |
| 67 | + $wgUser->setEmail( $newadr ); |
| 68 | + } |
| 69 | + if( $oldadr != $newadr ) { |
| 70 | + wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldadr, $newadr ) ); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + // Fortunately, the realname field is MUCH simpler |
| 75 | + global $wgAllowRealName; |
| 76 | + if ($wgAllowRealName) { |
| 77 | + $realName = $formData['realname']; |
| 78 | + $wgUser->setRealName( $realName ); |
| 79 | + } |
| 80 | + |
34 | 81 | foreach( $saveBlacklist as $b ) |
35 | 82 | unset( $formData[$b] ); |
36 | 83 | |
— | — | @@ -39,6 +86,10 @@ |
40 | 87 | |
41 | 88 | $wgUser->saveSettings(); |
42 | 89 | |
| 90 | + // Done |
| 91 | + global $wgOut; |
| 92 | + $wgOut->redirect( SpecialPage::getTitleFor( 'Preferences' )->getFullURL( 'success' ) ); |
| 93 | + |
43 | 94 | return true; |
44 | 95 | } |
45 | 96 | } |
Index: branches/preferences-work/phase3/includes/Preferences.php |
— | — | @@ -70,14 +70,17 @@ |
71 | 71 | } |
72 | 72 | |
73 | 73 | // Actually changeable stuff |
74 | | - $defaultPreferences['realname'] = |
75 | | - array( |
76 | | - 'type' => 'text', |
77 | | - 'default' => $user->getRealName(), |
78 | | - 'section' => 'user', |
79 | | - 'label-message' => 'yourrealname', |
80 | | - 'help-message' => 'prefs-help-realname', |
81 | | - ); |
| 74 | + global $wgAllowRealName; |
| 75 | + if ($wgAllowRealName) { |
| 76 | + $defaultPreferences['realname'] = |
| 77 | + array( |
| 78 | + 'type' => 'text', |
| 79 | + 'default' => $user->getRealName(), |
| 80 | + 'section' => 'user', |
| 81 | + 'label-message' => 'yourrealname', |
| 82 | + 'help-message' => 'prefs-help-realname', |
| 83 | + ); |
| 84 | + } |
82 | 85 | |
83 | 86 | global $wgEmailConfirmToEdit; |
84 | 87 | |
— | — | @@ -90,8 +93,26 @@ |
91 | 94 | 'help-message' => $wgEmailConfirmToEdit |
92 | 95 | ? 'prefs-help-email-required' |
93 | 96 | : 'prefs-help-email', |
| 97 | + 'validation-callback' => array( 'Preferences', 'validateEmail' ), |
94 | 98 | ); |
95 | 99 | |
| 100 | + global $wgAuth; |
| 101 | + if ($wgAuth->allowPasswordChange()) { |
| 102 | + global $wgUser; // For skin. |
| 103 | + $link = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'ResetPass' ), |
| 104 | + wfMsgHtml( 'prefs-resetpass' ), array() , |
| 105 | + array('returnto' => SpecialPage::getTitleFor( 'Preferences') ) ); |
| 106 | + |
| 107 | + $defaultPreferences['password'] = |
| 108 | + array( |
| 109 | + 'type' => 'info', |
| 110 | + 'raw' => true, |
| 111 | + 'default' => $link, |
| 112 | + 'label-message' => 'yourpassword', |
| 113 | + 'section' => 'user', |
| 114 | + ); |
| 115 | + } |
| 116 | + |
96 | 117 | $defaultPreferences['gender'] = |
97 | 118 | array( |
98 | 119 | 'type' => 'select', |
— | — | @@ -795,4 +816,17 @@ |
796 | 817 | |
797 | 818 | return $signature; |
798 | 819 | } |
| 820 | + |
| 821 | + static function validateEmail( $email, $alldata ) { |
| 822 | + global $wgUser; // To check |
| 823 | + if ( !$wgUser->isValidEmailAddr( $email ) ) { |
| 824 | + return wfMsgExt( 'invalidemailaddress', 'parseinline' ); |
| 825 | + } |
| 826 | + |
| 827 | + global $wgEmailConfirmToEdit; |
| 828 | + if( $wgEmailConfirmToEdit && !$email ) { |
| 829 | + return wfMsgExt( 'noemailtitle', 'parseinline' ); |
| 830 | + } |
| 831 | + return true; |
| 832 | + } |
799 | 833 | } |