for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Mediawiki\Api\Service;
use InvalidArgumentException;
use Mediawiki\Api\MediawikiApi;
use Mediawiki\Api\SimpleRequest;
use Mediawiki\Api\UsageException;
/**
* @access private
*
* @author Addshore
*/
class UserCreator {
* @var MediawikiApi
private $api;
* @param MediawikiApi $api
public function __construct( MediawikiApi $api ) {
$this->api = $api;
}
* @param string $username
* @param string $password
* @param string|null $email
* @return bool
public function create( $username, $password, $email = null ) {
if ( !is_string( $username ) ) {
throw new InvalidArgumentException( '$username should be a string' );
if ( !is_string( $password ) ) {
throw new InvalidArgumentException( '$password should be a string' );
if ( !is_string( $email ) && !is_null( $email ) ) {
throw new InvalidArgumentException( '$email should be a string or null' );
$params = [
'createreturnurl' => $this->api->getApiUrl(),
'createtoken' => $this->api->getToken( 'createaccount' ),
'username' => $username,
'password' => $password,
'retype' => $password,
];
if ( !is_null( $email ) ) {
$params['email'] = $email;
$result = $this->api->postRequest( new SimpleRequest( 'createaccount', $params ) );
return $result['createaccount']['status'] === 'PASS';