MediaWiki master
ApiCreateTempUserTrait.php
Go to the documentation of this file.
1<?php
2
7
24 protected function getTempUserRedirectUrl(
25 array $params,
26 UserIdentity $savedTempUser
27 ): string {
28 $returnToQuery = $params['returntoquery'];
29 $returnToAnchor = $params['returntoanchor'];
30 if ( str_starts_with( $returnToQuery, '?' ) ) {
31 // Remove leading '?' if provided (both ways work, but this is more common elsewhere)
32 $returnToQuery = substr( $returnToQuery, 1 );
33 }
34 if ( $returnToAnchor !== '' && !str_starts_with( $returnToAnchor, '#' ) ) {
35 // Add leading '#' if missing (it's required)
36 $returnToAnchor = '#' . $returnToAnchor;
37 }
38 $redirectUrl = '';
39 $this->getHookRunner()->onTempUserCreatedRedirect(
40 $this->getRequest()->getSession(),
41 $savedTempUser,
42 $params['returnto'] ?: '',
43 $returnToQuery,
44 $returnToAnchor,
45 $redirectUrl
46 );
47 return $redirectUrl;
48 }
49
55 protected function getCreateTempUserParams(): array {
56 return [
57 'returnto' => [
58 ParamValidator::PARAM_TYPE => 'title',
59 ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-returnto',
60 ],
61 'returntoquery' => [
62 ParamValidator::PARAM_TYPE => 'string',
63 ParamValidator::PARAM_DEFAULT => '',
64 ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-returntoquery',
65 ],
66 'returntoanchor' => [
67 ParamValidator::PARAM_TYPE => 'string',
68 ParamValidator::PARAM_DEFAULT => '',
69 ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-returntoanchor',
70 ],
71 ];
72 }
73
74 // region Methods required from ApiBase
83 abstract protected function getHookRunner();
84
89 abstract public function getRequest();
90
92 // endregion -- end of methods required from ApiBase
93}
getRequest()
array $params
The job parameters.
This class provides an implementation of the hook interfaces used by the core Action API,...
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form,...
Service for formatting and validating API parameters.
trait ApiCreateTempUserTrait
Methods needed by APIs that create a temporary user.
Interface for objects representing user identity.