diff --git a/includes/YesWiki.php b/includes/YesWiki.php
index e918a02e9..bfacd5c76 100755
--- a/includes/YesWiki.php
+++ b/includes/YesWiki.php
@@ -386,14 +386,28 @@ public function GetMessage()
return $message;
}
- public function getBaseUrl()
+ public function getBaseUrl($useDataPath = false)
{
$url = explode('wakka.php', $this->config['base_url']);
$url = explode('index.php', $url[0]);
$url = preg_replace(array('/\/\?$/', '/\/$/'), '', $url[0]);
+ if ($useDataPath && !empty($this->config['dataPath']) ) {
+ // we add an imaginary folder in order to retrieve yeswiki assets from yeswiki's source folder. web servers need to be configured to redirect yeswiki-assets to the main yeswiki folder
+ $url .= '/yeswiki-assets';
+ }
return $url;
}
+ public function getLocalPath($folder = '')
+ {
+ $dataFolders = ['', 'cache', 'files', 'custom'];
+ if (in_array($folder, $dataFolders) && !empty($this->config['dataPath']) ) {
+ // we add an imaginary folder in order to retrieve yeswiki assets from yeswiki's source folder. web servers need to be configured to redirect yeswiki-assets to the main yeswiki folder
+ $folder = $this->config['dataPath'].'/'.$folder ;
+ }
+ return $folder;
+ }
+
public function Redirect($url)
{
header("Location: $url");
diff --git a/includes/YesWikiInit.php b/includes/YesWikiInit.php
index 9f4862622..9113c737a 100644
--- a/includes/YesWikiInit.php
+++ b/includes/YesWikiInit.php
@@ -48,9 +48,12 @@ class Init
public function __construct($config = array())
{
$this->getRoute();
+ if (!empty($_SERVER['YESWIKI_DATA_PATH']) && is_dir($_SERVER['YESWIKI_DATA_PATH'])) {
+ $this->configFile = $_SERVER['YESWIKI_DATA_PATH'].'/yeswiki.config.php';
+ }
$this->config = $this->getConfig($config);
$this->setIframeHeaders();
-
+
/* @todo : compare versions, start installer for update if necessary */
if (!file_exists($this->configFile)) {
$this->doInstall();
@@ -231,6 +234,7 @@ public function getConfig($wakkaConfig = array())
'timezone' => 'Europe/Paris', // Only used if not set in wakka.config.php nor in php.ini
'root_page' => 'PagePrincipale', // backup root_page if deleted from wakka.config.php
'wakka_name' => '', // backup wakka_name if deleted from wakka.config.php
+ 'dataPath' => !empty($_SERVER['YESWIKI_DATA_PATH']) ? $_SERVER['YESWIKI_DATA_PATH'] : '',
'htmlPurifierActivated' => false, // TODO ectoplasme set to true
'favorites_activated' => true,
ArchiveService::PARAMS_KEY_IN_WAKKA => [
diff --git a/includes/services/AssetsManager.php b/includes/services/AssetsManager.php
index 633b94ea7..7b5fcb99c 100644
--- a/includes/services/AssetsManager.php
+++ b/includes/services/AssetsManager.php
@@ -75,7 +75,7 @@ public function LinkCSSFile($file, $conditionstart = '', $conditionend = '', $at
$isUrl = strpos($file, "http://") === 0 || strpos($file, "https://") === 0;
if ($isUrl || !empty($file) && file_exists($file)) {
- $href = $isUrl ? $file : "{$this->wiki->getBaseUrl()}/{$file}";
+ $href = $isUrl ? $file : "{$this->wiki->getBaseUrl(true)}/{$file}";
$revision = $this->wiki->GetConfigValue('yeswiki_release', null);
return <<wiki->GetConfigValue('debug') != 'yes') {
if (array_key_exists($file, self::PRODUCTION_PATH_MAPPING)) {
$file = self::PRODUCTION_PATH_MAPPING[$file];
diff --git a/includes/services/CommentService.php b/includes/services/CommentService.php
index ab755187a..cdd61ee80 100644
--- a/includes/services/CommentService.php
+++ b/includes/services/CommentService.php
@@ -22,6 +22,7 @@ class CommentService implements EventSubscriberInterface
protected $eventDispatcher;
protected $mailer;
protected $pageManager;
+ protected $hashcashService;
protected $params;
protected $pagesWhereCommentWereRendered;
protected $userManager;
@@ -35,6 +36,7 @@ public function __construct(
EventDispatcher $eventDispatcher,
Mailer $mailer,
PageManager $pageManager,
+ HashCashService $hashcashService,
ParameterBagInterface $params,
TemplateEngine $templateEngine,
UserManager $userManager
@@ -47,6 +49,7 @@ public function __construct(
$this->pageManager = $pageManager;
$this->templateEngine = $templateEngine;
$this->userManager = $userManager;
+ $this->hashcashService = $hashcashService;
$this->params = $params;
$this->pagesWhereCommentWereRendered = [];
$this->commentsActivated = $this->params->get('comments_activated');
@@ -71,8 +74,7 @@ public function addCommentIfAuthorized($content, $idComment = '')
} else {
if ($this->wiki->HasAccess("comment", $content['pagetag']) && $this->wiki->Loadpage($content['pagetag'])) {
if ($this->params->get('use_hashcash')) {
- require_once('tools/security/secret/wp-hashcash.lib');
- if (!isset($content["hashcash_value"]) || ($content["hashcash_value"] != hashcash_field_value())) {
+ if (!isset($content["hashcash_value"]) || ($content["hashcash_value"] != $this->hashcashService->hashcash_field_value())) {
return [
'code' => 400,
'error' => _t('HASHCASH_COMMENT_NOT_SAVED_MAYBE_YOU_ARE_A_ROBOT')
diff --git a/includes/services/Mailer.php b/includes/services/Mailer.php
index a4c954ba8..46a4a2b0b 100644
--- a/includes/services/Mailer.php
+++ b/includes/services/Mailer.php
@@ -220,6 +220,7 @@ public function subscribeToMailingList($email, $mailingList)
// TODO when PR #967 merged, refactor this part with YesWiki::getBaseUrl
public function getBaseUrl(): string
{
+ // TODO: use getBaseUrl from core unless there is a trap ?
return preg_replace('/(\\/wakka\\.php\\?wiki=|\\/\\?wiki=|\\/\\?|\\/)$/m', '', $this->params->get('base_url')) ;
}
diff --git a/includes/services/TemplateEngine.php b/includes/services/TemplateEngine.php
index f9f84cf46..119ebdac8 100644
--- a/includes/services/TemplateEngine.php
+++ b/includes/services/TemplateEngine.php
@@ -81,9 +81,11 @@ public function __construct(
}
}
+ $dataPath = (!empty($this->wiki->config['dataPath'])) ? $this->wiki->config['dataPath'].'/' : '';
+
// Set up twig
$this->twig = new \Twig\Environment($this->twigLoader, [
- 'cache' => 'cache/templates/',
+ 'cache' => $dataPath.'cache/templates/',
'auto_reload' => true
]);
@@ -104,6 +106,9 @@ public function __construct(
$this->addTwigHelper('_t', function ($key, $params = []) {
return html_entity_decode(_t($key, $params));
});
+ $this->addTwigHelper('baseUrl', function ($useDataPath = null) {
+ return $this->wiki->getBaseUrl($useDataPath);
+ });
$this->addTwigHelper('url', function ($options) {
$options = array_merge(['tag' => '', 'handler' => '', 'params' => []], $options);
$iframe = !empty($options['handler']) ? $options['handler'] : testUrlInIframe();
diff --git a/includes/urlutils.inc.php b/includes/urlutils.inc.php
index c857bed06..63a2b1042 100755
--- a/includes/urlutils.inc.php
+++ b/includes/urlutils.inc.php
@@ -35,9 +35,10 @@ function getAbsoluteUrl()
* as it affects the resulting url. Defaults to false.
* @return string The base url of the wiki
*/
-function computeBaseURL($rewrite_mode = false)
+function computeBaseURL($rewrite_mode = false, $dataPath = null)
{
- $scriptlocation = str_replace(array('/index.php', '/wakka.php'), '', $_SERVER["SCRIPT_NAME"]);
+ $prefix = (!empty($dataPath) && is_dir($dataPath)) ? '/yeswiki-assets' : '';
+ $scriptlocation = $prefix.str_replace(array('/index.php', '/wakka.php'), '', $_SERVER["SCRIPT_NAME"]);
return getRootUrl()
. $scriptlocation
diff --git a/setup/footer.php b/setup/footer.php
index 55156e31e..4fa065be1 100755
--- a/setup/footer.php
+++ b/setup/footer.php
@@ -6,7 +6,7 @@
ob_end_flush();
?>
-
-
+
+