MediaWiki master
ApiAcquireTempUserName.php
Go to the documentation of this file.
1<?php
2
23
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}
Acquire a temporary user username and stash it in the current session, if temp account creation is en...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
mustBePosted()
Indicates whether this module must be called with a POST request.
__construct(ApiMain $main, string $action, TempUserCreator $tempUserCreator)
isWriteMode()
Indicates whether this module requires write mode.
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:65
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1540
checkUserRightsAny( $rights)
Helper function for permission-denied errors.
Definition ApiBase.php:1655
getResult()
Get the result object.
Definition ApiBase.php:681
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:542
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:67
Service for temporary user creation.