Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4137113
GroupReviewActionApi.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
GroupReviewActionApi.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\MessageGroupProcessing
;
use
ApiBase
;
use
ApiMain
;
use
MediaWiki\Languages\LanguageNameUtils
;
use
Wikimedia\ParamValidator\ParamValidator
;
/**
* API module for switching workflow states for message groups
* @author Niklas Laxström
* @license GPL-2.0-or-later
* @ingroup API TranslateAPI
*/
class
GroupReviewActionApi
extends
ApiBase
{
/** @var string */
protected
static
$right
=
'translate-groupreview'
;
private
LanguageNameUtils
$languageNameUtils
;
private
MessageGroupReviewStore
$messageGroupReviewStore
;
public
function
__construct
(
ApiMain
$main
,
string
$action
,
LanguageNameUtils
$languageNameUtils
,
MessageGroupReviewStore
$messageGroupReviewStore
)
{
parent
::
__construct
(
$main
,
$action
);
$this
->
languageNameUtils
=
$languageNameUtils
;
$this
->
messageGroupReviewStore
=
$messageGroupReviewStore
;
}
public
function
execute
()
{
$user
=
$this
->
getUser
();
$requestParams
=
$this
->
extractRequestParams
();
$group
=
MessageGroups
::
getGroup
(
$requestParams
[
'group'
]
);
$code
=
$requestParams
[
'language'
];
if
(
!
$group
||
MessageGroups
::
isDynamic
(
$group
)
)
{
$this
->
dieWithError
(
[
'apierror-badparameter'
,
'group'
]
);
}
$stateConfig
=
$group
->
getMessageGroupStates
()->
getStates
();
if
(
!
$stateConfig
)
{
$this
->
dieWithError
(
'apierror-translate-groupreviewdisabled'
,
'disabled'
);
}
$this
->
checkUserRightsAny
(
self
::
$right
);
$block
=
$user
->
getBlock
();
if
(
$block
)
{
$this
->
dieBlocked
(
$block
);
}
$languages
=
$this
->
languageNameUtils
->
getLanguageNames
();
if
(
!
isset
(
$languages
[
$code
]
)
)
{
$this
->
dieWithError
(
[
'apierror-badparameter'
,
'language'
]
);
}
$targetState
=
$requestParams
[
'state'
];
if
(
!
isset
(
$stateConfig
[
$targetState
]
)
)
{
$this
->
dieWithError
(
'apierror-translate-invalidstate'
,
'invalidstate'
);
}
if
(
is_array
(
$stateConfig
[
$targetState
]
)
&&
isset
(
$stateConfig
[
$targetState
][
'right'
]
)
)
{
$this
->
checkUserRightsAny
(
$stateConfig
[
$targetState
][
'right'
]
);
}
$this
->
messageGroupReviewStore
->
changeState
(
$group
,
$code
,
$targetState
,
$user
);
$output
=
[
'review'
=>
[
'group'
=>
$group
->
getId
(),
'language'
=>
$code
,
'state'
=>
$targetState
,
]
];
$this
->
getResult
()->
addValue
(
null
,
$this
->
getModuleName
(),
$output
);
}
public
function
isWriteMode
():
bool
{
return
true
;
}
public
function
needsToken
():
string
{
return
'csrf'
;
}
protected
function
getAllowedParams
():
array
{
return
[
'group'
=>
[
ParamValidator
::
PARAM_TYPE
=>
'string'
,
ParamValidator
::
PARAM_REQUIRED
=>
true
,
],
'language'
=>
[
ParamValidator
::
PARAM_TYPE
=>
'string'
,
ParamValidator
::
PARAM_DEFAULT
=>
'en'
,
],
'state'
=>
[
ParamValidator
::
PARAM_TYPE
=>
'string'
,
ParamValidator
::
PARAM_REQUIRED
=>
true
,
],
'token'
=>
[
ParamValidator
::
PARAM_TYPE
=>
'string'
,
ParamValidator
::
PARAM_REQUIRED
=>
true
,
],
];
}
protected
function
getExamplesMessages
():
array
{
return
[
'action=groupreview&group=page-Example&language=de&state=ready&token=foo'
=>
'apihelp-groupreview-example-1'
,
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 14:00 (3 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
3f/87/434e1bbdb3f15068d6872f7d6c56
Default Alt Text
GroupReviewActionApi.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment