Skip to content

Commit

Permalink
Fix factory state being ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Apr 2, 2020
1 parent 09cbbdb commit be79d2e
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 22 deletions.
4 changes: 2 additions & 2 deletions INSTALL.md
Expand Up @@ -25,11 +25,11 @@ minimum requirements are indicated in bold. For a detailed list of changes, see
<th>Release status<br>&nbsp;</th>
</tr>
<tr>
<th>7.16.x</th>
<th>7.17.x</th>
<td>7.1 - 7.4+</td>
<td>1.31 - 1.34+</td>
<td>3.1.x</td>
<td>Planned Q1 2020</td>
<td>Planned Q2 2020</td>
</tr>
<tr>
<th>7.16.x</th>
Expand Down
7 changes: 4 additions & 3 deletions RELEASE-NOTES.md
Expand Up @@ -3,11 +3,12 @@ different releases and which versions of PHP and MediaWiki they support, see the
[platform compatibility tables](INSTALL.md#platform-compatibility-and-release-status).


## Maps 7.17.0
## Maps 7.16.1

Under development
Released on April 2nd, 2020.

* Leaflet maps now show properly in Visual Editor (no enhanced editing was added)
* Leaflet maps now show properly in the Visual Editor extension (no enhanced editing was added)
* Fixed issue causing some settings to be ignored in some situations

## Maps 7.16.0

Expand Down
2 changes: 1 addition & 1 deletion extension.json
@@ -1,6 +1,6 @@
{
"name": "Maps",
"version": "7.17.0 alpha",
"version": "7.16.1",

"author": [
"[https://www.entropywins.wtf/mediawiki Jeroen De Dauw]",
Expand Down
4 changes: 4 additions & 0 deletions resources/leaflet/LeafletLoader.js
Expand Up @@ -34,6 +34,10 @@ window.mapsLeafletList = [];
1000
);

// mw.hook( 've.deactivationComplete' ).add( function() {
// clearInterval( thread );
// } );

// surface.getModel().on( 'history', function() {
// console.log('history');
// initializeMaps( $( surface.$element[0] ) );
Expand Down
2 changes: 1 addition & 1 deletion src/LeafletService.php
Expand Up @@ -216,7 +216,7 @@ public function processingResultToMapParams( ProcessingResult $processingResult

public function processedParamsToMapParams( array $params ): array {
if ( $params['geojson'] !== '' ) {
$fetcher = MapsFactory::newDefault()->newGeoJsonFetcher();
$fetcher = MapsFactory::globalInstance()->newGeoJsonFetcher();

$result = $fetcher->fetch( $params['geojson'] );

Expand Down
31 changes: 25 additions & 6 deletions src/MapsFactory.php
Expand Up @@ -47,15 +47,14 @@ class MapsFactory {
private $settings;
private $mediaWikiServices;

private $leafletService;
private $googleService;

private function __construct( array $settings, MediaWikiServices $mediaWikiServices ) {
$this->settings = $settings;
$this->mediaWikiServices = $mediaWikiServices;
}

public static function newDefault(): self {
return new self( $GLOBALS, MediaWikiServices::getInstance() );
}

/**
* Only for legacy code where dependency injection is not possible
*/
Expand All @@ -69,6 +68,10 @@ public static function globalInstance(): self {
return $instance;
}

public static function newDefault(): self {
return new self( $GLOBALS, MediaWikiServices::getInstance() );
}

public function newLocationParser(): LocationParser {
return LocationParser::newInstance(
$this->getGeocoder(),
Expand Down Expand Up @@ -169,11 +172,27 @@ public function getMappingServices(): MappingServices {
return new MappingServices(
$this->settings['egMapsAvailableServices'],
$this->settings['egMapsDefaultService'],
new GoogleMapsService(),
new LeafletService()
$this->getGoogleMapsService(),
$this->getLeafletService()
);
}

private function getGoogleMapsService(): GoogleMapsService {
if ( $this->googleService === null ) {
$this->googleService = new GoogleMapsService();
}

return $this->googleService;
}

private function getLeafletService(): LeafletService {
if ( $this->leafletService === null ) {
$this->leafletService = new LeafletService();
}

return $this->leafletService;
}

public function getDisplayMapFunction(): DisplayMapFunction {
return new DisplayMapFunction(
$this->getMappingServices()
Expand Down
4 changes: 2 additions & 2 deletions src/MapsSetup.php
Expand Up @@ -85,7 +85,7 @@ private function registerParserHooks() {
$parser->setFunctionHook(
$hookName,
function ( Parser $parser, PPFrame $frame, array $arguments ) {
$mapHtml = MapsFactory::newDefault()->getDisplayMapFunction()->getMapHtmlForKeyValueStrings(
$mapHtml = MapsFactory::globalInstance()->getDisplayMapFunction()->getMapHtmlForKeyValueStrings(
$parser,
array_map(
function ( $argument ) use ( $frame ) {
Expand All @@ -111,7 +111,7 @@ function ( $text, array $arguments, Parser $parser ) {
$arguments[DisplayMapFunction::getDefaultParameters()[0]] = $text;
}

return MapsFactory::newDefault()->getDisplayMapFunction()->getMapHtmlForParameterList( $parser, $arguments );
return MapsFactory::globalInstance()->getDisplayMapFunction()->getMapHtmlForParameterList( $parser, $arguments );
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/MediaWiki/ParserHooks/DisplayMapRenderer.php
Expand Up @@ -55,7 +55,7 @@ public function __construct( MappingService $service = null ) {
* @return string
*/
public final function renderMap( array $params, Parser $parser ) {
$factory = \Maps\MapsFactory::newDefault();
$factory = \Maps\MapsFactory::globalInstance();

$this->locationParser = $factory->newLocationParser();
$this->fileUrlFinder = $factory->getFileUrlFinder();
Expand Down
2 changes: 1 addition & 1 deletion src/MediaWiki/ParserHooks/GeocodeFunction.php
Expand Up @@ -18,7 +18,7 @@ class GeocodeFunction extends ParserHook {
private $geocoder;

public function __construct( Geocoder $geocoder = null ) {
$this->geocoder = $geocoder ?? \Maps\MapsFactory::newDefault()->getGeocoder();
$this->geocoder = $geocoder ?? \Maps\MapsFactory::globalInstance()->getGeocoder();
parent::__construct();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Presentation/WikitextParsers/CircleParser.php
Expand Up @@ -24,7 +24,7 @@ class CircleParser implements ValueParser {
private $geocoder;

public function __construct( $geocoder = null ) {
$this->geocoder = $geocoder instanceof Geocoder ? $geocoder : MapsFactory::newDefault()->getGeocoder();
$this->geocoder = $geocoder instanceof Geocoder ? $geocoder : MapsFactory::globalInstance()->getGeocoder();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Presentation/WikitextParsers/ImageOverlayParser.php
Expand Up @@ -20,7 +20,7 @@ class ImageOverlayParser implements ValueParser {
private $geocoder;

public function __construct( $geocoder = null ) {
$this->geocoder = $geocoder instanceof Geocoder ? $geocoder : MapsFactory::newDefault()->getGeocoder();
$this->geocoder = $geocoder instanceof Geocoder ? $geocoder : MapsFactory::globalInstance()->getGeocoder();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Presentation/WikitextParsers/LineParser.php
Expand Up @@ -30,7 +30,7 @@ public function setGeocoder( Geocoder $geocoder ) {

private function getGeocoder(): Geocoder {
if ( $this->geocoder == null ) {
$this->geocoder = MapsFactory::newDefault()->getGeocoder();
$this->geocoder = MapsFactory::globalInstance()->getGeocoder();
}

return $this->geocoder;
Expand Down
2 changes: 1 addition & 1 deletion src/Presentation/WikitextParsers/RectangleParser.php
Expand Up @@ -24,7 +24,7 @@ class RectangleParser implements ValueParser {
private $geocoder;

public function __construct( $geocoder = null ) {
$this->geocoder = $geocoder instanceof Geocoder ? $geocoder : MapsFactory::newDefault()->getGeocoder();
$this->geocoder = $geocoder instanceof Geocoder ? $geocoder : MapsFactory::globalInstance()->getGeocoder();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/SemanticMW/ResultPrinters/MapPrinter.php
Expand Up @@ -111,7 +111,7 @@ public final function getResultText( SMWQueryResult $res, $outputMode ) {

$this->isHTML = true;

$factory = \Maps\MapsFactory::newDefault();
$factory = \Maps\MapsFactory::globalInstance();
$this->locationParser = $factory->newLocationParser();
$this->fileUrlFinder = $factory->getFileUrlFinder();

Expand Down

0 comments on commit be79d2e

Please sign in to comment.