MediaWiki  master
SpecialUserLogout.php
Go to the documentation of this file.
1 <?php
33  private $oldUserName;
34 
35  public function __construct() {
36  parent::__construct( 'Userlogout' );
37  }
38 
39  public function doesWrites() {
40  return true;
41  }
42 
43  public function isListed() {
44  return $this->getAuthManager()->canAuthenticateNow();
45  }
46 
47  protected function getGroupName() {
48  return 'login';
49  }
50 
51  protected function getFormFields() {
52  return [];
53  }
54 
55  protected function getDisplayFormat() {
56  return 'ooui';
57  }
58 
59  public function execute( $par ) {
60  $user = $this->getUser();
61  if ( $user->isAnon() ) {
62  $this->setHeaders();
63  $this->showSuccess();
64  return;
65  }
66  $this->oldUserName = $user->getName();
67 
68  parent::execute( $par );
69  }
70 
71  public function alterForm( HTMLForm $form ) {
72  $form->setTokenSalt( 'logoutToken' );
73  $form->addHeaderHtml( $this->msg(
74  $this->getUser()->isTemp() ? 'userlogout-temp' : 'userlogout-continue'
75  ) );
76 
77  $form->addHiddenFields( $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
78  }
79 
89  public function onSubmit( array $data ) {
90  // Make sure it's possible to log out
92  if ( !$session->canSetUser() ) {
93  throw new ErrorPageError(
94  'cannotlogoutnow-title',
95  'cannotlogoutnow-text',
96  [
97  $session->getProvider()->describe( $this->getLanguage() )
98  ]
99  );
100  }
101 
102  $user = $this->getUser();
103 
104  $user->logout();
105  return new Status();
106  }
107 
108  public function onSuccess() {
109  $this->showSuccess();
110 
111  $out = $this->getOutput();
112  // Hook.
113  $injected_html = '';
114  $this->getHookRunner()->onUserLogoutComplete( $this->getUser(), $injected_html, $this->oldUserName );
115  $out->addHTML( $injected_html );
116  }
117 
118  private function showSuccess() {
119  $loginURL = SpecialPage::getTitleFor( 'Userlogin' )->getFullURL(
120  $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
121 
122  $out = $this->getOutput();
123  $out->addWikiMsg( 'logouttext', $loginURL );
124 
125  $out->returnToMain();
126  }
127 
132  public function requiresUnblock() {
133  return false;
134  }
135 }
An error page which can definitely be safely rendered using the OutputPage.
Special page which uses an HTMLForm to handle processing.
string null $par
The sub-page of the special page.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:153
addHeaderHtml( $html, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:895
setTokenSalt( $salt)
Set the salt for the edit token.
Definition: HTMLForm.php:1247
addHiddenFields(array $fields)
Add an array of hidden fields to the output Array values are discarded for security reasons (per WebR...
Definition: HTMLForm.php:1171
static getGlobalSession()
If PHP's session_id() has been set, returns that session.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
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,...
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getRequest()
Get the WebRequest being used for this instance.
Implements Special:Userlogout.
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
getDisplayFormat()
Get display format for the form.
isListed()
Whether this special page is listed in Special:SpecialPages.
doesWrites()
Indicates whether this special page may perform database writes.
execute( $par)
Basic SpecialPage workflow: get a form, send it to the user; get some data back,.
onSubmit(array $data)
Process the form.
getFormFields()
Get an HTMLForm descriptor array.
requiresUnblock()
Let blocked users to log out and come back with their sockpuppets.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:46