1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Wicked_Page
14: {
15: const MATCH_LEFT = 1;
16: const MATCH_RIGHT = 2;
17: const MATCH_ENDS = 3;
18: const MATCH_ANY = 4;
19:
20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34:
35: public $supportedModes = array();
36:
37: 38: 39: 40: 41:
42: protected $_proc;
43:
44: 45: 46: 47: 48:
49: protected $_page;
50:
51: 52: 53: 54: 55:
56: public function isValid()
57: {
58: return !empty($this->_page);
59: }
60:
61: 62: 63: 64: 65: 66: 67:
68: public function getPermissions($pageName = null)
69: {
70: global $wicked;
71:
72: if (is_null($pageName)) {
73: $pageName = $this->pageName();
74: }
75:
76: $pageId = $wicked->getPageId($pageName);
77: $permName = 'wicked:pages:' . $pageId;
78: $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
79:
80: if ($pageId !== false && $perms->exists($permName)) {
81: return $perms->getPermissions($permName, $GLOBALS['registry']->getAuth());
82: } elseif ($perms->exists('wicked:pages')) {
83: return $perms->getPermissions('wicked:pages', $GLOBALS['registry']->getAuth());
84: } else {
85: if (!$GLOBALS['registry']->getAuth()) {
86: return Horde_Perms::SHOW | Horde_Perms::READ;
87: } else {
88: return Horde_Perms::SHOW | Horde_Perms::READ | Horde_Perms::EDIT | Horde_Perms::DELETE;
89: }
90: }
91: }
92:
93: 94: 95: 96: 97: 98: 99: 100: 101: 102:
103: public function allows($mode)
104: {
105: global $browser;
106:
107: $pagePerms = $this->getPermissions();
108:
109: switch ($mode) {
110: case Wicked::MODE_CREATE:
111:
112:
113: if ($browser->isRobot()) {
114: return false;
115: }
116:
117: if ($GLOBALS['registry']->isAdmin()) {
118: return true;
119: }
120:
121: $permName = 'wicked:pages';
122: $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
123:
124: if ($perms->exists($permName)) {
125: return $perms->hasPermission($permName, $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT);
126: } else {
127: return $GLOBALS['registry']->getAuth();
128: }
129: break;
130:
131: case Wicked::MODE_EDIT:
132: if ($browser->isRobot()) {
133: return false;
134: }
135:
136: if ($GLOBALS['registry']->isAdmin()) {
137: return true;
138: }
139:
140: if (($pagePerms & Horde_Perms::EDIT) == 0) {
141: return false;
142: }
143: break;
144:
145: case Wicked::MODE_REMOVE:
146: if ($browser->isRobot()) {
147: return false;
148: }
149:
150: if ($GLOBALS['registry']->isAdmin()) {
151: return true;
152: }
153:
154: if (($pagePerms & Horde_Perms::DELETE) == 0) {
155: return false;
156: }
157: break;
158:
159:
160: default:
161: if ($GLOBALS['registry']->isAdmin()) {
162: return true;
163: }
164:
165: if (($pagePerms & Horde_Perms::READ) == 0) {
166: return false;
167: }
168: break;
169: }
170:
171: return $this->supports($mode);
172: }
173:
174: 175: 176: 177: 178: 179: 180: 181:
182: public function supports($mode)
183: {
184: return !empty($this->supportedModes[$mode]);
185: }
186:
187: 188: 189: 190: 191: 192:
193: public function getCurrentPage()
194: {
195: return Wicked_Page::getPage(rtrim(Horde_Util::getFormData('page'), '/'),
196: Horde_Util::getFormData('version'),
197: Horde_Util::getFormData('referrer'));
198: }
199:
200: 201: 202: 203: 204: 205:
206: static public function getPage($pagename, $pagever = null, $referrer = null)
207: {
208: global $conf, $notification, $wicked;
209:
210: if (empty($pagename)) {
211: $pagename = 'Wiki/Home';
212: }
213:
214: $classname = 'Wicked_Page_' . $pagename;
215: if ($pagename == basename($pagename) && class_exists($classname)) {
216: return new $classname($referrer);
217: }
218:
219: 220:
221: if (!empty($pagever)) {
222: $page = new Wicked_Page_StandardPage($pagename, false, null);
223: if ($page->isValid() && $page->version() == $pagever) {
224: return $page;
225: }
226: return new Wicked_Page_StandardHistoryPage($pagename, $pagever);
227: }
228:
229: $page = new Wicked_Page_StandardPage($pagename);
230: if ($page->isValid() || !$page->allows(Wicked::MODE_EDIT)) {
231: return $page;
232: }
233:
234: return new Wicked_Page_AddPage($pagename);
235: }
236:
237: public function versionCreated()
238: {
239: throw new Wicked_Exception(_("Unsupported"));
240: }
241:
242: public function formatVersionCreated()
243: {
244: try {
245: $v = $this->versionCreated();
246: if ($v) {
247: return strftime($GLOBALS['prefs']->getValue('date_format'), $v);
248: }
249: } catch (Wicked_Exception $e) {}
250: return _("Never");
251: }
252:
253: public function author()
254: {
255: if (isset($this->_page['change_author'])) {
256: $modify = $this->_page['change_author'];
257: } else {
258: return _("Guest");
259: }
260:
261: $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($modify);
262: $name = $identity->getValue('fullname');
263: if (!empty($name)) {
264: $modify = $name;
265: }
266:
267: return $modify;
268: }
269:
270: public function hits()
271: {
272: throw new Wicked_Exception(_("Unsupported"));
273: }
274:
275: public function version()
276: {
277: throw new Wicked_Exception(_("Unsupported"));
278: }
279:
280: 281: 282: 283: 284: 285: 286:
287: public function previousVersion()
288: {
289: global $wicked;
290:
291: $this->version();
292: $history = $wicked->getHistory($this->pageName());
293:
294: if (count($history) == 0) {
295: return null;
296: }
297: if ($this->isOld()) {
298: for ($i = 0; $i < count($history); $i++) {
299: if ($history[$i]['page_version'] == $this->version()) {
300: if ($i + 1 < count($history)) {
301: $i++;
302: break;
303: } else {
304: return null;
305: }
306: }
307: }
308:
309: if ($i == count($history)) {
310: return null;
311: }
312: } else {
313: $i = 0;
314: }
315:
316: return $history[$i]['page_version'];
317: }
318:
319: public function isOld()
320: {
321: return false;
322: }
323:
324: 325: 326: 327: 328: 329: 330:
331: public function display()
332: {
333:
334: $inner = $this->displayContents(false);
335: require WICKED_TEMPLATES . '/display/title.inc';
336: echo $inner;
337: }
338:
339: 340: 341: 342: 343: 344: 345: 346: 347: 348:
349: public function preDisplay($mode, $params)
350: {
351: }
352:
353: 354: 355: 356: 357: 358: 359: 360:
361: public function block()
362: {
363: return $this->displayContents(true);
364: }
365:
366: public function displayContents($isBlock)
367: {
368: throw new Wicked_Exception(_("Unsupported"));
369: }
370:
371: 372: 373:
374: public function remove()
375: {
376: throw new Wicked_Exception(_("Unsupported"));
377: }
378:
379: 380: 381:
382: public function history()
383: {
384: throw new Wicked_Exception(_("Unsupported"));
385: }
386:
387: 388: 389:
390: public function diff()
391: {
392: throw new Wicked_Exception(_("Unsupported"));
393: }
394:
395: public function &getProcessor($output_format = 'Xhtml')
396: {
397: if (isset($this->_proc)) {
398: return $this->_proc;
399: }
400:
401: $view_url = Wicked::url('%s')
402: ->setRaw(true)
403: ->add('referrer', $this->pageName());
404: $view_url = str_replace(array(urlencode('%s'), urlencode('/')), array('%s', '%' . urlencode('/')), $view_url);
405:
406:
407: $class = 'Text_Wiki_' . $GLOBALS['conf']['wicked']['format'];
408: $this->_proc = new $class();
409:
410: 411:
412: $this->_proc->delim = chr(1);
413:
414:
415: $this->_proc->insertRule('Heading2', 'Heading');
416: $this->_proc->deleteRule('Heading');
417: $this->_proc->loadParseObj('Paragraph');
418: $skip = $this->_proc->parseObj['Paragraph']->getConf('skip');
419: $skip[] = 'heading2';
420: $this->_proc->setParseConf('Paragraph', 'skip', $skip);
421:
422: $this->_proc->insertRule('Toc2', 'Toc');
423: $this->_proc->deleteRule('Toc');
424:
425: switch ($output_format) {
426: case 'Xhtml':
427: if ($GLOBALS['conf']['wicked']['format'] != 'Creole') {
428: $this->_proc->insertRule('Code2', 'Code');
429: $this->_proc->deleteRule('Code');
430: }
431:
432: if ($GLOBALS['conf']['wicked']['format'] == 'BBCode') {
433: $this->_proc->insertRule('Wickedblock', 'Code2');
434: } else {
435: $this->_proc->insertRule('Wikilink2', 'Wikilink');
436: $this->_proc->setParseConf('Wikilink2', 'utf-8', true);
437: $this->_proc->deleteRule('Wikilink');
438:
439: $this->_proc->insertRule('Wickedblock', 'Raw');
440: }
441:
442: if ($GLOBALS['conf']['wicked']['format'] == 'Default' ||
443: $GLOBALS['conf']['wicked']['format'] == 'Cowiki' ||
444: $GLOBALS['conf']['wicked']['format'] == 'Tiki') {
445: $this->_proc->insertRule('Freelink2', 'Freelink');
446: $this->_proc->deleteRule('Freelink');
447: }
448:
449: $this->_proc->insertRule('Image2', 'Image');
450: $this->_proc->deleteRule('Image');
451: $this->_proc->insertRule('RegistryLink', 'Wickedblock');
452: $this->_proc->insertRule('Attribute', 'RegistryLink');
453:
454: $this->_proc->deleteRule('Include');
455: $this->_proc->deleteRule('Embed');
456:
457: $this->_proc->setFormatConf('Xhtml', 'charset', 'UTF-8');
458: $this->_proc->setFormatConf('Xhtml', 'translate', HTML_SPECIALCHARS);
459: $create = $this->allows(Wicked::MODE_CREATE) ? 1 : 0;
460: $linkConf = array(
461: 'pages' => $GLOBALS['wicked']->getPages(),
462: 'view_url' => $view_url,
463: 'new_url' => $create ? $view_url : false,
464: 'new_text_pos' => false,
465: 'css_new' => 'newpage',
466: 'ext_chars' => true,
467: );
468:
469: $this->_proc->setRenderConf('Xhtml', 'Wikilink2', $linkConf);
470: $this->_proc->setRenderConf('Xhtml', 'Freelink2', $linkConf);
471: $this->_proc->setRenderConf('Xhtml', 'Toc',
472: array('title' => '<h2>' . _("Table of Contents") . '</h2>'));
473: $this->_proc->setRenderConf('Xhtml', 'Table',
474: array('css_table' => 'table',
475: 'css_td' => 'table-cell',
476: 'css_th' => 'table-cell'));
477:
478: break;
479:
480: case 'Rst':
481: require_once dirname(__FILE__) . '/Text_Wiki/Render/Rst.php';
482: break;
483: }
484:
485: $autoloader = $GLOBALS['injector']->getInstance('Horde_Autoloader');
486: $autoloader->addClassPathMapper(
487: new Horde_Autoloader_ClassPathMapper_Prefix(
488: '/^Text_Wiki_Render_' . $output_format . '/',
489: WICKED_BASE . '/lib/Text_Wiki/Render/' . $output_format
490: )
491: );
492: $autoloader->addClassPathMapper(
493: new Horde_Autoloader_ClassPathMapper_Prefix(
494: '/^Text_Wiki_Parse/',
495: WICKED_BASE . '/lib/Text_Wiki/Parse/' . $GLOBALS['conf']['wicked']['format']
496: )
497: );
498:
499: return $this->_proc;
500: }
501:
502: public function render($mode, $params = null)
503: {
504: switch ($mode) {
505: case Wicked::MODE_CONTENT:
506: return $this->content($params);
507:
508: case Wicked::MODE_DISPLAY:
509: return $this->display($params);
510:
511: case Wicked::MODE_BLOCK:
512: return $this->block($params);
513:
514: case Wicked::MODE_REMOVE:
515: return $this->remove();
516:
517: case Wicked::MODE_HISTORY:
518: return $this->history();
519:
520: case Wicked::MODE_DIFF:
521: return $this->diff($params);
522:
523: default:
524: throw new Wicked_Exception(_("Unsupported"));
525: }
526: }
527:
528: public function isLocked()
529: {
530: return false;
531: }
532:
533: public function lock()
534: {
535: throw new Wicked_Exception(_("Unsupported"));
536: }
537:
538: public function unlock()
539: {
540: throw new Wicked_Exception(_("Unsupported"));
541: }
542:
543: public function updateText($newtext, $changelog)
544: {
545: throw new Wicked_Exception(_("Unsupported"));
546: }
547:
548: public function getText()
549: {
550: throw new Wicked_Exception(_("Unsupported"));
551: }
552:
553: public function pageName()
554: {
555: return null;
556: }
557:
558: public function referrer()
559: {
560: return null;
561: }
562:
563: public function pageUrl($linkpage = null, $actionId = null)
564: {
565: $params = array('page' => $this->pageName());
566: if ($this->referrer()) {
567: $params['referrer'] = $this->referrer();
568: }
569: if ($actionId) {
570: $params['actionID'] = $actionId;
571: }
572:
573: if (!$linkpage) {
574: $url = Wicked::url($this->pageName());
575: unset($params['page']);
576: } else {
577: $url = Horde::url($linkpage);
578: }
579:
580: return Horde_Util::addParameter($url, $params);
581: }
582:
583: public function pageTitle()
584: {
585: return $this->pageName();
586: }
587:
588: public function handleAction()
589: {
590: throw new Wicked_Exception(_("Unsupported"));
591: }
592:
593: }
594: