Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 763 - show editor in Geojson namespace #767

6 changes: 5 additions & 1 deletion src/GeoJsonPages/GeoJsonContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class GeoJsonContent extends \JsonContent {

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

public static function formatJson( $value ): string {
return FormatJson::encode( $value, true, FormatJson::UTF8_OK );
}

public function __construct( string $text, string $modelId = self::CONTENT_MODEL_ID ) {
Expand Down
29 changes: 17 additions & 12 deletions src/GeoJsonPages/GeoJsonContentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,26 @@ 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() ) {
if ( $cpoParams->getGenerateHtml() && $content->isValid() ) {

// @FIXME alternatively decode $this->mText in GeoJsonLegacyContent
// to avoid decoding it again in SubObjectBuilder -> getSubObjectsFromGeoJson
$text = json_encode( $content->getData()->getValue() );
// display map
( GeoJsonMapPageUi::forExistingPage( GeoJsonContent::formatJson( $content->getData()->getValue() ) ) )
->addToOutput( OutputFacade::newFromParserOutput( $parserOutput ) );

MapsFactory::globalInstance()
->newSemanticGeoJsonStore( $parserOutput, $cpoParams->getPage() )
->storeGeoJson( $text );
if ( MapsFactory::globalInstance()->smwIntegrationIsEnabled() ) {
// @FIXME alternatively decode $this->mText in GeoJsonLegacyContent
// to avoid decoding it again in SubObjectBuilder -> getSubObjectsFromGeoJson
$text = json_encode( $content->getData()->getValue() );

MapsFactory::globalInstance()
->newSemanticGeoJsonStore( $parserOutput, $cpoParams->getPage() )
->storeGeoJson( $text );
}

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