From: Bartosz DziewoƄski Date: Thu, 21 Jan 2016 18:20:53 +0000 (+0100) Subject: Allow users to tag file uploads X-Git-Tag: 1.31.0-rc.0~7946^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=05c2c65ab9f4f30439de5282fe0d86384e8ae01a;p=lhc%2Fweb%2Fwiklou.git Allow users to tag file uploads Using either action=upload API or Special:Upload. (No user interface is provided for the latter, this is meant to be used by on-wiki scripts/gadgets enhancing the upload process.) Modelled after how ae3ab9eef0379e3e0a6cd9408f153648297e0853 implemented tagging of regular edits. Bug: T121876 Change-Id: Ia3e0dbd895b2f8bc66985b24db35f112b6f9a22d --- diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 82f66a8c67..d674846022 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -703,6 +703,13 @@ class ApiUpload extends ApiBase { $watch = true; } + if ( $this->mParams['tags'] ) { + $status = ChangeTags::canAddTagsAccompanyingChange( $this->mParams['tags'], $this->getUser() ); + if ( !$status->isOK() ) { + $this->dieStatus( $status ); + } + } + // No errors, no warnings: do the upload if ( $this->mParams['async'] ) { $progress = UploadBase::getSessionStatus( $this->getUser(), $this->mParams['filekey'] ); @@ -720,6 +727,7 @@ class ApiUpload extends ApiBase { 'filename' => $this->mParams['filename'], 'filekey' => $this->mParams['filekey'], 'comment' => $this->mParams['comment'], + 'tags' => $this->mParams['tags'], 'text' => $this->mParams['text'], 'watch' => $watch, 'session' => $this->getContext()->exportSession() @@ -730,7 +738,7 @@ class ApiUpload extends ApiBase { } else { /** @var $status Status */ $status = $this->mUpload->performUpload( $this->mParams['comment'], - $this->mParams['text'], $watch, $this->getUser() ); + $this->mParams['text'], $watch, $this->getUser(), $this->mParams['tags'] ); if ( !$status->isGood() ) { $error = $status->getErrorsArray(); @@ -764,6 +772,10 @@ class ApiUpload extends ApiBase { 'comment' => array( ApiBase::PARAM_DFLT => '' ), + 'tags' => array( + ApiBase::PARAM_TYPE => 'tags', + ApiBase::PARAM_ISMULTI => true, + ), 'text' => array( ApiBase::PARAM_TYPE => 'text', ), diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index 4a1f2f188b..6ea643a9bc 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -1346,6 +1346,7 @@ "apihelp-upload-description": "Upload a file, or get the status of pending uploads.\n\nSeveral methods are available:\n* Upload file contents directly, using the $1file parameter.\n* Upload the file in pieces, using the $1filesize, $1chunk, and $1offset parameters.\n* Have the MediaWiki server fetch a file from a URL, using the $1url parameter.\n* Complete an earlier upload that failed due to warnings, using the $1filekey parameter.\nNote that the HTTP POST must be done as a file upload (i.e. using multipart/form-data) when sending the $1file.", "apihelp-upload-param-filename": "Target filename.", "apihelp-upload-param-comment": "Upload comment. Also used as the initial page text for new files if $1text is not specified.", + "apihelp-upload-param-tags": "Change tags to apply to the upload log entry and file page revision.", "apihelp-upload-param-text": "Initial page text for new files.", "apihelp-upload-param-watch": "Watch the page.", "apihelp-upload-param-watchlist": "Unconditionally add or remove the page from the current user's watchlist, use preferences or do not change watch.", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index df4f881dee..2108b332de 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -1253,6 +1253,7 @@ "apihelp-upload-description": "{{doc-apihelp-description|upload}}", "apihelp-upload-param-filename": "{{doc-apihelp-param|upload|filename}}", "apihelp-upload-param-comment": "{{doc-apihelp-param|upload|comment}}", + "apihelp-upload-param-tags": "{{doc-apihelp-param|upload|tags}}", "apihelp-upload-param-text": "{{doc-apihelp-param|upload|text}}", "apihelp-upload-param-watch": "{{doc-apihelp-param|upload|watch}}", "apihelp-upload-param-watchlist": "{{doc-apihelp-param|upload|watchlist}}", diff --git a/includes/jobqueue/jobs/PublishStashedFileJob.php b/includes/jobqueue/jobs/PublishStashedFileJob.php index 59166e8035..5f8af8b309 100644 --- a/includes/jobqueue/jobs/PublishStashedFileJob.php +++ b/includes/jobqueue/jobs/PublishStashedFileJob.php @@ -79,7 +79,8 @@ class PublishStashedFileJob extends Job { $this->params['comment'], $this->params['text'], $this->params['watch'], - $user + $user, + isset( $this->params['tags'] ) ? $this->params['tags'] : array() ); if ( !$status->isGood() ) { UploadBase::setSessionStatus( diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 5b3c43e698..3ccc797641 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -501,11 +501,29 @@ class SpecialUpload extends SpecialPage { $pageText = false; } + $changeTags = $this->getRequest()->getVal( 'wpChangeTags' ); + if ( is_null( $changeTags ) || $changeTags === '' ) { + $changeTags = array(); + } else { + $changeTags = array_filter( array_map( 'trim', explode( ',', $changeTags ) ) ); + } + + if ( $changeTags ) { + $changeTagsStatus = ChangeTags::canAddTagsAccompanyingChange( + $changeTags, $this->getUser() ); + if ( !$changeTagsStatus->isOK() ) { + $this->showUploadError( $this->getOutput()->parse( $changeTagsStatus->getWikiText() ) ); + + return; + } + } + $status = $this->mUpload->performUpload( $this->mComment, $pageText, $this->mWatchthis, - $this->getUser() + $this->getUser(), + $changeTags ); if ( !$status->isGood() ) {