MediaWiki REL1_35
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 false;
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->addHeaderText( $this->msg( 'userlogout-continue' ) );
74
75 $form->addHiddenFields( $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
76 }
77
87 public function onSubmit( array $data ) {
88 // Make sure it's possible to log out
89 $session = MediaWiki\Session\SessionManager::getGlobalSession();
90 if ( !$session->canSetUser() ) {
91 throw new ErrorPageError(
92 'cannotlogoutnow-title',
93 'cannotlogoutnow-text',
94 [
95 $session->getProvider()->describe( RequestContext::getMain()->getLanguage() )
96 ]
97 );
98 }
99
100 $user = $this->getUser();
101
102 $user->logout();
103 return new Status();
104 }
105
106 public function onSuccess() {
107 $this->showSuccess();
108
109 $out = $this->getOutput();
110 // Hook.
111 $injected_html = '';
112 $this->getHookRunner()->onUserLogoutComplete( $this->getUser(), $injected_html, $this->oldUserName );
113 $out->addHTML( $injected_html );
114 }
115
116 private function showSuccess() {
117 $loginURL = SpecialPage::getTitleFor( 'Userlogin' )->getFullURL(
118 $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
119
120 $out = $this->getOutput();
121 $out->addWikiMsg( 'logouttext', $loginURL );
122
123 $out->returnToMain();
124 }
125
130 public function requiresUnblock() {
131 return false;
132 }
133}
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:135
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition HTMLForm.php:819
setTokenSalt( $salt)
Set the salt for the edit token.
addHiddenFields(array $fields)
Add an array of hidden fields to the output.
Definition HTMLForm.php:974
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 Stable to override.
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:44