Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / specials / SpecialUserLogout.php
blob0988397324f95fb1a1426951baa93de57ded1490
1 <?php
2 /**
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
18 * @file
21 namespace MediaWiki\Specials;
23 use ErrorPageError;
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;
31 /**
32 * Implements Special:Userlogout
34 * @ingroup SpecialPage
35 * @ingroup Auth
37 class SpecialUserLogout extends FormSpecialPage {
38 /**
39 * @var string|null
41 private $oldUserName;
43 private TempUserConfig $tempUserConfig;
45 public function __construct( TempUserConfig $tempUserConfig ) {
46 parent::__construct( 'Userlogout' );
47 $this->tempUserConfig = $tempUserConfig;
50 public function doesWrites() {
51 return true;
54 public function isListed() {
55 return $this->getAuthManager()->canAuthenticateNow();
58 protected function getGroupName() {
59 return 'login';
62 protected function getFormFields() {
63 return [];
66 protected function getDisplayFormat() {
67 return 'ooui';
70 public function execute( $par ) {
71 $user = $this->getUser();
72 if ( $user->isAnon() ) {
73 $this->setHeaders();
74 $this->showSuccess();
75 return;
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'
86 ) );
88 $form->addHiddenFields( $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
91 /**
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
94 * resets are allowed.
95 * @param array $data
96 * @return Status
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();
113 $user->logout();
114 return new Status();
117 public function onSuccess() {
118 $this->showSuccess();
120 $out = $this->getOutput();
121 // Hook.
122 $injected_html = '';
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';
134 if (
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
149 * @return bool
151 public function requiresUnblock() {
152 return false;
155 public function getDescription() {
156 // Set the page title as "templogout" if the user is (or just was) logged in to a temporary account
157 if (
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' );