Skip to content

Commit de71585

Browse files
committed
Allowed the display of deleted items via plugin
1 parent 8690254 commit de71585

File tree

8 files changed

+169
-21
lines changed

8 files changed

+169
-21
lines changed

com.woltlab.wcf/templates/deletedContentList.tpl

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
{capture assign='pageTitle'}{lang}wcf.moderation.deletedContent.{@$objectType}{/lang}{/capture}
22

33
{capture assign='sidebarRight'}
4-
<section class="box" data-static-box-identifier="com.woltlab.wcf.DeletedContentListMenu">
5-
<h2 class="boxTitle">{lang}wcf.moderation.deletedContent.objectTypes{/lang}</h2>
6-
7-
<div class="boxContent">
8-
<nav>
9-
<ul class="boxMenu">
10-
{foreach from=$availableObjectTypes item=availableObjectType}
11-
<li{if $objectType == $availableObjectType->objectType} class="active"{/if}><a class="boxMenuLink" href="{link controller='DeletedContentList'}objectType={@$availableObjectType->objectType}{/link}">{lang}wcf.moderation.deletedContent.objectType.{@$availableObjectType->objectType}{/lang}</a></li>
12-
{/foreach}
13-
</ul>
14-
</nav>
15-
</div>
16-
</section>
4+
{unsafe:$deletedItemsBox->render()}
175
{/capture}
186

197
{capture assign='contentTitle'}{lang}wcf.moderation.deletedContent.{@$objectType}{/lang}{/capture}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<section class="box" data-static-box-identifier="com.woltlab.wcf.DeletedContentListMenu">
2+
<h2 class="boxTitle">{lang}wcf.moderation.deletedContent.objectTypes{/lang}</h2>
3+
4+
<div class="boxContent">
5+
<nav>
6+
<ul class="boxMenu">
7+
{foreach from=$types item=type}
8+
<li{if $type->id == $activeId} class="active"{/if}>
9+
<a class="boxMenuLink" href="{$type->link}">{lang}{$type->languageItem}{/lang}</a>
10+
</li>
11+
{/foreach}
12+
</ul>
13+
</nav>
14+
</div>
15+
</section>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace wcf\event\moderation;
4+
5+
use wcf\data\object\type\ObjectTypeCache;
6+
use wcf\event\IPsr14Event;
7+
use wcf\page\DeletedContentListPage;
8+
use wcf\system\moderation\DeletedItems;
9+
use wcf\system\request\LinkHandler;
10+
11+
/**
12+
* Requests the collection of deleted item types.
13+
*
14+
* @author Marcel Werk
15+
* @copyright 2001-2025 WoltLab GmbH
16+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17+
* @since 6.2
18+
*/
19+
final class DeletedItemsCollecting implements IPsr14Event
20+
{
21+
/**
22+
* @var DeletedItems[]
23+
*/
24+
private array $types = [];
25+
26+
public function __construct()
27+
{
28+
$this->loadLegacyProviders();
29+
}
30+
31+
public function register(DeletedItems $type): void
32+
{
33+
$this->types[] = $type;
34+
}
35+
36+
/**
37+
* @return DeletedItems[]
38+
*/
39+
public function getTypes(): array
40+
{
41+
return $this->types;
42+
}
43+
44+
/**
45+
* @deprecated 6.2
46+
*/
47+
private function loadLegacyProviders(): void
48+
{
49+
$objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.deletedContent');
50+
foreach ($objectTypes as $objectType) {
51+
$this->register(new DeletedItems(
52+
$objectType->objectType,
53+
'wcf.moderation.deletedContent.objectType.' . $objectType->objectType,
54+
LinkHandler::getInstance()->getControllerLink(
55+
DeletedContentListPage::class,
56+
['objectType' => $objectType->objectType]
57+
)
58+
));
59+
}
60+
}
61+
}

wcfsetup/install/files/lib/page/DeletedContentListPage.class.php

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
namespace wcf\page;
44

5+
use Laminas\Diactoros\Response\RedirectResponse;
56
use wcf\data\DatabaseObject;
67
use wcf\data\DatabaseObjectList;
78
use wcf\data\object\type\ObjectTypeCache;
9+
use wcf\event\moderation\DeletedItemsCollecting;
10+
use wcf\system\event\EventHandler;
811
use wcf\system\exception\IllegalLinkException;
12+
use wcf\system\moderation\DeletedItemsBoxComponent;
913
use wcf\system\WCF;
1014

