From 6eb85b88a8b05de44a83ff967ed72cc6ee4337f6 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 16 Apr 2005 17:17:18 +0000 Subject: [PATCH] Feature: user can specify upload destination name, separately from source name. JavaScript fills in the default destination, a blank destination also uses the default for the convenience of non-JS users. Also fixed a bug caused by the stat cache. --- includes/Image.php | 4 ++-- includes/SpecialUpload.php | 36 +++++++++++++++++++++++++++--------- languages/Language.php | 2 ++ skins/common/wikibits.js | 27 +++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/includes/Image.php b/includes/Image.php index 5824da8aa8..e081739236 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -184,8 +184,7 @@ class Image if ( $this->fileExists ) { # Get size in bytes - $s = stat( $this->imagePath ); - $this->size = $s['size']; + $this->size = filesize( $this->imagePath ); # Height and width # Don't try to get the width and height of sound and video files, that's bad for performance @@ -823,6 +822,7 @@ class Image global $wgInternalServer, $wgUseSquid; // Refresh metadata cache + clearstatcache(); $this->loadFromFile(); $this->saveToCache(); diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index de2199acf2..967576b1f0 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -31,7 +31,7 @@ class UploadForm { var $mUploadAffirm, $mUploadFile, $mUploadDescription, $mIgnoreWarning; var $mUploadSaveName, $mUploadTempName, $mUploadSize, $mUploadOldVersion; var $mUploadCopyStatus, $mUploadSource, $mReUpload, $mAction, $mUpload; - var $mOname, $mSessionKey, $mStashed; + var $mOname, $mSessionKey, $mStashed, $mDestFile; /**#@-*/ /** @@ -40,11 +40,13 @@ class UploadForm { * @param $request Data posted. */ function UploadForm( &$request ) { + $this->mDestFile = $request->getText( 'wpDestFile' ); + if( !$request->wasPosted() ) { - # GET requests just give the main form; no data. + # GET requests just give the main form; no data except wpDestfile. return; } - + $this->mUploadAffirm = $request->getCheck( 'wpUploadAffirm' ); $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning'); $this->mReUpload = $request->getCheck( 'wpReUpload' ); @@ -132,7 +134,7 @@ class UploadForm { /** * If there was no filename or a zero size given, give up quick. */ - if( ( trim( $this->mOname ) == '' ) || empty( $this->mUploadSize ) ) { + if( trim( $this->mOname ) == '' || empty( $this->mUploadSize ) ) { return $this->mainUploadForm('
  • '.wfMsg( 'emptyfile' ).'
  • '); } @@ -156,7 +158,11 @@ class UploadForm { } # Chop off any directories in the given filename - $basename = basename( $this->mOname ); + if ( $this->mDestFile ) { + $basename = basename( $this->mDestFile ); + } else { + $basename = basename( $this->mOname ); + } /** * We'll want to blacklist against *any* 'extension', and use @@ -479,6 +485,7 @@ class UploadForm { mSessionKey ) . "\" /> mUploadDescription ) . "\" /> + mDestFile ) . "\" /> {$copyright} @@ -525,7 +532,10 @@ class UploadForm { $wgOut->addWikiText( wfMsg( 'uploadtext' ) ); $sk = $wgUser->getSkin(); - $fn = wfMsg( 'filename' ); + + $sourcefilename = wfMsg( 'sourcefilename' ); + $destfilename = wfMsg( 'destfilename' ); + $fd = wfMsg( 'filedesc' ); $ulb = wfMsg( 'uploadbtn' ); @@ -537,6 +547,8 @@ class UploadForm { $titleObj = Title::makeTitle( NS_SPECIAL, 'Upload' ); $action = $titleObj->escapeLocalURL(); + $encDestFile = htmlspecialchars( $this->mDestFile ); + $source = "
    @@ -556,11 +568,17 @@ class UploadForm { } $wgOut->addHTML( " -
    + - + + +
    {$fn}: - + + {$sourcefilename}: +
    {$destfilename}: + +
    {$fd}: