Skip to content

Commit

Permalink
Removed broken layers functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Jun 21, 2016
1 parent 927c19a commit 9f7662b
Show file tree
Hide file tree
Showing 21 changed files with 5 additions and 2,526 deletions.
168 changes: 4 additions & 164 deletions Maps.hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,8 @@
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
* @author Daniel Werner
*/
final class MapsHooks {
/**
* Helper flag indicating whether the page has been purged.
* @var bool
*
* TODO: Figure out a better way to do this, not requiring this flag and make sure it works with
* later MW versions (purging mechanism got changed somewhat around 1.18).
*/
static $purgedBeforeStore = false;

/**
* Adds a link to Admin Links page.
Expand All @@ -44,30 +35,14 @@ public static function addToAdminLinks( ALTree &$admin_links_tree ) {
return true;
}

/**
* Intercept pages in the Layer namespace to handle them correctly.
*
* @param $title: Title
* @param $article: Article or null
*
* @return boolean
*/
public static function onArticleFromTitle( Title &$title, /* Article */ &$article ) {
if ( $title->getNamespace() == Maps_NS_LAYER ) {
$article = new MapsLayerPage( $title );
}

return true;
}

/**
* Adds global JavaScript variables.
*
* @since 1.0
* @see http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript
* @param array &$vars Variables to be added into the output
* @param OutputPage $outputPage OutputPage instance calling the hook
* @return boolean true in all cases
* @see http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript
* @param array &$vars Variables to be added into the output
* @param OutputPage $outputPage OutputPage instance calling the hook
* @return boolean true in all cases
*/
public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $outputPage ) {
global $egMapsGlobalJSVars;
Expand All @@ -80,140 +55,5 @@ public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $ou
return true;
}

/**
* @since 0.7
*
* @param array $list
*
* @return boolean
*/
public static function onCanonicalNamespaces( array &$list ) {
$list[Maps_NS_LAYER] = 'Layer';
$list[Maps_NS_LAYER_TALK] = 'Layer_talk';
return true;
}

/**
* This will setup database tables for layer functionality.
*
* @since 3.0
*
* @param DatabaseUpdater $updater
*
* @return true
*/
public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) {
switch( $GLOBALS['wgDBtype'] ) {
case 'mysql':
case 'sqlite':
$updater->addExtensionTable( 'maps_layers', __DIR__ . '/schema/MapsLayers.sql' );
break;
case 'postgres':
$updater->addExtensionTable( 'maps_layers', __DIR__ . '/schema/MapsLayers-postgres.sql' );
break;
}

return true;
}

/**
* Make sure layer data will be stored into database when purging the page
*
* @since 3.0
*
* @param $article WikiPage|Article (depending on MW version, WikiPage in 1.18+)
* @return type
*/
public static function onArticlePurge( &$article ) {
self::$purgedBeforeStore = true;
return true;
}

/**
* At the end of article parsing, in case of layer page, save layers to database
*
* @since 3.0
*
* @param Parser &$parser
* @param string &$text
*
* @return true
*/
public static function onParserAfterTidy( Parser &$parser, &$text ) {

$title = $parser->getTitle();

if( $title === null
|| self::$purgedBeforeStore !== true
) {
// just preprocessing some stuff or no purge
return true;
}

self::processLayersStoreCandidate( $parser->getOutput(), $title );

// Set helper to false immediately so we won't run into job-processing weirdness:
self::$purgedBeforeStore = false;

return true;
}

/**
* After article was edited and parsed, in case of layer page, save layers to database
*
* @since 3.0
*
* @param LinksUpdate &$linksUpdate
*
* @return true
*/
public static function onLinksUpdateConstructed( LinksUpdate &$linksUpdate ) {
$title = $linksUpdate->getTitle();

self::processLayersStoreCandidate( $linksUpdate->mParserOutput, $title );

return true;
}

