Dvogel hallowelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/263056

Change subject: Flexiskin: New RL implementation
......................................................................

Flexiskin: New RL implementation

Due to path traversal issues the resource loader implementation was
reworked.

Change-Id: I7657985030d2fdb2d1fa8da322febef373557bc2
---
M Flexiskin/Flexiskin.class.php
M Flexiskin/Flexiskin.setup.php
M Flexiskin/includes/FlexiskinApi.class.php
M Flexiskin/includes/FlexiskinFormatter.class.php
A Flexiskin/includes/resourceloader/ResourceLoaderFlexiskinModule.php
A Flexiskin/includes/resourceloader/ResourceLoaderFlexiskinPreviewModule.php
6 files changed, 158 insertions(+), 224 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions 
refs/changes/56/263056/1

diff --git a/Flexiskin/Flexiskin.class.php b/Flexiskin/Flexiskin.class.php
index e4f8912..c64a061 100644
--- a/Flexiskin/Flexiskin.class.php
+++ b/Flexiskin/Flexiskin.class.php
@@ -52,8 +52,7 @@
                        EXTINFO::VERSION => 'default',
                        EXTINFO::STATUS => 'default',
                        EXTINFO::PACKAGE => 'default',
-                       EXTINFO::URL => 
'https://help.bluespice.com/index.php/FlexiSkin',
-                       EXTINFO::DEPS => array( 'bluespice' => '2.22.0' )
+                       EXTINFO::URL => 
'https://help.bluespice.com/index.php/FlexiSkin'
                );
                $this->mExtensionKey = 'MW::Flexiskin';
 
