3 Load [http://localhost/ewiki/tools/t_setupwiz.php] with your browser
4 to generate an "ewiki.ini" file by using a simple configuration
5 wizard, which queries you about all the features (plugins) and
6 settings you wish to use.
8 Save the generated .ini file to disk and then load the "ini.php"
9 script instead of "config.php" or "ewiki.php".
11 - not yet 100% compatible with the new *.meta data files
12 - beware of spaghetti code
17 include("../plugins/lib/pluginmetadata.php");
18 $_cached = !empty($_POST);
21 #-- defaults for the separately handled database settings in $db[]
22 if (!($db = $_REQUEST["db"])) {
25 "server" => "localhost",
29 "dba" => "/tmp/wiki.dbm",
33 #-- read in ewiki.ini, if one was uploaded (POST <input file>)
34 if ($li = $_FILES["load_ini"]["tmp_name"]) {
36 $uu = preg_split('/^\[(\w+)\]/m', implode("",file($li)), -1, PREG_SPLIT_DELIM_CAPTURE);
37 for ($i=1; $i<=count($uu); $i+=2) {
39 preg_match_all('/^\s*(\w[^\s]+)\s*=[\t ]*(.+?)(\s;.+)?\s*$/m', $uu[$i+1], $rows);
40 foreach ($rows[1] as $r=>$name) {
41 $ini[$sect][$name][] = trim($rows[2][$r]);
45 #-- pre-set the separate $db[] hash
47 foreach ($ini["db"] as $i=>$val) {
53 $default_priority_level = array(
54 "core"=>"1", "required"=>"1",
55 "default"=>1, "standard"=>1,
56 "recommended"=>1, "important"=>1,
60 #-- heavily mixed list of features and options
62 # - an array of arrays
63 # - each entry gives a 'feature' or simply a text fragment
64 # - first level subarrays have following entries
65 # [0] type setting, "!"=headline, "="=always_enabled_feature,
66 # 0=disabled, 1=enabled, "..."=text_fragment_only
68 # [2] text / description
69 # [3] list of plugin file names (without .php)
70 # [4] another subarray of option settings
71 # - an option setting subarray has following structure:
72 # [0] <input> field type
74 # [2] EWIKI_ constant or $ewiki_ var name
75 # [3] default setting (value)
76 # [4] text / description
77 # [5] options for <select> input, separated by "|" with "values=titles"
78 # - html text fragments can be inserted anywhere in titles or text and
79 # description entries (used for "database selection" part)
83 foreach (ewiki_pmd_by_category() as $category=>$pmd) {
89 foreach ($pmd as $id=>$row) {
90 if (!ewiki_pmd_hidden($row)) {
92 foreach (explode("\n", $row["config"]) as $l) {
94 $name = trim(strtok($l, "="));
97 if ($p = strpos($val, " //")) {
98 $comm = substr($val, $p+3);
99 $val = trim(trim(substr($val, 0, $p)), '"');
102 preg_match("/^([01](\|[01])?)$/", $val) ? "checkbox" : (strpos($val, "|") ? "select" : "text"),
112 ($uu = $default_priority_level[$row["priority"]]) ? $uu : 0,
113 htmlentities($row["title"]),
114 htmlentities($row["description"]),
127 <input type="radio" id="db-0" name="db[type]" value="none"><label for="db-0"> don't care</label>
128 <span class="feature-desc">If you don't need to open the database connection in the config.php - if a MySQL connection was already established somewhere else</span>
131 <input type="radio" id="db-1" name="db[type]" value="mysql"><label for="db-1"> built-in MySQL</label> <br>
132 <input type="radio" id="db-2" name="db[type]" value="pgsql"><label for="db-2"> or PostgreSQL</label> <span class="feature-desc">(with anydb_ wrapper)</span>
134 <label for="db-1-1">server </label><input type="text" id="db-1-1" name="db[server]" value="$db[server]"><br>
135 <label for="db-1-2">user name </label><input type="text" id="db-1-2" name="db[user]" value="$db[user]"><br>
136 <label for="db-1-3">password </label><input type="password" id="db-1-3" name="db[pw]" value="$db[pw]"><br>
137 <label for="db-1-4">database name </label><input type="text" id="db-1-4" name="db[dbname]" value="$db[dbname]"><br>
138 <label for="db-1-5">table name </label><input type="text" id="db-1-5" name="db[table]" value="$db[table]"> will be created automatically, when you activate ewiki for the first time<br>
141 <input type="radio" id="db-3" name="db[type]" value="flat"><label for="db-3"> flat file</label> <span class="feature-desc">database backend</span> <br>
142 <input type="radio" id="db-4" name="db[type]" value="fast"><label for="db-4"> fast file</label> <span class="feature-desc">(compressed)</span> <br>
143 <input type="radio" id="db-5" name="db[type]" value="dzf2"><label for="db-5"> new flat file backend 'dzf2'</label> <span class="feature-desc">(provides case-insensitive storage, plattform compatible, but more complicated structure)</span>
145 <label for="db-3-1">storage directory </label><input type="text" id="db-3-1" name="db[dir]" value="$db[dir]">
146 <span class="option-desc">Note: the directory "/tmp" exists on most
147 Unix/Linux webservers, but will be purged on reboot; so you normally want to
148 use a different location for your pages. Choose a <i>relative path name</i>
149 (like for example "<kbd>./files</kbd>") and create that directory ("<kbd>mkdir
150 <i>files</i></kbd>" in FTP/shell) and give it <i>world-write permissions</i>
151 ("<kbd>chmod 777 <i>files</i></kbd>" in FTP/shell).</span>
154 <input type="radio" id="db-6" name="db[type]" value="dba"><label for="db-6"> .dbm</label> <span class="feature-desc"> Berkely database file</span> <br>
156 <label for="db-6-1">database file </label><input type="text" id="db-6-1" name="db[dba]" value="$db[dba]">
157 <span class="option-desc">The file name extension must be one of:
158 .dbm, .db2, .db3, .db4, .ndbm, .gdbm or .flatfile, and the file must
159 be world-writable of course</span>
169 #---------------------------------------------------------------------------
175 #-- read in plugins/ dir
176 function find_plugin_files($realdir, $dirname) {
178 $dh = opendir($realdir);
179 while ($dh && ($fn = readdir($dh))) {
183 elseif (is_dir("$realdir/$fn")) {
184 $r = array_merge($r, find_plugin_files("$realdir/$fn", "$dirname/$fn"));
186 elseif ($len = strrpos($fn, ".")) {
187 $fn = substr($fn, 0, $len);
188 if (isset($r[$fn]) && $_SERVER["REQUEST_METHOD"]=="GET") {
189 echo "WARNING: two same named plugins '$fn' in two different locations!<br>\n";
191 $r[$fn] = "$dirname/$fn";
198 $uu = dirname(__FILE__)."/../plugins";
199 $plugin_files = find_plugin_files($uu, "plugins");
201 #-- adjust incomplete filenames in feature $list
202 foreach ($list as $i1=>$d) {
203 if (is_array($d[3])) foreach($d[3] as $i2=>$fn) {
204 if (!strpos($fn, "/")) {
205 if ($fullfn = $plugin_files[$fn]) {
206 $list[$i1][3][$i2] = $fullfn;
209 echo "WARNING: could not determine real file name for plugin '$fn'<br>\n";
218 #---------------------------------------------------------------------------
223 #-- inject values (into $list[]) imported from earlier loaded ewiki.ini
225 foreach ($list as $fid=>$row) {
227 #-- enable feature, if all requ/mentioned plugins were loaded in .ini
228 if (($row[0]===0) || ($row[0]===1)) {
229 $is = all_in_array($row[3], $ini["plugins"]["load"]);
230 $list[$fid][0] = ($is ? 1 : 0);
233 #-- set feature options
235 foreach ($row[4] as $oid=>$opts) {
237 $val = $ini["settings"][$name][0];
239 $list[$fid][4][$oid][3] = $val;
244 #-- compare two arrays, all elements of first must be in second
245 function all_in_array($a1, $a2) {
246 $a3 = array_intersect($a1, $a2);
247 return(count($a1) == count($a3));
251 #---------------------------------------------------------------------------
255 #-- prepare generation of config.php or ewiki.ini
256 # (builds plugin and constant/var lists from _REQUEST settings)
258 if ($_REQUEST["feature"]) {
260 $set = &$_REQUEST["feature"];
261 $opt = &$_REQUEST["option"];
263 $c_plugins = array();
264 $c_settings = array(0=>array(), 1=>array());
266 #-- go through hardcoded feature $list
267 foreach ($list as $fid=>$row) {
269 #-- compare if feature array enabled in _REQUEST
270 $enabled = ($row[0] === "=") || ($set[$fid]);
272 #echo "ENABLED=$set[$fid] feature[$fid], r0=$row[0], r1=$row[1],\n";
274 #-- list of plugins (always triggered)
275 $c_plugins[] = $row[3];
277 #-- settings, individual $_REQUEST entries
278 if ($options = $row[4]) {
279 foreach ($options as $oid=>$row) {
281 $v = $opt[$fid][$oid];
283 $var = ($i[0] == "$") ? 1 : 0;
284 $c_settings[$var][$i] = preg_match('/^\d+$/', $v) ? "$v" : "'$v'";
292 #-- cleanup plugin list (in case one was injected twice)
293 $c_plugins = array_unique($c_plugins);
298 #---------------------------------------------------------------------------
301 function config_php_db() {
305 echo "#-- database connection/plugins\n";
306 switch ($db["type"]) {
308 echo "// MySQL support is built-in, we only open the connection\n";
309 echo "define(\"EWIKI_DB_TABLE_NAME\", \"$db[table]\");\n";
310 echo "mysql_connect('$db[server]', '$db[user]', '$db[pw]');\n";
311 echo "mysql_query('USE $db[dbname]');\n\n";
315 echo "define(\"EWIKI_DB_TABLE_NAME\", \"$db[table]\");\n";
316 echo "define(\"EWIKI_DB_UTF8\", 0); //depends on your Postgres db\n";
317 echo "include_once(\"plugins/db/any.php\");\n";
318 echo "\$db = anydb_connect('', '$db[user]', '$db[pw]', '$db[dbname]', 'pgsql');\n\n";
322 echo "define(\"EWIKI_DB_FAST_FILES\", 1);\n";
324 echo "define(\"EWIKI_DBFILES_DIRECTORY\", \"$db[dir]\");\n";
325 echo "include_once(\"plugins/db/flat_files.php\");\n";
326 echo "// the given directory must exist and be world-writable (chmod 777)\n\n";
330 echo "define(\"EWIKI_DBFILES_DIRECTORY\", \"$db[dir]\");\n";
331 echo "define(\"EWIKI_DBFF_ACCURATE\", 1);\n";
332 echo "define(\"DZF2_HIT_COUNTING\", 1);\n";
333 echo "include_once(\"plugins/db/dzf2.php\");\n";
334 echo "// the given directory must exist and be world-writable (chmod 777)\n\n";
338 echo "define(\"EWIKI_DBA\", \"$db[dba]\");\n";
339 echo "include_once(\"plugins/db/dba.php\");\n";
343 echo "// you must open a connection (MySQL) outside of the config.php,\n";
344 echo "// it has not been configured with the setup wizard\n\n";
350 function config_php_settings() {
354 echo "#-- constants\n";
355 foreach ($c_settings[0] as $id=>$val) {
356 echo "define(\"$id\", $val);\n";
359 echo "\n#-- set a few configuration variables\n";
360 foreach ($c_settings[1] as $id=>$val) {
361 echo "$id = $val;\n";
366 #---------------------------------------------------------------------------
370 #-- write out "config.php" file
372 if ($_REQUEST["config_php"]) {
373 header("Content-Type: application/x-httpd-php");
374 header("Content-Disposition: attachment; filename=\"config.php\"");
376 #-- write out config.php
379 # automatically generated config.php
380 # (see the ewiki configuration wizard)
385 config_php_settings();
387 echo "\n#-- load plugins\n";
388 foreach ($c_plugins as $id) if ($id != "core") {
390 if ($fn = $ewiki_pmd[$id]["fn"]) {
391 echo "include_once(\"$fn\");\n";
394 echo "//plugin not found: $id\n";
398 echo "\n#-- load ewiki 'lib'\ninclude_once(\"ewiki.php\");\n\n";
404 #---------------------------------------------------------------------------
408 #-- write out as "ewiki.ini" file
410 if ($_REQUEST["ewiki_ini"]) {
411 header("Content-Type: text/x-ini-file");
412 header("Content-Disposition: attachment; filename=\"ewiki.ini\"");
417 #-- write out config.php
418 function out_ewiki_ini() {
419 global $db, $c_settings, $c_plugins, $ewiki_pmd;
420 echo "; automatically generated configuration summary\n; see ewiki config wizard\n";
423 foreach ($db as $id=>$val) {
426 echo "\n[settings]\n";
427 $c_settings = array_merge($c_settings[0], $c_settings[1]);
428 foreach ($c_settings as $id=>$val) {
429 $val = trim($val, "'");
432 echo "\n[plugins]\n";
433 foreach ($c_plugins as $id) {
434 if ($fn = $ewiki_pmd[$id]["fn"]) {
438 echo ";not found = $id\n";
446 #---------------------------------------------------------------------------
450 #-- generate a "monsterwiki.php" script (all-in-one)
452 if ($_REQUEST["monsterwiki_php"]) {
453 header("Content-Type: application/x-httpd-php");
454 header("Content-Disposition: attachment; filename=\"monsterwiki.php\"");
460 # (this script was assembled with the ewiki configuration wizard)
461 # include() this instead of the bare 'ewiki.php' script as follows:
463 # include("monsterwiki.php");
471 config_php_settings();
473 echo "\n#-- end of settings,\n# plugins follow\n\n/*-- config summary in .ini format:\n";
475 echo "--*/\n\n" . "?".">";
479 foreach ($c_plugins as $fn) {
480 if (($fn != "core") && ($fn != "ewiki")) {
481 if ($fn = $ewiki_pmd[$fn]["fn"]) {
482 readfile($PREFIX . $fn);
487 readfile($PREFIX."ewiki.php");
494 #---------------------------------------------------------------------------
495 # <html> page output otherwise
500 <title>ewiki configuration wizard</title>
501 <style type="text/css"><!--
503 show-tags: as-you-like-dear-browser;
506 margin: 0px; padding: 0px;
507 font: Verdana,sans-serif 16px;
515 padding: 0px 0px 0px 20px;
526 background-color: #4c4c4e;
531 background-color: #464646;
535 background-color: #404040;
538 input,checkbox,textarea,select {
539 background-color: #666666;
540 border: 1px solid #444444;
544 border-color: #663333;
546 .feature-desc, .option-desc {
561 text-decoration: none;
562 border-bottom: dashed 1px #773333;
566 <body bgcolor="#555555"><div class="left-bar">
567 <div class="stripe" style="background:#662222"> </div>
568 <div class="stripe" style="background:#642424"> </div>
569 <div class="stripe" style="background:#622626"> </div>
570 <div class="stripe" style="background:#602828"> </div>
571 <div class="stripe" style="background:#5E2A2A"> </div>
574 <div class="real-body">
575 <h1>ewiki configuration wizard</h1>
576 Generates an initial <tt>ewiki.ini</tt> or <tt>config.php</tt> for you.
577 The plugin list is unfiltered and therefore rather long. Skip all the
578 settings and options that don't look interesting or senseful at first.
581 <b>Note</b>: This wizard has not yet been fully updated to handle the
582 new plugin *.meta files. Please use the 'tools/setup' console program
586 You can reuse an earlier <tt>ewiki.ini</tt>, if you kept a copy of your
587 previously choosen settings:
589 <form action="t_setupwiz.php" method="POST" enctype="multipart/form-data" >
590 <input size="32" type="file" name="load_ini"> <input type="submit" value="load it">
596 foreach ($list as $fid=>$row) {
598 #-- print main feature field
603 echo " <input type=\"checkbox\" id=\"feature-$fid\" name=\"feature[$fid]\" value=\"1\" ".($row[0]?"checked":"").">\n";
604 echo " <label for=\"feature-$fid\">$row[1]</label>\n";
606 echo " <span class=\"feature-desc\">$row[2]</span>";
612 echo " <input type=\"hidden\" name=\"feature[$fid]\" value=\"1\">\n";
615 echo " <span class=\"feature-desc\">$row[2]</span>";
621 echo " <h3>$row[1]</h3>\n";
627 #-- show up associated options
628 if ($options = $row[4])
629 foreach ($options as $oid=>$row) {
630 $id = "option-$fid-$oid";
631 echo ' <div class="option">';
632 echo " <label for=\"$id\">$row[1]</label> ";
635 $checked = ($row[3] ? " checked" : "");
636 echo "<input type=\"checkbox\" name=\"option[$fid][$oid]\" id=\"$id\" value=\"1\"$checked>";
639 echo "<select name=\"option[$fid][$oid]\" id=\"$id\">";
640 foreach (explode("|", $row[5]) as $val) {
642 if (strpos($val, "=")) {
643 list($val, $title) = explode("=", $val, 2);
645 $checked = (($row[3]==$value) ? " selected" : "");
646 echo "<option value=\"$val\"$selected>$title</option>";
651 echo "<input type=\"$row[0]\" name=\"option[$fid][$oid]\" id=\"$id\" value=\"$row[3]\">";
653 echo "<span class=\"option-desc\"> $row[4]</span></div>\n";
660 Now, that you've finished clicking around, you can save your configuration
661 settings. A save dialog will open, and you should store the files directly
662 into your ewiki/ directory.
665 <input style="color:#ffffff" type="submit" name="config_php" value="save config.php"> is
666 what you should do now; you can use it as replacement for the example
667 file distributed with ewiki.
670 <input type="submit" name="ewiki_ini" value="save ewiki.ini"> is
671 useful to later come back and reuse the settings you've made here.
674 <input type="submit" name="monsterwiki_php" value="create monsterwiki script"> with
675 above options and extensions merged in; use this script instead of ewiki.php
676 then (it is believed to run a bit faster)