Uploading KML files to MediaWiki

So you want to upload KML files to your MediaWiki install? Simple as putting ‘kml’ in your allowed file extensions right?


Through the almighty power of a string match that’s not actually a regular expression, but instead a strpos match in the SpecialUpload:detectScript function (yes, that’s right, a strpos match, not a stripos match – but a strtolower takes care of that a few lines before – that’s probably faster anyway).

The strpos looks for <head in the chunk o’ text that’s in the uploaded file – which of course matches the KML heading tag – producing a detectScript match

Yes, one could modify the function in MediaWiki to handle KML file uploads – pulling <head out of the following code block:

		$tags = array(			'<body',			'<head',			'<html',   #also in safari			'<img',			'<pre',			'<script', #also in safari			'<table'			);		if( ! $wgAllowTitlesInSVG && $extension !== 'svg' && $mime !== 'image/svg' ) {			$tags[] = '<title';		}    		foreach( $tags as $tag ) {			if( false !== strpos( $chunk, $tag ) ) {				return true;			}		}

And then writing a regex to match <head and not <heading

Which is certainly do-able due to the beauty of open-source software(*) But thankfully (very thankfully) there’s a KMZ (scroll down) format. Which should upload just fine with just a file extension addition. (And the bonus is that it’s far more feature-rich to use.)

(* which, of course, making custom local modifications to your open-source software packages that don’t merit patch submissions back to the package authors is a whole other discussion topic, look for the future post and/or Conversations with Plastic Dinosaurs about being on the hook to maintain custom changes change for any and all future updates to the open-source software packages you use, which inevitably, you’ll forget you made, and then you’ll upgrade, and you’ll break expected functionality, which won’t be noticed for months after you’ve forgotten you ever even upgraded, at which point someone will complain, memos will be written, you’ll get blamed, you’ll bitch about getting blamed, everyone but you, given that you actually do the work, will promise not to forget about it again, which you’ll promptly do six months and thousands of tasks later on the next upgrade. Lather, Rinse, Repeat. )