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