Robert Vogel has submitted this change and it was merged.
Change subject: Flexiskin: New RL implementation
......................................................................
Flexiskin: New RL implementation
Due to path traversal issues the resource loader implementation was
reworked.
Patch set 2: fixed phplint issue
Patch set 3: fixed phplint issue
Patch set 5: backward compatibility for using the logo (prevously not
stored in the conf.json)
Patch set 6: changes due to comments
Cherry-Picked from REL1_23
Conflicts:
Flexiskin/Flexiskin.class.php
Change-Id: Idb0a9a12ccb3485f2b77519de141c25b49074ba2
---
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, 179 insertions(+), 259 deletions(-)
Approvals:
Robert Vogel: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Flexiskin/Flexiskin.class.php b/Flexiskin/Flexiskin.class.php
index dcde1d7..c0da164 100755
--- 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,98 +66,16 @@
}
/**
- * 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 ),
- );
- }
- }
- }
+ BsConfig::registerVar( 'MW::Flexiskin::Logo', "",
BsConfig::LEVEL_PRIVATE | BsConfig::TYPE_STRING );
$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";
- if(defined('WIKI_FARMING')) {
- $sFilePath = '../..' . $sFilePath;
- } else {
- $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;
+ wfProfileOut( 'BS::' . __METHOD__ );
}
public function getForm() {
@@ -173,17 +90,20 @@
$api = new ApiMain(
new DerivativeRequest(
- $this->getRequest(), array(
- 'action' => 'flexiskin',
- 'type' => 'get'
- ), false
- ), true
+ $this->getRequest(),
+ array(
+ 'action' => 'flexiskin',
+ 'type' => 'get'
+ ),
+ false
+ ),
+ true
);
$oResult = $api->execute();
$aData = $api->getResultData();
$aResult = array( 'options' => array(
- wfMessage( 'bs-flexiskin-defaultname' )->plain() =>
'default',
- ) );
+ wfMessage( 'bs-flexiskin-defaultname'
)->plain() => 'default',
+ ) );
if ( isset( $aData['flexiskin'] ) && count( $aData['flexiskin']
) > 0 ) {
foreach ( $aData['flexiskin'] as $aConf ) {
$aResult['options'][$aConf['flexiskin_name']] =
$aConf['flexiskin_id'];
@@ -217,48 +137,7 @@
if ( !$bReturn ) {
return array();
}
- return FormatJson::encode($aConfig);
- }
-
- public static function generateScreenFile($bIsTmp = false){
- $sPreviewTimestamp =
RequestContext::getMain()->getRequest()->getSessionData( 'PreviewTimestamp' );
- $aScreenFile = array();
- if(defined('WIKI_FARMING')) {
- $sPathPrefix = '../../../../..';
- } else {
- $sPathPrefix = '../../../..';
- }
- $aScreenFile[] = "@import
'{$sPathPrefix}/skins/BlueSpiceSkin/resources/variables.less';";
- $aScreenFile[] = "@import 'variables.".($bIsTmp ?
$sPreviewTimestamp . ".tmp." : "")."less';";
- $aScreenFile[] = "@import
'{$sPathPrefix}/skins/BlueSpiceSkin/resources/screen.layout.less';";
- $aScreenFile[] = "@import
'{$sPathPrefix}/skins/BlueSpiceSkin/resources/components.less';";
- return implode("\n", $aScreenFile);
- }
-
- public static function generateStyleFile( $aConfigs ) {
- $aFile = array();
- if ( !is_array( $aConfigs ) ) {
- $aConfigs = FormatJson::decode( $aConfigs );
- }
- if(defined('WIKI_FARMING')) {
- $sPathPrefix = '../../../../..';
- } else {
- $sPathPrefix = '../../../..';
- }
- $aFile[] = '@bs-skin-path: "' . $sPathPrefix .
'/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){
@@ -273,49 +152,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' => 'ResourceLoaderFlexiskinModule'
+ )
+ );
+ 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..ca05008 100755
--- 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['ResourceLoaderFlexiskinModule'] = __DIR__ .
'/includes/resourceloader/ResourceLoaderFlexiskinModule.php';
+$wgAutoloadClasses['ResourceLoaderFlexiskinPreviewModule'] = __DIR__ .
'/includes/resourceloader/ResourceLoaderFlexiskinPreviewModule.php';
-$wgHooks['SkinTemplateOutputPageBeforeExec'][] =
"Flexiskin::onSkinTemplateOutputPageBeforeExec";
+$wgResourceModules['ext.bluespice.flexiskin.skin.preview'] = array(
+ 'class' => 'ResourceLoaderFlexiskinPreviewModule'
+);
$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..419c0b6 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 );
}
@@ -222,13 +195,6 @@
* @return String encoded result JSON string
*/
public function addFlexiskin() {
-
- if ( $this->getRequest()->getSessionData( 'PreviewTimestamp' )
!== NULL ) {
- $sPreviewTimestamp =
$this->getRequest()->getSessionData( 'PreviewTimestamp' );
- } else {
- $sPreviewTimestamp = time();
- }
-
$aData = FormatJson::decode( $this->getMain()->getVal( 'data',
"" ) );
$oData = $aData[0];
@@ -267,17 +233,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 +259,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..a4ce968 100644
--- a/Flexiskin/includes/FlexiskinFormatter.class.php
+++ b/Flexiskin/includes/FlexiskinFormatter.class.php
@@ -4,14 +4,22 @@
public static function format_general( $aConfig, $sNewId ) {
$aReturn = "";
- if ( $aConfig->customBackgroundColor == "" && (ctype_xdigit(
$aConfig->customBackgroundColor )) ){
+ if ( $aConfig->customBackgroundColor == "" && ( ctype_xdigit(
$aConfig->customBackgroundColor ) ) ){
$aReturn[] = "body{background-color:#" .
$aConfig->backgroundColor . " !important;}";
}
else{
$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() ){
+ $oFileInfo = new SplFileInfo(
$aConfig->backgroundImage );
+ $sMime =
MimeMagic::singleton()->guessTypesForExtension( $oFileInfo->getExtension() );
+ $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,16 @@
public static function format_header( $aConfig, $sNewId ) {
$aReturn = array();
- BsConfig::set("MW::Flexiskin::Logo", $aConfig->logo);
- BsConfig::saveSettings();
+ if ( isset( $aConfig->logo ) && $aConfig->logo != "" ) {
+ $aReturn[] = self::renderLogo( $aConfig->logo, $sNewId
);
+ }
+ elseif ( !isset( $aConfig->logo ) || $aConfig->logo == "" ){
+ $sLegacyLogo = BsConfig::get( 'MW::Flexiskin::Logo' );
+ if ( $sLegacyLogo != null && $sLegacyLogo != '' ){
+ $aReturn[] = self::renderLogo( $sLegacyLogo,
$sNewId );
+ }
+ }
+
wfRunHooks( "BSFlexiskinFormatterHeader", array( &$aConfig,
&$aReturn ) );
return implode( " \n", $aReturn );
}
@@ -33,27 +49,36 @@
public static function format_position( $aConfig, $sNewId ) {
$aReturn = "";
if ( $aConfig->navigation == 'right' ) {
- $aReturn[] = "#bs-application{position: relative;}";
- $aReturn[] = "#bs-content-column{margin: 0 302px 0 0;}";
- $aReturn[] = "#bs-nav-sections{right: 0; top: 30px;}";
- $aReturn[] = "#footer{margin: 0px 302px 5px 0px}";
+ $aReturn[] = "#bs-application{position: relative
!important;}";
+ $aReturn[] = "#bs-content-column{margin: 0 302px 0 0
!important;}";
+ $aReturn[] = "#bs-nav-sections{right: 0; top: 30px
!important;}";
+ $aReturn[] = "#footer{margin: 0px 302px 5px 0px
!important;}";
}
if ( $aConfig->content != 'center' ) {
- $aReturn[] = "#bs-wrapper{margin-" . $aConfig->content
. ":0;}";
+ $aReturn[] = "#bs-wrapper{margin-" . $aConfig->content
. ":0 !important;}";
}
if ( $aConfig->fullWidth == 0 ) {
- $aReturn[] = "#bs-menu-top{width:" . (int)
$aConfig->width . "px;}";
- $aReturn[] = "#bs-application{width:" . (int)
$aConfig->width . "px;}";
- $aReturn[] = "#bs-wrapper{width:" . (int)
$aConfig->width . "px;min-width:" . (int) $aConfig->width . "px;}";
- //$aReturn[] = "#bs-tools-container{width:" . ((int)
$aConfig->width - 200 + 28) . "px;margin-left:-" . ((int) $aConfig->width -
246) . "px}";
+ $aReturn[] = "#bs-menu-top{width:" . (int)
$aConfig->width . "px !important;}";
+ $aReturn[] = "#bs-application{width:" . (int)
$aConfig->width . "px !important;}";
+ $aReturn[] = "#bs-wrapper{width:" . (int)
$aConfig->width . "px !important;min-width:" . (int) $aConfig->width . "px
!important;}";
} else {
- $aReturn[] = "#bs-menu-top{width:100%;}";
- $aReturn[] = "#bs-application{width:100%;}";
- $aReturn[] = "#bs-wrapper{width:100%;min-width:100%;}";
+ $aReturn[] = "#bs-menu-top{width:100% !important;}";
+ $aReturn[] = "#bs-application{width:100% !important;}";
+ $aReturn[] = "#bs-wrapper{width:100%
!important;min-width:100% !important;}";
}
wfRunHooks( "BSFlexiskinFormatterPosition", array( &$aConfig,
&$aReturn ) );
return implode( " \n", $aReturn );
}
+ public static function renderLogo( $sFileName, $sNewId ) {
+ $oStatus = BsFileSystemHelper::getFileContent( $sFileName,
'flexiskin' . DS . $sNewId . DS . 'images' );
+ if( $oStatus->isGood() ){
+ $oFileInfo = new SplFileInfo( $sFileName );
+ $sMime =
MimeMagic::singleton()->guessTypesForExtension( $oFileInfo->getExtension() );
+ return "#bs-logo >
a{background-image:url('data:$sMime;base64," . base64_encode(
$oStatus->getValue() ) . "') !important;}";
+ }
+ return '';
+ }
+
}
diff --git
a/Flexiskin/includes/resourceloader/ResourceLoaderFlexiskinModule.php
b/Flexiskin/includes/resourceloader/ResourceLoaderFlexiskinModule.php
new file mode 100644
index 0000000..7fc6118
--- /dev/null
+++ b/Flexiskin/includes/resourceloader/ResourceLoaderFlexiskinModule.php
@@ -0,0 +1,44 @@
+<?php
+
+class ResourceLoaderFlexiskinModule extends ResourceLoaderFileModule {
+ public function __construct( $options = array(), $localBasePath = null,
$remoteBasePath = null ) {
+ parent::__construct( $options, $localBasePath, $remoteBasePath
);
+ }
+
+ public function getStyles( \ResourceLoaderContext $context ) {
+ $sFlexiSkinId = $this->makeFlexiSkinID( $context );
+
+ $oStatus = BsFileSystemHelper::getFileContent(
+ $this->makeSourceFileName(),
+ "flexiskin" . DS . $sFlexiSkinId
+ );
+
+ if( !$oStatus->isGood() ){
+ wfDebug( "BS::Flexiskin method getStyles: style for " .
$sFlexiSkinId . " could not be loaded" );
+ return array();
+ }
+ $aConfJson = FormatJson::decode( $oStatus->getValue() );
+ $aConfigs = array();
+ foreach( $aConfJson as $aConfig ) {
+ $func = "FlexiskinFormatter::format_" . $aConfig->id;
+
+ $bReturn = wfRunHooks( "BSFlexiskinGenerateStyleFile",
array( &$func, &$aConfig ) );
+
+ if( $bReturn === true && is_callable( $func ) ) {
+ $aConfigs[] = call_user_func_array( $func,
array( $aConfig, $sFlexiSkinId ) );
+ }
+ else {
+ wfDebug( "BS::Flexiskin method " . $func . "
could not be called." );
+ }
+ }
+ 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..c479136
--- /dev/null
+++ b/Flexiskin/includes/resourceloader/ResourceLoaderFlexiskinPreviewModule.php
@@ -0,0 +1,26 @@
+<?php
+
+class ResourceLoaderFlexiskinPreviewModule extends
ResourceLoaderFlexiskinModule {
+
+
+ /**
+ *
+ * @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/264726
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idb0a9a12ccb3485f2b77519de141c25b49074ba2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Robert Vogel <[email protected]>
Gerrit-Reviewer: Dvogel hallowelt <[email protected]>
Gerrit-Reviewer: Ljonka <[email protected]>
Gerrit-Reviewer: Mglaser <[email protected]>
Gerrit-Reviewer: Pwirth <[email protected]>
Gerrit-Reviewer: Robert Vogel <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits