-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathApiOpenFlexForm.php
More file actions
91 lines (79 loc) · 2.16 KB
/
ApiOpenFlexForm.php
File metadata and controls
91 lines (79 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
use FlexForm\Core\Config;
use FlexForm\Core\Debug;
use FlexForm\Core\HandleResponse;
use FlexForm\Core\Protect;
use FlexForm\FlexFormException;
use MediaWiki\MediaWikiServices;
use Wikimedia\ParamValidator\ParamValidator;
class ApiOpenFlexForm extends ApiBase {
/**
* @throws FlexFormException
* @throws \MediaWiki\Api\ApiUsageException
*/
public function execute() {
Config::setConfigFromMW();
$configVar = Config::getConfigVariable( 'allowFlexFormOpenAPI' );
if ( $configVar === null || $configVar === false ) {
$this->dieWithError( $this->msg( 'flexform-api-error-api-function-not-active' )->text() );
}
$params = $this->extractRequestParams();
$action = $params['ffAction'];
if ( !$action || $action === null ) {
$this->dieWithError( 'missingparam ffAction' );
}
switch ( $action ) {
case "canUserBeCreated":
$result = true;
$userName = $params['additionalData'];
if ( empty( $userName ) ) {
$this->dieWithError( 'missingparam' );
}
$userFactory = MediaWikiServices::getInstance()->getUserFactory();
$userNew = $userFactory->newFromName( $userName );
if ( $userNew->isRegistered() ) {
$result = false;
}
$nameUtils = MediaWikiServices::getInstance()->getUserNameUtils();
if ( !$nameUtils->isCreatable( $userName ) ) {
$result = false;
}
$this->getResult()->addValue( null, 'canUserBeCreated', $result );
break;
default :
$this->dieWithError( $this->msg( 'flexform-api-error-unknown-what-parameter' )->text() );
}
return true;
}
public function isReadMode() {
return false;
}
public function needsToken() {
return false;
}
public function isWriteMode() {
return false;
}
/**
* @return array
*/
public function getAllowedParams() {
return [
'ffAction' => [
ParamValidator::PARAM_TYPE => 'string',
ParamValidator::PARAM_REQUIRED => true
],
'additionalData' => [
ParamValidator::PARAM_TYPE => 'string'
],
];
}
/**
* @return array
*/
protected function getExamplesMessages(): array {
return [
'action=FlexFormOpen&ffAction=canUserBeCreated&additionalData=Harry%20Potter' => 'apihelp-flexform-ffaction-example-1'
];
}
}