Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / api / ApiLogout.php
blob48fc5f882dfca1041d9449902eb7915e9fb0a3ad
1 <?php
2 /**
3 * Copyright © 2008 Yuri Astrakhan "<Firstname><Lastname>@gmail.com",
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
23 namespace MediaWiki\Api;
25 use MediaWiki\Session\BotPasswordSessionProvider;
26 use MediaWiki\Session\SessionManager;
28 /**
29 * API module to allow users to log out of the wiki. API equivalent of
30 * Special:Userlogout.
32 * @ingroup API
34 class ApiLogout extends ApiBase {
36 public function execute() {
37 $session = SessionManager::getGlobalSession();
39 // Handle bot password logout specially
40 if ( $session->getProvider() instanceof BotPasswordSessionProvider ) {
41 $session->unpersist();
42 return;
45 // Make sure it's possible to log out
46 if ( !$session->canSetUser() ) {
47 $this->dieWithError(
49 'cannotlogoutnow-text',
50 $session->getProvider()->describe( $this->getErrorFormatter()->getLanguage() )
52 'cannotlogout'
56 $user = $this->getUser();
58 if ( $user->isAnon() ) {
59 // Cannot logout a anon user, so add a warning and return early.
60 $this->addWarning( 'apierror-mustbeloggedin-generic', 'notloggedin' );
61 return;
64 $oldName = $user->getName();
65 $user->logout();
67 // Give extensions to do something after user logout
68 $injected_html = '';
69 $this->getHookRunner()->onUserLogoutComplete( $user, $injected_html, $oldName );
72 public function mustBePosted() {
73 return true;
76 public function needsToken() {
77 return 'csrf';
80 public function isWriteMode() {
81 // While core is optimized by default to not require DB writes on log out,
82 // these are authenticated POST requests and extensions (eg. CheckUser) are
83 // allowed to perform DB writes here without warnings.
84 return true;
87 protected function getWebUITokenSalt( array $params ) {
88 return 'logoutToken';
91 public function isReadMode() {
92 return false;
95 protected function getExamplesMessages() {
96 return [
97 'action=logout&token=123ABC'
98 => 'apihelp-logout-example-logout',
102 public function getHelpUrls() {
103 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Logout';
107 /** @deprecated class alias since 1.43 */
108 class_alias( ApiLogout::class, 'ApiLogout' );