mirror of
https://github.com/til-schneider/slim-wiki.git
synced 2025-08-06 00:27:28 +02:00
Fixed encoding problems with directory names
This commit is contained in:
@@ -15,6 +15,8 @@ function init() {
|
||||
$requestPathArray = array();
|
||||
$isBasePath = true;
|
||||
foreach ($uriPathArray as $level => $uriDir) {
|
||||
$uriDir = urldecode($uriDir);
|
||||
|
||||
$scriptDir = isset($scriptPathArray[$level]) ? $scriptPathArray[$level] : null;
|
||||
if ($isBasePath && $scriptDir != $uriDir) {
|
||||
// The URI path differs from the script path here -> We arrived at the level where the app is installed
|
||||
|
@@ -79,7 +79,7 @@ class EditorService {
|
||||
}
|
||||
|
||||
public function getNewArticleMarkdown($pageTitle) {
|
||||
return $pageTitle . "\n" . str_repeat('=', strlen($pageTitle)) . "\n\n"
|
||||
return $pageTitle . "\n" . str_repeat('=', mb_strlen($pageTitle, $encoding = 'utf-8')) . "\n\n"
|
||||
. $this->context->getI18n()['createArticle.content'];
|
||||
}
|
||||
|
||||
|
@@ -138,7 +138,12 @@ class Main {
|
||||
// Open a fake "new article" for demo mode
|
||||
|
||||
// We have no real page title here -> Create one from the file name
|
||||
$pageTitle = str_replace('_', ' ', end($requestPathArray));
|
||||
$lastPathPart = end($requestPathArray);
|
||||
if ($lastPathPart == '') {
|
||||
// This is the `index.md` of a directory -> Use the directory name
|
||||
$lastPathPart = prev($requestPathArray);
|
||||
}
|
||||
$pageTitle = str_replace('_', ' ', $lastPathPart);
|
||||
|
||||
$editorService = $this->context->getEditorService();
|
||||
$articleMarkdown = $editorService->getNewArticleMarkdown($pageTitle);
|
||||
@@ -172,8 +177,8 @@ class Main {
|
||||
$articleFilename = implode('/', $requestPathArray);
|
||||
|
||||
// Support `index.md` for directories
|
||||
if (is_dir($articleBaseDir . $articleFilename)) {
|
||||
$articleFilename = ltrim($articleFilename . '/index.md', '/');
|
||||
if ($articleFilename == '' || substr($articleFilename, -1) == '/') {
|
||||
$articleFilename = $articleFilename . 'index.md';
|
||||
}
|
||||
|
||||
// Make the extension `.md` optional
|
||||
@@ -194,14 +199,22 @@ class Main {
|
||||
$config = $this->context->getConfig();
|
||||
$wikiName = $config['wikiName'];
|
||||
$showCompleteBreadcrumbs = $config['showCompleteBreadcrumbs'];
|
||||
|
||||
$pathCount = count($requestPathArray);
|
||||
if ($pathCount > 1 && end($requestPathArray) == '') {
|
||||
// This is the `index.md` of a directory -> Don't include the last part in the breadcrumbs
|
||||
$pathCount--;
|
||||
}
|
||||
|
||||
$breadcrumbArray = array(array('name' => $wikiName, 'path' => '', 'active' => ($pathCount == 0)));
|
||||
|
||||
$articleBaseDir = $this->context->getArticleBaseDir();
|
||||
$currentPath = '';
|
||||
$currentPathUrlEncoded = '';
|
||||
for ($i = 0; $i < $pathCount; $i++) {
|
||||
$pathPart = $requestPathArray[$i];
|
||||
$currentPath .= ($i == 0 ? '' : '/') . $pathPart;
|
||||
$currentPathUrlEncoded .= ($i == 0 ? '' : '/') . urlencode($pathPart);
|
||||
$isLast = ($i == $pathCount - 1);
|
||||
|
||||
$hasContent = ($isLast || file_exists($articleBaseDir . $currentPath . '/index.md'));
|
||||
@@ -209,7 +222,7 @@ class Main {
|
||||
// This is the requested file or an directory having an index -> Add it
|
||||
$breadcrumbArray[] = array(
|
||||
'name' => str_replace('_', ' ', $pathPart),
|
||||
'path' => $hasContent ? urlencode($currentPath) : null,
|
||||
'path' => $hasContent ? $currentPathUrlEncoded : null,
|
||||
'active' => $isLast);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user