Thursday, May 17, 2012

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:

$wgFileExtensions[] = 'swf';

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

$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:

	if ($extension === 'swf') return false;

I put it straight after:

function detectScript($file, $mime, $extension) {
	global $wgAllowTitlesInSVG;
...
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:
# 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';

 

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()

	function doGuessMimeType( $file, $ext = true ) {
		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.

Add comment

Please note: all comments are reviewed before being published.


Security code
Refresh

Member Login

Joes Latest Members

A huge WELCOME goes to today's newest members:

  • infonat
Member Signups (Activated)
BeforeCurrentTrend
Day21=
Week105ê
Month11224ê
Year2,265612ê

Member Stats
56 guests are currently online.
1,178 members are still deciding.
There are 5,935 members in total.

Latest Comments

Paypal Donations

Want to support my work? Any donation is a blessing :c)