Added BetterCodes Repository to README.
[phpwikibot.git] / cfgparse.php
blobcc5edd317ce1151cfc1a3f287734761cb379fe4b
1 <?php
2 /**
3 * PHPwikiBot Configuration File Parser
4 * @author Xiaomao
5 * @package PHPwikiBot
6 * @name Configuration Parser
7 * @license http://www.gnu.org/licenses/gpl.html GPLv3+
8 */
10 /** Include the required files */
11 require dirname(__FILE__).'/spyc.php';
12 require_once dirname(__FILE__).'/stddef.inc';
13 /** Load config.yml */
14 $cfg = spyc_load_file('config.yml');
16 /** Find out some config problems */
17 if (!isset ($cfg['useragent']) || !is_string($cfg['useragent'])) echo '\'useragent\' MUST be a string!!!'.PHP_EOL;
18 if (!isset ($cfg['key']) || !is_string($cfg['key'])) echo '\'key\' MUST be a string!!!'.PHP_EOL;
19 if (!isset ($cfg['logfile']) || !is_string($cfg['logfile'])) echo '\'logfile\' MUST be a string!!!'.PHP_EOL;
20 if (!isset ($cfg['output_log']) || !is_bool($cfg['output_log'])) echo '\'output_log\' MUST be yes or no!!!'.PHP_EOL;
21 if (!isset ($cfg['log2stderr']) || !is_bool($cfg['log2stderr'])) echo '\'log2stderr\' MUST be yes or no!!!'.PHP_EOL;
23 /** Set the variables */
24 /** User-Agent of the bot */
25 $useragent = $cfg['useragent'];
26 /** Password encryption key */
27 $key = $cfg['key'];
28 /** Log level handling */
29 switch ($cfg['log_level']) {
30 case 'LG_DEBUG':
31 $log_level = LG_DEBUG;
32 break;
33 case 'LG_INFO':
34 $log_level = LG_INFO;
35 break;
36 case 'LG_NOTICE':
37 $log_level = LG_NOTICE;
38 break;
39 case 'LG_WARN':
40 $log_level = LG_WARN;
41 break;
42 case 'LG_ERROR':
43 $log_level = LG_ERROR;
44 break;
45 case 'LG_FATAL':
46 $log_level = LG_FATAL;
47 break;
48 default:
49 echo <<<'EOD'
50 Error level MUST be one of the following:
51 * LG_DEBUG
52 * LG_INFO
53 * LG_NOTICE
54 * LG_WARN
55 * LG_ERROR
56 * LG_FATAL
58 EOD;
60 /** Log file */
61 $logfile = $cfg['logfile'];
62 /** Whether to output the log */
63 $output_log = $cfg['output_log'];
64 /** Log to STDERR??? */
65 define('LOG_TO_STDERR', $cfg['log2stderr']);
66 /** Wiki Configuration */
67 $wiki = $cfg['wiki'];
68 /** User Configuration */
69 $users = $cfg['users'];
70 /** Clean up */
71 $cfg = null;