Overview

Packages

  • None
  • Wicked

Classes

  • Text_Wiki_Parse_Heading2
  • Text_Wiki_Parse_Toc2
  • Text_Wiki_Render_Latex_Heading2
  • Text_Wiki_Render_Latex_Toc2
  • Text_Wiki_Render_Plain_Heading2
  • Text_Wiki_Render_Plain_Toc2
  • Text_Wiki_Render_Rst
  • Text_Wiki_Render_Rst_Blockquote
  • Text_Wiki_Render_Rst_Bold
  • Text_Wiki_Render_Rst_Code
  • Text_Wiki_Render_Rst_Deflist
  • Text_Wiki_Render_Rst_Emphasis
  • Text_Wiki_Render_Rst_Freelink
  • Text_Wiki_Render_Rst_Heading2
  • Text_Wiki_Render_Rst_Links
  • Text_Wiki_Render_Rst_List
  • Text_Wiki_Render_Rst_Newline
  • Text_Wiki_Render_Rst_Paragraph
  • Text_Wiki_Render_Rst_Raw
  • Text_Wiki_Render_Rst_Toc2
  • Text_Wiki_Render_Rst_Tt
  • Text_Wiki_Render_Rst_Url
  • Text_Wiki_Render_Xhtml_Attribute
  • Text_Wiki_Render_Xhtml_Code2
  • Text_Wiki_Render_Xhtml_Freelink2
  • Text_Wiki_Render_Xhtml_Heading2
  • Text_Wiki_Render_Xhtml_Image2
  • Text_Wiki_Render_Xhtml_Interwiki
  • Text_Wiki_Render_Xhtml_Registrylink
  • Text_Wiki_Render_Xhtml_Toc2
  • Text_Wiki_Render_Xhtml_Url
  • Text_Wiki_Render_Xhtml_Wickedblock
  • Text_Wiki_Render_Xhtml_Wikilink2
  • Wicked
  • Wicked_Api
  • Wicked_Driver
  • Wicked_Driver_Sql
  • Wicked_Exception
  • Wicked_Factory_Driver
  • Wicked_Page
  • Wicked_Page_AddPage
  • Wicked_Page_AllPages
  • Wicked_Page_AttachedFiles
  • Wicked_Page_BackLinks
  • Wicked_Page_DeletePage
  • Wicked_Page_EditPage
  • Wicked_Page_LeastPopular
  • Wicked_Page_LikePages
  • Wicked_Page_MergeOrRename
  • Wicked_Page_MostPopular
  • Wicked_Page_NewPage
  • Wicked_Page_RecentChanges
  • Wicked_Page_RevertPage
  • Wicked_Page_Search
  • Wicked_Page_StandardHistoryPage
  • Wicked_Page_StandardPage
  • Wicked_Page_SyncDiff
  • Wicked_Page_SyncPages
  • Wicked_Sync
  • Wicked_Sync_Wicked
  • Wicked_Test
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Wicked Abtract Page Class.
  4:  *
  5:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author  Tyler Colbert <tyler@colberts.us>
 11:  * @package Wicked
 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:      * Display modes supported by this page. Possible modes:
 22:      *
 23:      *   Wicked::MODE_CONTENT
 24:      *   Wicked::MODE_DISPLAY
 25:      *   Wicked::MODE_EDIT
 26:      *   Wicked::MODE_REMOVE
 27:      *   Wicked::MODE_HISTORY
 28:      *   Wicked::MODE_DIFF
 29:      *   Wicked::MODE_LOCKING
 30:      *   Wicked::MODE_UNLOCKING
 31:      *   Wicked::MODE_CREATE
 32:      *
 33:      * @var array
 34:      */
 35:     public $supportedModes = array();
 36: 
 37:     /**
 38:      * Instance of a Text_Wiki processor.
 39:      *
 40:      * @var Text_Wiki
 41:      */
 42:     protected $_proc;
 43: 
 44:     /**
 45:      * The loaded page info.
 46:      *
 47:      * @var array
 48:      */
 49:     protected $_page;
 50: 
 51:     /**
 52:      * Is this a validly loaded page?
 53:      *
 54:      * @return boolean  True if we've loaded data, false otherwise.
 55:      */
 56:     public function isValid()
 57:     {
 58:         return !empty($this->_page);
 59:     }
 60: 
 61:     /**
 62:      * Retrieve this user's permissions for this page. If a
 63:      * permissions object does not exist, we assume reasonable
 64:      * defaults.
 65:      *
 66:      * @return integer  The permissions bitmask.
 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:      * Returns if the page allows a mode. Access rights and user state
 95:      * are taken into consideration.
 96:      *
 97:      * @see $supportedModes
 98:      *
 99:      * @param integer $mode  The mode to check for.
100:      *
101:      * @return boolean  True if the mode is allowed.
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:             // Special mode for pages that don't exist yet - generic
112:             // to all pages.
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:         // All other modes require READ permissions.
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:      * See if the page supports a particular mode.
176:      * @see $supportedModes
177:      *
178:      * @param integer $mode      Which mode to check for
179:      *
180:      * @return boolean            True or false
181:      */
182:     public function supports($mode)
183:     {
184:         return !empty($this->supportedModes[$mode]);
185:     }
186: 
187:     /**
188:      * Returns the page we are currently on.
189:      *
190:      * @return Wicked_Page  The current page.
191:      * @throws Wicked_Exception
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:      * Returns the requested page.
202:      *
203:      * @return Wicked_Page  The requested page.
204:      * @throws Wicked_Exception
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:         /* If we have a version, but it is actually the most recent version,
220:          * ignore it. */
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:      * Returns the previous version number for this page.
282:      *
283:      * @return string  A string containing the previous version or null if this
284:      *                 is the first version.
285:      * @throws Wicked_Exception
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:      * Renders this page in display mode.
326:      *
327:      * This must be overridden if the page is to be anything like a real page.
328:      *
329:      * @throws Wicked_Exception
330:      */
331:     public function display()
332:     {
333:         // Get content first, it might throw an exception.
334:         $inner = $this->displayContents(false);
335:         require WICKED_TEMPLATES . '/display/title.inc';
336:         echo $inner;
337:     }
338: 
339:     /**
340:      * Perform any pre-display checks for permissions, searches,
341:      * etc. Called before any output is sent so the page can do
342:      * redirects. If the page wants to take control of flow from here,
343:      * it can, and is entirely responsible for handling the user
344:      * (should call exit after redirecting, for example).
345:      *
346:      * $param integer $mode    The page render mode.
347:      * $param array   $params  Any page parameters.
348:      */
349:     public function preDisplay($mode, $params)
350:     {
351:     }
352: 
353:     /**
354:      * Renders this page for displaying in a block.
355:      *
356:      * This must be overridden if the page is to be anything like a real page.
357:      *
358:      * @return string  The content.
359:      * @throws Wicked_Exception
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:      * Renders this page in remove mode.
373:      */
374:     public function remove()
375:     {
376:         throw new Wicked_Exception(_("Unsupported"));
377:     }
378: 
379:     /**
380:      * Renders this page in history mode.
381:      */
382:     public function history()
383:     {
384:         throw new Wicked_Exception(_("Unsupported"));
385:     }
386: 
387:     /**
388:      * Renders this page in diff mode.
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:         /* Create format-specific Text_Wiki object */
407:         $class = 'Text_Wiki_' . $GLOBALS['conf']['wicked']['format'];
408:         $this->_proc = new $class();
409: 
410:         /* Use a non-printable delimiter character that is still a valid UTF-8
411:          * character. See http://pear.php.net/bugs/bug.php?id=12490. */
412:         $this->_proc->delim = chr(1);
413: 
414:         /* Override rules */
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: 
API documentation generated by ApiGen