/**
* Checks whether the parser output has some layer data which should be stored of the
* given title and performs the task.
*
* @since 3.0
*
* @param ParserOutput $parserOutput
* @param Title $title
*/
protected static function processLayersStoreCandidate( ParserOutput $parserOutput, Title $title ) {

// if site which is being parsed is in maps namespace:
if( $title->getNamespace() === Maps_NS_LAYER ) {

if( ! isset( $parserOutput->mExtMapsLayers ) ) {
$parserOutput->mExtMapsLayers = new MapsLayerGroup();
}

// get MapsLayerGroup object with layers to be stored:
$mapsForStore = $parserOutput->mExtMapsLayers;

// store layers in database (also deletes previous definitions still in db):
MapsLayers::storeLayers( $mapsForStore, $title );
}
}

/**
* If a new parser process is getting started, clear collected layer data of the
* previous one.
*
* @since 3.0
*
* @param Parser $parser
*
* @return true
*/
public static function onParserClearState( Parser &$parser ) {
$parser->getOutput()->mExtMapsLayers = null;
return true;
}
}

18 changes: 0 additions & 18 deletions Maps.i18n.namespaces.php

This file was deleted.

20 changes: 0 additions & 20 deletions Maps.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
// Internationalization
$GLOBALS['wgMessagesDirs']['Maps'] = __DIR__ . '/i18n';
$GLOBALS['wgExtensionMessagesFiles']['MapsMagic'] = __DIR__ . '/Maps.i18n.magic.php';
$GLOBALS['wgExtensionMessagesFiles']['MapsNamespaces'] = __DIR__ . '/Maps.i18n.namespaces.php';
$GLOBALS['wgExtensionMessagesFiles']['MapsAlias'] = __DIR__ . '/Maps.i18n.alias.php';

$GLOBALS['wgResourceModules'] = array_merge( $GLOBALS['wgResourceModules'], include 'Maps.resources.php' );
Expand All @@ -100,13 +99,7 @@
};

$GLOBALS['wgHooks']['AdminLinks'][] = 'MapsHooks::addToAdminLinks';
$GLOBALS['wgHooks']['ArticleFromTitle'][] = 'MapsHooks::onArticleFromTitle';
$GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = 'MapsHooks::onMakeGlobalVariablesScript';
$GLOBALS['wgHooks']['CanonicalNamespaces'][] = 'MapsHooks::onCanonicalNamespaces'; $GLOBALS['wgHooks']['LoadExtensionSchemaUpdates'][] = 'MapsHooks::onLoadExtensionSchemaUpdates';
$GLOBALS['wgHooks']['ArticlePurge'][] = 'MapsHooks::onArticlePurge';
$GLOBALS['wgHooks']['LinksUpdateConstructed'][] = 'MapsHooks::onLinksUpdateConstructed';
$GLOBALS['wgHooks']['ParserAfterTidy'][] = 'MapsHooks::onParserAfterTidy';
$GLOBALS['wgHooks']['ParserClearState'][] = 'MapsHooks::onParserClearState';

// Parser hooks

Expand Down Expand Up @@ -146,11 +139,6 @@
return $instance->init( $parser );
};

$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
$instance = new MapsLayerDefinition();
return $instance->init( $parser );
};

// Geocoders

// Registration of the GeoNames service geocoder.
Expand All @@ -162,11 +150,6 @@
// Registration of the geocoder.us service geocoder.
$GLOBALS['wgHooks']['GeocoderFirstCallInit'][] = 'MapsGeocoderusGeocoder::register';

// Layers

// Registration of the image layer type.
$GLOBALS['wgHooks']['MappingLayersInitialization'][] = 'MapsImageLayer::register';

// Mapping services

// Include the mapping services that should be loaded into Maps.
Expand All @@ -187,9 +170,6 @@

require_once __DIR__ . '/Maps_Settings.php';

define( 'Maps_NS_LAYER' , $GLOBALS['egMapsNamespaceIndex'] + 0 );
define( 'Maps_NS_LAYER_TALK' , $GLOBALS['egMapsNamespaceIndex'] + 1 );

$GLOBALS['wgAvailableRights'][] = 'geocode';

// Users that can geocode. By default the same as those that can edit.
Expand Down
7 changes: 0 additions & 7 deletions Maps.resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@
],
],

'ext.maps.layers' => $moduleTemplate + [
'styles' => [
'ext.maps.layers.css'
]
],

'ext.maps.coord' => $moduleTemplate + [
'messages' => [
'maps-abb-north',
Expand Down Expand Up @@ -96,7 +90,6 @@
],
'dependencies' => [
'ext.maps.common',
'ext.maps.layers',
'ext.maps.coord'
]
]
Expand Down
3 changes: 0 additions & 3 deletions Maps_Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@
// Namespace index start of the mapping namespaces.
$GLOBALS['egMapsNamespaceIndex'] = 420;

// Boolean. Controls if you can specify images using a full path in layers.
$GLOBALS['egMapsAllowExternalImages'] = true;

// Boolean. Sets if pages with maps should be put in special category
$GLOBALS['egMapsEnableCategory'] = true;

Expand Down
61 changes: 1 addition & 60 deletions includes/Maps_DisplayMapRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,69 +224,10 @@ public static function evilOpenLayersHack( $layers ) {
$layerNames[] = $lcLayerOrGroup;
}
}
// Image layers. Check validity and add if not present yet:
else {
$layerParts = explode( ';', $layerOrGroup, 2 );
$layerGroup = $layerParts[0];
$layerName = count( $layerParts ) > 1 ? $layerParts[1] : null;

$title = Title::newFromText( $layerGroup, Maps_NS_LAYER );

if ( $title !== null && $title->getNamespace() == Maps_NS_LAYER ) {
// TODO: FIXME: This shouldn't be here and using $wgParser, instead it should
// be somewhere around MapsBaseMap::renderMap. But since we do a lot more than
// 'parameter manipulation' in here, we already diminish the information needed
// for this which will never arrive there.
global $wgParser;
// add dependency to the layer page so if the layer definition gets updated,
// the page where it is used will be updated as well:
$rev = Revision::newFromTitle( $title );
$revId = null;
if( $rev !== null ) {
$revId = $rev->getId();
}
$wgParser->getOutput()->addTemplate( $title, $title->getArticleID(), $revId );

// if the whole layer group is not yet loaded into the map and the group exists:
if( !in_array( $layerGroup, $layerNames )
&& $title->exists()
) {
if( $layerName !== null ) {
// load specific layer with name:
$layer = MapsLayers::loadLayer( $title, $layerName );
$layers = new MapsLayerGroup( $layer );
$usedLayer = $layerOrGroup;
}
else {
// load all layers from group:
$layers = MapsLayers::loadLayerGroup( $title );
$usedLayer = $layerGroup;
}

foreach( $layers->getLayers() as $layer ) {
if( ( // make sure named layer is only taken once (in case it was requested on its own before)
$layer->getName() === null
|| !in_array( $layerGroup . ';' . $layer->getName(), $layerNames )
)
&& $layer->isOk()
) {
$layerDefs[] = $layer->getJavaScriptDefinition();
}
}

$layerNames[] = $usedLayer; // have to add this after loop of course!
}
}
else {
wfWarn( "Invalid layer ($layerOrGroup) encountered after validation." );
}
}
}

MapsMappingServices::getServiceInstance( 'openlayers' )->addLayerDependencies( self::getLayerDependencies( $layerNames ) );

// print_r( $layerDefs );
// die();
return $layerDefs;
}

Expand All @@ -310,5 +251,5 @@ private static function getLayerDependencies( array $layerNames ) {

return array_unique( $layerDependencies );
}

}
Loading

0 comments on commit 9f7662b

Please sign in to comment.