2 require_once dirname(__FILE__) . '/../wrgeo/wrgeo.body.php'; # for the function wrGeoGeoStringToGeo
4 function wrMapParserFirstCallInit() {
6 $wgParser->setHook('wrmap', 'wrmapParserHook');
11 /// Format inside <wrmap>...</wrmap> has to be like this:
14 /// Rodelbahn|47.143241 N 11.208959 E|Birgitzer Alm
18 /// The extension produces a format like this:
19 /// <googlemap version="0.9" lat="47.241016" lon="11.56517" zoom="11">
20 /// 47.241731, 11.358994, Birgitzer Alm
21 /// Die Birgitzer Alm ist nett
22 /// 47.17607, 11.542763, Naviser Hütte
25 function wrmapParserHook($input, $args, $parser) {
26 $debug = (isset($args['debug']));
29 $lines = explode("\n", $input);
31 $longitudes = array();
32 foreach ($lines as $line) {
35 if (strlen($l) == 0) continue;
36 $columns = explode('|', $line);
37 if (count($columns) != 3) throw new Exception(sprintf(utf8_encode('Die Anzahl der Spalten ist nicht 3 sondern %d'), count($columns)));
38 $columns = list($type, $geo, $name) = $columns;
39 list($latitude, $longitude) = wrGeoStringToGeo($geo);
40 $latitudes[] = $latitude;
41 $longitudes[] = $longitude;
42 $output .= sprintf("%F, %F, %s\n", $latitude, $longitude, htmlspecialchars($name));
43 } catch (Exception $e) {
44 return sprintf(utf8_encode('Ungültige Zeile in der Koordinatenliste: <em>%s</em>. %s'), htmlspecialchars($line), htmlspecialchars($e->getMessage()));
47 if (count($latitudes) == 0) return utf8_encode('Keine Koordinaten eingetragen');
48 $minLatitude = min($latitudes);
49 $centerLat = $minLatitude + (max($latitudes) - $minLatitude) / 2;
50 $minLongitude = min($longitudes);
51 $centerLon = $minLongitude + (max($longitudes) - $minLongitude) / 2;
53 // TODO: Varable zoom level
54 $output = '<googlemap version="0.9" lat="' . $centerLat . '" lon="' . $centerLon . '" type="terrain" zoom="9">'. "\n" . $output . "</googlemap>\n";
56 if ($debug) return $output = "<pre><nowiki>$output</nowiki></pre>";
59 global $wgTitle, $wgUser;
60 $parser = new Parser();
61 $parserOptions = new ParserOptions();
62 $parserOptions->initialiseFromUser($wgUser);
63 $result = $parser->parse($output, $wgTitle, $parserOptions); // TODO: Make this call less complicated
64 return $result->getText();
67 $output = $parser->recursiveTagParse($output); // TODO: Maybe this is already the solution?