From 81b932462026fd47b11790d72ef0759ca5aef4bf Mon Sep 17 00:00:00 2001 From: Justin Du Date: Thu, 29 Dec 2016 21:39:51 -0600 Subject: [PATCH] Add tagging support to imagerotate, revisiondelete, and tag API modules Adds a tags parameter. This allows a user with the applychangetags right to tag the log entry corresponding to the action. Bug: T97720 Change-Id: I11418d22ee780944e92d82e32b271b8276c396bf --- includes/api/ApiImageRotate.php | 24 ++++++++++++++++++++++-- includes/api/ApiRevisionDelete.php | 21 ++++++++++++++++++--- includes/api/ApiTag.php | 16 ++++++++++++++++ includes/api/i18n/en.json | 3 +++ includes/api/i18n/qqq.json | 3 +++ includes/revisiondelete/RevDelList.php | 9 +++++++-- 6 files changed, 69 insertions(+), 7 deletions(-) diff --git a/includes/api/ApiImageRotate.php b/includes/api/ApiImageRotate.php index 72fb16d19b..71bda6d7e4 100644 --- a/includes/api/ApiImageRotate.php +++ b/includes/api/ApiImageRotate.php @@ -42,6 +42,14 @@ class ApiImageRotate extends ApiBase { 'invalidTitles', 'special', 'missingIds', 'missingRevIds', 'interwikiTitles', ] ); + // Check if user can add tags + if ( count( $params['tags'] ) ) { + $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $this->getUser() ); + if ( !$ableToTag->isOK() ) { + $this->dieStatus( $ableToTag ); + } + } + foreach ( $pageSet->getTitles() as $title ) { $r = []; $r['id'] = $title->getArticleID(); @@ -104,8 +112,16 @@ class ApiImageRotate extends ApiBase { $comment = wfMessage( 'rotate-comment' )->numParams( $rotation )->inContentLanguage()->text(); - $status = $file->upload( $dstPath, - $comment, $comment, 0, false, false, $this->getUser() ); + $status = $file->upload( + $dstPath, + $comment, + $comment, + 0, + false, + false, + $this->getUser(), + $params['tags'] ?: [] + ); if ( $status->isGood() ) { $r['result'] = 'Success'; } else { @@ -157,6 +173,10 @@ class ApiImageRotate extends ApiBase { 'continue' => [ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', ], + 'tags' => [ + ApiBase::PARAM_TYPE => 'tags', + ApiBase::PARAM_ISMULTI => true, + ], ]; if ( $flags ) { $result += $this->getPageSet()->getFinalParams( $flags ); diff --git a/includes/api/ApiRevisionDelete.php b/includes/api/ApiRevisionDelete.php index 763aef5f03..4896e7e527 100644 --- a/includes/api/ApiRevisionDelete.php +++ b/includes/api/ApiRevisionDelete.php @@ -46,6 +46,14 @@ class ApiRevisionDelete extends ApiBase { $this->dieWithError( [ 'apierror-paramempty', 'ids' ], 'paramempty_ids' ); } + // Check if user can add tags + if ( count( $params['tags'] ) ) { + $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user ); + if ( !$ableToTag->isOK() ) { + $this->dieStatus( $ableToTag ); + } + } + $hide = $params['hide'] ?: []; $show = $params['show'] ?: []; if ( array_intersect( $hide, $show ) ) { @@ -90,9 +98,12 @@ class ApiRevisionDelete extends ApiBase { $list = RevisionDeleter::createList( $params['type'], $this->getContext(), $targetObj, $params['ids'] ); - $status = $list->setVisibility( - [ 'value' => $bitfield, 'comment' => $params['reason'], 'perItemStatus' => true ] - ); + $status = $list->setVisibility( [ + 'value' => $bitfield, + 'comment' => $params['reason'], + 'perItemStatus' => true, + 'tags' => $params['tags'] + ] ); $result = $this->getResult(); $data = $this->extractStatusInfo( $status ); @@ -165,6 +176,10 @@ class ApiRevisionDelete extends ApiBase { ApiBase::PARAM_DFLT => 'nochange', ], 'reason' => null, + 'tags' => [ + ApiBase::PARAM_TYPE => 'tags', + ApiBase::PARAM_ISMULTI => true, + ], ]; } diff --git a/includes/api/ApiTag.php b/includes/api/ApiTag.php index b142900a7d..7470ff3507 100644 --- a/includes/api/ApiTag.php +++ b/includes/api/ApiTag.php @@ -36,6 +36,14 @@ class ApiTag extends ApiBase { $this->dieBlocked( $user->getBlock() ); } + // Check if user can add tags + if ( count( $params['tags'] ) ) { + $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user ); + if ( !$ableToTag->isOk() ) { + $this->dieStatus( $ableToTag ); + } + } + // validate and process each revid, rcid and logid $this->requireAtLeastOneParameter( $params, 'revid', 'rcid', 'logid' ); $ret = []; @@ -116,6 +124,10 @@ class ApiTag extends ApiBase { ApiResult::setIndexedTagName( $idResult['added'], 't' ); $idResult['removed'] = $status->value->removedTags; ApiResult::setIndexedTagName( $idResult['removed'], 't' ); + + if ( $params['tags'] ) { + ChangeTags::addTags( $params['tags'], null, null, $status->value->logId ); + } } } return $idResult; @@ -154,6 +166,10 @@ class ApiTag extends ApiBase { 'reason' => [ ApiBase::PARAM_DFLT => '', ], + 'tags' => [ + ApiBase::PARAM_TYPE => 'tags', + ApiBase::PARAM_ISMULTI => true, + ], ]; } diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index f6eeffe880..3cd7183511 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -218,6 +218,7 @@ "apihelp-imagerotate-description": "Rotate one or more images.", "apihelp-imagerotate-param-rotation": "Degrees to rotate image clockwise.", + "apihelp-imagerotate-param-tags": "Tags to apply to the entry in the upload log.", "apihelp-imagerotate-example-simple": "Rotate File:Example.png by 90 degrees.", "apihelp-imagerotate-example-generator": "Rotate all images in Category:Flip by 180 degrees.", @@ -1326,6 +1327,7 @@ "apihelp-revisiondelete-param-show": "What to unhide for each revision.", "apihelp-revisiondelete-param-suppress": "Whether to suppress data from administrators as well as others.", "apihelp-revisiondelete-param-reason": "Reason for the deletion or undeletion.", + "apihelp-revisiondelete-param-tags": "Tags to apply to the entry in the deletion log.", "apihelp-revisiondelete-example-revision": "Hide content for revision 12345 on the page Main Page.", "apihelp-revisiondelete-example-log": "Hide all data on log entry 67890 with the reason BLP violation.", @@ -1371,6 +1373,7 @@ "apihelp-tag-param-add": "Tags to add. Only manually defined tags can be added.", "apihelp-tag-param-remove": "Tags to remove. Only tags that are either manually defined or completely undefined can be removed.", "apihelp-tag-param-reason": "Reason for the change.", + "apihelp-tag-param-tags": "Tags to apply to the log entry that will be created as a result of this action.", "apihelp-tag-example-rev": "Add the vandalism tag to revision ID 123 without specifying a reason", "apihelp-tag-example-log": "Remove the spam tag from log entry ID 123 with the reason Wrongly applied", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index 2c6637c4d2..6a9b360560 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -211,6 +211,7 @@ "apihelp-help-example-query": "{{doc-apihelp-example|help}}", "apihelp-imagerotate-description": "{{doc-apihelp-description|imagerotate}}", "apihelp-imagerotate-param-rotation": "{{doc-apihelp-param|imagerotate|rotation}}", + "apihelp-imagerotate-param-tags": "{{doc-apihelp-param|imagerotate|tags}}", "apihelp-imagerotate-example-simple": "{{doc-apihelp-example|imagerotate}}", "apihelp-imagerotate-example-generator": "{{doc-apihelp-example|imagerotate}}", "apihelp-import-description": "{{doc-apihelp-description|import}}", @@ -1238,6 +1239,7 @@ "apihelp-revisiondelete-param-show": "{{doc-apihelp-param|revisiondelete|show}}", "apihelp-revisiondelete-param-suppress": "{{doc-apihelp-param|revisiondelete|suppress}}", "apihelp-revisiondelete-param-reason": "{{doc-apihelp-param|revisiondelete|reason}}", + "apihelp-revisiondelete-param-tags": "{{doc-apihelp-param|revisiondelete|tags}}", "apihelp-revisiondelete-example-revision": "{{doc-apihelp-example|revisiondelete}}", "apihelp-revisiondelete-example-log": "{{doc-apihelp-example|revisiondelete}}", "apihelp-rollback-description": "{{doc-apihelp-description|rollback}}", @@ -1278,6 +1280,7 @@ "apihelp-tag-param-add": "{{doc-apihelp-param|tag|add}}", "apihelp-tag-param-remove": "{{doc-apihelp-param|tag|remove}}", "apihelp-tag-param-reason": "{{doc-apihelp-param|tag|reason}}", + "apihelp-tag-param-tags": "{{doc-apihelp-param|tag|tags}}", "apihelp-tag-example-rev": "{{doc-apihelp-example|tag}}", "apihelp-tag-example-log": "{{doc-apihelp-example|tag}}", "apihelp-tokens-description": "{{doc-apihelp-description|tokens}}", diff --git a/includes/revisiondelete/RevDelList.php b/includes/revisiondelete/RevDelList.php index 674846db05..833e38b2dc 100644 --- a/includes/revisiondelete/RevDelList.php +++ b/includes/revisiondelete/RevDelList.php @@ -97,8 +97,9 @@ abstract class RevDelList extends RevisionListBase { * * @param array $params Associative array of parameters. Members are: * value: ExtractBitParams() bitfield array - * comment: The log comment. + * comment: The log comment * perItemStatus: Set if you want per-item status reports + * tags: The array of change tags to apply to the log entry * @return Status * @since 1.23 Added 'perItemStatus' param */ @@ -269,7 +270,8 @@ abstract class RevDelList extends RevisionListBase { 'comment' => $comment, 'ids' => $idsForLog, 'authorIds' => $authorIds, - 'authorIPs' => $authorIPs + 'authorIPs' => $authorIPs, + 'tags' => isset( $params['tags'] ) ? $params['tags'] : [], ] ); @@ -327,6 +329,7 @@ abstract class RevDelList extends RevisionListBase { * comment: The log comment * authorsIds: The array of the user IDs of the offenders * authorsIPs: The array of the IP/anon user offenders + * tags: The array of change tags to apply to the log entry * @throws MWException */ private function updateLog( $logType, $params ) { @@ -349,6 +352,8 @@ abstract class RevDelList extends RevisionListBase { 'target_author_id' => $params['authorIds'], 'target_author_ip' => $params['authorIPs'], ] ); + // Apply change tags to the log entry + $logEntry->setTags( $params['tags'] ); $logId = $logEntry->insert(); $logEntry->publish( $logId ); } -- 2.20.1