jenkins-bot has submitted this change and it was merged.

Change subject: Cleanup HTML output and modules
......................................................................


Cleanup HTML output and modules

For parsing consistency always output
  <div class="mw-kartographer mw-kartographer-{mode}">
as the root element.

Change-Id: I9ff808430cd91125554a167071db4b25944f9f42
---
M extension.json
M includes/DataModule.php
M includes/TagHandler.php
M modules/kartographer.js
R styles/kartographer.less
D styles/live.less
D styles/static.less
7 files changed, 27 insertions(+), 51 deletions(-)

Approvals:
  MaxSem: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index 7c069ab..ac45558 100644
--- a/extension.json
+++ b/extension.json
@@ -18,21 +18,10 @@
                "Kartographer\\TagHandler": "includes/TagHandler.php"
        },
        "ResourceModules": {
-               "ext.kartographer.data": {
-                       "class": "Kartographer\\DataModule"
-               },
-               "ext.kartographer.error": {
+               "ext.kartographer": {
+                       "class": "Kartographer\\DataModule",
                        "styles": [
-                               "styles/error.less"
-                       ],
-                       "targets": [
-                               "mobile",
-                               "desktop"
-                       ]
-               },
-               "ext.kartographer.static": {
-                       "styles": [
-                         "styles/static.less"
+                               "styles/kartographer.less"
                        ],
                        "targets": [
                                "mobile",
@@ -41,14 +30,13 @@
                },
                "ext.kartographer.live": {
                        "dependencies": [
-                               "ext.kartographer.data"
+                               "ext.kartographer"
                        ],
                        "scripts": [
                          "lib/mapbox-lib.js",
                          "modules/kartographer.js"
                        ],
                        "styles": [
-                         "styles/live.less",
                          "lib/style.css"
                        ],
                        "targets": [
diff --git a/includes/DataModule.php b/includes/DataModule.php
index 5405207..7d4c713 100644
--- a/includes/DataModule.php
+++ b/includes/DataModule.php
@@ -10,11 +10,9 @@
 
 use ResourceLoader;
 use ResourceLoaderContext;
-use ResourceLoaderModule;
+use ResourceLoaderFileModule;
 
-class DataModule extends ResourceLoaderModule {
-
-       protected $targets = array( 'desktop', 'mobile' );
+class DataModule extends ResourceLoaderFileModule {
 
        public function getScript( ResourceLoaderContext $context ) {
                $config = $context->getResourceLoader()->getConfig();
@@ -23,9 +21,5 @@
                        'wgKartographerIconServer' => $config->get( 
'KartographerIconServer' ),
                        'wgKartographerSrcsetScales' => $config->get( 
'KartographerSrcsetScales' ),
                ) );
-       }
-
-       public function enableModuleContentVersion() {
-               return true;
        }
 }
diff --git a/includes/TagHandler.php b/includes/TagHandler.php
index 78ddad7..7990d67 100644
--- a/includes/TagHandler.php
+++ b/includes/TagHandler.php
@@ -31,6 +31,7 @@
        ) {
                global $wgKartographerStyles, $wgKartographerDfltStyle;
                $output = $parser->getOutput();
+               $output->addModuleStyles( 'ext.kartographer' );
 
                if ( $input !== '' && $input !== null ) {
                        $status = FormatJson::parse( $input, 
FormatJson::TRY_FIXING | FormatJson::STRIP_COMMENTS );
@@ -129,6 +130,9 @@
                }
 
                $html = '';
+               $attrs = array(
+                       'class' => 'mw-kartographer mw-kartographer-' . $mode,
+               );
                switch ( $mode ) {
                        case 'static':
                                // 
http://.../img/{source},{zoom},{lat},{lon},{width}x{height} [ @{scale}x ] 
.{format}
@@ -139,7 +143,6 @@
                                        $wgKartographerMapServer, $style, 
$zoom, $lat, $lon, $width, $height );
 
                                $imgAttrs = array(
-                                       'class' => 'mw-kartographer-img',
                                        'src' => $statParams . '.jpeg' . 
$dataParam,
                                        'width' => $width,
                                        'height' => $height,
@@ -153,19 +156,15 @@
                                        $imgAttrs['srcset'] = Html::srcSet( 
$srcSet );
                                }
 
-                               $output->addModules( 'ext.kartographer.static' 
);
-                               $html = Html::rawElement( 'img', $imgAttrs );
+                               $html = Html::rawElement( 'div', $attrs, 
Html::rawElement( 'img', $imgAttrs ) );
                                break;
 
                        case 'interactive':
-                               $attrs = array(
-                                       'class' => 'mw-kartographer-live',
-                                       'style' => 
"width:${width}px;height:${height}px;",
-                                       'data-style' => $style,
-                                       'data-zoom' => $zoom,
-                                       'data-lat' => $lat,
-                                       'data-lon' => $lon,
-                               );
+                               $attrs['style'] = 
"width:${width}px;height:${height}px;";
+                               $attrs['data-style'] = $style;
+                               $attrs['data-zoom'] = $zoom;
+                               $attrs['data-lat'] = $lat;
+                               $attrs['data-lon'] = $lon;
                                if ( $groups ) {
                                        $attrs['data-overlays'] = 
FormatJson::encode( $groups, false,
                                                FormatJson::ALL_OK );
@@ -176,13 +175,11 @@
 
                        case 'anchor':
                                if ( $counter !== false ) {
-                                       $html = Html::element( 'a', array(
-                                               'class' => 'mw-kartographer',
-                                               'data-zoom' => $zoom,
-                                               'data-lat' => $lat,
-                                               'data-lon' => $lon,
-                                               'data-style' => $style,
-                                       ), $counter );
+                                       $attrs['data-style'] = $style;
+                                       $attrs['data-zoom'] = $zoom;
+                                       $attrs['data-lat'] = $lat;
+                                       $attrs['data-lon'] = $lon;
+                                       $html = Html::element( 'a', $attrs, 
$counter );
                                }
                                break;
                }
@@ -365,7 +362,6 @@
         * @return string
         */
        private static function reportError( ParserOutput $output, Status 
$status ) {
-               $output->addModules( 'ext.kartographer.error' );
                $output->setExtensionData( 'kartographer_broken', true );
                return Html::rawElement( 'div', array( 'class' => 
'mw-kartographer-error' ),
                        $status->getWikiText( false, 'kartographer-errors' ) );
diff --git a/modules/kartographer.js b/modules/kartographer.js
index 92cf5c0..680fe0e 100644
--- a/modules/kartographer.js
+++ b/modules/kartographer.js
@@ -37,7 +37,7 @@
                urlFormat = '/{z}/{x}/{y}' + scale + '.png';
                mapData = mw.config.get( 'wgKartographerLiveData' ) || {};
 
-               $content.find( '.mw-kartographer-live' ).each( function () {
+               $content.find( '.mw-kartographer-interactive' ).each( function 
() {
                        var dataLayer, geoJson,
                                $this = $( this ),
                                style = $this.data( 'style' ),
diff --git a/styles/error.less b/styles/kartographer.less
similarity index 63%
rename from styles/error.less
rename to styles/kartographer.less
index ce59b10..5b8673e 100644
--- a/styles/error.less
+++ b/styles/kartographer.less
@@ -1,4 +1,8 @@
-.mw-kartographer-error {
+.mw-kartographer {
        display: inline-block;
+}
+
+.mw-kartographer-error {
+       .mw-kartographer;
        background: #ffc0cb
 }
diff --git a/styles/live.less b/styles/live.less
deleted file mode 100644
index e86ba6a..0000000
--- a/styles/live.less
+++ /dev/null
@@ -1,3 +0,0 @@
-.mw-kartographer-live {
-       display: inline-block;
-}
diff --git a/styles/static.less b/styles/static.less
deleted file mode 100644
index 353f6cf..0000000
--- a/styles/static.less
+++ /dev/null
@@ -1,3 +0,0 @@
-.mw-kartographer-img {
-       display: inline-block;
-}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9ff808430cd91125554a167071db4b25944f9f42
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/Kartographer
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[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

Reply via email to