changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / init.php
1 <?php
2
3 /*
4    This plugin is used as SetupWizard and initializes the database with
5    the distributed default pages from the ./init-pages directory. It
6    gives some configuration advice, when it thinks this is necessary.
7
8    You need this plugin to run only once (when you first run the Wiki),
9    afterwards you can and should comment out the include() directive which
10    enabled it.   
11 */
12
13
14 $ewiki_plugins["handler"][-125] = "ewiki_initialization_wizard";
15 $ewiki_plugins["init"][] = "ewiki_initialization_wizard2";
16
17
18 function ewiki_initialization_wizard2() {
19    global $ewiki_plugins;
20
21    #-- disable the default handler
22    unset($ewiki_plugins["handler"][-105]);
23 }
24
25 function ewiki_initialization_wizard($id, &$data, &$action) {
26
27    global $ewiki_plugins;
28
29    #-- proceed only if frontpage missing or explicetely requested
30    if ((strtolower($id)=="wikisetupwizard") || ($id==EWIKI_PAGE_INDEX) && ($action=="edit") && empty($data["version"]) && !($_REQUEST["abort"])) {
31
32       if ($_REQUEST["abort"]) {
33       }
34
35       #-- first print some what-would-we-do-stats
36       elseif (empty($_REQUEST["init"])) {
37
38          $o = "<h2>WikiSetupWizard</h2>\n";
39          $o .= "You don't have any pages in your Wiki yet, so we should try to read-in the default ones from <tt>init-pages/</tt> now.<br /><br />";
40
41          $o .= '<a href="'.ewiki_script("",$id,array("init"=>"now")).'">[InitializeWikiDatabase]</a>';
42          $o .= " &nbsp; ";
43          $o .= '<a href="'.ewiki_script("",$id,array("abort"=>"this")).'">[NoThanks]</a>';
44          $o .= "<br /><br />";
45
46          #-- analyze and print settings and misconfigurations
47          $pf_db = $ewiki_plugins["database"][0];
48          $db = substr("_$pf_db", strrpos($pf_db, "_") + 1);
49          $o .= '<table border="0" width="90%" class="diagnosis">';
50          $o .= '<tr><td>DatabaseBackend</td><td>';
51          $o .= "<b>" . $db . "</b><br />";
52          if (($db == "files") || strstr($db, "f2")) {
53             $o .= "<small>_DBFILES_DIR='</small><tt>" . EWIKI_DBFILES_DIRECTORY . "'</tt>";
54             if (strpos(EWIKI_DBFILES_DIRECTORY, "tmp")) {
55                $o .= "<br /><b>Warning</b>: Storing your pages into a temporary directory is not what you want (there they would get deleted randomly), except for testing purposes of course. See the README.";
56             }
57          }
58          else {
59             $o .= "(looks ok)";
60          }
61          $o .= "</td></tr>";
62
63          $o .= '<tr><td>WikiSoftware</td><td>ewiki '.EWIKI_VERSION."</td></tr>";
64          $o .= "</table>";
65
66          #-- more diagnosis 
67          if (ini_get("magic_quotes")) {
68             $o.= "<b>Warning</b>: Your PHP interpreter has enabled the ugly and outdated '<i>magic_quotes</i>'. This will lead to problems, so please ask your provider to correct it; or fix it yourself with .htaccess settings as documented in the README. Otherwise don't forget to include() the <tt>fragments/strip_wonderful_slashes.php</tt> (it's ok to proceed for the moment).<br /><br />";
69          }
70          if (ini_get("register_globals")) {
71             $o.= "<b>Security warning</b>: The horrible '<i>register_globals</i>' setting is enabled. Without always using <tt>fragments/strike_register_globals.php</tt> or letting your provider fix that, you could get into trouble some day.<br /><br />";
72          }
73
74          return('<div class="wiki view WikiSetupWizard">' . $o . '</div>');
75       }
76
77
78       #-- actually initialize the database
79       else {
80          ewiki_db::INIT();
81          if ($dh = @opendir($path=EWIKI_INIT_PAGES)) {
82             while ($filename = readdir($dh)) {
83                if (preg_match('/^(['.EWIKI_CHARS_U.']+['.EWIKI_CHARS_L.']+\w*)+/', $filename)) {
84                   $found = ewiki_db::FIND(array($filename));
85                   if (! $found[$filename]) {
86                      $content = implode("", file("$path/$filename"));
87                      ewiki_scan_wikiwords($content, $ewiki_links, "_STRIP_EMAIL=1");
88                      $refs = "\n\n" . implode("\n", array_keys($ewiki_links)) . "\n\n";
89                      $save = array(
90                         "id" => "$filename",
91                         "version" => "1",
92                         "flags" => "1",
93                         "content" => $content,
94                         "author" => ewiki_author("ewiki_initialize"),
95                         "refs" => $refs,
96                         "lastmodified" => filemtime("$path/$filename"),
97                         "created" => filectime("$path/$filename")   // (not exact)
98                      );
99                      ewiki_db::WRITE($save);
100                   }
101                }
102             }
103             closedir($dh);
104             ewiki_log("initializing database", 0);
105          }
106          else {
107             return("<b>ewiki error</b>: could not read from directory ". realpath($path) ."<br />\n");
108          }
109
110          #-- try to view/ that newly inserted page
111          if ($data = ewiki_db::GET($id)) {
112             $action = "view";
113          }
114
115          #-- let ewiki_page() proceed as usual
116          return("");
117       }
118    }
119
120 }
121
122
123 ?>