diff --git a/.gitignore b/.gitignore index 0c0fc0042..4a04ea203 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # we ignore all folders other than yeswiki's ones, to be able to use farm for example -*/ +/*/ !.github/ !actions/ !cache/ diff --git a/actions/EraseSpamedCommentsAction.php b/actions/EraseSpamedCommentsAction.php index 28f20154f..ac182fc7c 100755 --- a/actions/EraseSpamedCommentsAction.php +++ b/actions/EraseSpamedCommentsAction.php @@ -20,9 +20,7 @@ * * */ -use YesWiki\Bazar\Controller\EntryController; -use YesWiki\Bazar\Service\EntryManager; -use YesWiki\Core\Service\PageManager; +use YesWiki\Core\Controller\PageController; use YesWiki\Core\YesWikiAction; class EraseSpamedCommentsAction extends YesWikiAction @@ -86,12 +84,7 @@ public function run() // (si DeleteOrphanedPage ne convient pas, soit on créé // une autre, soit on la modifie echo "Effacement de : " . $page . "
\n"; - if ($wiki->services->get(EntryManager::class)->isEntry($page)){ - if($wiki->services->get(EntryController::class)->delete($page)){ - $deletedPages .= $page . ", "; - } - } else { - $wiki->services->get(PageManager::class)->deleteOrphaned($page); + if ($wiki->services->get(PageController::class)->delete($page)){ $deletedPages .= $page . ", "; } } diff --git a/actions/footer.php b/actions/footer.php deleted file mode 100644 index a38ba7c35..000000000 --- a/actions/footer.php +++ /dev/null @@ -1,64 +0,0 @@ -services->get(ThemeManager::class); -if ($themeManager->getUseFallbackTheme()) { - $chemin_theme = 'themes/'.$themeManager->getFavoriteTheme().'/squelettes/'.$themeManager->getFavoriteSquelette(); - $file_content = file_get_contents($chemin_theme); -} else { - $chemin_theme = 'themes/'.$themeManager->getFavoriteTheme().'/squelettes/'.$themeManager->getFavoriteSquelette(); - if (file_exists('custom/'.$chemin_theme)) { - $file_content = file_get_contents('custom/'.$chemin_theme); - } else { - $file_content = file_get_contents($chemin_theme); - } -} - -//On recupere la partie bas du template et on execute les actions wikini -$template_decoupe = explode("{WIKINI_PAGE}", $file_content); -$template_footer = $template_decoupe[1]; - -if ($act = preg_match_all("/".'(\\{\\{)'.'(.*?)'.'(\\}\\})'."/is", $template_footer, $matches)) { - $i = 0; - $j = 0; - foreach ($matches as $valeur) { - foreach ($valeur as $val) { - if (isset($matches[2][$j]) && $matches[2][$j]!='') { - $action= $matches[2][$j]; - $template_footer = str_replace('{{'.$action.'}}', $this->Format('{{'.$action.'}}', 'action'), $template_footer); - } - $j++; - } - $i++; - } -} - -// on affiche les requetes SQL et le temps de chargement en mode debug -if ($this->GetConfigValue('debug')=='yes') { - $debug_log_sql_queries = ''; - $T_SQL=0; - - $queryLog = $this->services->get(DbService::class)->getQueryLog(); - foreach ($queryLog as $query) { - $debug_log_sql_queries .= $query['query'].' ('.round($query['time'], 4).")
\n"; - $T_SQL = $T_SQL + $query['time']; - } - - $end = microtime(true); - $debug_log = "
DEPRECIATED FOOTER USED FOR BACKUP
\n"; - $debug_log .= "
\n

Query log

