Allow users to tag file uploads
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 21 Jan 2016 18:20:53 +0000 (19:20 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Tue, 16 Feb 2016 02:51:29 +0000 (03:51 +0100)
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

includes/api/ApiUpload.php
includes/api/i18n/en.json
includes/api/i18n/qqq.json
includes/jobqueue/jobs/PublishStashedFileJob.php
includes/specials/SpecialUpload.php

index 82f66a8..d674846 100644 (file)
@@ -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',
                        ),
index 4a1f2f1..6ea643a 100644 (file)
        "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.",
index df4f881..2108b33 100644 (file)
        "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}}",
index 59166e8..5f8af8b 100644 (file)
@@ -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(
index 5b3c43e..3ccc797 100644 (file)
@@ -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() ) {