@@ -67,94 +66,15 @@
        }
 
        /**
-        * Initialization of ArticleInfo extension
+        * Initialization of Flexiskin extension
         */
        public function initExt() {
                wfProfileIn( 'BS::' . __METHOD__ );
+
                BsConfig::registerVar( 'MW::Flexiskin::Active', "default", 
BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_STRING | 
BsConfig::USE_PLUGIN_FOR_PREFS, 'bs-flexiskin-pref-active', 'select' );
-               BsConfig::registerVar( 'MW::Flexiskin::Logo', "", 
BsConfig::LEVEL_PUBLIC | BsConfig::TYPE_STRING | 
BsConfig::USE_PLUGIN_FOR_PREFS, 'bs-flexiskin-pref-logo', 'text' );
-
-               $sFlexiskin = $this->getRequest()->getVal( 'flexiskin', '' );
-               if( $this->getRequest()->getSessionData( "sPreviewSkin" ) !== 
NULL){
-                       $sPreviewSkin = $this->getRequest()->getSessionData( 
"sPreviewSkin" );
-               } else {
-                       $sPreviewSkin = FALSE;
-               }
-
-               $oResponse = $this->getRequest()->response();
-               $oRequest = $this->getRequest();
-               //this statemenet is just for setting the cookie, this is why 
we need to do some checks here
-               //check if the request comes via index.php, flexiskin is set in 
query and if you are in view mode (block some ajax requests)
-
-               $sPreview = false;
-               $sFlexiskin = $sFlexiskin == '' ? $sPreviewSkin : $sFlexiskin;
-               if ( strpos( wfGetScriptUrl(), "index.php" ) !== false && 
$sFlexiskin !== "" && $oRequest->getVal( 'action', 'view' ) === 'view' ) {
-                       $bIsTemp = (bool) $oRequest->getBool( 'preview', false 
);
-                       //is it in preview mode?
-                       //set the session
-                       if ( $bIsTemp ) {
-                               $this->getRequest()->setSessionData( 
"sPreviewSkin", $sFlexiskin );
-                               $sPreviewSkin = $sFlexiskin;
-                       //or just unset it
-                       } else {
-                               $this->getRequest()->setSessionData( 
"sPreviewSkin", NULL );
-                               $sPreviewSkin = false;
-                       }
-               }
-               $sFlexiskin = $sFlexiskin == '' ? $sPreviewSkin : $sFlexiskin;
-               if ( $sFlexiskin != "" || BsConfig::get( 
'MW::Flexiskin::Active' ) != '' || $sPreviewSkin ) {
-                       $sId = $sFlexiskin != '' ? $sFlexiskin : BsConfig::get( 
'MW::Flexiskin::Active' );
-                       if ( $sId != "default" || $sPreviewSkin !== false ) {
-                               $this->addCssFile( $sId, $sPreviewSkin !== 
false );
-                               if ( $sPreviewSkin ) {
-                                       //reset resource loader cache for 
preview
-                                       global $wgResourceLoaderMaxage;
-                                       $wgResourceLoaderMaxage = array (
-                                               'versioned' => array ( 'server' 
=> 1, 'client' => 1 ),
-                                               'unversioned' => array ( 
'server' => 1, 'client' => 1 ),
-                                       );
-                               }
-                       }
-               }
                $this->mCore->registerPermission( 'flexiskinedit', array(), 
array( 'type' => 'global' ) );
+
                wfProfileOut('BS::' . __METHOD__);
-       }
-
-       /**
-        * Replaces the BlueSpiceSkin screen.less file with the one specified 
by the parameters
-        * @global string $wgResourceModules
-        * @param string $sFlexiskinId
-        * @param int $bIsTemp
-        * @return boolean true of replaced correctly, otherwise false
-        */
-       public function addCssFile( $sFlexiskinId, $bIsTemp = false ) {
-               global $wgResourceModules;
-               global $wgScriptPath;
-
-               $sPreviewTimestamp = $this->getRequest()->getSessionData( 
'PreviewTimestamp' );
-               $oStatus = BsFileSystemHelper::ensureDataDirectory( 
"flexiskin/" . $sFlexiskinId );
-               if ( !$oStatus->isGood() ) {
-                       return false;
-               }
-
-               $sFilePath = BsFileSystemHelper::getDataPath("flexiskin/" . 
$sFlexiskinId);
-               $sFilePath .= "/screen" . ($bIsTemp ? '.' . $sPreviewTimestamp 
. '.tmp' : '') . ".less";
-               $sFilePath = str_replace($wgScriptPath, "..", $sFilePath);
-
-               if ( !isset( $wgResourceModules['skins.bluespiceskin'] ) ||
-                               !isset( 
$wgResourceModules['skins.bluespiceskin']['styles'] ) ) {
-                       return false;
-               }
-               foreach ( $wgResourceModules['skins.bluespiceskin']['styles'] 
as $iIndex => $sStylePath ) {
-                       //check if element ends with "screen.less"
-                       if ( strpos( $sStylePath, "screen.less", strlen( 
$sStylePath ) - strlen( "screen.less" ) ) === false ) {
-                               continue;
-                       }
-                       
$wgResourceModules['skins.bluespiceskin']['styles'][$iIndex] = $sFilePath;
-
-                       return true;
-               }
-               return false;
        }
 
        public function getForm() {
@@ -168,12 +88,15 @@
                }
 
                $api = new ApiMain(
-                               new DerivativeRequest(
-                               $this->getRequest(), array(
-                       'action' => 'flexiskin',
-                       'type' => 'get'
-                               ), false
-                               ), true
+                       new DerivativeRequest(
+                               $this->getRequest(),
+                               array(
+                                       'action' => 'flexiskin',
+                                       'type' => 'get'
+                               ),
+                               false
+                       ),
+                       true
                );
                $oResult = $api->execute();
                $aData = $api->getResultData();
@@ -213,38 +136,7 @@
                if ( !$bReturn ) {
                        return array();
                }
