summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Maps/src/Presentation
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/Maps/src/Presentation')
-rw-r--r--www/wiki/extensions/Maps/src/Presentation/GeoJsonMapPageUi.php83
-rw-r--r--www/wiki/extensions/Maps/src/Presentation/GeoJsonNewPageUi.php27
-rw-r--r--www/wiki/extensions/Maps/src/Presentation/MapHtmlBuilder.php10
-rw-r--r--www/wiki/extensions/Maps/src/Presentation/MapsDistanceParser.php2
-rw-r--r--www/wiki/extensions/Maps/src/Presentation/OutputFacade.php62
5 files changed, 181 insertions, 3 deletions
diff --git a/www/wiki/extensions/Maps/src/Presentation/GeoJsonMapPageUi.php b/www/wiki/extensions/Maps/src/Presentation/GeoJsonMapPageUi.php
new file mode 100644
index 00000000..89440f1f
--- /dev/null
+++ b/www/wiki/extensions/Maps/src/Presentation/GeoJsonMapPageUi.php
@@ -0,0 +1,83 @@
+<?php
+
+declare( strict_types = 1 );
+
+namespace Maps\Presentation;
+
+use Html;
+
+class GeoJsonMapPageUi {
+
+ private $json;
+
+ public static function forExistingPage( string $mapJson ): self {
+ return new self( $mapJson );
+ }
+
+ private function __construct( ?string $json ) {
+ $this->json = $json;
+ }
+
+ public function addToOutput( OutputFacade $output ) {
+ $leafletPath = $GLOBALS['wgScriptPath'] . '/extensions/Maps/resources/lib/leaflet';
+
+ $output->addHeadItem(
+ 'MapsGeoJsonHeadItem',
+ Html::linkedStyle( "$leafletPath/leaflet.css" ) . Html::linkedScript( "$leafletPath/leaflet.js" )
+ );
+
+ $output->addHTML( $this->getJavascript() . $this->getHtml() );
+ $output->addModules( 'ext.maps.geojson.page' );
+ }
+
+ private function getJavascript(): string {
+ return Html::element(
+ 'script',
+ [],
+ $this->getJsonJs()
+ );
+ }
+
+ private function getJsonJs(): string {
+ return 'var GeoJson ='
+ . $this->json
+ . ';';
+ }
+
+ private function getHtml(): string {
+ return $this->wrapHtmlInThumbDivs(
+ Html::rawElement(
+ 'div',
+ [
+ 'id' => 'GeoJsonMap',
+ 'style' => 'width: 100%; height: 600px; background-color: #eeeeee; overflow: hidden;',
+ 'class' => 'maps-map maps-leaflet maps-geojson-editor'
+ ],
+ Html::element(
+ 'div',
+ [
+ 'class' => 'maps-loading-message'
+ ],
+ wfMessage( 'maps-loading-map' )->inContentLanguage()->text()
+ )
+ )
+ );
+ }
+
+ private function wrapHtmlInThumbDivs( string $html ): string {
+ return Html::rawElement(
+ 'div',
+ [
+ 'class' => 'thumb'
+ ],
+ Html::rawElement(
+ 'div',
+ [
+ 'class' => 'thumbinner'
+ ],
+ $html
+ )
+ );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/src/Presentation/GeoJsonNewPageUi.php b/www/wiki/extensions/Maps/src/Presentation/GeoJsonNewPageUi.php
new file mode 100644
index 00000000..5de1df71
--- /dev/null
+++ b/www/wiki/extensions/Maps/src/Presentation/GeoJsonNewPageUi.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Maps\Presentation;
+
+class GeoJsonNewPageUi {
+
+ private $output;
+
+ public function __construct( OutputFacade $output ) {
+ $this->output = $output;
+ }
+
+ public function addToOutput() {
+ $this->output->addModules( 'ext.maps.geojson.new.page' );
+
+ $this->output->addHtml(
+ \Html::element(
+ 'button',
+ [
+ 'id' => 'maps-geojson-new'
+ ],
+ wfMessage( 'maps-geo-json-create-page-button' )->inContentLanguage()->text()
+ )
+ );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/src/Presentation/MapHtmlBuilder.php b/www/wiki/extensions/Maps/src/Presentation/MapHtmlBuilder.php
index aa47e558..7d74ad34 100644
--- a/www/wiki/extensions/Maps/src/Presentation/MapHtmlBuilder.php
+++ b/www/wiki/extensions/Maps/src/Presentation/MapHtmlBuilder.php
@@ -22,12 +22,18 @@ class MapHtmlBuilder {
'div',
[
'id' => $mapName,
- 'style' => "width: {$params['width']}; height: {$params['height']}; background-color: #cccccc; overflow: hidden;",
+ 'style' => "width: {$params['width']}; height: {$params['height']}; background-color: #eeeeee; overflow: hidden;",
'class' => 'maps-map maps-' . $serviceName
],
- wfMessage( 'maps-loading-map' )->inContentLanguage()->escaped() .
Html::element(
'div',
+ [
+ 'class' => 'maps-loading-message'
+ ],
+ wfMessage( 'maps-loading-map' )->inContentLanguage()->text()
+ )
+ . Html::element(
+ 'div',
[ 'style' => 'display:none', 'class' => 'mapdata' ],
FormatJson::encode( $params )
)
diff --git a/www/wiki/extensions/Maps/src/Presentation/MapsDistanceParser.php b/www/wiki/extensions/Maps/src/Presentation/MapsDistanceParser.php
index c8fb0ef1..7c0d595a 100644
--- a/www/wiki/extensions/Maps/src/Presentation/MapsDistanceParser.php
+++ b/www/wiki/extensions/Maps/src/Presentation/MapsDistanceParser.php
@@ -99,7 +99,7 @@ class MapsDistanceParser {
$strlen = strlen( $distance );
for ( $i = 0; $i < $strlen; $i++ ) {
- if ( !ctype_digit( $distance{$i} ) && !in_array( $distance{$i}, [ ',', '.' ] ) ) {
+ if ( !ctype_digit( $distance[$i] ) && !in_array( $distance[$i], [ ',', '.' ] ) ) {
$value = substr( $distance, 0, $i );
$unit = substr( $distance, $i );
break;
diff --git a/www/wiki/extensions/Maps/src/Presentation/OutputFacade.php b/www/wiki/extensions/Maps/src/Presentation/OutputFacade.php
new file mode 100644
index 00000000..119f3b1d
--- /dev/null
+++ b/www/wiki/extensions/Maps/src/Presentation/OutputFacade.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Maps\Presentation;
+
+use OutputPage;
+use ParserOutput;
+
+class OutputFacade {
+
+ /**
+ * @var OutputPage
+ */
+ private $outputPage;
+
+ /**
+ * @var ParserOutput
+ */
+ private $parserOutput;
+
+ public static function newFromOutputPage( OutputPage $outputPage ) {
+ $instance = new self();
+ $instance->outputPage = $outputPage;
+ return $instance;
+ }
+
+ public static function newFromParserOutput( ParserOutput $parserOutput ) {
+ $instance = new self();
+ $instance->parserOutput = $parserOutput;
+ return $instance;
+ }
+
+ public function addHtml( string $html ) {
+ if ( $this->outputPage !== null ) {
+ $this->outputPage->addHTML( $html );
+ }
+
+ if ( $this->parserOutput !== null ) {
+ $this->parserOutput->setText( $this->parserOutput->getRawText() . $html );
+ }
+ }
+
+ public function addModules( string ...$modules ) {
+ if ( $this->outputPage !== null ) {
+ $this->outputPage->addModules( $modules );
+ }
+
+ if ( $this->parserOutput !== null ) {
+ $this->parserOutput->addModules( $modules );
+ }
+ }
+
+ public function addHeadItem( string $name, string $html ) {
+ if ( $this->outputPage !== null ) {
+ $this->outputPage->addHeadItem( $name, $html );
+ }
+
+ if ( $this->parserOutput !== null ) {
+ $this->parserOutput->addHeadItem( $html, $name );
+ }
+ }
+
+}