Commit | Line | Data |
---|---|---|
7bbcd781 TD |
1 | <?php |
2 | namespace wcf\acp\form; | |
7bbcd781 TD |
3 | use wcf\form\AbstractForm; |
4 | use wcf\system\clipboard\ClipboardHandler; | |
5 | use wcf\system\edit\EditHistoryManager; | |
6 | use wcf\system\exception\IllegalLinkException; | |
7 | use wcf\system\exception\UserInputException; | |
8 | use wcf\system\WCF; | |
9 | ||
10 | /** | |
11 | * Shows the user content revert changes form. | |
12 | * | |
13 | * @author Tim Duesterhus | |
14 | * @copyright 2001-2014 WoltLab GmbH | |
15 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
16 | * @package com.woltlab.wcf | |
17 | * @subpackage acp.form | |
18 | * @category Community Framework | |
19 | */ | |
20 | class UserContentRevertChangesForm extends AbstractForm { | |
77838209 | 21 | /** |
1a6e8c52 | 22 | * @see \wcf\page\AbstractPage::$neededModules |
77838209 TD |
23 | */ |
24 | public $neededModules = array('MODULE_EDIT_HISTORY'); | |
1a6e8c52 | 25 | |
7bbcd781 TD |
26 | /** |
27 | * @see \wcf\page\AbstractPage::$neededPermissions | |
28 | */ | |
29 | public $neededPermissions = array('admin.content.canBulkRevertContentChanges'); | |
30 | ||
31 | /** | |
32 | * @see \wcf\page\AbstractPage::$activeMenuItem | |
33 | */ | |
34 | public $activeMenuItem = 'wcf.acp.menu.link.user.management'; | |
35 | ||
36 | /** | |
37 | * ids of the relevant users | |
38 | * @var array<integer> | |
39 | */ | |
40 | public $userIDs = array(); | |
41 | ||
42 | /** | |
43 | * relevant users | |
44 | * @var array<\wcf\data\user\User> | |
45 | */ | |
46 | public $users = array(); | |
47 | ||
48 | /** | |
49 | * timeframe to consider | |
50 | * @var integer | |
51 | */ | |
52 | public $timeframe = 7; | |
53 | ||
54 | /** | |
55 | * id of the user clipboard item object type | |
56 | * @var integer | |
57 | */ | |
58 | protected $objectTypeID = null; | |
59 | ||
60 | /** | |
61 | * @see \wcf\page\IPage::readParameters() | |
62 | */ | |
63 | public function readParameters() { | |
64 | parent::readParameters(); | |
65 | ||
66 | // get object type id | |
67 | $this->objectTypeID = ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user'); | |
68 | // get user | |
69 | $this->users = ClipboardHandler::getInstance()->getMarkedItems($this->objectTypeID); | |
70 | if (empty($this->users)) { | |
71 | throw new IllegalLinkException(); | |
72 | } | |
73 | $this->userIDs = array_keys($this->users); | |
74 | } | |
75 | ||
76 | /** | |
77 | * @see \wcf\form\IForm::readFormParameters() | |
78 | */ | |
79 | public function readFormParameters() { | |
80 | parent::readFormParameters(); | |
81 | ||
82 | if (isset($_POST['timeframe'])) $this->timeframe = intval($_POST['timeframe']); | |
83 | } | |
84 | ||
85 | /** | |
86 | * @see \wcf\form\IForm::validate() | |
87 | */ | |
88 | public function validate() { | |
89 | parent::validate(); | |
90 | ||
91 | if ($this->timeframe < 1) { | |
92 | throw new UserInputException('timeframe'); | |
93 | } | |
94 | } | |
95 | ||
96 | /** | |
97 | * @see \wcf\form\IForm::save() | |
98 | */ | |
99 | public function save() { | |
100 | parent::save(); | |
101 | ||
102 | EditHistoryManager::getInstance()->bulkRevert($this->userIDs, $this->timeframe * 86400); | |
103 | ||
104 | // reset clipboard | |
105 | ClipboardHandler::getInstance()->removeItems($this->objectTypeID); | |
106 | $this->saved(); | |
107 | ||
108 | // show success message | |
109 | WCF::getTPL()->assign('message', 'wcf.global.success'); | |
110 | WCF::getTPL()->display('success'); | |
111 | exit; | |
112 | } | |
113 | ||
114 | /** | |
115 | * @see \wcf\page\IPage::assignVariables() | |
116 | */ | |
117 | public function assignVariables() { | |
118 | parent::assignVariables(); | |
119 | ||
120 | WCF::getTPL()->assign(array( | |
121 | 'users' => $this->users, | |
122 | 'userIDs' => $this->userIDs, | |
123 | 'timeframe' => $this->timeframe | |
124 | )); | |
125 | } | |
126 | } |