1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16:
17: class Wicked_Page_DeletePage extends Wicked_Page {
18:
19: 20: 21: 22: 23:
24: public $supportedModes = array(Wicked::MODE_DISPLAY => true);
25:
26: 27: 28: 29: 30:
31: protected $_referrer = null;
32:
33: public function __construct($referrer)
34: {
35: $this->_referrer = $referrer;
36: }
37:
38: 39: 40: 41: 42:
43: public function getPermissions()
44: {
45: return parent::getPermissions($this->referrer());
46: }
47:
48: 49: 50: 51:
52: public function preDisplay()
53: {
54: $page = Wicked_Page::getPage($this->referrer());
55: if (!$page->allows(Wicked::MODE_REMOVE)) {
56: Wicked::url($this->referrer(), true)->redirect();
57: }
58: }
59:
60: 61: 62: 63: 64:
65: public function display()
66: {
67: $version = Horde_Util::getFormData('version');
68: $page = Wicked_Page::getPage($this->referrer(), $version);
69: if (!$page->isValid()) {
70: Wicked::url('Wiki/Home', true)->redirect();
71: }
72:
73: if (empty($version)) {
74: $msg = _("Are you sure you want to delete this page? All versions will be permanently removed.");
75: } else {
76: $msg = sprintf(_("Are you sure you want to delete version %s of this page?"),
77: $page->version());
78: }
79: ?>
80: <form method="post" name="deleteform" action="<?php echo Wicked::url('DeletePage') ?>">
81: <?php Horde_Util::pformInput() ?>
82: <input type="hidden" name="page" value="DeletePage" />
83: <input type="hidden" name="actionID" value="special" />
84: <input type="hidden" name="version" value="<?php echo htmlspecialchars($version) ?>" />
85: <input type="hidden" name="referrer" value="<?php echo htmlspecialchars($page->pageName()) ?>" />
86:
87: <h1 class="header">
88: <?php echo _("Delete Page") . ': ' . Horde::link($page->pageUrl()) . htmlspecialchars($page->pageName()) . '</a> '; if ($page->isLocked()) echo Horde::img('locked.png', _("Locked")) ?>
89: </h1>
90:
91: <div class="headerbox" style="padding:4px">
92: <p><?php echo $msg ?></p>
93: <p>
94: <input type="submit" value="<?php echo _("Delete") ?>" class="button" />
95: <a class="button" href="<?php echo Wicked::url($page->pageName()) ?>"><?php echo _("Cancel") ?></a>
96: </p>
97: </div>
98:
99: </form>
100: <?php
101: }
102:
103: public function pageName()
104: {
105: return 'DeletePage';
106: }
107:
108: public function pageTitle()
109: {
110: return _("Delete Page");
111: }
112:
113: public function referrer()
114: {
115: return $this->_referrer;
116: }
117:
118: public function handleAction()
119: {
120: $pagename = $this->referrer();
121: $page = Wicked_Page::getPage($pagename);
122: if ($page->allows(Wicked::MODE_REMOVE)) {
123: $version = Horde_Util::getFormData('version');
124: if (empty($version)) {
125: $GLOBALS['wicked']->removeAllVersions($pagename);
126: $GLOBALS['notification']->push(sprintf(_("Successfully deleted \"%s\"."), $pagename), 'horde.success');
127: Wicked::mail("Deleted page: $pagename\n",
128: array('Subject' => '[' . $GLOBALS['registry']->get('name') . '] deleted: ' . $pagename));
129: Wicked::url('Wiki/Home', true)->redirect();
130: }
131: $GLOBALS['wicked']->removeVersion($pagename, $version);
132: $GLOBALS['notification']->push(sprintf(_("Deleted version %s of \"%s\"."), $version, $pagename), 'horde.success');
133: Wicked::mail("Deleted version: $version of $pagename\n",
134: array('Subject' => '[' . $GLOBALS['registry']->get('name') . '] deleted: ' . $pagename . ' [' . $version . ']'));
135: Wicked::url($pagename, true)->redirect();
136: }
137:
138: $GLOBALS['notification']->push(sprintf(_("You don't have permission to delete \"%s\"."), $pagename), 'horde.warning');
139: Wicked::url($this->referrer(), true)->redirect();
140: }
141:
142: }
143: