Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://svn.foswiki.org/trunk/TopicInteractionPlugin@10383 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
- Loading branch information
MichaelDaum
authored and
MichaelDaum
committed
Dec 22, 2010
0 parents
commit 615a123
Showing
50 changed files
with
9,160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
---+!! %TOPIC% | ||
%SHORTDESCRIPTION% | ||
|
||
%TOC% | ||
|
||
---++ Usage | ||
|
||
---++ Syntax | ||
|
||
---+++ ATTACHMENTS | ||
List all attachments of a given topic. Without any parameters it displays a | ||
table of attachments similar to the one generated by the templates at the bottom | ||
of a topic. There are a couple of parameters that take regular expressions to | ||
limit the number of attachments to be listed. | ||
|
||
*Syntax:* | ||
| *%<nop>ATTACHMENTS%, %<nop>ATTACHMENTS{"<topic>" ...}* || | ||
| ="<topic>"= | topic whos attachments we want to query | | ||
| =attr="..."= | match the attachments' attribute | | ||
| =autoattached="yes,no,undef"= | limit attachments to those that are (not) autoattached | | ||
| =comment="..."= | match the attachments' comment | | ||
| =maxdate="..."= | specify latest attachment | | ||
| =maxsize="..."= | specify biggest attachment | | ||
| =mindate="..."= | specify earliest attachment | | ||
| =minsize="..."= | specify smallest attachment | | ||
| =names="..."= | match the name of attachments to be include in the list | | ||
| =user="..."= | match the attachments' user who uploaded it | | ||
| =footer="..."= | format string appended to the result | | ||
| =format="..."= | how to format each attachment | | ||
| =header="..."= | format string prefixing the resulting output | | ||
| =separator="..."= | format string put between each formatted attachment | | ||
| =hidenull="on,off"= | hide/display the empty result; only the header and the footer are included \ | ||
if set to "off" and there's no attachment at the given topic | | ||
| =sort="name,date,size,user,comment,comment:name"= | sort results by specified field | | ||
| =reverse="on/off"= | enable reverse sorting | | ||
| =limit="..."= | limit the number of attachments to the given number; by default show all | | ||
|
||
The following variables can be used in the format parameter: | ||
* $attr: the attributes | ||
* $autoattached: the autoattach flag | ||
* $comment: the comment field | ||
* $date(<format>): the attachment date using <format> to format the date | ||
* $date: the attachment date | ||
* $delete: the action to delete the current attachment | ||
* $deleteUrl: the url used in the delete action | ||
* $icon: img tag representing the filetype | ||
* $iconUrl: the url pointing to the icon used in the img tag | ||
* $index: the position index of the attachment in the result | ||
* $move: the action to move the current attachment | ||
* $moveUrl: the url used in the move action | ||
* $name: the name of the attachment | ||
* $path: the path property of the attachment | ||
* $props: the action to change the properties of the current attachment | ||
* $propsUrl: the url used in the props action | ||
* $size: the size in bytes | ||
* $sizeK: the size in kilo bytes | ||
* $sizeM: the size in mega bytes | ||
* $topic: the name of the topic of whose attachments are listed | ||
* $type: the file type of the current attachment | ||
* $url: the attachments url | ||
* $urlpath: the attachments urlpath | ||
* $user: the user that uploaded the attachment | ||
* $web: the web name of the current topic | ||
* $webdav: the action to edit the current attachment using the Foswiki:Extensions/WebDavPlugin | ||
* $webdavUrl: the url used in the webdav action | ||
* $wikiuser: the user's home topic that recently changed the current attachment | ||
|
||
The header and footer format strings may only contain | ||
* $count: the number of attachments found | ||
|
||
The format, header and footer may contain the standard escape sequences: | ||
* $dollar: $ sign | ||
* $n: newline | ||
* $percnt: % sign | ||
* $quot: " sign | ||
Example: | ||
<verbatim>%ATTACHMENTS{format="| $name: | $type |"}%</verbatim> | ||
generates: | ||
%ATTACHMENTS{format="| $name: | $type |"}% | ||
|
||
---++ Installation Instructions | ||
|
||
%$INSTALL_INSTRUCTIONS% | ||
|
||
---++ Info | ||
<!-- | ||
* Set SHORTDESCRIPTION = %$SHORTDESCRIPTION% | ||
--> | ||
|
||
| Author(s): | Michael Daum| | ||
| Copyright: | © 2010 Michael Daum http://michaeldaumconsulting.com | | ||
| License: | [[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]] | | ||
| Release: | %$RELEASE% | | ||
| Version: | %$VERSION% | | ||
| Change History: | <!-- versions below in reverse order --> | | ||
| Dependencies: | %$DEPENDENCIES% | | ||
| Home page: | Foswiki:Extensions/%TOPIC% | | ||
| Support: | Foswiki:Support/%TOPIC% | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ | ||
# | ||
# Copyright (C) 2009-2010 Michael Daum http://michaeldaumconsulting.com | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details, published at | ||
# http://www.gnu.org/copyleft/gpl.html | ||
|
||
package Foswiki::Plugins::TopicInteractionPlugin; | ||
|
||
use strict; | ||
|
||
our $VERSION = '$Rev: 1340 $'; | ||
our $RELEASE = '2.00'; | ||
our $SHORTDESCRIPTION = 'Improved interaction with attachments and !DataForms'; | ||
our $NO_PREFS_IN_TOPIC = 1; | ||
|
||
use Foswiki::Func (); | ||
use Foswiki::Plugins::JQueryPlugin (); | ||
|
||
############################################################################## | ||
sub initPlugin { | ||
|
||
Foswiki::Func::registerTagHandler('UPLOADFORM', \&handleUPLOADFORM); | ||
Foswiki::Func::registerTagHandler('ATTACHMENTS', \&handleATTACHMENTS); | ||
Foswiki::Func::registerRESTHandler('handle', \&handleRest); | ||
|
||
Foswiki::Plugins::JQueryPlugin::registerPlugin("uploader", 'Foswiki::Plugins::TopicInteractionPlugin::Uploader'); | ||
|
||
return 1; | ||
} | ||
|
||
############################################################################## | ||
sub handleATTACHMENTS { | ||
require Foswiki::Plugins::TopicInteractionPlugin::Attachments; | ||
return Foswiki::Plugins::TopicInteractionPlugin::Attachments::handle(@_); | ||
} | ||
|
||
############################################################################## | ||
sub handleUPLOADFORM { | ||
require Foswiki::Plugins::TopicInteractionPlugin::UploadForm; | ||
return Foswiki::Plugins::TopicInteractionPlugin::UploadForm::handle(@_); | ||
} | ||
|
||
############################################################################## | ||
sub handleRest { | ||
require Foswiki::Plugins::TopicInteractionPlugin::Core; | ||
return Foswiki::Plugins::TopicInteractionPlugin::Core::handleRest(@_); | ||
} | ||
|
||
1; |
89 changes: 89 additions & 0 deletions
89
lib/Foswiki/Plugins/TopicInteractionPlugin/Action/ChangeProperties.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ | ||
# | ||
# Copyright (C) 2010 Michael Daum, http://michaeldaumconsulting.com | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details, published at | ||
# http://www.gnu.org/copyleft/gpl.html | ||
|
||
package Foswiki::Plugins::TopicInteractionPlugin::Action::ChangeProperties; | ||
|
||
use strict; | ||
use warnings; | ||
use Error qw( :try ); | ||
use Foswiki::Func (); | ||
use Foswiki::Plugins::TopicInteractionPlugin::Core (); | ||
|
||
use constant DRY => 0; # toggle me | ||
|
||
sub handle { | ||
my ($response, $params) = @_; | ||
|
||
my $newFileName = $params->{filename}; | ||
my $fileName = $params->{origfilename}; | ||
|
||
($fileName) = Foswiki::Func::sanitizeAttachmentName($fileName); | ||
($newFileName) = Foswiki::Func::sanitizeAttachmentName($newFileName); | ||
|
||
my $web = $params->{web}; | ||
my $topic = $params->{topic}; | ||
my $id = $params->{id}; | ||
|
||
unless (Foswiki::Func::attachmentExists($web, $topic, $fileName)) { | ||
Foswiki::Plugins::TopicInteractionPlugin::Core::printJSONRPC($response, 104, "Attachment $fileName does not exist", $id); | ||
return; | ||
} | ||
|
||
my $fileCreateLink = $params->{createlink} || '0'; | ||
$fileCreateLink = $fileCreateLink eq 'on' ? 1:0; | ||
|
||
my $fileHide = $params->{hidefile}; | ||
$fileHide = 'off' unless defined $fileHide; | ||
$fileHide = $fileHide eq 'on' ? 1:0; | ||
|
||
my $fileComment = $params->{filecomment} || ''; | ||
|
||
Foswiki::Plugins::TopicInteractionPlugin::Core::writeDebug("fileName=$fileName, newFileName=$newFileName, comment=$fileComment, hide=$fileHide, createlink=$fileCreateLink"); | ||
|
||
my $error; | ||
try { | ||
unless (DRY) { | ||
if ($newFileName ne $fileName) { | ||
Foswiki::Func::moveAttachment( | ||
$web, $topic, $fileName, | ||
$web, $topic, $newFileName | ||
); | ||
} | ||
$error = Foswiki::Func::saveAttachment( | ||
$web, $topic, $newFileName, { | ||
name => $newFileName, | ||
attachment => $newFileName, | ||
dontlog => !$Foswiki::cfg{Log}{upload}, | ||
comment => $fileComment, | ||
hide => $fileHide, | ||
createlink => $fileCreateLink, | ||
}); | ||
|
||
} | ||
} catch Error::Simple with { | ||
$error = shift->{-text}; | ||
Foswiki::Plugins::TopicInteractionPlugin::Core::writeDebug("ERROR: $error"); | ||
}; | ||
|
||
if ($error) { | ||
Foswiki::Plugins::TopicInteractionPlugin::Core::printJSONRPC($response, 1, $error, $id) | ||
} else { | ||
Foswiki::Plugins::TopicInteractionPlugin::Core::printJSONRPC($response, 0, undef, $id) | ||
} | ||
} | ||
|
||
1; | ||
|
||
|
61 changes: 61 additions & 0 deletions
61
lib/Foswiki/Plugins/TopicInteractionPlugin/Action/CreateImageGallery.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ | ||
# | ||
# Copyright (C) 2010 Michael Daum, http://michaeldaumconsulting.com | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details, published at | ||
# http://www.gnu.org/copyleft/gpl.html | ||
|
||
package Foswiki::Plugins::TopicInteractionPlugin::Action::CreateImageGallery; | ||
|
||
use strict; | ||
use warnings; | ||
use Error qw( :try ); | ||
use Foswiki::Func (); | ||
use Foswiki::Plugins::TopicInteractionPlugin::Core (); | ||
use constant DRY => 0; # toggle me | ||
|
||
sub handle { | ||
my ($response, $params) = @_; | ||
|
||
my @fileNames = split(/\s*,\s*/, $params->{filename}); | ||
|
||
my $web = $params->{web}; | ||
my $topic = $params->{topic}; | ||
my $id = $params->{id}; | ||
|
||
my ($oopsUrl, $loginName, $unlockTime) = Foswiki::Func::checkTopicEditLock($web, $topic); | ||
if ($unlockTime) { | ||
Foswiki::Plugins::TopicInteractionPlugin::Core::printJSONRPC($response, 105, "Topic is locked by $loginName", $id); | ||
return; | ||
} | ||
my ($meta, $text) = Foswiki::Func::readTopic($web, $topic); | ||
my $format = '%IMAGEGALLERY{include="$pattern"}%'; | ||
my $pattern = '^('.join('|', @fileNames).')$'; | ||
$format =~ s/\$pattern\b/$pattern/g; | ||
$text .= $format."\n"; | ||
|
||
my $error; | ||
try { | ||
Foswiki::Func::saveTopic($web, $topic, undef, $text); | ||
} catch Error::Simple with { | ||
$error = shift->{-text}; | ||
Foswiki::Plugins::TopicInteractionPlugin::Core::writeDebug("ERROR: $error"); | ||
}; | ||
|
||
if ($error) { | ||
Foswiki::Plugins::TopicInteractionPlugin::Core::printJSONRPC($response, 1, $error, $id); | ||
} else { | ||
Foswiki::Plugins::TopicInteractionPlugin::Core::printJSONRPC($response, 0, undef, $id) | ||
} | ||
} | ||
|
||
1; | ||
|
84 changes: 84 additions & 0 deletions
84
lib/Foswiki/Plugins/TopicInteractionPlugin/Action/CreateLinks.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ | ||
# | ||
# Copyright (C) 2010 Michael Daum, http://michaeldaumconsulting.com | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details, published at | ||
# http://www.gnu.org/copyleft/gpl.html | ||
|
||
package Foswiki::Plugins::TopicInteractionPlugin::Action::CreateLinks; | ||
|
||
use strict; | ||
use warnings; | ||
use Error qw( :try ); | ||
use Foswiki::Plugins::DBCachePlugin (); | ||
use Foswiki::Plugins::TopicInteractionPlugin::Core (); | ||
use constant DRY => 0; # toggle me | ||
|
||
sub handle { | ||
my ($response, $params) = @_; | ||
|
||
my @fileNames = split(/\s*,\s*/, $params->{filename}); | ||
|
||
my $web = $params->{web}; | ||
my $topic = $params->{topic}; | ||
my $id = $params->{id}; | ||
|
||
# disable dbcache handler during loop | ||
Foswiki::Plugins::DBCachePlugin::disableRenameHandler(); | ||
|
||
my $error; | ||
foreach my $fileName (@fileNames) { | ||
($fileName) = Foswiki::Sandbox::sanitizeAttachmentName($fileName); | ||
|
||
if (!Foswiki::Func::attachmentExists($web, $topic, $fileName)) { | ||
Foswiki::Plugins::TopicInteractionPlugin::Core::printJSONRPC($response, 104, "Attachment $fileName does not exist", $id); | ||
last; | ||
} | ||
|
||
Foswiki::Plugins::TopicInteractionPlugin::Core::writeDebug("createlink fileName=$fileName, web=$web, topic=$topic"); | ||
|
||
my ($meta, $text) = Foswiki::Func::readTopic($web, $topic); | ||
my $prevAttachment = $meta->get('FILEATTACHMENT', $fileName); | ||
my $prevHide = ($prevAttachment && $prevAttachment->{attr} =~ /h/)?1:0; | ||
|
||
try { | ||
unless (DRY) { | ||
$error = Foswiki::Func::saveAttachment( | ||
$web, $topic, $fileName, { | ||
dontlog => !$Foswiki::cfg{Log}{upload}, | ||
hide => $prevHide, # SMELL: we need to ship the prev hide flag as it gets nulled otherwise | ||
createlink => 1, | ||
}); | ||
|
||
} | ||
} catch Error::Simple with { | ||
$error = shift->{-text}; | ||
Foswiki::Plugins::TopicInteractionPlugin::Core::writeDebug("ERROR: $error"); | ||
}; | ||
|
||
last if $error; | ||
} | ||
|
||
# enabling dbcache handlers again | ||
Foswiki::Plugins::DBCachePlugin::enableRenameHandler(); | ||
|
||
# manually update this topic | ||
Foswiki::Plugins::DBCachePlugin::loadTopic($web, $topic); | ||
|
||
if ($error) { | ||
Foswiki::Plugins::TopicInteractionPlugin::Core::printJSONRPC($response, 1, $error, $id); | ||
} else { | ||
Foswiki::Plugins::TopicInteractionPlugin::Core::printJSONRPC($response, 0, undef, $id) | ||
} | ||
} | ||
|
||
1; | ||
|
Oops, something went wrong.