1115
/**
@@ -42,23 +46,36 @@ public function readParameters()
4246
{
4347
parent::readParameters();
4448

45-
// get object type
4649
if (isset($_REQUEST['objectType'])) {
4750
$this->objectType = ObjectTypeCache::getInstance()->getObjectTypeByName(
4851
'com.woltlab.wcf.deletedContent',
4952
$_REQUEST['objectType']
5053
);
54+
55+
if ($this->objectType === null) {
56+
throw new IllegalLinkException();
57+
}
5158
} else {
52-
// use first object type
53-
$objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.deletedContent');
54-
if (!empty($objectTypes)) {
55-
$this->objectType = \reset($objectTypes);
59+
$link = $this->getFirstTypeLink();
60+
if ($link === null) {
61+
throw new IllegalLinkException();
5662
}
63+
64+
return new RedirectResponse($link);
5765
}
66+
}
5867

59-
if ($this->objectType === null) {
60-
throw new IllegalLinkException();
68+
private function getFirstTypeLink(): ?string
69+
{
70+
$event = new DeletedItemsCollecting();
71+
EventHandler::getInstance()->fire($event);
72+
$types = $event->getTypes();
73+
74+
if ($types === []) {
75+
return null;
6176
}
77+
78+
return reset($types)->link;
6279
}
6380

6481
/**
@@ -77,7 +94,7 @@ public function assignVariables()
7794
parent::assignVariables();
7895

7996
WCF::getTPL()->assign([
80-
'availableObjectTypes' => ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.deletedContent'),
97+
'deletedItemsBox' => new DeletedItemsBoxComponent($this->objectType->objectType),
8198
'objectType' => $this->objectType->objectType,
8299
'resultListTemplateName' => $this->objectType->getProcessor()->getTemplateName(),
83100
'resultListApplication' => $this->objectType->getProcessor()->getApplication(),

wcfsetup/install/files/lib/system/moderation/AbstractDeletedContentProvider.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* @author Matthias Schmidt
1212
* @copyright 2001-2019 WoltLab GmbH
1313
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @deprecated 6.2 Use `DeletedItems` instead
1415
*
1516
* @template T of DatabaseObjectList
1617
* @implements IDeletedContentProvider<T>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace wcf\system\moderation;
4+
5+
/**
6+
* Represents a type of deleted items.
7+
*
8+
* @author Marcel Werk
9+
* @copyright 2001-2025 WoltLab GmbH
10+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11+
* @since 6.2
12+
*/
13+
class DeletedItems
14+
{
15+
public function __construct(
16+
public readonly string $id,
17+
public readonly string $languageItem,
18+
public readonly string $link
19+
) {}
20+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace wcf\system\moderation;
4+
5+
use wcf\event\moderation\DeletedItemsCollecting;
6+
use wcf\system\event\EventHandler;
7+
use wcf\system\WCF;
8+
9+
/**
10+
* Represents the deleted items box.
11+
*
12+
* @author Marcel Werk
13+
* @copyright 2001-2025 WoltLab GmbH
14+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15+
* @since 6.2
16+
*/
17+
class DeletedItemsBoxComponent
18+
{
19+
public function __construct(
20+
public readonly string $activeId,
21+
) {}
22+
23+
public function render(): string
24+
{
25+
return WCF::getTPL()->render(
26+
'wcf',
27+
'deletedItemsBox',
28+
[
29+
'types' => $this->getTypes(),
30+
'activeId' => $this->activeId,
31+
],
32+
);
33+
}
34+
35+
/**
36+
* @return DeletedItems[]
37+
*/
38+
private function getTypes(): array
39+
{
40+
$event = new DeletedItemsCollecting();
41+
EventHandler::getInstance()->fire($event);
42+
43+
return $event->getTypes();
44+
}
45+
}

wcfsetup/install/files/lib/system/moderation/IDeletedContentProvider.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* @author Marcel Werk
1111
* @copyright 2001-2019 WoltLab GmbH
1212
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13+
* @deprecated 6.2 Use `DeletedItems` instead
1314
*
1415
* @template T of DatabaseObjectList
1516
*/

0 commit comments

Comments
 (0)