3 * MediaWiki Plugin for FusionForge
5 * Copyright © 2010, 2012
6 * Thorsten Glaser <t.glaser@tarent.de>
7 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
8 * Copyright 2012, Franck Villaume - TrivialDev
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * Admin page for the plugin
29 require_once '../../env.inc.php';
30 require_once $gfcommon.'include/pre.php';
32 function logo_create($file_location, $project_mw_images_dir) {
33 $logofile = $project_mw_images_dir . "/.wgLogo.png";
35 if (!is_file($file_location) || !file_exists($file_location))
36 return _("Invalid file upload");
38 $img = getimagesize($file_location);
39 if (!$img || ($img[2] != IMAGETYPE_PNG))
40 return _("Not a valid PNG image");
41 if ($img[0] != 135 || $img[1] != 135)
42 return sprintf(_("Image size is %dx%d pixels, expected %dx%d instead"),
43 $img[0], $img[1], 135, 135);
45 if (!is_writable($project_mw_images_dir))
46 return sprintf( _("Cannot copy file to target directory %s"), $project_mw_images_dir) ;
48 if (file_exists($logofile) && !is_writable($logofile))
49 return _("Cannot overwrite existing file");
51 $cmd = "/bin/mv " . escapeshellcmd($file_location) .
52 " " . escapeshellcmd($logofile);
54 if (!file_exists($logofile))
55 return _("Cannot move file to target location");
57 return _("New file installed successfully");
60 $user = session_get_user();
61 if (!$user || !is_object($user) || $user->isError() || !$user->isActive())
62 exit_error("Invalid User", "Cannot process your request for this user.");
64 $gid = getIntFromRequest("group_id", -1);
68 $group = group_get_object($gid);
71 exit_error("Invalid Project", "Nonexistent Project");
73 if (!$group->usesPlugin("mediawiki")) {
74 exit_error("Invalid Project", "Project does not use MediaWiki Plugin");
77 $userperm = $group->getPermission();
78 if (!$userperm->IsMember())
79 exit_error("Access Denied", "You are not a member of this project");
80 if (!$userperm->IsAdmin())
81 exit_error("Access Denied", "You are not an admin of this project");
83 $group_unix_name = $group->getUnixName();
84 $wgUploadDirectory = forge_get_config('projects_path', 'mediawiki') . "/" .
85 $group_unix_name . "/images";
86 $group_logo = $wgUploadDirectory . "/.wgLogo.png";
87 $group_logo_url = util_make_url("/plugins/mediawiki/wiki/" .
88 $group_unix_name . "/images/.wgLogo.png");
91 if (forge_get_config('use_manual_uploads')) {
92 $incoming = forge_get_config('groupdir_prefix')."/$group_unix_name/incoming";
94 if ( (! is_dir($incoming)) || (! opendir($incoming)) ) {
95 $error_msg = sprintf( _("Not a directory or could not access contents of %s"), $incoming);
99 /* As the cronjob creates images subdirs in project data only if the uploads are enabled, there are chances the upload may fail */
100 if (! forge_get_config('enable_uploads', 'mediawiki')) {
101 $error_msg .= _("Mediawiki plugin's configuration may require to enable uploads ('enable_uploads'). Contact your admin.");
104 if (getStringFromRequest("logo_submit")) {
105 $userfile = getUploadedFile('userfile');
106 $userfile_name = $userfile['name'];
107 $manual_filename = getStringFromRequest('manual_filename');
111 if (getIntFromRequest("logo_nuke") == 1) {
112 if (unlink($wgUploadDirectory . "/.wgLogo.png")) {
113 $feedback = _("File successfully removed");
115 $feedback = _("File removal error");
117 } elseif ($userfile && is_uploaded_file($userfile['tmp_name']) &&
118 util_is_valid_filename($userfile['name'])) {
119 $infile = $userfile['tmp_name'];
120 $fname = $userfile['name'];
122 } elseif ($userfile && $userfile['error'] != UPLOAD_ERR_OK &&
123 $userfile['error'] != UPLOAD_ERR_NO_FILE) {
124 switch ($userfile['error']) {
125 case UPLOAD_ERR_INI_SIZE:
126 case UPLOAD_ERR_FORM_SIZE:
127 $feedback = _('The uploaded file exceeds the maximum file size. Contact to the site admin to upload this big file, or use an alternate upload method (if available).');
129 case UPLOAD_ERR_PARTIAL:
130 $feedback = _('The uploaded file was only partially uploaded.');
133 $feedback = _('Unknown file upload error.');
136 } elseif (forge_get_config ('use_manual_uploads') && $manual_filename &&
137 util_is_valid_filename($manual_filename) &&
138 is_file($incoming.'/'.$manual_filename)) {
139 $incoming = forge_get_config('groupdir_prefix')."/$group_unix_name/incoming";
140 $infile = $incoming.'/'.$manual_filename;
141 $fname = $manual_filename;
144 $feedback = _('Unknown file upload error.');
149 $tmp = tempnam('', '');
153 $feedback = logo_create($infile, $wgUploadDirectory);
157 site_project_header(array(
158 "title" => "MediaWiki Plugin Admin",
159 "pagename" => "MediaWiki Project Admin",
160 "sectionvals" => array($group->getPublicName()),
165 echo "<h1>MediaWiki Plugin Admin for ".$group->getPublicName()."</h1>\n\n";
167 echo "<h2>" . _('Nightly XML dump') . "</h2>\n";
169 printf(_('<a href="%s">Download</a> the nightly created XML dump (backup) here.'),
170 util_make_url("/plugins/mediawiki/dumps/" . $group_unix_name . ".xml"));
173 echo '<h2>'. _("This project's wiki logo : \$wgLogo") . "</h2>\n";
174 echo '<div style="border:solid 1px black; margin:3px; padding:3px;">';
175 if (file_exists($group_logo)) {
176 echo "\n <p>" . _("Current logo:") . ' (<a href="' . $group_logo_url .
177 '">' . _("Download") . '</a>)<br /><img alt="wgLogo.png" ' .
178 'class="boxed_wgLogo" src="' . $group_logo_url . '" />' .
181 echo "\n <p>" . _("No per-project logo currently installed.") . "</p>\n";
186 <form enctype="multipart/form-data" method="post"
187 style="border:solid 1px black; margin:3px; padding:3px;"
188 action="<?php echo getStringFromServer('PHP_SELF')."?group_id=$gid"; ?>">
189 <h4><?php echo _("Upload a new logo") ?></h4>
190 <p><?php echo _('The logo must be in PNG format and precisely 135x135 pixels in size.'); ?></p>
191 <span class="important">
192 <?php echo _('NOTE: In some browsers you must select the file in the file-upload dialog and click "OK". Double-clicking doesn\'t register the file.')?>)
194 <p><?php echo _('Upload a new file') ?>: <input type="file" name="userfile"
196 <?php if (forge_get_config('use_manual_uploads')) {
198 printf(_('Alternatively, you can use a file you already uploaded (by SFTP or SCP) to the <a href="%2$s">project\'s incoming directory</a> (%1$s).'),
199 $incoming, "sftp://" . forge_get_config('web_host') . $incoming . "/");
200 echo ' ' . _('This direct <tt>sftp://</tt> link only works with some browsers, such as Konqueror.') . '<br />';
201 $manual_files_arr=ls($incoming,true);
202 if ( count($manual_files_arr) > 0 ) {
203 echo _('Choose an already uploaded file:').'<br />';
204 echo html_build_select_box_from_arrays($manual_files_arr,$manual_files_arr,'manual_filename','');
206 echo '<input type="hidden" name="manual_filename" value="">';
210 <p><input type="checkbox" name="logo_nuke" value="1" /><?php
211 echo _("… or delete the currently uploaded logo and revert to the site default"); ?></p>
212 <p><input type="submit" name="logo_submit" value="<?php echo _("Upload new logo"); ?>" /></p>
216 site_project_footer(array());