MediaWiki
master
ApiAcquireTempUserName.php
Go to the documentation of this file.
1
<?php
2
22
use
MediaWiki\User\TempUser\TempUserCreator
;
23
35
class
ApiAcquireTempUserName
extends
ApiBase
{
36
37
private
TempUserCreator
$tempUserCreator;
38
39
public
function
__construct
(
40
ApiMain
$main,
41
string
$action,
42
TempUserCreator
$tempUserCreator
43
) {
44
parent::__construct( $main, $action );
45
$this->tempUserCreator = $tempUserCreator;
46
}
47
48
public
function
execute
() {
49
// Like TempUserCreator::shouldAutoCreate(), but without the action check
50
if
( !$this->tempUserCreator->isEnabled() ) {
51
$this->
dieWithError
(
'apierror-tempuserdisabled'
,
'tempuserdisabled'
);
52
}
53
if
( $this->
getUser
()->isRegistered() ) {
54
$this->
dieWithError
(
'apierror-alreadyregistered'
,
'alreadyregistered'
);
55
}
56
$this->
checkUserRightsAny
(
'createaccount'
);
57
58
// Checks passed, acquire the name
59
$session = $this->
getRequest
()->getSession();
60
$name = $this->tempUserCreator->acquireAndStashName( $session );
61
if
( $name ===
null
) {
62
$this->
dieWithError
(
'apierror-tempuseracquirefailed'
,
'tempuseracquirefailed'
);
63
}
64
65
$session->persist();
66
$this->
getResult
()->addValue(
null
, $this->
getModuleName
(), $name );
67
}
68
69
public
function
isWriteMode
() {
70
return
true
;
71
}
72
73
public
function
mustBePosted
() {
74
return
true
;
75
}
76
}
ApiAcquireTempUserName
Acquire a temporary user username and stash it in the current session, if temp account creation is en...
Definition
ApiAcquireTempUserName.php:35
ApiAcquireTempUserName\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition
ApiAcquireTempUserName.php:48
ApiAcquireTempUserName\mustBePosted
mustBePosted()
Indicates whether this module must be called with a POST request.
Definition
ApiAcquireTempUserName.php:73
ApiAcquireTempUserName\__construct
__construct(ApiMain $main, string $action, TempUserCreator $tempUserCreator)
Definition
ApiAcquireTempUserName.php:39
ApiAcquireTempUserName\isWriteMode
isWriteMode()
Indicates whether this module requires write access to the wiki.
Definition
ApiAcquireTempUserName.php:69
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition
ApiBase.php:67
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition
ApiBase.php:1568
ApiBase\checkUserRightsAny
checkUserRightsAny( $rights)
Helper function for permission-denied errors.
Definition
ApiBase.php:1683
ApiBase\getResult
getResult()
Get the result object.
Definition
ApiBase.php:701
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition
ApiBase.php:562
ApiMain
This is the main API class, used for both external and internal processing.
Definition
ApiMain.php:68
MediaWiki\Context\ContextSource\getUser
getUser()
Definition
ContextSource.php:161
MediaWiki\Context\ContextSource\getRequest
getRequest()
Definition
ContextSource.php:95
MediaWiki\User\TempUser\TempUserCreator
Service for temporary user creation.
Definition
TempUserCreator.php:30
includes
api
ApiAcquireTempUserName.php
Generated on Tue Sep 17 2024 09:22:18 for MediaWiki by
1.10.0