1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Wicked_Page_RevertPage extends Wicked_Page {
14:
15: 16: 17: 18: 19:
20: public $supportedModes = array(Wicked::MODE_DISPLAY => true);
21:
22: 23: 24: 25: 26:
27: protected $_referrer = null;
28:
29: public function __construct($referrer)
30: {
31: $this->_referrer = $referrer;
32: }
33:
34: 35: 36: 37: 38:
39: public function getPermissions()
40: {
41: return parent::getPermissions($this->referrer());
42: }
43:
44: 45: 46: 47:
48: public function preDisplay()
49: {
50: $page = Wicked_Page::getPage($this->referrer());
51: if (!$page->allows(Wicked::MODE_EDIT)) {
52: Wicked::url($this->referrer(), true)->redirect();
53: }
54: }
55:
56: 57: 58: 59: 60:
61: public function display()
62: {
63: $version = Horde_Util::getFormData('version');
64: $page = Wicked_Page::getPage($this->referrer(), $version);
65: $msg = sprintf(_("Are you sure you want to revert to version %s of this page?"), $version);
66: ?>
67: <form method="post" name="revertform" action="<?php echo Wicked::url('RevertPage') ?>">
68: <?php Horde_Util::pformInput() ?>
69: <input type="hidden" name="page" value="RevertPage" />
70: <input type="hidden" name="actionID" value="special" />
71: <input type="hidden" name="version" value="<?php echo htmlspecialchars($version) ?>" />
72: <input type="hidden" name="referrer" value="<?php echo htmlspecialchars($page->pageName()) ?>" />
73:
74: <h1 class="header">
75: <?php echo _("Revert Page") . ': ' . Horde::link($page->pageUrl(), $page->pageName()) . $page->pageName() . '</a>'; if ($page->isLocked()) echo Horde::img('locked.png', _("Locked")) ?>
76: </h1>
77:
78: <div class="headerbox" style="padding:4px">
79: <p><?php echo $msg ?></p>
80: <p>
81: <input type="submit" value="<?php echo _("Revert") ?>" class="button" />
82: <a class="button" href="<?php echo Wicked::url($page->pageName()) ?>"><?php echo _("Cancel") ?></a>
83: </p>
84: </div>
85:
86: </form>
87: <?php
88: }
89:
90: public function pageName()
91: {
92: return 'RevertPage';
93: }
94:
95: public function pageTitle()
96: {
97: return _("Revert Page");
98: }
99:
100: public function referrer()
101: {
102: return $this->_referrer;
103: }
104:
105: public function handleAction()
106: {
107: global $notification;
108:
109: $page = Wicked_Page::getPage($this->referrer());
110: if ($page->allows(Wicked::MODE_EDIT)) {
111: $version = Horde_Util::getPost('version');
112: if (empty($version)) {
113: $notification->push(sprintf(_("Can't revert to an unknown version.")), 'horde.error');
114: Wicked::url($this->referrer(), true)->redirect();
115: }
116: $oldpage = Wicked_Page::getPage($this->referrer(), $version);
117: $page->updateText($oldpage->getText(), 'Revert');
118: $notification->push(sprintf(_("Reverted to version %s of \"%s\"."), $version, $page->pageName()));
119: Wicked::url($page->pageName(), true)->redirect();
120: }
121:
122: $notification->push(sprintf(_("You don't have permission to edit \"%s\"."), $page->pageName()), 'horde.warning');
123: Wicked::url($this->referrer(), true)->redirect();
124: }
125:
126: }
127: