Media Wiki 1.42 / using xampp v3.3.0 with Apache/2.4.58 (Win64) OpenSSL/3.1.3 PHP/8.2.12 - this could be corrected by know but I wanted it up here just in case.
After attempting an upload of a ".rdp" file not uploading as application/x-rdp type but continuously as :
NxWare-SVN.rdp (file size: 2 KB, MIME type: text/plain)
I could not get the file to do what I wanted with it coming in as a Text/Plain
Changed apache/php/and localSettings multiple time to no avail with all instruction available to me online.
Tested with a separate php file importer I created using Html and php:
<?php
if ($_FILES) {
// Get the uploaded file
$file = $_FILES['file']['tmp_name'];
$fileName = $_FILES['file']['name'];
// Open the file info object to check its MIME type
$fileInfo = finfo_open(FILEINFO_MIME_TYPE);
$mimeType = finfo_file($fileInfo, $file); // Get the MIME type
finfo_close($fileInfo); // Close the file info object
// If the MIME type is incorrectly detected, override based on the file extension
if ($mimeType == 'text/plain' && pathinfo($fileName, PATHINFO_EXTENSION) == 'rdp') {
$mimeType = 'application/x-rdp'; // Override to the correct MIME type for .rdp files
}
echo 'Uploaded file: ' . $fileName . '<br>';
echo 'MIME Type: ' . $mimeType . '<br>';
echo 'File Size: ' . $_FILES['file']['size'] . ' bytes<br>';
}
and
<form action="MimeType.php" method="POST" enctype="multipart/form-data">
<label for="file">Upload an .rdp file:</label>
<input type="file" name="file" id="file" accept=".rdp" required>
<button type="submit">Upload</button>
</form>
and the file would come up correctly, so I knew apache and php was correct it was just the php's in Media wiki
So, after some messing around and pinpointing I narrowed it down to the MWFileProps.php that is called from UploadBase.php.
in the function: public function getPropsFromPath
I modified and changed it to the following, just to handle rdp-files, if there is another file type you have an issue with you can modify it to match you mime information and it should load correctly:
public function getPropsFromPath( $path, $ext = true ) {
// SAFE PATCH: Detect .rdp extension reliably
$checkExt = null;
if ( is_string( $ext ) && strtolower($ext) === 'rdp' ) {
$checkExt = 'rdp';
} elseif ( is_string( $path ) && strtolower(pathinfo($path, PATHINFO_EXTENSION)) === 'rdp' ) {
$checkExt = 'rdp';
}
if ( $checkExt === 'rdp' && is_string($path) && file_exists($path) ) {
$fsFile = new FSFile( $path );
return [
'fileExists' => true,
'size' => $fsFile->getSize(),
'sha1' => $fsFile->getSha1Base36(),
'mime' => 'application/x-rdp',
'file-mime' => 'application/x-rdp',
'major_mime' => 'application',
'minor_mime' => 'x-rdp',
'media_type' => 'UNKNOWN', // was MEDIATYPE_BINARY
'metadata' => [],
'width' => null,
'height' => null,
'bits' => null,
'pageCount' => null,
'duration' => null,
'commentCount' => null,
];
}
$fsFile = new FSFile( $path );
$info = $this->newPlaceholderProps();
$info['fileExists'] = $fsFile->exists();
if ( $info['fileExists'] ) {
$info['size'] = $fsFile->getSize(); // bytes
$info['sha1'] = $fsFile->getSha1Base36();
# MIME type according to file contents
$info['file-mime'] = $this->magic->guessMimeType( $path, false );
# Logical MIME type
$ext = ( $ext === true ) ? FileBackend::extensionFromPath( $path ) : (string)$ext;
# XXX: MimeAnalyzer::improveTypeFromExtension() may return null (T253483).
# Unclear if callers of this method expect that.
$info['mime'] = $this->magic->improveTypeFromExtension( $info['file-mime'], $ext );
[ $info['major_mime'], $info['minor_mime'] ] = File::splitMime( $info['mime'] );
$info['media_type'] = $this->magic->getMediaType( $path, $info['mime'] );
# Height, width and metadata
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable See XXX above
$handler = MediaHandler::getHandler( $info['mime'] );
if ( $handler ) {
$sizeAndMetadata = $handler->getSizeAndMetadataWithFallback( $fsFile, $path );
if ( $sizeAndMetadata ) {
$info = $sizeAndMetadata + $info;
}
}
}
return $info;
}
The creators can tell you if this is a bad idea, but it works for what I needed it for. Just thought I would share after 5 hours of troubleshooting this.