This file contains HTML or script code that may be erroneously interpreted by a web browser

The Error: This file contains HTML or script code that may be erroneously interpreted by a web browser

This is a common error when uploading files that the MediaWiki system does not allow.  By making some minor changes to the MediaWiki LocalSettings.php file, we can fix this.

For demo purposes, I'm going to make our system recognize SWF files (by default these are disallowed):

Firstly:

Add the following line to somewhere in the LocalSettings.php file in the web root folder where your MediaWiki is installed:

copyraw
$wgFileExtensions[] = 'swf';
  1.  $wgFileExtensions[] = 'swf'

or if you already have an array, just add it to the end:

copyraw
$wgFileExtensions = array('png', 'gif', 'jpg', 'jpeg', 'doc', 'ppt', 'xls', 'mpp', 'pdf', 'zip', 'flv', 'swf');
  1.  $wgFileExtensions = array('png', 'gif', 'jpg', 'jpeg', 'doc', 'ppt', 'xls', 'mpp', 'pdf', 'zip', 'flv', 'swf')

 

Online forums are saying this is it, but my system still didn't allow them and returned the above error...

Secondly:

Edit your /includes/specials/SpecialUpload.php file and add the following line shortly after the declaration of detectScript function:

copyraw
if ($extension === 'swf') return false;
  1.  if ($extension === 'swf') return false

I put it straight after:

copyraw
function detectScript($file, $mime, $extension) {
	global $wgAllowTitlesInSVG;
...
  1.  function detectScript($file, $mime, $extension) { 
  2.      global $wgAllowTitlesInSVG
  3.  ... 
That's all I do.  This means that you are allowing all SWF files to be uploaded.  You will be restricted in how big the SWF files are by your server.  We changed ours to 20Mb to accommodate for 5 minute SWF videos...

 

If the screen just goes blank when you've uploaded a file, then you'll need to debug. Put the following code at the beginning of your LocalSettings.php file:
copyraw
# for debug purposes
error_reporting(E_ALL);
ini_set("display_errors", 1);
$wgShowExceptionDetails = true;
$wgShowSQLErrors = true;
$wgDebugDumpSql  = true;
$wgDebugLogFile  = '/var/www/html/debug_log.txt';
  1.  # for debug purposes 
  2.  error_reporting(E_ALL)
  3.  ini_set("display_errors", 1)
  4.  $wgShowExceptionDetails = true
  5.  $wgShowSQLErrors = true
  6.  $wgDebugDumpSql  = true
  7.  $wgDebugLogFile  = '/var/www/html/debug_log.txt'

 

I still couldn't upload SWF files despite following all the information on the Internet. Ultimately I fixed this by a worrying fix...: modify /includes/MimeMagic.php under the line 434 "function doGuessMimeType()

copyraw
function doGuessMimeType( $file, $ext = true ) {
		return "application/x-shockwave-flash";
  1.  function doGuessMimeType( $file, $ext = true ) { 
  2.          return "application/x-shockwave-flash"
Of course this means that any mime types it's not sure about, it will return as shockwave files. This could be a security concern but as our MediaWiki is on our Intranet for Staff use only, it isn't.
Category: Hypertext Markup Language :: Article: 768