Foxtrott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/124373
Change subject: Initialize wgResourceModules early; improve cache handling
......................................................................
Initialize wgResourceModules early; improve cache handling
* the BootstrapManager expects initialized $wgResourceModules, so they need to
be -as far
as possible- initialized early to avoid errors from calls in LocalSettings
* the cache needs to be purged in case of a LESS compiler error
Change-Id: I52655511ad758e23deec46c5f0550a2f785e8154
---
M includes/BootstrapManager.php
M includes/Hooks.php
M includes/ResourceLoaderBootstrapModule.php
3 files changed, 26 insertions(+), 24 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Bootstrap
refs/changes/73/124373/1
diff --git a/includes/BootstrapManager.php b/includes/BootstrapManager.php
index 2a66b7c..7e926fc 100644
--- a/includes/BootstrapManager.php
+++ b/includes/BootstrapManager.php
@@ -178,8 +178,6 @@
if ( isset( $description[ $filetype ] ) ) {
- $path = $GLOBALS[ 'wgResourceModules' ][
'ext.bootstrap.' . $filetype ][ 'localBasePath' ];
-
$GLOBALS[ 'wgResourceModules' ][ 'ext.bootstrap.' .
$filetype ][ $filetype ] =
array_merge(
$GLOBALS[ 'wgResourceModules' ][
'ext.bootstrap.' . $filetype ][ $filetype ],
diff --git a/includes/Hooks.php b/includes/Hooks.php
index f0bad33..0566ee1 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -38,26 +38,22 @@
$localBasePath = $GLOBALS[ 'IP' ] . '/vendor/twitter/bootstrap';
$remoteBasePath = $GLOBALS[ 'wgScriptPath' ] .
'/vendor/twitter/bootstrap';
- // register skeleton resource module with the Resource Loader
- $GLOBALS[ 'wgResourceModules' ][ 'ext.bootstrap.styles' ] =
array(
- 'localBasePath' => $localBasePath . '/less',
- 'remoteBasePath' => $remoteBasePath. '/less',
- 'class' =>
'bootstrap\ResourceLoaderBootstrapModule',
- 'styles' => array(),
- 'variables' => array(
- 'icon-font-path' =>
"\"$remoteBasePath/fonts/\"",
+ // register if they do not yet exist
+ $GLOBALS[ 'wgResourceModules' ][ 'ext.bootstrap.styles' ] =
array_replace_recursive( array(
+ 'localBasePath' => $localBasePath . '/less',
+ 'remoteBasePath' => $remoteBasePath . '/less',
+ 'variables' => array(
+ 'icon-font-path' =>
"\"$remoteBasePath/fonts/\"",
+ ),
),
- 'dependencies' => array(),
+ $GLOBALS[ 'wgResourceModules' ][ 'ext.bootstrap.styles'
]
);
- $GLOBALS[ 'wgResourceModules' ][ 'ext.bootstrap.scripts' ] =
array(
- 'localBasePath' => $localBasePath . '/js',
- 'remoteBasePath' => $remoteBasePath. '/js',
- 'scripts' => array(),
- );
-
- $GLOBALS[ 'wgResourceModules' ][ 'ext.bootstrap' ] = array(
- 'dependencies' => array( 'ext.bootstrap.styles',
'ext.bootstrap.scripts' ),
+ $GLOBALS[ 'wgResourceModules' ][ 'ext.bootstrap.scripts' ] =
array_replace_recursive( array(
+ 'localBasePath' => $localBasePath . '/js',
+ 'remoteBasePath' => $remoteBasePath . '/js',
+ ),
+ $GLOBALS[ 'wgResourceModules' ][
'ext.bootstrap.scripts' ]
);
return true;
diff --git a/includes/ResourceLoaderBootstrapModule.php
b/includes/ResourceLoaderBootstrapModule.php
index 622139e..9887e5a 100644
--- a/includes/ResourceLoaderBootstrapModule.php
+++ b/includes/ResourceLoaderBootstrapModule.php
@@ -86,10 +86,7 @@
$this->retrieveStylesFromCache( $context );
if ( $this->styleText === null ) {
-
- $this->compileStyles();
- $this->updateCache( $context );
-
+ $this->compileStyles( $context );
}
}
@@ -128,7 +125,14 @@
}
- protected function compileStyles() {
+ protected function purgeCache( ResourceLoaderContext $context ) {
+
+ $cache = wfGetCache( CACHE_ANYTHING );
+ $cache->delete( $this->getCacheKey( $context ) );
+
+ }
+
+ protected function compileStyles( ResourceLoaderContext $context ) {
$parser = new \Less_Parser();
$remotePath = $this->getRemotePath( '' );
@@ -147,7 +151,11 @@
$this->styleText = $parser->getCss();
+ $this->updateCache( $context );
+
} catch ( \Exception $e ) {
+
+ $this->purgeCache( $context );
wfDebug( $e->getMessage() );
$this->styleText = '/* LESS compile error: ' .
$e->getMessage() . '*/';
}
--
To view, visit https://gerrit.wikimedia.org/r/124373
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I52655511ad758e23deec46c5f0550a2f785e8154
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Bootstrap
Gerrit-Branch: master
Gerrit-Owner: Foxtrott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits