Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
48.15% |
13 / 27 |
|
62.50% |
5 / 8 |
CRAP | |
0.00% |
0 / 1 |
ApiLogout | |
48.15% |
13 / 27 |
|
62.50% |
5 / 8 |
23.94 | |
0.00% |
0 / 1 |
execute | |
47.06% |
8 / 17 |
|
0.00% |
0 / 1 |
4.34 | |||
mustBePosted | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
needsToken | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isWriteMode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getWebUITokenSalt | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isReadMode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Copyright © 2008 Yuri Astrakhan "<Firstname><Lastname>@gmail.com", |
4 | * |
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. |
9 | * |
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. |
14 | * |
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 |
19 | * |
20 | * @file |
21 | */ |
22 | |
23 | use MediaWiki\Session\BotPasswordSessionProvider; |
24 | |
25 | /** |
26 | * API module to allow users to log out of the wiki. API equivalent of |
27 | * Special:Userlogout. |
28 | * |
29 | * @ingroup API |
30 | */ |
31 | class 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 | } |