summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Maps/src/MediaWiki/MapsHooks.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/Maps/src/MediaWiki/MapsHooks.php')
-rw-r--r--www/wiki/extensions/Maps/src/MediaWiki/MapsHooks.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/www/wiki/extensions/Maps/src/MediaWiki/MapsHooks.php b/www/wiki/extensions/Maps/src/MediaWiki/MapsHooks.php
index e2a8ad95..9cefac2d 100644
--- a/www/wiki/extensions/Maps/src/MediaWiki/MapsHooks.php
+++ b/www/wiki/extensions/Maps/src/MediaWiki/MapsHooks.php
@@ -1,9 +1,13 @@
<?php
+
namespace Maps\MediaWiki;
use AlItem;
use ALTree;
+use Maps\Presentation\GeoJsonNewPageUi;
+use Maps\Presentation\OutputFacade;
+use SkinTemplate;
/**
* Static class for hooks handled by the Maps extension.
@@ -59,10 +63,67 @@ final class MapsHooks {
$vars['egMapsDebugJS'] = $GLOBALS['egMapsDebugJS'];
$vars['egMapsAvailableServices'] = $GLOBALS['egMapsAvailableServices'];
$vars['egMapsLeafletLayersApiKeys'] = $GLOBALS['egMapsLeafletLayersApiKeys'];
+ $vars['egMapsLeafletLayersDark'] = $GLOBALS['egMapsLeafletLayersDark'];
$vars += $GLOBALS['egMapsGlobalJSVars'];
return true;
}
+ public static function onSkinTemplateNavigation( SkinTemplate $skinTemplate, array &$links ) {
+ if ( $skinTemplate->getTitle() === null ) {
+ return true;
+ }
+
+ if ( $skinTemplate->getTitle()->getNamespace() === NS_GEO_JSON ) {
+ if ( array_key_exists( 'edit', $links['views'] ) ) {
+ $links['views']['edit']['text'] = wfMessage(
+ $skinTemplate->getTitle()->exists() ? 'maps-geo-json-edit-source': 'maps-geo-json-create-source'
+ );
+ }
+ }
+
+ return true;
+ }
+
+ public static function onBeforeDisplayNoArticleText( \Article $article ) {
+ return !self::shouldShowGeoJsonCreatePageUi( $article );
+ }
+
+ public static function onShowMissingArticle( \Article $article ) {
+ if ( self::shouldShowGeoJsonCreatePageUi( $article ) ) {
+ $ui = new GeoJsonNewPageUi( OutputFacade::newFromOutputPage( $article->getContext()->getOutput() ) );
+ $ui->addToOutput();
+ }
+
+ return true;
+ }
+
+ private static function shouldShowGeoJsonCreatePageUi( \Article $article ): bool {
+ return $article->getTitle()->getNamespace() === NS_GEO_JSON
+ && $article->getContext()->getUser()->isAllowed( 'createpage' );
+ }
+
+ public static function onRegisterTags( array &$tags ) {
+ $tags[] = 'maps-visual-edit';
+ return true;
+ }
+
+ public static function onChangeTagsAllowedAdd( array &$allowedTags, array $tags, \User $user = null ) {
+ $allowedTags[] = 'maps-visual-edit';
+ }
+
+ public static function onResourceLoaderTestModules( array &$modules, $resourceLoader ) {
+ $modules['qunit']['ext.maps.test'] = [
+ 'scripts' => [
+ 'tests/js/leaflet/GeoJsonTest.js',
+ ],
+ 'dependencies' => [
+ 'ext.maps.leaflet.geojson',
+ ],
+ 'localBasePath' => __DIR__ . '/../../',
+ 'remoteExtPath' => 'Maps'
+ ];
+ }
+
}