X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/20ba12802b3897bf48d8a7704a57e9cede2466bd..2c308db3967568d46b4aa337feeaf240bef1f202:/IkiWiki/Plugin/attachment.pm diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index ad1dd9bca..647a671a5 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -58,7 +58,7 @@ sub check_canattach ($$;$) { $config{allowed_attachments}, file => $file, user => $session->param("name"), - ip => $ENV{REMOTE_ADDR}, + ip => $session->remote_addr(), ); } @@ -92,7 +92,7 @@ sub formbuilder_setup (@) { # Add the toggle javascript; the attachments interface uses # it to toggle visibility. require IkiWiki::Plugin::toggle; - $form->tmpl_param("javascript" => IkiWiki::Plugin::toggle::include_javascript($params{page}, 1)); + $form->tmpl_param("javascript" => IkiWiki::Plugin::toggle::include_javascript($params{page})); # Start with the attachments interface toggled invisible, # but if it was used, keep it open. if ($form->submitted ne "Upload Attachment" && @@ -134,16 +134,19 @@ sub formbuilder (@) { } } + $filename=IkiWiki::basename($filename); + $filename=~s/.*\\+(.+)/$1/; # hello, windows + $filename=linkpage(IkiWiki::possibly_foolish_untaint( attachment_location($form->field('page')). - IkiWiki::basename($filename))); - if (IkiWiki::file_pruned($filename, $config{srcdir})) { + $filename)); + if (IkiWiki::file_pruned($filename)) { error(gettext("bad attachment filename")); } # Check that the user is allowed to edit a page with the # name of the attachment. - IkiWiki::check_canedit($filename, $q, $session, 1); + IkiWiki::check_canedit($filename, $q, $session); # And that the attachment itself is acceptable. check_canattach($session, $filename, $tempfile); @@ -180,9 +183,12 @@ sub formbuilder (@) { if ($config{rcs}) { IkiWiki::rcs_add($filename); IkiWiki::disable_commit_hook(); - IkiWiki::rcs_commit($filename, gettext("attachment upload"), - IkiWiki::rcs_prepedit($filename), - $session->param("name"), $ENV{REMOTE_ADDR}); + IkiWiki::rcs_commit( + file => $filename, + message => gettext("attachment upload"), + token => IkiWiki::rcs_prepedit($filename), + session => $session, + ); IkiWiki::enable_commit_hook(); IkiWiki::rcs_update(); } @@ -195,7 +201,14 @@ sub formbuilder (@) { foreach my $f ($q->param("attachment_select")) { $f=Encode::decode_utf8($f); $f=~s/^$page\///; - $add.="[[$f]]\n"; + if (IkiWiki::isinlinableimage($f) && + UNIVERSAL::can("IkiWiki::Plugin::img", "import")) { + $add.='[[!img '.$f.' align="right" size="" alt=""]]'; + } + else { + $add.="[[$f]]"; + } + $add.="\n"; } $form->field(name => 'editcontent', value => $form->field('editcontent')."\n\n".$add, @@ -225,12 +238,11 @@ sub attachment_list ($) { my @ret; foreach my $f (values %pagesources) { if (! defined pagetype($f) && - $f=~m/^\Q$loc\E[^\/]+$/ && - -e "$config{srcdir}/$f") { + $f=~m/^\Q$loc\E[^\/]+$/) { push @ret, { "field-select" => '', link => htmllink($page, $page, $f, noimageinline => 1), - size => IkiWiki::Plugin::filecheck::humansize((stat(_))[7]), + size => IkiWiki::Plugin::filecheck::humansize((stat($f))[7]), mtime => displaytime($IkiWiki::pagemtime{$f}), mtime_raw => $IkiWiki::pagemtime{$f}, };