r106550 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106549‎ | r106550 | r106551 >
Date:02:20, 18 December 2011
Author:mah
Status:ok
Tags:
Comment:
w/s changes and update INSTALL doc to reflect the fact that an API key
is no longer needed.
Modified paths:
  • /trunk/extensions/GoogleMaps/GoogleMaps.body.php (modified) (history)
  • /trunk/extensions/GoogleMaps/GoogleMaps.i18n.php (modified) (history)
  • /trunk/extensions/GoogleMaps/GoogleMaps.php (modified) (history)
  • /trunk/extensions/GoogleMaps/INSTALL (modified) (history)
  • /trunk/extensions/GoogleMaps/SpecialGoogleMapsKML.php (modified) (history)
  • /trunk/extensions/GoogleMaps/export/GoogleMapsImgExporter.php (modified) (history)
  • /trunk/extensions/GoogleMaps/export/GoogleMapsKmlExporter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GoogleMaps/GoogleMaps.body.php
@@ -178,17 +178,17 @@
179179 'container':'toolbar', 'textbox':'wpTextbox1', 'toggle':'google_maps_toggle_link',
180180 JAVASCRIPT;
181181
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+ }
193193 // add all of the map settings to the editors_options JS variable
194194 foreach( array_keys( $o ) as $key ) {
195195 if( is_numeric( $o[$key] ) ) {
@@ -200,7 +200,7 @@
201201
202202 // output the 'rtl' setting
203203 $isRTLString = $this->mLanguage->isRTL() ? 'true' : 'false';
204 - $extensionVersion = GOOGLE_MAPS_EXTENSION_VERSION;
 204+ $extensionVersion = GOOGLE_MAPS_EXTENSION_VERSION;
205205 $output .= " 'rtl':{$isRTLString} };";
206206
207207 // output the base utility JS (addLoadEvent function, etc.)
@@ -216,16 +216,16 @@
217217 $output .= <<<JAVASCRIPT
218218
219219 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);
225225 }
226226
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+ }
230230 function loadEditorsMapJavascript() {
231231 addScript('{$this->mUrlPath}/color_select.js');
232232 addScript('{$this->mUrlPath}/EditorsMap.js?v={$extensionVersion}');
@@ -234,24 +234,24 @@
235235 }
236236
237237 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+ }
243243 }
244244
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);
253253
254 - emap = new EditorsMap(editors_options);
255 - }
 254+ emap = new EditorsMap(editors_options);
 255+ }
256256
257257 function insertGoogleMapLinks() {
258258 var image = document.createElement("img");
@@ -264,7 +264,7 @@
265265 image.style.cursor = "pointer";
266266 image.onclick = function() {
267267 if( typeof(EditorsMap) == "undefined" ) {
268 - loadEditorsMapJavascript();
 268+ loadEditorsMapJavascript();
269269 } else {
270270 emap.toggleGoogleMap();
271271 }
@@ -360,7 +360,7 @@
361361 global $wgGoogleMaps;
362362 // pass through to the main render function, creating a new parser
363363 // for parsing the local content
364 - return $wgGoogleMaps->render( $pContent, $pArgv, $pParser, new Parser() );
 364+ return $wgGoogleMaps->render( $pContent, $pArgv, $pParser, new Parser() );
365365 }
366366
367367 /**
@@ -375,41 +375,41 @@
376376 * @return string - the html for rendering the map
377377 **/
378378 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;
381381
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+ }
388388
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+ }
395395
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 );
399399
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();
407407
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+ }
414414
415415 function renderKmlLink($pContent, $pArgv) {
416416 global $wgTitle;
@@ -420,175 +420,175 @@
421421 }
422422
423423 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;
433433
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'];
441441
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 ) ) {
447447
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+ }
454454
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));
458458
459 - $tabs = array( );
460 - $caption = '';
461 - $title = null;
462 - }
 459+ $tabs = array( );
 460+ $caption = '';
 461+ $title = null;
 462+ }
463463
464 - $state = GOOGLE_MAPS_PARSE_POINTS;
 464+ $state = GOOGLE_MAPS_PARSE_POINTS;
465465
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+ }
472472
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));
496496
497 - $tabs = array( );
498 - $caption = '';
499 - $title = null;
500 - }
 497+ $tabs = array( );
 498+ $caption = '';
 499+ $title = null;
 500+ }
501501
502 - $state = GOOGLE_MAPS_PARSE_POINTS;
 502+ $state = GOOGLE_MAPS_PARSE_POINTS;
503503
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+ }
513513
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+ }
519519
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 ) ) {
522522
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+ }
527527
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+ }
534534
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+ }
542542
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+ }
548548
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+ }
554554
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);
560560
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+ }
569569
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+ }
586586
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+ }
593593
594594 //----------------------------------------------
595595 // UTILITIES
@@ -608,9 +608,9 @@
609609 'normal',
610610 'hybrid',
611611 'terrain',
612 - 'satellite',
613 - 'elevation',
614 - 'infrared'
 612+ 'satellite',
 613+ 'elevation',
 614+ 'infrared'
