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
This commit is contained in:
Justin Du 2016-12-29 21:39:51 -06:00
parent 9fa9a26b98
commit 81b9324620
6 changed files with 69 additions and 7 deletions

View file

@ -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 );

View file

@ -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,
],
];
}

View file

@ -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,
],
];
}

View file

@ -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 <kbd>File:Example.png</kbd> by <kbd>90</kbd> degrees.",
"apihelp-imagerotate-example-generator": "Rotate all images in <kbd>Category:Flip</kbd> by <kbd>180</kbd> 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 <kbd>12345</kbd> on the page <kbd>Main Page</kbd>.",
"apihelp-revisiondelete-example-log": "Hide all data on log entry <kbd>67890</kbd> with the reason <kbd>BLP violation</kbd>.",
@ -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 <kbd>vandalism</kbd> tag to revision ID 123 without specifying a reason",
"apihelp-tag-example-log": "Remove the <kbd>spam</kbd> tag from log entry ID 123 with the reason <kbd>Wrongly applied</kbd>",

View file

@ -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}}",

View file

@ -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 );
}