MediaWiki  1.29.1
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  $trxProfiler = Profiler::instance()->getTransactionProfiler();
53 
54  $this->setHeaders();
55  $this->checkReadOnly();
56  $this->checkPermissions();
57 
58  // This could also let someone check the current email address, so
59  // require both permissions.
60  if ( !$this->getUser()->isAllowed( 'viewmyprivateinfo' ) ) {
61  throw new PermissionsError( 'viewmyprivateinfo' );
62  }
63 
64  if ( $code === null || $code === '' ) {
65  $this->requireLogin( 'confirmemail_needlogin' );
66  if ( Sanitizer::validateEmail( $this->getUser()->getEmail() ) ) {
67  $this->showRequestForm();
68  } else {
69  $this->getOutput()->addWikiMsg( 'confirmemail_noemail' );
70  }
71  } else {
72  $old = $trxProfiler->setSilenced( true );
73  $this->attemptConfirm( $code );
74  $trxProfiler->setSilenced( $old );
75  }
76  }
77 
81  function showRequestForm() {
82  $user = $this->getUser();
83  $out = $this->getOutput();
84 
85  if ( !$user->isEmailConfirmed() ) {
86  $descriptor = [];
87  if ( $user->isEmailConfirmationPending() ) {
88  $descriptor += [
89  'pending' => [
90  'type' => 'info',
91  'raw' => true,
92  'default' => "<div class=\"error mw-confirmemail-pending\">\n" .
93  $this->msg( 'confirmemail_pending' )->escaped() .
94  "\n</div>",
95  ],
96  ];
97  }
98 
99  $out->addWikiMsg( 'confirmemail_text' );
100  $form = HTMLForm::factory( 'ooui', $descriptor, $this->getContext() );
101  $form
102  ->setMethod( 'post' )
103  ->setAction( $this->getPageTitle()->getLocalURL() )
104  ->setSubmitTextMsg( 'confirmemail_send' )
105  ->setSubmitCallback( [ $this, 'submitSend' ] );
106 
107  $retval = $form->show();
108 
109  if ( $retval === true ) {
110  // should never happen, but if so, don't let the user without any message
111  $out->addWikiMsg( 'confirmemail_sent' );
112  } elseif ( $retval instanceof Status && $retval->isGood() ) {
113  $out->addWikiText( $retval->getValue() );
114  }
115  } else {
116  // date and time are separate parameters to facilitate localisation.
117  // $time is kept for backward compat reasons.
118  // 'emailauthenticated' is also used in SpecialPreferences.php
119  $lang = $this->getLanguage();
120  $emailAuthenticated = $user->getEmailAuthenticationTimestamp();
121  $time = $lang->userTimeAndDate( $emailAuthenticated, $user );
122  $d = $lang->userDate( $emailAuthenticated, $user );
123  $t = $lang->userTime( $emailAuthenticated, $user );
124  $out->addWikiMsg( 'emailauthenticated', $time, $d, $t );
125  }
126  }
127 
133  public function submitSend() {
134  $status = $this->getUser()->sendConfirmationMail();
135  if ( $status->isGood() ) {
136  return Status::newGood( $this->msg( 'confirmemail_sent' )->text() );
137  } else {
138  return Status::newFatal( new RawMessage(
139  $status->getWikiText( 'confirmemail_sendfailed' )
140  ) );
141  }
142  }
143 
150  private function attemptConfirm( $code ) {
151  $user = User::newFromConfirmationCode( $code, User::READ_LATEST );
152  if ( !is_object( $user ) ) {
153  $this->getOutput()->addWikiMsg( 'confirmemail_invalid' );
154 
155  return;
156  }
157 
158  $user->confirmEmail();
159  $user->saveSettings();
160  $message = $this->getUser()->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success';
161  $this->getOutput()->addWikiMsg( $message );
162 
163  if ( !$this->getUser()->isLoggedIn() ) {
164  $title = SpecialPage::getTitleFor( 'Userlogin' );
165  $this->getOutput()->returnToMain( true, $title );
166  }
167  }
168 }
EmailConfirmation\__construct
__construct()
Definition: SpecialConfirmemail.php:33
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:628
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:675
Profiler\instance
static instance()
Singleton.
Definition: Profiler.php:62
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
UnlistedSpecialPage
Shortcut to construct a special page which is unlisted by default.
Definition: UnlistedSpecialPage.php:29
text
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
$status
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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:1049
$user
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 account $user
Definition: hooks.txt:246
SpecialPage\checkPermissions
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
Definition: SpecialPage.php:306
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:63
EmailConfirmation\showRequestForm
showRequestForm()
Show a nice form for the user to request a confirmation mail.
Definition: SpecialConfirmemail.php:81
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:82
EmailConfirmation\execute
execute( $code)
Main execution point.
Definition: SpecialConfirmemail.php:49
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition: PermissionsError.php:28
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:705
php
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
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
HTMLForm\factory
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:277
EmailConfirmation\attemptConfirm
attemptConfirm( $code)
Attempt to confirm the user's email address and show success or failure as needed; if successful,...
Definition: SpecialConfirmemail.php:150
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:484
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:685
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1769
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:648
SpecialPage\requireLogin
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
Definition: SpecialPage.php:336
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:746
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:76
$retval
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 account incomplete not yet checked for validity & $retval
Definition: hooks.txt:246
EmailConfirmation\doesWrites
doesWrites()
Indicates whether this special page may perform database writes.
Definition: SpecialConfirmemail.php:37
$code
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:783
EmailConfirmation
Special page allows users to request email confirmation message, and handles processing of the confir...
Definition: SpecialConfirmemail.php:32
EmailConfirmation\submitSend
submitSend()
Callback for HTMLForm send confirmation mail.
Definition: SpecialConfirmemail.php:133
SpecialPage\checkReadOnly
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
Definition: SpecialPage.php:319
$t
$t
Definition: testCompression.php:67
User\newFromConfirmationCode
static newFromConfirmationCode( $code, $flags=0)
Factory method to fetch whichever user has a given email confirmation code.
Definition: User.php:598
$out
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:783