Seb35 has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/374034 )
Change subject: Always verify an extension exists, even if the mechanism is
forced
......................................................................
Always verify an extension exists, even if the mechanism is forced
When an extension is loaded with a forced mechanism, it was not verified the
extension really exists; it is now the case.
Bug: T168807
Change-Id: I8146406a9a5139b8d86dcffd18c342fc16a2b94c
---
M src/MediaWikiFarmConfiguration.php
M tests/phpunit/ConfigurationTest.php
M tests/phpunit/data/config/extensionssettings.php
3 files changed, 40 insertions(+), 19 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiFarm
refs/changes/34/374034/1
diff --git a/src/MediaWikiFarmConfiguration.php
b/src/MediaWikiFarmConfiguration.php
index 458a247..9d70f51 100644
--- a/src/MediaWikiFarmConfiguration.php
+++ b/src/MediaWikiFarmConfiguration.php
@@ -424,32 +424,45 @@
$setting = 'wgUse' . preg_replace(
'/[^a-zA-Z0-9_\x7f\xff]/', '', $key );
$value =& $this->configuration['settings'][$setting];
+ # Extension is deactivated
if( $value === false ) {
$status = null;
unset( $this->configuration['extensions'][$key]
);
- } elseif( $ExtensionRegistry === null || $value ===
'composer' ) {
- if( $this->detectComposer( $type, $name ) ) {
- $status = 'composer';
- $value = true;
- } elseif( $value === 'composer' ) {
- $value = false;
- unset(
$this->configuration['extensions'][$key] );
- }
- } elseif( $value === 'require_once' || $value ===
'wfLoad' . ucfirst( $type ) ) {
+
+ # Mechanism Composer wanted
+ } elseif( $value === 'composer' &&
$this->detectComposer( $type, $name ) ) {
+ $status = 'composer';
+ $value = true;
+
+ # MediaWiki still not loaded: we must wait before
taking a decision
+ } elseif( $ExtensionRegistry === null ) {
+ # nop
+
+ # Mechanism require_once wanted
+ } elseif( $value === 'require_once' &&
$this->detectLoadingMechanism( $type, $name, true ) == $value ) {
$status = $value;
$value = true;
- // @codingStandardsIgnoreLine
MediaWiki.ControlStructures.AssignmentInControlStructures.AssignmentInControlStructures
- } elseif( $status = $this->detectLoadingMechanism(
$type, $name ) ) {
+
+ # Mechanism wfLoadSkin/wfLoadExtension wanted
+ } elseif( $value === 'wfLoad' . ucfirst( $type ) &&
$this->detectLoadingMechanism( $type, $name ) == $value ) {
+ $status = $value;
$value = true;
+
+ # Any mechanism to load the extension
+ // @codingStandardsIgnoreLine
MediaWiki.ControlStructures.AssignmentInControlStructures.AssignmentInControlStructures
+ } elseif( $value === true && $status =
$this->detectLoadingMechanism( $type, $name ) ) {
+ # nop
+
+ # Missing extension or wrong configuration value
} elseif( $key != 'ExtensionMediaWikiFarm' ) {
- if( $value ) {
- $this->farm->log[] = "Requested but
missing $type $name for wiki " .
- $this->farm->getVariable(
'$WIKIID' ) . ' in version ' .
- $this->farm->getVariable(
'$VERSION' );
- }
+ $this->farm->log[] = "Requested but missing
$type $name for wiki " .
+ $this->farm->getVariable( '$WIKIID' ) .
' in version ' .
+ $this->farm->getVariable( '$VERSION' );
$value = false;
$status = null;
unset( $this->configuration['extensions'][$key]
);
+
+ # MediaWikiFarm is specific because in a non-standard
location
} else {
$status = $ExtensionRegistry ?
'wfLoadExtension' : 'require_once';
}
@@ -513,9 +526,10 @@
*
* @param string $type Type, in ['extension', 'skin'].
* @param string $name Name of the extension/skin.
+ * @param string $preferedRO Prefered require_once mechanism.
* @return string|null Loading mechnism in ['wfLoadExtension',
'wfLoadSkin', 'require_once', 'composer'] or null if all mechanisms failed.
*/
- function detectLoadingMechanism( $type, $name ) {
+ function detectLoadingMechanism( $type, $name, $preferedRO = null ) {
# Search base directory
$base = $this->farm->getVariable( '$CODE' ) . '/' . $type . 's';
@@ -530,6 +544,11 @@
return null;
}
+ # A MyExtension.php file is in the directory -> assume it is
the loading mechanism
+ if( $preferedRO === true && is_file( $base . '/' . $name . '/'
. $name . '.php' ) ) {
+ return 'require_once';
+ }
+
# An extension.json/skin.json file is in the directory ->
assume it is the loading mechanism
if( $this->environment['ExtensionRegistry'] && is_file( $base .
'/' . $name . '/' . $type . '.json' ) ) {
return 'wfLoad' . ucfirst( $type );
diff --git a/tests/phpunit/ConfigurationTest.php
b/tests/phpunit/ConfigurationTest.php
index c1c9b3d..67a10da 100644
--- a/tests/phpunit/ConfigurationTest.php
+++ b/tests/phpunit/ConfigurationTest.php
@@ -299,6 +299,8 @@
$this->assertFalse( array_key_exists(
'wgUseExtensionConfirmEdit/QuestyCaptcha', $config ) );
$this->assertTrue( array_key_exists(
'wgUseExtensionConfirmEditQuestyCaptcha', $config ) );
$this->assertFalse(
$config['wgUseExtensionConfirmEditQuestyCaptcha'] );
+ $this->assertFalse(
$config['wgUseExtensionTestExtensionMissing'] );
+ $this->assertFalse( $config['wgUseSkinTestSkinMissing'] );
# Re-load to use config cache
AbstractMediaWikiFarmScript::rmdirr(
self::$wgMediaWikiFarmCacheDir . '/versions.php' );
diff --git a/tests/phpunit/data/config/extensionssettings.php
b/tests/phpunit/data/config/extensionssettings.php
index f0fc4de..bbb2b06 100644
--- a/tests/phpunit/data/config/extensionssettings.php
+++ b/tests/phpunit/data/config/extensionssettings.php
@@ -9,7 +9,7 @@
'atestextensionsfarm' => true,
'ctestextensionsfarm' => 'require_once',
'dtestextensionsfarm' => 'require_once',
- 'etestextensionsfarm' => true,
+ 'etestextensionsfarm' => 'wfLoadExtension',
),
'wgUseExtensionTestExtensionRequireOnce' => array(
'atestextensionsfarm' => true,
@@ -41,7 +41,7 @@
'wgUseSkinTestSkinBiLoading' => array(
'atestextensionsfarm' => true,
'dtestextensionsfarm' => 'require_once',
- 'etestextensionsfarm' => true,
+ 'etestextensionsfarm' => 'wfLoadSkin',
),
'wgUseSkinTestSkinRequireOnce' => array(
'atestextensionsfarm' => true,
--
To view, visit https://gerrit.wikimedia.org/r/374034
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8146406a9a5139b8d86dcffd18c342fc16a2b94c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MediaWikiFarm
Gerrit-Branch: master
Gerrit-Owner: Seb35 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits