create new tag
, view all tags

VotePluginDev Discussion: Page for developer collaboration, enhancement requests, patches and improved versions on VotePlugin contributed by the TWikiCommunity.
• Please let us know what you think of this extension.
• For support, check the existing questions, or ask a new support question in the Support web!
• Please report bugs below

Feedback on VotePlugin

-- MichaelDaum - 07 Mar 2005

Thanks Michael for sharing this Plugin with the community smile

How about measuring and documenting the PluginBenchmarks?

-- PeterThoeny - 08 Mar 2005

Hi, I get the following error when I use the VotePlugin:

"Undefined subroutine &TWiki::normalizeFileName called at /var/www/twiki/lib/TWiki/Plugins/VotePlugin.pm line 344."

When I comment the line out, it works in my FireFox browser - but if I try it in IE, the combo boxes don't size correctly, it only draws a few pixels (about half a letter).

I'm using Twiki bundle TWiki20040902.tar.gz


-- ScottCampbellTwo - 01 Apr 2005

About TWiki::normalizeFileName:
The VotePlugin has been written using the security patches from UncoordinatedSecurityAlert23Feb2005. So you might follow the recommendations there first anyway, Scott.

About the comboxes:
Actually I've got no IE arround for testing. So could you do me a favor and attach a screenshot showing the problem.

-- MichaelDaum - 02 Apr 2005

Thanks for the link, I'll check it out.

Here are the screen shots in IE version 6.0

  • votePlugin1.jpg:

  • votePlugin2.jpg:

-- ScottCampbellTwo - 04 Apr 2005

Try this patch:

@@ -167,7 +167,7 @@
     next if ! $optionNames;

     $result .= "<tr><td><b>$selectName</b>&nbsp;</td>\n";
-    $result .= "<td><select name=\"$selectName\" size=\"1\" style=\"width:90%\">\n";
+    $result .= "<td><select name=\"$selectName\" size=\"1\">\n";
     $result .= "<option selected value=\"\">Select ...</option>\n";

     foreach my $optionName (split /\s?,\s?/,$optionNames) {

-- MichaelDaum - 04 Apr 2005


I applied the security patch so I no longer get the error I was receiveing before.

I also applied the patch above and it displays correctly in IE now.


-- ScottCampbellTwo - 04 Apr 2005

checked .zip into CVS

-- WillNorris - 19 Jul 2005

I added a signature to the Plugin topic; the report on the PluginPackage topic depends on it.

How about measuring and documenting the PluginBenchmarks?

-- PeterThoeny - 23 Aug 2005

Peter, why not extract the plugin author from the plugin info table. Isn't this extra signature redundant?

-- MichaelDaum - 23 Aug 2005

There's a new version v1.10 which runs on dakar now.

-- MichaelDaum - 14 Sep 2005

Hi! I dont want the users to be able to vote once a day, just one vote generally. Is it enough to change line 309 in VotePlugin.pm from

- $host = md5_base64("$ENV{REMOTE_ADDR}$user$date"); 
+ $host = md5_base64("$user"); 

So every registered user can vote only once.

-- TomWolf - 15 Sep 2005

Yes, certainly. Sorry, that there is no configuration switch to do so.

-- MichaelDaum - 15 Sep 2005

Hazzard: The parameters are very sensitive.

  • Using single quotes instead of double quotes breaks things.
  • You can't have something like "...,5% to 10%,..." in the option string. It deens't like the percentage marks.

-- AntonAylward - 05 Oct 2005


-- AntonAylward - 05 Oct 2005

Thanks for the elaborated tests, Anton (btw. your email is broken).

About "Bug in handling of arguments - quotes": single quoted arguments are no proper TWikiML. Although there's a bug in the VotePlugin that prevented to return a proper error message and resulted in displaying nothing.

About "Bug when used with Dakar: vote storage": the VotePlugin will convert Votes*.txt to _Votes*.txt if needed to match the new storage constraints.

More to come.

-- MichaelDaum - 07 Oct 2005

Ok. Released a new version v1.20 today which addresses the reported bugs and feature requests. See also http://ntwiki.ethermage.net/~develop/cgi-bin/view/Bugs/Item580.

-- MichaelDaum - 08 Oct 2005

We have been using Wiki for our organization and there are some problem with this vote plug-in:-
1) There is no option to limit user to vote only once per pool. Although user can�t vote more than once a day, but can do so on different day!

2) There is no option to display voter user and time voted. If at least we can see who have been voted, then we can tell who vote more than once. But so far I couldn�t trace for the voters, not sure if it�s because my Wiki�s authorization level.

3) Perhaps I might not fully understand this functionality. But I could only find one reference document at https://wiki.au.adp.com/wiki/bin/view/TWiki/VotePlugin, which obviously not sufficient.

-- KenBuncharoen - 24 Feb 2006

The extension of VotePlugin is far better than original. But still one problem that it allow voter to vote more than once and it seems not easy to setup.

-- KenBuncharoen - 09 Mar 2006

The VotePlugin does not work in topics with limited read access. When voting in a page where I have read access, I get the following error:

TWiki . OurWeb . OurTopic (oops)     
View Access Denied
You do not have permission to view topic OurWeb.OurTopic.
Contact al_twiki_admin@xxxx if you have any questions.
Related topics: TWikiGroups, TWikiAccessControl
The vote is not counted.

-- PeterHuisken - 27 Mar 2006

Awesome work!! After trying unsuccessfully to get PollPlugin working I switched over to this one. Exactly what i was looking for... funny that searching the plugins database didn't list this at all; but i was fairly tired so I guess i just missed it.

-- DavidWall - 19 Apr 2006

Looks interesting!

The PackageForm and Plugin Info (especially change history) are not updated.

-- JosMaccabiani - 19 Apr 2006

Excellent work! I have one question however. How do I map the syntax of the Vote plugin to a preference variable? I would like to create a preference variable named RANK and I would like to map the entire syntax of the vote plugin to this variable. But the problem is that the vote plugin requires a unique ID.

-- AlokNarula - 08 May 2006

Looking at TagMePlugin, I would like to suggest an improvement to this plugin. I'm using this plugin to capture feedback on TWiki topics. The feedback is captured on a 1-5 scale (1 being least useful and 5 being moset useful). I would like to run a search on all topics who have a rank x, where x is 1 to 5.

-- AlokNarula - 26 Jun 2006

I might be tired and missing something here, but doesn't $host = md5_base64("$ENV{REMOTE_ADDR}$user$date"); allow people to have more than one vote counted if they vote from different IPs (also for different dates)?

-- KarlSkidmore - 09 Jul 2006

