3 * MediaWiki Plugin for FusionForge
6 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
7 * Thorsten Glaser <t.glaser@tarent.de>
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, $wgUploadDirectory) {
33 $logofile = $wgUploadDirectory . "/.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($wgUploadDirectory))
46 return _("Cannot copy file to target directory");
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);
70 exit_error("Invalid Project", "Nonexistent Project");
71 if (!$group->usesPlugin("mediawiki"))
72 exit_error("Invalid Project", "Project does not use MediaWiki Plugin");
74 $userperm = $group->getPermission();
75 if (!$userperm->IsMember())
76 exit_error("Access Denied", "You are not a member of this project");
77 if (!$userperm->IsAdmin())
78 exit_error("Access Denied", "You are not an admin of this project");
80 $group_unix_name = $group->getUnixName();
81 $wgUploadDirectory = forge_get_config('projects_path', 'mediawiki') . "/" .
82 $group_unix_name . "/images";
83 $group_logo = $wgUploadDirectory . "/.wgLogo.png";
84 $group_logo_url = util_make_url("/plugins/mediawiki/wiki/" .
85 $group_unix_name . "/images/.wgLogo.png");
87 /* As the cronjob creates images subdirs in project data only if the uploads are enabled, there are chances the upload may fail */
88 if (! forge_get_config('enable_uploads', 'mediawiki')) {
89 $error_msg .= _("Mediawiki plugin's configuration may require to enable uploads ('enable_uploads'). Contact your admin.");
92 if (getStringFromRequest("logo_submit")) {
93 $userfile = getUploadedFile('userfile');
94 $userfile_name = $userfile['name'];
95 $manual_filename = getStringFromRequest('manual_filename');
99 if (getIntFromRequest("logo_nuke") == 1) {
100 if (unlink($wgUploadDirectory . "/.wgLogo.png"))
101 $feedback = _("File successfully removed");
103 $feedback = _("File removal error");
104 } else if ($userfile && is_uploaded_file($userfile['tmp_name']) &&
105 util_is_valid_filename($userfile['name'])) {
106 $infile = $userfile['tmp_name'];
107 $fname = $userfile['name'];
109 } else if ($userfile && $userfile['error'] != UPLOAD_ERR_OK &&
110 $userfile['error'] != UPLOAD_ERR_NO_FILE) {
111 switch ($userfile['error']) {
112 case UPLOAD_ERR_INI_SIZE:
113 case UPLOAD_ERR_FORM_SIZE:
114 $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).');
116 case UPLOAD_ERR_PARTIAL:
117 $feedback = _('The uploaded file was only partially uploaded.');
120 $feedback = _('Unknown file upload error.');
123 } else if (forge_get_config ('use_manual_uploads') && $manual_filename &&
124 util_is_valid_filename($manual_filename) &&
125 is_file($incoming.'/'.$manual_filename)) {
126 $incoming = forge_get_config('groupdir_prefix')."/$group_unix_name/incoming";
127 $infile = $incoming.'/'.$manual_filename;
128 $fname = $manual_filename;
131 $feedback = _('Unknown file upload error.');
136 $tmp = tempnam('', '');
140 $feedback = logo_create($infile, $wgUploadDirectory);
144 site_project_header(array(
145 "title" => "MediaWiki Plugin Admin",
146 "pagename" => "MediaWiki Project Admin",
147 "sectionvals" => array($group->getPublicName()),
152 echo "<h1>MediaWiki Plugin Admin for ".$group->getPublicName()."</h1>\n\n";
154 echo "<h2>" . _('Nightly XML dump') . "</h2>\n";
156 printf(_('<a href="%s">Download</a> the nightly created XML dump (backup) here.'),
157 util_make_url("/plugins/mediawiki/dumps/" . $group_unix_name . ".xml"));
160 echo "<h2>\$wgLogo</h2>\n";
161 echo '<div style="border:solid 1px black; margin:3px; padding:3px;">';
162 if (file_exists($group_logo)) {
163 echo "\n <p>" . _("Current logo:") . ' (<a href="' . $group_logo_url .
164 '">' . _("Download") . '</a>)<br /><img alt="wgLogo.png" ' .
165 'class="boxed_wgLogo" src="' . $group_logo_url . '" />' .
168 echo "\n <p>" . _("No per-project logo currently installed.") . "</p>\n";
173 <form enctype="multipart/form-data" method="post"
174 style="border:solid 1px black; margin:3px; padding:3px;"
175 action="<?php echo getStringFromServer('PHP_SELF')."?group_id=$gid"; ?>">
176 <h4><?php echo _("Upload a new logo") ?></h4>
177 <span class="important">
178 <?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.')?>)
180 <p><?php echo _('Upload a new file') ?>: <input type="file" name="userfile"
182 <?php if (forge_get_config('use_manual_uploads')) {
183 $incoming = forge_get_config('groupdir_prefix')."/$group_unix_name/incoming" ;
186 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).'),
187 $incoming, "sftp://" . forge_get_config('web_host') . $incoming . "/");
188 echo ' ' . _('This direct <tt>sftp://</tt> link only works with some browsers, such as Konqueror.') . '<br />';
189 echo _('Choose an already uploaded file:').'<br />';
190 $manual_files_arr=ls($incoming,true);
191 echo html_build_select_box_from_arrays($manual_files_arr,$manual_files_arr,'manual_filename',''); ?>
194 <p><input type="checkbox" name="logo_nuke" value="1" /><?php
195 echo _("… or delete the currently uploaded logo and revert to the site default"); ?></p>
196 <p><input type="submit" name="logo_submit" value="<?php echo _("Upload new logo"); ?>" /></p>
200 site_project_footer(array());