19 protected static $right =
'translate-groupreview';
21 private $languageNameUtils;
23 private $messageGroupReview;
25 public function __construct(
28 LanguageNameUtils $languageNameUtils,
31 parent::__construct( $main, $action );
32 $this->languageNameUtils = $languageNameUtils;
33 $this->messageGroupReview = $messageGroupReview;
36 public function execute() {
37 $user = $this->getUser();
38 $requestParams = $this->extractRequestParams();
40 $group = MessageGroups::getGroup( $requestParams[
'group'] );
41 $code = $requestParams[
'language'];
43 if ( !$group || MessageGroups::isDynamic( $group ) ) {
44 $this->dieWithError( [
'apierror-badparameter',
'group' ] );
46 $stateConfig = $group->getMessageGroupStates()->getStates();
47 if ( !$stateConfig ) {
48 $this->dieWithError(
'apierror-translate-groupreviewdisabled',
'disabled' );
51 $this->checkUserRightsAny( self::$right );
53 if ( $user->getBlock() ) {
54 $this->dieBlocked( $user->getBlock() );
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->messageGroupReview->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',