From c2b6efffa5d76674f007de7990945ee8e361765a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Dufraisse?= Date: Fri, 4 Feb 2022 09:58:59 +0100 Subject: [PATCH] refactor(attach.lib.php): move params in config.yaml --- tools/attach/config.yaml | 14 ++++++++ tools/attach/libs/attach.lib.php | 59 +++----------------------------- 2 files changed, 19 insertions(+), 54 deletions(-) diff --git a/tools/attach/config.yaml b/tools/attach/config.yaml index ea70ac45b..d81c965c7 100644 --- a/tools/attach/config.yaml +++ b/tools/attach/config.yaml @@ -113,6 +113,20 @@ parameters: ots: 'opendocument spreadsheet-template' otp: 'opendocument presentation-template' otg: 'opendocument graphics-template' + attach_config: + ext_images: "gif|jpeg|png|jpg|svg|webp" + ext_audio: "mp3|aac" + ext_video: "mp4|webm|ogg" + ext_wma: "wma" + ext_pdf: "pdf" + ext_freemind: "mm" + ext_flashvideo: "flv" + ext_script: "php|php3|asp|asx|vb|vbs|js" + upload_path: "files" + update_symbole: "" + fmDelete_symbole: "Supr" + fmRestore_symbole: "Rest" + fmTrash_symbole: "Corbeille" attach-video-config: default_video_service: 'peertube' default_peertube_instance: 'https://framatube.org/' diff --git a/tools/attach/libs/attach.lib.php b/tools/attach/libs/attach.lib.php index f2eccc426..5c82890a6 100644 --- a/tools/attach/libs/attach.lib.php +++ b/tools/attach/libs/attach.lib.php @@ -34,6 +34,7 @@ # voir actions/attach.php ppour la documentation # copyrigth Eric Feldstein 2003-2004 +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use YesWiki\Core\Service\LinkTracker; if (!defined("WIKINI_VERSION")) { @@ -62,74 +63,24 @@ class attach public $pageId = 0; //identifiant de la page public $isSafeMode = true; //indicateur du safe mode de PHP public $data = ''; //indicateur du safe mode de PHP + private $params; /** * Constructeur. Met les valeurs par defaut aux parametres de configuration */ public function __construct(&$wiki) { $this->wiki = $wiki; - $this->attachConfig = $this->wiki->GetConfigValue("attach_config"); + $this->params = $this->wiki->services->get(ParameterBagInterface::class); + $this->attachConfig = $this->params->get("attach_config"); if (!is_array($this->attachConfig)) { - $this->attachConfig = array(); - } - - if (empty($this->attachConfig["ext_images"])) { - $this->attachConfig["ext_images"] = "gif|jpeg|png|jpg|svg|webp"; - } - - if (empty($this->attachConfig["ext_audio"])) { - $this->attachConfig["ext_audio"] = "mp3|aac"; - } - - if (empty($this->attachConfig["ext_video"])) { - $this->attachConfig["ext_video"] = "mp4|webm|ogg"; - } - - if (empty($this->attachConfig["ext_wma"])) { - $this->attachConfig["ext_wma"] = "wma"; - } - - if (empty($this->attachConfig["ext_pdf"])) { - $this->attachConfig["ext_pdf"] = "pdf"; - } - - if (empty($this->attachConfig["ext_freemind"])) { - $this->attachConfig["ext_freemind"] = "mm"; - } - - if (empty($this->attachConfig["ext_flashvideo"])) { - $this->attachConfig["ext_flashvideo"] = "flv"; - } - - if (empty($this->attachConfig["ext_script"])) { - $this->attachConfig["ext_script"] = "php|php3|asp|asx|vb|vbs|js"; - } - - if (empty($this->attachConfig['upload_path'])) { - $this->attachConfig['upload_path'] = 'files'; - } - - if (empty($this->attachConfig['update_symbole'])) { - $this->attachConfig['update_symbole'] = ''; + throw new Exception("attach_config should be an array in wakka.config.php"); } if (empty($this->attachConfig['max_file_size'])) { $this->attachConfig['max_file_size'] = $this->wiki->GetConfigValue("max_file_size") ? $this->wiki->GetConfigValue("max_file_size") : $this->file_upload_max_size(); } - if (empty($this->attachConfig['fmDelete_symbole'])) { - $this->attachConfig['fmDelete_symbole'] = 'Supr'; - } - - if (empty($this->attachConfig['fmRestore_symbole'])) { - $this->attachConfig['fmRestore_symbole'] = 'Rest'; - } - - if (empty($this->attachConfig['fmTrash_symbole'])) { - $this->attachConfig['fmTrash_symbole'] = 'Corbeille'; - } - $safemode = $this->wiki->GetConfigValue("no_safe_mode"); if (empty($safemode)) { if (version_compare(phpversion(), '5.3', '<')) {