Skip to content

Commit c1d314f

Browse files
committedJun 30, 2016
Fix "Cannot redeclare class" when using the tarball install, refs 1699, 1680
1 parent 86f7006 commit c1d314f

11 files changed

+241
-229
lines changed
 

‎SemanticMediaWiki.settings.php ‎DefaultSettings.php

+9-18
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
<?php
22

3-
namespace SMW;
4-
53
/**
6-
* SemanticMediaWiki default settings
4+
* DO NOT EDIT!
75
*
6+
* The following default settings are to be used by the extension itself,
7+
* please modify settings in the LocalSettings file.
8+
*
9+
* Most settings should be make between including this file and the call
10+
* to enableSemantics(). Exceptions that need to be set before are
11+
* documented below.
12+
*
13+
* @codeCoverageIgnore
814
*/
9-
10-
/**
11-
* @file
12-
* @ingroup SMW
13-
*/
14-
15-
#################################################################
16-
# CHANGING THE CONFIGURATION FOR SEMANTIC MEDIAWIKI #
17-
#################################################################
18-
# Do not change this file directly, but copy custom settings #
19-
# into your LocalSettings.php. Most settings should be make #
20-
# between including this file and the call to enableSemantics().#
21-
# Exceptions that need to be set before are documented below. #
22-
#################################################################
23-
2415
if ( !defined( 'MEDIAWIKI' ) ) {
2516
die( "This file is part of the Semantic MediaWiki extension. It is not a valid entry point.\n" );
2617
}

‎SemanticMediaWiki.php

+54-123
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<?php
22