-               return FormatJson::encode($aConfig);
-       }
-
-       public static function generateScreenFile($bIsTmp = false){
-               $sPreviewTimestamp = 
RequestContext::getMain()->getRequest()->getSessionData( 'PreviewTimestamp' );
-               $aScreenFile = array();
-               $aScreenFile[] = "@import 
'../../../../skins/BlueSpiceSkin/resources/variables.less';";
-               $aScreenFile[] = "@import 'variables.".($bIsTmp ? 
$sPreviewTimestamp . ".tmp." : "")."less';";
-               $aScreenFile[] = "@import 
'../../../../skins/BlueSpiceSkin/resources/screen.layout.less';";
-               $aScreenFile[] = "@import 
'../../../../skins/BlueSpiceSkin/resources/components.less';";
-               return implode("\n", $aScreenFile);
-       }
-
-       public static function generateStyleFile( $aConfigs ) {
-               $aFile = array();
-               if ( !is_array( $aConfigs ) ) {
-                       $aConfigs = FormatJson::decode( $aConfigs );
-               }
-               $aFile[] = '@bs-skin-path: 
"../../../../skins/BlueSpiceSkin/resources/";';
-               $sNewId = self::getFlexiskinIdFromConfig($aConfigs);
-               foreach ( $aConfigs as $aConfig ) {
-                       $func = "FlexiskinFormatter::format_" . $aConfig->id;
-                       $bReturn = wfRunHooks( "BSFlexiskinGenerateStyleFile", 
array( &$func, &$aConfig ) );
-
-                       if ( $bReturn === true && is_callable( $func ) ) {
-                               $aFile[] = call_user_func_array( $func, array( 
$aConfig, $sNewId) );
-                       }
-                       else{
-                               wfDebug("BS::Flexiskin method " . $func . " 
could not be called.");
-                       }
-               }
-               return implode( " \n", $aFile );
+               return FormatJson::encode($aConfig, true);
        }
        
        public static function getFlexiskinIdFromConfig($aConfig){
@@ -259,49 +151,40 @@
        }
 
        /**
-        * Modifies the logo on runtime
-        * @param SkinTemplate $sktemplate
-        * @param BaseTemplate $tpl
-        * @return boolean Always true to keep hook running
+        *
+        * @param OutputPage $out
+        * @return boolean
         */
-       public static function onSkinTemplateOutputPageBeforeExec( 
&$sktemplate, &$tpl ) {
-               $sFlexiskin = $sktemplate->getRequest()->getVal( 'flexiskin' );
-               if ( $sFlexiskin || BsConfig::get( 'MW::Flexiskin::Active' ) != 
'' ) {
-                       $sId = $sFlexiskin != '' ? $sFlexiskin : BsConfig::get( 
'MW::Flexiskin::Active' );
-                       if ( $sId != "default" ) {
-                               $bPreview = $sktemplate->getRequest()->getVal( 
'preview', false );
-                               $api = new ApiMain(
-                                               new DerivativeRequest(
-                                                       
$sktemplate->getRequest(),
-                                                       array(
-                                                               'action' => 
'flexiskin',
-                                                               'type' => 'get',
-                                                               'mode' => 
'config',
-                                                               'id' => $sId,
-                                                               'preview' => 
$bPreview
-                                                       ),
-                                                       false
-                                               ),
-                                               true
-                               );
-                               $api->execute();
-                               $aResult = $api->getResultData();
-                               $oResult = FormatJson::decode( 
$aResult['flexiskin'] );
-                               if ($oResult->success === false){
-                                       return true;
-                               }
-                               $aConfig = FormatJson::decode($oResult->config);
-                               $sLogo = BsConfig::get("MW::Flexiskin::Logo");
-                               if ( $sLogo == "" ) {
-                                       return true;
-                               }
-                               $sPath = BS_DATA_PATH . "/flexiskin/" . $sId . 
"/images/";
-                               $tpl->set( 'logopath', $sPath . $sLogo );
-                               return true;
-                       }
-                       return true;
+       public static function onBeforePageDisplay( &$out ) {
+               $inPreviewMode = $out->getRequest()->getBool('preview');
+
+               if( $inPreviewMode && $out->getRequest()->getVal( 'flexiskin' ) 
!== null ) {
+                       $out->getRequest()->setSessionData('flexiskin', 
$out->getRequest()->getVal( 'flexiskin' ) );
+                       $out->addModuleStyles( 
'ext.bluespice.flexiskin.skin.preview' );
                }
+               else {
+                       $out->addModuleStyles( 
Flexiskin::generateDynamicModuleStyleName() );
+               }
+
                return true;
        }
 
+       /**
+        *
+        * @param ResourceLoader $resourceLoader
+        * @return boolean
+        */
+       public static function onResourceLoaderRegisterModules( 
&$resourceLoader ) {
+               $resourceLoader->register(
+                       Flexiskin::generateDynamicModuleStyleName(),
+                       array(
+                               'class' => 'FlexiskinResourceLoaderModule'
+                       )
+               );
+               return true;
+       }
+
+       public static function generateDynamicModuleStyleName(){
+               return 'ext.bluespice.flexiskin.skin.' . BsConfig::get( 
'MW::Flexiskin::Active' );
+       }
 }
diff --git a/Flexiskin/Flexiskin.setup.php b/Flexiskin/Flexiskin.setup.php
index bd77a38..c928efc 100644
--- a/Flexiskin/Flexiskin.setup.php
+++ b/Flexiskin/Flexiskin.setup.php
@@ -2,14 +2,23 @@
 
 BsExtensionManager::registerExtension( 'Flexiskin', BsRUNLEVEL::FULL | 
BsRUNLEVEL::REMOTE );
 
-$wgMessagesDirs['Flexiskin'] = __DIR__ . '/i18n';
+$GLOBALS['wgAutoloadClasses']['Flexiskin'] = __DIR__ . '/Flexiskin.class.php';
 
+$wgHooks['BeforePageDisplay'][] = "Flexiskin::onBeforePageDisplay";
+$wgHooks['ResourceLoaderRegisterModules'][] = 
"Flexiskin::onResourceLoaderRegisterModules";
+
+$wgMessagesDirs['Flexiskin'] = __DIR__ . '/i18n';
 $wgExtensionMessagesFiles['Flexiskin'] = __DIR__ . 
'/languages/Flexiskin.i18n.php';
 $wgExtensionMessagesFiles['FlexiskinAlias'] = __DIR__ . 
'/languages/Flexiskin.alias.php';
 
-$GLOBALS['wgAutoloadClasses']['Flexiskin'] = __DIR__ . '/Flexiskin.class.php';
+$wgAutoloadClasses['FlexiskinApi'] = __DIR__ . 
'/includes/FlexiskinApi.class.php';
+$wgAutoloadClasses['FlexiskinFormatter'] = __DIR__ . 
'/includes/FlexiskinFormatter.class.php';
+$wgAutoloadClasses['FlexiskinResourceLoaderModule'] = __DIR__ . 
'/includes/resourceloader/ResourceLoaderFlexiskinModule.php';
+$wgAutoloadClasses['FlexiskinPreviewResourceLoaderModule'] = __DIR__ . 
'/includes/resourceloader/ResourceLoaderFlexiskinPreviewModule.php';
 
-$wgHooks['SkinTemplateOutputPageBeforeExec'][] = 
"Flexiskin::onSkinTemplateOutputPageBeforeExec";
+$wgResourceModules['ext.bluespice.flexiskin.skin.preview'] =  array(
+       'class' => 'FlexiskinPreviewResourceLoaderModule'
+);
 
 $wgResourceModules['ext.bluespice.flexiskin'] = array(
        'scripts' => array(
@@ -55,9 +64,7 @@
        'remoteBasePath' => &$GLOBALS['wgScriptPath']
 );
 
-$wgAutoloadClasses['FlexiskinApi'] = __DIR__ . 
'/includes/FlexiskinApi.class.php';
 $wgAPIModules['flexiskin'] = 'FlexiskinApi';
-$wgAutoloadClasses['FlexiskinFormatter'] = __DIR__ . 
'/includes/FlexiskinFormatter.class.php';
 
 $wgEditPageFrameOptions = "SAMEORIGIN";
 
diff --git a/Flexiskin/includes/FlexiskinApi.class.php 
b/Flexiskin/includes/FlexiskinApi.class.php
index 15e8d00..2f1a173 100644
--- a/Flexiskin/includes/FlexiskinApi.class.php
+++ b/Flexiskin/includes/FlexiskinApi.class.php
@@ -70,7 +70,7 @@
                $sOldId = $this->getMain()->getVal( 'id' );
                $aConfigs = FormatJson::decode( $aData );
                $sNewId = Flexiskin::getFlexiskinIdFromConfig( $aConfigs );
-               $aFile = Flexiskin::generateStyleFile( $aConfigs );
+
                $sFlexiskinPath = BsFileSystemHelper::getDataDirectory( 
'flexiskin' ) . DS;
                //check if skin already exists
                if ( $sOldId != $sNewId && is_dir( $sFlexiskinPath . DS . 
$sNewId ) && file_exists( $sFlexiskinPath . DS . $sNewId . DS . "conf.json" ) ) 
{
@@ -89,14 +89,14 @@
                        }
                }
                BsFileSystemHelper::ensureDataDirectory($sFlexiskinPath . DS . 
$sNewId);
-               $oStatus = BsFileSystemHelper::saveToDataDirectory( 
"variables.less", $aFile, "flexiskin" . DS . $sNewId );
+               $oStatus = BsFileSystemHelper::saveToDataDirectory( 
"conf.json", FormatJson::encode( $aConfigs, true ), "flexiskin" . DS . $sNewId 
);
                if ( !$oStatus->isGood() ) {
                        return FormatJson::encode( array(
                                'success' => false,
                                'msg' => wfMessage( 
"bs-flexiskin-api-error-save", $this->getErrorMessage( $oStatus ) )->plain()
                                        ) );
                }
-               $oStatus = BsFileSystemHelper::saveToDataDirectory( 
"conf.json", $aData, "flexiskin" . DS . $sNewId );
+               $oStatus = BsFileSystemHelper::saveToDataDirectory( 
"conf.tmp.json", FormatJson::encode( $aConfigs, true ), "flexiskin" . DS . 
$sNewId );
                if ( !$oStatus->isGood() ) {
                        return FormatJson::encode( array(
                                'success' => false,
@@ -106,7 +106,7 @@
                return FormatJson::encode( array(
                        'success' => true,
                        'id' => $sNewId,
-                       'src' => $wgScriptPath . "/index.php?flexiskin=" . 
$sNewId )
+                       'src' => $wgScriptPath . "/index.php?flexiskin=" . 
$sNewId . "&preview=true" )
                                );
        }
 
@@ -118,41 +118,17 @@
        public function savePreview() {
                global $wgScriptPath;
 
-               $sPreviewTimestamp = $this->getRequest()->getSessionData( 
'PreviewTimestamp' );
-
-               $sId = $this->getMain()->getVal( 'id', '' );
-               if ( $sId == "" ) {
-                       return FormatJson::encode( array( 'success' => false, 
'msg' => wfMessage( 'bs-flexiskin-api-error-missing-param', 'id' )->plain() ) );
-               }
-               $delVariablesStatus = BsFileSystemHelper::deleteFile( 
"variables." . $sPreviewTimestamp . ".tmp.less", "flexiskin" . DS . $sId );
-               $delConfStatus = BsFileSystemHelper::deleteFile( "conf." . 
$sPreviewTimestamp . ".tmp.json", "flexiskin" . DS . $sId );
-               $delScreenStatus = BsFileSystemHelper::deleteFile( "screen." . 
$sPreviewTimestamp . ".tmp.less", "flexiskin" . DS . $sId );
-
-               $sPreviewTimestamp = time();
-               $this->getRequest()->setSessionData( 'PreviewTimestamp', 
$sPreviewTimestamp );
-
                $sId = $this->getMain()->getVal( 'id', '' );
                if ( $sId == "" ) {
                        return FormatJson::encode( array( 'success' => false, 
'msg' => wfMessage( 'bs-flexiskin-api-error-missing-param', 'id' )->plain() ) );
                }
                $aData = $this->getMain()->getVal( 'data', array() );
                $aConfigs = FormatJson::decode( $aData );
-               $aFile = Flexiskin::generateStyleFile( $aConfigs );
-               $sScreen = Flexiskin::generateScreenFile( true );
 
-               $oStatus = BsFileSystemHelper::saveToDataDirectory( 
"variables." . $sPreviewTimestamp . ".tmp.less", $aFile, "flexiskin" . DS . 
$sId );
+               $oStatus = BsFileSystemHelper::saveToDataDirectory( 
"conf.tmp.json", FormatJson::encode( $aConfigs, true ), "flexiskin" . DS . $sId 
);
                if ( !$oStatus->isGood() ) {
                        return FormatJson::encode( array( 'success' => false, 
'msg' => wfMessage( "bs-flexiskin-api-error-save-preview", 
$this->getErrorMessage( $oStatus ) )->plain() ) );
                }
-               $oStatus = BsFileSystemHelper::saveToDataDirectory( "conf." . 
$sPreviewTimestamp . ".tmp.json", $aData, "flexiskin" . DS . $sId );
-               if ( !$oStatus->isGood() ) {
-                       return FormatJson::encode( array( 'success' => false, 
'msg' => wfMessage( "bs-flexiskin-api-error-save-preview", 
$this->getErrorMessage( $oStatus ) )->plain() ) );
-               }
-               $oStatus = BsFileSystemHelper::saveToDataDirectory( "screen." . 
$sPreviewTimestamp . ".tmp.less", $sScreen, "flexiskin" . DS . $sId );
-               if ( !$oStatus->isGood() ) {
-                       return FormatJson::encode( array( 'success' => false, 
'msg' => wfMessage( "bs-flexiskin-api-error-save-preview", 
$this->getErrorMessage( $oStatus ) )->plain() ) );
-               }
-               //tbd: check if this is usefull
                RequestContext::getMain()->getTitle()->invalidateCache();
                return FormatJson::encode( array( 'success' => true, 'src' => 
$wgScriptPath . "/index.php?flexiskin=" . $sId . "&preview=true" ) );
        }
@@ -184,11 +160,8 @@
         * @return Status The status object
         */
        public function getConfigFromId( $sId, $bPreview = false ) {
-
-               $sPreviewTimestamp = 
$this->getRequest()->getSessionData('PreviewTimestamp');
-
                if ( $bPreview ) {
-                       $oStatus = BsFileSystemHelper::getFileContent( "conf." 
. $sPreviewTimestamp . ".tmp.json", "flexiskin" . DS . $sId );
+                       $oStatus = BsFileSystemHelper::getFileContent( 
"conf.tmp.json", "flexiskin" . DS . $sId );
                } else {
                        $oStatus = BsFileSystemHelper::getFileContent( 
"conf.json", "flexiskin" . DS . $sId );
                }
@@ -267,17 +240,9 @@
                        return FormatJson::encode( array( 'success' => false, 
'msg' => wfMessage( 'bs-flexiskin-error-fail-add-skin', $this->getErrorMessage( 
$oStatus ) )->plain() ) );
                }
                if ( $oData->template != 'default' ) {
-                       $oStatus = BsFileSystemHelper::copyFile( 
'variables.less', "flexiskin" . DS . $oData->template, "flexiskin" . DS . md5( 
$sId ) );
                        $oStatus = BsFileSystemHelper::copyFolder( "images", 
"flexiskin" . DS . $oData->template, "flexiskin" . DS . md5( $sId ) );
-               } else {
-                       $oStatus = BsFileSystemHelper::saveToDataDirectory( 
'variables.less', Flexiskin::generateStyleFile( $sConfigFile ), "flexiskin" . 
DS . md5( $sId ) );
                }
-               $oStatus = 
BsFileSystemHelper::saveToDataDirectory('screen.less', 
Flexiskin::generateScreenFile(), "flexiskin" . DS . md5($sId));
-               $oStatus = BsFileSystemHelper::saveToDataDirectory('screen.' . 
$sPreviewTimestamp . '.tmp.less', Flexiskin::generateScreenFile(true), 
"flexiskin" . DS . md5($sId));
-               //tbd: check 1st, 2nd and 3rd status
-               if ( !$oStatus->isGood() ) {
-                       return FormatJson::encode( array( 'success' => false, 
'msg' => wfMessage( 'bs-flexiskin-error-fail-add-skin', $this->getErrorMessage( 
$oStatus ) )->plain() ) );
-               }
+
                BsFileSystemHelper::ensureDataDirectory( "flexiskin" . DS . 
md5( $sId ) . DS . "images" );
                return FormatJson::encode( array( 'success' => true ) );
        }
@@ -301,25 +266,15 @@
        public function resetFlexiskin() {
                global $wgScriptPath;
 
-               $sPreviewTimestamp = $this->getRequest()->getSessionData( 
'PreviewTimestamp' );
-               //$this->getRequest()->setSessionData("sPreviewSkin", NULL);
-
                $sId = $this->getMain()->getVal( 'id', '' );
                if ( $sId == "" ) {
                        return FormatJson::encode( array( 'success' => false, 
'msg' => wfMessage( 'bs-flexiskin-api-error-missing-param', 'id' )->plain() ) );
                }
-               $oStatus = BsFileSystemHelper::deleteFile( "variables." . 
$sPreviewTimestamp . ".tmp.less", "flexiskin" . DS . $sId );
+               $oStatus = BsFileSystemHelper::deleteFile( "conf.tmp.json", 
"flexiskin" . DS . $sId );
                if ( !$oStatus->isGood() ) {
                        return FormatJson::encode( array( 'success' => false, 
'msg' => wfMessage( "bs-flexiskin-reset-error", $this->getErrorMessage( 
$oStatus ) )->plain() ) );
                }
-               $oStatus = BsFileSystemHelper::deleteFile( "conf." . 
$sPreviewTimestamp . ".tmp.json", "flexiskin" . DS . $sId );
-               if ( !$oStatus->isGood() ) {
-                       return FormatJson::encode( array( 'success' => false, 
'msg' => wfMessage( "bs-flexiskin-reset-error", $this->getErrorMessage( 
$oStatus ) )->plain() ) );
-               }
-               $oStatus = BsFileSystemHelper::deleteFile( "screen." . 
$sPreviewTimestamp . ".tmp.less", "flexiskin" . DS . $sId );
-               if ( !$oStatus->isGood() ) {
-                       return FormatJson::encode( array( 'success' => false, 
'msg' => wfMessage( "bs-flexiskin-reset-error", $this->getErrorMessage( 
$oStatus ) )->plain() ) );
-               }
+
                $oResult = FormatJson::decode( $this->getConfig( $sId ) );
                if ( !$oResult->success ) {
                        return FormatJson::encode( array( 'success' => false, 
'msg' => wfMessage( "bs-flexiskin-reset-error", $oResult->msg )->plain() ) );
diff --git a/Flexiskin/includes/FlexiskinFormatter.class.php 
b/Flexiskin/includes/FlexiskinFormatter.class.php
index 8c9d92d..324ff92 100644
--- a/Flexiskin/includes/FlexiskinFormatter.class.php
+++ b/Flexiskin/includes/FlexiskinFormatter.class.php
@@ -11,7 +11,15 @@
                        $aReturn[] = "body{background-color:#" . 
$aConfig->customBackgroundColor . " !important;}";
                }
                if ( isset( $aConfig->backgroundImage ) && 
$aConfig->backgroundImage != "" ) {
-                       $aReturn[] = "body{background-image:url('images/" . 
$aConfig->backgroundImage . "') !important;}";
+                       $oStatus = BsFileSystemHelper::getFileContent( 
$aConfig->backgroundImage, 'flexiskin'.DS.$sNewId.DS.'images' );
+                       if( $oStatus->isGood() ){
+                               $sFileExtension = ( new SplFileInfo( 
$aConfig->backgroundImage ) )->getExtension();
+                               $sMime = 
MimeMagic::singleton()->guessTypesForExtension( $sFileExtension );
+                               $aReturn[] = 
"body{background-image:url('data:$sMime;base64," . base64_encode( 
$oStatus->getValue() ) . "') !important;}";
+                       }
+                       else{
+                               $aReturn[] = "body{background-image:none 
!important;}";
+                       }
                }
                else {
                        $sPath = 
RequestContext::getMain()->getSkin()->getSkinStylePath( 
"resources/images/desktop/bg-lo.png" );
@@ -24,8 +32,17 @@
 
        public static function format_header( $aConfig, $sNewId ) {
                $aReturn = array();
-               BsConfig::set("MW::Flexiskin::Logo", $aConfig->logo);
-               BsConfig::saveSettings();
+               if ( isset( $aConfig->logo ) && $aConfig->logo != "" ) {
+                       $oStatus = BsFileSystemHelper::getFileContent( 
$aConfig->logo, 'flexiskin'.DS.$sNewId.DS.'images' );
+                       if( $oStatus->isGood() ){
+                               $sFileExtension = ( new SplFileInfo( 
$aConfig->logo ) )->getExtension();
+                               $sMime = 
MimeMagic::singleton()->guessTypesForExtension( $sFileExtension );
+                               $aReturn[] = "#bs-logo > 
a{background-image:url('data:$sMime;base64," . base64_encode( 
$oStatus->getValue() ) . "') !important;}";
+                       }
+                       else{
+                               $aReturn[] = "#bs-logo > 
a{background-image:none !important;}";
+                       }
+               }
                wfRunHooks( "BSFlexiskinFormatterHeader", array( &$aConfig, 
&$aReturn ) );
                return implode( " \n", $aReturn );
        }
diff --git 
a/Flexiskin/includes/resourceloader/ResourceLoaderFlexiskinModule.php 
b/Flexiskin/includes/resourceloader/ResourceLoaderFlexiskinModule.php
new file mode 100644
index 0000000..cf6fa82
--- /dev/null
+++ b/Flexiskin/includes/resourceloader/ResourceLoaderFlexiskinModule.php
@@ -0,0 +1,46 @@
+<?php
+
+class FlexiskinResourceLoaderModule extends ResourceLoaderFileModule {
+       public function __construct($options = array(), $localBasePath = null, 
$remoteBasePath = null) {
+               parent::__construct($options, $localBasePath, $remoteBasePath);
+       }
+
+       public function getStyles(\ResourceLoaderContext $context) {
+               $sFlexiSkinId =  BsConfig::get( 'MW::Flexiskin::Active' );
+
+               $oStatus = BsFileSystemHelper::getFileContent(
+                       $this->makeSourceFileName(),
+                       "flexiskin" . DS . $this->makeFlexiSkinID( $context )
+               );
+
+               if( !$oStatus->isGood() ){
+                       return;
+               }
+               $aConfJson = FormatJson::decode($oStatus->getValue());
+               $aConfigs = array();
+               foreach ( $aConfJson as $aConfig ) {
+                       switch ($aConfig->id){
+                               case "general":
+                                       $aConfigs[] = 
FlexiskinFormatter::format_general($aConfig, $sFlexiSkinId);
+                                       break;
+                               case "header":
+                                       $aConfigs[] = 
FlexiskinFormatter::format_header($aConfig, $sFlexiSkinId);
+                                       break;
+                               case "position":
+                                       $aConfigs[] = 
FlexiskinFormatter::format_position($aConfig, $sFlexiSkinId);
+                                       break;
+                               default:
+                                       break;
+                       }
+               }
+               return array( implode( "\n", $aConfigs ) );
+       }
+
+       public function makeSourceFileName() {
+               return 'conf.json';
+       }
+
+       public function makeFlexiSkinID( $context ) {
+               return BsConfig::get( 'MW::Flexiskin::Active' );
+       }
+}
diff --git 
a/Flexiskin/includes/resourceloader/ResourceLoaderFlexiskinPreviewModule.php 
b/Flexiskin/includes/resourceloader/ResourceLoaderFlexiskinPreviewModule.php
new file mode 100644
index 0000000..70ceedf
--- /dev/null
+++ b/Flexiskin/includes/resourceloader/ResourceLoaderFlexiskinPreviewModule.php
@@ -0,0 +1,26 @@
+<?php
+
+class FlexiskinPreviewResourceLoaderModule extends 
FlexiskinResourceLoaderModule {
+
+
+       /**
+        *
+        * @param ResourceLoaderContext $context
+        * @return type
+        */
+       public function makeFlexiSkinID( $context ) {
+               return $context->getRequest()->getSessionData('flexiskin');
+       }
+
+       public function makeSourceFileName() {
+               return 'conf.tmp.json';
+       }
+
+       public function getModifiedTime(\ResourceLoaderContext $context) {
+               return time();
+       }
+
+       public function getGroup() {
+               return 'user';
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/263056
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7657985030d2fdb2d1fa8da322febef373557bc2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: REL1_23
Gerrit-Owner: Dvogel hallowelt <daniel.vo...@hallowelt.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to