1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: class Wicked_Page_EditPage extends Wicked_Page {
17:
18: 19: 20: 21: 22:
23: public $supportedModes = array(
24: Wicked::MODE_DISPLAY => true,
25: Wicked::MODE_EDIT => true);
26:
27: 28: 29: 30: 31:
32: protected $_referrer = null;
33:
34: public function __construct($referrer)
35: {
36: $this->_referrer = $referrer;
37: if ($GLOBALS['conf']['lock']['driver'] != 'none') {
38: $this->supportedModes[Wicked::MODE_LOCKING] = $this->supportedModes[Wicked::MODE_UNLOCKING] = true;
39: }
40: }
41:
42: 43: 44: 45: 46: 47: 48: 49: 50: 51:
52: public function allows($mode)
53: {
54: if ($mode == Wicked::MODE_EDIT) {
55: $page = Wicked_Page::getPage($this->referrer());
56: if ($page->isLocked(Wicked::lockUser())) {
57: return false;
58: }
59: }
60: return parent::allows($mode);
61: }
62:
63: 64: 65: 66: 67:
68: public function getPermissions()
69: {
70: return parent::getPermissions($this->referrer());
71: }
72:
73: 74: 75: 76:
77: public function preDisplay()
78: {
79: if (!$this->allows(Wicked::MODE_EDIT)) {
80: Wicked::url($this->referrer(), true)->redirect();
81: }
82: if ($this->allows(Wicked::MODE_LOCKING)) {
83: $page = Wicked_Page::getPage($this->referrer());
84: if ($page->isLocked()) {
85: $page->unlock();
86: }
87: try {
88: $page->lock();
89: } catch (Wicked_Exception $e) {
90: $GLOBALS['notification']->push(sprintf(_("Page failed to lock: %s"), $e->getMessage()), 'horde.error');
91: }
92: }
93: }
94:
95: 96: 97: 98: 99:
100: public function display()
101: {
102: $page = Wicked_Page::getPage($this->referrer());
103: $page_text = Horde_Util::getFormData('page_text');
104: if (is_null($page_text)) {
105: $page_text = $page->getText();
106: }
107: require WICKED_TEMPLATES . '/edit/standard.inc';
108: }
109:
110: public function pageName()
111: {
112: return 'EditPage';
113: }
114:
115: public function pageTitle()
116: {
117: return _("Edit Page");
118: }
119:
120: public function referrer()
121: {
122: return $this->_referrer;
123: }
124:
125: public function isLocked()
126: {
127: $page = Wicked_Page::getPage($this->referrer());
128: return $page->isLocked();
129: }
130:
131: public function getLockRequestor()
132: {
133: $page = Wicked_Page::getPage($this->referrer());
134: return $page->getLockRequestor();
135: }
136:
137: public function getLockTime()
138: {
139: $page = Wicked_Page::getPage($this->referrer());
140: return $page->getLockTime();
141: }
142:
143: public function handleAction()
144: {
145: global $notification, $conf;
146:
147: $page = Wicked_Page::getPage($this->referrer());
148: if (!$this->allows(Wicked::MODE_EDIT)) {
149: $notification->push(sprintf(_("You don't have permission to edit \"%s\"."), $page->pageName()));
150: } else {
151: if (!empty($GLOBALS['conf']['wicked']['captcha']) &&
152: !$GLOBALS['registry']->getAuth() &&
153: (Horde_String::lower(Horde_Util::getFormData('wicked_captcha')) != Horde_String::lower(Wicked::getCAPTCHA()))) {
154: $notification->push(_("Random string did not match."), 'horde.error');
155: return;
156: }
157: $text = Horde_Util::getFormData('page_text');
158: $changelog = Horde_Util::getFormData('changelog');
159: if ($conf['wicked']['require_change_log'] && empty($changelog)) {
160: $notification->push(_("You must provide a change log."), 'horde.error');
161: Horde::addInlineScript(array(
162: 'if (document.editform && document.editform.changelog) document.editform.changelog.focus()'
163: ), 'dom');
164: return;
165: }
166: if (trim($text) == trim($page->getText())) {
167: $notification->push(_("No changes made"), 'horde.warning');
168: } else {
169: $page->updateText($text, $changelog);
170: $notification->push(_("Page Saved"), 'horde.success');
171: }
172:
173: if ($page->allows(Wicked::MODE_UNLOCKING)) {
174: $page->unlock();
175: }
176: }
177:
178:
179: Wicked::url($this->referrer(), true)->redirect();
180: }
181:
182: }
183: