Index: trunk/extensions/GoogleMaps/GoogleMaps.body.php |
— | — | @@ -178,17 +178,17 @@ |
179 | 179 | 'container':'toolbar', 'textbox':'wpTextbox1', 'toggle':'google_maps_toggle_link', |
180 | 180 | JAVASCRIPT; |
181 | 181 | |
182 | | - if ($o['icondir'] && is_dir($o['icondir'])) { |
183 | | - $labels = array(); |
184 | | - if ($dh = opendir($o['icondir'])) { |
185 | | - while (($file = readdir($dh)) !== false) { |
186 | | - if (substr($file, 0, 1) != "." && substr($file, -4) == ".png") { |
187 | | - $labels[] = substr($file, 0, -4); |
188 | | - } |
189 | | - } |
190 | | - } |
191 | | - $o['iconlabels'] = implode(",", $labels); |
192 | | - } |
| 182 | + if ($o['icondir'] && is_dir($o['icondir'])) { |
| 183 | + $labels = array(); |
| 184 | + if ($dh = opendir($o['icondir'])) { |
| 185 | + while (($file = readdir($dh)) !== false) { |
| 186 | + if (substr($file, 0, 1) != "." && substr($file, -4) == ".png") { |
| 187 | + $labels[] = substr($file, 0, -4); |
| 188 | + } |
| 189 | + } |
| 190 | + } |
| 191 | + $o['iconlabels'] = implode(",", $labels); |
| 192 | + } |
193 | 193 | // add all of the map settings to the editors_options JS variable |
194 | 194 | foreach( array_keys( $o ) as $key ) { |
195 | 195 | if( is_numeric( $o[$key] ) ) { |
— | — | @@ -200,7 +200,7 @@ |
201 | 201 | |
202 | 202 | // output the 'rtl' setting |
203 | 203 | $isRTLString = $this->mLanguage->isRTL() ? 'true' : 'false'; |
204 | | - $extensionVersion = GOOGLE_MAPS_EXTENSION_VERSION; |
| 204 | + $extensionVersion = GOOGLE_MAPS_EXTENSION_VERSION; |
205 | 205 | $output .= " 'rtl':{$isRTLString} };"; |
206 | 206 | |
207 | 207 | // output the base utility JS (addLoadEvent function, etc.) |
— | — | @@ -216,16 +216,16 @@ |
217 | 217 | $output .= <<<JAVASCRIPT |
218 | 218 | |
219 | 219 | function addScript(script) { |
220 | | - var js = document.createElement("script"); |
221 | | - js.setAttribute('src', script); |
222 | | - js.setAttribute('type', '{$this->mJsMimeType}'); |
223 | | - //document.getElementsByTagName("head")[0].appendChild(js); |
224 | | - document.body.appendChild(js); |
| 220 | + var js = document.createElement("script"); |
| 221 | + js.setAttribute('src', script); |
| 222 | + js.setAttribute('type', '{$this->mJsMimeType}'); |
| 223 | + //document.getElementsByTagName("head")[0].appendChild(js); |
| 224 | + document.body.appendChild(js); |
225 | 225 | } |
226 | 226 | |
227 | | - function loadGoogleMapsJavascript() { |
228 | | - addScript('http://maps.google.com/maps?file=api&v={$o['api']}&key={$this->mApiKey}&hl={$this->mLanguageCode}&async=2&callback=initEditorsMap'); |
229 | | - } |
| 227 | + function loadGoogleMapsJavascript() { |
| 228 | + addScript('http://maps.google.com/maps?file=api&v={$o['api']}&key={$this->mApiKey}&hl={$this->mLanguageCode}&async=2&callback=initEditorsMap'); |
| 229 | + } |
230 | 230 | function loadEditorsMapJavascript() { |
231 | 231 | addScript('{$this->mUrlPath}/color_select.js'); |
232 | 232 | addScript('{$this->mUrlPath}/EditorsMap.js?v={$extensionVersion}'); |
— | — | @@ -234,24 +234,24 @@ |
235 | 235 | } |
236 | 236 | |
237 | 237 | function tryLoadingEditorsMap() { |
238 | | - if (typeof(EditorsMap) != "undefined") { |
239 | | - loadGoogleMapsJavascript(); |
240 | | - } else { |
241 | | - window.setTimeout(tryLoadingEditorsMap, 100); |
242 | | - } |
| 238 | + if (typeof(EditorsMap) != "undefined") { |
| 239 | + loadGoogleMapsJavascript(); |
| 240 | + } else { |
| 241 | + window.setTimeout(tryLoadingEditorsMap, 100); |
| 242 | + } |
243 | 243 | } |
244 | 244 | |
245 | | - function initEditorsMap() { |
246 | | - GME_SMALL_ICON = new GIcon(); |
247 | | - GME_SMALL_ICON.image = "http://labs.google.com/ridefinder/images/mm_20_yellow.png"; |
248 | | - GME_SMALL_ICON.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; |
249 | | - GME_SMALL_ICON.iconSize = new GSize(12, 20); |
250 | | - GME_SMALL_ICON.shadowSize = new GSize(22, 20); |
251 | | - GME_SMALL_ICON.iconAnchor = new GPoint(6, 20); |
252 | | - GME_SMALL_ICON.infoWindowAnchor = new GPoint(5, 1); |
| 245 | + function initEditorsMap() { |
| 246 | + GME_SMALL_ICON = new GIcon(); |
| 247 | + GME_SMALL_ICON.image = "http://labs.google.com/ridefinder/images/mm_20_yellow.png"; |
| 248 | + GME_SMALL_ICON.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; |
| 249 | + GME_SMALL_ICON.iconSize = new GSize(12, 20); |
| 250 | + GME_SMALL_ICON.shadowSize = new GSize(22, 20); |
| 251 | + GME_SMALL_ICON.iconAnchor = new GPoint(6, 20); |
| 252 | + GME_SMALL_ICON.infoWindowAnchor = new GPoint(5, 1); |
253 | 253 | |
254 | | - emap = new EditorsMap(editors_options); |
255 | | - } |
| 254 | + emap = new EditorsMap(editors_options); |
| 255 | + } |
256 | 256 | |
257 | 257 | function insertGoogleMapLinks() { |
258 | 258 | var image = document.createElement("img"); |
— | — | @@ -264,7 +264,7 @@ |
265 | 265 | image.style.cursor = "pointer"; |
266 | 266 | image.onclick = function() { |
267 | 267 | if( typeof(EditorsMap) == "undefined" ) { |
268 | | - loadEditorsMapJavascript(); |
| 268 | + loadEditorsMapJavascript(); |
269 | 269 | } else { |
270 | 270 | emap.toggleGoogleMap(); |
271 | 271 | } |
— | — | @@ -360,7 +360,7 @@ |
361 | 361 | global $wgGoogleMaps; |
362 | 362 | // pass through to the main render function, creating a new parser |
363 | 363 | // for parsing the local content |
364 | | - return $wgGoogleMaps->render( $pContent, $pArgv, $pParser, new Parser() ); |
| 364 | + return $wgGoogleMaps->render( $pContent, $pArgv, $pParser, new Parser() ); |
365 | 365 | } |
366 | 366 | |
367 | 367 | /** |
— | — | @@ -375,41 +375,41 @@ |
376 | 376 | * @return string - the html for rendering the map |
377 | 377 | **/ |
378 | 378 | function render ( $pContent, $pArgv, &$pParser, &$pLocalParser ) { |
379 | | - $pLocalParser->mTitle = $this->mTitle; |
380 | | - $pLocalParser->mOptions = $pParser->mOptions; |
| 379 | + $pLocalParser->mTitle = $this->mTitle; |
| 380 | + $pLocalParser->mOptions = $pParser->mOptions; |
381 | 381 | |
382 | | - // Keep a count of how many <googlemap> tags were used for unique ids |
383 | | - if( !isset( $this->mGoogleMapsOnThisPage ) ) { |
384 | | - $this->mGoogleMapsOnThisPage = 1; |
385 | | - } else { |
386 | | - $this->mGoogleMapsOnThisPage++; |
387 | | - } |
| 382 | + // Keep a count of how many <googlemap> tags were used for unique ids |
| 383 | + if( !isset( $this->mGoogleMapsOnThisPage ) ) { |
| 384 | + $this->mGoogleMapsOnThisPage = 1; |
| 385 | + } else { |
| 386 | + $this->mGoogleMapsOnThisPage++; |
| 387 | + } |
388 | 388 | |
389 | | - if( $this->mProcessTemplateVariables ) { // experimental, see MW bug #2257 |
390 | | - foreach( array_keys( $pArgv ) as $key ) { |
391 | | - $pArgv[$key] = $pParser->replaceTemplateVariables( $pArgv[$key] ); |
392 | | - } |
393 | | - $pContent = $pParser->replaceTemplateVariables( $pContent ); |
394 | | - } |
| 389 | + if( $this->mProcessTemplateVariables ) { // experimental, see MW bug #2257 |
| 390 | + foreach( array_keys( $pArgv ) as $key ) { |
| 391 | + $pArgv[$key] = $pParser->replaceTemplateVariables( $pArgv[$key] ); |
| 392 | + } |
| 393 | + $pContent = $pParser->replaceTemplateVariables( $pContent ); |
| 394 | + } |
395 | 395 | |
396 | | - // a dictionary for validating and interpreting some options. |
397 | | - $o = self::getMapSettings( $this->mTitle, $this->mMapDefaults ); |
398 | | - $o = $this->getThisMapSettings( $o, $pArgv ); |
| 396 | + // a dictionary for validating and interpreting some options. |
| 397 | + $o = self::getMapSettings( $this->mTitle, $this->mMapDefaults ); |
| 398 | + $o = $this->getThisMapSettings( $o, $pArgv ); |
399 | 399 | |
400 | | - $o = array_merge($o, array('number_of_maps' => $this->mGoogleMapsOnThisPage, |
401 | | - 'incompatible_message' => $this->translateMessage( 'gm-incompatible-browser' ), |
402 | | - 'incompatible_message_link' => $this->translateMessage( 'gm-incompatible-browser-link' ))); |
403 | | - $img_exporter = new GoogleMapsImgExporter($this->mApiKey, $this->mLanguageCode); |
404 | | - $img_exporter->addHeader($o); |
405 | | - self::renderContent($pContent, $pParser, $pLocalParser, $img_exporter, $o); |
406 | | - $img_exporter->addTrailer(); |
| 400 | + $o = array_merge($o, array('number_of_maps' => $this->mGoogleMapsOnThisPage, |
| 401 | + 'incompatible_message' => $this->translateMessage( 'gm-incompatible-browser' ), |
| 402 | + 'incompatible_message_link' => $this->translateMessage( 'gm-incompatible-browser-link' ))); |
| 403 | + $img_exporter = new GoogleMapsImgExporter($this->mApiKey, $this->mLanguageCode); |
| 404 | + $img_exporter->addHeader($o); |
| 405 | + self::renderContent($pContent, $pParser, $pLocalParser, $img_exporter, $o); |
| 406 | + $img_exporter->addTrailer(); |
407 | 407 | |
408 | | - $js_exporter = new GoogleMapsJsExporter($this->mLanguage, $this->mProxyKey, $this->mEnablePaths); |
409 | | - $js_exporter->addHeader($o, $img_exporter->render()); |
410 | | - self::renderContent($pContent, $pParser, $pLocalParser, $js_exporter, $o); |
411 | | - $js_exporter->addTrailer($o); |
412 | | - return $js_exporter->render(); |
413 | | - } |
| 408 | + $js_exporter = new GoogleMapsJsExporter($this->mLanguage, $this->mProxyKey, $this->mEnablePaths); |
| 409 | + $js_exporter->addHeader($o, $img_exporter->render()); |
| 410 | + self::renderContent($pContent, $pParser, $pLocalParser, $js_exporter, $o); |
| 411 | + $js_exporter->addTrailer($o); |
| 412 | + return $js_exporter->render(); |
| 413 | + } |
414 | 414 | |
415 | 415 | function renderKmlLink($pContent, $pArgv) { |
416 | 416 | global $wgTitle; |
— | — | @@ -420,175 +420,175 @@ |
421 | 421 | } |
422 | 422 | |
423 | 423 | static function renderContent($pContent, &$pParser, &$pLocalParser, &$exporter, $o) { |
424 | | - $lines = preg_split( "/[\r\n]/", $pContent ); |
425 | | - $tabs = array( ); // the tabs for the current marker |
426 | | - $polyline = array( ); // points in a polyline |
427 | | - $icons = array( ); // keeps track of which icons we've made in the JS |
428 | | - $lineColor = null; |
429 | | - $lineOpacity = null; |
430 | | - $fillColor = null; |
431 | | - $fillOpacity = null; |
432 | | - $state = GOOGLE_MAPS_PARSE_INCLUDES; |
| 424 | + $lines = preg_split( "/[\r\n]/", $pContent ); |
| 425 | + $tabs = array( ); // the tabs for the current marker |
| 426 | + $polyline = array( ); // points in a polyline |
| 427 | + $icons = array( ); // keeps track of which icons we've made in the JS |
| 428 | + $lineColor = null; |
| 429 | + $lineOpacity = null; |
| 430 | + $fillColor = null; |
| 431 | + $fillOpacity = null; |
| 432 | + $state = GOOGLE_MAPS_PARSE_INCLUDES; |
433 | 433 | |
434 | | - $icon = null; |
435 | | - $lat = null; |
436 | | - $lon = null; |
437 | | - $caption = ''; |
438 | | - $title = null; |
439 | | - $stroke = null; |
440 | | - $syntax = $o['version']; |
| 434 | + $icon = null; |
| 435 | + $lat = null; |
| 436 | + $lon = null; |
| 437 | + $caption = ''; |
| 438 | + $title = null; |
| 439 | + $stroke = null; |
| 440 | + $syntax = $o['version']; |
441 | 441 | |
442 | | - // The meat of the extension. Translate the content of the tag |
443 | | - // into JS that produces a set of points, lines, and markers |
444 | | - foreach( $lines as $line ) { |
445 | | - // if the line is a hex code, it's the start of a path |
446 | | - if( preg_match( "/^(\d+)?#([0-9a-fA-F]{2})?([0-9a-fA-F]{6})(?: \(#([0-9a-fA-F]{2})?([0-9a-fA-F]{6})\))?$/", $line, $matches ) ) { |
| 442 | + // The meat of the extension. Translate the content of the tag |
| 443 | + // into JS that produces a set of points, lines, and markers |
| 444 | + foreach( $lines as $line ) { |
| 445 | + // if the line is a hex code, it's the start of a path |
| 446 | + if( preg_match( "/^(\d+)?#([0-9a-fA-F]{2})?([0-9a-fA-F]{6})(?: \(#([0-9a-fA-F]{2})?([0-9a-fA-F]{6})\))?$/", $line, $matches ) ) { |
447 | 447 | |
448 | | - // if the color is already set, we were just rendering a path so finish it and start |
449 | | - // a new one |
450 | | - if( isset( $lineColor ) ) { |
451 | | - $exporter->addPolyline( $polyline, $lineColor, $lineOpacity, $stroke, $fillColor, $fillOpacity ); |
452 | | - $polyline = array( ); |
453 | | - } |
| 448 | + // if the color is already set, we were just rendering a path so finish it and start |
| 449 | + // a new one |
| 450 | + if( isset( $lineColor ) ) { |
| 451 | + $exporter->addPolyline( $polyline, $lineColor, $lineOpacity, $stroke, $fillColor, $fillOpacity ); |
| 452 | + $polyline = array( ); |
| 453 | + } |
454 | 454 | |
455 | | - if( $state == GOOGLE_MAPS_PARSE_ADD_MARKER ) { |
456 | | - self::addMarker($exporter, $pParser, $pLocalParser, $lat, $lon, |
457 | | - $icon, $title, $tabs, $caption, isset($lineColor)); |
| 455 | + if( $state == GOOGLE_MAPS_PARSE_ADD_MARKER ) { |
| 456 | + self::addMarker($exporter, $pParser, $pLocalParser, $lat, $lon, |
| 457 | + $icon, $title, $tabs, $caption, isset($lineColor)); |
458 | 458 | |
459 | | - $tabs = array( ); |
460 | | - $caption = ''; |
461 | | - $title = null; |
462 | | - } |
| 459 | + $tabs = array( ); |
| 460 | + $caption = ''; |
| 461 | + $title = null; |
| 462 | + } |
463 | 463 | |
464 | | - $state = GOOGLE_MAPS_PARSE_POINTS; |
| 464 | + $state = GOOGLE_MAPS_PARSE_POINTS; |
465 | 465 | |
466 | | - $stroke = isset($matches[1]) && $matches[1] ? $matches[1] : $o['stroke']; |
467 | | - $lineOpacity = isset($matches[2]) && $matches[2] ? $matches[2] : "ff"; |
468 | | - $lineColor = isset($matches[3]) && $matches[3] ? $matches[3] : null; |
469 | | - $fillOpacity = isset($matches[4]) && $matches[4] ? $matches[4] : "ff"; |
470 | | - $fillColor = isset($matches[5]) && $matches[5] ? $matches[5] : null; |
471 | | - } |
| 466 | + $stroke = isset($matches[1]) && $matches[1] ? $matches[1] : $o['stroke']; |
| 467 | + $lineOpacity = isset($matches[2]) && $matches[2] ? $matches[2] : "ff"; |
| 468 | + $lineColor = isset($matches[3]) && $matches[3] ? $matches[3] : null; |
| 469 | + $fillOpacity = isset($matches[4]) && $matches[4] ? $matches[4] : "ff"; |
| 470 | + $fillColor = isset($matches[5]) && $matches[5] ? $matches[5] : null; |
| 471 | + } |
472 | 472 | |
473 | | - // if the line matches the tab format, add the tabs |
474 | | - elseif( $syntax == "0" && preg_match( '/^\/([^\\\\]+)\\\\ *(.*)$/', $line, $matches ) ) { |
475 | | - $parsed = self::parseWikiText($pParser, $pLocalParser, $matches[2], $pParser->mTitle, $pParser->mOptions); |
476 | | - $tabs[] = array( 'title' => $matches[1], 'gm-caption' => $parsed); |
477 | | - $state = GOOGLE_MAPS_PARSE_ADD_MARKER; |
478 | | - } |
479 | | - elseif ($syntax != "0" && preg_match( '/^\/([^\\\\]+)\\\\ *$/', $line, $matches ) ) { |
480 | | - if (count($tabs)) { |
481 | | - $parsed = self::parseWikiText($pParser, $pLocalParser, $caption, $pParser->mTitle, $pParser->mOptions); |
482 | | - $tabs[count($tabs)-1]['gm-caption'] = $parsed; |
483 | | - $caption = ''; |
484 | | - } |
485 | | - $tabs[] = array( 'title' => $matches[1] ); |
486 | | - } |
487 | | - elseif( $state == GOOGLE_MAPS_PARSE_INCLUDES && preg_match( "/^http:\/\//", $line ) ) { |
488 | | - $exporter->addXmlSource($line); |
489 | | - } |
490 | | - // the line is a regular point |
491 | | - elseif( preg_match( "/^(?:\(([.a-zA-Z0-9_-]*?)\))? *([0-9.-]+), *([0-9.-]+)(?:, ?(.+))?/", $line, $matches ) ) { |
492 | | - // first create the previous marker, now that we have all the tab/caption info |
493 | | - if( $state == GOOGLE_MAPS_PARSE_ADD_MARKER ) { |
494 | | - self::addMarker($exporter, $pParser, $pLocalParser, $lat, $lon, |
495 | | - $icon, $title, $tabs, $caption, isset($lineColor)); |
| 473 | + // if the line matches the tab format, add the tabs |
| 474 | + elseif( $syntax == "0" && preg_match( '/^\/([^\\\\]+)\\\\ *(.*)$/', $line, $matches ) ) { |
| 475 | + $parsed = self::parseWikiText($pParser, $pLocalParser, $matches[2], $pParser->mTitle, $pParser->mOptions); |
| 476 | + $tabs[] = array( 'title' => $matches[1], 'gm-caption' => $parsed); |
| 477 | + $state = GOOGLE_MAPS_PARSE_ADD_MARKER; |
| 478 | + } |
| 479 | + elseif ($syntax != "0" && preg_match( '/^\/([^\\\\]+)\\\\ *$/', $line, $matches ) ) { |
| 480 | + if (count($tabs)) { |
| 481 | + $parsed = self::parseWikiText($pParser, $pLocalParser, $caption, $pParser->mTitle, $pParser->mOptions); |
| 482 | + $tabs[count($tabs)-1]['gm-caption'] = $parsed; |
| 483 | + $caption = ''; |
| 484 | + } |
| 485 | + $tabs[] = array( 'title' => $matches[1] ); |
| 486 | + } |
| 487 | + elseif( $state == GOOGLE_MAPS_PARSE_INCLUDES && preg_match( "/^http:\/\//", $line ) ) { |
| 488 | + $exporter->addXmlSource($line); |
| 489 | + } |
| 490 | + // the line is a regular point |
| 491 | + elseif( preg_match( "/^(?:\(([.a-zA-Z0-9_-]*?)\))? *([0-9.-]+), *([0-9.-]+)(?:, ?(.+))?/", $line, $matches ) ) { |
| 492 | + // first create the previous marker, now that we have all the tab/caption info |
| 493 | + if( $state == GOOGLE_MAPS_PARSE_ADD_MARKER ) { |
| 494 | + self::addMarker($exporter, $pParser, $pLocalParser, $lat, $lon, |
| 495 | + $icon, $title, $tabs, $caption, isset($lineColor)); |
496 | 496 | |
497 | | - $tabs = array( ); |
498 | | - $caption = ''; |
499 | | - $title = null; |
500 | | - } |
| 497 | + $tabs = array( ); |
| 498 | + $caption = ''; |
| 499 | + $title = null; |
| 500 | + } |
501 | 501 | |
502 | | - $state = GOOGLE_MAPS_PARSE_POINTS; |
| 502 | + $state = GOOGLE_MAPS_PARSE_POINTS; |
503 | 503 | |
504 | | - // extract the individual fields from the regex match |
505 | | - $icon = isset( $matches[1] ) ? $matches[1] : null; |
506 | | - $lat = isset( $matches[2] ) ? $matches[2] : null; |
507 | | - $lon = isset( $matches[3] ) ? $matches[3] : null; |
508 | | - if ($syntax == "0") { |
509 | | - $caption = isset( $matches[4] ) ? $matches[4] : ''; |
510 | | - } else { |
511 | | - $title = isset( $matches[4] ) ? $matches[4] : null; |
512 | | - } |
| 504 | + // extract the individual fields from the regex match |
| 505 | + $icon = isset( $matches[1] ) ? $matches[1] : null; |
| 506 | + $lat = isset( $matches[2] ) ? $matches[2] : null; |
| 507 | + $lon = isset( $matches[3] ) ? $matches[3] : null; |
| 508 | + if ($syntax == "0") { |
| 509 | + $caption = isset( $matches[4] ) ? $matches[4] : ''; |
| 510 | + } else { |
| 511 | + $title = isset( $matches[4] ) ? $matches[4] : null; |
| 512 | + } |
513 | 513 | |
514 | | - // need to create this icon, since we haven't already |
515 | | - if( $icon && !isset($icons[$icon]) ) { |
516 | | - $exporter->addIcon($icon, $o); |
517 | | - $icons[$icon] = true; |
518 | | - } |
| 514 | + // need to create this icon, since we haven't already |
| 515 | + if( $icon && !isset($icons[$icon]) ) { |
| 516 | + $exporter->addIcon($icon, $o); |
| 517 | + $icons[$icon] = true; |
| 518 | + } |
519 | 519 | |
520 | | - // if we have numeric latitude and longitude, process the point |
521 | | - if( is_numeric( $lat ) && is_numeric( $lon ) ) { |
| 520 | + // if we have numeric latitude and longitude, process the point |
| 521 | + if( is_numeric( $lat ) && is_numeric( $lon ) ) { |
522 | 522 | |
523 | | - // if it has an icon override, a caption, or is not in a path, add the marker |
524 | | - if ( $icon || count($tabs) > 0 || $caption || $title || !isset( $lineColor ) ) { |
525 | | - $state = GOOGLE_MAPS_PARSE_ADD_MARKER; |
526 | | - } |
| 523 | + // if it has an icon override, a caption, or is not in a path, add the marker |
| 524 | + if ( $icon || count($tabs) > 0 || $caption || $title || !isset( $lineColor ) ) { |
| 525 | + $state = GOOGLE_MAPS_PARSE_ADD_MARKER; |
| 526 | + } |
527 | 527 | |
528 | | - // If we're making a path, record the location and move on. |
529 | | - if( isset( $lineColor ) ) { |
530 | | - $polyline[] = array( 'lat' => $lat, 'lon' => $lon ); |
531 | | - } |
532 | | - } |
533 | | - } |
| 528 | + // If we're making a path, record the location and move on. |
| 529 | + if( isset( $lineColor ) ) { |
| 530 | + $polyline[] = array( 'lat' => $lat, 'lon' => $lon ); |
| 531 | + } |
| 532 | + } |
| 533 | + } |
534 | 534 | |
535 | | - elseif (($state == GOOGLE_MAPS_PARSE_POINTS || $state == GOOGLE_MAPS_PARSE_ADD_MARKER) && $syntax != "0") { // a caption line |
536 | | - if ($line != '') { |
537 | | - $caption .= $line . "\r\n"; |
538 | | - $state = GOOGLE_MAPS_PARSE_ADD_MARKER; |
539 | | - } |
540 | | - } |
541 | | - } |
| 535 | + elseif (($state == GOOGLE_MAPS_PARSE_POINTS || $state == GOOGLE_MAPS_PARSE_ADD_MARKER) && $syntax != "0") { // a caption line |
| 536 | + if ($line != '') { |
| 537 | + $caption .= $line . "\r\n"; |
| 538 | + $state = GOOGLE_MAPS_PARSE_ADD_MARKER; |
| 539 | + } |
| 540 | + } |
| 541 | + } |
542 | 542 | |
543 | | - // if the last iteration was to add a marker, add it |
544 | | - if( $state == GOOGLE_MAPS_PARSE_ADD_MARKER ) { |
545 | | - self::addMarker($exporter, $pParser, $pLocalParser, $lat, $lon, $icon, |
546 | | - $title, $tabs, $caption, isset($lineColor)); |
547 | | - } |
| 543 | + // if the last iteration was to add a marker, add it |
| 544 | + if( $state == GOOGLE_MAPS_PARSE_ADD_MARKER ) { |
| 545 | + self::addMarker($exporter, $pParser, $pLocalParser, $lat, $lon, $icon, |
| 546 | + $title, $tabs, $caption, isset($lineColor)); |
| 547 | + } |
548 | 548 | |
549 | | - // if the last iteration was to add a polyline, add it |
550 | | - if( isset( $lineColor ) ) { |
551 | | - $exporter->addPolyline( $polyline, $lineColor, $lineOpacity, $stroke, $fillColor, $fillOpacity ); |
552 | | - } |
553 | | - } |
| 549 | + // if the last iteration was to add a polyline, add it |
| 550 | + if( isset( $lineColor ) ) { |
| 551 | + $exporter->addPolyline( $polyline, $lineColor, $lineOpacity, $stroke, $fillColor, $fillOpacity ); |
| 552 | + } |
| 553 | + } |
554 | 554 | |
555 | | - static function addMarker(&$pExporter, &$pParser, &$pLocalParser, $pLat, $pLon, |
556 | | - $pIcon, $pTitle, $pTabs, $pCaption, $pLineColorSet) { |
557 | | - global $wgUser; |
558 | | - $parsed = self::parseWikiText($pParser, $pLocalParser, preg_replace('/\r\n/', '<br />', $pCaption), $pParser->mTitle, $pParser->mOptions); |
559 | | - $title = Title::newFromText($pTitle); |
| 555 | + static function addMarker(&$pExporter, &$pParser, &$pLocalParser, $pLat, $pLon, |
| 556 | + $pIcon, $pTitle, $pTabs, $pCaption, $pLineColorSet) { |
| 557 | + global $wgUser; |
| 558 | + $parsed = self::parseWikiText($pParser, $pLocalParser, preg_replace('/\r\n/', '<br />', $pCaption), $pParser->mTitle, $pParser->mOptions); |
| 559 | + $title = Title::newFromText($pTitle); |
560 | 560 | |
561 | | - // GoogleMaps extension allows user to provide title of the page to be included as |
562 | | - // a marker description. This check here is to prevent recursive parsing if the provided title |
563 | | - // is the same as the current page. |
564 | | - if ($title instanceof Title && $pLocalParser->mTitle instanceof Title) { |
565 | | - if ($title->equals($pLocalParser->getTitle())) { |
566 | | - $title = null; |
567 | | - } |
568 | | - } |
| 561 | + // GoogleMaps extension allows user to provide title of the page to be included as |
| 562 | + // a marker description. This check here is to prevent recursive parsing if the provided title |
| 563 | + // is the same as the current page. |
| 564 | + if ($title instanceof Title && $pLocalParser->mTitle instanceof Title) { |
| 565 | + if ($title->equals($pLocalParser->getTitle())) { |
| 566 | + $title = null; |
| 567 | + } |
| 568 | + } |
569 | 569 | |
570 | | - $revision = is_null($title) ? null : |
571 | | - Revision::newFromTitle($title); |
572 | | - $parsedArticleText = is_null($revision) ? null : |
573 | | - self::parseWikiText($pParser, $pLocalParser, $revision->getText(), $revision->getTitle(), $pParser->mOptions); |
574 | | - $titleMaybeNonexistent = is_null($title) ? Title::makeTitleSafe(NS_MAIN, $pTitle) : $title; |
575 | | - $skin = $wgUser->getSkin(); |
576 | | - $titleLink = is_null($titleMaybeNonexistent) ? '' : $skin->makeLinkObj($titleMaybeNonexistent); |
577 | | - if (count($pTabs)) { |
578 | | - $pTabs[count($pTabs)-1]['gm-caption'] = $parsed; |
579 | | - $pExporter->addMarker( $pLat, $pLon, $pIcon, $pTitle, $titleLink, |
580 | | - $pTabs, $parsedArticleText, $pLineColorSet ); |
581 | | - } else { |
582 | | - $pExporter->addMarker( $pLat, $pLon, $pIcon, $pTitle, $titleLink, |
583 | | - $parsed, $parsedArticleText, $pLineColorSet); |
584 | | - } |
585 | | - } |
| 570 | + $revision = is_null($title) ? null : |
| 571 | + Revision::newFromTitle($title); |
| 572 | + $parsedArticleText = is_null($revision) ? null : |
| 573 | + self::parseWikiText($pParser, $pLocalParser, $revision->getText(), $revision->getTitle(), $pParser->mOptions); |
| 574 | + $titleMaybeNonexistent = is_null($title) ? Title::makeTitleSafe(NS_MAIN, $pTitle) : $title; |
| 575 | + $skin = $wgUser->getSkin(); |
| 576 | + $titleLink = is_null($titleMaybeNonexistent) ? '' : $skin->makeLinkObj($titleMaybeNonexistent); |
| 577 | + if (count($pTabs)) { |
| 578 | + $pTabs[count($pTabs)-1]['gm-caption'] = $parsed; |
| 579 | + $pExporter->addMarker( $pLat, $pLon, $pIcon, $pTitle, $titleLink, |
| 580 | + $pTabs, $parsedArticleText, $pLineColorSet ); |
| 581 | + } else { |
| 582 | + $pExporter->addMarker( $pLat, $pLon, $pIcon, $pTitle, $titleLink, |
| 583 | + $parsed, $parsedArticleText, $pLineColorSet); |
| 584 | + } |
| 585 | + } |
586 | 586 | |
587 | | - static function parseWikiText(&$pParser, &$pLocalParser, $pText, $pTitle, &$pOptions) { |
588 | | - // recursiveTagParse seems broken, so do it the old-fashioned way. |
589 | | - $parsed = $pLocalParser->parse( $pText, $pTitle, $pOptions, false ); |
590 | | - $html = $parsed->getText(); |
591 | | - return preg_replace('/<script.*?<\/script>/', '', $html); |
592 | | - } |
| 587 | + static function parseWikiText(&$pParser, &$pLocalParser, $pText, $pTitle, &$pOptions) { |
| 588 | + // recursiveTagParse seems broken, so do it the old-fashioned way. |
| 589 | + $parsed = $pLocalParser->parse( $pText, $pTitle, $pOptions, false ); |
| 590 | + $html = $parsed->getText(); |
| 591 | + return preg_replace('/<script.*?<\/script>/', '', $html); |
| 592 | + } |
593 | 593 | |
594 | 594 | //---------------------------------------------- |
595 | 595 | // UTILITIES |
— | — | @@ -608,9 +608,9 @@ |
609 | 609 | 'normal', |
610 | 610 | 'hybrid', |
611 | 611 | 'terrain', |
612 | | - 'satellite', |
613 | | - 'elevation', |
614 | | - 'infrared' |
| 612 | + 'satellite', |
| 613 | + 'elevation', |
| 614 | + 'infrared' |
615 | 615 | ), |
616 | 616 | 'controls' => array( |
617 | 617 | 'small', |
— | — | @@ -635,11 +635,11 @@ |
636 | 636 | 'smooth', |
637 | 637 | 'fast' |
638 | 638 | ), |
639 | | - 'world' => array( |
640 | | - 'earth', |
641 | | - 'moon', |
642 | | - 'mars' |
643 | | - ), |
| 639 | + 'world' => array( |
| 640 | + 'earth', |
| 641 | + 'moon', |
| 642 | + 'mars' |
| 643 | + ), |
644 | 644 | 'scrollwheel' => array( |
645 | 645 | 'zoom', |
646 | 646 | 'nothing' |
— | — | @@ -700,25 +700,25 @@ |
701 | 701 | 'height' => 400, |
702 | 702 | 'icon' => 'http://www.google.com/mapfiles/marker.png', |
703 | 703 | 'icons' => 'http://maps.google.com/mapfiles/marker{label}.png', |
704 | | - 'iconlabels' => 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z', |
705 | | - 'icondir' => false, |
| 704 | + 'iconlabels' => 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z', |
| 705 | + 'icondir' => false, |
706 | 706 | 'shadow' => 'http://maps.google.com/intl/en_us/mapfiles/shadow50.png', |
707 | | - 'shadowsize' => '37x34', |
708 | | - 'windowanchor'=> '9x2', |
709 | | - 'iconsize' => '20x34', |
710 | | - 'iconanchor' => '9x34', |
| 707 | + 'shadowsize' => '37x34', |
| 708 | + 'windowanchor'=> '9x2', |
| 709 | + 'iconsize' => '20x34', |
| 710 | + 'iconanchor' => '9x34', |
711 | 711 | 'lat' => 42.711618, |
712 | 712 | 'localsearch' => true, |
713 | 713 | 'lon' => -73.205112, |
714 | 714 | 'opacity' => 0.7, |
715 | 715 | 'overview' => 'no', |
716 | | - 'world' => 'earth', |
| 716 | + 'world' => 'earth', |
717 | 717 | 'precision' => 6, |
718 | 718 | 'scale' => 'no', |
719 | 719 | 'scrollwheel' => 'nothing', |
720 | 720 | 'selector' => 'yes', |
721 | 721 | 'stroke' => 6, |
722 | | - 'style' => '', |
| 722 | + 'style' => '', |
723 | 723 | 'type' => 'hybrid', |
724 | 724 | 'units' => 'kilometers', |
725 | 725 | 'version' => 0, |
— | — | @@ -758,19 +758,19 @@ |
759 | 759 | return $o; |
760 | 760 | } |
761 | 761 | |
762 | | - function getThisMapSettings($o, $pArgv) { |
763 | | - // Override the defaults with what the user specified. |
764 | | - foreach( array_keys( $o ) as $key ) { |
765 | | - if( is_numeric( $o[$key] ) && isset( $pArgv[$key] ) && is_numeric( $pArgv[$key] ) ) { |
766 | | - $o[$key] = $pArgv[$key]; |
767 | | - } elseif( isset($pArgv[$key] ) && self::isOptionLegal( $key, $pArgv[$key] ) ) { |
768 | | - $o[$key] = $this->translateOption( $key, $pArgv[$key] ); |
769 | | - } else { // and translate |
770 | | - $o[$key] = $this->translateOption( $key, $o[$key] ); |
771 | | - } |
772 | | - } |
773 | | - return $o; |
774 | | - } |
| 762 | + function getThisMapSettings($o, $pArgv) { |
| 763 | + // Override the defaults with what the user specified. |
| 764 | + foreach( array_keys( $o ) as $key ) { |
| 765 | + if( is_numeric( $o[$key] ) && isset( $pArgv[$key] ) && is_numeric( $pArgv[$key] ) ) { |
| 766 | + $o[$key] = $pArgv[$key]; |
| 767 | + } elseif( isset($pArgv[$key] ) && self::isOptionLegal( $key, $pArgv[$key] ) ) { |
| 768 | + $o[$key] = $this->translateOption( $key, $pArgv[$key] ); |
| 769 | + } else { // and translate |
| 770 | + $o[$key] = $this->translateOption( $key, $o[$key] ); |
| 771 | + } |
| 772 | + } |
| 773 | + return $o; |
| 774 | + } |
775 | 775 | |
776 | 776 | |
777 | 777 | /** |
Index: trunk/extensions/GoogleMaps/GoogleMaps.i18n.php |
— | — | @@ -7071,4 +7071,3 @@ |
7072 | 7072 | 'gm-moon' => '月亮', |
7073 | 7073 | 'gm-mars' => '火星', |
7074 | 7074 | ); |
7075 | | - |
Index: trunk/extensions/GoogleMaps/export/GoogleMapsKmlExporter.php |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | $this->mOutput .= '<description><![CDATA['. |
86 | 86 | GoogleMaps::fixBlockDirection(GoogleMaps::fixTidy($pCaption), $this->mLanguage->isRTL()). |
87 | 87 | ']]></description>'; |
88 | | - } elseif (is_array($pCaption)) { // TODO tabs and max content |
| 88 | + } elseif (is_array($pCaption)) { // TODO tabs and max content |
89 | 89 | } |
90 | 90 | $this->mOutput .= "</Placemark>\n"; |
91 | 91 | } |
Index: trunk/extensions/GoogleMaps/export/GoogleMapsImgExporter.php |
— | — | @@ -1,53 +1,53 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class GoogleMapsImgExporter extends GoogleMapsExporter { |
5 | | - var $mApiKey; |
6 | | - var $mLanguageCode; |
| 5 | + var $mApiKey; |
| 6 | + var $mLanguageCode; |
7 | 7 | |
8 | | - function __construct($pApiKey, $pLanguageCode) { |
9 | | - $this->mApiKey = $pApiKey; |
10 | | - $this->mLanguageCode = $pLanguageCode; |
11 | | - } |
| 8 | + function __construct($pApiKey, $pLanguageCode) { |
| 9 | + $this->mApiKey = $pApiKey; |
| 10 | + $this->mLanguageCode = $pLanguageCode; |
| 11 | + } |
12 | 12 | |
13 | | - function addHeader($o) { |
14 | | - $width = $o['width'] > 640 ? 640 : $o['width']; |
15 | | - $height = $o['height'] > 640 ? 640 : $o['height']; |
16 | | - $this->mOutput .= '<img '; |
17 | | - $this->mOutput .= "alt=\"Map\" "; |
18 | | - $this->mOutput .= "height=\"{$height}\" width=\"{$width}\" "; |
19 | | - $this->mOutput .= 'src="http://maps.google.com/maps/api/staticmap'; |
20 | | - $this->mOutput .= "?center={$o['lat']}%2C{$o['lon']}"; |
21 | | - $this->mOutput .= "&zoom={$o['zoom']}"; |
22 | | - $this->mOutput .= "&size={$width}x{$height}"; |
23 | | - $this->mOutput .= "&key={$this->mApiKey}"; |
24 | | - $this->mOutput .= "&language={$this->mLanguageCode}"; |
25 | | - $this->mOutput .= "&sensor=false"; |
26 | | - if ($o['type'] == 'terrain' || $o['type'] == 'satellite' || $o['type'] == 'hybrid') { |
27 | | - $this->mOutput .= "&maptype={$o['type']}"; |
28 | | - } |
29 | | - } |
| 13 | + function addHeader($o) { |
| 14 | + $width = $o['width'] > 640 ? 640 : $o['width']; |
| 15 | + $height = $o['height'] > 640 ? 640 : $o['height']; |
| 16 | + $this->mOutput .= '<img '; |
| 17 | + $this->mOutput .= "alt=\"Map\" "; |
| 18 | + $this->mOutput .= "height=\"{$height}\" width=\"{$width}\" "; |
| 19 | + $this->mOutput .= 'src="http://maps.google.com/maps/api/staticmap'; |
| 20 | + $this->mOutput .= "?center={$o['lat']}%2C{$o['lon']}"; |
| 21 | + $this->mOutput .= "&zoom={$o['zoom']}"; |
| 22 | + $this->mOutput .= "&size={$width}x{$height}"; |
| 23 | + $this->mOutput .= "&key={$this->mApiKey}"; |
| 24 | + $this->mOutput .= "&language={$this->mLanguageCode}"; |
| 25 | + $this->mOutput .= "&sensor=false"; |
| 26 | + if ($o['type'] == 'terrain' || $o['type'] == 'satellite' || $o['type'] == 'hybrid') { |
| 27 | + $this->mOutput .= "&maptype={$o['type']}"; |
| 28 | + } |
| 29 | + } |
30 | 30 | |
31 | | - function addMarker($pLat, $pLon, $pIcon, $pTitle, $pTitleLink, $pCaption, $pMaxContent, $pIsLine) |
32 | | - { |
33 | | - $this->mOutput .= "&markers=".urlencode("size:mid|color:red"); |
34 | | - if ($pIcon) { |
35 | | - $this->mOutput .= urlencode("|label:" . strtoupper(substr($pIcon, 0, 1))); |
36 | | - } |
37 | | - $this->mOutput .= urlencode("|{$pLat},{$pLon}"); |
38 | | - } |
| 31 | + function addMarker($pLat, $pLon, $pIcon, $pTitle, $pTitleLink, $pCaption, $pMaxContent, $pIsLine) |
| 32 | + { |
| 33 | + $this->mOutput .= "&markers=".urlencode("size:mid|color:red"); |
| 34 | + if ($pIcon) { |
| 35 | + $this->mOutput .= urlencode("|label:" . strtoupper(substr($pIcon, 0, 1))); |
| 36 | + } |
| 37 | + $this->mOutput .= urlencode("|{$pLat},{$pLon}"); |
| 38 | + } |
39 | 39 | |
40 | | - function addPolyline( $pPolyline, $pLineColor, $pLineOpacity, $pStroke, $pFillColor, $pFillOpacity ) |
41 | | - { |
42 | | - $this->mOutput .= "&path=".urlencode("color:0x{$pLineColor}{$pLineOpacity}|weight:{$pStroke}"); |
43 | | - if ( isset( $pFillColor ) ) { |
44 | | - $this->mOutput .= urlencode("|fillcolor:0x{$pFillColor}{$pFillOpacity}"); |
45 | | - } |
46 | | - foreach ($pPolyline as $p) { |
47 | | - $this->mOutput .= urlencode("|{$p['lat']},{$p['lon']}"); |
48 | | - } |
49 | | - } |
| 40 | + function addPolyline( $pPolyline, $pLineColor, $pLineOpacity, $pStroke, $pFillColor, $pFillOpacity ) |
| 41 | + { |
| 42 | + $this->mOutput .= "&path=".urlencode("color:0x{$pLineColor}{$pLineOpacity}|weight:{$pStroke}"); |
| 43 | + if ( isset( $pFillColor ) ) { |
| 44 | + $this->mOutput .= urlencode("|fillcolor:0x{$pFillColor}{$pFillOpacity}"); |
| 45 | + } |
| 46 | + foreach ($pPolyline as $p) { |
| 47 | + $this->mOutput .= urlencode("|{$p['lat']},{$p['lon']}"); |
| 48 | + } |
| 49 | + } |
50 | 50 | |
51 | | - function addTrailer() { |
52 | | - $this->mOutput .= "\" />"; |
53 | | - } |
| 51 | + function addTrailer() { |
| 52 | + $this->mOutput .= "\" />"; |
| 53 | + } |
54 | 54 | } |
Index: trunk/extensions/GoogleMaps/GoogleMaps.php |
— | — | @@ -116,7 +116,7 @@ |
117 | 117 | $wgTitle ); |
118 | 118 | |
119 | 119 | // This hook will add the interactive editing map to the article edit page. |
120 | | - $editHook = array( $wgGoogleMaps, 'editForm' ); |
| 120 | + $editHook = array( $wgGoogleMaps, 'editForm' ); |
121 | 121 | if( !$wgGoogleMapsDisableEditorsMap ) { |
122 | 122 | if( isset( $wgHooks['EditPage::showEditForm:initial'] ) |
123 | 123 | && is_array( $wgHooks['EditPage::showEditForm:initial'] ) ) { |
— | — | @@ -128,7 +128,7 @@ |
129 | 129 | |
130 | 130 | // This hook will do some post-processing on the javascript that has been added |
131 | 131 | // to an article. |
132 | | - $hook = 'wfGoogleMaps_CommentJS'; |
| 132 | + $hook = 'wfGoogleMaps_CommentJS'; |
133 | 133 | if( isset( $wgHooks['ParserAfterTidy'] ) && is_array( $wgHooks['ParserAfterTidy'] ) ) { |
134 | 134 | array_unshift( $wgHooks['ParserAfterTidy'], $hook ); |
135 | 135 | } else { |
Index: trunk/extensions/GoogleMaps/INSTALL |
— | — | @@ -1,10 +1,5 @@ |
2 | | -1. Go sign up for a Google Maps API key from |
| 2 | +1. Make sure this GoogleMaps folder is in your "extensions" directory |
3 | 3 | |
4 | | - http://maps.google.com/apis/maps/ |
| 4 | +2. Add this to the end of LocalSettings.php: |
5 | 5 | |
6 | | -2. Make sure this GoogleMaps folder is in your "extensions" directory |
7 | | - |
8 | | -3. Add this to the end of LocalSettings.php: |
9 | | - |
10 | | -$wgGoogleMapsKey = "your key from step 1 goes here"; |
11 | 6 | require_once( "extensions/GoogleMaps/GoogleMaps.php" ); |
Index: trunk/extensions/GoogleMaps/SpecialGoogleMapsKML.php |
— | — | @@ -8,9 +8,9 @@ |
9 | 9 | // Easy links to KML files |
10 | 10 | |
11 | 11 | class GoogleMapsKML extends SpecialPage { |
12 | | - function __construct() { |
13 | | - parent::__construct('GoogleMapsKML', '', false /* listed */); |
14 | | - } |
| 12 | + function __construct() { |
| 13 | + parent::__construct('GoogleMapsKML', '', false /* listed */); |
| 14 | + } |
15 | 15 | function execute( $params ) { |
16 | 16 | global $wgRequest, $wgOut, $wgUser; |
17 | 17 | global $wgContLang, $wgProxyKey, $wgParser; |
— | — | @@ -35,7 +35,7 @@ |
36 | 36 | |
37 | 37 | $popts = ParserOptions::newFromUser( $wgUser ); |
38 | 38 | $popts->setEditSection( false ); |
39 | | - |
| 39 | + |
40 | 40 | $wgParser->startExternalParse( $this->getTitle(), $popts, OT_WIKI, true ); |
41 | 41 | |
42 | 42 | $localParser = new Parser(); |
— | — | @@ -44,12 +44,12 @@ |
45 | 45 | if (preg_match_all("/<googlemap( .*?|)>(.*?)<\/googlemap>/s", $revision->getText(), $matches)) { |
46 | 46 | $exporter->addFileHeader(); |
47 | 47 | for($i=0;$i<count($matches[2]);$i++) { |
48 | | - $attrs = Sanitizer::decodeTagAttributes($matches[1][$i]); |
49 | | - $mapOptions['version'] = isset($attrs['version']) ? $attrs['version'] : "0"; |
50 | | - $exporter->addHeader(isset($attrs['title']) ? $attrs['title'] : "Map #".($i+1)); |
51 | | - GoogleMaps::renderContent($matches[2][$i], $wgParser, $localParser, $exporter, $mapOptions); |
52 | | - $exporter->addTrailer(); |
53 | | - } |
| 48 | + $attrs = Sanitizer::decodeTagAttributes($matches[1][$i]); |
| 49 | + $mapOptions['version'] = isset($attrs['version']) ? $attrs['version'] : "0"; |
| 50 | + $exporter->addHeader(isset($attrs['title']) ? $attrs['title'] : "Map #".($i+1)); |
| 51 | + GoogleMaps::renderContent($matches[2][$i], $wgParser, $localParser, $exporter, $mapOptions); |
| 52 | + $exporter->addTrailer(); |
| 53 | + } |
54 | 54 | $exporter->addFileTrailer(); |
55 | 55 | echo $exporter->render(); |
56 | 56 | } else { |