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 if (getStringFromRequest("logo_submit")) {
88 $userfile = getUploadedFile('userfile');
89 $userfile_name = $userfile['name'];
90 $manual_filename = getStringFromRequest('manual_filename');
94 if (getIntFromRequest("logo_nuke") == 1) {
95 if (unlink($wgUploadDirectory . "/.wgLogo.png"))
96 $feedback = _("File successfully removed");
98 $feedback = _("File removal error");
99 } else if ($userfile && is_uploaded_file($userfile['tmp_name']) &&
100 util_is_valid_filename($userfile['name'])) {
101 $infile = $userfile['tmp_name'];
102 $fname = $userfile['name'];
104 } else if ($userfile && $userfile['error'] != UPLOAD_ERR_OK &&
105 $userfile['error'] != UPLOAD_ERR_NO_FILE) {
106 switch ($userfile['error']) {
107 case UPLOAD_ERR_INI_SIZE:
108 case UPLOAD_ERR_FORM_SIZE:
109 $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).');
111 case UPLOAD_ERR_PARTIAL:
112 $feedback = _('The uploaded file was only partially uploaded.');
115 $feedback = _('Unknown file upload error.');
118 } else if (forge_get_config ('use_manual_uploads') && $manual_filename &&
119 util_is_valid_filename($manual_filename) &&
120 is_file($incoming.'/'.$manual_filename)) {
121 $incoming = forge_get_config('groupdir_prefix')."/$group_unix_name/incoming";
122 $infile = $incoming.'/'.$manual_filename;
123 $fname = $manual_filename;
126 $feedback = _('Unknown file upload error.');
131 $tmp = tempnam('', '');
135 $feedback = logo_create($infile, $wgUploadDirectory);
139 site_project_header(array(
140 "title" => "MediaWiki Plugin Admin",
141 "pagename" => "MediaWiki Project Admin",
142 "sectionvals" => array($group->getPublicName()),
147 echo "<h1>MediaWiki Plugin Admin for ".$group->getPublicName()."</h1>\n\n";
149 echo "<h2>" . _('Nightly XML dump') . "</h2>\n";
151 printf(_('<a href="%s">Download</a> the nightly created XML dump (backup) here.'),
152 util_make_url("/plugins/mediawiki/dumps/" . $group_unix_name . ".xml"));
155 echo "<h2>\$wgLogo</h2>\n";
156 echo '<div style="border:solid 1px black; margin:3px; padding:3px;">';
157 if (file_exists($group_logo)) {
158 echo "\n <p>" . _("Current logo:") . ' (<a href="' . $group_logo_url .
159 '">' . _("Download") . '</a>)<br /><img alt="wgLogo.png" ' .
160 'class="boxed_wgLogo" src="' . $group_logo_url . '" />' .
163 echo "\n <p>" . _("No per-project logo currently installed.") . "</p>\n";
168 <form enctype="multipart/form-data" method="post"
169 style="border:solid 1px black; margin:3px; padding:3px;"
170 action="<?php echo getStringFromServer('PHP_SELF')."?group_id=$gid"; ?>">
171 <h4><?php echo _("Upload a new logo") ?></h4>
172 <span class="important">
173 <?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.')?>)
175 <p><?php echo _('Upload a new file') ?>: <input type="file" name="userfile"
177 <?php if (forge_get_config('use_manual_uploads')) {
178 $incoming = forge_get_config('groupdir_prefix')."/$group_unix_name/incoming" ;
181 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).'),
182 $incoming, "sftp://" . forge_get_config('web_host') . $incoming . "/");
183 echo ' ' . _('This direct <tt>sftp://</tt> link only works with some browsers, such as Konqueror.') . '<br />';
184 echo _('Choose an already uploaded file:').'<br />';
185 $manual_files_arr=ls($incoming,true);
186 echo html_build_select_box_from_arrays($manual_files_arr,$manual_files_arr,'manual_filename',''); ?>
189 <p><input type="checkbox" name="logo_nuke" value="1" /><?php
190 echo _("… or delete the currently uploaded logo and revert to the site default"); ?></p>
191 <p><input type="submit" name="logo_submit" value="<?php echo _("Upload new logo"); ?>" /></p>
195 site_project_footer(array());