Karl, see the TomWolf comment from 15 Sep 2005 for the answer to that question (although, now the line to change is found at #272 of Core.pm

-- KeithHelfrich - 18 Jul 2006

I found that the vote mechanism does not require an authenticated user. So TWikiGuest is allowed to vote if the user hasn't yet logged on.

This means that, even with the one vote per user fix above, one person could always vote twice by voting for himself and then again as TWikiGuest.

I've asked the community for an answer in LogonBeforeFormSubmit.

-- KeithHelfrich - 18 Jul 2006

Thanks to Peter in LogonBeforeFormSubmit, the following directive in your ../twiki/bin/.htaccess would prevent the casual user from voting before logging on.

<Files "vote">
   require valid-user

But the clever user could still logon as TWikiGuest with password guest. Is there a way to update the plugin to prevent this user from voting ?

thanks !

-- KeithHelfrich - 19 Jul 2006

Happily reporting that my users have been voting smile To me an operational voting mechanism really helps people collaborate. Here's a small list of the things I'd like to see this plugin be able to do :

  1. prevent TWikiGuest from casting a vote (even when authenticated w/ password guest)
  2. allow the option for an "open" or "closed" ballotbox
    • if open, then $host = $user;
    • if closed, then $host = md5_base64("$user");
  3. allow for a deadline after which votes can no longer be added or changed

To achieve #3, I manually adjusted the file permissions on the ballotbox file /pub/Web/Topic/_Vote*.txt to make it read only. But doing so results in a fairly ugly Software error the next time someone tries to vote :

cannot append /path/to/twiki/pub/Web/Topic/_Votes_Example.txt at /path/to/twiki/lib/TWiki/Plugins/VotePlugin/Core.pm line 265.

A friendlier oops page, or a "this poll is no longer accepting votes" message, or a javascript disable of the vote button would be much more elegant.

All three of those mods I'm requesting are things I'd be happy to put some time into developing. Except I'm not a programmer and don't know the first bit of Perl. So I would need some help. This could be my first real perl contribution to the TWikiCommunity ( and my first step on a slippery slope? )

Is somebody out there willing to mentor me through making these modifications ? For example, with pointers on where to begin and a code review in case I have trouble ?

-- KeithHelfrich - 04 Aug 2006

I have a couple of feature requests:

  • Be able to display radio buttons instead of a select box
  • Be able to specify the text in the dropdown "Select"
  • Add a link "View results" (and be able to specify this text)
  • Be able to specify if the results are only shown after clicking this link
  • Be able to specify the bar images, or better yet, make this a CSS style
  • Be able to use this as suggestion box, with an freetext input field
  • Be able to show the results in a pop-up window
  • Have CSS classes documented
  • Be able to specify the format of the result table.
    • If one of the keys is a WikiWord, I wouldn't want a link for instance.
  • Be able to display the total number of cast votes
  • As mentioned above: be able to let users vote only once
  • Be able to change the text of the poll without throwing away cast votes

The results table header is redundant if the question is listed above the results.

-- ArthurClemens - 23 Nov 2006

The dependency on CPAN Digest::MD5 is not listed.

This dependency can cause this plugin to not work with hosted twikis. Is it possible to make this functionality optional?

-- ArthurClemens - 23 Nov 2006

I implemented the following:

  • freq parameter allows setting votes to be counted only once
  • anon parameter allows turning off anonymous voting
  • voters style shows voters per key/value pair if anonymous voting is off
  • list style shows a list of votes if anonymous voting is off

Patch attached, you can apply it by standing in the twiki dir and running patch -p0 < VotePlugin-extras.patch

Some comments:

  • Placing the votes in a pub dir allows them to be read by anyone, which in turn allows them to decypher who voted for what.
  • Placing the votes in a pub dir allows anyone to attach a file that contains their set of votes
  • The vote binary doesn't initialize TWiki properly for version 4.0. This makes it fail the allowview test on closed topics. Perhaps the vote binary should instead be implemented as a rest verb, although I can't find any information about that other than the little bit at TWikiScripts#rest .

I think the votes should be placed somewhere in the data dir, in a non-topic. The PollPlugin puts the votes in the same topic, which might or might not be a good idea.

-- WoutMertens - 14 Dec 2006

On storing plugin specific data see TWikiPlugins#Recommended_Storage_of_Plugin_Sp

This plugin is marked as PleaseFeelFreeToModify, so please feel free to create a new package. See ReadmeFirst and PluginsInSubversion.

-- PeterThoeny - 14 Dec 2006

Thank you!! These are some changes we've been waiting for smile I think it would be worthwhile to create a new package because these changes are clearly improvements to the VotePlugin that everyone should enjoy. Some of ArthurClemens' other requests would also be quite useful, as well as preventing the default TWikiGuest user from casting a vote. Thanks again.

-- KeithHelfrich - 15 Dec 2006

Help, this Plugin drives me nuts. Almost nothing works confused and what I'd like to know isn't documented or I don't unterstand it .

  • stars is the only vote-style that works (where something happens when I selecet somthing and where I see a result)

  • For every other style: I don't now how to use them corrctly and I don't see any results and I don't know how to get the results.

  • eg, I just have a select box and if I select an item nothing happens.
    • no submit, no refresh, no results,

here's one of my non-working examples:

%VOTE{id="FruitOfTheMonth" select1="Fruit" options1="Apple,Pineapple,Mango,Orange"}%

applying a style="..." parameter to code above or any other %VOTE{} leads to nothing...

I'd like to fix the docu and add some examples as the given instructions don't help at all - if I only unterstood how this plugin works.

The plugin topic says PLEASE DO NOT EDIT THIS TOPIC. So what do I have to do if i want to fix a typo or add some examples?

-- CarloSchulz - 30 May 2007

Carlo, if you've got a patch, then just attach it here. That's perfectly fine. Or mail it to me.

-- MichaelDaum - 30 May 2007

Michael, I would do so but unfortunately i cant document something thats not working (at least in my environmet)... any ideas what's wrong?

-- CarloSchulz - 30 May 2007

Yes. Working on it.

-- MichaelDaum - 30 May 2007

I've been beavering away in the background, hopefully without breaking compatibility. I have attached my work in progress for comments.

Note that the style parameter has been deprecated in favour of a "TWiki-standard" formatting approach.

-- CrawfordCurrie - 02 Jun 2007

Awesome, just when I needed it you come along and upload a new version smile

I'm taking a look at it now, so far I like the code, it's plenty cleaner than the old code.

Things I'm noticing:

  • Does the new code honor topic permissions when storing/retrieving votes with a defined saveto value?
    • Yes
  • I love the fact that you now allow storing the votes as meta info on a topic
  • The previous code stored the date alongside the vote, even though it wasn't used. I'd like to keep that in there, for administrative use or perhaps historic graphs.
  • The star field will only work on browsers that support javascript and css. Blind users have no way to know how many stars were selected.
    • Correct
  • The "Ok" button is rather small and doesn't look like a standard button. I overlooked it at first. I would prefer it to the right of the form with the standard button look.
  • When you vote a star it works correctly, but if you vote a select box nothing happens until you click "Ok". This is confusing if both types are present in the form.
    • I have made it so that if there is only one item in the vote, then a button isn;t required; otherwise it is.
  • If you click on a star field, and then click "Ok", your star vote is reset to 0 provided the new page view made it through before you clicked "Ok". I think the input field doesn't get the current value.
    • Fixed
  • When you try to reload a page that you just voted on, the browser complains that the page was created with POSTDATA. Would it be possible to let the plugin register the vote and immediately redirect the user to the "regular" view, or, even better, perform the vote using AJAX? See http://engadget.com for an example of such voting in the comments.
    • No. Well, it would be possible, but I'm not going to do it.
  • The aggregation doesn't work for "select" values but does work for "star" values. For example, if you vote twice in a default poll, with differing values for a select box and a star field, the select box will count both votes but the star field will only show one vote, your latest.
  • The plugin depends on voting.js but doesn't have it in the package... * Fixed.
  • Err that's it so far, nice code smile

Longer-standing issues:

  • If the voting is open, people can vote once a day. If it's closed, people can only vote once (even though they can change their vote). Not entirely sure that always makes sense.
    My patch against the previous code added support for choosing the frequency, but that was more to allow single votes. I wonder what the reasoning behind it is. I'm actually having trouble coming up with use cases for other systems than the current setup :-).
  • I also noted that there's no way to show the list of voters per value or a list of all votes per voter. I'd really like to have that, for example when you're trying to find out who wants what when ordering pizza.
  • Vote parameters aren't encoded. If you vote for something with a '|' in it, you'll break the data retrieval
    • (Generally, I wish TWiki had a cleaner metadata storage implementation, with key-value pairs and nested structures. Ah well.)

Final comment, this plugin does almost everything better than PollPlugin, except for the fact that PollPlugin supports other parameter types than select boxes. I'd love to be able to easily add a comment box to polls... (for example to say that the pizza should not have onion) I know that CommentPlugin could be made to do something like it but that's way harder to set up.

Great job so far!

-- WoutMertens - 03 Jun 2007

Thanks for the feedback, Wout, very useful. Comments embedded above. I also added Bayesian averages for rating, though it's a bit clunky to use. New rev attached.

-- CrawfordCurrie - 05 Jun 2007

Crawford, i think you accidentelly attached the zip to the dev topic so I moved it to the plugin topic. I hope thats fine with you

-- CarloSchulz - 06 Jun 2007

I couldn't move it so I attached your version to the plugin topic

-- CarloSchulz - 06 Jun 2007

Hmm, Carlo you are in the TWikiCommunityGroup, so you should be able gto move the attachments.

-- PeterThoeny - 06 Jun 2007

I have located a bug in the latest VotePlugin that is causing percentages to always come out zero. Here's the diff on Core.pm that fixes the problem. It also avoids recopying the keyValuesFreq hash entries. (That works because it already is a hash reference and the showSelect sub doesn't alter the contents)

