| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 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; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
class SpecialUserLogout extends FormSpecialPage { |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
private $oldUserName; |
| 42 |
|
| 43 |
private TempUserConfig $tempUserConfig; |
| 44 |
|
| 45 |
public function __construct( TempUserConfig $tempUserConfig ) { |
| 46 |
parent::__construct( 'Userlogout' ); |
| 47 |
$this->tempUserConfig = $tempUserConfig; |
| 48 |
} |
| 49 |
|
| 50 |
public function doesWrites() { |
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
public function isListed() { |
| 55 |
return $this->getAuthManager()->canAuthenticateNow(); |
| 56 |
} |
| 57 |
|
| 58 |
protected function getGroupName() { |
| 59 |
return 'login'; |
| 60 |
} |
| 61 |
|
| 62 |
protected function getFormFields() { |
| 63 |
return []; |
| 64 |
} |
| 65 |
|
| 66 |
protected function getDisplayFormat() { |
| 67 |
return 'ooui'; |
| 68 |
} |
| 69 |
|
| 70 |
public function execute( $par ) { |
| 71 |
$user = $this->getUser(); |
| 72 |
if ( $user->isAnon() ) { |
| 73 |
$this->setHeaders(); |
| 74 |
$this->showSuccess(); |
| 75 |
return; |
| 76 |
} |
| 77 |
$this->oldUserName = $user->getName(); |
| 78 |
|
| 79 |
parent::execute( $par ); |
| 80 |
} |
| 81 |
|
| 82 |
public function alterForm( HTMLForm $form ) { |
| 83 |
$form->setTokenSalt( 'logoutToken' ); |
| 84 |
$form->addHeaderHtml( $this->msg( |
| 85 |
$this->getUser()->isTemp() ? 'userlogout-temp' : 'userlogout-continue' |
| 86 |
) ); |
| 87 |
|
| 88 |
$form->addHiddenFields( $this->getRequest()->getValues( 'returnto', 'returntoquery' ) ); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public function onSubmit( array $data ) { |
| 99 |
|
| 100 |
$session = SessionManager::getGlobalSession(); |
| 101 |
if ( !$session->canSetUser() ) { |
| 102 |
throw new ErrorPageError( |
| 103 |
'cannotlogoutnow-title', |
| 104 |
'cannotlogoutnow-text', |
| 105 |
[ |
| 106 |
$session->getProvider()->describe( $this->getLanguage() ) |
| 107 |
] |
| 108 |
); |
| 109 |
} |
| 110 |
|
| 111 |
$user = $this->getUser(); |
| 112 |
|
| 113 |
$user->logout(); |
| 114 |
return new Status(); |
| 115 |
} |
| 116 |
|
| 117 |
public function onSuccess() { |
| 118 |
$this->showSuccess(); |
| 119 |
|
| 120 |
$out = $this->getOutput(); |
| 121 |
|
| 122 |
$injected_html = ''; |
| 123 |
$this->getHookRunner()->onUserLogoutComplete( $this->getUser(), $injected_html, $this->oldUserName ); |
| 124 |
$out->addHTML( $injected_html ); |
| 125 |
} |
| 126 |
|
| 127 |
private function showSuccess() { |
| 128 |
$loginURL = SpecialPage::getTitleFor( 'Userlogin' )->getFullURL( |
| 129 |
$this->getRequest()->getValues( 'returnto', 'returntoquery' ) ); |
| 130 |
|
| 131 |
$out = $this->getOutput(); |
| 132 |
|
| 133 |
$messageKey = 'logouttext'; |
| 134 |
if ( |
| 135 |
( isset( $this->oldUserName ) && $this->tempUserConfig->isTempName( $this->oldUserName ) ) || |
| 136 |
$this->getRequest()->getCheck( 'wasTempUser' ) |
| 137 |
) { |
| 138 |
|
| 139 |
|
| 140 |
$messageKey .= '-for-temporary-account'; |
| 141 |
} |
| 142 |
$out->addWikiMsg( $messageKey, $loginURL ); |
| 143 |
|
| 144 |
$out->returnToMain(); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
public function requiresUnblock() { |
| 152 |
return false; |
| 153 |
} |
| 154 |
|
| 155 |
public function getDescription() { |
| 156 |
|
| 157 |
if ( |
| 158 |
$this->getUser()->isTemp() || |
| 159 |
( isset( $this->oldUserName ) && $this->tempUserConfig->isTempName( $this->oldUserName ) ) || |
| 160 |
$this->getRequest()->getCheck( 'wasTempUser' ) |
| 161 |
) { |
| 162 |
return $this->msg( 'templogout' ); |
| 163 |
} |
| 164 |
return parent::getDescription(); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
class_alias( SpecialUserLogout::class, 'SpecialUserLogout' ); |