MediaWiki 1.42.1
ApiLogout.php
Go to the documentation of this file.
1<?php
24
31class ApiLogout extends ApiBase {
32
33 public function execute() {
34 $session = MediaWiki\Session\SessionManager::getGlobalSession();
35
36 // Handle bot password logout specially
37 if ( $session->getProvider() instanceof BotPasswordSessionProvider ) {
38 $session->unpersist();
39 return;
40 }
41
42 // Make sure it's possible to log out
43 if ( !$session->canSetUser() ) {
44 $this->dieWithError(
45 [
46 'cannotlogoutnow-text',
47 $session->getProvider()->describe( $this->getErrorFormatter()->getLanguage() )
48 ],
49 'cannotlogout'
50 );
51 }
52
53 $user = $this->getUser();
54 $oldName = $user->getName();
55 $user->logout();
56
57 // Give extensions to do something after user logout
58 $injected_html = '';
59 $this->getHookRunner()->onUserLogoutComplete( $user, $injected_html, $oldName );
60 }
61
62 public function mustBePosted() {
63 return true;
64 }
65
66 public function needsToken() {
67 return 'csrf';
68 }
69
70 public function isWriteMode() {
71 // While core is optimized by default to not require DB writes on log out,
72 // these are authenticated POST requests and extensions (eg. CheckUser) are
73 // allowed to perform DB writes here without warnings.
74 return true;
75 }
76
77 protected function getWebUITokenSalt( array $params ) {
78 return 'logoutToken';
79 }
80
81 public function isReadMode() {
82 return false;
83 }
84
85 protected function getExamplesMessages() {
86 return [
87 'action=logout&token=123ABC'
88 => 'apihelp-logout-example-logout',
89 ];
90 }
91
92 public function getHelpUrls() {
93 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Logout';
94 }
95}
array $params
The job parameters.
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:64
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1533
getHookRunner()
Get an ApiHookRunner for running core API hooks.
Definition ApiBase.php:756
API module to allow users to log out of the wiki.
Definition ApiLogout.php:31
getWebUITokenSalt(array $params)
Fetch the salt used in the Web UI corresponding to this module.
Definition ApiLogout.php:77
isWriteMode()
Indicates whether this module requires write mode.
Definition ApiLogout.php:70
needsToken()
Returns the token type this module requires in order to execute.
Definition ApiLogout.php:66
getHelpUrls()
Return links to more detailed help pages about the module.
Definition ApiLogout.php:92
mustBePosted()
Indicates whether this module must be called with a POST request.
Definition ApiLogout.php:62
isReadMode()
Indicates whether this module requires read rights.
Definition ApiLogout.php:81
getExamplesMessages()
Returns usage examples for this module.
Definition ApiLogout.php:85
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition ApiLogout.php:33