verbatim7 -- MalcolmDavis - 06 Jun 2007

the ! marks in Malcoms patch caused an error so I removed them. VotePlugin works fine after this so incorperated the patch and attached a new version...

-- CarloSchulz - 07 Jun 2007

Sorry about that. Must have used the wrong flags for diff.

While I am writing, I do have a question. Are there plans for something like the %POLLRESULTS% tag, or is that functionality available in some way that I am missing?

I have been able to get a bit of what I want by creating %VOTE%s with formats which do not include a $prompt for select-type votes or either a $small or $large for star-type votes. However, besides the fact that I can only show numerical results for the star-type votes, I must also include only one key at a time to keep the submit button from being generated. So, I'm hoping for a better solution.

-- MalcolmDavis - 07 Jun 2007

Carlo, I deliberately attached the zip here; I didn't want to publish yet. BTW this plugin is maintained in subversion, so any code changes you make that aren't checked in will be lost the next time it's released. Patching is the best way to propose changes (or get checkin access; see HowCanIContribute).

Malcolm, nice one! Use unified diff (see man diff) to generate patches.

I don't have any plans for a POLLRESULTS. It's a reasonable idea, though. I like your approach, as it leverages what's already there. Blocking the submit button would be easy enough, all we'd need to do would be to block the generation of the form and the button.

-- CrawfordCurrie - 08 Jun 2007

Sorry for that Crawford. I thought it would be a good idea as the former plugin version was broken and yours not.

Off topic: I find this subversion thingy as it appers to me contradicts the wiki nature... see my comment on SoYouWantToBeATWikiDeveloper

-- CarloSchulz - 08 Jun 2007

There's a grey area between "managed development" where it's essential to have fine granularity histories of code changes - a job that subversion is terrific at - versus "wiki development" where you'd like anyone to be able to contribute to the code, any time. Unfortunately the risk of someone screwing up the code (maliciously or otherwise) is too high to allow unconstrained "wiki code editing", at least on this site. This is also why I generate md5 checksums.

Of course that doesn't stop you using it that way in your own environment. I've often thought that collaborative web-based code development (edit the code of the site in the browser, save it, and see what happens) would be an interesting experiment. As long as you had a way to revert to a "last known good" version, it might actually work.

-- CrawfordCurrie - 08 Jun 2007

I just released it, with a new submit parameter to answer Malcolm's requirement.

-- CrawfordCurrie - 08 Jun 2007

Great! Thanks!

-- MalcolmDavis - 09 Jun 2007

  1. When there's only one entry of a poll, it can't seem to generate a proper table markup. Without HTML codes for submit button, the table markup is just followed by ending tag and it prevents correct rendering. I had to modify line 199 of Core.pm to set $needSubmit always 1. Does this happen only to me?
  2. I got the latest version (11 Jun 2007). But it still seems to retain 'zero percentage' bug. Is it fixed?
  3. The default formats in VotePlugin page looks a bit outdated. No $item exists for select format. $myLast should be $mylast and $total be $sum on stars format.

-- KyungdahmYun - 16 Jun 2007

am i right in thinking that TWikiGuest in an open poll counts as 1 user? If so then having TWikiGuest not able to vote more than once pretty much means that an open poll is not much different to an closed poll...right?

-- AdamHyde - 05 Jul 2007

Ok, I did some work on the latest version and I thought I'd report in with my preliminary results. Consider this beta quality. I'll attach just the updated Core.pm since that's all that changed.

Basically I needed the plugin to perform duties as a registration form and I coded up everything I deemed necessary.

  • Supports text, textbox and hidden field types. Use like the select type, for example text1="Comments"
    • The vote display code for text and textbox doesn't yet allow you to list all comments and their authors. As a workaround, use the topicsave attribute.
  • Added selectformat, starsformat and textformat fields that override the default format strings for each type
  • The poll results are now encoded so that "," and "|" and some others don't break the data storage
    • I'm hitting the problem that if you have newlines in your textbox vote string, they will mess up the display of the votes, because I don't know how to embed newlines in a verbatim string in a twiki "|" table. Hints welcome.
  • Added enable attribute that has %IF{}%-type syntax to optionally enable a field. This hides the prompt (and results) from view if the expression evaluates to false.
  • Added desc attribute that can be used as a longhand (or localized) field name. Changed the default templates to have the $desc variable instead of $key. $desc will be replaced with the desc attribute or, if it's missing, the key attribute like before.
  • Added thanks attribute that shows up in front of the vote form if you have voted
    • I'm pondering if it should implement the $form variable so that the user can choose how/where the form shows up with respect to the "thanks" string.
  • Added $vote variable on select and text/textbox types so that you can have a %VOTE% displaying just the results of your vote in a form you like.
  • Can't think of anything else right now...

