SemanticMediaWiki /
SemanticMaps
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Initialization file for the Semantic Maps extension. |
||
| 5 | * |
||
| 6 | * @licence GNU GPL v2+ |
||
| 7 | * @author Jeroen De Dauw < [email protected] > |
||
| 8 | */ |
||
| 9 | |||
| 10 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
| 11 | die( 'Not an entry point.' ); |
||
| 12 | } |
||
| 13 | |||
| 14 | if ( defined( 'SM_VERSION' ) ) { |
||
| 15 | // Do not initialize more than once. |
||
| 16 | return 1; |
||
| 17 | } |
||
| 18 | |||
| 19 | if ( version_compare( $GLOBALS['wgVersion'], '1.23c', '<' ) ) { |
||
| 20 | throw new Exception( |
||
| 21 | 'This version of Semantic Maps requires MediaWiki 1.23 or above; use Semantic Maps 3.3.x for older versions.' |
||
| 22 | . ' See https://github.com/SemanticMediaWiki/SemanticMaps/blob/master/INSTALL.md for more info.' |
||
| 23 | ); |
||
| 24 | } |
||
| 25 | |||
| 26 | if ( !defined( 'Maps_VERSION' ) && is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
||
| 27 | include_once( __DIR__ . '/vendor/autoload.php' ); |
||
| 28 | } |
||
| 29 | |||
| 30 | if ( !defined( 'Maps_VERSION' ) ) { |
||
| 31 | throw new Exception( 'You need to have Maps installed in order to use Semantic Maps' ); |
||
| 32 | } |
||
| 33 | |||
| 34 | SemanticMaps::initExtension(); |
||
| 35 | |||
| 36 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
| 37 | SemanticMaps::onExtensionFunction(); |
||
| 38 | }; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @codeCoverageIgnore |
||
| 42 | */ |
||
| 43 | class SemanticMaps { |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @since 3.4 |
||
| 47 | */ |
||
| 48 | public static function initExtension() { |
||
|
0 ignored issues
–
show
|
|||
| 49 | |||
| 50 | // Load DefaultSettings |
||
| 51 | require_once __DIR__ . '/DefaultSettings.php'; |
||
| 52 | |||
| 53 | define( 'SM_VERSION', '3.4.0-alpha' ); |
||
| 54 | |||
| 55 | $GLOBALS['wgExtensionCredits']['semantic'][] = [ |
||
| 56 | 'path' => __FILE__, |
||
| 57 | 'name' => 'Semantic Maps', |
||
| 58 | 'version' => SM_VERSION, |
||
| 59 | 'author' => [ |
||
| 60 | '[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]' |
||
| 61 | ], |
||
| 62 | 'url' => 'https://github.com/SemanticMediaWiki/SemanticMaps/blob/master/README.md#semantic-maps', |
||
| 63 | 'descriptionmsg' => 'semanticmaps-desc', |
||
| 64 | 'license-name' => 'GPL-2.0+' |
||
| 65 | ]; |
||
| 66 | |||
| 67 | include_once __DIR__ . '/src/queryprinters/SM_QueryPrinters.php'; |
||
| 68 | |||
| 69 | $moduleTemplate = [ |
||
| 70 | 'position' => 'bottom', |
||
| 71 | 'localBasePath' => __DIR__ . '/src', |
||
| 72 | 'remoteExtPath' => 'SemanticMaps/src', |
||
| 73 | 'group' => 'ext.semanticmaps', |
||
| 74 | ]; |
||
| 75 | |||
| 76 | $GLOBALS['wgResourceModules']['ext.sm.forminputs'] = $moduleTemplate + [ |
||
| 77 | 'dependencies' => [ 'ext.maps.coord' ], |
||
| 78 | 'localBasePath' => __DIR__ . '/src/forminputs', |
||
| 79 | 'remoteExtPath' => 'SemanticMaps/src/forminputs', |
||
| 80 | 'scripts' => [ |
||
| 81 | 'jquery.mapforminput.js' |
||
| 82 | ], |
||
| 83 | 'messages' => [ |
||
| 84 | 'semanticmaps_enteraddresshere', |
||
| 85 | 'semanticmaps-updatemap', |
||
| 86 | 'semanticmaps_lookupcoordinates', |
||
| 87 | 'semanticmaps-forminput-remove', |
||
| 88 | 'semanticmaps-forminput-add', |
||
| 89 | 'semanticmaps-forminput-locations' |
||
| 90 | ] |
||
| 91 | ]; |
||
| 92 | |||
| 93 | $GLOBALS['wgResourceModules']['ext.sm.common'] = $moduleTemplate + [ |
||
| 94 | 'scripts' => [ |
||
| 95 | 'ext.sm.common.js' |
||
| 96 | ] |
||
| 97 | ]; |
||
| 98 | |||
| 99 | include_once __DIR__ . '/src/services/GoogleMaps3/SM_GoogleMaps3.php'; |
||
| 100 | include_once __DIR__ . '/src/services/Leaflet/SM_Leaflet.php'; |
||
| 101 | include_once __DIR__ . '/src/services/OpenLayers/SM_OpenLaysers.php'; |
||
| 102 | |||
| 103 | // Internationalization |
||
| 104 | $GLOBALS['wgMessagesDirs']['SemanticMaps'] = __DIR__ . '/i18n'; |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @since 3.4 |
||
| 109 | */ |
||
| 110 | public static function onExtensionFunction() { |
||
|
0 ignored issues
–
show
onExtensionFunction uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
Loading history...
|
|||
| 111 | |||
| 112 | $GLOBALS['wgHooks']['MappingServiceLoad'][] = function() { |
||
| 113 | MapsMappingServices::registerServiceFeature( 'openlayers', 'qp', 'SMMapPrinter' ); |
||
| 114 | return true; |
||
| 115 | }; |
||
| 116 | |||
| 117 | // Hook for initializing the Geographical Data types. |
||
| 118 | $GLOBALS['wgHooks']['SMW::DataType::initTypes'][] = 'SemanticMapsHooks::initGeoDataTypes'; |
||
| 119 | |||
| 120 | // Hook for defining the default query printer for queries that ask for geographical coordinates. |
||
| 121 | $GLOBALS['wgHooks']['SMWResultFormat'][] = 'SemanticMapsHooks::addGeoCoordsDefaultFormat'; |
||
| 122 | |||
| 123 | // Hook for adding a Semantic Maps links to the Admin Links extension. |
||
| 124 | $GLOBALS['wgHooks']['AdminLinks'][] = 'SemanticMapsHooks::addToAdminLinks'; |
||
| 125 | |||
| 126 | $GLOBALS['wgHooks']['sfFormPrinterSetup'][] = 'SemanticMaps\FormInputsSetup::run'; |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @since 3.4 |
||
| 131 | * |
||
| 132 | * @return string|null |
||
| 133 | */ |
||
| 134 | public static function getVersion() { |
||
| 135 | return SM_VERSION; |
||
| 136 | } |
||
| 137 | |||
| 138 | } |
||
| 139 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: