3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 namespace MediaWiki\Specials
;
24 use MediaWiki\HTMLForm\HTMLForm
;
25 use MediaWiki\Session\SessionManager
;
26 use MediaWiki\SpecialPage\FormSpecialPage
;
27 use MediaWiki\SpecialPage\SpecialPage
;
28 use MediaWiki\Status\Status
;
29 use MediaWiki\User\TempUser\TempUserConfig
;
32 * Implements Special:Userlogout
34 * @ingroup SpecialPage
37 class SpecialUserLogout
extends FormSpecialPage
{
43 private TempUserConfig
$tempUserConfig;
45 public function __construct( TempUserConfig
$tempUserConfig ) {
46 parent
::__construct( 'Userlogout' );
47 $this->tempUserConfig
= $tempUserConfig;
50 public function doesWrites() {
54 public function isListed() {
55 return $this->getAuthManager()->canAuthenticateNow();
58 protected function getGroupName() {
62 protected function getFormFields() {
66 protected function getDisplayFormat() {
70 public function execute( $par ) {
71 $user = $this->getUser();
72 if ( $user->isAnon() ) {
77 $this->oldUserName
= $user->getName();
79 parent
::execute( $par );
82 public function alterForm( HTMLForm
$form ) {
83 $form->setTokenSalt( 'logoutToken' );
84 $form->addHeaderHtml( $this->msg(
85 $this->getUser()->isTemp() ?
'userlogout-temp' : 'userlogout-continue'
88 $form->addHiddenFields( $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
92 * Process the form. At this point we know that the user passes all the criteria in
93 * userCanExecute(), and if the data array contains 'Username', etc, then Username
98 public function onSubmit( array $data ) {
99 // Make sure it's possible to log out
100 $session = SessionManager
::getGlobalSession();
101 if ( !$session->canSetUser() ) {
102 throw new ErrorPageError(
103 'cannotlogoutnow-title',
104 'cannotlogoutnow-text',
106 $session->getProvider()->describe( $this->getLanguage() )
111 $user = $this->getUser();
117 public function onSuccess() {
118 $this->showSuccess();
120 $out = $this->getOutput();
123 $this->getHookRunner()->onUserLogoutComplete( $this->getUser(), $injected_html, $this->oldUserName
);
124 $out->addHTML( $injected_html );
127 private function showSuccess() {
128 $loginURL = SpecialPage
::getTitleFor( 'Userlogin' )->getFullURL(
129 $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
131 $out = $this->getOutput();
133 $messageKey = 'logouttext';
135 ( $this->oldUserName
!== null && $this->tempUserConfig
->isTempName( $this->oldUserName
) ) ||
136 $this->getRequest()->getCheck( 'wasTempUser' )
138 // Generates the message key logouttext-for-temporary-account which is used to customise the success
139 // message for a temporary account.
140 $messageKey .= '-for-temporary-account';
142 $out->addWikiMsg( $messageKey, $loginURL );
144 $out->returnToMain();
148 * Let blocked users to log out and come back with their sockpuppets
151 public function requiresUnblock() {
155 public function getDescription() {
156 // Set the page title as "templogout" if the user is (or just was) logged in to a temporary account
158 $this->getUser()->isTemp() ||
159 ( $this->oldUserName
!== null && $this->tempUserConfig
->isTempName( $this->oldUserName
) ) ||
160 $this->getRequest()->getCheck( 'wasTempUser' )
162 return $this->msg( 'templogout' );
164 return parent
::getDescription();
169 * Retain the old class name for backwards compatibility.
170 * @deprecated since 1.41
172 class_alias( SpecialUserLogout
::class, 'SpecialUserLogout' );