-- WoutMertens - 12 Jul 2007

Micha remarked to me a while ago "this plugin is getting to be a bit of a monster" … sounds like it just grew another arm wink

Wout, I'm not sure what you mean by a "registration form", but did you consider creating a new type for the CommentPlugin? I created the RatingContrib as a way to support at least ratings (though not selection votes) in comments, since there is a great deal of overlap between CommentPlugin and this plugin.

I suspect you are going to have to get checkin rights to merge this large change into the released version.

-- CrawfordCurrie - 12 Jul 2007

Yes, an extra arm at least wink And checkin rights would be awesome!

I did consider using the commentplugin, but that would convert structured data into a blob of text, without the individual users being able to go back later and look at what they selected or being able to change their choices. Also, the template-based setup is pretty hard to do :-(.


I think that tags, voting, TWikiForms, preferences, comments and so on should be first class TWiki citizens. What is lacking is a proper metadata infrastructure in TWiki.

The above things share a lot of common traits:

  • Structured data consisting of specific types, like users, timestamps, integers, strings, booleans etc.
  • Data tied to specific webs, topics or users (can be abstracted to a topic in each case)
  • The data has semantics that can and should be validated
  • The data shouldn't be visible text but should be presented according to its use. Therefore it should be stored as metadata
  • The data should be fast to query/aggregate

Pretend that TWiki can store metadata efficiently and do instant lookups based on topic (or user topic), including searches on specific metadata keys or values. Pretend as well that the "* Set" entries in topics are also stored as metadata. All traits of a topic are query-able as metadata.


  • The same mechanism that presents a voting form could present a set of user preferences.
  • Topic access rights could be edited and presented consistently while being checked for common errors.
  • Comments would be rendered inside the topic, but with all the features of sites like slashdot.org.
  • Users could be subscribed to mail notifications of topics that they commented on.
  • ...

In other words, a lot of currently-duplicated code would merge, benefiting all these things.


But maybe this should be discussed elsewhere, any idea where?

-- WoutMertens - 13 Jul 2007

I have come across two problems.

Setting the option open="off" inside VOTE breaks the plugin. However setting

has the desired effect.

Percentage is always 0% and so the bar graphs to not expand. I set line 253 as $totalVotes{$key}, $params)); (see above ) . This initially fixed the problem and I had non-zero percentages and a bar. However on reloading the page the percentage returned to zero again.

-- PeterJones - 16 Jul 2007

I'm uses VOTE{... stars1="A" stars2="B" }, and I get see bizarre behaviour. If someone votes for 5 stars on option A, and then I vote for 3 stars on option A, it immediately sets the score to 4 as expected. But when I vote for option B, it updates option B as expected, but also uses the average score of 4 as my vote for option A, and updates the score to 4.5 stars!!! For the option you don't click on, the score becomes your vote! This makes "starN" unusable for anything other than N=1.

-- ArthurNeufeld - 08 Sep 2007

I see the problem. The code is generating the following HTML:

  {input value="2" name="vote_data_A" type="hidden" ... /}
  {small}Score: 2, My vote: 3, Total votes: 2{/small}

The hidden input 'value' should be the 'My vote' value of '3', not the current score of '2'.

-- ArthurNeufeld - 12 Sep 2007

I'm having the same problem as Peter above - all the percentages are coming out as 0, even with the most current version of the plugin.

-- MichelleHedstrom - 20 Sep 2007

The plugin seems to have an issue when using hierarchical webs - looks as the relative path to pub/_work_areas/VorePlugin is only valid for webs at top level.

-- GaryNewman - 12 Nov 2007 Fixed, -- ColasNahaboo - 14 Oct 2008

I have the same use case as ArthurNeufeld, and almost fixed it.

