/**
  * Sets up requires directories
  * @param DatabaseUpdater $updater Provided by MediaWikis update.php
  * @return boolean Always true to keep the hook running
  */
 public static function getSchemaUpdates($updater)
 {
     //TODO: Create abstraction in Core/Adapter
     $sTmpDir = BSDATADIR . DS . 'UEModulePDF';
     if (!file_exists($sTmpDir)) {
         echo 'Directory "' . $sTmpDir . '" not found. Creating.' . "\n";
         wfMkdirParents($sTmpDir);
     } else {
         echo 'Directory "' . $sTmpDir . '" found.' . "\n";
     }
     $sDefaultTemplateDir = BSDATADIR . DS . 'PDFTemplates';
     if (!file_exists($sDefaultTemplateDir)) {
         echo 'Default template directory "' . $sDefaultTemplateDir . '" not found. Copying.' . "\n";
         BsFileSystemHelper::copyRecursive(__DIR__ . DS . 'data' . DS . 'PDFTemplates', $sDefaultTemplateDir);
     }
     return true;
 }
 private function exportPNG($sData)
 {
     $this->getOutput()->disable();
     global $wgRequest, $wgSVGConverter, $wgSVGConverters, $wgSVGConverterPath, $IP;
     if ($wgSVGConverter == false || !isset($wgSVGConverters[$wgSVGConverter])) {
         echo wfMessage('bs-statistics-err-converter')->plain();
         return false;
     }
     $sFileName = wfTimestampNow();
     $sFileExt = '.svg';
     $oStatus = BsFileSystemHelper::saveToCacheDirectory($sFileName . $sFileExt, $sData, 'Statistics');
     if (!$oStatus->isGood()) {
         echo $oStatus->getMessage();
         return false;
     }
     $sCacheDir = $oStatus->getValue();
     $cmd = str_replace(array('$path/', '$width', '$height', '$input', '$output'), array($wgSVGConverterPath ? wfEscapeShellArg("{$wgSVGConverterPath}/") : "", intval($wgRequest->getVal('width', 600)), intval($wgRequest->getVal('height', 400)), wfEscapeShellArg($sCacheDir . '/' . $sFileName . $sFileExt), wfEscapeShellArg($sCacheDir)), $wgSVGConverters[$wgSVGConverter]) . " 2>&1";
     $err = wfShellExec($cmd);
     unlink($sCacheDir . '/' . $sFileName . $sFileExt);
     $sFileExt = '.png';
     if (!file_exists($sCacheDir . '/' . $sFileName . $sFileExt)) {
         echo $err;
         return false;
     }
     $this->getRequest()->response()->header("Content-Type:image/png");
     $this->getRequest()->response()->header("Content-Disposition:attachment; filename={$sFileName}{$sFileExt}");
     readfile($sCacheDir . '/' . $sFileName . $sFileExt);
     unlink($sCacheDir . '/' . $sFileName . $sFileExt);
     return true;
 }
 /**
  * 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;
     $oStatus = BsFileSystemHelper::ensureDataDirectory("flexiskin/" . $sFlexiskinId);
     if (!$oStatus->isGood()) {
         return false;
     }
     $sFilePath = BsFileSystemHelper::getDataPath("flexiskin/" . $sFlexiskinId);
     $sFilePath .= "/screen" . ($bIsTemp ? '.tmp' : '') . ".less";
     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;
 }
 /**
  * Triggers a file upload to the Flexiskin data directory defined by id via request parameter
  * @return AjaxResponse The AjaxResponse Object
  */
 public function uploadFile()
 {
     $sId = $this->getMain()->getVal('id', '');
     if ($sId == "") {
         return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-api-error-missing-param', 'id')->plain()));
     }
     $sName = $this->getMain()->getVal('name', '');
     if ($sId == "") {
         return FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-flexiskin-api-error-missing-param', 'name')->plain()));
     }
     $oStatus = BsFileSystemHelper::uploadFile($sName, "flexiskin" . DS . $sId . DS . "images");
     if (!$oStatus->isGood()) {
         $aResult = FormatJson::encode(array('success' => false, 'msg' => "err_cd:" . $oStatus->getMessage()));
     } else {
         $aResult = FormatJson::encode(array('success' => true, 'name' => $oStatus->getValue()));
     }
     return $aResult;
 }
 public static function uploadFile()
 {
     if (wfReadOnly()) {
         global $wgReadOnly;
         $oAjaxResponse = new AjaxResponse(FormatJson::encode(array('success' => false, 'msg' => wfMessage('bs-readonly', $wgReadOnly)->escaped())));
         $oAjaxResponse->setContentType('text/html');
         return $oAjaxResponse;
     }
     global $wgRequest, $wgUser;
     self::unsetUserImage($wgUser);
     $oAvatars = BsExtensionManager::getExtension('Avatars');
     $sAvatarFileName = self::$sAvatarFilePrefix . $wgUser->getId() . ".png";
     $oStatus = BsFileSystemHelper::uploadAndConvertImage($wgRequest->getVal('name'), $oAvatars->mInfo[EXTINFO::NAME], $sAvatarFileName);
     if (!$oStatus->isGood()) {
         $aErrors = $oStatus->getErrorsArray();
         $aResult = json_encode(array('success' => false, 'msg' => $aErrors[0][0]));
     } else {
         $aResult = json_encode(array('success' => true, 'msg' => wfMessage('bs-avatars-upload-complete')->plain(), 'name' => $oStatus->getValue()));
         # found no way to regenerate thumbs. just delete thumb folder if it exists
         $oStatus = BsFileSystemHelper::deleteFolder('Avatars' . DS . 'thumb' . DS . $sAvatarFileName, true);
         if (!$oStatus->isGood()) {
             throw new MWException('FATAL: Avatar thumbs could no be deleted!');
         }
     }
     $oAjaxResponse = new AjaxResponse($aResult);
     $oAjaxResponse->setContentType('text/html');
     return $oAjaxResponse;
 }