Skip to content

Commit

Permalink
SUS-2587: Implement MW 1.19 compatibility (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Máté Szabó authored Jan 24, 2018
1 parent 4c1d0a8 commit e4f1b2b
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

!.*
.idea/
*.iml

vendor/
extensions/

composer.phar
composer.lock
composer.lock
17 changes: 16 additions & 1 deletion Maps.hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class MapsHooks {
*
* @return boolean
*/
public static function addToAdminLinks( ALTree &$admin_links_tree ) {
public static function addToAdminLinks( ALTree $admin_links_tree ) {
$displaying_data_section = $admin_links_tree->getSection(
wfMessage( 'smw_adminlinks_displayingdata' )->text()
);
Expand Down Expand Up @@ -61,4 +61,19 @@ public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $ou
return true;
}

public static function onOutputPageParserOutput( OutputPage $out, ParserOutput $parserOutput ) {
if ( !isset( $parserOutput->mapsMappingServices ) ) {
return;
}

/** @var MapsMappingService $service */
foreach ( $parserOutput->mapsMappingServices as $service ) {
$html = $service->getDependencyHtml();

if ( $html ) {
$out->addHTML( $html );
}
}
}

}
36 changes: 36 additions & 0 deletions Maps.i18n.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* Beginning with MediaWiki 1.23, translation strings are stored in json files,
* and the EXTENSION.i18n.php file only exists to provide compatibility with
* older releases of MediaWiki. For more information about this migration, see:
* https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format
*
* This shim maintains compatibility back to MediaWiki 1.17.
*/

$messages = [];

if ( !function_exists( 'wfJsonI18nShimWikiaMaps' ) ) {
function wfJsonI18nShimWikiaMaps( $cache, $code, &$cachedData ) {
$codeSequence = array_merge( [ $code ], $cachedData['fallbackSequence'] );
foreach ( $codeSequence as $csCode ) {
$fileName = __DIR__ . "/i18n/$csCode.json";
if ( is_readable( $fileName ) ) {
$data = FormatJson::decode( file_get_contents( $fileName ), true );
foreach ( array_keys( $data ) as $key ) {
if ( $key === '' || $key[0] === '@' ) {
unset( $data[$key] );
}
}
$cachedData['messages'] = array_merge( $data, $cachedData['messages'] );
}

$cachedData['deps'][] = new FileDependency( $fileName );
}

return true;
}

$GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 'wfJsonI18nShimWikiaMaps';
}
23 changes: 10 additions & 13 deletions Maps.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

// Internationalization
$GLOBALS['wgMessagesDirs']['Maps'] = __DIR__ . '/i18n';
$GLOBALS['wgExtensionMessagesFiles']['Maps'] = __DIR__ . '/Maps.i18n.php'; // Wikia change
$GLOBALS['wgExtensionMessagesFiles']['MapsMagic'] = __DIR__ . '/Maps.i18n.magic.php';
$GLOBALS['wgExtensionMessagesFiles']['MapsAlias'] = __DIR__ . '/Maps.i18n.alias.php';

Expand All @@ -61,12 +62,7 @@
throw new Exception( 'You need to have Validator installed in order to use Maps' );
}

if ( version_compare( $GLOBALS['wgVersion'], '1.27c', '<' ) ) {
throw new Exception(
'This version of Maps requires MediaWiki 1.27 or above; use Maps 4.2.x for older versions.'
. ' More information at https://github.com/JeroenDeDauw/Maps/blob/master/INSTALL.md'
);
}
// Wikia change - hardcoded exception was removed here

define( 'Maps_VERSION', '5.2.0 alpha' );
define( 'SM_VERSION', Maps_VERSION );
Expand Down Expand Up @@ -101,41 +97,42 @@

$GLOBALS['wgHooks']['AdminLinks'][] = 'MapsHooks::addToAdminLinks';
$GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = 'MapsHooks::onMakeGlobalVariablesScript';
$GLOBALS['wgHooks']['OutputPageParserOutput'][] = 'MapsHooks::onOutputPageParserOutput';

// Parser hooks

// Required for #coordinates.
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser $parser ) {
$instance = new MapsCoordinates();
return $instance->init( $parser );
};

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

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

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

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

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

$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser $parser ) {
$instance = new MapsMapsDoc();
return $instance->init( $parser );
};
Expand Down
2 changes: 1 addition & 1 deletion Maps_Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
$GLOBALS['egMapsEnableGeoCache'] = true;
// Integer. If egMapsEnableGeoCache is true, determines the TTL of cached geocoded addresses.
// Default value: 1 day.
$GLOBALS['egMapsGeoCacheTtl'] = BagOStuff::TTL_DAY;
$GLOBALS['egMapsGeoCacheTtl'] = 86400;


// Coordinate configuration
Expand Down
15 changes: 13 additions & 2 deletions includes/Maps_DisplayMapRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,21 @@ public final function renderMap( array $params, Parser $parser ) {
);

$parserOutput = $parser->getOutput();

$this->service->addDependencies( $parserOutput );
$parserOutput->addHeadItem( $configVars );

// Wikia change - defer adding service html dependencies
// They will be handled in OutputPageParserOutput hook handler

$parserOutput->addModules( $this->service->getResourceModules() );

$parserOutput->mapsMappingServices = $parserOutput->mapsMappingServices ?? [];

$serviceName = $this->service->getName();

$parserOutput->mapsMappingServices[$serviceName] = $this->service;

// end Wikia change

return $output;
}

Expand Down
10 changes: 9 additions & 1 deletion includes/api/ApiGeocode.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,19 @@ public function getDescription() {
];
}

protected function getExamples() {
// Wikia change - make method public for MW 1.19 compat
public function getExamples() {
return [
'api.php?action=geocode&locations=new york',
'api.php?action=geocode&locations=new york|brussels|london',
];
}

/**
* Wikia change - implement MW 1.19 required method
* @return string
*/
public function getVersion() {
return Maps_VERSION;
}
}
1 change: 1 addition & 0 deletions includes/services/Leaflet/Maps_Leaflet.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public function getResourceModules() {

protected function getDependencies() {
$leafletPath = $GLOBALS['wgScriptPath'] . '/extensions/Maps/includes/services/Leaflet/leaflet';

return [
Html::linkedStyle( "$leafletPath/leaflet.css" ),
Html::linkedScript( "$leafletPath/leaflet.js" ),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
if (typeof define === 'function' && !define.amd) {
// AMD. Register as an anonymous module.
define(['leaflet'], factory);
} else if (typeof modules === 'object' && module.exports) {
Expand Down
2 changes: 1 addition & 1 deletion includes/services/Leaflet/leaflet/leaflet.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/Geocoders/CachingGeocoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function __construct( Geocoder $geocoder, BagOStuff $cache, int $cacheTtl
* @return LatLongValue|null
*/
public function geocode( string $address ) {
$key = $this->cache->makeKey( __CLASS__, $address );
// Wikia change - wfMemcKey for 1.19 compatibility
$key = wfMemcKey( __CLASS__, $address );

$coordinates = $this->cache->get( $key );

Expand Down

0 comments on commit e4f1b2b

Please sign in to comment.