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 along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * This script will automatically create mediawiki instances for
25 * projects that do not yet have it.
27 * It is intended to be started in a cronjob.
30 # TODO: How to use cronjob history?
31 # Required config variables:
32 # src_path: the directory where the mediawiki sources are installed
34 require_once dirname(__FILE__) . '/../../../www/env.inc.php';
35 require_once $gfcommon.'include/pre.php';
36 require_once $gfcommon.'include/cron_utils.php';
38 $src_path = forge_get_config('src_path', 'mediawiki');
39 $master_path = forge_get_config('master_path', 'mediawiki');
41 # Get all projects that use the mediawiki plugin
42 $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"));
44 $err = "Error: Database Query Failed: ".db_error();
50 # Loop over all projects that use the plugin
51 while ( $row = db_fetch_array($project_res) ) {
52 $project = $row['unix_group_name'];
53 $project_dir = forge_get_config('projects_path', 'mediawiki')
55 cron_debug("Checking $project...");
57 $res = db_query_params("SET search_path=public", array());
58 $res = db_query_params('DELETE FROM plugin_mediawiki_interwiki WHERE iw_prefix=$1', array($project));
59 $url = util_make_url('/plugins/mediawiki/wiki/' . $project . '/index.php/$1');
60 $res = db_query_params('INSERT INTO plugin_mediawiki_interwiki VALUES ($1, $2, 1, 0)',
64 // Create the project directory if necessary
65 if (is_dir($project_dir)) {
66 cron_debug(" Project dir $project_dir exists, so I assume the project already exists.");
69 $schema = "plugin_mediawiki_$project";
70 // Sanitize schema name
71 $schema = strtr($schema, "-", "_");
75 cron_debug(" Creating schema $schema.");
76 $res = db_query_params("CREATE SCHEMA $schema", array());
78 $err = "Error: Schema Creation Failed: " .
86 cron_debug(" Creating mediawiki database.");
87 $table_file = "$src_path/maintenance/postgres/tables.sql";
88 if (!file_exists($table_file)) {
89 $err = "Error: Couldn't find Mediawiki Database Creation File $table_file!";
96 $res = db_query_params("SET search_path=$schema", array());
98 $err = "Error: DB Query Failed: " .
106 $creation_query = file_get_contents($table_file);
107 $res = db_query_from_file($table_file);
109 $err = "Error: Mediawiki Database Creation Failed: " .
117 $res = db_query_params("CREATE TEXT SEARCH CONFIGURATION $schema.default ( COPY = pg_catalog.english )", array());
119 $err = "Error: DB Query Failed: " .
128 $err = "Error: DB Commit Failed: " .
135 cron_debug(" Creating project dir $project_dir.");
136 mkdir($project_dir, 0775, true);
137 chmod($project_dir, 0775);
139 $f = fopen("$project_dir/ProjectSettings.php", "w");
141 // Insert your project-local configuration here
144 chmod("$project_dir/ProjectSettings.php", 0775);
146 $mwwrapper = forge_get_config('source_path')."/plugins/mediawiki/bin/mw-wrapper.php" ;
147 $dumpfile = forge_get_config('config_path')."/plugins/mediawiki/initial-content.xml" ;
149 system ("$mwwrapper $project update.php --quick > /dev/null") ;
151 if (file_exists ($dumpfile)) {
152 system ("$mwwrapper $project importDump.php $dumpfile") ;
153 system ("$mwwrapper $project rebuildrecentchanges.php") ;
160 // c-file-style: "bsd"