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:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
  4:  *
  5:  * See the enclosed file COPYING for license information (GPL). If you
  6:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  7:  *
  8:  * @package Wicked
  9:  */
 10: 
 11: /**
 12:  * Wicked NewPage class.
 13:  *
 14:  * @author  Chuck Hagenbuch <chuck@horde.org>
 15:  * @package Wicked
 16:  */
 17: class Wicked_Page_NewPage extends Wicked_Page {
 18: 
 19:     /**
 20:      * Display modes supported by this page.
 21:      *
 22:      * @var array
 23:      */
 24:     public $supportedModes = array(
 25:         Wicked::MODE_DISPLAY => true,
 26:         Wicked::MODE_EDIT => true);
 27: 
 28:     /**
 29:      * The page that we're creating.
 30:      *
 31:      * @var string
 32:      */
 33:     protected $_referrer = null;
 34: 
 35:     /**
 36:      * Page template to use.
 37:      *
 38:      * @var string
 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:      * Retrieve this user's permissions for the referring page.
 50:      *
 51:      * @return integer  The permissions bitmask.
 52:      */
 53:     public function getPermissions()
 54:     {
 55:         return parent::getPermissions($this->referrer());
 56:     }
 57: 
 58:     /**
 59:      * Send them back whence they came if they aren't allowed to edit
 60:      * this page.
 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:      * Renders this page in display mode.
 76:      *
 77:      * @throws Wicked_Exception
 78:      */
 79:     public function display()
 80:     {
 81:         // Load the page template.
 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:         // Show the newly created page.
135:         Wicked::url($this->referrer(), true)->redirect();
136:     }
137: 
138: }
139: 
API documentation generated by ApiGen