| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
namespace MediaWiki\SpecialPage; |
| 25 |
|
| 26 |
use ErrorPageError; |
| 27 |
use Exception; |
| 28 |
use FatalError; |
| 29 |
use LogicException; |
| 30 |
use LoginHelper; |
| 31 |
use MediaWiki\Auth\AuthenticationRequest; |
| 32 |
use MediaWiki\Auth\AuthenticationResponse; |
| 33 |
use MediaWiki\Auth\AuthManager; |
| 34 |
use MediaWiki\Auth\PasswordAuthenticationRequest; |
| 35 |
use MediaWiki\Auth\UsernameAuthenticationRequest; |
| 36 |
use MediaWiki\Context\DerivativeContext; |
| 37 |
use MediaWiki\Context\RequestContext; |
| 38 |
use MediaWiki\Html\Html; |
| 39 |
use MediaWiki\HTMLForm\HTMLForm; |
| 40 |
use MediaWiki\Language\RawMessage; |
| 41 |
use MediaWiki\Logger\LoggerFactory; |
| 42 |
use MediaWiki\MainConfigNames; |
| 43 |
use MediaWiki\MediaWikiServices; |
| 44 |
use MediaWiki\Message\Message; |
| 45 |
use MediaWiki\Parser\Sanitizer; |
| 46 |
use MediaWiki\Session\SessionManager; |
| 47 |
use MediaWiki\Status\Status; |
| 48 |
use MediaWiki\Title\Title; |
| 49 |
use MediaWiki\User\User; |
| 50 |
use PermissionsError; |
| 51 |
use ReadOnlyError; |
| 52 |
use Skin; |
| 53 |
use StatusValue; |
| 54 |
use Wikimedia\ScopedCallback; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage { |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
protected string $mReturnTo; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
protected string $mReturnToQuery; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
protected string $mReturnToAnchor; |
| 85 |
|
| 86 |
|
| 87 |
protected $mPosted; |
| 88 |
|
| 89 |
protected $mAction; |
| 90 |
|
| 91 |
protected $mToken; |
| 92 |
|
| 93 |
protected $mStickHTTPS; |
| 94 |
|
| 95 |
protected $mFromHTTP; |
| 96 |
|
| 97 |
protected $mEntryError = ''; |
| 98 |
|
| 99 |
protected $mEntryErrorType = 'error'; |
| 100 |
|
| 101 |
protected $mDisplay = 'page'; |
| 102 |
|
| 103 |
|
| 104 |
protected $mLoaded = false; |
| 105 |
|
| 106 |
protected $mLoadedRequest = false; |
| 107 |
|
| 108 |
protected $mSecureLoginUrl; |
| 109 |
|
| 110 |
private $reasonValidatorResult = null; |
| 111 |
|
| 112 |
|
| 113 |
protected $securityLevel; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
protected $proxyAccountCreation; |
| 119 |
|
| 120 |
protected $targetUser; |
| 121 |
|
| 122 |
|
| 123 |
protected $authForm; |
| 124 |
|
| 125 |
abstract protected function isSignup(); |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
abstract protected function successfulAction( $direct = false, $extraMessages = null ); |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
abstract protected function logAuthResult( $success, $status = null ); |
| 141 |
|
| 142 |
protected function setRequest( array $data, $wasPosted = null ) { |
| 143 |
parent::setRequest( $data, $wasPosted ); |
| 144 |
$this->mLoadedRequest = false; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
private function loadRequestParameters() { |
| 151 |
if ( $this->mLoadedRequest ) { |
| 152 |
return; |
| 153 |
} |
| 154 |
$this->mLoadedRequest = true; |
| 155 |
$request = $this->getRequest(); |
| 156 |
|
| 157 |
$this->mPosted = $request->wasPosted(); |
| 158 |
$this->mAction = $request->getRawVal( 'action' ); |
| 159 |
$this->mFromHTTP = $request->getBool( 'fromhttp', false ) |
| 160 |
|| $request->getBool( 'wpFromhttp', false ); |
| 161 |
$this->mStickHTTPS = $this->getConfig()->get( MainConfigNames::ForceHTTPS ) |
| 162 |
|| ( !$this->mFromHTTP && $request->getProtocol() === 'https' ) |
| 163 |
|| $request->getBool( 'wpForceHttps', false ); |
| 164 |
$this->mReturnTo = $request->getVal( 'returnto', '' ); |
| 165 |
$this->mReturnToQuery = $request->getVal( 'returntoquery', '' ); |
| 166 |
$this->mReturnToAnchor = $request->getVal( 'returntoanchor', '' ); |
| 167 |
if ( $request->getVal( 'display' ) === 'popup' ) { |
| 168 |
$this->mDisplay = 'popup'; |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
protected function load( $subPage ) { |
| 178 |
$this->loadRequestParameters(); |
| 179 |
if ( $this->mLoaded ) { |
| 180 |
return; |
| 181 |
} |
| 182 |
$this->mLoaded = true; |
| 183 |
$request = $this->getRequest(); |
| 184 |
|
| 185 |
$securityLevel = $this->getRequest()->getText( 'force' ); |
| 186 |
if ( |
| 187 |
$securityLevel && |
| 188 |
MediaWikiServices::getInstance()->getAuthManager()->securitySensitiveOperationStatus( |
| 189 |
$securityLevel ) === AuthManager::SEC_REAUTH |
| 190 |
) { |
| 191 |
$this->securityLevel = $securityLevel; |
| 192 |
} |
| 193 |
|
| 194 |
$this->loadAuth( $subPage ); |
| 195 |
|
| 196 |
$this->mToken = $request->getVal( $this->getTokenName() ); |
| 197 |
|
| 198 |
|
| 199 |
$entryError = $this->msg( $request->getVal( 'error', '' ) ); |
| 200 |
$entryWarning = $this->msg( $request->getVal( 'warning', '' ) ); |
| 201 |
$entryNotice = $this->msg( $request->getVal( 'notice', '' ) ); |
| 202 |
|
| 203 |
|
| 204 |
$loginreqlink = $this->getLinkRenderer()->makeKnownLink( |
| 205 |
$this->getPageTitle(), |
| 206 |
$this->msg( 'loginreqlink' )->text(), |
| 207 |
[], |
| 208 |
$this->getPreservedParams( [ 'reset' => true ] ) |
| 209 |
); |
| 210 |
|
| 211 |
|
| 212 |
$validErrorMessages = LoginHelper::getValidErrorMessages(); |
| 213 |
if ( $entryError->exists() |
| 214 |
&& in_array( $entryError->getKey(), $validErrorMessages, true ) |
| 215 |
) { |
| 216 |
$this->mEntryErrorType = 'error'; |
| 217 |
$this->mEntryError = $entryError->rawParams( $loginreqlink )->parse(); |
| 218 |
|
| 219 |
} elseif ( $entryWarning->exists() |
| 220 |
&& in_array( $entryWarning->getKey(), $validErrorMessages, true ) |
| 221 |
) { |
| 222 |
$this->mEntryErrorType = 'warning'; |
| 223 |
$this->mEntryError = $entryWarning->rawParams( $loginreqlink )->parse(); |
| 224 |
} elseif ( $entryNotice->exists() |
| 225 |
&& in_array( $entryNotice->getKey(), $validErrorMessages, true ) |
| 226 |
) { |
| 227 |
$this->mEntryErrorType = 'notice'; |
| 228 |
$this->mEntryError = $entryNotice->parse(); |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
$returnToTitle = Title::newFromText( $this->mReturnTo ); |
| 235 |
if ( is_object( $returnToTitle ) |
| 236 |
&& ( $returnToTitle->isSpecial( 'Userlogout' ) |
| 237 |
|| $returnToTitle->isSpecial( 'PasswordReset' ) ) |
| 238 |
) { |
| 239 |
$this->mReturnTo = ''; |
| 240 |
$this->mReturnToQuery = ''; |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
protected function getPreservedParams( $options = [] ) { |
| 246 |
$params = parent::getPreservedParams( $options ); |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
$this->loadRequestParameters(); |
| 251 |
$properties = [ |
| 252 |
'returnto' => 'mReturnTo', |
| 253 |
'returntoquery' => 'mReturnToQuery', |
| 254 |
'returntoanchor' => 'mReturnToAnchor', |
| 255 |
]; |
| 256 |
foreach ( $properties as $key => $prop ) { |
| 257 |
$value = $this->$prop; |
| 258 |
if ( $value !== '' ) { |
| 259 |
$params[$key] = $value; |
| 260 |
} else { |
| 261 |
unset( $params[$key] ); |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
if ( $this->getConfig()->get( MainConfigNames::SecureLogin ) && !$this->isSignup() ) { |
| 266 |
$params['fromhttp'] = $this->mFromHTTP ? '1' : null; |
| 267 |
} |
| 268 |
if ( $this->mDisplay !== 'page' ) { |
| 269 |
$params['display'] = $this->mDisplay; |
| 270 |
} |
| 271 |
|
| 272 |
return array_filter( $params, fn ( $val ) => $val !== null ); |
| 273 |
} |
| 274 |
|
| 275 |
protected function beforeExecute( $subPage ) { |
| 276 |
|
| 277 |
$this->loadRequestParameters(); |
| 278 |
return parent::beforeExecute( $subPage ); |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
public function execute( $subPage ) { |
| 286 |
if ( $this->mPosted ) { |
| 287 |
$time = microtime( true ); |
| 288 |
$profilingScope = new ScopedCallback( function () use ( $time ) { |
| 289 |
$time = microtime( true ) - $time; |
| 290 |
$stats = MediaWikiServices::getInstance()->getStatsFactory(); |
| 291 |
$stats->getTiming( 'auth_specialpage_executeTiming_seconds' ) |
| 292 |
->setLabel( 'action', $this->authAction ) |
| 293 |
->copyToStatsdAt( "timing.login.ui.{$this->authAction}" ) |
| 294 |
->observe( $time * 1000 ); |
| 295 |
} ); |
| 296 |
} |
| 297 |
|
| 298 |
$authManager = MediaWikiServices::getInstance()->getAuthManager(); |
| 299 |
$session = SessionManager::getGlobalSession(); |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
$session->persist(); |
| 304 |
|
| 305 |
|
| 306 |
$this->getOutput()->disableClientCache(); |
| 307 |
|
| 308 |
$this->load( $subPage ); |
| 309 |
|
| 310 |
|
| 311 |
if ( $this->mDisplay === 'popup' ) { |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
$skinFactory = MediaWikiServices::getInstance()->getSkinFactory(); |
| 316 |
$this->getContext()->setSkin( $skinFactory->makeSkin( 'authentication-popup' ) ); |
| 317 |
} |
| 318 |
|
| 319 |
$this->setHeaders(); |
| 320 |
$this->checkPermissions(); |
| 321 |
|
| 322 |
|
| 323 |
if ( !$this->isSignup() && !$authManager->canAuthenticateNow() ) { |
| 324 |
if ( !$session->canSetUser() ) { |
| 325 |
throw new ErrorPageError( 'cannotloginnow-title', 'cannotloginnow-text', [ |
| 326 |
$session->getProvider()->describe( $this->getLanguage() ) |
| 327 |
] ); |
| 328 |
} |
| 329 |
throw new ErrorPageError( 'cannotlogin-title', 'cannotlogin-text' ); |
| 330 |
} elseif ( $this->isSignup() && !$authManager->canCreateAccounts() ) { |
| 331 |
throw new ErrorPageError( 'cannotcreateaccount-title', 'cannotcreateaccount-text' ); |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
if ( !$this->isSignup() && !$this->mPosted && !$this->securityLevel && |
| 353 |
( $this->mReturnTo !== '' || $this->mReturnToQuery !== '' ) && |
| 354 |
!$this->getUser()->isTemp() && $this->getUser()->isRegistered() |
| 355 |
) { |
| 356 |
$this->successfulAction(); |
| 357 |
return; |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
if ( $this->getRequest()->getProtocol() !== 'https' ) { |
| 362 |
$title = $this->getFullTitle(); |
| 363 |
$query = $this->getPreservedParams() + [ |
| 364 |
'title' => null, |
| 365 |
( $this->mEntryErrorType === 'error' ? 'error' |
| 366 |
: 'warning' ) => $this->mEntryError, |
| 367 |
] + $this->getRequest()->getQueryValues(); |
| 368 |
$url = $title->getFullURL( $query, false, PROTO_HTTPS ); |
| 369 |
if ( $this->getConfig()->get( MainConfigNames::SecureLogin ) && !$this->mFromHTTP ) { |
| 370 |
|
| 371 |
$url = wfAppendQuery( $url, 'fromhttp=1' ); |
| 372 |
$this->getOutput()->redirect( $url ); |
| 373 |
|
| 374 |
$this->getOutput()->addVaryHeader( 'X-Forwarded-Proto' ); |
| 375 |
|
| 376 |
return; |
| 377 |
} else { |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
if ( str_starts_with( $url, 'https://' ) ) { |
| 382 |
$this->mSecureLoginUrl = $url; |
| 383 |
} |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
if ( !$this->isActionAllowed( $this->authAction ) ) { |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
$this->mainLoginForm( [], 'authpage-cannot-' . $this->authAction ); |
| 392 |
return; |
| 393 |
} |
| 394 |
|
| 395 |
if ( $this->canBypassForm( $button_name ) ) { |
| 396 |
$this->setRequest( [], true ); |
| 397 |
$this->getRequest()->setVal( $this->getTokenName(), $this->getToken() ); |
| 398 |
if ( $button_name ) { |
| 399 |
$this->getRequest()->setVal( $button_name, true ); |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
$status = $this->trySubmit(); |
| 404 |
|
| 405 |
if ( !$status || !$status->isGood() ) { |
| 406 |
$this->mainLoginForm( $this->authRequests, $status ? $status->getMessage() : '', 'error' ); |
| 407 |
return; |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
$response = $status->getValue(); |
| 412 |
|
| 413 |
$returnToUrl = $this->getPageTitle( 'return' ) |
| 414 |
->getFullURL( $this->getPreservedParams( [ 'withToken' => true ] ), false, PROTO_HTTPS ); |
| 415 |
switch ( $response->status ) { |
| 416 |
case AuthenticationResponse::PASS: |
| 417 |
$this->logAuthResult( true ); |
| 418 |
$this->proxyAccountCreation = $this->isSignup() && $this->getUser()->isNamed(); |
| 419 |
$this->targetUser = User::newFromName( $response->username ); |
| 420 |
|
| 421 |
if ( |
| 422 |
!$this->proxyAccountCreation |
| 423 |
&& $response->loginRequest |
| 424 |
&& $authManager->canAuthenticateNow() |
| 425 |
) { |
| 426 |
|
| 427 |
$response2 = $authManager->beginAuthentication( [ $response->loginRequest ], |
| 428 |
$returnToUrl ); |
| 429 |
if ( $response2->status !== AuthenticationResponse::PASS ) { |
| 430 |
LoggerFactory::getInstance( 'login' ) |
| 431 |
->error( 'Could not log in after account creation' ); |
| 432 |
$this->successfulAction( true, Status::newFatal( 'createacct-loginerror' ) ); |
| 433 |
break; |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
if ( !$this->proxyAccountCreation ) { |
| 438 |
$context = RequestContext::getMain(); |
| 439 |
$localContext = $this->getContext(); |
| 440 |
if ( $context !== $localContext ) { |
| 441 |
|
| 442 |
$this->setContext( $context ); |
| 443 |
} |
| 444 |
|
| 445 |
$this->getAuthManager()->setRequestContextUserFromSessionUser(); |
| 446 |
} |
| 447 |
|
| 448 |
$this->successfulAction( true ); |
| 449 |
break; |
| 450 |
case AuthenticationResponse::FAIL: |
| 451 |
|
| 452 |
case AuthenticationResponse::RESTART: |
| 453 |
unset( $this->authForm ); |
| 454 |
if ( $response->status === AuthenticationResponse::FAIL ) { |
| 455 |
$action = $this->getDefaultAction( $subPage ); |
| 456 |
$messageType = 'error'; |
| 457 |
} else { |
| 458 |
$action = $this->getContinueAction( $this->authAction ); |
| 459 |
$messageType = 'warning'; |
| 460 |
} |
| 461 |
$this->logAuthResult( false, $response->message ? $response->message->getKey() : '-' ); |
| 462 |
$this->loadAuth( $subPage, $action, true ); |
| 463 |
$this->mainLoginForm( $this->authRequests, $response->message, $messageType ); |
| 464 |
break; |
| 465 |
case AuthenticationResponse::REDIRECT: |
| 466 |
unset( $this->authForm ); |
| 467 |
$this->getOutput()->redirect( $response->redirectTarget ); |
| 468 |
break; |
| 469 |
case AuthenticationResponse::UI: |
| 470 |
unset( $this->authForm ); |
| 471 |
$this->authAction = $this->isSignup() ? AuthManager::ACTION_CREATE_CONTINUE |
| 472 |
: AuthManager::ACTION_LOGIN_CONTINUE; |
| 473 |
$this->authRequests = $response->neededRequests; |
| 474 |
$this->mainLoginForm( $response->neededRequests, $response->message, $response->messageType ); |
| 475 |
break; |
| 476 |
default: |
| 477 |
throw new LogicException( 'invalid AuthenticationResponse' ); |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
private function canBypassForm( &$button_name ) { |
| 495 |
$button_name = null; |
| 496 |
if ( $this->isContinued() ) { |
| 497 |
return false; |
| 498 |
} |
| 499 |
$fields = AuthenticationRequest::mergeFieldInfo( $this->authRequests ); |
| 500 |
foreach ( $fields as $fieldname => $field ) { |
| 501 |
if ( !isset( $field['type'] ) ) { |
| 502 |
return false; |
| 503 |
} |
| 504 |
if ( !empty( $field['skippable'] ) ) { |
| 505 |
continue; |
| 506 |
} |
| 507 |
if ( $field['type'] === 'button' ) { |
| 508 |
if ( $button_name !== null ) { |
| 509 |
$button_name = null; |
| 510 |
return false; |
| 511 |
} else { |
| 512 |
$button_name = $fieldname; |
| 513 |
} |
| 514 |
} elseif ( $field['type'] !== 'null' ) { |
| 515 |
return false; |
| 516 |
} |
| 517 |
} |
| 518 |
return true; |
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
protected function showSuccessPage( |
| 531 |
$type, $title, $msgname, $injected_html, $extraMessages |
| 532 |
) { |
| 533 |
$out = $this->getOutput(); |
| 534 |
if ( is_string( $title ) ) { |
| 535 |
wfDeprecated( __METHOD__ . ' with string title', '1.41' ); |
| 536 |
$title = ( new RawMessage( '$1' ) )->rawParams( $title ); |
| 537 |
} |
| 538 |
$out->setPageTitleMsg( $title ); |
| 539 |
if ( $msgname ) { |
| 540 |
$out->addWikiMsg( $msgname, wfEscapeWikiText( $this->getUser()->getName() ) ); |
| 541 |
} |
| 542 |
if ( $extraMessages ) { |
| 543 |
$extraMessages = Status::wrap( $extraMessages ); |
| 544 |
$out->addWikiTextAsInterface( |
| 545 |
$extraMessages->getWikiText( false, false, $this->getLanguage() ) |
| 546 |
); |
| 547 |
} |
| 548 |
|
| 549 |
$out->addHTML( $injected_html ); |
| 550 |
|
| 551 |
$helper = new LoginHelper( $this->getContext() ); |
| 552 |
$helper->showReturnToPage( $type, $this->mReturnTo, $this->mReturnToQuery, |
| 553 |
$this->mStickHTTPS, $this->mReturnToAnchor ); |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
protected function mainLoginForm( array $requests, $msg = '', $msgtype = 'error' ) { |
| 570 |
$user = $this->getUser(); |
| 571 |
$out = $this->getOutput(); |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
if ( !$requests ) { |
| 576 |
$this->authAction = $this->getDefaultAction( $this->subPage ); |
| 577 |
$this->authForm = null; |
| 578 |
$requests = MediaWikiServices::getInstance()->getAuthManager() |
| 579 |
->getAuthenticationRequests( $this->authAction, $user ); |
| 580 |
} |
| 581 |
|
| 582 |
|
| 583 |
$out->addModuleStyles( [ |
| 584 |
'mediawiki.special.userlogin.common.styles' |
| 585 |
] ); |
| 586 |
if ( $this->isSignup() ) { |
| 587 |
|
| 588 |
$out->addModules( 'mediawiki.special.createaccount' ); |
| 589 |
$out->addModuleStyles( [ |
| 590 |
'mediawiki.special.userlogin.signup.styles' |
| 591 |
] ); |
| 592 |
} else { |
| 593 |
|
| 594 |
$out->addModuleStyles( [ |
| 595 |
'mediawiki.special.userlogin.login.styles' |
| 596 |
] ); |
| 597 |
} |
| 598 |
$out->disallowUserJs(); |
| 599 |
|
| 600 |
$form = $this->getAuthForm( $requests, $this->authAction ); |
| 601 |
$form->prepareForm(); |
| 602 |
|
| 603 |
$submitStatus = Status::newGood(); |
| 604 |
if ( $msg && $msgtype === 'warning' ) { |
| 605 |
$submitStatus->warning( $msg ); |
| 606 |
} elseif ( $msg && $msgtype === 'error' ) { |
| 607 |
$submitStatus->fatal( $msg ); |
| 608 |
} |
| 609 |
|
| 610 |
|
| 611 |
if ( |
| 612 |
!$this->isSignup() && |
| 613 |
$this->getUser()->isRegistered() && |
| 614 |
!$this->getUser()->isTemp() && |
| 615 |
$this->authAction !== AuthManager::ACTION_LOGIN_CONTINUE |
| 616 |
) { |
| 617 |
$reauthMessage = $this->securityLevel ? 'userlogin-reauth' : 'userlogin-loggedin'; |
| 618 |
$submitStatus->warning( $reauthMessage, $this->getUser()->getName() ); |
| 619 |
} |
| 620 |
|
| 621 |
$formHtml = $form->getHTML( $submitStatus ); |
| 622 |
|
| 623 |
$out->addHTML( $this->getPageHtml( $formHtml ) ); |
| 624 |
} |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
protected function getPageHtml( $formHtml ) { |
| 633 |
$loginPrompt = $this->isSignup() ? '' : Html::rawElement( 'div', |
| 634 |
[ 'id' => 'userloginprompt' ], $this->msg( 'loginprompt' )->parseAsBlock() ); |
| 635 |
$languageLinks = $this->getConfig()->get( MainConfigNames::LoginLanguageSelector ) |
| 636 |
? $this->makeLanguageSelector() : ''; |
| 637 |
$signupStartMsg = $this->msg( 'signupstart' ); |
| 638 |
$signupStart = ( $this->isSignup() && !$signupStartMsg->isDisabled() ) |
| 639 |
? Html::rawElement( 'div', [ 'id' => 'signupstart' ], $signupStartMsg->parseAsBlock() ) : ''; |
| 640 |
if ( $languageLinks ) { |
| 641 |
$languageLinks = Html::rawElement( 'div', [ 'id' => 'languagelinks' ], |
| 642 |
Html::rawElement( 'p', [], $languageLinks ) |
| 643 |
); |
| 644 |
} |
| 645 |
if ( $this->getUser()->isTemp() ) { |
| 646 |
$noticeHtml = $this->getNoticeHtml(); |
| 647 |
} else { |
| 648 |
$noticeHtml = ''; |
| 649 |
} |
| 650 |
$formBlock = Html::rawElement( 'div', [ 'id' => 'userloginForm' ], $formHtml ); |
| 651 |
$formAndBenefits = $formBlock; |
| 652 |
if ( $this->isSignup() && $this->showExtraInformation() ) { |
| 653 |
$benefitsContainerHtml = null; |
| 654 |
$info = [ |
| 655 |
'context' => $this->getContext(), |
| 656 |
'form' => $this->authForm, |
| 657 |
]; |
| 658 |
$options = [ |
| 659 |
'beforeForm' => false, |
| 660 |
]; |
| 661 |
$this->getHookRunner()->onSpecialCreateAccountBenefits( |
| 662 |
$benefitsContainerHtml, $info, $options |
| 663 |
); |
| 664 |
$benefitsContainerHtml ??= $this->getBenefitsContainerHtml(); |
| 665 |
$formAndBenefits = $options['beforeForm'] |
| 666 |
? ( $benefitsContainerHtml . $formBlock ) |
| 667 |
: ( $formBlock . $benefitsContainerHtml ); |
| 668 |
} |
| 669 |
|
| 670 |
return $loginPrompt |
| 671 |
. $languageLinks |
| 672 |
. $signupStart |
| 673 |
. $noticeHtml |
| 674 |
. Html::rawElement( 'div', [ 'class' => 'mw-ui-container' ], |
| 675 |
$formAndBenefits |
| 676 |
); |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
protected function getBenefitsContainerHtml(): string { |
| 687 |
$benefitsContainer = ''; |
| 688 |
$this->getOutput()->addModuleStyles( [ 'oojs-ui.styles.icons-user' ] ); |
| 689 |
if ( $this->isSignup() && $this->showExtraInformation() ) { |
| 690 |
if ( !$this->getUser()->isTemp() ) { |
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
$benefitCount = 3; |
| 696 |
$benefitList = ''; |
| 697 |
for ( $benefitIdx = 1; $benefitIdx <= $benefitCount; $benefitIdx++ ) { |
| 698 |
$headUnescaped = $this->msg( "createacct-benefit-head$benefitIdx" )->text(); |
| 699 |
$iconClass = $this->msg( "createacct-benefit-icon$benefitIdx" )->text(); |
| 700 |
$benefitList .= Html::rawElement( 'div', [ 'class' => "mw-number-text $iconClass" ], |
| 701 |
Html::rawElement( 'span', [], |
| 702 |
$this->msg( "createacct-benefit-head$benefitIdx" )->escaped() |
| 703 |
) |
| 704 |
. Html::rawElement( 'p', [], |
| 705 |
$this->msg( "createacct-benefit-body$benefitIdx" )->params( $headUnescaped )->escaped() |
| 706 |
) |
| 707 |
); |
| 708 |
} |
| 709 |
$benefitsContainer = Html::rawElement( 'div', [ 'class' => 'mw-createacct-benefits-container' ], |
| 710 |
Html::rawElement( 'div', [ 'class' => 'mw-createacct-benefits-heading' ], |
| 711 |
$this->msg( 'createacct-benefit-heading' )->escaped() |
| 712 |
) |
| 713 |
. Html::rawElement( 'div', [ 'class' => 'mw-createacct-benefits-list' ], $benefitList ) |
| 714 |
); |
| 715 |
} else { |
| 716 |
$benefitList = ''; |
| 717 |
$this->getOutput()->addModuleStyles( |
| 718 |
[ |
| 719 |
'oojs-ui.styles.icons-moderation', |
| 720 |
'oojs-ui.styles.icons-interactions', |
| 721 |
] |
| 722 |
); |
| 723 |
$benefits = [ |
| 724 |
[ |
| 725 |
'icon' => 'oo-ui-icon-unStar', |
| 726 |
'description' => $this->msg( "benefit-1-description" )->escaped() |
| 727 |
], |
| 728 |
[ |
| 729 |
'icon' => 'oo-ui-icon-userContributions', |
| 730 |
'description' => $this->msg( "benefit-2-description" )->escaped() |
| 731 |
], |
| 732 |
[ |
| 733 |
'icon' => 'oo-ui-icon-settings', |
| 734 |
'description' => $this->msg( "benefit-3-description" )->escaped() |
| 735 |
] |
| 736 |
]; |
| 737 |
foreach ( $benefits as $benefit ) { |
| 738 |
$benefitContent = Html::rawElement( 'div', [ 'class' => 'mw-benefit-item' ], |
| 739 |
Html::rawElement( 'span', [ 'class' => $benefit[ 'icon' ] ] ) |
| 740 |
. Html::rawElement( 'p', [], $benefit['description'] ) |
| 741 |
); |
| 742 |
|
| 743 |
$benefitList .= Html::rawElement( |
| 744 |
'div', [ 'class' => 'mw-benefit-item-wrapper' ], $benefitContent ); |
| 745 |
} |
| 746 |
|
| 747 |
$benefitsListWrapper = Html::rawElement( |
| 748 |
'div', [ 'class' => 'mw-benefit-list-wrapper' ], $benefitList ); |
| 749 |
|
| 750 |
$headingSubheadingWrapper = Html::rawElement( 'div', [ 'class' => 'mw-heading-subheading-wrapper' ], |
| 751 |
Html::rawElement( 'h2', [], $this->msg( 'createacct-benefit-heading-temp-user' )->escaped() ) |
| 752 |
. Html::rawElement( 'p', [ 'class' => 'mw-benefit-subheading' ], $this->msg( |
| 753 |
'createacct-benefit-subheading-temp-user' )->escaped() ) |
| 754 |
); |
| 755 |
|
| 756 |
$benefitsContainer = Html::rawElement( |
| 757 |
'div', [ 'class' => 'mw-createacct-benefits-container' ], |
| 758 |
$headingSubheadingWrapper |
| 759 |
. $benefitsListWrapper |
| 760 |
); |
| 761 |
} |
| 762 |
} |
| 763 |
return $benefitsContainer; |
| 764 |
} |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
protected function getAuthForm( array $requests, $action ) { |
| 773 |
|
| 774 |
|
| 775 |
if ( isset( $this->authForm ) ) { |
| 776 |
return $this->authForm; |
| 777 |
} |
| 778 |
|
| 779 |
$usingHTTPS = $this->getRequest()->getProtocol() === 'https'; |
| 780 |
|
| 781 |
|
| 782 |
$fieldInfo = AuthenticationRequest::mergeFieldInfo( $requests ); |
| 783 |
|
| 784 |
$formDescriptor = $this->fieldInfoToFormDescriptor( $requests, $fieldInfo, $this->authAction ); |
| 785 |
$this->postProcessFormDescriptor( $formDescriptor, $requests ); |
| 786 |
|
| 787 |
$context = $this->getContext(); |
| 788 |
if ( $context->getRequest() !== $this->getRequest() ) { |
| 789 |
|
| 790 |
$context = new DerivativeContext( $this->getContext() ); |
| 791 |
$context->setRequest( $this->getRequest() ); |
| 792 |
} |
| 793 |
$form = HTMLForm::factory( 'codex', $formDescriptor, $context ); |
| 794 |
|
| 795 |
$form->addHiddenField( 'authAction', $this->authAction ); |
| 796 |
$form->addHiddenField( 'force', $this->securityLevel ); |
| 797 |
$form->addHiddenField( $this->getTokenName(), $this->getToken()->toString() ); |
| 798 |
$config = $this->getConfig(); |
| 799 |
if ( $config->get( MainConfigNames::SecureLogin ) && |
| 800 |
!$config->get( MainConfigNames::ForceHTTPS ) ) { |
| 801 |
|
| 802 |
if ( !$this->isSignup() ) { |
| 803 |
$form->addHiddenField( 'wpForceHttps', (int)$this->mStickHTTPS ); |
| 804 |
$form->addHiddenField( 'wpFromhttp', $usingHTTPS ); |
| 805 |
} |
| 806 |
} |
| 807 |
|
| 808 |
$form->setAction( $this->getPageTitle()->getLocalURL( $this->getPreservedParams( |
| 809 |
|
| 810 |
[ 'reset' => true ] |
| 811 |
) ) ); |
| 812 |
$form->setName( 'userlogin' . ( $this->isSignup() ? '2' : '' ) ); |
| 813 |
if ( $this->isSignup() ) { |
| 814 |
$form->setId( 'userlogin2' ); |
| 815 |
} |
| 816 |
|
| 817 |
$form->suppressDefaultSubmit(); |
| 818 |
|
| 819 |
$this->authForm = $form; |
| 820 |
|
| 821 |
return $form; |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
public function onAuthChangeFormFields( |
| 826 |
array $requests, array $fieldInfo, array &$formDescriptor, $action |
| 827 |
) { |
| 828 |
$formDescriptor = self::mergeDefaultFormDescriptor( $fieldInfo, $formDescriptor, |
| 829 |
$this->getFieldDefinitions( $fieldInfo, $requests ) ); |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
protected function showExtraInformation() { |
| 839 |
return $this->authAction !== $this->getContinueAction( $this->authAction ) |
| 840 |
&& !$this->securityLevel; |
| 841 |
} |
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
protected function getFieldDefinitions( array $fieldInfo, array $requests ) { |
| 852 |
$isLoggedIn = $this->getUser()->isRegistered(); |
| 853 |
$continuePart = $this->isContinued() ? 'continue-' : ''; |
| 854 |
$anotherPart = $isLoggedIn ? 'another-' : ''; |
| 855 |
|
| 856 |
$expiration = $this->getRequest()->getSession()->getProvider()->getRememberUserDuration(); |
| 857 |
$expirationDays = ceil( $expiration / ( 3600 * 24 ) ); |
| 858 |
$secureLoginLink = ''; |
| 859 |
if ( $this->mSecureLoginUrl ) { |
| 860 |
$secureLoginLink = Html::rawElement( 'a', [ |
| 861 |
'href' => $this->mSecureLoginUrl, |
| 862 |
'class' => 'mw-login-flush-right mw-secure', |
| 863 |
], Html::element( 'span', [ 'class' => 'mw-secure--icon' ] ) . |
| 864 |
$this->msg( 'userlogin-signwithsecure' )->parse() ); |
| 865 |
} |
| 866 |
$usernameHelpLink = ''; |
| 867 |
if ( !$this->msg( 'createacct-helpusername' )->isDisabled() ) { |
| 868 |
$usernameHelpLink = Html::rawElement( 'span', [ |
| 869 |
'class' => 'mw-login-flush-right', |
| 870 |
], $this->msg( 'createacct-helpusername' )->parse() ); |
| 871 |
} |
| 872 |
|
| 873 |
if ( $this->isSignup() ) { |
| 874 |
$config = $this->getConfig(); |
| 875 |
$hideIf = isset( $fieldInfo['mailpassword'] ) ? [ 'hide-if' => [ '===', 'mailpassword', '1' ] ] : []; |
| 876 |
$fieldDefinitions = [ |
| 877 |
'username' => [ |
| 878 |
'label-raw' => $this->msg( 'userlogin-yourname' )->escaped() . $usernameHelpLink, |
| 879 |
'id' => 'wpName2', |
| 880 |
'placeholder-message' => $isLoggedIn ? 'createacct-another-username-ph' |
| 881 |
: 'userlogin-yourname-ph', |
| 882 |
], |
| 883 |
'mailpassword' => [ |
| 884 |
|
| 885 |
'type' => 'check', |
| 886 |
'label-message' => 'createaccountmail', |
| 887 |
'name' => 'wpCreateaccountMail', |
| 888 |
'id' => 'wpCreateaccountMail', |
| 889 |
], |
| 890 |
'password' => [ |
| 891 |
'id' => 'wpPassword2', |
| 892 |
'autocomplete' => 'new-password', |
| 893 |
'placeholder-message' => 'createacct-yourpassword-ph', |
| 894 |
'help-message' => 'createacct-useuniquepass', |
| 895 |
] + $hideIf, |
| 896 |
'domain' => [], |
| 897 |
'retype' => [ |
| 898 |
'type' => 'password', |
| 899 |
'label-message' => 'createacct-yourpasswordagain', |
| 900 |
'id' => 'wpRetype', |
| 901 |
'cssclass' => 'loginPassword', |
| 902 |
'size' => 20, |
| 903 |
'autocomplete' => 'new-password', |
| 904 |
'validation-callback' => function ( $value, $alldata ) { |
| 905 |
if ( empty( $alldata['mailpassword'] ) && !empty( $alldata['password'] ) ) { |
| 906 |
if ( !$value ) { |
| 907 |
return $this->msg( 'htmlform-required' ); |
| 908 |
} elseif ( $value !== $alldata['password'] ) { |
| 909 |
return $this->msg( 'badretype' ); |
| 910 |
} |
| 911 |
} |
| 912 |
return true; |
| 913 |
}, |
| 914 |
'placeholder-message' => 'createacct-yourpasswordagain-ph', |
| 915 |
] + $hideIf, |
| 916 |
'email' => [ |
| 917 |
'type' => 'email', |
| 918 |
'label-message' => $config->get( MainConfigNames::EmailConfirmToEdit ) |
| 919 |
? 'createacct-emailrequired' : 'createacct-emailoptional', |
| 920 |
'id' => 'wpEmail', |
| 921 |
'cssclass' => 'loginText', |
| 922 |
'size' => '20', |
| 923 |
'maxlength' => 255, |
| 924 |
'autocomplete' => 'email', |
| 925 |
|
| 926 |
'required' => $config->get( MainConfigNames::EmailConfirmToEdit ), |
| 927 |
'validation-callback' => function ( $value, $alldata ) { |
| 928 |
|
| 929 |
|
| 930 |
if ( !$value && |
| 931 |
$this->getConfig()->get( MainConfigNames::EmailConfirmToEdit ) |
| 932 |
) { |
| 933 |
|
| 934 |
|
| 935 |
return $this->msg( 'noemailtitle' ); |
| 936 |
} elseif ( !$value && !empty( $alldata['mailpassword'] ) ) { |
| 937 |
|
| 938 |
return $this->msg( 'noemailcreate' ); |
| 939 |
} elseif ( $value && !Sanitizer::validateEmail( $value ) ) { |
| 940 |
return $this->msg( 'invalidemailaddress' ); |
| 941 |
} elseif ( is_string( $value ) && strlen( $value ) > 255 ) { |
| 942 |
return $this->msg( 'changeemail-maxlength' ); |
| 943 |
} |
| 944 |
return true; |
| 945 |
}, |
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
'placeholder-message' => 'createacct-' . $anotherPart . 'email-ph', |
| 950 |
], |
| 951 |
'realname' => [ |
| 952 |
'type' => 'text', |
| 953 |
'help-message' => $isLoggedIn ? 'createacct-another-realname-tip' |
| 954 |
: 'prefs-help-realname', |
| 955 |
'label-message' => 'createacct-realname', |
| 956 |
'cssclass' => 'loginText', |
| 957 |
'size' => 20, |
| 958 |
'placeholder-message' => 'createacct-realname', |
| 959 |
'id' => 'wpRealName', |
| 960 |
'autocomplete' => 'name', |
| 961 |
], |
| 962 |
'reason' => [ |
| 963 |
|
| 964 |
'type' => 'text', |
| 965 |
'label-message' => 'createacct-reason', |
| 966 |
'cssclass' => 'loginText', |
| 967 |
'id' => 'wpReason', |
| 968 |
'size' => '20', |
| 969 |
'validation-callback' => function ( $value, $alldata ) { |
| 970 |
|
| 971 |
|
| 972 |
if ( $value && Sanitizer::validateEmail( $value ) ) { |
| 973 |
if ( $this->reasonValidatorResult !== null ) { |
| 974 |
return $this->reasonValidatorResult; |
| 975 |
} |
| 976 |
$this->reasonValidatorResult = true; |
| 977 |
$authManager = MediaWikiServices::getInstance()->getAuthManager(); |
| 978 |
if ( !$authManager->getAuthenticationSessionData( 'reason-retry', false ) ) { |
| 979 |
$authManager->setAuthenticationSessionData( 'reason-retry', true ); |
| 980 |
$this->reasonValidatorResult = $this->msg( 'createacct-reason-confirm' ); |
| 981 |
} |
| 982 |
return $this->reasonValidatorResult; |
| 983 |
} |
| 984 |
return true; |
| 985 |
}, |
| 986 |
'placeholder-message' => 'createacct-reason-ph', |
| 987 |
], |
| 988 |
'createaccount' => [ |
| 989 |
|
| 990 |
'type' => 'submit', |
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
'default' => $this->msg( 'createacct-' . $anotherPart . $continuePart . |
| 997 |
'submit' )->text(), |
| 998 |
'name' => 'wpCreateaccount', |
| 999 |
'id' => 'wpCreateaccount', |
| 1000 |
'weight' => 100, |
| 1001 |
], |
| 1002 |
]; |
| 1003 |
if ( !$this->msg( 'createacct-username-help' )->isDisabled() ) { |
| 1004 |
$fieldDefinitions['username']['help-message'] = 'createacct-username-help'; |
| 1005 |
} |
| 1006 |
} else { |
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
$passwordRequest = AuthenticationRequest::getRequestByClass( $this->authRequests, |
| 1011 |
PasswordAuthenticationRequest::class ); |
| 1012 |
$changePassword = $passwordRequest && $passwordRequest->action == AuthManager::ACTION_CHANGE; |
| 1013 |
$fieldDefinitions = [ |
| 1014 |
'username' => ( |
| 1015 |
[ |
| 1016 |
'label-raw' => $this->msg( 'userlogin-yourname' )->escaped() . $secureLoginLink, |
| 1017 |
'id' => 'wpName1', |
| 1018 |
'placeholder-message' => 'userlogin-yourname-ph', |
| 1019 |
] + ( $changePassword ? [ |
| 1020 |
|
| 1021 |
|
| 1022 |
'baseField' => 'password', |
| 1023 |
'nodata' => true, |
| 1024 |
'readonly' => true, |
| 1025 |
'cssclass' => 'mw-htmlform-hidden-field', |
| 1026 |
] : [] ) |
| 1027 |
), |
| 1028 |
'password' => ( |
| 1029 |
$changePassword ? [ |
| 1030 |
'autocomplete' => 'new-password', |
| 1031 |
'placeholder-message' => 'createacct-yourpassword-ph', |
| 1032 |
'help-message' => 'createacct-useuniquepass', |
| 1033 |
] : [ |
| 1034 |
'id' => 'wpPassword1', |
| 1035 |
'autocomplete' => 'current-password', |
| 1036 |
'placeholder-message' => 'userlogin-yourpassword-ph', |
| 1037 |
] |
| 1038 |
), |
| 1039 |
'retype' => [ |
| 1040 |
'type' => 'password', |
| 1041 |
'autocomplete' => 'new-password', |
| 1042 |
'placeholder-message' => 'createacct-yourpasswordagain-ph', |
| 1043 |
], |
| 1044 |
'domain' => [], |
| 1045 |
'rememberMe' => [ |
| 1046 |
|
| 1047 |
'type' => 'check', |
| 1048 |
'cssclass' => 'mw-userlogin-rememberme', |
| 1049 |
'name' => 'wpRemember', |
| 1050 |
'label-message' => $this->msg( 'userlogin-remembermypassword' ) |
| 1051 |
->numParams( $expirationDays ), |
| 1052 |
'id' => 'wpRemember', |
| 1053 |
], |
| 1054 |
'loginattempt' => [ |
| 1055 |
|
| 1056 |
'type' => 'submit', |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
'default' => $this->msg( 'pt-login-' . $continuePart . 'button' )->text(), |
| 1061 |
'id' => 'wpLoginAttempt', |
| 1062 |
'weight' => 100, |
| 1063 |
], |
| 1064 |
'linkcontainer' => [ |
| 1065 |
|
| 1066 |
'type' => 'info', |
| 1067 |
'cssclass' => 'mw-form-related-link-container mw-userlogin-help', |
| 1068 |
|
| 1069 |
'raw' => true, |
| 1070 |
'default' => Html::element( 'a', [ |
| 1071 |
'href' => Skin::makeInternalOrExternalUrl( $this->msg( 'helplogin-url' ) |
| 1072 |
->inContentLanguage() |
| 1073 |
->text() ), |
| 1074 |
], $this->msg( 'userlogin-helplink2' )->text() ), |
| 1075 |
'weight' => 200, |
| 1076 |
], |
| 1077 |
|
| 1078 |
'skipReset' => [ |
| 1079 |
'weight' => 110, |
| 1080 |
'flags' => [], |
| 1081 |
], |
| 1082 |
]; |
| 1083 |
} |
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
$isUsernameOrPasswordRequest = |
| 1089 |
AuthenticationRequest::getRequestByClass( $requests, UsernameAuthenticationRequest::class ) || |
| 1090 |
AuthenticationRequest::getRequestByClass( $requests, PasswordAuthenticationRequest::class ); |
| 1091 |
|
| 1092 |
if ( $isUsernameOrPasswordRequest ) { |
| 1093 |
$fieldDefinitions['username'] += [ |
| 1094 |
'type' => 'text', |
| 1095 |
'name' => 'wpName', |
| 1096 |
'cssclass' => 'loginText mw-userlogin-username', |
| 1097 |
'size' => 20, |
| 1098 |
'autocomplete' => 'username', |
| 1099 |
|
| 1100 |
]; |
| 1101 |
$fieldDefinitions['password'] += [ |
| 1102 |
'type' => 'password', |
| 1103 |
|
| 1104 |
'name' => 'wpPassword', |
| 1105 |
'cssclass' => 'loginPassword mw-userlogin-password', |
| 1106 |
'size' => 20, |
| 1107 |
|
| 1108 |
]; |
| 1109 |
} |
| 1110 |
|
| 1111 |
if ( $this->mEntryError ) { |
| 1112 |
$defaultHtml = ''; |
| 1113 |
if ( $this->mEntryErrorType === 'error' ) { |
| 1114 |
$defaultHtml = Html::errorBox( $this->mEntryError ); |
| 1115 |
} elseif ( $this->mEntryErrorType === 'warning' ) { |
| 1116 |
$defaultHtml = Html::warningBox( $this->mEntryError ); |
| 1117 |
} elseif ( $this->mEntryErrorType === 'notice' ) { |
| 1118 |
$defaultHtml = Html::noticeBox( $this->mEntryError, '' ); |
| 1119 |
} |
| 1120 |
$fieldDefinitions['entryError'] = [ |
| 1121 |
'type' => 'info', |
| 1122 |
'default' => $defaultHtml, |
| 1123 |
'raw' => true, |
| 1124 |
'rawrow' => true, |
| 1125 |
'weight' => -100, |
| 1126 |
]; |
| 1127 |
} |
| 1128 |
if ( !$this->showExtraInformation() ) { |
| 1129 |
unset( $fieldDefinitions['linkcontainer'], $fieldDefinitions['signupend'] ); |
| 1130 |
} |
| 1131 |
if ( $this->isSignup() && $this->showExtraInformation() ) { |
| 1132 |
|
| 1133 |
|
| 1134 |
$signupendMsg = $this->msg( 'signupend' ); |
| 1135 |
$signupendHttpsMsg = $this->msg( 'signupend-https' ); |
| 1136 |
if ( !$signupendMsg->isDisabled() ) { |
| 1137 |
$usingHTTPS = $this->getRequest()->getProtocol() === 'https'; |
| 1138 |
$signupendText = ( $usingHTTPS && !$signupendHttpsMsg->isBlank() ) |
| 1139 |
? $signupendHttpsMsg->parse() : $signupendMsg->parse(); |
| 1140 |
$fieldDefinitions['signupend'] = [ |
| 1141 |
'type' => 'info', |
| 1142 |
'raw' => true, |
| 1143 |
'default' => Html::rawElement( 'div', [ 'id' => 'signupend' ], $signupendText ), |
| 1144 |
'weight' => 225, |
| 1145 |
]; |
| 1146 |
} |
| 1147 |
} |
| 1148 |
if ( !$this->isSignup() && $this->showExtraInformation() ) { |
| 1149 |
$passwordReset = MediaWikiServices::getInstance()->getPasswordReset(); |
| 1150 |
if ( $passwordReset->isAllowed( $this->getUser() )->isGood() ) { |
| 1151 |
$fieldDefinitions['passwordReset'] = [ |
| 1152 |
'type' => 'info', |
| 1153 |
'raw' => true, |
| 1154 |
'cssclass' => 'mw-form-related-link-container', |
| 1155 |
'default' => $this->getLinkRenderer()->makeLink( |
| 1156 |
SpecialPage::getTitleFor( 'PasswordReset' ), |
| 1157 |
$this->msg( 'userlogin-resetpassword-link' )->text() |
| 1158 |
), |
| 1159 |
'weight' => 230, |
| 1160 |
]; |
| 1161 |
} |
| 1162 |
|
| 1163 |
|
| 1164 |
if ( $this->showCreateAccountLink() ) { |
| 1165 |
|
| 1166 |
$linkTitle = $this->getTitleFor( $this->isSignup() ? 'Userlogin' : 'CreateAccount' ); |
| 1167 |
$linkq = wfArrayToCgi( $this->getPreservedParams( [ 'reset' => true ] ) ); |
| 1168 |
$isLoggedIn = $this->getUser()->isRegistered() |
| 1169 |
&& !$this->getUser()->isTemp(); |
| 1170 |
|
| 1171 |
$fieldDefinitions['createOrLogin'] = [ |
| 1172 |
'type' => 'info', |
| 1173 |
'raw' => true, |
| 1174 |
'linkQuery' => $linkq, |
| 1175 |
'default' => function ( $params ) use ( $isLoggedIn, $linkTitle ) { |
| 1176 |
$buttonClasses = 'cdx-button cdx-button--action-progressive ' |
| 1177 |
. 'cdx-button--fake-button cdx-button--fake-button--enabled'; |
| 1178 |
|
| 1179 |
return Html::rawElement( 'div', |
| 1180 |
|
| 1181 |
|
| 1182 |
[ 'id' => 'mw-createaccount' . ( !$isLoggedIn ? '-cta' : '' ), |
| 1183 |
'class' => ( $isLoggedIn ? 'mw-form-related-link-container' : 'mw-ui-vform-field' ) ], |
| 1184 |
( $isLoggedIn ? '' : $this->msg( 'userlogin-noaccount' )->escaped() ) |
| 1185 |
. Html::element( 'a', |
| 1186 |
[ |
| 1187 |
|
| 1188 |
|
| 1189 |
'id' => 'mw-createaccount-join' . ( $isLoggedIn ? '-loggedin' : '' ), |
| 1190 |
'href' => $linkTitle->getLocalURL( $params['linkQuery'] ), |
| 1191 |
'class' => [ 'mw-authentication-popup-link', $buttonClasses => !$isLoggedIn ], |
| 1192 |
'target' => '_self', |
| 1193 |
'tabindex' => 100, |
| 1194 |
], |
| 1195 |
$this->msg( |
| 1196 |
$isLoggedIn ? 'userlogin-createanother' : 'userlogin-joinproject' |
| 1197 |
)->text() |
| 1198 |
) |
| 1199 |
); |
| 1200 |
}, |
| 1201 |
'weight' => 235, |
| 1202 |
]; |
| 1203 |
} |
| 1204 |
} |
| 1205 |
|
| 1206 |
return $fieldDefinitions; |
| 1207 |
} |
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
protected function hasSessionCookie() { |
| 1219 |
global $wgInitialSessionId; |
| 1220 |
|
| 1221 |
return $wgInitialSessionId && |
| 1222 |
$this->getRequest()->getSession()->getId() === (string)$wgInitialSessionId; |
| 1223 |
} |
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
private function showCreateAccountLink() { |
| 1231 |
return $this->isSignup() || |
| 1232 |
$this->getContext()->getAuthority()->isAllowed( 'createaccount' ); |
| 1233 |
} |
| 1234 |
|
| 1235 |
protected function getTokenName() { |
| 1236 |
return $this->isSignup() ? 'wpCreateaccountToken' : 'wpLoginToken'; |
| 1237 |
} |
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
protected function makeLanguageSelector() { |
| 1246 |
$msg = $this->msg( 'loginlanguagelinks' )->inContentLanguage(); |
| 1247 |
if ( $msg->isBlank() ) { |
| 1248 |
return ''; |
| 1249 |
} |
| 1250 |
$langs = explode( "\n", $msg->text() ); |
| 1251 |
$links = []; |
| 1252 |
foreach ( $langs as $lang ) { |
| 1253 |
$lang = trim( $lang, '* ' ); |
| 1254 |
$parts = explode( '|', $lang ); |
| 1255 |
if ( count( $parts ) >= 2 ) { |
| 1256 |
$links[] = $this->makeLanguageSelectorLink( $parts[0], trim( $parts[1] ) ); |
| 1257 |
} |
| 1258 |
} |
| 1259 |
|
| 1260 |
return count( $links ) > 0 ? $this->msg( 'loginlanguagelabel' )->rawParams( |
| 1261 |
$this->getLanguage()->pipeList( $links ) )->escaped() : ''; |
| 1262 |
} |
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
protected function makeLanguageSelectorLink( $text, $lang ) { |
| 1273 |
$services = MediaWikiServices::getInstance(); |
| 1274 |
|
| 1275 |
if ( $this->getLanguage()->getCode() == $lang |
| 1276 |
|| !$services->getLanguageNameUtils()->isValidCode( $lang ) |
| 1277 |
) { |
| 1278 |
|
| 1279 |
|
| 1280 |
return htmlspecialchars( $text ); |
| 1281 |
} |
| 1282 |
|
| 1283 |
$query = $this->getPreservedParams(); |
| 1284 |
$query['uselang'] = $lang; |
| 1285 |
|
| 1286 |
$attr = []; |
| 1287 |
$targetLanguage = $services->getLanguageFactory()->getLanguage( $lang ); |
| 1288 |
$attr['lang'] = $attr['hreflang'] = $targetLanguage->getHtmlCode(); |
| 1289 |
$attr['class'] = 'mw-authentication-popup-link'; |
| 1290 |
|
| 1291 |
return $this->getLinkRenderer()->makeKnownLink( |
| 1292 |
$this->getPageTitle(), |
| 1293 |
$text, |
| 1294 |
$attr, |
| 1295 |
$query |
| 1296 |
); |
| 1297 |
} |
| 1298 |
|
| 1299 |
protected function getGroupName() { |
| 1300 |
return 'login'; |
| 1301 |
} |
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
protected function postProcessFormDescriptor( &$formDescriptor, $requests ) { |
| 1308 |
|
| 1309 |
if ( |
| 1310 |
isset( $formDescriptor['username'] ) && |
| 1311 |
!isset( $formDescriptor['username']['default'] ) && |
| 1312 |
!$this->isSignup() |
| 1313 |
) { |
| 1314 |
$user = $this->getUser(); |
| 1315 |
if ( $user->isRegistered() && !$user->isTemp() ) { |
| 1316 |
$formDescriptor['username']['default'] = $user->getName(); |
| 1317 |
} else { |
| 1318 |
$formDescriptor['username']['default'] = |
| 1319 |
$this->getRequest()->getSession()->suggestLoginUsername(); |
| 1320 |
} |
| 1321 |
} |
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
if ( !$this->needsSubmitButton( $requests ) ) { |
| 1326 |
unset( $formDescriptor['createaccount'], $formDescriptor['loginattempt'] ); |
| 1327 |
} |
| 1328 |
|
| 1329 |
if ( !$this->isSignup() ) { |
| 1330 |
|
| 1331 |
|
| 1332 |
if ( |
| 1333 |
isset( $formDescriptor['username'] ) |
| 1334 |
&& empty( $formDescriptor['username']['default'] ) |
| 1335 |
&& !$this->getRequest()->getCheck( 'wpName' ) |
| 1336 |
) { |
| 1337 |
$formDescriptor['username']['autofocus'] = true; |
| 1338 |
} elseif ( isset( $formDescriptor['password'] ) ) { |
| 1339 |
$formDescriptor['password']['autofocus'] = true; |
| 1340 |
} |
| 1341 |
} |
| 1342 |
|
| 1343 |
$this->addTabIndex( $formDescriptor ); |
| 1344 |
} |
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
protected function getNoticeHtml() { |
| 1352 |
$noticeContent = $this->msg( 'createacct-temp-warning', $this->getUser()->getName() )->parse(); |
| 1353 |
return Html::noticeBox( |
| 1354 |
$noticeContent, |
| 1355 |
'mw-createaccount-temp-warning', |
| 1356 |
'', |
| 1357 |
'mw-userLogin-icon--user-temporary' |
| 1358 |
); |
| 1359 |
} |
| 1360 |
|
| 1361 |
} |
| 1362 |
|
| 1363 |
|
| 1364 |
class_alias( LoginSignupSpecialPage::class, 'LoginSignupSpecialPage' ); |