Rating2

Summary: Even Simpler Page Rating Counter
Version: 20100216
Status: Beta
Maintainer: Petko
Discussion: Rating2-Talk
Users: +1
License: PD

Description

Even Simpler Page Rating Counter.

* {$Rating2}
* {$Rating2count}
* {$Rating2percent} %
* {$Rating2diff}
* {$Rating2pos}
* {$Rating2neg}
* {$Rating2diffpad}
* {$Rating2pos}/{$Rating2count}
  • +4 -2
  • 6
  • 67 %
  • 2
  • 4
  • 2
  • 00002
  • 4/6
  • (+) test -Petko
  • (-) not cool
  • (+) love it
    • (-) hate it
    • (+) not bad
    • (support) this line isn't considered a vote
  • (+) excellent -Dev

Here is yet another recipe attempting to count votes on a page. This is the simplest possible implementation that does the job.

This recipe counts only the "generally positive" comments and the "generally negative" ones. It uses a very simple format, and has highly flexible understanding of what is a positive or a negative vote.

The format is: "asterisk", "(+)" or "(-)", an optional comment, signature. There were propositions to use keywords such as (friend), (endorse), (support) and others, but each of these words carries a meaning that may not be desired by a user who makes a comment. For this reason, the current proposition uses (+) and (-) as indicators for "generally" positive or negative opinions.

The recipe scans the page to count the votes only when it is modified, and the result is stored in a page attribute. This attribute is cached when the page is accessed, and the values are faster to access in pagelists or in external pages.

Installation

  • Copy rating2.phpΔ to your cookbook directory.
  • Add to config.php this line:
    include_once("$FarmD/cookbook/rating2.php");

Usage in a wiki page

The format in a wiki page was discussed in the mailing lists and tries to accommodate all expressed views:

 * (+) Good recipe. --Name (datestamp)
 * (-) Doesn't work for me. --Another Name (datestamp)

To display the rating, use the new Page variable {$Rating2} which outputs something like "+4 -2" :

  • in the current page : {$Rating2} or {*$Rating2}
  • if votes are in another page : {Page-Votes$Rating2}
  • in a pagelist : {=$Rating2}

Other page variables are

  • {$Rating2count} the total number of votes positive+negative,
  • {$Rating2diff} the difference, positive-negative,
  • {$Rating2diffpad} the difference, padded with zeros, to allow easier pagelist sorting, for example (:pagelist order=-$Rating2diffpad:)
  • {$Rating2percent} the ratio positive/total*100

The recipe is enabled on this page, you can edit it and test it.

Notes

  • The recipe will count (++), (+1), (+2) and other as one generally positive vote.

Release Notes

  • 20100216 : added a function for pmwiki.org to automatically save the rating from a *-Users page to a page attribute in the main page and a {$Users} variable. This should require pagelists to open only the recipes, which should be twice as fast.
  • 20100104 : added {$Rating2diffpad} to ease pagelist sorting
  • 20090510 : added {$Rating2pos}, {$Rating2neg}
  • 20090309 : added {$Rating2count}, {$Rating2diff}, {$Rating2percent}
  • 20090307 : first public release

See Also

Contributors

Recipe written by Petko, released into the Public domain.

Comments

See discussion at Rating2-Talk

User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.