private function _check_unique_wikiword($wikiword) { $resolver = new net_nemein_wiki_resolver($this->_topic->id); $resolved = $resolver->path_to_wikipage($wikiword, true, true); if (!empty($resolved['latest_parent'])) { $to_node =& $resolved['latest_parent']; } else { $to_node =& $resolved['folder']; } $created_page = false; switch (true) { case strstr($resolved['remaining_path'], '/'): // One or more namespaces left, find first, create it and recurse $paths = explode('/', $resolved['remaining_path']); $folder_title = array_shift($paths); $topic = new midcom_db_topic(); $topic->up = $to_node[MIDCOM_NAV_ID]; $topic->extra = $folder_title; $topic->title = $folder_title; $topic->name = midcom_helper_misc::generate_urlname_from_string($folder_title); $topic->component = 'net.nemein.wiki'; if (!$topic->create()) { throw new midcom_error("Could not create wiki namespace '{$folder_title}', last Midgard error was: " . midcom_connection::get_error_string()); } // refresh $topic = new midcom_db_topic($topic->id); // See if we have article with same title in immediate parent $qb = net_nemein_wiki_wikipage::new_query_builder(); $qb->add_constraint('title', '=', $folder_title); $qb->add_constraint('topic', '=', $topic->up); $results = $qb->execute(); if (is_array($results) && count($results) == 1) { $article =& $results[0]; $article->name = 'index'; $article->topic = $topic->id; if (!$article->update()) { // Could not move article, do something ? } } else { $created_page = net_nemein_wiki_viewer::initialize_index_article($topic); if (!$created_page) { // Could not create index $topic->delete(); throw new midcom_error("Could not create index for new topic, errstr: " . midcom_connection::get_error_string()); } } // We have created a new topic, now recurse to create the rest of the path. return $this->_check_unique_wikiword($wikiword); break; case is_object($resolved['wikipage']): // Page exists throw new midcom_error('Wiki page with that name already exists.'); break; default: // No more namespaces left, create the page to latest parent if ($to_node[MIDCOM_NAV_ID] != $this->_topic->id) { // Last parent is not this topic, redirect there $wikiword_url = rawurlencode($resolved['remaining_path']); midcom::get()->relocate($to_node[MIDCOM_NAV_FULLURL] . "create/{$this->_schema}?wikiword={$wikiword_url}"); // This will exit() } break; } return true; }
private function _load_page($wikiword) { $qb = net_nemein_wiki_wikipage::new_query_builder(); $qb->add_constraint('topic', '=', $this->_topic->id); $qb->add_constraint('name', '=', $wikiword); $result = $qb->execute(); if (count($result) > 0) { $this->_page = $result[0]; return true; } if ($wikiword == 'index') { // Autoinitialize $this->_topic->require_do('midgard:create'); $this->_page = net_nemein_wiki_viewer::initialize_index_article($this->_topic); if ($this->_page) { return true; } } $topic_qb = midcom_db_topic::new_query_builder(); $topic_qb->add_constraint('up', '=', $this->_topic->id); $topic_qb->add_constraint('name', '=', $wikiword); $topics = $topic_qb->execute(); if (count($topics) > 0) { // There is a topic by this URL name underneath, go there return false; } // We need to get the node from NAP for safe redirect $nap = new midcom_helper_nav(); $node = $nap->get_node($this->_topic->id); $urlized_wikiword = midcom_helper_misc::generate_urlname_from_string($wikiword); if ($urlized_wikiword != $wikiword) { // Lets see if the page for the wikiword exists $qb = net_nemein_wiki_wikipage::new_query_builder(); $qb->add_constraint('topic', '=', $this->_topic->id); $qb->add_constraint('title', '=', $wikiword); $result = $qb->execute(); if (count($result) > 0) { // This wiki page actually exists, so go there as "Permanent Redirect" midcom::get()->relocate("{$node[MIDCOM_NAV_ABSOLUTEURL]}{$result[0]->name}/", 301); } } midcom::get()->relocate("{$node[MIDCOM_NAV_ABSOLUTEURL]}notfound/" . rawurlencode($wikiword) . '/'); // This will exit }