<?php
-require_once dirname(__FILE__) . '/../wrgeo/wrgeo.body.php'; # for the function wrGeoGeoStringToGeo
-
-function wrMapParserFirstCallInit() {
- global $wgParser;
- $wgParser->setHook('wrmap', 'wrmapParserHook');
- return true;
-}
+class WrMap {
+ /// Renders the <wrgmap> tag
+ /// @param $content string - the content of the <wrgmap> tag
+ /// @param $args array - the array of attribute name/value pairs for the tag
+ /// @param $parser Parser - the MW Parser object for the current page
+ ///
+ /// @return string - the html for rendering the map
+ public static function render($content, $args, $parser, $frame) {
+ // Get center and zoom level from $args
+ if (isset($args['lat'])) $latitude = floatval($args['lat']); else $latitude = 47.267648; // latitude as float value
+ if (isset($args['lon'])) $longitude = floatval($args['lon']); else $longitude = 11.404655; // longitude as float value
+ if (isset($args['zoom'])) $zoom = intval($args['zoom']); else $zoom = 10; // Google Zoom Level
+ $latitude_s = sprintf('%.6F', $latitude);
+ $longitude_s = sprintf('%.6F', $longitude);
-/// Format inside <wrmap>...</wrmap> has to be like this:
-///
-/// <wrmap>
-/// Rodelbahn|47.143241 N 11.208959 E|Birgitzer Alm
-/// ...
-/// </wrmap>
-///
-/// The extension produces a format like this:
-/// <googlemap version="0.9" lat="47.241016" lon="11.56517" zoom="11">
-/// 47.241731, 11.358994, Birgitzer Alm
-/// Die Birgitzer Alm ist nett
-/// 47.17607, 11.542763, Naviser Hütte
-/// Die Naviser Hütte
-/// </googlemap>
-function wrmapParserHook($input, $args, $parser) {
- $output = '<googlemap version="0.9" lat="47.452237" lon="11.208801" type="terrain" zoom="9">'; // TODO: Varable coordinates
- $lines = explode("\n", $input);
- foreach ($lines as $line) {
- try {
- $l = trim($line);
- if (strlen($l) == 0) continue;
- $columns = explode('|', $line);
- if (count($columns) != 3) throw new Exception(sprintf(utf8_encode('Die Anzahl der Spalten ist nicht 3 sondern %d'), count($columns)));
- $columns = list($type, $geo, $name) = $columns;
- list($latitude, $longitude) = wrGeoStringToGeo($geo);
- $output .= sprintf("%F, %F, %s\n", $latitude, $longitude, htmlspecialchars($name));
- } catch (Exception $e) {
- return sprintf(utf8_encode('Ungültige Zeile in der Koordinatenliste: <em>%s</em>. %s'), htmlspecialchars($line), htmlspecialchars($e->getMessage()));
+ // Query database
+ $dbr = wfGetDB(DB_SLAVE);
+ $res = $dbr->select(array('wrsledruncache', 'wrreportcache'), array('wrsledruncache.page_title', 'position_latitude', 'position_longitude', 'date_report', '`condition`'), array('show_in_overview', 'not under_construction'), __METHOD__, array(), array('wrreportcache' => array('left outer join', 'wrsledruncache.page_id=wrreportcache.page_id')));
+ $sledruns = array();
+ while ($sledrun = $dbr->fetchRow($res)) $sledruns[] = $sledrun;
+ $dbr->freeResult($res);
+
+ $parserOutput = $parser->getOutput();
+ $parserOutput->addHeadItem('<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.8&sensor=false"></script>', 'googlemaps');
+ $parserOutput->addModules('ext.wrmap');
+
+ // Create <div/> element where the map is placed in
+ global $wgExtensionAssetsPath;
+ $output = "<div class=\"wrmap\" style=\"width: 100%; height: 450px; border-style:none;\" data-center-lon=\"$longitude_s\" data-center-lat=\"$latitude_s\" data-zoom=\"$zoom\" data-img-path=\"$wgExtensionAssetsPath/wrmap/openlayers/img/\">\n";
+ foreach ($sledruns as $sledrun) {
+ $lat = $sledrun['position_latitude'];
+ $lon = $sledrun['position_longitude'];
+ if (!$lat || !$lon) continue;
+ $title = Title::newFromText($sledrun['page_title']);
+ $title_text = htmlspecialchars($title->getText());
+ $title_url = htmlspecialchars($title->getLocalUrl());
+ $output .= "<p data-lon=\"$lon\" data-lat=\"$lat\" data-title=\"$title_text\" data-url=\"$title_url\" ";
+ if (!is_null($sledrun['date_report'])) $output .= "data-date_report=\"{$sledrun['date_report']}\" ";
+ if (!is_null($sledrun['condition'])) $output .= "data-condition=\"{$sledrun['condition']}\" ";
+ $output .= "/>\n";
}
+ $output .= "</div>\n";
+
+ return $output;
}
- $output = $output .= "</googlemap>\n";
- /*
- global $wgTitle, $wgUser;
- $parser = new Parser();
- $parserOptions = new ParserOptions();
- $parserOptions->initialiseFromUser($wgUser);
- $result = $parser->parse($output, $wgTitle, $parserOptions); // TODO: Make this call less complicated
- return $result->getText();
- */
- $result = $parser->recursiveTagParse($output); // TODO: Maybe this is already the solution?
- return $result;
+
}