Merge "Add CollationFa"
[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->dieWithError( 'tags-manage-no-permission', 'permissiondenied' );
36 } elseif ( !$this->getUser()->isAllowed( 'deletechangetags' ) ) {
37 $this->dieWithError( 'tags-delete-no-permission', 'permissiondenied' );
38 }
39
40 $result = $this->getResult();
41 $funcName = "{$params['operation']}TagWithChecks";
42 $status = ChangeTags::$funcName( $params['tag'], $params['reason'],
43 $this->getUser(), $params['ignorewarnings'] );
44
45 if ( !$status->isOK() ) {
46 $this->dieStatus( $status );
47 }
48
49 $ret = [
50 'operation' => $params['operation'],
51 'tag' => $params['tag'],
52 ];
53 if ( !$status->isGood() ) {
54 $ret['warnings'] = $this->getErrorFormatter()->arrayFromStatus( $status, 'warning' );
55 }
56 $ret['success'] = $status->value !== null;
57 if ( $ret['success'] ) {
58 $ret['logid'] = $status->value;
59 }
60 $result->addValue( null, $this->getModuleName(), $ret );
61 }
62
63 public function mustBePosted() {
64 return true;
65 }
66
67 public function isWriteMode() {
68 return true;
69 }
70
71 public function getAllowedParams() {
72 return [
73 'operation' => [
74 ApiBase::PARAM_TYPE => [ 'create', 'delete', 'activate', 'deactivate' ],
75 ApiBase::PARAM_REQUIRED => true,
76 ],
77 'tag' => [
78 ApiBase::PARAM_TYPE => 'string',
79 ApiBase::PARAM_REQUIRED => true,
80 ],
81 'reason' => [
82 ApiBase::PARAM_TYPE => 'string',
83 ],
84 'ignorewarnings' => [
85 ApiBase::PARAM_TYPE => 'boolean',
86 ApiBase::PARAM_DFLT => false,
87 ],
88 ];
89 }
90
91 public function needsToken() {
92 return 'csrf';
93 }
94
95 protected function getExamplesMessages() {
96 return [
97 'action=managetags&operation=create&tag=spam&reason=For+use+in+edit+patrolling&token=123ABC'
98 => 'apihelp-managetags-example-create',
99 'action=managetags&operation=delete&tag=vandlaism&reason=Misspelt&token=123ABC'
100 => 'apihelp-managetags-example-delete',
101 'action=managetags&operation=activate&tag=spam&reason=For+use+in+edit+patrolling&token=123ABC'
102 => 'apihelp-managetags-example-activate',
103 'action=managetags&operation=deactivate&tag=spam&reason=No+longer+required&token=123ABC'
104 => 'apihelp-managetags-example-deactivate',
105 ];
106 }
107
108 public function getHelpUrls() {
109 return 'https://www.mediawiki.org/wiki/API:Tag_management';
110 }
111 }