1
0
mirror of https://github.com/til-schneider/slim-wiki.git synced 2025-08-07 00:56:35 +02:00

Fixed encoding problems with directory names

This commit is contained in:
til-schneider
2016-03-14 12:04:30 +01:00
parent f2ec534e69
commit 127b3bb03a
3 changed files with 20 additions and 5 deletions

View File

@@ -15,6 +15,8 @@ function init() {
$requestPathArray = array(); $requestPathArray = array();
$isBasePath = true; $isBasePath = true;
foreach ($uriPathArray as $level => $uriDir) { foreach ($uriPathArray as $level => $uriDir) {
$uriDir = urldecode($uriDir);
$scriptDir = isset($scriptPathArray[$level]) ? $scriptPathArray[$level] : null; $scriptDir = isset($scriptPathArray[$level]) ? $scriptPathArray[$level] : null;
if ($isBasePath && $scriptDir != $uriDir) { if ($isBasePath && $scriptDir != $uriDir) {
// The URI path differs from the script path here -> We arrived at the level where the app is installed // The URI path differs from the script path here -> We arrived at the level where the app is installed

View File

@@ -79,7 +79,7 @@ class EditorService {
} }
public function getNewArticleMarkdown($pageTitle) { 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']; . $this->context->getI18n()['createArticle.content'];
} }

View File

@@ -138,7 +138,12 @@ class Main {
// Open a fake "new article" for demo mode // Open a fake "new article" for demo mode
// We have no real page title here -> Create one from the file name // 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(); $editorService = $this->context->getEditorService();
$articleMarkdown = $editorService->getNewArticleMarkdown($pageTitle); $articleMarkdown = $editorService->getNewArticleMarkdown($pageTitle);
@@ -172,8 +177,8 @@ class Main {
$articleFilename = implode('/', $requestPathArray); $articleFilename = implode('/', $requestPathArray);
// Support `index.md` for directories // Support `index.md` for directories
if (is_dir($articleBaseDir . $articleFilename)) { if ($articleFilename == '' || substr($articleFilename, -1) == '/') {
$articleFilename = ltrim($articleFilename . '/index.md', '/'); $articleFilename = $articleFilename . 'index.md';
} }
// Make the extension `.md` optional // Make the extension `.md` optional
@@ -194,14 +199,22 @@ class Main {
$config = $this->context->getConfig(); $config = $this->context->getConfig();
$wikiName = $config['wikiName']; $wikiName = $config['wikiName'];
$showCompleteBreadcrumbs = $config['showCompleteBreadcrumbs']; $showCompleteBreadcrumbs = $config['showCompleteBreadcrumbs'];
$pathCount = count($requestPathArray); $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))); $breadcrumbArray = array(array('name' => $wikiName, 'path' => '', 'active' => ($pathCount == 0)));
$articleBaseDir = $this->context->getArticleBaseDir(); $articleBaseDir = $this->context->getArticleBaseDir();
$currentPath = ''; $currentPath = '';
$currentPathUrlEncoded = '';
for ($i = 0; $i < $pathCount; $i++) { for ($i = 0; $i < $pathCount; $i++) {
$pathPart = $requestPathArray[$i]; $pathPart = $requestPathArray[$i];
$currentPath .= ($i == 0 ? '' : '/') . $pathPart; $currentPath .= ($i == 0 ? '' : '/') . $pathPart;
$currentPathUrlEncoded .= ($i == 0 ? '' : '/') . urlencode($pathPart);
$isLast = ($i == $pathCount - 1); $isLast = ($i == $pathCount - 1);
$hasContent = ($isLast || file_exists($articleBaseDir . $currentPath . '/index.md')); $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 // This is the requested file or an directory having an index -> Add it
$breadcrumbArray[] = array( $breadcrumbArray[] = array(
'name' => str_replace('_', ' ', $pathPart), 'name' => str_replace('_', ' ', $pathPart),
'path' => $hasContent ? urlencode($currentPath) : null, 'path' => $hasContent ? $currentPathUrlEncoded : null,
'active' => $isLast); 'active' => $isLast);
} }
} }