5 * This file is part of Fusionforge.
7 * Copyright 2010 (c) Marc-Etienne Vargenau, Alcatel-Lucent
9 * Fusionforge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Fusionforge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 class WikiConfig extends FFError {
27 var $default_config = array(
28 'DISABLE_MARKUP_WIKIWORD' => true,
29 'NUM_SPAM_LINKS' => false,
30 'ENABLE_RATEIT' => false,
33 var $default_desc = array(
36 function WikiConfig($group_id=false)
38 $this->default_desc['DISABLE_MARKUP_WIKIWORD']
39 = _("Check to disable automatic linking of camelcase words to pages. Internal page links must be forced with [[pagename]] then.");
40 $this->default_desc['NUM_SPAM_LINKS']
41 = _("Check to enable spam prevention. If a non-admin adds more than 20 external links, it will be rejected as spam.");
42 $this->default_desc['ENABLE_RATEIT']
43 = _("Check to enable page rating. Logged users will be able to rate wiki pages.");
44 $this->group_id = (int)$group_id;
48 function getWikiConfigNames()
50 return array_keys($this->default_config);
53 function getWikiConfigDescription($config_name)
55 return $this->default_desc[$config_name];
58 function getWikiConfig($config_name)
60 if (!isset($this->default_config[$config_name])) {
61 $this->setError('getWikiConfig: illegal config name');
64 $res = db_query_params('SELECT config_value FROM plugin_wiki_config WHERE group_id=$1 AND config_name=$2', array($this->group_id, $config_name));
65 if (db_numrows($res) > 0) {
66 return(db_result($res, 0, 'config_value'));
68 return $this->default_config[$config_name];
72 function updateWikiConfig($config_name, $config_value)
74 if (!isset($this->default_config[$config_name])) {
75 $this->setError('updateWikiConfig: illegal config name');
78 if (!is_numeric($config_value)) {
79 $this->setError('updateWikiConfig: value should be numeric');
82 $res = db_query_params('SELECT count(*) as c FROM plugin_wiki_config WHERE group_id=$1 AND config_name=$2',
83 array($this->group_id, $config_name));
84 if (db_result($res, 0, 'c') > 0) {
85 $res = db_query_params('UPDATE plugin_wiki_config SET config_value=$3 WHERE group_id=$1 AND config_name=$2',
86 array($this->group_id, $config_name, $config_value));
88 $res = db_query_params('INSERT INTO plugin_wiki_config (group_id, config_name, config_value) VALUES ($1, $2, $3)',
89 array($this->group_id, $config_name, $config_value));
92 $this->setError('WikiConfig::updateWikiConfig():: '.db_error());