Force email confirmation in Mediawiki 1.9

04 Oct 2007

Before proceeding to this article, have you tried the following links?

If non of the above answers the problem, you may try this solution.

How to check if a registered user has confirmed his registration email? Here is a simple modification I made. It checks if the user has confirmed his/her email before logging in. You may use it anytime at your own risk. If there are any bugs or it has been helpful, tell and share what you think here :)

Affected files are:
/wiki/languages/messages/MessagesEn.php
/wiki/includes/SpecialUserLogin.php

For Messages.php, I only added/edited the ffg:

PHP:
  1. $messages = array(
  2. 'not_authenticated'        => 'Please verify your email address and try again.',
  3. 'confirmemail_oncreate' => 'A confirmation code was sent to your e-mail address.
  4. Please verify it before you can edit any page.',
  5. )
  6.  
  7. For the <strong>SpecialUserLogin.php</strong>, here are the changes
  8.  
  9. class LoginForm {
  10. // Added for confirmation error in login
  11. const NO_AUTH = 8;
  12.  
  13. function addNewAccount() {
  14. global $wgUser, $wgEmailAuthentication;
  15.  
  16. # Create the account and abort if there's a problem doing so
  17. $u = $this-&gt;addNewAccountInternal();
  18. if( $u == NULL )
  19. return;
  20.  
  21. # If we showed up language selection links, and one was in use, be
  22. # smart (and sensible) and save that language as the user's preference
  23. global $wgLoginLanguageSelector;
  24. if( $wgLoginLanguageSelector &amp;&amp; $this-&gt;mLanguage )
  25. $u-&gt;setOption( 'language', $this-&gt;mLanguage );
  26.  
  27. # Save user settings and send out an email authentication message if needed
  28. if( $wgEmailAuthentication &amp;&amp; User::isValidEmailAddr( $u-&gt;getEmail() ) ) {
  29. //Position it here
  30. $u-&gt;saveSettings();
  31. global $wgOut;
  32. $error = $u-&gt;sendConfirmationMail();
  33. if( WikiError::isError( $error ) ) {
  34. $wgOut-&gt;addWikiText( wfMsg( 'confirmemail_sendfailed', $error-&gt;getMessage() ) );
  35. } else {
  36. $wgOut-&gt;addWikiText( wfMsg( 'confirmemail_oncreate' ) );
  37. }
  38. }
  39.  
  40. //removed the other unneccary conditions
  41. global $wgOut;
  42. $self = SpecialPage::getTitleFor( 'Userlogin' );
  43. $wgOut-&gt;setPageTitle( wfMsgHtml( 'accountcreated' ) );
  44. $wgOut-&gt;setArticleRelated( false );
  45. $wgOut-&gt;setRobotPolicy( 'noindex,nofollow' );
  46. $wgOut-&gt;addHtml( wfMsgWikiHtml( 'accountcreatedtext', $u-&gt;getName() ) );
  47. $wgOut-&gt;returnToMain( $self-&gt;getPrefixedText() );
  48. wfRunHooks( 'AddNewAccount', array( $u ) );
  49. return true;
  50. }
  51.  
  52. function authenticateUserData() {
  53. # code before the changes
  54. if ( 0 == $u-&gt;getID() ) {
  55. ...
  56. } else {
  57. $u-&gt;load();
  58. }
  59.  
  60. // check if the user has confirmed his/her email
  61. if( !$u-&gt;isEmailConfirmed() ) {
  62. return self::NO_AUTH;
  63. }
  64.  
  65. #code after the changes
  66. if (!$u-&gt;checkPassword( $this-&gt;mPassword )) {
  67. if( $u-&gt;checkTemporaryPassword( $this-&gt;mPassword ) ) {
  68. }
  69.  
  70. function processLogin() {
  71. ...
  72. # code before the changes
  73. case self::RESET_PASS:
  74. $this-&gt;resetLoginForm( wfMsg( 'resetpass_announce' ) );
  75. break;
  76. case self::NO_AUTH:
  77. $this-&gt;mainLoginForm( wfMsg( 'not_authenticated' ) );
  78. break;
  79. # code after the changes
  80. default:
  81. wfDebugDieBacktrace( "Unhandled case value" );
  82. }
  83. }

Improvement:

In the Special:Confirm, you may want to make this work without having to log in. I haven't had the time to tweak that. If you do have the solution, please share them here :)

Design by: primerg | Images by: vikifloki | PETIXE.COM © 2007