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