From 008f1ee491eee36f0edac2b655d7582744a27067 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 27 May 2010 07:30:34 +0000 Subject: [PATCH] Fixed severe breakage of non-JS upload, presumably introduced in the 1.16 upload rewrite. If the user doesn't enter a destination filename, it's meant to use the name of the source file. Untested code "$wgRequest->getText('wpUploadFile')" did not work, you need to fetch from $_FILES not $_REQUEST. Code to propagate the relevant default to UploadForm was missing, readded here. Apologies for the nodata hack, but I want to backport this to 1.16, so I don't want to make any HTMLForm.php changes if I can avoid it. --- includes/specials/SpecialUpload.php | 10 ++++++++-- includes/upload/UploadFromFile.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 33ed9f54e9..cba2851cd9 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -67,8 +67,8 @@ class SpecialUpload extends SpecialPage { // Guess the desired name from the filename if not provided $this->mDesiredDestName = $request->getText( 'wpDestFile' ); - if( !$this->mDesiredDestName ) { - $this->mDesiredDestName = $request->getText( 'wpUploadFile' ); + if( !$this->mDesiredDestName && $request->getFileName( 'wpUploadFile' ) !== null ) { + $this->mDesiredDestName = $request->getFileName( 'wpUploadFile' ); } $this->mComment = $request->getText( 'wpUploadDescription' ); $this->mLicense = $request->getText( 'wpLicense' ); @@ -226,6 +226,7 @@ class SpecialUpload extends SpecialPage { 'texttop' => $this->uploadFormTextTop, 'textaftersummary' => $this->uploadFormTextAfterSummary, + 'destfile' => $this->mDesiredDestName, ) ); $form->setTitle( $this->getTitle() ); @@ -718,6 +719,7 @@ class UploadForm extends HTMLForm { protected $mSessionKey; protected $mHideIgnoreWarning; protected $mDestWarningAck; + protected $mDestFile; protected $mTextTop; protected $mTextAfterSummary; @@ -731,6 +733,7 @@ class UploadForm extends HTMLForm { ? $options['sessionkey'] : ''; $this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] ); $this->mDestWarningAck = !empty( $options['destwarningack'] ); + $this->mDestFile = isset( $options['destfile'] ) ? $options['destfile'] : ''; $this->mTextTop = isset( $options['texttop'] ) ? $options['texttop'] : ''; @@ -903,6 +906,9 @@ class UploadForm extends HTMLForm { 'id' => 'wpDestFile', 'label-message' => 'destfilename', 'size' => 60, + 'default' => $this->mDestFile, + # FIXME: hack to work around poor handling of the 'default' option in HTMLForm + 'nodata' => strval( $this->mDestFile ) !== '', ), 'UploadDescription' => array( 'type' => 'textarea', diff --git a/includes/upload/UploadFromFile.php b/includes/upload/UploadFromFile.php index 28b514d00c..73581a61a6 100644 --- a/includes/upload/UploadFromFile.php +++ b/includes/upload/UploadFromFile.php @@ -13,7 +13,7 @@ class UploadFromFile extends UploadBase { function initializeFromRequest( &$request ) { $desiredDestName = $request->getText( 'wpDestFile' ); if( !$desiredDestName ) - $desiredDestName = $request->getText( 'wpUploadFile' ); + $desiredDestName = $request->getFileName( 'wpUploadFile' ); return $this->initializePathInfo( $desiredDestName, $request->getFileTempName( 'wpUploadFile' ), -- 2.20.1