Example #1
0
function create_wiki($gid = false, $wikiName = 'New wiki')
{
    $creatorId = claro_get_current_user_id();
    $tblList = claro_sql_get_course_tbl();
    $config = array();
    $config["tbl_wiki_properties"] = $tblList["wiki_properties"];
    $config["tbl_wiki_pages"] = $tblList["wiki_pages"];
    $config["tbl_wiki_pages_content"] = $tblList["wiki_pages_content"];
    $config["tbl_wiki_acls"] = $tblList["wiki_acls"];
    $con = Claroline::getDatabase();
    $acl = array();
    if ($gid) {
        $acl = WikiAccessControl::defaultGroupWikiACL();
    } else {
        $acl = WikiAccessControl::defaultCourseWikiACL();
    }
    $wiki = new Wiki($con, $config);
    $wiki->setTitle($wikiName);
    $wiki->setDescription('This is a sample wiki');
    $wiki->setACL($acl);
    $wiki->setGroupId($gid);
    $wikiId = $wiki->save();
    $wikiTitle = $wiki->getTitle();
    $mainPageContent = sprintf("This is the main page of the Wiki %s. Click on edit to modify the content.", $wikiTitle);
    $wikiPage = new WikiPage($con, $config, $wikiId);
    $wikiPage->create($creatorId, '__MainPage__', $mainPageContent, date("Y-m-d H:i:s"), true);
}
Example #2
0
 public function create()
 {
     $page = WikiPage::create(array_merge($this->params()->wiki_page, ['ip_addr' => $this->request()->remoteIp(), 'user_id' => $this->current_user->id]));
     if ($page->errors()->blank()) {
         $this->respond_to_success("Page created", ["#show", 'title' => $page->title], ['location' => $this->urlFor(["#show", 'title' => $page->title])]);
     } else {
         $this->respond_to_error($page, "#index");
     }
 }
Example #3
0
/**
 * create wiki MainPage
 * @param DatabaseConnection con database connection
 * @param int wikiId ID of the Wiki the page belongs to
 * @param int creatorId ID of the user who creates the page
 * @return boolean true if the creation succeeds, false if it fails
 */
function init_wiki_main_page($con, $wikiId, $creatorId, $wikiTitle)
{
    $tblList = claro_sql_get_course_tbl();
    $mainPageContent = get_lang("This is the main page of the Wiki %wikiTitle. Click on '''Edit''' to modify the content.", array('%wikiTitle' => $wikiTitle));
    $config = array();
    // use claro functions
    $config["tbl_wiki_pages"] = $tblList["wiki_pages"];
    $config["tbl_wiki_pages_content"] = $tblList["wiki_pages_content"];
    $wikiPage = new WikiPage($con, $config, $wikiId);
    $wikiPage->create($creatorId, '__MainPage__', $mainPageContent, date("Y-m-d H:i:s"), true);
    return !$wikiPage->hasError();
}
Example #4
0
                 $message = $langWikiIdenticalContent;
                 $style = 'caution';
                 $action = 'show';
             } else {
                 $wikiPage->edit($creatorId, $content, $changelog, $time, true);
                 if ($wikiPage->hasError()) {
                     $message = "Database error : " . $wikiPage->getError();
                     $style = "caution";
                 } else {
                     $message = $langWikiPageSaved;
                     $style = "success";
                 }
                 $action = 'show';
             }
         } else {
             $wikiPage->create($creatorId, $wiki_title, $content, $changelog, $time, true);
             if ($wikiPage->hasError()) {
                 $message = 'Database error : ' . $wikiPage->getError();
                 $style = 'caution';
             } else {
                 $message = $langWikiPageSaved;
                 $style = 'success';
             }
             $action = 'show';
         }
     }
     //release the lock after finishing saving
     $lock_manager->releaseLock($wiki_title, $wikiId);
 } else {
     //failed to lock, unable to save
     $action = 'conflict';
Example #5
0
     break;
     // execute edit
 // execute edit
 case 'exEdit':
     if ($wikiId == 0) {
         $wiki = new Wiki($con, $config);
         $wiki->setTitle($wikiTitle);
         $wiki->setDescription($wikiDesc);
         $wiki->setACL($wikiACL);
         $wiki->setGroupId($groupId);
         $wikiId = $wiki->save();
         //notify wiki modification
         $eventNotifier->notifyCourseEvent('wiki_added', claro_get_current_course_id(), claro_get_current_tool_id(), $wikiId, claro_get_current_group_id(), '0');
         $mainPageContent = sprintf(get_lang("This is the main page of the Wiki %s. Click on '''Edit''' to modify the content."), $wikiTitle);
         $wikiPage = new WikiPage($con, $config, $wikiId);
         if ($wikiPage->create($creatorId, '__MainPage__', $mainPageContent, date("Y-m-d H:i:s"), true)) {
             $message = get_lang("Wiki creation succeed");
             $dialogBox->success($message);
         } else {
             $message = get_lang("Wiki creation failed");
             $dialogBox->error($message . ":" . $wikiPage->getError());
         }
     } elseif ($wikiStore->wikiIdExists($wikiId)) {
         $wiki = $wikiStore->loadWiki($wikiId);
         $wiki->setTitle($wikiTitle);
         $wiki->setDescription($wikiDesc);
         $wiki->setACL($wikiACL);
         $wiki->setGroupId($groupId);
         $wikiId = $wiki->save();
         //notify wiki creation
         $eventNotifier->notifyCourseEvent('wiki_modified', claro_get_current_course_id(), claro_get_current_tool_id(), $wikiId, claro_get_current_group_id(), '0');
Example #6
0
                $wikiACL['group_create'] = true;
                $wikiACL['other_read'] = false;
                $wikiACL['other_edit'] = false;
                $wikiACL['other_create'] = false;

                $wiki = new Wiki();
                $wiki->setTitle($langGroup . " " . $group_num . " - Wiki");
                $wiki->setDescription('');
                $wiki->setACL($wikiACL);
                $wiki->setGroupId($id);
                $wikiId = $wiki->save();

                $mainPageContent = $langWikiMainPageContent;

                $wikiPage = new WikiPage($wikiId);
                $wikiPage->create($uid, '__MainPage__', $mainPageContent, '', date("Y-m-d H:i:s"), true);
                /*             * ************************************ */

                Log::record($course_id, MODULE_ID_GROUPS, LOG_INSERT, array('id' => $id,
                                                                            'name' => "$langGroup $group_num",
                                                                            'max_members' => $group_max,
                                                                            'secret_directory' => $secretDirectory));
            }
            if ($group_quantity == 1) {
                $message = "$group_quantity $langGroupAdded";
            } else {
                $message = "$group_quantity $langGroupsAdded";
            }
        } else {
            Session::flashPost()->Messages($langFormErrors)->Errors($v->errors());
            redirect_to_home_page("modules/group/group_creation.php?course=$course_code");
Example #7
0
                        $wikiPage->edit($creatorId, $content, $time, true);
                        unset($_SESSION['wikiLastVersion']);
                        if ($wikiPage->hasError()) {
                            $message = get_lang("Database error : ") . $wikiPage->getError();
                            $dialogBox->error($message);
                        } else {
                            $message = get_lang("Page saved");
                            $dialogBox->success($message);
                        }
                        $action = 'show';
                    }
                }
                //notify modification of the page
                $eventNotifier->notifyCourseEvent('wiki_page_modified', claro_get_current_course_id(), claro_get_current_tool_id(), $wikiId, claro_get_current_group_id(), '0');
            } else {
                $wikiPage->create($creatorId, $title, $content, $time, true);
                if ($wikiPage->hasError()) {
                    $message = get_lang("Database error : ") . $wikiPage->getError();
                    $dialogBox->error($message);
                } else {
                    $message = get_lang("Page saved");
                    $dialogBox->success($message);
                }
                $action = 'show';
                //notify creation of the page
                $eventNotifier->notifyCourseEvent('wiki_page_added', claro_get_current_course_id(), claro_get_current_tool_id(), $wikiId, claro_get_current_group_id(), '0');
            }
        }
        break;
}
// change to use empty page content
Example #8
0
 /**
  * @param $pageName
  * @param bool $ensureExists
  * @return WikiPage
  */
 public function getPageByName($pageName, $ensureExists = true)
 {
     $self = $this;
     $pageName = $this->normalizePageName($pageName);
     $page = Lazy::init($this->_cachedPages[$pageName], function () use($self, $pageName) {
         return WikiPage::create(array('name' => $pageName, 'repository' => $self));
     });
     if ($ensureExists) {
         $pageRealPath = realpath($page->path);
         if (!$pageRealPath || !file_exists($pageRealPath)) {
             throw new WikiPageNotFoundException($pageName, $this->path);
         }
         // ensure page's path should start with repo's path
         $repoRealPath = realpath($this->path);
         if (!$repoRealPath || strncmp($repoRealPath, $pageRealPath, strlen($repoRealPath)) != 0) {
             throw new WikiPageNotFoundException($pageName, $this->path);
         }
     }
     return $page;
 }
Example #9
0
 protected function commit_notes()
 {
     if ($this->notes) {
         if (!$this->wiki_page()) {
             WikiPage::create(array('title' => $this->name, 'body' => $this->notes, 'ip_addr' => $this->updater_ip_addr, 'user_id' => $this->updater_id));
         } elseif ($this->wiki_page()->is_locked) {
             $this->errors()->add('notes', "are locked");
         } else {
             $this->wiki_page()->updateAttributes(array('body' => $this->notes, 'ip_addr' => $this->updater_ip_addr, 'user_id' => $this->updater_id));
         }
     }
 }