MediaWiki  1.27.2
SpecialConfirmemail.php
Go to the documentation of this file.
1 <?php
33  public function __construct() {
34  parent::__construct( 'Confirmemail', 'editmyprivateinfo' );
35  }
36 
37  public function doesWrites() {
38  return true;
39  }
40 
49  function execute( $code ) {
50  // Ignore things like master queries/connections on GET requests.
51  // It's very convenient to just allow formless link usage.
52  Profiler::instance()->getTransactionProfiler()->resetExpectations();
53 
54  $this->setHeaders();
55 
56  $this->checkReadOnly();
57  $this->checkPermissions();
58 
59  // This could also let someone check the current email address, so
60  // require both permissions.
61  if ( !$this->getUser()->isAllowed( 'viewmyprivateinfo' ) ) {
62  throw new PermissionsError( 'viewmyprivateinfo' );
63  }
64 
65  if ( $code === null || $code === '' ) {
66  $this->requireLogin( 'confirmemail_needlogin' );
67  if ( Sanitizer::validateEmail( $this->getUser()->getEmail() ) ) {
68  $this->showRequestForm();
69  } else {
70  $this->getOutput()->addWikiMsg( 'confirmemail_noemail' );
71  }
72  } else {
73  $this->attemptConfirm( $code );
74  }
75  }
76 
80  function showRequestForm() {
81  $user = $this->getUser();
82  $out = $this->getOutput();
83 
84  if ( !$user->isEmailConfirmed() ) {
85  $descriptor = [];
86  if ( $user->isEmailConfirmationPending() ) {
87  $descriptor += [
88  'pending' => [
89  'type' => 'info',
90  'raw' => true,
91  'default' => "<div class=\"error mw-confirmemail-pending\">\n" .
92  $this->msg( 'confirmemail_pending' )->escaped() .
93  "\n</div>",
94  ],
95  ];
96  }
97 
98  $out->addWikiMsg( 'confirmemail_text' );
99  $form = HTMLForm::factory( 'ooui', $descriptor, $this->getContext() );
100  $form
101  ->setMethod( 'post' )
102  ->setAction( $this->getPageTitle()->getLocalURL() )
103  ->setSubmitTextMsg( 'confirmemail_send' )
104  ->setSubmitCallback( [ $this, 'submitSend' ] );
105 
106  $retval = $form->show();
107 
108  if ( $retval === true ) {
109  // should never happen, but if so, don't let the user without any message
110  $out->addWikiMsg( 'confirmemail_sent' );
111  } elseif ( $retval instanceof Status && $retval->isGood() ) {
112  $out->addWikiText( $retval->getValue() );
113  }
114  } else {
115  // date and time are separate parameters to facilitate localisation.
116  // $time is kept for backward compat reasons.
117  // 'emailauthenticated' is also used in SpecialPreferences.php
118  $lang = $this->getLanguage();
119  $emailAuthenticated = $user->getEmailAuthenticationTimestamp();
120  $time = $lang->userTimeAndDate( $emailAuthenticated, $user );
121  $d = $lang->userDate( $emailAuthenticated, $user );
122  $t = $lang->userTime( $emailAuthenticated, $user );
123  $out->addWikiMsg( 'emailauthenticated', $time, $d, $t );
124  }
125  }
126 
132  public function submitSend() {
133  $status = $this->getUser()->sendConfirmationMail();
134  if ( $status->isGood() ) {
135  return Status::newGood( $this->msg( 'confirmemail_sent' )->text() );
136  } else {
137  return Status::newFatal( new RawMessage(
138  $status->getWikiText( 'confirmemail_sendfailed' )
139  ) );
140  }
141  }
142 
149  function attemptConfirm( $code ) {
151  if ( !is_object( $user ) ) {
152  $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );
153 
154  return;
155  }
156 
157  $user->confirmEmail();
158  $user->saveSettings();
159  $message = $this->getUser()->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
160  $this->getOutput()->addWikiMsg( $message );
161 
162  if ( !$this->getUser()->isLoggedIn() ) {
163  $title = SpecialPage::getTitleFor( 'Userlogin' );
164  $this->getOutput()->returnToMain( true, $title );
165  }
166  }
167 }
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:762
Shortcut to construct a special page which is unlisted by default.
getContext()
Gets the context this SpecialPage is executed in.
static getTitleFor($name, $subpage=false, $fragment= '')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:75
static instance()
Singleton.
Definition: Profiler.php:60
if(!isset($args[0])) $lang
static factory($displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:264
msg()
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
Special page allows users to request email confirmation message, and handles processing of the confir...
showRequestForm()
Show a nice form for the user to request a confirmation mail.
static newFatal($message)
Factory function for fatal errors.
Definition: Status.php:89
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1612
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition: hooks.txt:762
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static newFromConfirmationCode($code, $flags=0)
Factory method to fetch whichever user has a given email confirmation code.
Definition: User.php:610
Variant of the Message class.
Definition: Message.php:1232
requireLogin($reasonMsg= 'exception-nologin-text', $titleMsg= 'exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
getUser()
Shortcut to get the User executing this instance.
Show an error when a user tries to do something they do not have the necessary permissions for...
getLanguage()
Shortcut to get user's language.
attemptConfirm($code)
Attempt to confirm the user's email address and show success or failure as needed; if successful...
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1004
static validateEmail($addr)
Does a string look like an e-mail address?
Definition: Sanitizer.php:1904
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
execute($code)
Main execution point.
submitSend()
Callback for HTMLForm send confirmation mail.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
Definition: hooks.txt:242
static newGood($value=null)
Factory function for good results.
Definition: Status.php:101
getPageTitle($subpage=false)
Get a self-referential title object.