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