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;
/**#@-*/
/**
* @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' );
/**
* 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>');
}
}
# 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
<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>
$wgOut->addWikiText( wfMsg( 'uploadtext' ) );
$sk = $wgUser->getSkin();
- $fn = wfMsg( 'filename' );
+
+ $sourcefilename = wfMsg( 'sourcefilename' );
+ $destfilename = wfMsg( 'destfilename' );
+
$fd = wfMsg( 'filedesc' );
$ulb = wfMsg( 'uploadbtn' );
$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' />
}
$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 ) .
}
}
}
+
+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;
+}
+