MediaWiki master
ApiAcquireTempUserName.php
Go to the documentation of this file.
1<?php
2
8namespace MediaWiki\Api;
9
11
24
25 public function __construct(
26 ApiMain $main,
27 string $action,
28 private readonly TempUserCreator $tempUserCreator,
29 ) {
30 parent::__construct( $main, $action );
31 }
32
33 public function execute() {
34 // Like TempUserCreator::shouldAutoCreate(), but without the action check
35 if ( !$this->tempUserCreator->isEnabled() ) {
36 $this->dieWithError( 'apierror-tempuserdisabled', 'tempuserdisabled' );
37 }
38 if ( $this->getUser()->isRegistered() ) {
39 $this->dieWithError( 'apierror-alreadyregistered', 'alreadyregistered' );
40 }
41 $this->checkUserRightsAny( 'createaccount' );
42
43 // Checks passed, acquire the name
44 $session = $this->getRequest()->getSession();
45 $name = $this->tempUserCreator->acquireAndStashName( $session );
46 if ( $name === null ) {
47 $this->dieWithError( 'apierror-tempuseracquirefailed', 'tempuseracquirefailed' );
48 }
49
50 $session->persist();
51 $this->getResult()->addValue( null, $this->getModuleName(), $name );
52 }
53
55 public function isWriteMode() {
56 return true;
57 }
58
60 public function mustBePosted() {
61 return true;
62 }
63}
64
66class_alias( ApiAcquireTempUserName::class, 'ApiAcquireTempUserName' );
Acquire a temporary user username and stash it in the current session, if temp account creation is en...
__construct(ApiMain $main, string $action, private readonly TempUserCreator $tempUserCreator,)
mustBePosted()
Indicates whether this module must be called with a POST request.Implementations of this method must ...
isWriteMode()
Indicates whether this module requires write access to the wiki.API modules must override this method...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:60
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1506
checkUserRightsAny( $rights)
Helper function for permission-denied errors.
Definition ApiBase.php:1615
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:542
getResult()
Get the result object.
Definition ApiBase.php:681
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:67
Service for temporary user creation.