SpecialEmailInvalidate.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Implements Special:EmailInvalidation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup SpecialPage
  22. */
  23. /**
  24. * Special page allows users to cancel an email confirmation using the e-mail
  25. * confirmation code
  26. *
  27. * @ingroup SpecialPage
  28. */
  29. class SpecialEmailInvalidate extends UnlistedSpecialPage {
  30. public function __construct() {
  31. parent::__construct( 'Invalidateemail', 'editmyprivateinfo' );
  32. }
  33. public function doesWrites() {
  34. return true;
  35. }
  36. function execute( $code ) {
  37. // Ignore things like master queries/connections on GET requests.
  38. // It's very convenient to just allow formless link usage.
  39. $trxProfiler = Profiler::instance()->getTransactionProfiler();
  40. $this->setHeaders();
  41. $this->checkReadOnly();
  42. $this->checkPermissions();
  43. $old = $trxProfiler->setSilenced( true );
  44. $this->attemptInvalidate( $code );
  45. $trxProfiler->setSilenced( $old );
  46. }
  47. /**
  48. * Attempt to invalidate the user's email address and show success or failure
  49. * as needed; if successful, link to main page
  50. *
  51. * @param string $code Confirmation code
  52. */
  53. private function attemptInvalidate( $code ) {
  54. $user = User::newFromConfirmationCode( $code, User::READ_LATEST );
  55. if ( !is_object( $user ) ) {
  56. $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );
  57. return;
  58. }
  59. $user->invalidateEmail();
  60. $user->saveSettings();
  61. $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' );
  62. if ( !$this->getUser()->isLoggedIn() ) {
  63. $this->getOutput()->returnToMain();
  64. }
  65. }
  66. }