/**
  * Method to save a Flexiskin defined by id and data via request parameter
  * @global String $wgScriptPath
  * @return String encoded result JSON string
  */
 public function saveFlexiskin()
 {
     global $wgScriptPath;
     $aData = $this->getMain()->getVal('data', array());
     $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")) {
         return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-error-skinexists')->plain()));
     }
     if ($sOldId != $sNewId && is_dir($sFlexiskinPath . DS . $sOldId)) {
         $oStatus = BsFileSystemHelper::renameFolder("flexiskin" . DS . $sOldId, "flexiskin" . DS . $sNewId);
         if (!$oStatus->isGood()) {
             return FormatJson::encode(array('success' => false, 'msg' => wfMessage("bs-flexiskin-api-error-save", $this->getErrorMessage($oStatus))->plain()));
         }
     }
     BsFileSystemHelper::ensureDataDirectory($sFlexiskinPath . DS . $sNewId);
     $oStatus = BsFileSystemHelper::saveToDataDirectory("variables.less", $aFile, "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);
     if (!$oStatus->isGood()) {
         return FormatJson::encode(array('success' => false, 'msg' => wfMessage("bs-flexiskin-api-error-save", $this->getErrorMessage($oStatus))->plain()));
     }
     return FormatJson::encode(array('success' => true, 'id' => $sNewId, 'src' => $wgScriptPath . "/index.php?flexiskin=" . $sNewId));
 }