18 protected static $right =
'translate-groupreview';
20 private $languageNameUtils;
22 private $messageGroupReviewStore;
24 public function __construct(
27 LanguageNameUtils $languageNameUtils,
30 parent::__construct( $main, $action );
31 $this->languageNameUtils = $languageNameUtils;
32 $this->messageGroupReviewStore = $messageGroupReviewStore;
35 public function execute() {
36 $user = $this->getUser();
37 $requestParams = $this->extractRequestParams();
40 $code = $requestParams[
'language'];
42 if ( !$group || MessageGroups::isDynamic( $group ) ) {
43 $this->dieWithError( [
'apierror-badparameter',
'group' ] );
45 $stateConfig = $group->getMessageGroupStates()->getStates();
46 if ( !$stateConfig ) {
47 $this->dieWithError(
'apierror-translate-groupreviewdisabled',
'disabled' );
50 $this->checkUserRightsAny( self::$right );
52 $block = $user->getBlock();
54 $this->dieBlocked( $block );
57 $languages = $this->languageNameUtils->getLanguageNames();
58 if ( !isset( $languages[$code] ) ) {
59 $this->dieWithError( [
'apierror-badparameter',
'language' ] );
62 $targetState = $requestParams[
'state'];
63 if ( !isset( $stateConfig[$targetState] ) ) {
64 $this->dieWithError(
'apierror-translate-invalidstate',
'invalidstate' );
67 if ( is_array( $stateConfig[$targetState] )
68 && isset( $stateConfig[$targetState][
'right'] )
70 $this->checkUserRightsAny( $stateConfig[$targetState][
'right'] );
73 $this->messageGroupReviewStore->changeState( $group, $code, $targetState, $user );
75 $output = [
'review' => [
76 'group' => $group->getId(),
78 'state' => $targetState,
81 $this->getResult()->addValue(
null, $this->getModuleName(), $output );
84 public function isWriteMode():
bool {
88 public function needsToken():
string {
92 protected function getAllowedParams(): array {
95 ParamValidator::PARAM_TYPE =>
'string',
96 ParamValidator::PARAM_REQUIRED =>
true,
99 ParamValidator::PARAM_TYPE =>
'string',
100 ParamValidator::PARAM_DEFAULT =>
'en',
103 ParamValidator::PARAM_TYPE =>
'string',
104 ParamValidator::PARAM_REQUIRED =>
true,
107 ParamValidator::PARAM_TYPE =>
'string',
108 ParamValidator::PARAM_REQUIRED =>
true,
113 protected function getExamplesMessages(): array {
115 'action=groupreview&group=page-Example&language=de&state=ready&token=foo'
116 =>
'apihelp-groupreview-example-1',