function createMediaObject ($pagename, $fname, $attribs=false) {
		if (trim($fname) == '')
			return false; 

		$type = MediaObjectFactory::type($fname);
		$ext = strtolower(file_extension($fname));
		// special case: RealAudio/-Video
		switch ($ext) {
			case 'smi' :
			case 'smil':
			case 'rm':
				if ($attribs->attribs['media'] == 'audio')
					return new RealAudioObject($pagename, $fname, $attribs);
				else
					return new RealVideoObject($pagename, $fname, $attribs);
			case 'htm' :
			case 'html':
				return new IFrameObject($pagename, $fname, $attribs);
		}

		switch ($type) {
			case 'image' : return MediaObjectFactory::createImageObject($pagename, $fname, $attribs);
			case 'audio' : return MediaObjectFactory::createAudioObject($pagename, $fname, $attribs);
			case 'video' : return MediaObjectFactory::createVideoObject($pagename, $fname, $attribs);
		}
		// try to create a ScriptObject
		if ($so = ScriptObjectFactory::createScriptObjectFromFilename($pagename, $fname, $attribs))
			return $so;

		if (is_object($attribs)) {
			$attr = $attribs->getAttribs();
			if (isset($attr['url']))
				return new IFrameObject($pagename, $fname, $attribs);
		}

		$co = new CodeObject($pagename, $fname, $attribs);
		return $co->isBinary() ? false : $co;
	}
function doScript ($pagename, $scriptFormat, $code, $attrstr) {
	$attr = new Attributes($attrstr, array('print'=>'fo'));
	$attr = $attr->getAttribs('fo');
	if ($code == '')
		$so = ScriptObjectFactory::createScriptObjectFromFile($pagename, $scriptFormat, $attr['file']);
	else {
		$code = html_entity_decode($code);
		$code = str_replace("\\'", "'", $code);
		$code = str_replace("\\\"", '"', $code);
		$so = ScriptObjectFactory::createScriptObjectFromCode($pagename, $scriptFormat, $code);
	}	
	if ($so !== false) {
		$mo_png = $so->convert('png', $attr);
		$mo_eps = $so->convert('eps', $attr);
		$mo_pdf = $so->convert('pdf', $attr);
		$xml = "<imageobject>\n";
		if ($mo_png !== false)
			$xml.= $mo_png->getWikiXML('html', $attr) . "\n";
		if ($mo_eps !== false)
			$xml.= $mo_eps->getWikiXML('fo', $attr) . "\n";
		if ($mo_pdf !== false)
			$xml.= $mo_pdf->getWikiXML('fo', $attr) . "\n";
		$xml.= "</imageobject>\n";
		return Keep($xml);
	}
	return '';
}
function doScript ($pagename, $scriptFormat, $code, $attrstr) {
	$attribs = new Attributes($attrstr);
	$attr = $attribs->getAttribs('html');
	if ($scriptFormat == '')  // (:script ...:) => get script type from attributes
		$scriptFormat = $attr['type'];
	if ($code == '') 
		$so = ScriptObjectFactory::createScriptObjectFromFile($pagename, $scriptFormat, $attr['file']);
	else {
		$code = str_replace("\\'", "'", $code);
		$code = str_replace("\\\"", '"', $code);
		$so = ScriptObjectFactory::createScriptObjectFromCode($pagename, $scriptFormat, $code);
	}
	if ($so !== false) {
		$mo = $so->convert('png', $attr);
	//	M2MMarkReference($pagename, $mo->fname, $mo->type(), "generated $scriptFormat image");
		if (is_object($mo))
			return Keep($mo->getHTML($attr));
	}
	return '';
}