Пример #1
0
 public function render_link($wikilink, $text = null)
 {
     if (null === $text) {
         $text = $wikilink;
     }
     // Don't choke on links with anchors
     $parts = explode('#', $wikilink, 2);
     $page_anchor = null;
     if (count($parts) == 2) {
         $wikilink = $parts[0];
         $page_anchor = "#{$parts[1]}";
     }
     $resolver = new net_nemein_wiki_resolver($this->_page->topic);
     $wikipage_match = $resolver->path_to_wikipage($wikilink);
     if (is_null($wikipage_match['wikipage'])) {
         // No page matched, link to creation
         $folder = $wikipage_match['folder'];
         if (is_null($wikipage_match['folder'])) {
             $folder = $wikipage_match['latest_parent'];
         }
         if (isset($folder[MIDCOM_NAV_OBJECT]) && $folder[MIDCOM_NAV_OBJECT]->can_do('midgard:create')) {
             $wikilink = rawurlencode($wikilink);
             return "<a href=\"{$folder[MIDCOM_NAV_FULLURL]}create/?wikiword={$wikipage_match['remaining_path']}\" class=\"wiki_missing\" title=\"" . midcom::get('i18n')->get_string('click to create', 'net.nemein.wiki') . "\">{$text}</a>";
         } else {
             return "<span class=\"wiki_missing_nouser\" title=\"" . midcom::get('i18n')->get_string('login to create', 'net.nemein.wiki') . "\">{$text}</span>";
         }
     }
     $url_name = $resolver->generate_page_url($wikipage_match['wikipage']);
     $type = $wikipage_match['wikipage']->parameter('midcom.helper.datamanager2', 'schema_name');
     return "<a href=\"{$url_name}{$page_anchor}\" class=\"wikipage {$type}\" title=\"{$wikilink}\">{$text}</a>";
 }
Пример #2
0
 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;
 }