aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFinn Schneider <schneider@data-quest.de>2025-11-27 09:46:32 +0000
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2026-01-16 14:00:08 +0100
commite71d4e8b3015ad4a3e1dafc595070894cf640710 (patch)
tree17a7b0cd05d4ba6e3d5e7a4525758f3eceecb6c1
parentda5706740aad5509eb6b7873156395d0c4aca312 (diff)
Resolve "Wiki-Startseite-Umbau"
Closes #5946 Merge request studip/studip!4614
-rw-r--r--app/controllers/course/wiki.php139
-rw-r--r--app/views/course/wiki/page.php2
-rw-r--r--db/migrations/5.5.37_cleanup_wiki_startpage_parent.php22
-rw-r--r--lib/modules/CoreWiki.class.php8
4 files changed, 98 insertions, 73 deletions
diff --git a/app/controllers/course/wiki.php b/app/controllers/course/wiki.php
index 4163e66..2b69639 100644
--- a/app/controllers/course/wiki.php
+++ b/app/controllers/course/wiki.php
@@ -82,7 +82,7 @@ class Course_WikiController extends AuthenticatedController
_('Neue Wiki-Seite anlegen'),
$this->new_pageURL($this->page->id),
Icon::create('add'),
- ['data-dialog' => 'width=700']
+ $this->range->getConfiguration()->WIKI_STARTPAGE_ID ? ['data-dialog' => 'width=700'] : []
);
if ($GLOBALS['perm']->have_studip_perm('tutor', $this->range->id)) {
$actions->addLink(
@@ -246,7 +246,7 @@ class Course_WikiController extends AuthenticatedController
],
'parent_id' => [
'label' => _('Übergeordnete Seite im Inhaltsverzeichnis'),
- 'type' => 'select',
+ 'type' => $this->range->getConfiguration()->WIKI_STARTPAGE_ID == $page->getId() ? 'no' : 'select',
'options' => $options
],
'read_permission' => [
@@ -417,8 +417,14 @@ class Course_WikiController extends AuthenticatedController
throw new AccessDeniedException();
}
CSRFProtection::verifyUnsafeRequest();
+
+ $start_page_id = Request::option('wiki_startpage_id');
+
$this->config = $this->range->getConfiguration();
- $this->config->store('WIKI_STARTPAGE_ID', trim(Request::option('wiki_startpage_id')));
+ $this->config->store('WIKI_STARTPAGE_ID', $start_page_id);
+ $page = WikiPage::find($start_page_id);
+ $page->parent_id = null;
+ $page->store();
if (
$this->config->WIKI_CREATE_PERMISSION === 'all'
|| $GLOBALS['perm']->have_studip_perm($this->config->WIKI_CREATE_PERMISSION, Context::getId())
@@ -854,69 +860,65 @@ class Course_WikiController extends AuthenticatedController
'range_id = ? ORDER BY name',
[$this->range->id]
);
- $is_start_page = count($options) <= 1;
- if ($is_start_page) {
- PageLayout::setTitle(_('Wiki-Startseite erstellen'));
+ if (!$this->range->getConfiguration()->WIKI_STARTPAGE_ID) {
+ $page->user_id = User::findCurrent()->getId();
+ $page->name = _('Wiki-Startseite');
+ $page->parent_id = null;
+ $page->range_id = Context::getId();
+ $page->store();
+ $this->range->getConfiguration()->store('WIKI_STARTPAGE_ID', $page->id);
+ $this->redirect($this->editURL($page));
} else {
PageLayout::setTitle(_('Neue Wikiseite erstellen'));
- }
- $this->form = \Studip\Forms\Form::fromSORM(
- $page,
- [
- 'legend' => _('Daten'),
- 'fields' => [
- 'range_id' => [
- 'type' => 'no',
- 'mapper' => function () { return $this->range->id; }
- ],
- 'user_id' => [
- 'type' => 'no',
- 'mapper' => function () { return User::findCurrent()->id; }
- ],
- 'name' => [
- 'required' => !$is_start_page,
- 'label' => _('Name der Seite'),
- 'type' => $is_start_page ? 'no' : 'text',
- 'mapper' => function ($value) use ($is_start_page) {
- return $is_start_page ? 'Wiki-Startseite' : $value;
- },
- 'validate' => function ($value, $input) {
- $name_count = WikiPage::countBySql('`name` = :name AND `range_id` = :range_id', [
- 'name' => $value,
- 'range_id' => $this->range->id
- ]);
- if ($name_count === 0) {
+ $this->form = \Studip\Forms\Form::fromSORM(
+ $page,
+ [
+ 'legend' => _('Daten'),
+ 'fields' => [
+ 'range_id' => [
+ 'type' => 'no',
+ 'mapper' => function () {
+ return $this->range->id;
+ }
+ ],
+ 'user_id' => [
+ 'type' => 'no',
+ 'mapper' => fn() => User::findCurrent()->id,
+ ],
+ 'name' => [
+ 'required' => true,
+ 'label' => _('Name der Seite'),
+ 'type' => 'text',
+ 'validate' => function ($value, $input) {
+ $name_count = WikiPage::countBySql(
+ '`name` = :name AND `range_id` = :range_id',
+ [
+ 'name' => $value,
+ 'range_id' => $this->range->id
+ ]
+ );
+
+ if ($name_count > 0) {
+ return _('Name existiert schon.');
+ }
+
return true;
- } else {
- return _('Name existiert schon.');
}
- }
- ],
- 'parent_id' => [
- 'label' => _('Übergeordnete Seite im Inhaltsverzeichnis'),
- 'type' => 'select',
- 'options' => $options
- ],
- 'autocreate_links' => [
- 'label' => _('Den Seitennamen der neuen Seite automatisch in anderen Wikiseiten verlinken.'),
- 'type' => 'checkbox',
- 'permission' => WikiPage::countBySql("`range_id` = ?", [$this->range->id]) > 0
- ]
- ]
- ],
- $this->allpagesURL()
- )->addStoreCallback(function ($form, $values) {
- $page = $form->getLastPart()->getContextObject();
- $other_pages = WikiPage::countBySQL(
- "`range_id` = :range_id AND `page_id` != :page_id",
- [
- 'page_id' => $page->id,
- 'range_id' => $page->range_id,
+ ],
+ 'parent_id' => [
+ 'label' => _('Übergeordnete Seite im Inhaltsverzeichnis'),
+ 'type' => 'select',
+ 'options' => $options
+ ],
+ 'autocreate_links' => [
+ 'label' => _('Den Seitennamen der neuen Seite automatisch in anderen Wikiseiten verlinken.'),
+ 'type' => 'checkbox',
+ 'permission' => WikiPage::countByRange_id($this->range->id) > 0
+ ]
]
- );
- if ($other_pages == 0) {
- $this->range->getConfiguration()->store('WIKI_STARTPAGE_ID', $page->id);
- }
+ ],
+ $this->allpagesURL()
+ )->addStoreCallback(function ($form, $values) {
if (Request::bool('autocreate_links')) {
$pages = WikiPage::findBySQL(
"`range_id` = :range_id AND `content` LIKE :search",
@@ -940,13 +942,14 @@ class Course_WikiController extends AuthenticatedController
}
}
}
- )->setURL($this->new_pageURL($parent_id))
- ->validate();
- if (Request::isPost()) {
- $this->form->store();
- $this->redirect($this->editURL($page));
- } else {
- $this->render_form($this->form);
+ )->setURL($this->new_pageURL($parent_id))
+ ->validate();
+ if (Request::isPost()) {
+ $this->form->store();
+ $this->redirect($this->editURL($page));
+ } else {
+ $this->render_form($this->form);
+ }
}
}
diff --git a/app/views/course/wiki/page.php b/app/views/course/wiki/page.php
index 0b36c6c..97f66e9 100644
--- a/app/views/course/wiki/page.php
+++ b/app/views/course/wiki/page.php
@@ -21,7 +21,6 @@ echo $contentbar;
<div class="wiki-empty-background"></div>
<? else : ?>
<a href="<?= $controller->new_page() ?>"
- data-dialog
class="wiki-empty-background"
title="<?= _('Dieses Wiki ist noch leer. Erstellen Sie die erste Wiki-Seite.') ?>"></a>
<? endif ?>
@@ -30,7 +29,6 @@ echo $contentbar;
<div class="wiki-teaser">
<? else : ?>
<a href="<?= $controller->new_page() ?>"
- data-dialog
class="wiki-teaser">
<? endif ?>
<?= _('Erstelle die erste Wiki-Seite') ?>
diff --git a/db/migrations/5.5.37_cleanup_wiki_startpage_parent.php b/db/migrations/5.5.37_cleanup_wiki_startpage_parent.php
new file mode 100644
index 0000000..74c188a
--- /dev/null
+++ b/db/migrations/5.5.37_cleanup_wiki_startpage_parent.php
@@ -0,0 +1,22 @@
+<?php
+/**
+ * @see https://gitlab.studip.de/studip/studip/-/issues/5946
+ */
+class CleanupWikiStartpageParent extends Migration
+{
+ public function up(): void
+ {
+ $query = "SELECT `range_id`, `value`
+ FROM `config_values`
+ WHERE `field` = 'WIKI_STARTPAGE_ID'";
+ $pages = DBManager::get()->fetchAll($query);
+
+ $query = "UPDATE `wiki_pages`
+ SET `parent_id` = NULL
+ WHERE `page_id` = ? AND `range_id` = ?";
+ $statement = DBManager::get()->prepare($query);
+ foreach ($pages as [$range_id, $page_id]) {
+ $statement->execute([$page_id, $range_id]);
+ }
+ }
+}
diff --git a/lib/modules/CoreWiki.class.php b/lib/modules/CoreWiki.class.php
index 45ddef2..593b829 100644
--- a/lib/modules/CoreWiki.class.php
+++ b/lib/modules/CoreWiki.class.php
@@ -115,7 +115,9 @@ class CoreWiki extends CorePlugin implements StudipModule
$navigation->setImage(Icon::create('wiki', Icon::ROLE_INFO_ALT));
$navigation->setActiveImage(Icon::create('wiki', Icon::ROLE_INFO));
- $navigation->addSubNavigation('start', new Navigation(_('Wiki-Startseite'), 'dispatch.php/course/wiki/page'));
+ $id = Context::get()->getConfiguration()->WIKI_STARTPAGE_ID;
+ $title = $id ? htmlReady(WikiPage::find($id)->name) : _('Wiki-Startseite');
+ $navigation->addSubNavigation('start', new Navigation($title, 'dispatch.php/course/wiki/page'));
if (WikiPage::countBySQL('`range_id` = ?', [$range_id]) > 0) {
if ($GLOBALS['perm']->have_studip_perm('user', $range_id)) {
$navigation->addSubNavigation('listnew', new Navigation(_('Neue Seiten'), 'dispatch.php/course/wiki/newpages'));
@@ -195,7 +197,7 @@ class CoreWiki extends CorePlugin implements StudipModule
$rootPage = WikiPage::find($rootId) ?? $activePage;
$rootToc = self::getTOCRecursive($rootPage, $activePage->page_id);
- $rootToc->setTitle(_('Wiki-Startseite'));
+ $rootToc->setTitle(htmlReady($rootPage->name));
$rootToc->setIcon(Icon::create('wiki'));
return $rootToc;
}
@@ -210,7 +212,7 @@ class CoreWiki extends CorePlugin implements StudipModule
*/
private static function getTOCRecursive(WikiPage $page, ?int $active_page_id): TOCItem
{
- $toc = new TOCItem($page->isNew() ? _('Wiki-Startseite') : $page->name);
+ $toc = new TOCItem($page->name);
$toc->setURL($page->isNew() ? URLHelper::getURL('dispatch.php/course/wiki/page') : URLHelper::getURL('dispatch.php/course/wiki/page/' . $page->id));
$toc->setActive($page->page_id == $active_page_id);
foreach ($page->children as $child) {