Example #1
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_orphan($handler_id, array $args, array &$data)
 {
     $data['wiki_name'] = $this->_topic->extra;
     $data['view_title'] = sprintf($this->_l10n->get('orphaned pages in wiki %s'), $data['wiki_name']);
     midcom::get('head')->set_pagetitle($data['view_title']);
     $this->_node_toolbar->hide_item('orphans/');
     $data['orphans'] = array();
     $qb = net_nemein_wiki_wikipage::new_query_builder();
     $qb->add_constraint('topic', '=', $this->_topic->id);
     $qb->add_constraint('name', '<>', 'index');
     $qb->add_order('name');
     $wikipages = $qb->execute();
     foreach ($wikipages as $wikipage) {
         $link_qb = net_nemein_wiki_link_dba::new_query_builder();
         $link_qb->add_constraint('topage', '=', $wikipage->title);
         $links = $link_qb->count_unchecked();
         if ($links == 0) {
             $data['orphans'][] = $wikipage;
         }
     }
     $this->add_breadcrumb('orphans/', $data['view_title']);
 }
Example #2
0
 /**
  * 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();
     }
 }
Example #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_whatlinks($handler_id, $args, &$data, $view_mode = true)
 {
     $this->_load_page($args[0]);
     if (!$this->_page) {
         throw new midcom_error_notfound('The page ' . $args[0] . ' could not be found.');
     }
     $this->_load_datamanager();
     $this->_populate_toolbar();
     $this->_view_toolbar->hide_item("whatlinks/{$this->_page->name}/");
     $qb = net_nemein_wiki_link_dba::new_query_builder();
     $qb->add_constraint('topage', '=', $this->_page->title);
     $data['wikilinks'] = $qb->execute();
 }