/** * * @param mixed $handler_id The ID of the handler. * @param array &$data The local request data. */ public function _show_rss($handler_id, array &$data) { $qb = net_nemein_wiki_wikipage::new_query_builder(); $qb->add_constraint('topic.component', '=', midcom_core_context::get()->get_key(MIDCOM_CONTEXT_COMPONENT)); $qb->add_constraint('topic', 'INTREE', $this->_topic->id); $qb->add_order('metadata.revised', 'DESC'); $qb->set_limit($this->_config->get('rss_count')); $result = $qb->execute(); foreach ($result as $wikipage) { if ($wikipage->topic == $this->_topic->id) { $node = $data['node']; } else { $node = $data['nap']->get_node($wikipage->topic); } $item = new FeedItem(); $item->title = $wikipage->title; if ($wikipage->name == 'index') { $item->link = "{$node[MIDCOM_NAV_FULLURL]}"; } else { $item->link = "{$node[MIDCOM_NAV_FULLURL]}{$wikipage->name}/"; } $item->date = $wikipage->metadata->revised; try { $author = new midcom_db_person($wikipage->metadata->revisor); $item->author = $author->name; } catch (midcom_error $e) { $e->log(); } $parser = new net_nemein_wiki_parser($wikipage); $item->description = $parser->get_html(); $data['rss_creator']->addItem($item); } $data['rss'] = $data['rss_creator']->createFeed('RSS2.0'); echo $data['rss']; }
/** * Caches links in the wiki page into database for faster "what links here" queries */ private function _update_link_cache() { $parser = new net_nemein_wiki_parser($this); $links_in_content = $parser->find_links_in_content(); $qb = net_nemein_wiki_link_dba::new_query_builder(); $qb->add_constraint('frompage', '=', $this->id); $links_in_db = $qb->execute(); $links_matched = array(); // Check links in DB versus links in content to see what needs to be removed foreach ($links_in_db as $link) { if (!array_key_exists($link->topage, $links_in_content)) { // This link is not any more in content, remove $link->delete(); continue; } $links_matched[$link->topage] = $link; } // Check links in content versus matched links to see what needs to be added foreach ($links_in_content as $wikilink => $label) { if (array_key_exists($wikilink, $links_matched)) { // This is already in DB, skip continue; } $link = new net_nemein_wiki_link_dba(); $link->frompage = $this->id; $link->topage = $wikilink; debug_add("Creating net_nemein_wiki_link_dba: from page #{$link->frompage}, to page: '{$link->topage}'"); $link->create(); } }
/** * * @param mixed $handler_id The ID of the handler. * @param array &$data The local request data. */ public function _show_delete($handler_id, array &$data) { $this->_request_data['wikipage_view'] = $this->_datamanager->get_content_html(); // Replace wikiwords if (array_key_exists('content', $this->_request_data['wikipage_view'])) { $parser = new net_nemein_wiki_parser($this->_page); $this->_request_data['wikipage_view']['content'] = $parser->get_markdown($this->_request_data['wikipage_view']['content']); } midcom_show_style('view-wikipage-delete'); }
/** * @dataProvider provider_find_links_in_content */ public function test_find_links_in_content($text, $result) { self::$_page->content = $text; midcom::get('auth')->request_sudo('net.nemein.wiki'); self::$_page->update(); midcom::get('auth')->drop_sudo(); $parser = new net_nemein_wiki_parser(self::$_page); $links = $parser->find_links_in_content(); $this->assertEquals($result, $links); }
} // List possible wiki pages tagged with name of this page $tagged_pages = net_nemein_tag_handler::get_objects_with_tags(array($data['wikipage']->title), array('net_nemein_wiki_wikipage')); if (count($tagged_pages) > 0) { usort($tagged_pages, array('net_nemein_wiki_handler_view', 'sort_by_title')); echo "<dl class=\"tagged\">\n"; echo " <dt>" . sprintf($data['l10n']->get('%s for %s'), midcom::get('i18n')->get_string('tagged', 'net.nemein.tag'), $data['wikipage']->title) . "</dt>\n"; foreach ($tagged_pages as $page) { echo " <dd><a href=\"{$node[MIDCOM_NAV_FULLURL]}{$page->name}/\">{$page->title}</a></dd>\n"; } echo "</dl>\n"; } // List tags used in this wiki page $tags_by_context = net_nemein_tag_handler::get_object_tags_by_contexts($data['wikipage']); if (count($tags_by_context) > 0) { $parser = new net_nemein_wiki_parser($data['wikipage']); echo "<dl class=\"tags\">\n"; foreach ($tags_by_context as $context => $tags) { if (!$context) { $context = midcom::get('i18n')->get_string('tagged', 'net.nemein.tag'); } echo " <dt>{$context}</dt>\n"; foreach ($tags as $tag => $url) { $link = $parser->render_link($tag); echo " <dd class=\"tag\">{$link}</dd>\n"; } } echo "</dl>\n"; } ?> </div>
/** * * @param mixed $handler_id The ID of the handler. * @param array &$data The local request data. */ public function _show_edit($handler_id, array &$data) { $data['controller'] =& $this->_controller; $data['preview_mode'] = $this->_preview; if ($this->_preview) { // Populate preview page with values from form $data['preview_page'] = $this->_page; foreach ($this->_controller->datamanager->schema->fields as $name => $type_definition) { if (!is_a($this->_controller->datamanager->types[$name], 'midcom_helper_datamanager2_type_text')) { // Skip fields of other types continue; } switch ($type_definition['storage']) { case 'parameter': case 'configuration': case 'metadata': // Skip continue; default: $location = $type_definition['storage']['location']; } $data['preview_page']->{$location} = $this->_controller->datamanager->types[$name]->convert_to_storage(); } // Load DM for rendering the page $datamanager = new midcom_helper_datamanager2_datamanager($this->_schemadb); $datamanager->autoset_storage($data['preview_page']); $data['wikipage_view'] = $datamanager->get_content_html(); $data['wikipage'] =& $data['preview_page']; $data['autogenerate_toc'] = false; $data['display_related_to'] = false; // Replace wikiwords // TODO: We should somehow make DM2 do this so it would also work in AJAX previews $parser = new net_nemein_wiki_parser($data['preview_page']); $data['wikipage_view']['content'] = $parser->get_markdown($data['wikipage_view']['content']); } midcom_show_style('view-wikipage-edit'); }
/** * * @param mixed $handler_id The ID of the handler. * @param array &$data The local request data. */ public function _show_whatlinks($handler_id, array &$data) { if ($this->_controller) { $data['wikipage_view'] = $this->_controller->get_content_html(); } else { $data['wikipage_view'] = $this->_datamanager->get_content_html(); } // Replace wikiwords $parser = new net_nemein_wiki_parser($this->_page); $data['wikipage_view']['content'] = $parser->get_markdown($data['wikipage_view']['content']); midcom_show_style('view-wikipage-whatlinks'); }