| 1 | <?php |
||
| 14 | class net_nemein_wiki_wikipage extends midcom_db_article |
||
|
1 ignored issue
–
show
|
|||
| 15 | { |
||
| 16 | public $autodelete_dependents = array |
||
| 17 | ( |
||
| 18 | 'net_nemein_wiki_link_dba' => 'frompage' |
||
| 19 | ); |
||
| 20 | |||
| 21 | public function _on_loaded() |
||
| 22 | { |
||
| 23 | // Backwards compatibility |
||
| 24 | if ($this->name == '') |
||
| 25 | { |
||
| 26 | $generator = midcom::get()->serviceloader->load('midcom_core_service_urlgenerator'); |
||
| 27 | $this->name = $generator->from_string($this->title); |
||
| 28 | $this->update(); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | public function _on_creating() |
||
| 33 | { |
||
| 34 | if ( $this->title == '' |
||
| 35 | || !$this->topic) |
||
| 36 | { |
||
| 37 | // We must have wikiword and topic at this stage |
||
| 38 | return false; |
||
| 39 | } |
||
| 40 | |||
| 41 | // Check for duplicates |
||
| 42 | $qb = net_nemein_wiki_wikipage::new_query_builder(); |
||
| 43 | $qb->add_constraint('topic', '=', $this->topic); |
||
| 44 | $qb->add_constraint('title', '=', $this->title); |
||
| 45 | if ($qb->count() > 0) |
||
| 46 | { |
||
| 47 | midcom_connection::set_error(MGD_ERR_OBJECT_NAME_EXISTS); |
||
| 48 | return false; |
||
| 49 | } |
||
| 50 | |||
| 51 | // Generate URL-clean name |
||
| 52 | if ($this->name != 'index') |
||
| 53 | { |
||
| 54 | $generator = midcom::get()->serviceloader->load('midcom_core_service_urlgenerator'); |
||
| 55 | $this->name = $generator->from_string($this->title); |
||
| 56 | } |
||
| 57 | return true; |
||
| 58 | } |
||
| 59 | |||
| 60 | public function _on_updating() |
||
| 74 | |||
| 75 | public function _on_updated() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Caches links in the wiki page into database for faster "what links here" queries |
||
| 84 | */ |
||
| 85 | private function update_link_cache() |
||
| 86 | { |
||
| 87 | $parser = new net_nemein_wiki_parser($this); |
||
| 88 | $links_in_content = $parser->find_links_in_content(); |
||
| 89 | |||
| 90 | $qb = net_nemein_wiki_link_dba::new_query_builder(); |
||
| 91 | $qb->add_constraint('frompage', '=', $this->id); |
||
| 92 | $links_in_db = $qb->execute(); |
||
| 93 | |||
| 94 | // Check links in DB versus links in content to see what needs to be removed |
||
| 95 | foreach ($links_in_db as $link) |
||
| 96 | { |
||
| 97 | if (!array_key_exists($link->topage, $links_in_content)) |
||
| 98 | { |
||
| 99 | // This link is not any more in content, remove |
||
| 100 | $link->delete(); |
||
| 101 | continue; |
||
| 102 | } |
||
| 103 | //no change for this link |
||
| 104 | unset($links_in_content[$link->topage]); |
||
| 105 | } |
||
| 106 | |||
| 107 | // What is still left needs to be added |
||
| 108 | $links_in_content = array_keys($links_in_content); |
||
| 109 | foreach ($links_in_content as $wikilink) |
||
| 110 | { |
||
| 111 | $link = new net_nemein_wiki_link_dba(); |
||
| 112 | $link->frompage = $this->id; |
||
| 113 | $link->topage = $wikilink; |
||
| 114 | debug_add("Creating net_nemein_wiki_link_dba: from page #{$link->frompage}, to page: '$link->topage'"); |
||
| 115 | $link->create(); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | private function list_watchers() |
||
| 146 | |||
| 147 | private function update_watchers() |
||
| 148 | { |
||
| 149 | $watchers = $this->list_watchers(); |
||
| 195 | |||
| 196 | private function get_diff($field = 'content') |
||
| 233 | } |
||
| 234 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.