Feature: user can specify upload destination name, separately from source name. JavaS...
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 16 Apr 2005 17:17:18 +0000 (17:17 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 16 Apr 2005 17:17:18 +0000 (17:17 +0000)
includes/Image.php
includes/SpecialUpload.php
languages/Language.php
skins/common/wikibits.js

index 5824da8..e081739 100644 (file)
@@ -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();
 
index de2199a..967576b 100644 (file)
@@ -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('<li>'.wfMsg( 'emptyfile' ).'</li>');
                }
                
@@ -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 {
                <input type='hidden' name='wpIgnoreWarning' value='1' />
                <input type='hidden' name='wpSessionKey' value=\"" . htmlspecialchars( $this->mSessionKey ) . "\" />
                <input type='hidden' name='wpUploadDescription' value=\"" . htmlspecialchars( $this->mUploadDescription ) . "\" />
+               <input type='hidden' name='wpDestFile' value=\"" . htmlspecialchars( $this->mDestFile ) . "\" />
        {$copyright}
        <table border='0'>
                <tr>
@@ -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 = "
        <td align='right'>
        <input tabindex='3' type='checkbox' name='wpUploadAffirm' value='1' id='wpUploadAffirm' />
@@ -556,11 +568,17 @@ class UploadForm {
                  }
 
                $wgOut->addHTML( "
-       <form id='upload' method='post' enctype='multipart/form-data' action='$action'>
+       <form id='upload' method='post' enctype='multipart/form-data' action=\"$action\">
        <table border='0'><tr>
-       <td align='right'>{$fn}:</td><td align='left'>
-       <input tabindex='1' type='file' name='wpUploadFile' size='40' />
+
+       <td align='right'>{$sourcefilename}:</td><td align='left'>
+       <input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' onchange='fillDestFilename()' size='40' />
        </td></tr><tr>
+
+       <td align='right'>{$destfilename}:</td><td align='left'>
+       <input tabindex='1' type='text' name='wpDestFile' id='wpDestFile' size='40' value=\"$encDestFile\" />
+       </td></tr><tr>
+       
        <td align='right'>{$fd}:</td><td align='left'>
        <textarea tabindex='2' name='wpUploadDescription' rows='6' cols='{$cols}'{$ew}>"        
          . htmlspecialchars( $this->mUploadDescription ) .
index d382ca9..190a14e 100644 (file)
@@ -1027,6 +1027,8 @@ created and by whom, and anything else you may know about it. If this is an imag
 'uploadedimage' => "uploaded \"[[$1]]\"",
 'uploaddisabled' => 'Sorry, uploading is disabled.',
 'uploadcorrupt' => 'The file is corrupt or has an incorrect extension. Please check the file and upload again.',
+'sourcefilename' => 'Source filename',
+'destfilename' => 'Destination filename',
 
 # Image list
 #
index 6d2edc5..74483e4 100644 (file)
@@ -453,3 +453,30 @@ function addRightClickEditHandler( el ) {
                }
        }
 }
+
+function fillDestFilename() {
+       if (!document.getElementById) return;
+       var path = document.getElementById('wpUploadFile').value;
+       // Find trailing part
+       var slash = path.lastIndexOf( '/' );
+       var backslash = path.lastIndexOf( '\\' );
+       var fname;
+       if ( slash == -1 && backslash == -1 ) {
+               fname = path;
+       } else if ( slash > backslash ) {
+               fname = path.substring( slash+1, 10000 );
+       } else {
+               fname = path.substring( backslash+1, 10000 );
+       }
+
+       // Capitalise first letter and replace spaces by underscores
+       fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace( / /g, '_' );
+
+       // Output result
+       var destFile = document.getElementById('wpDestFile');
+       if (destFile.value == '' || destFile.value == document.fname ) {
+               document.getElementById('wpDestFile').value = fname;
+       }
+       document.fname = fname;
+}
+