Foxtrott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/132739
Change subject: Enable support for Visual Editor
......................................................................
Enable support for Visual Editor
* including test! o_O
* there will be a number of styling issues that have to be fixed, but it should
work
* new global: $egChameleonEnableVisualEditor (default: true)
Change-Id: I4e3ef39eaeb7d98e7bdf46e55bf58b2616f8aaee
---
M Chameleon.php
M README.md
M src/Hooks/SetupAfterCache.php
M tests/phpunit/Hooks/SetupAfterCacheTest.php
4 files changed, 136 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/skins/chameleon
refs/changes/39/132739/1
diff --git a/Chameleon.php b/Chameleon.php
index 273f70f..7b865f2 100644
--- a/Chameleon.php
+++ b/Chameleon.php
@@ -112,12 +112,16 @@
*/
$GLOBALS[ 'wgHooks' ][ 'SetupAfterCache' ][ ] = function() {
- $configuration = array(
- 'egChameleonExternalStyleModules' => isset( $GLOBALS[
'egChameleonExternalStyleModules' ] ) ? $GLOBALS[
'egChameleonExternalStyleModules' ] : array(),
- 'egChameleonExternalLessVariables' => isset( $GLOBALS[
'egChameleonExternalLessVariables' ] ) ? $GLOBALS[
'egChameleonExternalLessVariables' ] : array(),
- 'wgStyleDirectory' =>
$GLOBALS['wgStyleDirectory'],
- 'wgStylePath' =>
$GLOBALS['wgStylePath']
+ $configKeysToCopy = array(
+ 'egChameleonExternalStyleModules',
+ 'egChameleonExternalLessVariables',
+ 'egChameleonEnableVisualEditor',
+ 'wgStyleDirectory',
+ 'wgStylePath',
+ 'wgVisualEditorSupportedSkins',
);
+
+ $configuration = array_intersect_key( $GLOBALS, array_flip(
$configKeysToCopy));
$setupAfterCache = new \Skins\Chameleon\Hooks\SetupAfterCache(
\Bootstrap\BootstrapManager::getInstance(),
@@ -125,9 +129,14 @@
);
$setupAfterCache->process();
+
+ array_replace( $GLOBALS, $setupAfterCache->getConfiguration() );
};
// set default skin layout
$GLOBALS[ 'egChameleonLayoutFile' ] = dirname( __FILE__ ) .
'/layouts/standard.xml';
+ // enable the VisualEditor for this skin
+ $GLOBALS[ 'egChameleonEnableVisualEditor' ] = true;
+
} );
diff --git a/README.md b/README.md
index f5ad28f..7858709 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,10 @@
## Tests
-The extension provides unit tests that covers core-functionality normally run
by a continues integration platform. Tests can also be executed manually using
the [PHPUnit][mw-testing] configuration file found in the root directory.
+The extension provides unit tests that covers core-functionality normally run
by a continues integration platform. Tests can also be executed manually using
the [PHPUnit][mw-testing] configuration file found in the root directory:
+```sh
+php <MW-path>/tests/phpunit/phpunit.php -c
<MW-path>/skins/chameleon/phpunit.xml.dist --group skins-chameleon
+```
[mw-chameleon-skin]: https://www.mediawiki.org/wiki/Skin:Chameleon
[mw-bootstrap]: https://www.mediawiki.org/wiki/Extension:Bootstrap
diff --git a/src/Hooks/SetupAfterCache.php b/src/Hooks/SetupAfterCache.php
index 8b4ed0d..cc9a6f7 100644
--- a/src/Hooks/SetupAfterCache.php
+++ b/src/Hooks/SetupAfterCache.php
@@ -34,11 +34,42 @@
* @since 1.0
*/
public function process() {
+ $this->doLateSettings();
$this->registerCommonBootstrapModules();
$this->registerExternalStyleModules();
$this->registerExternalLessVariables();
}
+ /**
+ * @since 1.0
+ * @return array
+ */
+ public function getConfiguration() {
+ return $this->configuration;
+ }
+
+ protected function doLateSettings()
+ {
+
+ // if Visual Editor is installed and there is a setting to
enable or disable it
+ if ( isset( $this->configuration[
'wgVisualEditorSupportedSkins' ] ) && isset ( $this->configuration[
'egChameleonEnableVisualEditor' ] ) ) {
+
+ // if VE should be enabled
+ if ( $this->configuration[
'egChameleonEnableVisualEditor' ] === true ) {
+
+ // if Chameleon is not yet in the list of
VE-enabled skins
+ if ( !in_array( 'chameleon',
$this->configuration[ 'wgVisualEditorSupportedSkins' ] ) ) {
+ $this->configuration[
'wgVisualEditorSupportedSkins' ][ ] = 'chameleon';
+ }
+
+ } else {
+ // remove all entries of Chameleon from the
list of VE-enabled skins
+ $this->configuration[
'wgVisualEditorSupportedSkins' ] = array_diff($this->configuration[
'wgVisualEditorSupportedSkins' ], array('chameleon'));
+ }
+
+ }
+ }
+
protected function registerCommonBootstrapModules() {
$this->bootstrapManager->addAllBootstrapModules();
$this->bootstrapManager->addExternalModule(
diff --git a/tests/phpunit/Hooks/SetupAfterCacheTest.php
b/tests/phpunit/Hooks/SetupAfterCacheTest.php
index 04c5cd2..2ed28bd 100644
--- a/tests/phpunit/Hooks/SetupAfterCacheTest.php
+++ b/tests/phpunit/Hooks/SetupAfterCacheTest.php
@@ -148,4 +148,91 @@
$instance->process();
}
+ /**
+ * @dataProvider lateSettingsProvider
+ */
+ public function testProcessDoesLateSettings( $configuration, $result ) {
+
+ $bootstrapManager = $this->getMockBuilder(
'\Bootstrap\BootstrapManager' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $instance = new SetupAfterCache(
+ $bootstrapManager,
+ $configuration
+ );
+
+ $instance->process();
+
+ $this->assertEquals( $instance->getConfiguration(), $result );
+
+ }
+
+ /**
+ *
+ */
+ public function lateSettingsProvider() {
+
+ return array(
+
+ array (
+ array(
+ ),
+ array(
+ ),
+ ),
+
+ array (
+ array(
+ 'wgVisualEditorSupportedSkins' =>
array(),
+ ),
+ array(
+ 'wgVisualEditorSupportedSkins' =>
array(),
+ ),
+ ),
+
+ array (
+ array(
+ 'egChameleonEnableVisualEditor' => true,
+ ),
+ array(
+ 'egChameleonEnableVisualEditor' => true,
+ ),
+ ),
+
+ array (
+ array(
+ 'egChameleonEnableVisualEditor' => true,
+ 'wgVisualEditorSupportedSkins' =>
array( 'foo'),
+ ),
+ array(
+ 'egChameleonEnableVisualEditor' => true,
+ 'wgVisualEditorSupportedSkins' =>
array( 'foo', 'chameleon' ),
+ ),
+ ),
+
+ array (
+ array(
+ 'egChameleonEnableVisualEditor' => true,
+ 'wgVisualEditorSupportedSkins' =>
array( 'foo', 'chameleon' ),
+ ),
+ array(
+ 'egChameleonEnableVisualEditor' => true,
+ 'wgVisualEditorSupportedSkins' =>
array( 'foo', 'chameleon' ),
+ ),
+ ),
+
+ array (
+ array(
+ 'egChameleonEnableVisualEditor' =>
false,
+ 'wgVisualEditorSupportedSkins' =>
array( 'chameleon', 'foo' => 'chameleon', 'foo' ),
+ ),
+ array(
+ 'egChameleonEnableVisualEditor' =>
false,
+ 'wgVisualEditorSupportedSkins' =>
array( 1 => 'foo' ),
+ ),
+ ),
+
+ );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/132739
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4e3ef39eaeb7d98e7bdf46e55bf58b2616f8aaee
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/skins/chameleon
Gerrit-Branch: master
Gerrit-Owner: Foxtrott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits