summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Bootstrap/Bootstrap.php
blob: 805c04345aa4046096deab6819220392b34fe3a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
 * An extension providing the Bootstrap library to other extensions
 *
 * @see      https://www.mediawiki.org/wiki/Extension:Bootstrap
 * @see      https://getbootstrap.com/
 *
 * @author   Stephan Gambke
 *
 * @defgroup Bootstrap Bootstrap
 */

/**
 * The main file of the Bootstrap extension
 *
 * @copyright (C) 2013 - 2018, Stephan Gambke
 * @license       https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License, version 3 (or later)
 *
 * This file is part of the MediaWiki extension Bootstrap.
 * The Bootstrap extension is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * The Bootstrap extension is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * @file
 * @ingroup       Bootstrap
 *
 * @codeCoverageIgnore
 */
call_user_func( function () {

	if ( !defined( 'MEDIAWIKI' ) ) {
		die( 'This file is part of the MediaWiki extension Bootstrap, it is not a valid entry point.' );
	}

	if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.22', 'lt' ) ) {
		die( '<b>Error:</b> This version of <a href="https://www.mediawiki.org/wiki/Extension:Bootstrap">Bootstrap</a> is only compatible with MediaWiki 1.22 or above. You need to upgrade MediaWiki first.' );
	}

	/**
	 * The extension version
	 */
	define( 'BS_VERSION', '1.3.0' );

	// register the extension
	$GLOBALS[ 'wgExtensionCredits' ][ 'other' ][ ] = array(
		'path'           => __FILE__,
		'name'           => 'Bootstrap',
		'author' => array( '[https://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]', 'James Hong Kong' ),
		'url'            => 'https://www.mediawiki.org/wiki/Extension:Bootstrap',
		'descriptionmsg' => 'bootstrap-desc',
		'version'        => BS_VERSION,
		'license-name'   => 'GPL-3.0+',
	);

	// register message files
	$GLOBALS[ 'wgMessagesDirs' ][ 'Bootstrap' ] = __DIR__ . '/i18n';
	$GLOBALS[ 'wgExtensionMessagesFiles' ][ 'Bootstrap' ] = __DIR__ . '/Bootstrap.i18n.php';

	// register classes
	$GLOBALS[ 'wgAutoloadClasses' ][ 'Bootstrap\ResourceLoaderBootstrapModule' ] = __DIR__ . '/src/ResourceLoaderBootstrapModule.php';
	$GLOBALS[ 'wgAutoloadClasses' ][ 'Bootstrap\BootstrapManager' ]      = __DIR__ . '/src/BootstrapManager.php';
	$GLOBALS[ 'wgAutoloadClasses' ][ 'Bootstrap\Hooks\SetupAfterCache' ] = __DIR__ . '/src/Hooks/SetupAfterCache.php';
	$GLOBALS[ 'wgAutoloadClasses' ][ 'Bootstrap\Definition\ModuleDefinition' ]   = __DIR__ . '/src/Definition/ModuleDefinition.php';
	$GLOBALS[ 'wgAutoloadClasses' ][ 'Bootstrap\Definition\V3ModuleDefinition' ] = __DIR__ . '/src/Definition/V3ModuleDefinition.php';

	$GLOBALS[ 'wgHooks' ][ 'SetupAfterCache' ][ ] = function() {

		$configuration = array();
		$configuration[ 'IP' ] = $GLOBALS[ 'IP' ];
		$configuration[ 'remoteBasePath' ] = $GLOBALS[ 'wgExtensionAssetsPath' ] . '/Bootstrap/resources/bootstrap';

		if ( isset( $GLOBALS[ 'wgExtensionDirectory' ] ) ) { // MW >= 1.25
			$configuration[ 'localBasePath' ] = $GLOBALS[ 'wgExtensionDirectory' ] . '/Bootstrap/resources/bootstrap';
		} else {
			$configuration[ 'localBasePath' ] = __DIR__ . '/resources/bootstrap';
		}

		$setupAfterCache = new \Bootstrap\Hooks\SetupAfterCache( $configuration );
		$setupAfterCache->process();
	};

	// register skeleton resource module with the Resource Loader
	// do not add paths, globals are not set yet
	$GLOBALS[ 'wgResourceModules' ][ 'ext.bootstrap.styles' ] = array(
		'class'          => 'Bootstrap\ResourceLoaderBootstrapModule',
		'position'       => 'top',
		'styles'         => array(),
		'variables'      => array(),
		'dependencies'   => array(),
		'cachetriggers'   => array(
			'LocalSettings.php' => null,
			'composer.lock'     => null,
		),
	);

	$GLOBALS[ 'wgResourceModules' ][ 'ext.bootstrap.scripts' ] = array(
		'scripts'        => array(),
	);

	$GLOBALS[ 'wgResourceModules' ][ 'ext.bootstrap' ] = array(
		'dependencies' => array( 'ext.bootstrap.styles', 'ext.bootstrap.scripts' ),
	);

} );