\n"; - $debug_log .= "".round($end-T_START, 4)." s total time
\n"; - $debug_log .= round($T_SQL, 4)." s total SQL time
(".round((($T_SQL/($end-T_START))*100), 2)."% of total time)
\n"; - $debug_log .= "".count($queryLog)." queries :
\n"; - $debug_log .= $debug_log_sql_queries; - $debug_log .= "
\n"; - $template_footer = str_replace('', $debug_log.'', $template_footer); -} - -echo $template_footer; diff --git a/actions/header.php b/actions/header.php deleted file mode 100644 index cae5515a6..000000000 --- a/actions/header.php +++ /dev/null @@ -1,47 +0,0 @@ -services->get(ThemeManager::class); -//=======Restes de wikini================================================================================= -$user = $this->GetUser(); - -if ($themeManager->getUseFallbackTheme()) { - $chemin_theme = 'themes/'.$themeManager->getFavoriteTheme().'/squelettes/'.$themeManager->getFavoriteSquelette(); - $file_content = file_get_contents($chemin_theme); -} else { - $chemin_theme = 'themes/'.$themeManager->getFavoriteTheme().'/squelettes/'.$themeManager->getFavoriteSquelette(); - if (file_exists('custom/'.$chemin_theme)) { - $file_content = file_get_contents('custom/'.$chemin_theme); - } else { - $file_content = file_get_contents($chemin_theme); - } -} - -//On recupere la partie haut du template et on execute les actions wikini -$template_decoupe = explode("{WIKINI_PAGE}", $file_content); -$template_header = $template_decoupe[0]; - -if ($act = preg_match_all("/".'(\\{\\{)'.'(.*?)'.'(\\}\\})'."/is", $template_header, $matches)) { - $i = 0; - $j = 0; - foreach ($matches as $valeur) { - foreach ($valeur as $val) { - if (isset($matches[2][$j]) && $matches[2][$j]!='') { - $action = $matches[2][$j]; - $template_header = str_replace('{{'.$action.'}}', $this->Format('{{'.$action.'}}', 'action'), $template_header); - } - $j++; - } - $i++; - } -} - -if ($this->GetConfigValue('debug')=='yes') { - $template_header .= "
DEPRECIATED HEADER USED FOR BACKUP
\n"; -} - -echo $template_header; diff --git a/handlers/page/deletepage.php b/handlers/page/deletepage.php index 4a4f181c0..ff5ea9845 100755 --- a/handlers/page/deletepage.php +++ b/handlers/page/deletepage.php @@ -2,10 +2,8 @@ use Symfony\Component\Security\Csrf\Exception\TokenNotFoundException; use Symfony\Component\Security\Csrf\CsrfTokenManager; -use YesWiki\Bazar\Controller\EntryController; -use YesWiki\Bazar\Service\EntryManager; use YesWiki\Core\Controller\CsrfTokenController; -use YesWiki\Core\Service\PageManager; +use YesWiki\Core\Controller\PageController; // Vérification de sécurité if (!defined("WIKINI_VERSION")) { @@ -53,15 +51,7 @@ } else { try { $csrfTokenController->checkToken('main', 'POST', 'csrf-token',false); - if ($this->services->get(EntryManager::class)->isEntry($tag)){ - if($this->services->get(EntryController::class)->delete($tag)){ - $hasBeenDeleted = true; - } - } else { - $this->services->get(PageManager::class)->deleteOrphaned($tag); - $this->LogAdministrativeAction($this->GetUserName(), "Suppression de la page ->\"\"" . $tag . "\"\""); - $hasBeenDeleted = true; - } + $hasBeenDeleted = $this->services->get(PageController::class)->delete($tag); if ($hasBeenDeleted){ $msg = str_replace("{tag}", $tag, _t('DELETEPAGE_MESSAGE')); // if $incomingurl has been defined and doesn't refer to the deleted page, redirect to it diff --git a/includes/YesWiki.php b/includes/YesWiki.php index 48ba03d4d..460092011 100755 --- a/includes/YesWiki.php +++ b/includes/YesWiki.php @@ -989,7 +989,7 @@ public function MakesGroupRecursive($gname, $acl, $origin = null, $checked = arr if ($line[0] == '@') { $line = substr($line, 1); if (! in_array($line, $checked)) { - if ($this->MakesGroupRecursive($line, $this->GetGroupACL($line), $origin, $checked)) { + if ($this->MakesGroupRecursive($line, $this->GetGroupACL($line) ?? '', $origin, $checked)) { return true; } } diff --git a/includes/controllers/ApiController.php b/includes/controllers/ApiController.php index 797b39ad0..1d1a07aac 100644 --- a/includes/controllers/ApiController.php +++ b/includes/controllers/ApiController.php @@ -14,6 +14,7 @@ use YesWiki\Core\Controller\ArchiveController; use YesWiki\Core\Controller\AuthController; use YesWiki\Core\Controller\CsrfTokenController; +use YesWiki\Core\Controller\PageController; use YesWiki\Core\Controller\UserController; use YesWiki\Core\Exception\DeleteUserException; use YesWiki\Core\Exception\ExitException; @@ -377,9 +378,12 @@ public function getPage(Request $request, $tag) public function deletePage($tag) { $pageManager = $this->getService(PageManager::class); + $pageController = $this->getService(PageController::class); $dbService = $this->getService(DbService::class); - $result = []; + $result = [ + 'notDeleted' => [$tag] + ]; $code = Response::HTTP_INTERNAL_SERVER_ERROR; try { $page = $pageManager->getOne($tag, null, false); @@ -387,22 +391,17 @@ public function deletePage($tag) $code = Response::HTTP_NOT_FOUND; } else { $tag = isset($page['tag']) ? $page['tag'] : $tag; + $result['notDeleted'] = [$tag]; if ($this->wiki->UserIsOwner($tag) || $this->wiki->UserIsAdmin()) { if (!$pageManager->isOrphaned($tag)) { $dbService->query("DELETE FROM {$dbService->prefixTable('links')} WHERE to_tag = '$tag'"); } - $pageManager->deleteOrphaned($tag); - $page = $pageManager->getOne($tag, null, false); - if (!empty($page)) { + $done = $pageController->delete($tag); + if (!$done || !empty($pageManager->getOne($tag, null, false))) { $code = Response::HTTP_INTERNAL_SERVER_ERROR; - $result = [ - 'notDeleted' => [$tag] - ]; } else { - $this->wiki->LogAdministrativeAction($this->wiki->GetUserName(), "Suppression de la page ->\"\"$tag\"\"", false); - $result = [ - 'deleted' => [$tag] - ]; + $result['deleted'] = [$tag]; + unset($result['notDeleted']); $code = Response::HTTP_OK; } } else { @@ -412,25 +411,17 @@ public function deletePage($tag) } catch (Throwable $th) { try { $page = $pageManager->getOne($tag, null, false); + $result['error'] = $th->getMessage(); if (!empty($page)) { $code = Response::HTTP_INTERNAL_SERVER_ERROR; - $result = [ - 'notDeleted' => [$tag], - 'error' => $th->getMessage() - ]; } else { $code = Response::HTTP_OK; - $result = [ - 'deleted' => [$tag], - 'error' => $th->getMessage() - ]; + unset($result['notDeleted']); + $result['deleted'] = [$tag]; } } catch (Throwable $th) { $code = Response::HTTP_INTERNAL_SERVER_ERROR; - $result = [ - 'notDeleted' => [$tag], - 'error' => $th->getMessage() - ]; + $result['error'] = $th->getMessage(); } } diff --git a/includes/controllers/PageController.php b/includes/controllers/PageController.php new file mode 100644 index 000000000..d496da4bd --- /dev/null +++ b/includes/controllers/PageController.php @@ -0,0 +1,48 @@ +authController = $authController; + $this->entryController = $entryController; + $this->entryManager = $entryManager; + $this->pageManager = $pageManager; + } + + /** + * delete a page from tag + * but be carefull entry or page + * @param string $tag + * @return bool $done + * @throws Exception if in hibernation or if entry not deleted + */ + public function delete(string $tag): bool + { + if ($this->entryManager->isEntry($tag)){ + return $this->entryController->delete($tag); + } else { + $this->pageManager->deleteOrphaned($tag); + $this->wiki->LogAdministrativeAction($this->authController->getLoggedUserName(), "Suppression de la page ->\"\"" . $tag . "\"\""); + return true; + } + } +} diff --git a/includes/services/Performer.php b/includes/services/Performer.php index f63ef7d9d..13ebdc716 100644 --- a/includes/services/Performer.php +++ b/includes/services/Performer.php @@ -93,11 +93,7 @@ private function findObjectInPath($dir, $objectType) 'baseName' => $baseName, 'isDefinedAsClass' => $isDefinedAsClass ]); - } elseif ( - // TODO remove this test when removing actions/header.php and footer.php - !isset($object['filePath']) // object not already defined - || !in_array($filePath, ['actions/header.php','actions\header.php','actions/footer.php','actions\footer.php']) - ) { + } else { $object = [ 'filePath' => $filePath, 'baseName' => $baseName, diff --git a/tools/bazar/fields/FileField.php b/tools/bazar/fields/FileField.php index ec69a3464..7ce453782 100644 --- a/tools/bazar/fields/FileField.php +++ b/tools/bazar/fields/FileField.php @@ -7,6 +7,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use YesWiki\Bazar\Service\EntryManager; use YesWiki\Bazar\Service\Guard; +use YesWiki\Core\Service\EventDispatcher; use YesWiki\Security\Controller\SecurityController; /** @@ -279,11 +280,16 @@ protected function updateEntryAfterFileDelete($entry) unset($entryFromDb[$this->propertyName]); $entryFromDb['antispam'] = 1; $entryFromDb['date_maj_fiche'] = date('Y-m-d H:i:s', time()); - $entryManager->update($entryFromDb['id_fiche'], $entryFromDb, false, true); + $newEntry = $entryManager->update($entryFromDb['id_fiche'], $entryFromDb, false, true); $_GET = $previousGet; $_POST = $previousPost; $_REQUEST = $previousRequest; + + $errors = $this->services->get(EventDispatcher::class)->yesWikiDispatch('entry.updated', [ + 'id' => $newEntry['id_fiche'], + 'data' => $newEntry + ]); } } } diff --git a/tools/bazar/fields/LinkedEntryField.php b/tools/bazar/fields/LinkedEntryField.php index 35557f51a..bccb0d3aa 100644 --- a/tools/bazar/fields/LinkedEntryField.php +++ b/tools/bazar/fields/LinkedEntryField.php @@ -76,7 +76,7 @@ protected function renderSecuredBazarList($entry): string protected function isEmptyOutput(string $output): bool { - return empty($output) || preg_match('/
]*>\s*
<\/div><\/div>/',$output); + return empty($output) || preg_match('/
]*>\\s*
\\s*<\\/div>\\s*<\\/div>/',$output); } private function getBazarListAction($entry) diff --git a/tools/security/actions/despam.php b/tools/security/actions/despam.php index d867ecb35..0b837cae6 100755 --- a/tools/security/actions/despam.php +++ b/tools/security/actions/despam.php @@ -1,8 +1,6 @@ services->get(EntryManager::class)->isEntry($page)){ - if($this->services->get(EntryController::class)->delete($page)){ - $deletedPages .= $page . ", "; - } - } else { - $this->services->get(PageManager::class)->deleteOrphaned($page); - $deletedPages .= $page . ", "; + if ($this->services->get(PageController::class)->delete($page)){ + $deletedPages .= $page . ", "; } } $deletedPages = trim($deletedPages, ", "); diff --git a/tools/tags/handlers/page/ajaxdeletepage.php b/tools/tags/handlers/page/ajaxdeletepage.php index df093229f..80f579d57 100755 --- a/tools/tags/handlers/page/ajaxdeletepage.php +++ b/tools/tags/handlers/page/ajaxdeletepage.php @@ -1,8 +1,6 @@ UserIsOwner() || $this->UserIsAdmin()) { $tag = $this->GetPageTag(); - if ($this->services->get(EntryManager::class)->isEntry($page)){ - $this->services->get(EntryController::class)->delete($page); - } else { - $this->services->get(PageManager::class)->deleteOrphaned($page); - $this->LogAdministrativeAction($this->GetUserName(), "Suppression de la page ->\"\"" . $tag . "\"\""); - } + $this->services->get(PageController::class)->delete($tag); echo $_GET['jsonp_callback']."(".json_encode(array("reponse"=>mb_convert_encoding("succes", 'UTF-8', 'ISO-8859-1'))).")"; } else { echo $_GET['jsonp_callback']."(".json_encode(array("reponse"=>mb_convert_encoding("interdit", 'UTF-8', 'ISO-8859-1'))).")";