From: Roland Mas Date: Mon, 10 May 2010 13:19:57 +0000 (+0000) Subject: allow file upload for per-project wgLogo X-Git-Tag: v5.1~2381 X-Git-Url: https://scm.fusionforge.org/anonscm/gitweb?p=fusionforge%2Ffusionforge.git;a=commitdiff_plain;h=a92e966eb708222430b07e393d3187904a2457f6 allow file upload for per-project wgLogo --- diff --git a/gforge/plugins/mediawiki/www/LocalSettings.php b/gforge/plugins/mediawiki/www/LocalSettings.php index d4a97cddfe..820544604a 100644 --- a/gforge/plugins/mediawiki/www/LocalSettings.php +++ b/gforge/plugins/mediawiki/www/LocalSettings.php @@ -295,6 +295,10 @@ if (is_file("/etc/mediawiki-extensions/extensions.php")) { include( "/etc/mediawiki-extensions/extensions.php" ); } +if (file_exists("$wgUploadDirectory/.wgLogo.png")) { + $wgLogo = "$wgScriptPath/images/.wgLogo.png"; +} + // project specific settings if (is_file("$project_dir/ProjectSettings.php")) { include ("$project_dir/ProjectSettings.php") ; diff --git a/gforge/plugins/mediawiki/www/plugin_admin.php b/gforge/plugins/mediawiki/www/plugin_admin.php index 45ea48e6b0..46c5f0a8d2 100644 --- a/gforge/plugins/mediawiki/www/plugin_admin.php +++ b/gforge/plugins/mediawiki/www/plugin_admin.php @@ -27,6 +27,27 @@ require_once('../../env.inc.php'); require_once $gfwww.'include/pre.php'; +function logo_create($file_location, $wgUploadDirectory) { + $logofile = $wgUploadDirectory . "/.wgLogo.png"; + + if (!is_file($file_location) || !file_exists($file_location)) + return _("Invalid file upload"); + + if (!is_writable($wgUploadDirectory)) + return _("Cannot copy file to target directory"); + + if (file_exists($logofile) && !is_writable($logofile)) + return _("Cannot overwrite existing file"); + + $cmd = "/bin/mv " . escapeshellcmd($file_location) . + " " . escapeshellcmd($logofile); + exec($cmd,$out); + if (!file_exists($logofile)) + return _("Cannot move file to target location"); + + return _("New file installed successfully"); +} + $user = session_get_user(); if (!$user || !is_object($user) || $user->isError() || !$user->isActive()) exit_error("Invalid User", "Cannot process your request for this user."); @@ -47,6 +68,67 @@ if (!$userperm->IsMember()) if (!$userperm->IsAdmin()) exit_error("Access Denied", "You are not an admin of this project"); +$group_unix_name = $group->getUnixName(); +$wgUploadDirectory = "/var/lib/gforge/plugins/mediawiki/wikidata/" . + $group_unix_name . "/images"; +$group_logo = $wgUploadDirectory . "/.wgLogo.png"; +$group_logo_url = util_make_url("/plugins/mediawiki/wiki/" . + $group_unix_name . "/images/.wgLogo.png"); + +if (getStringFromRequest("logo_submit")) { + global $groupdir_prefix, $sys_use_manual_uploads; + + $userfile = getUploadedFile('userfile'); + $userfile_name = $userfile['name']; + $manual_filename = getStringFromRequest('manual_filename'); + + $feedback = ""; + + if (getIntFromRequest("logo_nuke") == 1) { + if (unlink($wgUploadDirectory . "/.wgLogo.png")) + $feedback = _("File successfully removed"); + else + $feedback = _("File removal error"); + } else if ($userfile && is_uploaded_file($userfile['tmp_name']) && + util_is_valid_filename($userfile['name'])) { + $infile = $userfile['tmp_name']; + $fname = $userfile['name']; + $move = true; + } else if ($userfile && $userfile['error'] != UPLOAD_ERR_OK && + $userfile['error'] != UPLOAD_ERR_NO_FILE) { + switch ($userfile['error']) { + case UPLOAD_ERR_INI_SIZE: + case UPLOAD_ERR_FORM_SIZE: + $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).'); + break; + case UPLOAD_ERR_PARTIAL: + $feedback = _('The uploaded file was only partially uploaded.'); + break; + default: + $feedback = _('Unknown file upload error.'); + break; + } + } else if ($sys_use_manual_uploads && $manual_filename && + util_is_valid_filename($manual_filename) && + is_file($incoming.'/'.$manual_filename)) { + $incoming = "$groupdir_prefix/$group_unix_name/incoming"; + $infile = $incoming.'/'.$manual_filename; + $fname = $manual_filename; + $move = false; + } else { + $feedback = _('Unknown file upload error.'); + } + + if (!$feedback) { + if (!$move) { + $tmp = tempnam('', ''); + copy($infile, $tmp); + $infile = $tmp; + } + $feedback = logo_create($infile, $wgUploadDirectory); + } +} + site_project_header(array( "title" => "MediaWiki Plugin Admin", "pagename" => "MediaWiki Project Admin", @@ -55,7 +137,46 @@ site_project_header(array( "group" => $gid, )); -echo "

Dummy page.

\n"; +echo "

MediaWiki Plugin Admin for ".$group->getPublicName()."

\n\n"; + +echo "

\$wgLogo

\n"; +echo '
'; +if (file_exists($group_logo)) { + echo "\n

" . _("Current logo:") . '
wgLogo.png' . + "

\n"; +} else { + echo "\n

" . _("No per-project logo currently installed.") . "

\n"; +} +echo "
\n\n"; +?> +
"> +

+ + ) + +

:

+'; + printf(_('Alternatively, you can use a file you already uploaded (by SFTP or SCP) to the project\'s incoming directory (%1$s).'), + $incoming); + echo '
'; + echo _('Choose an already uploaded file:').'
'; + $manual_files_arr=ls($incoming,true); + echo html_build_select_box_from_arrays($manual_files_arr,$manual_files_arr,'manual_filename',''); ?> +

+ +

+

" />

+
+ + diff --git a/gforge/www/themes/css/gforge.css b/gforge/www/themes/css/gforge.css index d9a83a16bb..f2ff920d9b 100644 --- a/gforge/www/themes/css/gforge.css +++ b/gforge/www/themes/css/gforge.css @@ -418,3 +418,10 @@ A.lnkutility:hover { COLOR: #ffffff } .artifact_closed { text-decoration: line-through; } .task_closed { text-decoration: line-through; } +.boxed_wgLogo { + width:135px; + height:135px; + border:1px solid #CCCCCC; + margin:1px; + padding:1px; +}