MarkAHershberger has submitted this change and it was merged.
Change subject: installer: Run the LESS compiler for *.less files
......................................................................
installer: Run the LESS compiler for *.less files
Includes the following improvements:
* Use the ResourceLoader module definitions (with a hardcoded list of
module names) instead of a hardcoded list of filenames.
* Make the errors more discoverable like we do in load.php, prepending
them instead of burying them in the middle somewhere.
Bug: 55589
Change-Id: Iab78a60209ab46a10d4c492c75527e717f36f803
(cherry picked from commit 8cc7208753c45acf2c47f78b0569e18150f193a5)
---
M includes/installer/Installer.php
M includes/installer/WebInstallerOutput.php
M includes/resourceloader/ResourceLoader.php
M resources/Resources.php
4 files changed, 83 insertions(+), 33 deletions(-)
Approvals:
MarkAHershberger: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php
index 276c572..2f45005 100644
--- a/includes/installer/Installer.php
+++ b/includes/installer/Installer.php
@@ -1737,6 +1737,11 @@
// Some of the environment checks make shell requests, remove
limits
$GLOBALS['wgMaxShellMemory'] = 0;
+
+ // Don't bother embedding images into generated CSS, which is
not cached
+ $GLOBALS['wgResourceLoaderLESSFunctions']['embeddable'] =
function( $frame, $less ) {
+ return $less->toBool( false );
+ };
}
/**
diff --git a/includes/installer/WebInstallerOutput.php
b/includes/installer/WebInstallerOutput.php
index 1df8f05..f2dc37f 100644
--- a/includes/installer/WebInstallerOutput.php
+++ b/includes/installer/WebInstallerOutput.php
@@ -104,47 +104,83 @@
/**
* Get the raw vector CSS, flipping if needed
+ *
+ * @todo Possibly get rid of this function and use ResourceLoader in
the manner it was
+ * designed to be used in, rather than just grabbing a list of
filenames from it,
+ * and not properly handling such details as media types in module
definitions.
+ *
* @param string $dir 'ltr' or 'rtl'
* @return String
*/
public function getCSS( $dir ) {
- $skinDir = dirname( dirname( __DIR__ ) ) . '/skins';
-
- // All these files will be concatenated in sequence and loaded
- // as one file.
- // The string 'images/' in the files' contents will be replaced
- // by '../skins/$skinName/images/', where $skinName is what
appears
- // before the last '/' in each of the strings.
- $cssFileNames = array(
-
- // Basically the "skins.vector" ResourceLoader module
styles
- 'common/shared.css',
- 'common/commonElements.css',
- 'common/commonContent.css',
- 'common/commonInterface.css',
- 'vector/screen.css',
-
- // mw-config specific
- 'common/config.css',
+ // All CSS files these modules reference will be concatenated
in sequence
+ // and loaded as one file.
+ $moduleNames = array(
+ 'mediawiki.legacy.shared',
+ 'skins.vector',
+ 'mediawiki.legacy.config',
);
+ $prepend = '';
$css = '';
- wfSuppressWarnings();
- foreach ( $cssFileNames as $cssFileName ) {
- $fullCssFileName = "$skinDir/$cssFileName";
- $cssFileContents = file_get_contents( $fullCssFileName
);
- if ( $cssFileContents ) {
- preg_match( "/^(\w+)\//", $cssFileName, $match
);
- $skinName = $match[1];
- $css .= str_replace( 'images/',
"../skins/$skinName/images/", $cssFileContents );
- } else {
- $css .= "/** Your webserver cannot read
$fullCssFileName. Please check file permissions. */";
- }
+ $cssFileNames = array();
+ $resourceLoader = new ResourceLoader();
+ foreach ( $moduleNames as $moduleName ) {
+ $module = $resourceLoader->getModule( $moduleName );
+ $cssFileNames = $module->getAllStyleFiles();
- $css .= "\n";
+ wfSuppressWarnings();
+ foreach ( $cssFileNames as $cssFileName ) {
+ if ( !file_exists( $cssFileName ) ) {
+ $prepend .=
ResourceLoader::makeComment( "Unable to find $cssFileName." );
+ continue;
+ }
+
+ if ( !is_readable( $cssFileName ) ) {
+ $prepend .=
ResourceLoader::makeComment( "Unable to read $cssFileName. Please check file
permissions." );
+ continue;
+ }
+
+ try {
+
+ if ( preg_match( '/\.less$/',
$cssFileName ) ) {
+ // Run the LESS compiler for
*.less files (bug 55589)
+ $compiler =
ResourceLoader::getLessCompiler();
+ $cssFileContents =
$compiler->compileFile( $cssFileName );
+ } else {
+ // Regular CSS file
+ $cssFileContents =
file_get_contents( $cssFileName );
+ }
+
+ if ( $cssFileContents ) {
+ // Rewrite URLs, though don't
bother embedding images. While static image
+ // files may be cached, CSS
returned by this function is definitely not.
+ $cssDirName = dirname(
$cssFileName );
+ $css .= CSSMin::remap(
+ /* source */
$cssFileContents,
+ /* local */ $cssDirName,
+ /* remote */ '..' .
str_replace(
+ array(
$GLOBALS['IP'], DIRECTORY_SEPARATOR ),
+ array( '', '/'
),
+ $cssDirName
+ ),
+ /* embedData */ false
+ );
+ } else {
+ $prepend .=
ResourceLoader::makeComment( "Unable to read $cssFileName." );
+ }
+
+ } catch ( Exception $e ) {
+ $prepend .=
ResourceLoader::formatException( $e );
+ }
+
+ $css .= "\n";
+ }
+ wfRestoreWarnings();
}
- wfRestoreWarnings();
+
+ $css = $prepend . $css;
if ( $dir == 'rtl' ) {
$css = CSSJanus::transform( $css, true );
diff --git a/includes/resourceloader/ResourceLoader.php
b/includes/resourceloader/ResourceLoader.php
index ef999d9..6380efc 100644
--- a/includes/resourceloader/ResourceLoader.php
+++ b/includes/resourceloader/ResourceLoader.php
@@ -1223,6 +1223,13 @@
public static function getLessCompiler() {
global $wgResourceLoaderLESSFunctions,
$wgResourceLoaderLESSImportPaths;
+ // When called from the installer, it is possible that a
required PHP extension
+ // is missing (at least for now; see bug 47564). If this is the
case, throw an
+ // exception (caught by the installer) to prevent a fatal error
later on.
+ if ( !function_exists( 'ctype_digit' ) ) {
+ throw new MWException( 'lessc requires the Ctype
extension' );
+ }
+
$less = new lessc();
$less->setPreserveComments( true );
$less->setVariables( self::getLESSVars() );
diff --git a/resources/Resources.php b/resources/Resources.php
index 2c02de8..ec6c71b 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -87,7 +87,7 @@
'localBasePath' => $GLOBALS['wgStyleDirectory'],
),
'skins.vector' => array(
- // Keep in sync with WebInstallerOutput::getCSS()
+ // Used in the web installer. Test it after modifying this
definition!
'styles' => array(
'common/commonElements.css' => array( 'media' =>
'screen' ),
'common/commonContent.css' => array( 'media' =>
'screen' ),
@@ -1109,8 +1109,9 @@
'localBasePath' => $GLOBALS['wgStyleDirectory'],
),
'mediawiki.legacy.config' => array(
+ // Used in the web installer. Test it after modifying this
definition!
'scripts' => 'common/config.js',
- 'styles' => array( 'common/config.css', 'common/config-cc.css'
),
+ 'styles' => array( 'common/config.css' ),
'remoteBasePath' => $GLOBALS['wgStylePath'],
'localBasePath' => $GLOBALS['wgStyleDirectory'],
'dependencies' => 'mediawiki.legacy.wikibits',
@@ -1132,6 +1133,7 @@
'position' => 'top',
),
'mediawiki.legacy.shared' => array(
+ // Used in the web installer. Test it after modifying this
definition!
'styles' => array( 'common/shared.css' => array( 'media' =>
'screen' ) ),
'remoteBasePath' => $GLOBALS['wgStylePath'],
'localBasePath' => $GLOBALS['wgStyleDirectory'],
--
To view, visit https://gerrit.wikimedia.org/r/92462
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iab78a60209ab46a10d4c492c75527e717f36f803
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: REL1_22
Gerrit-Owner: MarkAHershberger <[email protected]>
Gerrit-Reviewer: MarkAHershberger <[email protected]>
Gerrit-Reviewer: PleaseStand <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits