MediaWiki master
ApiAcquireTempUserName.php
Go to the documentation of this file.
1<?php
2
22namespace MediaWiki\Api;
23
25
38
39 private TempUserCreator $tempUserCreator;
40
41 public function __construct(
42 ApiMain $main,
43 string $action,
44 TempUserCreator $tempUserCreator
45 ) {
46 parent::__construct( $main, $action );
47 $this->tempUserCreator = $tempUserCreator;
48 }
49
50 public function execute() {
51 // Like TempUserCreator::shouldAutoCreate(), but without the action check
52 if ( !$this->tempUserCreator->isEnabled() ) {
53 $this->dieWithError( 'apierror-tempuserdisabled', 'tempuserdisabled' );
54 }
55 if ( $this->getUser()->isRegistered() ) {
56 $this->dieWithError( 'apierror-alreadyregistered', 'alreadyregistered' );
57 }
58 $this->checkUserRightsAny( 'createaccount' );
59
60 // Checks passed, acquire the name
61 $session = $this->getRequest()->getSession();
62 $name = $this->tempUserCreator->acquireAndStashName( $session );
63 if ( $name === null ) {
64 $this->dieWithError( 'apierror-tempuseracquirefailed', 'tempuseracquirefailed' );
65 }
66
67 $session->persist();
68 $this->getResult()->addValue( null, $this->getModuleName(), $name );
69 }
70
71 public function isWriteMode() {
72 return true;
73 }
74
75 public function mustBePosted() {
76 return true;
77 }
78}
79
81class_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.
__construct(ApiMain $main, string $action, TempUserCreator $tempUserCreator)
isWriteMode()
Indicates whether this module requires write access to the wiki.
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:76
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
Definition ApiBase.php:1565
checkUserRightsAny( $rights)
Helper function for permission-denied errors.
Definition ApiBase.php:1680
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:571
getResult()
Get the result object.
Definition ApiBase.php:710
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:78
Service for temporary user creation.