Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/Map/SemanticFormat/MapPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Maps\Map\MapOutput;
use Maps\Map\MapOutputBuilder;
use Maps\MappingService;
use Maps\MapsFactory;
use Maps\Presentation\ElementJsonSerializer;
use Maps\Presentation\WikitextParser;
use Maps\SemanticMW\QueryHandler;
Expand Down Expand Up @@ -89,7 +90,7 @@ final public function getResultText( QueryResult $res, $outputMode ): string {

$this->isHTML = true;

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

Expand Down Expand Up @@ -170,14 +171,14 @@ function( BaseElement $element ) {

private function addTrackingCategoryIfNeeded() {
// Queries on special pages, such as Special:Ask, are not part of a page.
if ( !$this->mInline || !\Maps\MapsFactory::globalInstance()->getEffectiveSettings()->get( 'egMapsEnableCategory' ) ) {
if ( !$this->mInline || !MapsFactory::globalInstance()->getEffectiveSettings()->get( 'egMapsEnableCategory' ) ) {
return;
}

// copyParser() does not copy: it returns the parser that runs the inline query.
// copyParser() does not copy. For #ask and #show it returns the parser running the query; other callers can
// get a parser that never parsed and has no output yet.
$parser = $this->copyParser();

// Callers other than SMW's #ask can pass a parser that never parsed and has no output yet.
if ( $parser->getOptions() !== null ) {
$parser->addTrackingCategory( 'maps-tracking-category' );
}
Expand Down Expand Up @@ -317,7 +318,7 @@ public function getParamDefinitions( array $definitions ): array {
* @return array
*/
private function getParameterInfo() {
$config = \Maps\MapsFactory::globalInstance()->getEffectiveSettings();
$config = MapsFactory::globalInstance()->getEffectiveSettings();

$params = $this->service->getParameterInfo();

Expand Down
26 changes: 22 additions & 4 deletions tests/Integration/ConfigPageHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testContentModelIsNotForcedWhenWikiConfigDisabled() {
}

public function testSavingInvalidConfigFailsWithEachError() {
$status = $this->saveConfigPage( '{"leaflets":{},"googlemaps":{}}' );
$status = $this->trySavingConfigPage( '{"leaflets":{},"googlemaps":{}}' );

$this->assertStatusNotOK( $status );
$this->assertStatusMessagesExactly(
Expand All @@ -88,8 +88,26 @@ public function testSavingInvalidConfigFailsWithEachError() {
}

/**
* Saves the way maintenance scripts and extensions do, without the edit form.
* Saves the way maintenance scripts and extensions do, without the edit form. A save that goes through is
* undone, so a failing run does not leave the test config as the wiki's configuration.
*/
private function trySavingConfigPage( string $json ): StatusValue {
$previousJson = $this->configPageJson();
$status = $this->saveConfigPage( $json );

if ( $status->isOK() ) {
$this->saveConfigPage( $previousJson );
}

return $status;
}

private function configPageJson(): string {
$content = MapsTestFactory::newTestInstance()->getPageContentFetcher()->getPageContent( 'MediaWiki:Maps' );

return $content instanceof JsonContent ? $content->getText() : '{}';
}

private function saveConfigPage( string $json ): StatusValue {
return PageCreator::instance()->createPageWithContent( 'MediaWiki:Maps', new JsonContent( $json ) );
}
Expand Down Expand Up @@ -123,9 +141,9 @@ public function testErrorsShowConfigKeysAsText() {
$this->assertStringContainsString( '(maps-config-error-unknown-key: later)', $text );
}

public function testOtherJsonPagesAreNotValidated() {
public function testPageNamedMapsInAnotherNamespaceIsNotValidated() {
$this->assertStatusGood( $this->validateSave(
Title::makeTitle( NS_GEO_JSON, 'Some area' ),
Title::makeTitle( NS_GEO_JSON, 'Maps' ),
'{"type":"FeatureCollection","features":[]}'
) );
}
Expand Down
Loading