/**
  * Edit a wiki page
  * 
  * @return void
  */
 function edit()
 {
     if (!WikiPage::canEdit(logged_user())) {
         flash_error(lang('no wiki page edit permissions'));
         $this->redirectToReferer(get_url('wiki'));
     }
     //Get the page from the url params
     $page = Wiki::getPageById(get_id(), active_project());
     if (!instance_of($page, 'WikiPage')) {
         //If the page doesn't exist, redirect to wiki index
         flash_error(lang('wiki page dnx'));
         $this->redirectToReferer(get_url('wiki'));
     }
     // if
     //Check that the user can edit this entry
     if (!$page->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectTo(get_url('wiki'));
     }
     // if
     // Check that the page isn't locked
     if ($page->isLocked() && !$page->canUnlock(logged_user())) {
         flash_error(lang('wiki page locked by', $page->getLockedByUser()->getUsername()));
         $this->redirectToUrl($page->getViewUrl());
     }
     // if
     //Here we will edit a wiki page
     $preview = false;
     $data = array_var($_POST, 'wiki', false);
     if (false !== $data) {
         $preview = array_key_exists('preview', $data);
     }
     if (!$preview && $data) {
         //if(null !== ($data = array_var($_POST, 'wiki'))){
         //If we have received data
         //Make a new revision
         $revision = $page->makeRevision();
         $revision->setFromAttributes($data);
         $page->setProjectIndex($data['project_index']);
         $page->setProjectSidebar($data['project_sidebar']);
         $page->setPublish($data['publish']);
         $page->setParentId($data['parent_id']);
         // Check to see if we want to lock this page
         if (isset($data['locked'])) {
             if ($data['locked'] == 1 && $page->canLock(logged_user()) && !$page->isLocked()) {
                 // If we want to lock this page and the user has permissions to lock it, and the page is not already locked
                 $page->setLocked(true);
                 $page->setLockedById(logged_user()->getId());
                 $page->setLockedOn(DateTimeValueLib::now());
             } elseif ($data['locked'] == 0 & $page->canUnlock(logged_user()) && $page->isLocked()) {
                 // Else if we want to unlock the page, and the user is allowed to, and the page is locked
                 $page->setLocked(false);
             }
             // if
         }
         // if
         //Set the users ID
         $revision->setCreatedById(logged_user()->getId());
         try {
             //Start the transaction
             DB::beginWork();
             //Save the page and create revision
             //The page will make sure that the revision's project and page Id are correct
             $page->save();
             ApplicationLogs::createLog($page, active_project(), ApplicationLogs::ACTION_EDIT);
             if (plugin_active('tags')) {
                 //Set the tags
                 $page->setTagsFromCSV($data['tags']);
             }
             //Commit changes
             DB::commit();
             flash_success(lang('success edit wiki page'));
             //Redirect to the page we just created
             $this->redirectToUrl($page->getViewUrl());
         } catch (Exception $e) {
             //Get rid of any Db changes we've made
             DB::rollback();
             //Assign the problem to the template so we can tell the user
             tpl_assign('error', $e);
         }
         //try
     } else {
         if (array_var($_GET, 'revision')) {
             //If we want to make a new revision based off a revision
             $revision = $page->getRevision($_GET['revision']);
         } else {
             $revision = $page->getLatestRevision();
         }
     }
     //if
     if (!$data) {
         // there was no input POSTed
         $data['content'] = $revision->getContent();
     }
     $data['preview_content'] = do_textile($data['content']);
     //Assign revision object
     tpl_assign('revision', $revision);
     tpl_assign('data', $data);
     //Assign the page object
     tpl_assign('page', $page);
     $tag_names = plugin_active('tags') ? $page->getTagNames() : '';
     $tags = is_array($tag_names) ? implode(', ', $tag_names) : '';
     tpl_assign('tags', $tags);
     //Set the template
     $this->setTemplate('edit');
     $this->setSidebar(get_template_path('textile_help_sidebar'));
 }
예제 #2
0
 /**
  * Edit a wiki page
  * 
  * @return void
  */
 function edit()
 {
     if (!WikiPage::canEdit(logged_user())) {
         flash_error(lang('no wiki page edit permissions'));
         $this->redirectToReferer(get_url('wiki'));
     }
     //Get the page from the url params
     $page = Wiki::getPageById(get_id(), active_project());
     if (!instance_of($page, 'WikiPage')) {
         //If the page doesn't exist, redirect to wiki index
         flash_error(lang('wiki page dnx'));
         $this->redirectToReferer(get_url('wiki'));
     }
     // if
     //Check that the user can edit this entry
     if (!$page->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectTo();
     }
     // if
     //Here we will edit a wiki page
     if (null !== ($data = array_var($_POST, 'wiki'))) {
         //If we have received data
         //Make a new revision
         $revision = $page->makeRevision();
         $revision->setFromAttributes($data);
         $page->setProjectIndex($data['project_index']);
         $page->setProjectSidebar($data['project_sidebar']);
         //Set the users ID
         $revision->setCreatedById(logged_user()->getId());
         try {
             //Start the transaction
             DB::beginWork();
             //Save the page and create revision
             //The page will make sure that the revision's project and page Id are correct
             $page->save();
             ApplicationLogs::createLog($page, active_project(), ApplicationLogs::ACTION_EDIT);
             if (plugin_active('tags')) {
                 //Set the tags
                 $page->setTagsFromCSV($data['tags']);
             }
             //Commit changes
             DB::commit();
             flash_success(lang('success edit wiki page'));
             //Redirect to the page we just created
             $this->redirectToUrl($page->getViewUrl());
         } catch (Exception $e) {
             //Get rid of any Db changes we've made
             DB::rollback();
             //Assign the problem to the template so we can tell the user
             tpl_assign('error', $e);
         }
         //try
     } else {
         if (array_var($_GET, 'revision')) {
             //If we want to make a new revision based off a revision
             $revision = $page->getRevision($_GET['revision']);
         } else {
             $revision = $page->getLatestRevision();
         }
     }
     //if
     //Assign revision object
     tpl_assign('revision', $revision);
     //Assign the page object
     tpl_assign('page', $page);
     //Set the template
     $this->setTemplate('edit');
 }