| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Api; |
| 4 |
|
| 5 |
use MediaWiki\Request\WebRequest; |
| 6 |
use MediaWiki\User\UserIdentity; |
| 7 |
use Wikimedia\ParamValidator\ParamValidator; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
trait ApiCreateTempUserTrait { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
protected function getTempUserRedirectUrl( |
| 26 |
array $params, |
| 27 |
UserIdentity $savedTempUser |
| 28 |
): string { |
| 29 |
$returnToQuery = $params['returntoquery']; |
| 30 |
$returnToAnchor = $params['returntoanchor']; |
| 31 |
if ( str_starts_with( $returnToQuery, '?' ) ) { |
| 32 |
|
| 33 |
$returnToQuery = substr( $returnToQuery, 1 ); |
| 34 |
} |
| 35 |
if ( $returnToAnchor !== '' && !str_starts_with( $returnToAnchor, '#' ) ) { |
| 36 |
|
| 37 |
$returnToAnchor = '#' . $returnToAnchor; |
| 38 |
} |
| 39 |
$redirectUrl = ''; |
| 40 |
$this->getHookRunner()->onTempUserCreatedRedirect( |
| 41 |
$this->getRequest()->getSession(), |
| 42 |
$savedTempUser, |
| 43 |
$params['returnto'] ?: '', |
| 44 |
$returnToQuery, |
| 45 |
$returnToAnchor, |
| 46 |
$redirectUrl |
| 47 |
); |
| 48 |
return $redirectUrl; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
protected function getCreateTempUserParams(): array { |
| 57 |
return [ |
| 58 |
'returnto' => [ |
| 59 |
ParamValidator::PARAM_TYPE => 'title', |
| 60 |
ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-returnto', |
| 61 |
], |
| 62 |
'returntoquery' => [ |
| 63 |
ParamValidator::PARAM_TYPE => 'string', |
| 64 |
ParamValidator::PARAM_DEFAULT => '', |
| 65 |
ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-returntoquery', |
| 66 |
], |
| 67 |
'returntoanchor' => [ |
| 68 |
ParamValidator::PARAM_TYPE => 'string', |
| 69 |
ParamValidator::PARAM_DEFAULT => '', |
| 70 |
ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-returntoanchor', |
| 71 |
], |
| 72 |
]; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
abstract protected function getHookRunner(); |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
abstract public function getRequest(); |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
class_alias( ApiCreateTempUserTrait::class, 'ApiCreateTempUserTrait' ); |