4 * Copyright (C) 2010 Olaf Lenz
6 * This file is part of FusionForge.
8 * FusionForge is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * FusionForge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with FusionForge; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /** This script will automatically create mediawiki instances for
24 projects that do not yet have it.
26 It is intended to be started in a cronjob.
29 # TODO: How to use cronjob history?
31 # $mediawiki_src_path: the directory where the mediawiki sources are installed
32 # $mediawiki_var_path: the directory where mediawiki can store its data (i.e. LocalSettings.php and images/)
34 require (dirname(__FILE__) . '/../../env.inc.php');
35 require_once ($gfwww . 'include/squal_pre.php');
36 require $gfcommon.'include/cron_utils.php';
38 $project_settings_filename = "ProjectSettings.php";
39 $upload_dir_basename = "images";
41 if (!isset($mediawiki_var_path))
42 $mediawiki_var_path = "$sys_var_path/plugins/mediawiki";
43 if (!isset($mediawiki_src_path))
44 $mediawiki_src_path = "/usr/share/mediawiki";
45 if (!isset($mediawiki_projects_path))
46 $mediawiki_projects_path = "$mediawiki_var_path/projects";
47 if (!isset($mediawiki_master_path))
48 $mediawiki_master_path = "$mediawiki_var_path/master";
50 # Find the project settings template
51 $project_settings_template =
52 "$sys_etc_path/plugins/mediawiki/ProjectSettings.template.php";
53 if (!file_exists($project_settings_template))
54 $project_settings_template =
55 "$sys_opt_path/plugins/mediawiki/etc/plugins/mediawiki/$ProjectSettings.template.php";
57 # Owner of files - apache
58 $file_owner = $sys_apache_user.':'.$sys_apache_group;
59 if (empty($sys_apache_user) || empty($sys_apache_group)) {
60 $err = "Error: sys_apache_user Is Not Set Or sys_apache_group Is Not Set!";
67 # Get all projects that use the mediawiki plugin
68 $project_res = db_query_params ("SELECT g.unix_group_name from groups g, group_plugin gp, plugins p where g.group_id = gp.group_id and gp.plugin_id = p.plugin_id and p.plugin_name = $1;", array("mediawiki"));
70 $err = "Error: Database Query Failed: ".db_error();
76 # Loop over all projects that use the plugin
77 while ( $row = db_fetch_array($project_res) ) {
78 $project = $row['unix_group_name'];
79 $project_dir = "$mediawiki_projects_path/$project";
80 cron_debug("Checking $project...");
82 // Check whether the image (and project) directory exists
83 $upload_dir = "$project_dir/$upload_dir_basename";
84 if (!is_dir($upload_dir)) {
85 cron_debug(" Creating upload dir $upload_dir.");
86 system("mkdir -p $upload_dir");
88 cron_debug(" Upload dir $upload_dir exists.");
91 // Check whether the project settings file exists
92 $project_settings = "$project_dir/ProjectSettings.php";
93 if (!file_exists($project_settings)) {
94 cron_debug(" Copying $project_settings_template to $project_settings.");
95 if (!copy($project_settings_template, $project_settings)) {
96 $err = ("Error: Failed to copy $project_settings_template to $project_settings!");
102 cron_debug(" File $project_settings exists.");
108 $schema = "plugin_mediawiki_$project";
109 // Sanitize schema name
110 strtr($schema, "-", "_");
114 cron_debug(" Creating schema $schema.");
115 $res = db_query_params("CREATE SCHEMA $schema", array());
117 $err = "Error: Schema Creation Failed: " .
125 cron_debug(" Creating mediawiki database.");
126 $table_file = "$mediawiki_src_path/maintenance/postgres/tables.sql";
127 if (!file_exists($table_file)) {
128 $err = "Error: Couldn't find Mediawiki Database Creation File $mediawiki_creation_file!";
135 $res = db_query_params("SET search_path=$schema", array());
137 $err = "Error: DB Query Failed: " .
145 $creation_query = file_get_contents($table_file);
146 $res = db_query_from_file($table_file);
148 $err = "Error: Mediawiki Database Creation Failed: " .
156 $res = db_query_params("CREATE TEXT SEARCH CONFIGURATION $schema.default ( COPY = pg_catalog.english )", array());
158 $err = "Error: DB Query Failed: " .
167 $err = "Error: DB Commit Failed: " .
174 $mwwrapper = $sys_opt_path."/plugins/mediawiki/bin/mw-wrapper.php" ;
175 $dumpfile = $sys_etc_path."/mediawiki/initial-content.xml" ;
177 if (file_exists ($dumpfile)) {
178 system ("$mwwrapper $project importDump.php $dumpfile") ;
179 system ("$mwwrapper $project rebuildrecentchanges.php") ;
182 cron_debug(" Nothing to be done.");
189 // c-file-style: "bsd"