18 protected static $right =
'translate-groupreview';
20 private $languageNameUtils;
22 private $messageGroupReview;
24 public function __construct(
27 LanguageNameUtils $languageNameUtils,
30 parent::__construct( $main, $action );
31 $this->languageNameUtils = $languageNameUtils;
32 $this->messageGroupReview = $messageGroupReview;
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 if ( $user->getBlock() ) {
53 $this->dieBlocked( $user->getBlock() );
56 $languages = $this->languageNameUtils->getLanguageNames();
57 if ( !isset( $languages[$code] ) ) {
58 $this->dieWithError( [
'apierror-badparameter',
'language' ] );
61 $targetState = $requestParams[
'state'];
62 if ( !isset( $stateConfig[$targetState] ) ) {
63 $this->dieWithError(
'apierror-translate-invalidstate',
'invalidstate' );
66 if ( is_array( $stateConfig[$targetState] )
67 && isset( $stateConfig[$targetState][
'right'] )
69 $this->checkUserRightsAny( $stateConfig[$targetState][
'right'] );
72 $this->messageGroupReview->changeState( $group, $code, $targetState, $user );
74 $output = [
'review' => [
75 'group' => $group->getId(),
77 'state' => $targetState,
80 $this->getResult()->addValue(
null, $this->getModuleName(), $output );
83 public function isWriteMode():
bool {
87 public function needsToken():
string {
91 protected function getAllowedParams(): array {
94 ParamValidator::PARAM_TYPE =>
'string',
95 ParamValidator::PARAM_REQUIRED =>
true,
98 ParamValidator::PARAM_TYPE =>
'string',
99 ParamValidator::PARAM_DEFAULT =>
'en',
102 ParamValidator::PARAM_TYPE =>
'string',
103 ParamValidator::PARAM_REQUIRED =>
true,
106 ParamValidator::PARAM_TYPE =>
'string',
107 ParamValidator::PARAM_REQUIRED =>
true,
112 protected function getExamplesMessages(): array {
114 'action=groupreview&group=page-Example&language=de&state=ready&token=foo'
115 =>
'apihelp-groupreview-example-1',