for r65152: fixed web ui for UploadFromUrl
authorMark A. Hershberger <mah@users.mediawiki.org>
Sat, 17 Apr 2010 21:44:51 +0000 (21:44 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Sat, 17 Apr 2010 21:44:51 +0000 (21:44 +0000)
* Add watchlist and ignorewarnings params for job — not used yet
* Add permissions check for isValidRequest

includes/specials/SpecialUpload.php
includes/upload/UploadFromUrl.php
languages/messages/MessagesEn.php

index d236f12..cc4843d 100644 (file)
@@ -387,6 +387,10 @@ class SpecialUpload extends SpecialPage {
                        return;
                }
 
+               if( $this->mUpload instanceOf UploadFromUrl ) {
+                       return $this->showUploadError( wfMsg( 'uploadfromurl-queued' ) );
+               }
+
                // Fetch the file if required
                $status = $this->mUpload->fetchFile();
                if( !$status->isOK() ) {
index 9c2f0cc..4392543 100644 (file)
@@ -10,7 +10,7 @@
  */
 class UploadFromUrl extends UploadBase {
        protected $mTempDownloadPath;
-       protected $comment, $watchList;
+       protected $comment, $watchList, $ignoreWarnings;
 
        /**
         * Checks if the user is allowed to use the upload-by-URL feature. If the
@@ -35,7 +35,7 @@ class UploadFromUrl extends UploadBase {
         * Entry point for API upload
         * @return bool true on success
         */
-       public function initialize( $name, $url, $comment, $watchlist ) {
+       public function initialize( $name, $url, $comment, $watchList, $ignoreWarn ) {
                global $wgUser;
 
                if( !Http::isValidURI( $url ) ) {
@@ -47,7 +47,8 @@ class UploadFromUrl extends UploadBase {
                        "url" => trim( $url ),
                        "timestamp" => wfTimestampNow(),
                        "comment" => $comment,
-                       "watchlist" => $watchlist);
+                       "watchlist" => $watchList,
+                       "ignorewarnings" => $ignoreWarn);
 
                $title = Title::newFromText( $name );
                /* // Check whether the user has the appropriate permissions to upload anyway */
@@ -81,6 +82,7 @@ class UploadFromUrl extends UploadBase {
                $this->mDesiredDestName = $job->title;
                $this->comment = $job->params['comment'];
                $this->watchList = $job->params['watchlist'];
+               $this->ignoreWarnings = $job->params['ignorewarnings'];
                $this->getTitle();
        }
 
@@ -95,8 +97,9 @@ class UploadFromUrl extends UploadBase {
                return $this->initialize(
                        $desiredDestName,
                        $request->getVal( 'wpUploadFileURL' ),
-                       '',
-                       false
+                       $request->getVal( 'wpUploadDescription' ),
+                       $request->getVal( 'wpWatchThis' ),
+                       $request->getVal( 'wpIgnoreWarnings' )
                );
        }
 
@@ -104,10 +107,12 @@ class UploadFromUrl extends UploadBase {
         * @param $request Object: WebRequest object
         */
        public static function isValidRequest( $request ){
-               if( !$request->getVal( 'wpUploadFileURL' ) )
-                       return false;
-               // check that is a valid url:
-               return Http::isValidURI( $request->getVal( 'wpUploadFileURL' ) );
+               global $wgUser;
+
+               $url = $request->getVal( 'wpUploadFileURL' );
+               return !empty( $url )
+                       && Http::isValidURI( $url )
+                       && $wgUser->isAllowed( 'upload_by_url' );
        }
 
        private function saveTempFile( $req ) {
@@ -151,11 +156,6 @@ class UploadFromUrl extends UploadBase {
                /* $warnings = $this->checkForWarnings(); */
                /* if( isset($warnings) ) return $warnings; */
 
-               // Use comment as initial page text by default
-               if ( is_null( $this->mParams['text'] ) ) {
-                       $this->mParams['text'] = $this->mParams['comment'];
-               }
-
                $file = $this->getLocalFile();
                // This comes from ApiBase
                /* $watch = $this->getWatchlistValue( $this->mParams['watchlist'], $file->getTitle() ); */
@@ -165,7 +165,7 @@ class UploadFromUrl extends UploadBase {
                }
 
                $status = $this->getLocalFile()->upload( $this->mTempPath, $this->comment,
-                       $this->pageText, File::DELETE_SOURCE, $this->mFileProps, false, $wgUser );
+                       $this->comment, File::DELETE_SOURCE, $this->mFileProps, false, $wgUser );
 
                return $status;
        }
index 01c79cf..f7f76fa 100644 (file)
@@ -2106,6 +2106,7 @@ You should check that file's deletion history before proceeding to re-upload it.
 'overwroteimage'              => 'uploaded a new version of "[[$1]]"',
 'uploaddisabled'              => 'Uploads disabled.',
 'copyuploaddisabled'          => 'Upload by URL disabled.',
+'uploadfromurl-queued'        => 'Your upload has been queued.',
 'uploaddisabledtext'          => 'File uploads are disabled.',
 'php-uploaddisabledtext'      => 'File uploads are disabled in PHP.
 Please check the file_uploads setting.',