Skip to content

Commit

Permalink
Merge pull request #1111 from J9rem/fix/some-compatibility-errors
Browse files Browse the repository at this point in the history
Fix/some compatibility errors and PageController
  • Loading branch information
mrflos authored Nov 9, 2023
2 parents 9cefbe6 + 3d4319f commit 1b6933a
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 183 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

# we ignore all folders other than yeswiki's ones, to be able to use farm for example
*/
/*/
!.github/
!actions/
!cache/
Expand Down
11 changes: 2 additions & 9 deletions actions/EraseSpamedCommentsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 . "<br />\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 . ", ";
}
}
Expand Down
64 changes: 0 additions & 64 deletions actions/footer.php

This file was deleted.

47 changes: 0 additions & 47 deletions actions/header.php

This file was deleted.

14 changes: 2 additions & 12 deletions handlers/page/deletepage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion includes/YesWiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
37 changes: 14 additions & 23 deletions includes/controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -377,32 +378,30 @@ 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);
if (empty($page)) {
$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 {
Expand All @@ -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();
}
}

Expand Down
48 changes: 48 additions & 0 deletions includes/controllers/PageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace YesWiki\Core\Controller;

use Exception;
use YesWiki\Bazar\Controller\EntryController;
use YesWiki\Bazar\Service\EntryManager;
use YesWiki\Core\Controller\AuthController;
use YesWiki\Core\Service\PageManager;
use YesWiki\Core\YesWikiController;

class PageController extends YesWikiController
{
protected $authController;
protected $entryController;
protected $entryManager;
protected $pageManager;

public function __construct(
AuthController $authController,
EntryController $entryController,
EntryManager $entryManager,
PageManager $pageManager
) {
$this->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;
}
}
}
6 changes: 1 addition & 5 deletions includes/services/Performer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion tools/bazar/fields/FileField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
]);
}
}
}
2 changes: 1 addition & 1 deletion tools/bazar/fields/LinkedEntryField.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function renderSecuredBazarList($entry): string

protected function isEmptyOutput(string $output): bool
{
return empty($output) || preg_match('/<div id="[^"]+" class="bazar-list[^"]*"[^>]*>\s*<div class="list"><\/div><\/div>/',$output);
return empty($output) || preg_match('/<div id="[^"]+" class="bazar-list[^"]*"[^>]*>\\s*<div class="list">\\s*<\\/div>\\s*<\\/div>/',$output);
}

private function getBazarListAction($entry)
Expand Down
13 changes: 3 additions & 10 deletions tools/security/actions/despam.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

use YesWiki\Bazar\Controller\EntryController;
use YesWiki\Bazar\Service\EntryManager;
use YesWiki\Core\Service\PageManager;
use YesWiki\Core\Controller\PageController;
use YesWiki\Security\Controller\SecurityController;

// TODO
Expand Down Expand Up @@ -149,13 +147,8 @@
// Effacement de la page en utilisant la méthode adéquate
// (si DeleteOrphanedPage ne convient pas, soit on créé
// une autre, soit on la modifie
if ($this->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, ", ");
Expand Down
Loading

0 comments on commit 1b6933a

Please sign in to comment.