3-
use SMW\NamespaceManager;
4-
use SMW\ApplicationFactory;
5-
use SMW\Setup;
6-
73
/**
84
* This documentation group collects source code files belonging to Semantic
95
* MediaWiki.
@@ -24,129 +20,64 @@
2420
return 1;
2521
}
2622

27-
define( 'SMW_VERSION', '2.4.0-rc1' );
28-
2923
if ( version_compare( $GLOBALS['wgVersion'], '1.19c', '<' ) ) {
3024
die( '<b>Error:</b> This version of Semantic MediaWiki requires MediaWiki 1.19 or above; use SMW 1.8.x for MediaWiki 1.18.x or 1.17.x.' );
3125
}
3226

33-
SemanticMediaWiki::initExtension();
34-
35-
$GLOBALS['wgExtensionFunctions'][] = function() {
36-
SemanticMediaWiki::onExtensionFunction();
37-
};
38-
3927
/**
40-
* @codeCoverageIgnore
28+
* THIS IS A TEMPORARY HACK to get around the #1699 issue in connection with the
29+
* tarball release that conflicts with the Composer autoloading when invoked
30+
* via the LocalSettings.
31+
*
32+
* By the time `extension.json` is used, the content from load.php is to be moved
33+
* into this file.
4134
*/
42-
class SemanticMediaWiki {
43-
44-
/**
45-
* As soon as Composer is autoloading this file, start the init process for some
46-
* components.
47-
*
48-
* @since 2.4
49-
*/
50-
public static function initExtension() {
51-
52-
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
53-
include_once __DIR__ . '/vendor/autoload.php';
54-
}
55-
56-
// Registration of the extension credits, see Special:Version.
57-
$GLOBALS['wgExtensionCredits']['semantic'][] = array(
58-
'path' => __FILE__,
59-
'name' => 'Semantic MediaWiki',
60-
'version' => SMW_VERSION,
61-
'author' => array(
62-
'[http://korrekt.org Markus Krötzsch]',
63-
'[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]',
64-
'James Hong Kong',
65-
'[https://www.semantic-mediawiki.org/wiki/Contributors ...]'
66-
),
67-
'url' => 'https://www.semantic-mediawiki.org',
68-
'descriptionmsg' => 'smw-desc',
69-
'license-name' => 'GPL-2.0+'
70-
);
71-
72-
// A flag used to indicate SMW defines a semantic extension type for extension credits.
73-
// @deprecated, removal in SMW 3.0
74-
define( 'SEMANTIC_EXTENSION_TYPE', true );
75-
76-
// Load class_alias
77-
require_once __DIR__ . '/includes/Aliases.php';
78-
79-
// Load global constants
80-
require_once __DIR__ . '/includes/Defines.php';
81-
82-
// Temporary measure to ease Composer/MW 1.22 migration
83-
require_once __DIR__ . '/includes/NamespaceManager.php';
84-
85-
// Load global functions
86-
require_once __DIR__ . '/includes/GlobalFunctions.php';
87-
88-
// Load default settings
89-
require_once __DIR__ . '/SemanticMediaWiki.settings.php';
90-
91-
// Because of MW 1.19 we need to register message files here
92-
$GLOBALS['wgMessagesDirs']['SemanticMediaWiki'] = $GLOBALS['smwgIP'] . 'i18n';
93-
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWiki'] = $GLOBALS['smwgIP'] . 'languages/SMW_Messages.php';
94-
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWikiAlias'] = $GLOBALS['smwgIP'] . 'languages/SMW_Aliases.php';
95-
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWikiMagic'] = $GLOBALS['smwgIP'] . 'languages/SMW_Magic.php';
96-
}
97-
98-
/**
99-
* Setup and initialization
100-
*
101-
* @note $wgExtensionFunctions variable is an array that stores
102-
* functions to be called after most of MediaWiki initialization
103-
* has finalized
104-
*
105-
* @see https://www.mediawiki.org/wiki/Manual:$wgExtensionFunctions
106-
*
107-
* @since 1.9
108-
*/
109-
public static function onExtensionFunction() {
110-
111-
// 3.x reverse the order to ensure that smwgMainCacheType is used
112-
// as main and smwgCacheType being deprecated with 3.x
113-
$GLOBALS['smwgMainCacheType'] = $GLOBALS['smwgCacheType'];
35+
require_once __DIR__ . "/load.php";
11436

115-
$applicationFactory = ApplicationFactory::getInstance();
116-
117-
$namespace = new NamespaceManager( $GLOBALS );
118-
$namespace->init();
119-
120-
$setup = new Setup( $applicationFactory, $GLOBALS, __DIR__ );
121-
$setup->run();
122-
}
123-
124-
/**
125-
* @since 2.4
126-
*
127-
* @return string|null
128-
*/
129-
public static function getVersion() {
130-
return SMW_VERSION;
131-
}
132-
133-
/**
134-
* @since 2.4
135-
*
136-
* @return array
137-
*/
138-
public static function getStoreVersion() {
139-
140-
$store = '';
141-
142-
if ( isset( $GLOBALS['smwgDefaultStore'] ) ) {
143-
$store = $GLOBALS['smwgDefaultStore'] . ( strpos( $GLOBALS['smwgDefaultStore'], 'SQL' ) ? '' : ' ['. $GLOBALS['smwgSparqlDatabaseConnector'] .']' );
144-
};
145-
146-
return array(
147-
'store' => $store,
148-
'db' => isset( $GLOBALS['wgDBtype'] ) ? $GLOBALS['wgDBtype'] : 'N/A'
149-
);
150-
}
151-
152-
}
37+
/**
38+
* `extension.json` should only be introduced by the time:
39+
*
40+
* - A major SMW release change (e.g. 3.x) occurs
41+
* - `requires` section in extension.json is supported for extensions
42+
* - MW 1.27 to be a minimum requirement
43+
*
44+
* @note Only remove the SemanticMediaWiki.php from the `files` section in the
45+
* composer.json, any other `files` entry remains to ensure that initial
46+
* settings, aliases are loaded before `wfLoadExtension( 'SemanticMediaWiki' );`
47+
* is invoked.
48+
*
49+
* Furthermore, remove the `require_once` from the SemanticMediaWiki::initExtension
50+
* as those are loaded using Composer.
51+
*
52+
* Expected format:
53+
*
54+
* {
55+
* "name": "Semantic MediaWiki",
56+
* "version": "3.0.0-alpha",
57+
* "author": [
58+
* "..."
59+
* ],
60+
* "url": "https://www.semantic-mediawiki.org",
61+
* "descriptionmsg": "smw-desc",
62+
* "license-name": "GPL-2.0+",
63+
* "type": "semantic",
64+
* "requires": {
65+
* "MediaWiki": ">= 1.27"
66+
* },
67+
* "MessagesDirs": {
68+
* "SemanticMediaWiki": [
69+
* "i18n"
70+
* ]
71+
* },
72+
* "AutoloadClasses": {
73+
* "SemanticMediaWiki": "SemanticMediaWiki.php"
74+
* },
75+
* "callback": "SemanticMediaWiki::initExtension",
76+
* "ExtensionFunctions": [
77+
* "SemanticMediaWiki::onExtensionFunction"
78+
* ],
79+
* "load_composer_autoloader":true,
80+
* "manifest_version": 1
81+
* }
82+
*
83+
*/

‎composer.json

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
"SMW\\Maintenance\\": "maintenance/"
7373
},
7474
"files" : [
75+
"src/Aliases.php",
76+
"src/Defines.php",
77+
"src/GlobalFunctions.php",
78+
"DefaultSettings.php",
7579
"SemanticMediaWiki.php"
7680
],
7781
"classmap": [

‎load.php

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
3+
use SMW\NamespaceManager;
4+
use SMW\ApplicationFactory;
5+
use SMW\Setup;
6+
7+
if ( !defined( 'MEDIAWIKI' ) ) {
8+
die( 'Not an entry point.' );
9+
}
10+
11+
SemanticMediaWiki::initExtension();
12+
13+
$GLOBALS['wgExtensionFunctions'][] = function() {
14+
SemanticMediaWiki::onExtensionFunction();
15+
};
16+
17+
/**
18+
* @codeCoverageIgnore
19+
*/
20+
class SemanticMediaWiki {
21+
22+
/**
23+
* As soon as Composer is autoloading this file, start the init process for some
24+
* components.
25+
*
26+
* @since 2.4
27+
*/
28+
public static function initExtension() {
29+
30+
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
31+
include_once __DIR__ . '/vendor/autoload.php';
32+
}
33+
34+
define( 'SMW_VERSION', '2.4.0-rc1' );
35+
36+
// Registration of the extension credits, see Special:Version.
37+
$GLOBALS['wgExtensionCredits']['semantic'][] = array(
38+
'path' => __FILE__,
39+
'name' => 'Semantic MediaWiki',
40+
'version' => SMW_VERSION,
41+
'author' => array(
42+
'[http://korrekt.org Markus Krötzsch]',
43+
'[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]',
44+
'James Hong Kong',
45+
'[https://www.semantic-mediawiki.org/wiki/Contributors ...]'
46+
),
47+
'url' => 'https://www.semantic-mediawiki.org',
48+
'descriptionmsg' => 'smw-desc',
49+
'license-name' => 'GPL-2.0+'
50+
);
51+
52+
// A flag used to indicate SMW defines a semantic extension type for extension credits.
53+
// @deprecated, removal in SMW 3.0
54+
define( 'SEMANTIC_EXTENSION_TYPE', true );
55+
56+
// Load class_alias
57+
require_once __DIR__ . '/src/Aliases.php';
58+
59+
// Load global constants
60+
require_once __DIR__ . '/src/Defines.php';
61+
62+
// Temporary measure to ease Composer/MW 1.22 migration
63+
require_once __DIR__ . '/includes/NamespaceManager.php';
64+
65+
// Load global functions
66+
require_once __DIR__ . '/src/GlobalFunctions.php';
67+
68+
// Load default settings
69+
require_once __DIR__ . '/DefaultSettings.php';
70+
71+
// Because of MW 1.19 we need to register message files here
72+
$GLOBALS['wgMessagesDirs']['SemanticMediaWiki'] = $GLOBALS['smwgIP'] . 'i18n';
73+
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWiki'] = $GLOBALS['smwgIP'] . 'languages/SMW_Messages.php';
74+
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWikiAlias'] = $GLOBALS['smwgIP'] . 'languages/SMW_Aliases.php';
75+
$GLOBALS['wgExtensionMessagesFiles']['SemanticMediaWikiMagic'] = $GLOBALS['smwgIP'] . 'languages/SMW_Magic.php';
76+
}
77+
78+
/**
79+
* Setup and initialization
80+
*
81+
* @note $wgExtensionFunctions variable is an array that stores
82+
* functions to be called after most of MediaWiki initialization
83+
* has finalized
84+
*
85+
* @see https://www.mediawiki.org/wiki/Manual:$wgExtensionFunctions
86+
*
87+
* @since 1.9
88+
*/
89+
public static function onExtensionFunction() {
90+
91+
// 3.x reverse the order to ensure that smwgMainCacheType is used
92+
// as main and smwgCacheType being deprecated with 3.x
93+
$GLOBALS['smwgMainCacheType'] = $GLOBALS['smwgCacheType'];
94+
95+
$applicationFactory = ApplicationFactory::getInstance();
96+
97+
$namespace = new NamespaceManager( $GLOBALS );
98+
$namespace->init();
99+
100+
$setup = new Setup( $applicationFactory, $GLOBALS, __DIR__ );
101+
$setup->run();
102+
}
103+
104+
/**
105+
* @since 2.4
106+
*
107+
* @return string|null
108+
*/
109+
public static function getVersion() {
110+
return SMW_VERSION;
111+
}
112+
113+
/**
114+
* @since 2.4
115+
*
116+
* @return array
117+
*/
118+
public static function getStoreVersion() {
119+
120+
$store = '';
121+
122+
if ( isset( $GLOBALS['smwgDefaultStore'] ) ) {
123+
$store = $GLOBALS['smwgDefaultStore'] . ( strpos( $GLOBALS['smwgDefaultStore'], 'SQL' ) ? '' : ' ['. $GLOBALS['smwgSparqlDatabaseConnector'] .']' );
124+
};
125+
126+
return array(
127+
'store' => $store,
128+
'db' => isset( $GLOBALS['wgDBtype'] ) ? $GLOBALS['wgDBtype'] : 'N/A'
129+
);
130+
}
131+
132+
}

‎maintenance/setupStore.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected function loadGlobalFunctions() {
9999
$smwgIP = dirname( __FILE__ ) . '/../';
100100
}
101101

102-
require_once ( $smwgIP . 'includes/GlobalFunctions.php' );
102+
require_once ( $smwgIP . 'src/GlobalFunctions.php' );
103103
}
104104

105105
protected function getStore() {
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎tests/phpunit/Unit/DefinesTest.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace SMW\Tests;
4+
5+
/**
6+
* @group semantic-mediawiki
7+
*
8+
* @license GNU GPL v2+
9+
* @since 1.9
10+
*
11+
* @author mwjames
12+
*/
13+
class DefinesTest extends \PHPUnit_Framework_TestCase {
14+
15+
/**
16+
* @dataProvider constantsDataProvider
17+
*/
18+
public function testConstants( $constant, $expected ) {
19+
$this->assertEquals( $expected, $constant );
20+
}
21+
22+
public function constantsDataProvider() {
23+
return array(
24+
array( SMW_HEADERS_SHOW, 2 ),
25+
array( SMW_HEADERS_PLAIN, 1 ),
26+
array( SMW_HEADERS_HIDE, 0 ),
27+
array( SMW_OUTPUT_HTML, 1 ),
28+
array( SMW_OUTPUT_WIKI, 2 ),
29+
array( SMW_OUTPUT_FILE, 3 ),
30+
array( SMW_FACTBOX_HIDDEN, 1 ),
31+
array( SMW_FACTBOX_SPECIAL, 2 ),
32+
array( SMW_FACTBOX_NONEMPTY, 3 ),
33+
array( SMW_FACTBOX_SHOWN, 5 ),
34+
);
35+
}
36+
37+
}

‎tests/phpunit/includes/GlobalFunctionsTest.php ‎tests/phpunit/Unit/GlobalFunctionsTest.php

+4-23
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
11
<?php
22

3-
namespace SMW\Test;
3+
namespace SMW\Tests;
44

55
/**
6-
* Tests for the GlobalFunctions
6+
* @group semantic-mediawiki
77
*
8+
* @license GNU GPL v2+
89
* @since 1.9
910
*
10-
* @file
11-
*
12-
* @licence GNU GPL v2+
1311
* @author mwjames
1412
*/
15-
16-
/**
17-
* Tests for the GlobalFunctions
18-
*
19-
*
20-
* @group SMW
21-
* @group SMWExtension
22-
*/
23-
class GlobalFunctionsTest extends SemanticMediaWikiTestCase {
24-
25-
/**
26-
* Returns the name of the class to be tested
27-
*
28-
* @return string|false
29-
*/
30-
public function getClass() {
31-
return false;
32-
}
13+
class GlobalFunctionsTest extends \PHPUnit_Framework_TestCase {
3314

3415
/**
3516
* @covers ::smwfGetLinker

‎tests/phpunit/includes/DefinesTest.php

-64
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.