MediaWiki 1.42.0
SpecialUserLogout.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Specials;
25
32
42 private $oldUserName;
43
44 public function __construct() {
45 parent::__construct( 'Userlogout' );
46 }
47
48 public function doesWrites() {
49 return true;
50 }
51
52 public function isListed() {
53 return $this->getAuthManager()->canAuthenticateNow();
54 }
55
56 protected function getGroupName() {
57 return 'login';
58 }
59
60 protected function getFormFields() {
61 return [];
62 }
63
64 protected function getDisplayFormat() {
65 return 'ooui';
66 }
67
68 public function execute( $par ) {
69 $user = $this->getUser();
70 if ( $user->isAnon() ) {
71 $this->setHeaders();
72 $this->showSuccess();
73 return;
74 }
75 $this->oldUserName = $user->getName();
76
77 parent::execute( $par );
78 }
79
80 public function alterForm( HTMLForm $form ) {
81 $form->setTokenSalt( 'logoutToken' );
82 $form->addHeaderHtml( $this->msg(
83 $this->getUser()->isTemp() ? 'userlogout-temp' : 'userlogout-continue'
84 ) );
85
86 $form->addHiddenFields( $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
87 }
88
96 public function onSubmit( array $data ) {
97 // Make sure it's possible to log out
98 $session = SessionManager::getGlobalSession();
99 if ( !$session->canSetUser() ) {
100 throw new ErrorPageError(
101 'cannotlogoutnow-title',
102 'cannotlogoutnow-text',
103 [
104 $session->getProvider()->describe( $this->getLanguage() )
105 ]
106 );
107 }
108
109 $user = $this->getUser();
110
111 $user->logout();
112 return new Status();
113 }
114
115 public function onSuccess() {
116 $this->showSuccess();
117
118 $out = $this->getOutput();
119 // Hook.
120 $injected_html = '';
121 $this->getHookRunner()->onUserLogoutComplete( $this->getUser(), $injected_html, $this->oldUserName );
122 $out->addHTML( $injected_html );
123 }
124
125 private function showSuccess() {
126 $loginURL = SpecialPage::getTitleFor( 'Userlogin' )->getFullURL(
127 $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
128
129 $out = $this->getOutput();
130 $out->addWikiMsg( 'logouttext', $loginURL );
131
132 $out->returnToMain();
133 }
134
139 public function requiresUnblock() {
140 return false;
141 }
142}
143
148class_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:944
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
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...