3 * MediaWiki Plugin for FusionForge
6 * Thorsten Glaser <t.glaser@tarent.de>
7 * Copyright 2012, Franck Villaume - TrivialDev
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * Admin page for the plugin
28 require_once('../../env.inc.php');
29 require_once $gfcommon.'include/pre.php';
31 function logo_create($file_location, $wgUploadDirectory) {
32 $logofile = $wgUploadDirectory . "/.wgLogo.png";
34 if (!is_file($file_location) || !file_exists($file_location))
35 return _("Invalid file upload");
37 $img = getimagesize($file_location);
38 if (!$img || ($img[2] != IMAGETYPE_PNG))
39 return _("Not a valid PNG image");
40 if ($img[0] != 135 || $img[1] != 135)
41 return sprintf(_("Image size is %dx%d pixels, expected %dx%d instead"),
42 $img[0], $img[1], 135, 135);
44 if (!is_writable($wgUploadDirectory))
45 return _("Cannot copy file to target directory");
47 if (file_exists($logofile) && !is_writable($logofile))
48 return _("Cannot overwrite existing file");
50 $cmd = "/bin/mv " . escapeshellcmd($file_location) .
51 " " . escapeshellcmd($logofile);
53 if (!file_exists($logofile))
54 return _("Cannot move file to target location");
56 return _("New file installed successfully");
59 $user = session_get_user();
60 if (!$user || !is_object($user) || $user->isError() || !$user->isActive())
61 exit_error("Invalid User", "Cannot process your request for this user.");
63 $gid = getIntFromRequest("group_id", -1);
67 $group = group_get_object($gid);
69 exit_error("Invalid Project", "Nonexistent Project");
70 if (!$group->usesPlugin("mediawiki"))
71 exit_error("Invalid Project", "Project does not use MediaWiki Plugin");
73 $userperm = $group->getPermission($user);
74 if (!$userperm->IsMember())
75 exit_error("Access Denied", "You are not a member of this project");
76 if (!$userperm->IsAdmin())
77 exit_error("Access Denied", "You are not an admin of this project");
79 $group_unix_name = $group->getUnixName();
80 $wgUploadDirectory = forge_get_config('projects_path', 'mediawiki') . "/" .
81 $group_unix_name . "/images";
82 $group_logo = $wgUploadDirectory . "/.wgLogo.png";
83 $group_logo_url = util_make_url("/plugins/mediawiki/wiki/" .
84 $group_unix_name . "/images/.wgLogo.png");
86 /* As the cronjob creates images subdirs in project data only if the uploads are enabled, there are chances the upload may fail */
87 if (! forge_get_config('enable_uploads', 'mediawiki')) {
88 $error_msg .= _("Mediawiki plugin's configuration may require to enable uploads ('enable_uploads'). Contact your admin.");
91 if (getStringFromRequest("logo_submit")) {
92 $userfile = getUploadedFile('userfile');
93 $userfile_name = $userfile['name'];
94 $manual_filename = getStringFromRequest('manual_filename');
98 if (getIntFromRequest("logo_nuke") == 1) {
99 if (unlink($wgUploadDirectory . "/.wgLogo.png"))
100 $feedback = _("File successfully removed");
102 $feedback = _("File removal error");
103 } else if ($userfile && is_uploaded_file($userfile['tmp_name']) &&
104 util_is_valid_filename($userfile['name'])) {
105 $infile = $userfile['tmp_name'];
106 $fname = $userfile['name'];
108 } else if ($userfile && $userfile['error'] != UPLOAD_ERR_OK &&
109 $userfile['error'] != UPLOAD_ERR_NO_FILE) {
110 switch ($userfile['error']) {
111 case UPLOAD_ERR_INI_SIZE:
112 case UPLOAD_ERR_FORM_SIZE:
113 $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).');
115 case UPLOAD_ERR_PARTIAL:
116 $feedback = _('The uploaded file was only partially uploaded.');
119 $feedback = _('Unknown file upload error.');
122 } else if (forge_get_config ('use_manual_uploads') && $manual_filename &&
123 util_is_valid_filename($manual_filename) &&
124 is_file($incoming.'/'.$manual_filename)) {
125 $incoming = forge_get_config('groupdir_prefix')."/$group_unix_name/incoming";
126 $infile = $incoming.'/'.$manual_filename;
127 $fname = $manual_filename;
130 $feedback = _('Unknown file upload error.');
135 $tmp = tempnam('', '');
139 $feedback = logo_create($infile, $wgUploadDirectory);
143 site_project_header(array(
144 "title" => "MediaWiki Plugin Admin",
145 "pagename" => "MediaWiki Project Admin",
146 "sectionvals" => array($group->getPublicName()),
151 echo "<h1>MediaWiki Plugin Admin for ".$group->getPublicName()."</h1>\n\n";
153 echo "<h2>" . _('Nightly XML dump') . "</h2>\n";
155 printf(_('<a href="%s">Download</a> the nightly created XML dump (backup) here.'),
156 util_make_url("/plugins/mediawiki/dumps/" . $group_unix_name . ".xml"));
159 echo "<h2>\$wgLogo</h2>\n";
160 echo '<div style="border:solid 1px black; margin:3px; padding:3px;">';
161 if (file_exists($group_logo)) {
162 echo "\n <p>" . _("Current logo:") . ' (<a href="' . $group_logo_url .
163 '">' . _("Download") . '</a>)<br /><img alt="wgLogo.png" ' .
164 'class="boxed_wgLogo" src="' . $group_logo_url . '" />' .
167 echo "\n <p>" . _("No per-project logo currently installed.") . "</p>\n";
172 <form enctype="multipart/form-data" method="post"
173 style="border:solid 1px black; margin:3px; padding:3px;"
174 action="<?php echo getStringFromServer('PHP_SELF')."?group_id=$gid"; ?>">
175 <h4><?php echo _("Upload a new logo") ?></h4>
176 <span class="important">
177 <?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.')?>)
179 <p><?php echo _('Upload a new file') ?>: <input type="file" name="userfile"
181 <?php if (forge_get_config('use_manual_uploads')) {
182 $incoming = forge_get_config('groupdir_prefix')."/$group_unix_name/incoming" ;
185 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).'),
186 $incoming, "sftp://" . forge_get_config('web_host') . $incoming . "/");
187 echo ' ' . _('This direct <tt>sftp://</tt> link only works with some browsers, such as Konqueror.') . '<br />';
188 echo _('Choose an already uploaded file:').'<br />';
189 $manual_files_arr=ls($incoming,true);
190 echo html_build_select_box_from_arrays($manual_files_arr,$manual_files_arr,'manual_filename',''); ?>
193 <p><input type="checkbox" name="logo_nuke" value="1" /><?php
194 echo _("… or delete the currently uploaded logo and revert to the site default"); ?></p>
195 <p><input type="submit" name="logo_submit" value="<?php echo _("Upload new logo"); ?>" /></p>
199 site_project_footer(array());