11use UnexpectedValueException;
25 if ( $params[
'operation'] !==
'delete'
26 && !$authority->isAllowed(
'managechangetags' )
28 $this->
dieWithError(
'tags-manage-no-permission',
'permissiondenied' );
29 } elseif ( !$authority->isAllowed(
'deletechangetags' ) ) {
30 $this->
dieWithError(
'tags-delete-no-permission',
'permissiondenied' );
34 if ( $params[
'tags'] ) {
35 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params[
'tags'], $authority );
36 if ( !$ableToTag->isOK() ) {
42 $tag = $params[
'tag'];
43 $reason = $params[
'reason'];
44 $ignoreWarnings = $params[
'ignorewarnings'];
45 $tags = $params[
'tags'] ?: [];
46 $fn = match ( $params[
'operation'] ) {
47 'create' => ChangeTags::createTagWithChecks( ... ),
48 'delete' => ChangeTags::deleteTagWithChecks( ... ),
49 'activate' => ChangeTags::activateTagWithChecks( ... ),
50 'deactivate' => ChangeTags::deactivateTagWithChecks( ... ),
52 default =>
throw new UnexpectedValueException(
'invalid operation' )
54 $status = $fn( $tag, $reason, $authority, $ignoreWarnings, $tags );
55 if ( !$status->isOK() ) {
60 'operation' => $params[
'operation'],
61 'tag' => $params[
'tag'],
63 if ( !$status->isGood() ) {
64 $ret[
'warnings'] = $this->
getErrorFormatter()->arrayFromStatus( $status,
'warning' );
66 $ret[
'success'] = $status->value !==
null;
67 if ( $ret[
'success'] ) {
68 $ret[
'logid'] = $status->value;
88 ParamValidator::PARAM_TYPE => [
'create',
'delete',
'activate',
'deactivate' ],
89 ParamValidator::PARAM_REQUIRED =>
true,
93 ParamValidator::PARAM_TYPE =>
'string',
94 ParamValidator::PARAM_REQUIRED =>
true,
97 ParamValidator::PARAM_TYPE =>
'string',
98 ParamValidator::PARAM_DEFAULT =>
'',
100 'ignorewarnings' => [
101 ParamValidator::PARAM_TYPE =>
'boolean',
102 ParamValidator::PARAM_DEFAULT =>
false,
105 ParamValidator::PARAM_TYPE =>
'tags',
106 ParamValidator::PARAM_ISMULTI =>
true,
119 'action=managetags&operation=create&tag=spam&reason=For+use+in+edit+patrolling&token=123ABC'
120 =>
'apihelp-managetags-example-create',
121 'action=managetags&operation=delete&tag=vandlaism&reason=Misspelt&token=123ABC'
122 =>
'apihelp-managetags-example-delete',
123 'action=managetags&operation=activate&tag=spam&reason=For+use+in+edit+patrolling&token=123ABC'
124 =>
'apihelp-managetags-example-activate',
125 'action=managetags&operation=deactivate&tag=spam&reason=No+longer+required&token=123ABC'
126 =>
'apihelp-managetags-example-deactivate',
132 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Tag_management';
137class_alias( ApiManageTags::class,
'ApiManageTags' );