MaxSem has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/294364

Change subject: WIP: Automatically set map view if not defined explicitly
......................................................................

WIP: Automatically set map view if not defined explicitly

This is a backend part of what also needs some frontend love.

Bug: T137678
Change-Id: I3b7f0cb1017ae5c7c4d5394568ffa4a02a09b63d
---
M i18n/en.json
M includes/Tag/MapFrame.php
M includes/Tag/MapLink.php
M includes/Tag/TagHandler.php
M tests/parserTests.txt
5 files changed, 35 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Kartographer 
refs/changes/64/294364/1

diff --git a/i18n/en.json b/i18n/en.json
index a85022c..0f7f87f 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -24,6 +24,7 @@
        "kartographer-error-missing-attr": "Attribute \"$1\" is missing",
        "kartographer-error-bad_attr": "Attribute \"$1\" has an invalid value",
        "kartographer-error-bad_data": "The JSON content is not valid 
GeoJSON+simplestyle",
+       "kartographer-error-latlon": "Either both \"latitude\" and 
\"longitude\" parameters should be supplied or neither of them",
        "kartographer-tracking-category": "Pages with maps",
        "kartographer-tracking-category-desc": "The page includes a map",
        "kartographer-coord-combined": "$1 $2",
diff --git a/includes/Tag/MapFrame.php b/includes/Tag/MapFrame.php
index f5a0792..fb1a780 100644
--- a/includes/Tag/MapFrame.php
+++ b/includes/Tag/MapFrame.php
@@ -86,10 +86,15 @@
                                        'mw-data' => 'interface',
                                        'style' => "width:{$width}; 
height:{$this->height}px;",
                                        'data-style' => $this->mapStyle,
-                                       'data-zoom' => $this->zoom,
-                                       'data-lat' => $this->lat,
-                                       'data-lon' => $this->lon,
                                ];
+                               if ( !is_null( $this->zoom ) ) {
+                                       $attrs['data-zoom'] = $this->zoom;
+                               }
+                               if ( !is_null( $this->lat ) && !is_null( 
$this->lon ) ) {
+                                       $attrs['data-lat'] = $this->lat;
+                                       $attrs['data-lon'] = $this->lon;
+
+                               }
                                if ( isset( $alignClasses[$this->align] ) ) {
                                        $attrs['class'] .= ' ' . 
$alignClasses[$this->align];
                                }
diff --git a/includes/Tag/MapLink.php b/includes/Tag/MapLink.php
index 639724f..31f5ad9 100644
--- a/includes/Tag/MapLink.php
+++ b/includes/Tag/MapLink.php
@@ -39,10 +39,15 @@
                        'class' => 'mw-kartographer-link',
                        'mw-data' => 'interface',
                        'data-style' => $this->mapStyle,
-                       'data-zoom' => $this->zoom,
-                       'data-lat' => $this->lat,
-                       'data-lon' => $this->lon,
                ];
+               if ( !is_null( $this->zoom ) ) {
+                       $attrs['data-zoom'] = $this->zoom;
+               }
+               if ( !is_null( $this->lat ) && !is_null( $this->lon ) ) {
+                       $attrs['data-lat'] = $this->lat;
+                       $attrs['data-lon'] = $this->lon;
+
+               }
                $style = $this->extractMarkerCss();
                if ( $style ) {
                        $attrs['class'] .= ' mw-kartographer-autostyled';
diff --git a/includes/Tag/TagHandler.php b/includes/Tag/TagHandler.php
index e2c3e0d..2d50ece 100644
--- a/includes/Tag/TagHandler.php
+++ b/includes/Tag/TagHandler.php
@@ -149,9 +149,13 @@
        protected function parseArgs() {
                global $wgKartographerStyles, $wgKartographerDfltStyle;
 
-               $this->lat = $this->getFloat( 'latitude' );
-               $this->lon = $this->getFloat( 'longitude' );
-               $this->zoom = $this->getInt( 'zoom' );
+               $this->lat = $this->getFloat( 'latitude', null );
+               $this->lon = $this->getFloat( 'longitude', null );
+               if ( is_null( $this->lat ) ^ is_null( $this->lon ) ) {
+                       $this->status->fatal( 'kartographer-error-latlon' );
+               }
+
+               $this->zoom = $this->getInt( 'zoom', null );
                $regexp = '/^(' . implode( '|', $wgKartographerStyles ) . ')$/';
                $this->mapStyle = $this->getText( 'mapstyle', 
$wgKartographerDfltStyle, $regexp );
        }
@@ -190,7 +194,7 @@
 
        protected function getInt( $name, $default = false ) {
                $value = $this->getText( $name, $default, '/^-?[0-9]+$/' );
-               if ( $value !== false ) {
+               if ( $value !== false && $value !== null ) {
                        $value = intval( $value );
                }
 
@@ -204,7 +208,7 @@
         */
        protected function getFloat( $name, $default = false ) {
                $value = $this->getText( $name, $default, 
'/^-?[0-9]*\.?[0-9]+$/' );
-               if ( $value !== false ) {
+               if ( $value !== false && $value !== null ) {
                        $value = floatval( $value );
                }
 
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index 9fda8c6..fa114f6 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -1,9 +1,11 @@
 !! test
-<maplink> - custom link text
+<maplink>
 !! input
+<maplink />
 <maplink latitude=10 longitude=20 zoom=13 text='Foo &amp; bar'/>
 !! result
-<p><a class="mw-kartographer-link" mw-data="interface" data-style="osm-intl" 
data-zoom="13" data-lat="10" data-lon="20">Foo &amp; bar</a>
+<p><a class="mw-kartographer-link" mw-data="interface" 
data-style="osm-intl">0°0′0″N 0°0′0″E</a>
+<a class="mw-kartographer-link" mw-data="interface" data-style="osm-intl" 
data-zoom="13" data-lat="10" data-lon="20">Foo &amp; bar</a>
 </p>
 !! end
 
@@ -145,12 +147,13 @@
     }
   }
 </mapframe>
+<mapframe width=200 height=200 latitude=100/>
+<mapframe width=200 height=200 longitude=100/>
 !! result
 <div class="mw-kartographer-error"><p>&lt;maplink&gt; problems:
 </p>
 <ul><li> Couldn't parse JSON: Syntax error</li>
-<li> Attribute "longitude" has an invalid value</li>
-<li> Attribute "zoom" is missing</li></ul>
+<li> Attribute "longitude" has an invalid value</li></ul>
 </div>
 <div class="mw-kartographer-error"><p>&lt;mapframe&gt; problems:
 </p>
@@ -167,6 +170,8 @@
 <li> Attribute "mapstyle" has an invalid value</li>
 <li> Attribute "align" has an invalid value</li></ul>
 </div>
+<div class="mw-kartographer-error">&lt;mapframe&gt;: Either both "latitude" 
and "longitude" parameters should be supplied or neither of them</div>
+<div class="mw-kartographer-error">&lt;mapframe&gt;: Either both "latitude" 
and "longitude" parameters should be supplied or neither of them</div>
 
 !! end
 

-- 
To view, visit https://gerrit.wikimedia.org/r/294364
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3b7f0cb1017ae5c7c4d5394568ffa4a02a09b63d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Kartographer
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to