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.
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.
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
26 class ApiTag
extends ApiBase
{
28 protected function getAvailableTags() {
29 return ChangeTags
::listExplicitlyDefinedTags();
32 public function execute() {
33 $params = $this->extractRequestParams();
35 // make sure the user is allowed
36 if ( !$this->getUser()->isAllowed( 'changetags' ) ) {
37 $this->dieUsage( "You don't have permission to add or remove change tags from individual edits",
41 // validate and process each revid, rcid and logid
42 $this->requireAtLeastOneParameter( $params, 'revid', 'rcid', 'logid' );
44 if ( $params['revid'] ) {
45 foreach ( $params['revid'] as $id ) {
46 $ret[] = $this->processIndividual( 'revid', $params, $id );
49 if ( $params['rcid'] ) {
50 foreach ( $params['rcid'] as $id ) {
51 $ret[] = $this->processIndividual( 'rcid', $params, $id );
54 if ( $params['logid'] ) {
55 foreach ( $params['logid'] as $id ) {
56 $ret[] = $this->processIndividual( 'logid', $params, $id );
60 ApiResult
::setIndexedTagName( $ret, 'result' );
61 $this->getResult()->addValue( null, $this->getModuleName(), $ret );
64 protected static function validateLogId( $logid ) {
65 $dbr = wfGetDB( DB_SLAVE
);
66 $result = $dbr->selectField( 'logging', 'log_id', array( 'log_id' => $logid ),
71 protected function processIndividual( $type, $params, $id ) {
72 $idResult = array( $type => $id );
78 $valid = RecentChange
::newFromId( $id );
81 $valid = Revision
::newFromId( $id );
84 $valid = self
::validateLogId( $id );
89 $idResult['status'] = 'error';
90 $idResult +
= $this->parseMsg( array( "nosuch$type", $id ) );
94 $status = ChangeTags
::updateTagsWithChecks( $params['add'],
96 ( $type === 'rcid' ?
$id : null ),
97 ( $type === 'revid' ?
$id : null ),
98 ( $type === 'logid' ?
$id : null ),
103 if ( !$status->isOK() ) {
104 if ( $status->hasMessage( 'actionthrottledtext' ) ) {
105 $idResult['status'] = 'skipped';
107 $idResult['status'] = 'failure';
108 $idResult['errors'] = $this->getErrorFormatter()->arrayFromStatus( $status, 'error' );
111 $idResult['status'] = 'success';
112 if ( is_null( $status->value
->logId
) ) {
113 $idResult['noop'] = '';
115 $idResult['actionlogid'] = $status->value
->logId
;
116 $idResult['added'] = $status->value
->addedTags
;
117 ApiResult
::setIndexedTagName( $idResult['added'], 't' );
118 $idResult['removed'] = $status->value
->removedTags
;
119 ApiResult
::setIndexedTagName( $idResult['removed'], 't' );
125 public function mustBePosted() {
129 public function isWriteMode() {
133 public function getAllowedParams() {
136 ApiBase
::PARAM_TYPE
=> 'integer',
137 ApiBase
::PARAM_ISMULTI
=> true,
140 ApiBase
::PARAM_TYPE
=> 'integer',
141 ApiBase
::PARAM_ISMULTI
=> true,
144 ApiBase
::PARAM_TYPE
=> 'integer',
145 ApiBase
::PARAM_ISMULTI
=> true,
148 ApiBase
::PARAM_TYPE
=> $this->getAvailableTags(),
149 ApiBase
::PARAM_ISMULTI
=> true,
152 ApiBase
::PARAM_TYPE
=> 'string',
153 ApiBase
::PARAM_ISMULTI
=> true,
156 ApiBase
::PARAM_DFLT
=> '',
161 public function needsToken() {
165 protected function getExamplesMessages() {
167 'action=tag&revid=123&add=vandalism&token=123ABC'
168 => 'apihelp-tag-example-rev',
169 'action=tag&logid=123&remove=spam&reason=Wrongly+applied&token=123ABC'
170 => 'apihelp-tag-example-log',
174 public function getHelpUrls() {
175 return 'https://www.mediawiki.org/wiki/API:Tag';