Пример #1
0
 /**
  * Check the edit request
  *
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_edit($handler_id, array $args, array &$data)
 {
     $this->_page = $this->_master->load_page($args[0]);
     $this->_page->require_do('midgard:update');
     $this->_load_controller();
     switch ($this->_controller->process_form()) {
         case 'preview':
             $this->_preview = true;
             $data['formmanager'] =& $this->_controller->formmanager;
             break;
         case 'save':
             // Reindex the article
             $indexer = midcom::get('indexer');
             net_nemein_wiki_viewer::index($this->_controller->datamanager, $indexer, $this->_topic);
             midcom::get('uimessages')->add($this->_request_data['l10n']->get('net.nemein.wiki'), sprintf($this->_request_data['l10n']->get('page %s saved'), $this->_page->title), 'ok');
             // *** FALL-THROUGH ***
         // *** FALL-THROUGH ***
         case 'cancel':
             if ($this->_page->name == 'index') {
                 return new midcom_response_relocate(midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX));
             } else {
                 return new midcom_response_relocate(midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX) . "{$this->_page->name}/");
             }
     }
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "{$this->_page->name}/", MIDCOM_TOOLBAR_LABEL => $this->_request_data['l10n_midcom']->get('view'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_left.png', MIDCOM_TOOLBAR_ACCESSKEY => 'v'));
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "delete/{$this->_page->name}/", MIDCOM_TOOLBAR_LABEL => $this->_request_data['l10n_midcom']->get('delete'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png', MIDCOM_TOOLBAR_ACCESSKEY => 'd', MIDCOM_TOOLBAR_ENABLED => $this->_page->can_do('midgard:delete')));
     foreach (array_keys($this->_request_data['schemadb']) as $name) {
         if ($name == $this->_controller->datamanager->schema->name) {
             // The page is already of this type, skip
             continue;
         }
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "change/{$this->_page->name}/", MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n->get('change to %s'), $this->_l10n->get($this->_request_data['schemadb'][$name]->description)), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_refresh.png', MIDCOM_TOOLBAR_POST => true, MIDCOM_TOOLBAR_POST_HIDDENARGS => array('change_to' => $name), MIDCOM_TOOLBAR_ENABLED => $this->_page->can_do('midgard:update')));
     }
     $this->bind_view_to_object($this->_page, $this->_controller->datamanager->schema->name);
     $data['view_title'] = sprintf($this->_request_data['l10n']->get('edit %s'), $this->_page->title);
     midcom::get('head')->set_pagetitle($data['view_title']);
     // Set the breadcrumb pieces
     $this->add_breadcrumb("{$this->_page->name}/", $this->_page->title);
     $this->add_breadcrumb("edit/{$this->_page->name}/", $this->_l10n_midcom->get('edit'));
     // Set the help object in the toolbar
     $this->_view_toolbar->add_help_item('markdown', 'net.nemein.wiki');
 }
Пример #2
0
 /**
  * Iterate over all wiki pages and create index record using the datamanager2 indexer
  * method.
  */
 public function _on_reindex($topic, $config, &$indexer)
 {
     $qb = net_nemein_wiki_wikipage::new_query_builder();
     $qb->add_constraint('topic', '=', $topic->id);
     $result = $qb->execute();
     if ($result) {
         $schemadb = midcom_helper_datamanager2_schema::load_database($config->get('schemadb'));
         $datamanager = new midcom_helper_datamanager2_datamanager($schemadb);
         if (!$datamanager) {
             debug_add('Warning, failed to create a datamanager instance with this schemapath:' . $config->get('schemadb'), MIDCOM_LOG_WARN);
             continue;
         }
         foreach ($result as $wikipage) {
             if (!$datamanager->autoset_storage($wikipage)) {
                 debug_add("Warning, failed to initialize datamanager for Wiki page {$wikipage->id}. Skipping it.", MIDCOM_LOG_WARN);
                 continue;
             }
             net_nemein_wiki_viewer::index($datamanager, $indexer, $topic);
         }
     }
     return true;
 }
Пример #3
0
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_create($handler_id, array $args, array &$data)
 {
     // Initialize sessioning first
     $data['session'] = new midcom_services_session();
     if (!array_key_exists('wikiword', $_GET)) {
         if (!$data['session']->exists('wikiword')) {
             throw new midcom_error_notfound('No wiki word given');
         } else {
             $this->_wikiword = $data['session']->get('wikiword');
         }
     } else {
         $this->_wikiword = $_GET['wikiword'];
         $data['session']->set('wikiword', $this->_wikiword);
     }
     $this->_topic->require_do('midgard:create');
     if ($handler_id == 'create_by_word_schema') {
         $this->_schema = $args[0];
     } else {
         $this->_schema = $this->_config->get('default_schema');
     }
     if (!array_key_exists($this->_schema, $data['schemadb'])) {
         throw new midcom_error_notfound('Schema ' . $this->_schema . ' not found in schemadb');
     }
     $this->_check_unique_wikiword($this->_wikiword);
     $data['controller'] = $this->get_controller('create');
     switch ($data['controller']->process_form()) {
         case 'save':
             // Reindex the article
             $indexer = midcom::get('indexer');
             net_nemein_wiki_viewer::index($data['controller']->datamanager, $indexer, $this->_topic);
             midcom::get('uimessages')->add($this->_l10n->get('net.nemein.wiki'), sprintf($this->_l10n->get('page %s added'), $this->_wikiword), 'ok');
             return new midcom_response_relocate("{$this->_page->name}/");
         case 'cancel':
             return new midcom_response_relocate('');
     }
     $data['view_title'] = sprintf($this->_request_data['l10n']->get('create wikipage %s'), $this->_wikiword);
     midcom::get('head')->set_pagetitle($data['view_title']);
     $data['preview_mode'] = false;
     $this->add_breadcrumb("create/?wikiword=" . rawurlencode($this->_wikiword), sprintf($this->_l10n->get('create wikipage %s'), $this->_wikiword));
     // Set the help object in the toolbar
     $this->_view_toolbar->add_help_item('markdown', 'net.nemein.wiki');
 }
Пример #4
0
 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
 }