jenkins-bot has submitted this change and it was merged.
Change subject: Use marker styles
......................................................................
Use marker styles
Bug: T129507
Change-Id: Ieb1aa8a14c7ee83593d31fba9eb399c5adef2010
---
M extension.json
M includes/Tag/MapLink.php
M includes/Tag/TagHandler.php
M styles/kartographer.less
M tests/parserTests.txt
5 files changed, 118 insertions(+), 14 deletions(-)
Approvals:
Yurik: Looks good to me, approved
jenkins-bot: Verified
diff --git a/extension.json b/extension.json
index 007238b..35898af 100644
--- a/extension.json
+++ b/extension.json
@@ -205,7 +205,8 @@
"KartographerSrcsetScales": [1.3, 1.5, 2, 2.6, 3],
"KartographerMapServer": "https://maps.wikimedia.org",
"KartographerIconServer": "https://maps.wikimedia.org",
- "KartographerFrameMode": "interactive"
+ "KartographerFrameMode": "interactive",
+ "KartographerUseMarkerStyle": true
},
"TrackingCategories": [
"kartographer-tracking-category",
diff --git a/includes/Tag/MapLink.php b/includes/Tag/MapLink.php
index abe0793..31472c3 100644
--- a/includes/Tag/MapLink.php
+++ b/includes/Tag/MapLink.php
@@ -13,17 +13,19 @@
protected $tag = 'maplink';
protected function render() {
- $counter = $this->counter;
- if ( is_numeric( $counter ) ) {
- $counter =
$this->parser->getTargetLanguage()->formatNum( $counter );
- }
+ // @todo: Mapbox markers don't support localized numbers yet
$text = $this->getText( 'text', null, '/\S+/' );
if ( $text === null ) {
- $text = $counter ?: CoordFormatter::format( $this->lat,
$this->lon, $this->language );
+ $text = $this->counter ?: CoordFormatter::format(
$this->lat, $this->lon, $this->language );
}
$text = $this->parser->recursiveTagParse( $text, $this->frame );
- $attrs = $this->getDefaultAttributes();
+ $style = $this->extractMarkerCss();
+
+ $attrs = $this->getDefaultAttributes( $style );
$attrs['class'] .= ' mw-kartographer-link';
+ if ( $style ) {
+ $attrs['class'] .= ' mw-kartographer-autostyled';
+ }
$attrs['data-style'] = $this->mapStyle;
$attrs['data-zoom'] = $this->zoom;
$attrs['data-lat'] = $this->lat;
@@ -35,4 +37,24 @@
return Html::rawElement( 'a', $attrs, $text );
}
+
+ /**
+ * Extracts CSS style to be used by the link from GeoJSON
+ * @return string
+ */
+ private function extractMarkerCss() {
+ global $wgKartographerUseMarkerStyle;
+
+ if ( $wgKartographerUseMarkerStyle
+ && $this->markerProperties
+ && property_exists( $this->markerProperties,
'marker-color' )
+ ) {
+ preg_match( '/^#?(([0-9a-fA-F]{3}){1,2})$/',
$this->markerProperties->{'marker-color'}, $m );
+ if ( $m && $m[2] ) {
+ return "background: #{$m[2]};";
+ }
+ }
+
+ return '';
+ }
}
diff --git a/includes/Tag/TagHandler.php b/includes/Tag/TagHandler.php
index 819f7c2..1f1d855 100644
--- a/includes/Tag/TagHandler.php
+++ b/includes/Tag/TagHandler.php
@@ -50,7 +50,7 @@
protected $mapStyle;
/** @var string */
- protected $style;
+ protected $style = '';
/** @var string name of the group, or null for private */
protected $groupName;
@@ -69,6 +69,9 @@
/** @var Language */
protected $language;
+
+ /** @var stdClass */
+ protected $markerProperties;
/**
* Entry point for all tags
@@ -161,12 +164,14 @@
/**
* Returns default HTML attributes of the outermost tag of the output
+ * @param string $extraStyle
* @return string[]
*/
- protected function getDefaultAttributes() {
+ protected function getDefaultAttributes( $extraStyle = '' ) {
$attrs = [ 'class' => 'mw-kartographer', 'mw-data' =>
'interface' ];
- if ( $this->style ) {
- $attrs['style'] = $this->style;
+ $style = trim( "{$extraStyle} {$this->style}" );
+ if ( $style ) {
+ $attrs['style'] = $style;
}
return $attrs;
}
@@ -261,7 +266,10 @@
// For all GeoJSON items whose marker-symbol value begins with
'-counter' and '-letter',
// recursively replace them with an automatically incremented
marker icon.
$counters = $output->getExtensionData( 'kartographer_counters'
) ?: new stdClass();
- $this->counter = $this->doCountersRecursive( $this->geometries,
$counters );
+ $marker = $this->doCountersRecursive( $this->geometries,
$counters );
+ if ( $marker ) {
+ list( $this->counter, $this->markerProperties ) =
$marker;
+ }
$output->setExtensionData( 'kartographer_counters', $counters );
if ( $this->groupName === null ) {
@@ -316,7 +324,7 @@
/**
* @param $values
* @param stdClass $counters counter-name -> integer
- * @return bool|string returns the very first counter value that has
been used
+ * @return bool|array [ marker, marker properties ]
*/
private function doCountersRecursive( $values, &$counters ) {
$firstMarker = false;
@@ -342,7 +350,7 @@
$item->properties->{'marker-symbol'} =
$marker;
if ( $firstMarker === false ) {
// GeoJSON is in lowercase, but
the letter is shown as uppercase
- $firstMarker = mb_strtoupper(
$marker );
+ $firstMarker = [ mb_strtoupper(
$marker ), $item->properties ];
}
}
}
diff --git a/styles/kartographer.less b/styles/kartographer.less
index 8f534f1..3b0cdb1 100644
--- a/styles/kartographer.less
+++ b/styles/kartographer.less
@@ -17,3 +17,7 @@
a.mw-kartographer-link {
cursor: pointer;
}
+
+.mw-kartographer-autostyled {
+ color: white;
+}
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index 91f124e..ba13d00 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -133,3 +133,72 @@
<a class="mw-kartographer mw-kartographer-link" mw-data="interface" style="/*
insecure input */" data-style="osm-intl" data-zoom="10" data-lat="10"
data-lon="20"><span style="/* insecure input */">foo</span></a>
</p>
!! end
+
+!! test
+Marker styles
+!! input
+<maplink latitude=10 longitude=20 zoom=13>[
+{
+ "type": "Feature",
+ "geometry": {
+ "type": "Point",
+ "coordinates": [1, 2]
+ }
+},
+{
+"type": "Feature",
+ "geometry": {
+ "type": "Point",
+ "coordinates": [-122.3988, 37.8013]
+ },
+ "properties": {
+ "marker-symbol": "-letter",
+ "marker-color": "#abc"
+ }
+},
+{
+"type": "Feature",
+ "geometry": {
+ "type": "Point",
+ "coordinates": [-122.3988, 37.8013]
+ },
+ "properties": {
+ "marker-symbol": "-number",
+ "marker-color": "#DDEEFF"
+ }
+}
+]</maplink>
+
+<maplink latitude=10 longitude=20 zoom=13 style="border: yellow;">
+{
+"type": "Feature",
+ "geometry": {
+ "type": "Point",
+ "coordinates": [-122.3988, 37.8013]
+ },
+ "properties": {
+ "marker-symbol": "-number",
+ "marker-color": "fff"
+ }
+}
+</maplink>
+
+<maplink latitude=10 longitude=20 zoom=13>
+{
+"type": "Feature",
+ "geometry": {
+ "type": "Point",
+ "coordinates": [-122.3988, 37.8013]
+ },
+ "properties": {
+ "marker-symbol": "-number",
+ "marker-color": "something bad"
+ }
+}
+</maplink>
+!! result
+<p><a class="mw-kartographer mw-kartographer-link mw-kartographer-autostyled"
mw-data="interface" style="background: #abc;" data-style="osm-intl"
data-zoom="13" data-lat="10" data-lon="20"
data-overlays="["_19a72be79a2653cf0eeccdba3776a568873e8865"]">A</a>
+</p><p><a class="mw-kartographer mw-kartographer-link
mw-kartographer-autostyled" mw-data="interface" style="background: #fff;
border: yellow;" data-style="osm-intl" data-zoom="13" data-lat="10"
data-lon="20"
data-overlays="["_348b58ab5ba1db004b387561db7d945cdf90cea0"]">2</a>
+</p><p><a class="mw-kartographer mw-kartographer-link" mw-data="interface"
data-style="osm-intl" data-zoom="13" data-lat="10" data-lon="20"
data-overlays="["_737b28c57ddefefdb1da5a25bc09425dd124b6b6"]">3</a>
+</p>
+!! end
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/277913
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ieb1aa8a14c7ee83593d31fba9eb399c5adef2010
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Kartographer
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Yurik <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits