array_shift($out); $out = trim(implode("\n", $out)); $source_language = array_shift(explode('.', $xmlg["site_base_url"])); $target_language = get_param('translated_text_target_language', 'en'); $langpair = urlencode("{$source_language}|{$target_language}"); $url = "http://www.google.com/translate_t?langpair={$langpair}&text=" . urlencode(utf8_decode($out)); echo file_get_contents($url); } else { if ($format == "xhtml") { $xmlg['xhtml_justify'] = get_param('xhtml_justify', false); $xmlg['xhtml_logical_markup'] = get_param('xhtml_logical_markup', false); $xmlg['xhtml_source'] = get_param('xhtml_source', false); if ($xmlg['xhtml_source']) { header('Content-type: text/xml; charset=utf-8'); #header('Content-type: text/html; charset=utf-8'); $s = $converter->articles2xhtml($xml, $xmlg); $s = str_replace('>', ">\n", $s); $s = str_replace('<', "\n<", $s); $s = str_replace("\n\n", "\n", $s); echo trim($s); #echo str_replace ( "\n" , '<br/>' , htmlentities ( trim ( $s ) ) ) ; } else { # Header hack for IE if (stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml")) { header("Content-type: application/xhtml+xml"); } else { header("Content-type: text/html"); } echo $converter->articles2xhtml($xml, $xmlg); } } else {
$format = strtolower(get_param('format', 'xhtml')); $content_provider->basedir = $base_text_dir; $text = $content_provider->get_wiki_text($title); $xml = $converter->article2xml($title, $text, $xmlg); if ($format == "xml") { # XML header('Content-type: text/xml; charset=utf-8'); print "<?xml version='1.0' encoding='UTF-8' ?>\n"; print $xml; } else { if ($format == "text") { # Plain text $xmlg['plaintext_markup'] = true; $xmlg['plaintext_prelink'] = true; $out = $converter->articles2text($xml, $xmlg); $out = str_replace("\n", "<br/>", $out); header('Content-type: text/html; charset=utf-8'); print $out; } else { # XHTML if (stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml")) { # Skipping the "strict" part ;-) header("Content-type: text/html; charset=utf-8"); # header("Content-type: application/xhtml+xml"); } else { # Header hack for IE header("Content-type: text/html; charset=utf-8"); } print $converter->articles2xhtml($xml, $xmlg); } }
$xmlg['add_gfdl'] = false; $xmlg['keep_interlanguage'] = true; $xmlg['keep_categories'] = true; $xmlg['xml_articles_header'] = "<articles>"; $xmlg['xhtml_justify'] = false; $xmlg['xhtml_logical_markup'] = false; $xmlg['xhtml_source'] = false; $cnt = 1; print "<table border=1 width='100%'><tr><th>Test</th><th>Result</th><th>wiki2xml</th><th>Input</th><th>XML</th></tr>"; foreach ($tests as $t) { $res = $t->result; $col = ''; $content_provider = new ContentProviderHTTP(); $converter = new MediaWikiConverter(); $xml = $converter->article2xml("", $t->input, $xmlg); $nr = $converter->articles2xhtml($xml, $xmlg); $nr = array_pop(explode('<body>', $nr, 2)); $nr = array_shift(explode('</body>', $nr, 2)); # Fixing things to compare to the stupid parser test formatting $res = trim($res); $res = str_replace("<li> ", "<li>", $res); $res = str_replace("<dd> ", "<dd>", $res); $res = str_replace("\n<", "<", $res); $res = str_replace("\n", " ", $res); $res = str_replace(" </p>", "</p>", $res); do { $o = $res; $res = str_replace(" ", " ", $res); } while ($o != $res); $nr = trim($nr); $nr = str_replace("<li> ", "<li>", $nr);