1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16:
17: class Wicked_Page_NewPage extends Wicked_Page {
18:
19: 20: 21: 22: 23:
24: public $supportedModes = array(
25: Wicked::MODE_DISPLAY => true,
26: Wicked::MODE_EDIT => true);
27:
28: 29: 30: 31: 32:
33: protected $_referrer = null;
34:
35: 36: 37: 38: 39:
40: protected $_template = null;
41:
42: public function __construct($referrer)
43: {
44: $this->_referrer = $referrer;
45: $this->_template = Horde_Util::getFormData('template');
46: }
47:
48: 49: 50: 51: 52:
53: public function getPermissions()
54: {
55: return parent::getPermissions($this->referrer());
56: }
57:
58: 59: 60: 61:
62: public function preDisplay()
63: {
64: if (!strlen($this->referrer())) {
65: $GLOBALS['notification']->push(_("Page name must not be empty"));
66: Wicked::url('', true)->redirect();
67: }
68:
69: if (!$this->allows(Wicked::MODE_EDIT)) {
70: Wicked::url($this->referrer(), true)->redirect();
71: }
72: }
73:
74: 75: 76: 77: 78:
79: public function display()
80: {
81:
82: if ($this->_template) {
83: $page = Wicked_Page::getPage($this->_template);
84: $page_text = $page->getText();
85: } else {
86: $page_text = '';
87: }
88:
89: Horde::addInlineScript(array(
90: 'if (document.editform && document.editform.page_text) document.editform.changelog.page_text()'
91: ), 'dom');
92:
93: require WICKED_TEMPLATES . '/edit/new.inc';
94: return true;
95: }
96:
97: public function pageName()
98: {
99: return 'NewPage';
100: }
101:
102: public function pageTitle()
103: {
104: return _("New Page");
105: }
106:
107: public function referrer()
108: {
109: return $this->_referrer;
110: }
111:
112: public function handleAction()
113: {
114: global $notification, $wicked;
115:
116: if (!$this->allows(Wicked::MODE_EDIT)) {
117: $notification->push(sprintf(_("You don't have permission to create \"%s\"."), $this->referrer()));
118: } else {
119: $text = Horde_Util::getPost('page_text');
120: if (empty($text)) {
121: $notification->push(_("Pages cannot be empty."), 'horde.error');
122: return;
123: }
124:
125: try {
126: $result = $wicked->newPage($this->referrer(), $text);
127: $notification->push(_("Page Created"), 'horde.success');
128: } catch (Wicked_Exception $e) {
129: $notification->push(sprintf(_("Create Failed: %s"),
130: $e->getMessage()), 'horde.error');
131: }
132: }
133:
134:
135: Wicked::url($this->referrer(), true)->redirect();
136: }
137:
138: }
139: