Bartosz Dziewoński has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/265621

Change subject: Allow users to tag file uploads
......................................................................

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
---
M includes/api/ApiUpload.php
M includes/api/i18n/en.json
M includes/jobqueue/jobs/PublishStashedFileJob.php
M includes/specials/SpecialUpload.php
4 files changed, 34 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/21/265621/1

diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php
index e76b365..6384a86 100644
--- a/includes/api/ApiUpload.php
+++ b/includes/api/ApiUpload.php
@@ -735,6 +735,12 @@
                        $watch = true;
                }
 
+               if ( $this->mParams['tags'] ) {
+                       if ( !$this->getUser()->isAllowed( 'applychangetags' ) 
) {
+                               $this->dieUsage( 'You don\'t have permission to 
set change tags.', 'taggingnotallowed' );
+                       }
+               }
+
                // No errors, no warnings: do the upload
                if ( $this->mParams['async'] ) {
                        $progress = UploadBase::getSessionStatus( 
$this->getUser(), $this->mParams['filekey'] );
@@ -752,6 +758,7 @@
                                        '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()
@@ -762,7 +769,7 @@
                } 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();
@@ -815,6 +822,10 @@
                        'comment' => array(
                                ApiBase::PARAM_DFLT => ''
                        ),
+                       'tags' => array(
+                               ApiBase::PARAM_TYPE => 
ChangeTags::listExplicitlyDefinedTags(),
+                               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 2fb9a50..4b4489c 100644
--- a/includes/api/i18n/en.json
+++ b/includes/api/i18n/en.json
@@ -1335,6 +1335,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 <var>$1file</var> parameter.\n* Upload the file in pieces, 
using the <var>$1filesize</var>, <var>$1chunk</var>, and <var>$1offset</var> 
parameters.\n* Have the MediaWiki server fetch a file from a URL, using the 
<var>$1url</var> parameter.\n* Complete an earlier upload that failed due to 
warnings, using the <var>$1filekey</var> parameter.\nNote that the HTTP POST 
must be done as a file upload (i.e. using <code>multipart/form-data</code>) 
when sending the <var>$1file</var>.",
        "apihelp-upload-param-filename": "Target filename.",
        "apihelp-upload-param-comment": "Upload comment. Also used as the 
initial page text for new files if <var>$1text</var> 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/jobqueue/jobs/PublishStashedFileJob.php 
b/includes/jobqueue/jobs/PublishStashedFileJob.php
index 59166e8..5f8af8b 100644
--- a/includes/jobqueue/jobs/PublishStashedFileJob.php
+++ b/includes/jobqueue/jobs/PublishStashedFileJob.php
@@ -79,7 +79,8 @@
                                $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 5b3c43e..3ccc797 100644
--- a/includes/specials/SpecialUpload.php
+++ b/includes/specials/SpecialUpload.php
@@ -501,11 +501,29 @@
                        $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() ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/265621
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia3e0dbd895b2f8bc66985b24db35f112b6f9a22d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to