I also think that submitting on each star click when you have multiple is annoying. If anyone else wants to only have the stars submit on change when there is a single item, here's the modification for core.pm line 553:

    if ($submit) {
        if (! $needSubmit) {
            $eAttrs = {
                onChange =>
                "javascript: document.getElementById('$form').submit()" };
        } else {
            $eAttrs = { };

-- ByronIgoe - 20 Dec 2007

It's a simple fix, but it requires a change to RatingContrib as well:

VotePlugin/core.pm line 563: pass $myLast as an additional parameter to renderRating()

RatingContrib.pm line 17: add $myVote as a new parameter to renderRating()

RatingContrib.pm line 35: change $value to $myVote

This makes the default value of the hidden parameters equal to the current users last votes. Thus you can change your vote for one item without having to re-vote for every item in the group.

-- ByronIgoe - 03 Jan 2008

I am using VotePlugin (1.33, $Rev: 14312 (01 Jul 2007) $) on TWiki-4.2.0, Tue, 22 Jan 2008, build 16278, Plugin API version 1.2

It seems the percentage is always 0%. zero.JPG

-- LijiYu - 22 Feb 2008

See also the GenericVote, a simple TWiki application based on a custom CommentPlugin template.

-- PeterThoeny - 02 Mar 2008

I am trying to use this plugin to rate different ideas to allow engineers to influence which should be looked at, and the bayesian ranking seemed like a good way to do this. I setup 3 different pages, with different vote ids (To keep the ratings separate), but the rame stars names to allow bayesian ranking. When setting just global, they just performed like 3 different votes, and when using saveto to put the ratings all in one place, they were all being merged into a single rating, so all pages showed the same information.

I've updated my Core.pm (Patch included below) to perform bayesian filtering, but it requires that saveto is used to put all ratings that you wish to include in the filtering in one file.

--- Core.pm.orig        2008-03-04 08:41:23.000000000 +0000
+++ Core.pm     2008-03-04 08:44:36.000000000 +0000
@@ -167,22 +167,22 @@
     my %totalVoters;  # how many different people voted for each key
     my %totalRate;    # Total of all ratings for each key
     my %items;        # Hash of id's that have the same key
-    my $voteSum = 0;  # Sum of the number of votes on all rated items
-    my $rateSum = 0;  # Sum of all ratings of rated items
+    my %voteSum;      # Sum of the number of votes on all rated items
+    my %rateSum;      # Sum of all ratings of rated items
     foreach my $voter (keys %votes) {
         foreach my $vid (keys %{$votes{$voter}}) {
             foreach my $key (keys %{$votes{$voter}{$vid}}) {
                 my $choice = $votes{$voter}{$vid}{$key}->[0];
                 my $weight = $votes{$voter}{$vid}{$key}->[1];
                 $keyValueFreq{$vid}{$key}{$choice} += $weight;
-                $totalVotes{$key} += $weight;
+                $totalVotes{$key}{$vid} += $weight;
                 $items{$key}{$vid} = 1;
-                $voteSum += $weight;
+                $voteSum{$key} += $weight;
                 if ($choice =~ /^[\d.]+$/) {
-                    $totalRate{$key} += $choice * $weight;
-                    $rateSum += $choice * $weight;
+                    $totalRate{$key}{$vid} += $choice * $weight;
+                    $rateSum{$key} += $choice * $weight;
-                $totalVoters{$key}++;
+                $totalVoters{$key}{$vid}++;
@@ -218,22 +218,22 @@
             # num_votes>0
             # avg_rating: The average rating of each item (again, of those that
             # have num_votes>0)
-            my $avg_num_votes = $numItems ? $voteSum / $numItems : 0;
-            my $avg_rating = $voteSum ? $rateSum / $voteSum : 0;
+            my $avg_num_votes = $numItems ? $voteSum{$key} / $numItems : 0;
+            my $avg_rating = $voteSum{$key} ? $rateSum{$key} / $voteSum{$key} : 0;
             my $myLastVote =
               $votes{getIdent($isSecret, $isOpen)}{$id}{$key}->[0] || 0;
             my $mean = 0;
-            if ($totalVotes{$key}) {
-                $mean = $totalRate{$key} / $totalVotes{$key};
+            if ($totalVotes{$key}{$id}) {
+                $mean = $totalRate{$key}{$id} / $totalVotes{$key}{$id};
                 if ($bayesian) {
                     $mean = ($avg_num_votes * $avg_rating +
-                               $totalVotes{$key} * $mean) /
-                                 ($avg_num_votes + $totalVotes{$key});
+                               $totalVotes{$key}{$id} * $mean) /
+                                 ($avg_num_votes + $totalVotes{$key}{$id});
             push(@rows, showLineOfStars(
                 $id, $prompt, $submit, $needSubmit, $act,
-                $mean, $myLastVote, $totalVoters{$key} || 0));
+                $mean, $myLastVote, $totalVoters{$key}{$id} || 0));
         else {
             my $opts = CGI::option({selected=>'selected',

-- JeffJHarper - 04 Mar 2008

Following on from the patch above, I've made another change to Core.pm to display all ratings within a single saveto file, sorted by the mean.

I also updated the standard ouput line to show the ID and the key, so that you can distinguish between the different ratings. One thing I found useful is that you can use %TOPIC% as the id for a vote, making it possible to create templates with votes.

(The indenting in the attached patch file is somewhat broken, as I put a foreach around a large part of the code, and didn't want the patch to include all the indentation changes)

--- Core.pm.orig2       2008-03-04 09:14:38.000000000 +0000 +++ Core.pm     2008-03-04 13:24:38.000000000 +0000 @@ -169,6 +169,7 @@      my %items;        # Hash of id's that have the same key      my %voteSum;      # Sum of the number of votes on all rated items      my %rateSum;      # Sum of all ratings of rated items +    my %idlist;       # List of Vote id's      foreach my $voter (keys %votes) {          foreach my $vid (keys %{$votes{$voter}}) {              foreach my $key (keys %{$votes{$voter}{$vid}}) { @@ -183,6 +184,7 @@                      $rateSum{$key} += $choice * $weight;                  }                  $totalVoters{$key}{$vid}++; +                $idlist{$vid}++;              }          }      } @@ -206,7 +208,16 @@      # Do we need a submit button?      my $needSubmit = scalar(@prompts) > 1;   +    my @ids; +    if ($id ne "_bay_rank") { +        @ids = ( "$id", ); +    } else { +        @ids = keys(%idlist); +    }      my @rows; +    my $result; +foreach my $sid (@ids) { +$id = $sid;      foreach my $prompt (@prompts) {          my $key = $prompt->{name};          my $row; @@ -231,7 +242,7 @@                                   ($avg_num_votes + $totalVotes{$key}{$id});                  }              } -            push(@rows, showLineOfStars( +            push(@rows, "<$mean>".showLineOfStars(                  $id, $prompt, $submit, $needSubmit, $act,                  $mean, $myLastVote, $totalVoters{$key}{$id} || 0));          } @@ -253,7 +264,8 @@                  $totalVotes{$id}{$key}, $params));          }      } -    my $result = join($separator, @rows); +    $result = join($separator, reverse sort(@rows)); +    $result =~ s/\<[0-9]\.*[0-9]*\>//g;      if ($submit) {          my $hiddens = '';          while (my ($k, $v) = each %hidden) { @@ -269,6 +281,7 @@          }          $result = "$result$separator";      } +}      # Render tables and remove newlines      # so we can embed votes in TWiki tables      $result = TWiki::Func::renderText($result); @@ -542,7 +555,7 @@        $mean = sprintf("%.3g", $mean);      my $row = expandFormattingTokens($prompt->{format}); -    $row =~ s/\$key/$prompt->{name}/g; +    $row =~ s/\$key/$form $prompt->{name}/g;      $row =~ s/\$sum/$total/g;      $row =~ s/\$score/$mean/g;      $row =~ s/\$perc/$perc/g; 

-- JeffJHarper - 04 Mar 2008

I wanted to display the percentage of users that voted in a topic, but couldn't find a "TWiki way" to do that. There is already some code available in UserInfoPlugin to receive the (cleaned) number of TWikiUsers. So to display this relative participation in a vote, I added some code to core.pm (Version 14312, 01 Jul 2007) to get the number of TWikiUsers from UserInfoPlugin(so this change is dependent on it), to do the calculation and to add the formatting token $participation for stars items.

It's my first try in perl, so most probably not the best solution! I didn't test it that much, so take care. But it seems to work for my purpose. smile

In sub ShowLineOfStars, after line

    my $perc = $total ? int(1000 * $mean / $total) / 10 : 0;
I added the following:
    require TWiki::Plugins::UserInfoPlugin;
    my $core = &TWiki::Plugins::UserInfoPlugin::getCore();   
    my $twusers = $core->handleNrUsers(); # get number of TWikiUsers
    my $participation = $total ? int(1000 * $total / $twusers) / 10 : 0; # calc participation in percent

After line:

    $row =~ s/\$mylast/$myLast/g;
I added:
    $row =~ s/\$participation/$participation/g; # add FormattingToken $participation

Any comments and reviews are very welcome!

-- IngoBlickling - 10 Apr 2008

Great plugin! What would be the best way of adding a rating option to every topic of a web? Will it work just to stick the command in the template file for the left bar etc?

-- JonathanManning - 25 Apr 2008

Like others I am having trouble with the zero percent bug and bars not expanding. I think the problem is with $sum. When I included this token in my chart parameter it did not expand but just printed $sum. If this token is used to calculate the percentages and lengths of the bars it may be behaving like null or zero.

-- JimCrum - 02 May 2008

We also had the zero percent bug in the 1 Jul 2007 version of this plugin taken directly from VotePlugin with TWiki 4.2. Further investigation showed that MalcolmDavis's patch of 6 Jun 2007 has only been partially applied.

           push(@rows, showSelect(                 $id, $prompt, $submit, $select, $keyValueFreq{$id}{$key},                 $totalVotes{$id}{$key}, $params)); 
Removing the red marked text near line 253 in Core.pm fixed it.

-- UlfJastrow - 13 May 2008

TWiki version TWiki-4.1.2
VotePlugin Version: 14312 (01 Jul 2007)

"noautolink" does not work for text in starsN="text", this also makes it impossible to vote for the item.
The workaround I use for this is insert <nop> in front of wikiwords.

Every time a star is clicked the page refreshes. This is impractical when the list of items is long. What is the [OK] button at the bottom of the page for? (I expected to be able to click on stars for a number of item followed by a click on the [OK] button.)
Found the fix for this behaviour submitted by ByronIgoe - 20 Dec 2007

Example (raw view)

 id="For Implementation Test" open="off" secret="off" 
 stars1="DFT00008963  DynamicTranscript per slot"
 stars2="DFT00009230  It should be possible when generating a service"
 stars3="DFT00009270  Freeform provisioned attribute configuration"
 stars4="DFT00009393  ApplicationGrammar should be DiagramGrammar"
 stars5="DFT00009420  Remove all static references from code"
 stars6="DFT00009427  ConcatAudio Inflection and Token features"

-- ThomasSchodt - 16 May 2008

$bar(n) seems to have no effect. In the following vote, am I doing the width correctly?

  format="<div>$bar(100) $option $perc% ($score)</div>"}%
No matter what I set the value to, the bars stay the same length.

-- DavidWolfe - 16 Jul 2008

Took the latest voteplugin.tgz and added all my changes again. Would be nice if it could go upstream. I amended the documentation this time. http://www.twiki.org/p/pub/Plugins/VotePluginDev/VotePlugin.tgz

-- WoutMertens - 23 Jul 2008

Note that this patch doesn't include the voter list that was in my previous patch. Sigh. I don't feel like including it now - someone else be my guest.

-- WoutMertens - 23 Jul 2008

Some notes:

  • Using %TOPIC% as the id for a vote is great (making it possible to create templates with votes), thanks to Jeff for recommending that!

  • Removing the red marked text near line 253 in Core.pm, as suggested by UlfJastrow on 13 May 2008, also fixed the zero percent bug in the 1 Jul 2007 version for me too. Thanks!

And some questions:

  • I don't quite understand how to prevent the page from refreshing every time a star is clicked, can someone please summarize how to do that ?

  • When configuring only 5 stars as the max, the graphic shows 6 stars with the last 1 unuseable. How to make the graphic display only 5 ?

  • There should likely be a distinction made between a vote of zero stars versus no vote made. I'm finding that with Bayesian turned on, items that don't have any votes at all yet still get a score of .25, for example, because the Bayesian "pulls them up". Seems that if no votes exist, the value should always remain zero.

Thanks, with just a few tweaks the plugin is working great!

-- KeithHelfrich - 21 Sep 2008

Wout, "would be nice" in this topic doesn't work for me. Please add bug reports to the Bugs web, and attach patches there, if you want anything to go upstream. Keith, what you describe about the width is probably a result of your CSS. There are known problems in the CSS used by NatSkin, for example. Your point about zero stars is a good one; please raise a bug report. I can't remember how the Bayesian computation is done; suggest you read the code (I would have to).

-- CrawfordCurrie - 22 Sep 2008

I've found a new bug which actually prevents votes from being counted: Bugs:Item6020

-- KeithHelfrich - 24 Sep 2008

Does anyone know how to fix Bugs:Item6020 ? I'm finding the plugin to be unuseable, as it is constantly necessary to manipulate the results to add missing newline characters..

-- KeithHelfrich - 05 Oct 2008

Mmm I stumbled on the bug that Gary reported here one year ago but I guess wasnt adressed because of no proper bug report. Here it is, will provide a fix shortly http://develop.twiki.org/~twiki4/cgi-bin/view/Bugs/Item6070

  • Fixed as SVN commits 17635 & 17636

-- ColasNahaboo - 14 Oct 2008

Bugs:Item6020 fixed, commited, attached...

-- ColasNahaboo - 14 Oct 2008

Thanks, Colas.

-- MichaelDaum - 15 Oct 2008

Bugs:Item6125 on the incorrect month issue and Bugs:Item6127 on total votes counting issue have been filed.

-- KyungdahmYun - 18 Nov 2008

This plugin fails with sub-webs.

-- PeterThoeny - 2009-05-16

I just installed Plugin Rev 19292 (2010-07-31) and got the old zero-percentage bug back. As I mentioned on 13 May 2008 (see comment from me above) one has to remove a wrong {$id}. The line in Core.pm is 270 in this revision.

-- UlfJastrow - 2011-03-01

Thanks Ulf, I fixed and updated the plugin. Could you verify that it works now properly?

-- PeterThoeny - 2011-03-02

Did an update via configure and the new version works. Thank you.

-- UlfJastrow - 2011-03-15

Thanks Ulf, the plugin is marked as TWiki-5.0 compatible.

-- PeterThoeny - 2011-03-16

I would like to have a mouseover effect. For example for the following when the mouse is over Documentation, SubjectMatter or Completeness it should show a text box for each with a description. Also similarly when the cursor is over each star. How can I do this?

%VOTE{id="Review" stars1="Documentation" stars2="SubjectMatter" stars3="Completeness"}%

-- RonMascarenhas - 2011-10-31

The VotePlugin needs to be enhanced. You could use jQuery, which supports mouse over popups; TWiki standardized on the JQueryPlugin, so it is safe to use.

-- PeterThoeny - 2011-11-01

It should me mentioned that the select names cannot include commas.

-- AriTrachtenberg - 2012-11-27

Topic attachments
I Attachment History Action Size Date Who Comment
Perl source code filepm Core.pm r1 manage 22.9 K 2007-07-12 - 01:07 WoutMertens Beta Core.pm for features described in my July 12th comment
Unknown file formatpatch VotePlugin-extras.patch r1 manage 9.5 K 2006-12-14 - 18:57 WoutMertens anon, freq, voters, list patch
Compressed Zip archivetgz VotePlugin.tgz r1 manage 22.7 K 2008-07-23 - 01:34 WoutMertens VotePlugin with several new options
Compressed Zip archivezip VotePlugin.zip r2 r1 manage 46.8 K 2007-06-05 - 16:46 CrawfordCurrie Now has Bayesian averages
JPEGjpg votePlugin1.jpg r1 manage 18.9 K 2005-04-04 - 12:57 ScottCampbellTwo  
JPEGjpg votePlugin2.jpg r1 manage 18.5 K 2005-04-04 - 12:58 ScottCampbellTwo  
Unknown file formatJPG zero.JPG r1 manage 28.7 K 2008-02-22 - 01:38 LijiYu Show the "0%" bug.
Edit | Attach | Watch | Print version | History: r99 < r98 < r97 < r96 < r95 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r99 - 2012-11-27 - AriTrachtenberg
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.