From a9b3e1424e3433d20492c57710c8d1e1020ff45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Noack?= <noack@data-quest.de> Date: Thu, 3 Mar 2022 09:59:08 +0000 Subject: [PATCH] Resolve "Wiki: Jede Seite hat als Titel "WikiWikiWeb" in der Kopfzeile" --- lib/models/WikiPage.class.php | 19 +++++++++++++++++++ lib/modules/CoreWiki.class.php | 2 +- lib/wiki.inc.php | 18 ++++++++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/models/WikiPage.class.php b/lib/models/WikiPage.class.php index 3d8ca9e3f69..82abcd41885 100644 --- a/lib/models/WikiPage.class.php +++ b/lib/models/WikiPage.class.php @@ -289,4 +289,23 @@ class WikiPage extends SimpleORMap implements PrivacyObject return $descendants; } + /** + * @param string $other_keyword + * @return bool + */ + public function isDescendantOf(string $other_keyword): bool + { + if ($other_keyword === $this->keyword) { + return false; + } + $other_page = WikiPage::findLatestPage($this->range_id, $other_keyword); + if ($other_page) { + foreach ($other_page->getDescendants() as $descendant) { + if ($descendant->keyword === $this->keyword) { + return true; + } + } + } + return false; + } } diff --git a/lib/modules/CoreWiki.class.php b/lib/modules/CoreWiki.class.php index e389a8f0b2a..7921e4ce963 100644 --- a/lib/modules/CoreWiki.class.php +++ b/lib/modules/CoreWiki.class.php @@ -173,7 +173,7 @@ class CoreWiki extends CorePlugin implements StudipModule */ public static function getTOC($startPage): TOCItem { - $root = new TOCItem($startPage->keyword); + $root = new TOCItem($startPage->keyword === 'WikiWikiWeb' ? _('Wiki-Startseite') : $startPage->keyword); $root->setURL(URLHelper::getURL('wiki.php', ['keyword' => $startPage->keyword])) ->setActive($startPage->keyword == Request::get('keyword') || $startPage->keyword == 'WikiWikiWeb' && !Request::get('keyword')); diff --git a/lib/wiki.inc.php b/lib/wiki.inc.php index 70f4a2a76f1..f813d059ea2 100644 --- a/lib/wiki.inc.php +++ b/lib/wiki.inc.php @@ -995,6 +995,13 @@ function wikiEdit($keyword, $wikiData, $user_id, $backpage=NULL, $ancestor=NULL) $page->version, $editor); $page_string .= '<br>'; $page_string .= strftime(_('am %x, %X'), $page->chdate); + if ($page->keyword === 'WikiWikiWeb' || $page->isDescendantOf('WikiWikiWeb')) { + $toc = CoreWiki::getTOC(WikiPage::getStartPage(Context::getId())); + } else { + $toc = new TOCItem($page->keyword); + } + } else { + $toc = new TOCItem($keyword === 'WikiWikiWeb' ? _('Wiki-Startseite') : $keyword); } // Action menu for content bar. @@ -1027,7 +1034,7 @@ function wikiEdit($keyword, $wikiData, $user_id, $backpage=NULL, $ancestor=NULL) } // Create content bar. - $contentBar = new ContentBar(CoreWiki::getTOC(WikiPage::getStartPage(Context::getId())), + $contentBar = new ContentBar($toc, $page_string, Icon::create('wiki'), $actionMenu); $template = $GLOBALS['template_factory']->open('wiki/edit.php'); @@ -1540,6 +1547,13 @@ function showWikiPage($keyword, $version, $special="", $show_comments="icon", $h $page->version, $editor); $page_string .= '<br>'; $page_string .= strftime(_('am %x, %X'), $page->chdate); + if ($page->keyword === 'WikiWikiWeb' || $page->isDescendantOf('WikiWikiWeb')) { + $toc = CoreWiki::getTOC(WikiPage::getStartPage(Context::getId())); + } else { + $toc = new TOCItem($page->keyword); + } + } else { + $toc = new TOCItem($keyword === 'WikiWikiWeb' ? _('Wiki-Startseite') : $keyword); } // Action menu for content bar. @@ -1577,7 +1591,7 @@ function showWikiPage($keyword, $version, $special="", $show_comments="icon", $h } // Create content bar. - $contentBar = new ContentBar(CoreWiki::getTOC(WikiPage::getStartPage(Context::getId())), + $contentBar = new ContentBar($toc, $page_string, Icon::create('wiki'), $actionMenu); if ($hilight) { -- GitLab