615615 ),
616616 'controls' => array(
617617 'small',
@@ -635,11 +635,11 @@
636636 'smooth',
637637 'fast'
638638 ),
639 - 'world' => array(
640 - 'earth',
641 - 'moon',
642 - 'mars'
643 - ),
 639+ 'world' => array(
 640+ 'earth',
 641+ 'moon',
 642+ 'mars'
 643+ ),
644644 'scrollwheel' => array(
645645 'zoom',
646646 'nothing'
@@ -700,25 +700,25 @@
701701 'height' => 400,
702702 'icon' => 'http://www.google.com/mapfiles/marker.png',
703703 '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,
706706 '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',
711711 'lat' => 42.711618,
712712 'localsearch' => true,
713713 'lon' => -73.205112,
714714 'opacity' => 0.7,
715715 'overview' => 'no',
716 - 'world' => 'earth',
 716+ 'world' => 'earth',
717717 'precision' => 6,
718718 'scale' => 'no',
719719 'scrollwheel' => 'nothing',
720720 'selector' => 'yes',
721721 'stroke' => 6,
722 - 'style' => '',
 722+ 'style' => '',
723723 'type' => 'hybrid',
724724 'units' => 'kilometers',
725725 'version' => 0,
@@ -758,19 +758,19 @@
759759 return $o;
760760 }
761761
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+ }
775775
776776
777777 /**
Index: trunk/extensions/GoogleMaps/GoogleMaps.i18n.php
@@ -7071,4 +7071,3 @@
70727072 'gm-moon' => '月亮',
70737073 'gm-mars' => '火星',
70747074 );
7075 -
Index: trunk/extensions/GoogleMaps/export/GoogleMapsKmlExporter.php
@@ -84,7 +84,7 @@
8585 $this->mOutput .= '<description><![CDATA['.
8686 GoogleMaps::fixBlockDirection(GoogleMaps::fixTidy($pCaption), $this->mLanguage->isRTL()).
8787 ']]></description>';
88 - } elseif (is_array($pCaption)) { // TODO tabs and max content
 88+ } elseif (is_array($pCaption)) { // TODO tabs and max content
8989 }
9090 $this->mOutput .= "</Placemark>\n";
9191 }
Index: trunk/extensions/GoogleMaps/export/GoogleMapsImgExporter.php
@@ -1,53 +1,53 @@
22 <?php
33
44 class GoogleMapsImgExporter extends GoogleMapsExporter {
5 - var $mApiKey;
6 - var $mLanguageCode;
 5+ var $mApiKey;
 6+ var $mLanguageCode;
77
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+ }
1212
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+ }
3030
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+ }
3939
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+ }
5050
51 - function addTrailer() {
52 - $this->mOutput .= "\" />";
53 - }
 51+ function addTrailer() {
 52+ $this->mOutput .= "\" />";
 53+ }
5454 }
Index: trunk/extensions/GoogleMaps/GoogleMaps.php
@@ -116,7 +116,7 @@
117117 $wgTitle );
118118
119119 // This hook will add the interactive editing map to the article edit page.
120 - $editHook = array( $wgGoogleMaps, 'editForm' );
 120+ $editHook = array( $wgGoogleMaps, 'editForm' );
121121 if( !$wgGoogleMapsDisableEditorsMap ) {
122122 if( isset( $wgHooks['EditPage::showEditForm:initial'] )
123123 && is_array( $wgHooks['EditPage::showEditForm:initial'] ) ) {
@@ -128,7 +128,7 @@
129129
130130 // This hook will do some post-processing on the javascript that has been added
131131 // to an article.
132 - $hook = 'wfGoogleMaps_CommentJS';
 132+ $hook = 'wfGoogleMaps_CommentJS';
133133 if( isset( $wgHooks['ParserAfterTidy'] ) && is_array( $wgHooks['ParserAfterTidy'] ) ) {
134134 array_unshift( $wgHooks['ParserAfterTidy'], $hook );
135135 } 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
33
4 - http://maps.google.com/apis/maps/
 4+2. Add this to the end of LocalSettings.php:
55
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";
116 require_once( "extensions/GoogleMaps/GoogleMaps.php" );
Index: trunk/extensions/GoogleMaps/SpecialGoogleMapsKML.php
@@ -8,9 +8,9 @@
99 // Easy links to KML files
1010
1111 class GoogleMapsKML extends SpecialPage {
12 - function __construct() {
13 - parent::__construct('GoogleMapsKML', '', false /* listed */);
14 - }
 12+ function __construct() {
 13+ parent::__construct('GoogleMapsKML', '', false /* listed */);
 14+ }
1515 function execute( $params ) {
1616 global $wgRequest, $wgOut, $wgUser;
1717 global $wgContLang, $wgProxyKey, $wgParser;
@@ -35,7 +35,7 @@
3636
3737 $popts = ParserOptions::newFromUser( $wgUser );
3838 $popts->setEditSection( false );
39 -
 39+
4040 $wgParser->startExternalParse( $this->getTitle(), $popts, OT_WIKI, true );
4141
4242 $localParser = new Parser();
@@ -44,12 +44,12 @@
4545 if (preg_match_all("/<googlemap( .*?|)>(.*?)<\/googlemap>/s", $revision->getText(), $matches)) {
4646 $exporter->addFileHeader();
4747 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+ }
5454 $exporter->addFileTrailer();
5555 echo $exporter->render();
5656 } else {

Status & tagging log