|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package net.nemein.wiki |
|
4
|
|
|
* @author The Midgard Project, http://www.midgard-project.org |
|
5
|
|
|
* @copyright The Midgard Project, http://www.midgard-project.org |
|
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
use midcom\datamanager\datamanager; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Wiki MidCOM interface class. |
|
13
|
|
|
* |
|
14
|
|
|
* @package net.nemein.wiki |
|
15
|
|
|
*/ |
|
16
|
|
|
class net_nemein_wiki_interface extends midcom_baseclasses_components_interface |
|
17
|
|
|
implements midcom_services_permalinks_resolver |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @inheritdoc |
|
21
|
|
|
*/ |
|
22
|
|
|
public function _on_reindex($topic, $config, &$indexer) |
|
23
|
|
|
{ |
|
24
|
|
|
$qb = net_nemein_wiki_wikipage::new_query_builder(); |
|
25
|
|
|
$qb->add_constraint('topic', '=', $topic->id); |
|
26
|
|
|
|
|
27
|
|
|
if ($result = $qb->execute()) { |
|
28
|
|
|
$datamanager = datamanager::from_schemadb($config->get('schemadb')); |
|
29
|
|
|
|
|
30
|
|
|
foreach ($result as $wikipage) { |
|
31
|
|
|
try { |
|
32
|
|
|
$datamanager->set_storage($wikipage); |
|
33
|
|
|
} catch (midcom_error $e) { |
|
34
|
|
|
$e->log(MIDCOM_LOG_WARN); |
|
35
|
|
|
continue; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
net_nemein_wiki_viewer::index($datamanager, $indexer, $topic); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return true; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function resolve_object_link(midcom_db_topic $topic, midcom_core_dbaobject $object) |
|
46
|
|
|
{ |
|
47
|
|
|
if ( $object instanceof midcom_db_article |
|
48
|
|
|
&& $topic->id == $object->topic) { |
|
49
|
|
|
if ($object->name == 'index') { |
|
50
|
|
|
return ''; |
|
51
|
|
|
} |
|
52
|
|
|
return "{$object->name}/"; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return null; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Check whether given wikiword is free in given node |
|
60
|
|
|
* |
|
61
|
|
|
* Returns true if word is free, false if reserved |
|
62
|
|
|
*/ |
|
63
|
5 |
|
public static function node_wikiword_is_free($node, $wikiword) : bool |
|
64
|
|
|
{ |
|
65
|
5 |
|
if (empty($node)) { |
|
66
|
|
|
//Invalid node |
|
67
|
|
|
debug_add('given node is not valid', MIDCOM_LOG_ERROR); |
|
68
|
|
|
return false; |
|
69
|
|
|
} |
|
70
|
5 |
|
$wikiword_name = midcom_helper_misc::urlize($wikiword); |
|
71
|
5 |
|
$qb = new midgard_query_builder('midgard_article'); |
|
72
|
5 |
|
$qb->add_constraint('topic', '=', $node[MIDCOM_NAV_OBJECT]->id); |
|
73
|
5 |
|
$qb->add_constraint('name', '=', $wikiword_name); |
|
74
|
5 |
|
$ret = $qb->execute(); |
|
75
|
5 |
|
if (!empty($ret)) { |
|
76
|
|
|
//Match found, word is reserved |
|
77
|
|
|
debug_add("QB found matches for name '{$wikiword_name}' in topic #{$node[MIDCOM_NAV_OBJECT]->id}, given word '{$wikiword}' is reserved", MIDCOM_LOG_INFO); |
|
78
|
|
|
debug_print_r('QB results:', $ret); |
|
79
|
|
|
return false; |
|
80
|
|
|
} |
|
81
|
5 |
|
return true; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|