Skip to content

Commit

Permalink
fixes show editor MW > 1.37
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-topway-it authored Feb 15, 2024
1 parent 674e5e3 commit 33fcb62
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/GeoJsonPages/GeoJsonContentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Maps\GeoJsonPages;

use Content;
use FormatJson;
use Maps\MapsFactory;
use Maps\Presentation\OutputFacade;
use MediaWiki\Content\Renderer\ContentParseParams;
Expand All @@ -24,6 +25,11 @@ public function makeEmptyContent(): GeoJsonContent {
$class = $this->getContentClass();
return new $class( $class::newEmptyContentString() );
}

public static function newEmptyContentString(): string {
$text = '{"type": "FeatureCollection", "features": []}';
return FormatJson::encode( FormatJson::parse( $text )->getValue(), true, FormatJson::UTF8_OK );
}

/**
* @inheritdoc
Expand All @@ -34,13 +40,14 @@ protected function fillParserOutput(
ParserOutput &$parserOutput
) {
'@phan-var GeoJsonContent $content';
// this method won't be called below MW_VERSION 1.38

parent::fillParserOutput( $content, $cpoParams, $parserOutput );

if ( $cpoParams->getGenerateHtml()
&& $content->isValid()
&& MapsFactory::globalInstance()->smwIntegrationIsEnabled()
&& $parserOutput->hasText() ) {
&& MapsFactory::globalInstance()->smwIntegrationIsEnabled() ) {

( GeoJsonMapPageUi::forExistingPage( GeoJsonContent::formatJson( $content->getData()->getValue() ) ) )
->addToOutput( OutputFacade::newFromParserOutput( $parserOutput ) );

// @FIXME alternatively decode $this->mText in GeoJsonLegacyContent
// to avoid decoding it again in SubObjectBuilder -> getSubObjectsFromGeoJson
Expand All @@ -49,6 +56,9 @@ protected function fillParserOutput(
MapsFactory::globalInstance()
->newSemanticGeoJsonStore( $parserOutput, $cpoParams->getPage() )
->storeGeoJson( $text );

} else {
parent::fillParserOutput( $content, $cpoParams, $parserOutput );
}
}
}

0 comments on commit 33fcb62

Please sign in to comment.