3 * MediaWiki Plugin for FusionForge
6 * Thorsten Glaser <t.glaser@tarent.de>
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * Admin page for the plugin
27 require_once('../../env.inc.php');
28 require_once $gfcommon.'include/pre.php';
30 function logo_create($file_location, $wgUploadDirectory) {
31 $logofile = $wgUploadDirectory . "/.wgLogo.png";
33 if (!is_file($file_location) || !file_exists($file_location))
34 return _("Invalid file upload");
36 $img = getimagesize($file_location);
37 if (!$img || ($img[2] != IMAGETYPE_PNG))
38 return _("Not a valid PNG image");
39 if ($img[0] != 135 || $img[1] != 135)
40 return sprintf(_("Image size is %dx%d pixels, expected %dx%d instead"),
41 $img[0], $img[1], 135, 135);
43 if (!is_writable($wgUploadDirectory))
44 return _("Cannot copy file to target directory");
46 if (file_exists($logofile) && !is_writable($logofile))
47 return _("Cannot overwrite existing file");
49 $cmd = "/bin/mv " . escapeshellcmd($file_location) .
50 " " . escapeshellcmd($logofile);
52 if (!file_exists($logofile))
53 return _("Cannot move file to target location");
55 return _("New file installed successfully");
58 $user = session_get_user();
59 if (!$user || !is_object($user) || $user->isError() || !$user->isActive())
60 exit_error("Invalid User", "Cannot process your request for this user.");
62 $gid = getIntFromRequest("group_id", -1);
66 $group = group_get_object($gid);
68 exit_error("Invalid Project", "Nonexistent Project");
69 if (!$group->usesPlugin("mediawiki"))
70 exit_error("Invalid Project", "Project does not use MediaWiki Plugin");
72 $userperm = $group->getPermission($user);
73 if (!$userperm->IsMember())
74 exit_error("Access Denied", "You are not a member of this project");
75 if (!$userperm->IsAdmin())
76 exit_error("Access Denied", "You are not an admin of this project");
78 $group_unix_name = $group->getUnixName();
79 $wgUploadDirectory = "/var/lib/gforge/plugins/mediawiki/wikidata/" .
80 $group_unix_name . "/images";
81 $group_logo = $wgUploadDirectory . "/.wgLogo.png";
82 $group_logo_url = util_make_url("/plugins/mediawiki/wiki/" .
83 $group_unix_name . "/images/.wgLogo.png");
85 if (getStringFromRequest("logo_submit")) {
86 $userfile = getUploadedFile('userfile');
87 $userfile_name = $userfile['name'];
88 $manual_filename = getStringFromRequest('manual_filename');
92 if (getIntFromRequest("logo_nuke") == 1) {
93 if (unlink($wgUploadDirectory . "/.wgLogo.png"))
94 $feedback = _("File successfully removed");
96 $feedback = _("File removal error");
97 } else if ($userfile && is_uploaded_file($userfile['tmp_name']) &&
98 util_is_valid_filename($userfile['name'])) {
99 $infile = $userfile['tmp_name'];
100 $fname = $userfile['name'];
102 } else if ($userfile && $userfile['error'] != UPLOAD_ERR_OK &&
103 $userfile['error'] != UPLOAD_ERR_NO_FILE) {
104 switch ($userfile['error']) {
105 case UPLOAD_ERR_INI_SIZE:
106 case UPLOAD_ERR_FORM_SIZE:
107 $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).');
109 case UPLOAD_ERR_PARTIAL:
110 $feedback = _('The uploaded file was only partially uploaded.');
113 $feedback = _('Unknown file upload error.');
116 } else if (forge_get_config ('use_manual_uploads') && $manual_filename &&
117 util_is_valid_filename($manual_filename) &&
118 is_file($incoming.'/'.$manual_filename)) {
119 $incoming = forge_get_config('groupdir_prefix')."/$group_unix_name/incoming";
120 $infile = $incoming.'/'.$manual_filename;
121 $fname = $manual_filename;
124 $feedback = _('Unknown file upload error.');
129 $tmp = tempnam('', '');
133 $feedback = logo_create($infile, $wgUploadDirectory);
137 site_project_header(array(
138 "title" => "MediaWiki Plugin Admin",
139 "pagename" => "MediaWiki Project Admin",
140 "sectionvals" => array($group->getPublicName()),
145 echo "<h1>MediaWiki Plugin Admin for ".$group->getPublicName()."</h1>\n\n";
147 echo "<h2>\$wgLogo</h2>\n";
148 echo '<div style="border:solid 1px black; margin:3px; padding:3px;">';
149 if (file_exists($group_logo)) {
150 echo "\n <p>" . _("Current logo:") . ' (<a href="' . $group_logo_url .
151 '">' . _("Download") . '</a>)<br /><img alt="wgLogo.png" ' .
152 'class="boxed_wgLogo" src="' . $group_logo_url . '" />' .
155 echo "\n <p>" . _("No per-project logo currently installed.") . "</p>\n";
160 <form enctype="multipart/form-data" method="post"
161 style="border:solid 1px black; margin:3px; padding:3px;"
162 action="<?php echo getStringFromServer('PHP_SELF')."?group_id=$gid"; ?>">
163 <h4><?php echo _("Upload a new logo") ?></h4>
164 <span class="important">
165 <?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.')?>)
167 <p><?php echo _('Upload a new file') ?>: <input type="file" name="userfile"
169 <?php if (forge_get_config('use_manual_uploads')) {
170 $incoming = forge_get_config('groupdir_prefix')."/$group_unix_name/incoming" ;
173 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).'),
174 $incoming, "sftp://" . forge_get_config('web_host') . $incoming . "/");
175 echo ' ' . _('This direct <tt>sftp://</tt> link only works with some browsers, such as Konqueror.') . '<br />';
176 echo _('Choose an already uploaded file:').'<br />';
177 $manual_files_arr=ls($incoming,true);
178 echo html_build_select_box_from_arrays($manual_files_arr,$manual_files_arr,'manual_filename',''); ?>
181 <p><input type="checkbox" name="logo_nuke" value="1" /><?php
182 echo _("… or delete the currently uploaded logo and revert to the site default"); ?></p>
183 <p><input type="submit" name="logo_submit" value="<?php echo _("Upload new logo"); ?>" /></p>
187 site_project_footer(array());