Yurik has uploaded a new change for review.
https://gerrit.wikimedia.org/r/320153
Change subject: (WIP) "shapred" external data support
......................................................................
(WIP) "shapred" external data support
Change-Id: I933fdb5de26e905e6e7fa6e3dbfd0293c9267b53
---
M i18n/en.json
M i18n/qqq.json
M includes/SimpleStyleParser.php
M schemas/geojson.json
4 files changed, 79 insertions(+), 42 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Kartographer
refs/changes/53/320153/1
diff --git a/i18n/en.json b/i18n/en.json
index 04d61d9..9d22bf3 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -28,6 +28,7 @@
"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-error-service-name": "Invalid cartographic service
\"$1\"",
+ "kartographer-error-title": "Title \"$1\" is not a valid map data page",
"kartographer-tracking-category":
"{{#switch:{{NAMESPACE}}|{{ns:File}}=Files|#default=Pages}} with maps",
"kartographer-tracking-category-desc": "The page includes a map",
"kartographer-coord-combined": "$1 $2",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index eb386fd..c55c2b3 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -32,6 +32,7 @@
"kartographer-error-bad_data": "This error is shown if the content of
the tag is syntactically valid JSON however it does not adhere to GeoJSON and
simplestyle specifications",
"kartographer-error-latlon": "Error shown by <maplink> or
<mapframe> when certain parameters are incorrect",
"kartographer-error-service-name": "Error shown by <maplink> or
<mapframe>. Parameters:\n* $1 - service name.",
+ "kartographer-error-title": "Error shown by <maplink> or
<mapframe>. Parameters:\n* $1 - page title.",
"kartographer-tracking-category": "Name of the tracking category",
"kartographer-tracking-category-desc": "Description on
[[Special:TrackingCategories]] for the
{{msg-mw|kartographer-tracking-category}} tracking category.",
"kartographer-coord-combined": "{{optional}}\nJoins two parts of
geogrpahical coordinates. $1 and $2 are latitude and longitude, respectively.",
diff --git a/includes/SimpleStyleParser.php b/includes/SimpleStyleParser.php
index d773ef2..bc5a8b0 100644
--- a/includes/SimpleStyleParser.php
+++ b/includes/SimpleStyleParser.php
@@ -3,6 +3,8 @@
namespace Kartographer;
use FormatJson;
+use JsonConfig\JCMapDataContent;
+use JsonConfig\JCSingleton;
use JsonSchema\Validator;
use MediaWiki\MediaWikiServices;
use Parser;
@@ -15,8 +17,6 @@
*/
class SimpleStyleParser {
private static $parsedProps = [ 'title', 'description' ];
-
- private static $services = [ 'geoshape', 'geoline', 'geomask' ];
/** @var Parser */
private $parser;
@@ -204,38 +204,59 @@
* @return Status
*/
private function normalizeExternalData( &$object ) {
- if ( !in_array( $object->service, self::$services ) ) {
- return Status::newFatal(
'kartographer-error-service-name', $object->service );
- }
$ret = (object)[
'type' => 'ExternalData',
'service' => $object->service,
];
- $query = [
- 'getgeojson' => 1
- ];
+ switch ( $object->service ) {
+ default:
+ return Status::newFatal(
'kartographer-error-service-name', $object->service );
- if ( property_exists( $object, 'ids' ) ) {
- $query['ids'] = is_array( $object->ids )
- ? join( ',', $object->ids )
- : preg_replace( '/\s*,\s*/', ',', $object->ids
);
- }
- if ( property_exists( $object, 'query' ) ) {
- $query['query'] = $object->query;
- }
+ case 'geoshape':
+ case 'geoline':
+ case 'geomask':
+ $query = [ 'getgeojson' => 1 ];
+ if ( property_exists( $object, 'ids' ) ) {
+ $query['ids'] =
+ is_array( $object->ids ) ?
join( ',', $object->ids )
+ : preg_replace(
'/\s*,\s*/', ',', $object->ids );
+ }
+ if ( property_exists( $object, 'query' ) ) {
+ $query['query'] = $object->query;
+ }
+ // 'geomask' service is the same as inverted
geoshape service
+ // Kartotherian does not support it, request it
as geoshape
+ $service = $object->service === 'geomask' ?
'geoshape' : $object->service;
- // 'geomask' service is the same as inverted geoshape service
- // Kartotherian does not support it, request it as geoshape
- $service = $object->service === 'geomask' ? 'geoshape' :
$object->service;
- $ret->url = "{$this->mapService}/{$service}?" . wfArrayToCgi(
$query );
- if ( property_exists( $object, 'properties' ) ) {
- $ret->properties = $object->properties;
+ $ret->url = "{$this->mapService}/{$service}?" .
wfArrayToCgi( $query );
+ if ( property_exists( $object, 'properties' ) )
{
+ $ret->properties = $object->properties;
+ }
+ break;
+
+ case 'shared':
+ if ( !class_exists( 'JsonConfig\\JCSingleton' )
) {
+ return Status::newFatal(
'kartographer-error-service-name', $object->service );
+ }
+ $jct = JCSingleton::parseTitle( $object->title,
NS_DATA );
+ if ( !$jct || JCSingleton::getContentClass(
$jct->getConfig()->model ) !==
+
JCMapDataContent::class
+ ) {
+ return Status::newFatal(
'kartographer-error-title', $object->title );
+ }
+ $query = [
+ 'format' => 'json',
+ 'formatversion' => '2',
+ 'action' => 'jsondata',
+ 'title' => $jct->getText(),
+ ];
+ $ret->url = wfExpandUrl( "/w/api.php?" .
wfArrayToCgi( $query ) );
+ break;
}
$object = $ret;
-
return Status::newGood();
}
diff --git a/schemas/geojson.json b/schemas/geojson.json
index e750152..64d4bc3 100644
--- a/schemas/geojson.json
+++ b/schemas/geojson.json
@@ -157,30 +157,44 @@
"description": "WMF extension - reference to external
geometries",
"required": [ "type", "service" ],
- "anyOf": [
- { "required": [ "query" ] },
- { "required": [ "ids" ] }
+ "oneOf": [
+ {
+ "required": [ "title" ],
+ "properties": {
+ "service": { "enum": [ "shared"
] },
+ "title": { "type": "string" }
+ }
+ },
+ {
+ "anyOf": [
+ { "required": [ "query" ] },
+ { "required": [ "ids" ] }
+ ],
+ "properties": {
+ "service": { "enum": [
"geoshape", "geoline", "geomask" ] },
+ "query": { "type": "string" },
+ "ids": {
+ "oneOf": [
+ {
+ "type":
"array",
+
"items": {
+
"type": "string",
+
"pattern": "^Q[1-9]\\d{0,19}$"
+ }
+ },
+ {
+ "type":
"string",
+
"pattern": "^Q[1-9]\\d{0,19}(\\s*,\\s*Q[1-9]\\d{0,19})*$"
+ }
+ ]
+ }
+ }
+ }
],
"properties": {
"type": { "enum": [ "ExternalData" ] },
"service": { "type": "string" },
- "query": { "type": "string" },
- "ids": {
- "oneOf": [
- {
- "type": "array",
- "items": {
- "type":
"string",
- "pattern":
"^Q[1-9]\\d{0,19}$"
- }
- },
- {
- "type": "string",
- "pattern":
"^Q[1-9]\\d{0,19}(\\s*,\\s*Q[1-9]\\d{0,19})*$"
- }
- ]
- },
"properties": { "$ref":
"#/definitions/simplestyle" }
}
},
--
To view, visit https://gerrit.wikimedia.org/r/320153
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I933fdb5de26e905e6e7fa6e3dbfd0293c9267b53
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Kartographer
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits