Permalink
Browse files

Item1918: confuse everythig before cleanup. Still work in progress

git-svn-id: http://svn.foswiki.org/trunk/TagsPlugin@6083 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information...
1 parent d3356f6 commit d5bc4d3a44cba09cae39934a3ef616215860df83 @1977er 1977er committed Jan 18, 2010
@@ -1,15 +1,21 @@
-%META:TOPICINFO{author="BaseUserMapping_333" date="1253875512" format="1.1" version="1.9"}%
+%META:TOPICINFO{author="BaseUserMapping_333" date="1263789345" format="1.1" reprev="1.54" version="1.54"}%
%META:TOPICPARENT{name="TagsPlugin"}%
<!--
* Set TAGNAME = %URLPARAM{"tag" default="undef" encode="safe"}%
+ * Set TAGNAMEURL = %URLPARAM{"tag" default="undef" encode="url"}%
* Set TAGUSER = %URLPARAM{"taguser" default="undef" encode="safe"}%
* Set TAGWEB = %URLPARAM{"tagweb" default="undef" encode="safe"}%
* Set TAGTOPIC = %URLPARAM{"tagtopic" default="undef" encode="safe"}%
+ * Set TAGITEM = %TAGWEB%.%TAGTOPIC%
+ * Set TRASH = %ICON{"trash"}%
+ * Set PENCIL = %ICON{"pencil"}%
+ * Set LOCK = %ICON{"lock"}%
+ * Set SITETREE = %ICON{"sitetree"}%
-->
<div style="text-align:left;">
<noautolink>
----+++ %MAKETEXT{"Topics, tagged with this tag"}%
+
%TAGCLOUD{
terms="$percntTAGSEARCH{ query=\"topic\" tag=\"$percntTAGNAME$percnt\" format=\"$item:1:$web:$topic:$user\" }$percnt"
split="[,]"
@@ -19,24 +25,50 @@
warn="off"
}%
----+++ %MAKETEXT{"Users, who like this tag"}%
-%TAGCLOUD{
- terms="$percntTAGSEARCH{ query=\"user\" tag=\"$percntTAGNAME$percnt\" format=\"$user:1:$web:$topic\" }$percnt"
- header="<div style=\"text-align:center; padding:15px;line-height:180%\">"
- format="<span style='font-size:$weightpx;line-height:90%'><a href='$percntSCRIPTURL{view}$percnt/$percntUSERSWEB$percnt/$term' style='color:$fadeRGB(104,144,184,0,102,255);text-decoration:none' title='$count'>$term</a></span>"
- footer="</div>"
- warn="off"
-}%
-
+%TAGSEARCH{
+ query="user"
+ tag="%TAGNAME%"
+ web="%TAGWEB%"
+ topic="%TAGTOPIC%"
+ public="public"
+ format="$percntTRASH$percnt <a href='%SCRIPTURL{rest}%/TagsPlugin/untag?tag=%TAGNAMEURL%&item=$item&user=$user' class='tagsplugin_untag_link' tag='$tag' item='$item' user='$user'>Remove</a> public <span class='foswikiGrayText'>$tag</span>"
+ sep=" %BR% "
+ footer="%BR%"
+}%
%TAGSEARCH{
query="user"
tag="%TAGNAME%"
web="%TAGWEB%"
topic="%TAGTOPIC%"
- header="---+++ %MAKETEXT{"Maintain this tag"}%$n"
- format="<a href='%SCRIPTURL{rest}%/TagsPlugin/untag?tag=$tag&item=$item&user=$user' class='tagsplugin_untag_link' tag='$tag' item='$item' user='$user'>Remove</a> $percntIF{$quot'$public'='tagsplugin_public'$quot else=\"$user's\" then=\"public\"}$percnt <span class='foswikiGrayText'>$tag</span> tag from this topic."
+ public="private"
+ user="%WIKINAME%"
+ format="$percntTRASH$percnt <a href='%SCRIPTURL{rest}%/TagsPlugin/untag?tag=%TAGNAMEURL%&item=$item&user=$user' class='tagsplugin_untag_link' tag='$tag' item='$item' user='$user'>Remove</a> $user's <span class='foswikiGrayText'>$tag</span>"
sep=" %BR% "
-}%
+ footer="%BR%"
+}%
+%TAGSEARCH{
+ query="user"
+ tag="%TAGNAME%"
+ web="%TAGWEB%"
+ topic="%TAGTOPIC%"
+ public="public"
+ format="$percntLOCK$percnt <a href='%SCRIPTURL{rest}%/TagsPlugin/public?tag=%TAGNAMEURL%&item=$item&user=$user&redirectto=$item&public=0' class='tagsplugin_public_link' tag='$tag' item='$item' user='$user'>Flag this tag as non-public</a>"
+ sep=" %BR% "
+ footer="%BR%"
+}%
+%TAGSEARCH{
+ query="user"
+ tag="%TAGNAME%"
+ web="%TAGWEB%"
+ topic="%TAGTOPIC%"
+ public="private"
+ user="%WIKINAME%"
+ format="$percntLOCK$percnt <a href='%SCRIPTURL{rest}%/TagsPlugin/public?tag=%TAGNAMEURL%&item=$item&user=$user&redirectto=$item&public=1' class='tagsplugin_public_link' tag='$tag' item='$item' user='$user'>Flag this tag as public</a>"
+ sep=" %BR% "
+ footer="%BR%"
+}%
+%IF{ "'%ISTAGADMIN%'='1'" then="$percntSITETREE$percnt <a href='%SCRIPTURL{view}%/%SYSTEMWEB%.TagsPluginTagMerge?tag=%TAGNAMEURL%&redirectto=%TAGWEB%.%TAGTOPIC%'>Merge</a> this tag with another tag" }% %BR%
+%IF{ "'%ISTAGADMIN%'='1'" then="$percntPENCIL$percnt <a href='%SCRIPTURL{view}%/%SYSTEMWEB%.TagsPluginTagRename?tag=%TAGNAMEURL%&redirectto=%TAGWEB%.%TAGTOPIC%'>Rename</a> this tag" }%
</noautolink>
</div>
@@ -1,9 +1,19 @@
-%META:TOPICINFO{author="BaseUserMapping_333" date="1253480019" format="1.1" reprev="1.14" version="1.14"}%
+%META:TOPICINFO{author="BaseUserMapping_333" date="1263482161" format="1.1" version="1.22"}%
%META:TOPICPARENT{name="TagsPlugin"}%
%TAGSEARCH{
query="tag"
web="%URLPARAM{"tagweb" default="%TAGWEB%"}%"
topic="%URLPARAM{"tagtopic" default="%TAGTOPIC%" }%"
- format=" <li class='tagsplugin_tag $public'><a class='tagsplugin_tag_link' href='%SCRIPTURL{view}%/%SYSTEMWEB%/TagsPluginTagDetails?tag=$tag' tag='$tag' web='$web' topic='$topic'>$percntICON{tag}$percnt $tag</a></li>"
+ user="%WIKINAME%"
+ public="private"
+ format=" <li class='tagsplugin_tag'><a class='tagsplugin_tag_link' href='%SCRIPTURL{view}%/%SYSTEMWEB%/TagsPluginTagDetails?tag=$tag' tag='$tag' web='$web' topic='$topic'>$percntICON{tag}$percnt $tag</a></li>"
sep="$n"
}%
+%TAGSEARCH{
+ query="tag"
+ web="%URLPARAM{"tagweb" default="%TAGWEB%"}%"
+ topic="%URLPARAM{"tagtopic" default="%TAGTOPIC%" }%"
+ public="public"
+ format=" <li class='tagsplugin_tag $public'><a class='tagsplugin_tag_link' href='%SCRIPTURL{view}%/%SYSTEMWEB%/TagsPluginTagDetails?tag=$tag' tag='$tag' web='$web' topic='$topic'>$percntICON{tag}$percnt $tag</a></li>"
+ sep="$n"
+}%
@@ -0,0 +1,20 @@
+%META:TOPICINFO{author="BaseUserMapping_333" date="1263790531" format="1.1" reprev="1.2" version="1.2"}%
+%META:TOPICPARENT{name="TagsPlugin"}%
+<!--
+ * Set TAGNAME = %URLPARAM{"tag" default="undef" encode="safe"}%
+ * Set TARGET = %URLPARAM{"redirectto" default="%MAINWEB%.%HOMETOPIC%" encode="safe"}%
+-->
+<form name="foswikiTagsPluginMerge" action="%SCRIPTURL{rest}%/TagsPlugin/merge" method="get">
+ <input type="hidden" name="redirectto" value="%TARGET%" />
+ <input type="hidden" name="tag2" value="%TAGNAME%" />
+ Merge %ICON{"tag"}% <span class='foswikiGrayText'>%TAGNAME%</span> into the resulting tag <select name="tag1">
+%TAGSEARCH{
+ query="tag"
+ format=" <option value='$percntENCODE{\"$tag\" type=\"safe\"}$percnt'>$tag</option>"
+ sep="$n"
+}%
+ </select>
+ <input type="submit" value="Merge" class="foswikiSubmit" />
+</form>
+
+%META:PREFERENCE{name="VIEW_TEMPLATE" title="VIEW_TEMPLATE" type="Local" value="System.TagsPluginNoHeaderViewTemplate"}%
@@ -0,0 +1,14 @@
+%META:TOPICINFO{author="BaseUserMapping_333" date="1263789574" format="1.1" reprev="1.11" version="1.11"}%
+%META:TOPICPARENT{name="TagsPlugin"}%
+<!--
+ * Set TAGNAME = %URLPARAM{"tag" default="undef" encode="safe"}%
+ * Set TARGET = %URLPARAM{"redirectto" default="%MAINWEB%.%HOMETOPIC%" encode="safe"}%
+-->
+<form name="foswikiTagsPluginRename" action="%SCRIPTURL{rest}%/TagsPlugin/rename" method="get">
+ <input type="hidden" name="redirectto" value="%TARGET%" />
+ <input type="hidden" name="oldtag" value="%TAGNAME%" />
+ Rename %ICON{"tag"}% <span class='foswikiGrayText'>%TAGNAME%</span> to <input type="text" name="newtag" size="50" />.<br />
+ <input type="submit" value="Rename" class="foswikiSubmit" />
+</form>
+
+%META:PREFERENCE{name="VIEW_TEMPLATE" title="VIEW_TEMPLATE" type="Local" value="System.TagsPluginNoHeaderViewTemplate"}%
@@ -65,11 +65,12 @@ sub initPlugin {
Foswiki::Func::registerTagHandler( 'ISTAGADMIN', \&_ISTAGADMIN );
Foswiki::Func::registerTagHandler( 'TAGREQUIRE', \&_TAGREQUIRE );
- Foswiki::Func::registerRESTHandler( 'tag', \&tagCall );
- Foswiki::Func::registerRESTHandler( 'untag', \&untagCall );
- Foswiki::Func::registerRESTHandler( 'delete', \&deleteCall );
- Foswiki::Func::registerRESTHandler( 'rename', \&renameCall );
- Foswiki::Func::registerRESTHandler( 'merge', \&mergeCall );
+ Foswiki::Func::registerRESTHandler( 'tag', \&tagCall );
+ Foswiki::Func::registerRESTHandler( 'untag', \&untagCall );
+ Foswiki::Func::registerRESTHandler( 'public', \&publicCall );
+ Foswiki::Func::registerRESTHandler( 'delete', \&deleteCall );
+ Foswiki::Func::registerRESTHandler( 'rename', \&renameCall );
+ Foswiki::Func::registerRESTHandler( 'merge', \&mergeCall );
Foswiki::Func::registerRESTHandler( 'initialiseDatabase', \&initialiseDatabase );
Foswiki::Func::registerRESTHandler( 'convertDatabase', \&convertDatabase );
Foswiki::Func::registerRESTHandler( 'importTagMe', \&importTagMe );
@@ -446,6 +447,42 @@ sub untagCall {
return Foswiki::Plugins::TagsPlugin::Untag::rest( @_ );
}
+=pod
+
+---++ publicCall($session) -> $text
+
+This is the REST wrapper for public.
+
+Takes the following url parameters:
+ item : name of the topic (format: Sandbox.TestTopic)
+ tag : name of the tag
+ user : (Optional) Wikiname of the user or group (format: JoeDoe), defaults to current user
+ public : (Optional) Sets or unsets the public flag (values: "0" or "1")
+
+If "user" is a groupname, the currently logged in user has to be member of that group.
+
+It checks the prerequisites and sets the following status codes:
+ 200 : Ok
+ 400 : url parameter(s) are missing or empty
+ 401 : access denied for unauthorized user
+ 403 : the user is not allowed to to change the public flag
+
+Return:
+In case of an error (!=200 ) just the status code incl. short description is returned.
+Otherwise a 200 is returned.
+
+TODO:
+ force http POST method
+
+Sets public flag for a given topic/tag/user tupel. Quits silently if nothing to do.
+
+=cut
+
+sub publicCall {
+ use Foswiki::Plugins::TagsPlugin::Public;
+ return Foswiki::Plugins::TagsPlugin::Public::rest( @_ );
+}
+
=begin TML
@@ -43,7 +43,10 @@ sub rest {
require Unicode::MapUTF8;
$tag_text = Unicode::MapUTF8::from_utf8( { -string => $tag_text, -charset => $charset } );
$redirectto = Unicode::MapUTF8::from_utf8( { -string => $redirectto, -charset => $charset } );
-
+
+ # sanatize the tag_text
+ use Foswiki::Plugins::TagsPlugin::Func;
+ $tag_text = Foswiki::Plugins::TagsPlugin::Func::normalizeTagname( $tag_text );
#
# checking prerequisites
@@ -104,6 +107,8 @@ Takes the following parameters:
This routine does not check any prerequisites and/or priviledges. It returns 0, if
the given tag_text was not found.
+Note: Only use normalized tagnames!
+
Return:
number of affected tags in the format "n+m" with n as the number of tags and m as the number of (user) tag instances.
=cut
@@ -0,0 +1,45 @@
+# This script Copyright (c) 2010 Oliver Krueger, (wiki-one.net)
+# and distributed under the GPL (see below)
+#
+# 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
+#
+# Author(s): Oliver Krueger
+
+package Foswiki::Plugins::TagsPlugin::Func;
+
+use strict;
+use warnings;
+use Error qw(:try);
+
+use constant DEBUG => 0; # toggle me
+
+=begin TML
+
+---++ normalizeTagname( $tag_text )
+Replaces <, >, ' and " with html entities.
+
+=cut
+
+sub normalizeTagname {
+ my $tag_text = $_[0];
+
+ # sanatize the tag_text
+ # $tag_text =~ s/&/&amp;/g;
+ $tag_text =~ s/</&#60;/g;
+ $tag_text =~ s/>/&#62;/g;
+ $tag_text =~ s/'/&#39;/g;
+ $tag_text =~ s/"/&#34;/g;
+
+ return $tag_text;
+}
+
+1;
@@ -20,7 +20,7 @@ use strict;
use warnings;
use Error qw(:try);
-use constant DEBUG => 1; # toggle me
+use constant DEBUG => 0; # toggle me
=begin TML
@@ -55,18 +55,8 @@ sub rest {
=begin TML
----++ do( $tag_old, $tag_new )
-This does untagging.
+---++ do( )
-Takes the following parameters:
- tag_old : name of tag to be renamed
- tag_new : new name for the old tag
-
-This routine does not check any prerequisites and/or priviledges. It returns 0, if
-the old tagname was not found or the new tagname already exists.
-
-Return:
- number of affected tags.
=cut
sub do {
@@ -75,6 +65,8 @@ sub do {
Foswiki::Func::writeDebug("TagsPlugin:TagMe-Import:Start") if DEBUG;
+ use Foswiki::Plugins::TagsPlugin::Func;
+
$public = $public ? "1" : "0";
my $lineRegex = "^0*([0-9]+), ([^,]+), (.*)";
@@ -98,7 +90,7 @@ sub do {
foreach my $line ( @tagInfo ) {
if ( $line =~ /$lineRegex/ ) {
my $num = $1;
- my $tag = $2;
+ my $tag = Foswiki::Plugins::TagsPlugin::Func::normalizeTagname( $2 );
my @users = split( /,\s*/, $3 );
foreach my $user ( @users ) {
my $user_id = Foswiki::Plugins::TagsPlugin::getUserId( Foswiki::Func::getCanonicalUserID( $user ) );
@@ -10,6 +10,8 @@ data/System/TagsPluginTagCloud.txt 0644 Topic
data/System/TagsPluginTagDetails.txt Topic
data/System/TagsPluginTagDetailsSimple.txt Topic
data/System/TagsPluginTagDetailsAdmin.txt Topic
+data/System/TagsPluginTagRename.txt Topic
+data/System/TagsPluginTagMerge.txt Topic
data/System/TagsPluginUserSelector.txt Topic
data/System/TagsPluginWebSelector.txt Topic
data/System/VarTAGSEARCH.txt 0644 Documentation
@@ -47,7 +47,11 @@ sub rest {
$tag1 = Unicode::MapUTF8::from_utf8( { -string => $tag1, -charset => $charset } );
$tag2 = Unicode::MapUTF8::from_utf8( { -string => $tag2, -charset => $charset } );
$redirectto = Unicode::MapUTF8::from_utf8( { -string => $redirectto, -charset => $charset } );
-
+
+ # sanatize the tag_text
+ use Foswiki::Plugins::TagsPlugin::Func;
+ $tag1 = Foswiki::Plugins::TagsPlugin::Func::normalizeTagname( $tag1 );
+ $tag2 = Foswiki::Plugins::TagsPlugin::Func::normalizeTagname( $tag2 );
#
# checking prerequisites
@@ -98,7 +102,9 @@ sub rest {
# redirect on request
if ( $redirectto ) {
- Foswiki::Func::redirectCgiQuery( undef, $redirectto );
+ my ($rweb, $rtopic) = Foswiki::Func::normalizeWebTopicName( undef, $redirectto );
+ my $url = Foswiki::Func::getScriptUrl( $rweb, $rtopic, "view" );
+ Foswiki::Func::redirectCgiQuery( undef, $url );
}
return $retval;
@@ -117,6 +123,8 @@ Takes the following parameters:
This routine does not check any prerequisites and/or priviledges. It returns 0, if
tag1 or tag2 was not found.
+Note: Only use normalized tagnames!
+
Return:
0 on failure, any other positive number on success.
=cut
@@ -130,6 +138,7 @@ sub do {
my $tag_id1;
my $statement = sprintf( 'SELECT %s from %s WHERE binary %s = ? AND %s = ?',
qw( item_id Items item_name item_type) );
+ Foswiki::Func::writeDebug("$statement, $tag1, tag") if DEBUG;
my $arrayRef = $db->dbSelect( $statement, $tag1, 'tag' );
if ( defined( $arrayRef->[0][0] ) ) {
$tag_id1 = $arrayRef->[0][0];
@@ -143,6 +152,7 @@ sub do {
my $tag_id2;
$statement = sprintf( 'SELECT %s from %s WHERE binary %s = ? AND %s = ?',
qw( item_id Items item_name item_type) );
+ Foswiki::Func::writeDebug("$statement, $tag2, tag") if DEBUG;
$arrayRef = $db->dbSelect( $statement, $tag2, 'tag' );
if ( defined( $arrayRef->[0][0] ) ) {
$tag_id2 = $arrayRef->[0][0];
@@ -172,7 +182,7 @@ sub do {
my $modified = $db->dbDelete( $statement, $tag_id2 );
Foswiki::Func::writeDebug("Merge: $statement; ($tag_id2) -> $modified") if DEBUG;
if ( $modified eq "0E0" ) {
- throw Error::Simple("Database error: failed to clean up after the merge.", 4);
+ # throw Error::Simple("Database error: failed to clean up after the merge.", 4);
};
# update stats in TagStat (rebuild it actually)
Oops, something went wrong.

0 comments on commit d5bc4d3

Please sign in to comment.