Merge "Convert Special:DeletedContributions to use OOUI."
[lhc/web/wiklou.git] / includes / api / ApiManageTags.php
1 <?php
2
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 *
19 * @file
20 */
21
22 /**
23 * @ingroup API
24 * @since 1.25
25 */
26 class ApiManageTags extends ApiBase {
27
28 public function execute() {
29 $params = $this->extractRequestParams();
30
31 // make sure the user is allowed
32 if ( $params['operation'] !== 'delete'
33 && !$this->getUser()->isAllowed( 'managechangetags' )
34 ) {
35 $this->dieUsage( "You don't have permission to manage change tags",
36 'permissiondenied' );
37 } elseif ( !$this->getUser()->isAllowed( 'deletechangetags' ) ) {
38 $this->dieUsage( "You don't have permission to delete change tags",
39 'permissiondenied' );
40 }
41
42 $result = $this->getResult();
43 $funcName = "{$params['operation']}TagWithChecks";
44 $status = ChangeTags::$funcName( $params['tag'], $params['reason'],
45 $this->getUser(), $params['ignorewarnings'] );
46
47 if ( !$status->isOK() ) {
48 $this->dieStatus( $status );
49 }
50
51 $ret = [
52 'operation' => $params['operation'],
53 'tag' => $params['tag'],
54 ];
55 if ( !$status->isGood() ) {
56 $ret['warnings'] = $this->getErrorFormatter()->arrayFromStatus( $status, 'warning' );
57 }
58 $ret['success'] = $status->value !== null;
59 if ( $ret['success'] ) {
60 $ret['logid'] = $status->value;
61 }
62 $result->addValue( null, $this->getModuleName(), $ret );
63 }
64
65 public function mustBePosted() {
66 return true;
67 }
68
69 public function isWriteMode() {
70 return true;
71 }
72
73 public function getAllowedParams() {
74 return [
75 'operation' => [
76 ApiBase::PARAM_TYPE => [ 'create', 'delete', 'activate', 'deactivate' ],
77 ApiBase::PARAM_REQUIRED => true,
78 ],
79 'tag' => [
80 ApiBase::PARAM_TYPE => 'string',
81 ApiBase::PARAM_REQUIRED => true,
82 ],
83 'reason' => [
84 ApiBase::PARAM_TYPE => 'string',
85 ],
86 'ignorewarnings' => [
87 ApiBase::PARAM_TYPE => 'boolean',
88 ApiBase::PARAM_DFLT => false,
89 ],
90 ];
91 }
92
93 public function needsToken() {
94 return 'csrf';
95 }
96
97 protected function getExamplesMessages() {
98 return [
99 'action=managetags&operation=create&tag=spam&reason=For+use+in+edit+patrolling&token=123ABC'
100 => 'apihelp-managetags-example-create',
101 'action=managetags&operation=delete&tag=vandlaism&reason=Misspelt&token=123ABC'
102 => 'apihelp-managetags-example-delete',
103 'action=managetags&operation=activate&tag=spam&reason=For+use+in+edit+patrolling&token=123ABC'
104 => 'apihelp-managetags-example-activate',
105 'action=managetags&operation=deactivate&tag=spam&reason=No+longer+required&token=123ABC'
106 => 'apihelp-managetags-example-deactivate',
107 ];
108 }
109
110 public function getHelpUrls() {
111 return 'https://www.mediawiki.org/wiki/API:Tag_management';
112 }
113 }