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.
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?
30 # Required config variables:
31 # src_path: the directory where the mediawiki sources are installed
33 require_once dirname(__FILE__) . '/../../../www/env.inc.php';
34 require_once $gfcommon.'include/pre.php';
35 require_once $gfcommon.'include/cron_utils.php';
37 $src_path = forge_get_config('src_path', 'mediawiki');
38 $master_path = forge_get_config('master_path', 'mediawiki');
40 # Get all projects that use the mediawiki plugin
41 $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"));
43 $err = "Error: Database Query Failed: ".db_error();
49 # Loop over all projects that use the plugin
50 while ( $row = db_fetch_array($project_res) ) {
51 $project = $row['unix_group_name'];
52 $project_dir = forge_get_config('projects_path', 'mediawiki')
54 cron_debug("Checking $project...");
56 $res = db_query_params("SET search_path=public", array());
57 $res = db_query_params('DELETE FROM plugin_mediawiki_interwiki WHERE iw_prefix=$1', array($project));
58 $url = util_make_url('/plugins/mediawiki/wiki/' . $project . '/index.php/$1');
59 $res = db_query_params('INSERT INTO plugin_mediawiki_interwiki VALUES ($1, $2, 1, 0)',
63 // Create the project directory if necessary
64 if (is_dir($project_dir)) {
65 cron_debug(" Project dir $project_dir exists, so I assumen the project already exists.");
68 $schema = "plugin_mediawiki_$project";
69 // Sanitize schema name
70 $schema = strtr($schema, "-", "_");
74 cron_debug(" Creating schema $schema.");
75 $res = db_query_params("CREATE SCHEMA $schema", array());
77 $err = "Error: Schema Creation Failed: " .
85 cron_debug(" Creating mediawiki database.");
86 $table_file = "$src_path/maintenance/postgres/tables.sql";
87 if (!file_exists($table_file)) {
88 $err = "Error: Couldn't find Mediawiki Database Creation File $table_file!";
95 $res = db_query_params("SET search_path=$schema", array());
97 $err = "Error: DB Query Failed: " .
105 $creation_query = file_get_contents($table_file);
106 $res = db_query_from_file($table_file);
108 $err = "Error: Mediawiki Database Creation Failed: " .
116 $res = db_query_params("CREATE TEXT SEARCH CONFIGURATION $schema.default ( COPY = pg_catalog.english )", array());
118 $err = "Error: DB Query Failed: " .
127 $err = "Error: DB Commit Failed: " .
134 cron_debug(" Creating project dir $project_dir.");
135 mkdir($project_dir, 0775, true);
137 $mwwrapper = forge_get_config('source_path')."/plugins/mediawiki/bin/mw-wrapper.php" ;
138 $dumpfile = forge_get_config('config_path')."/mediawiki/initial-content.xml" ;
140 if (file_exists ($dumpfile)) {
141 system ("$mwwrapper $project importDump.php $dumpfile") ;
142 system ("$mwwrapper $project rebuildrecentchanges.php") ;
150 // c-file-style: "bsd"