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.

Array
(
    [post_max_size] => 64M
    [$_POST keys] => 
    [$_REQUEST keys] => n
    [$_SERVER] => Array
        (
            [CONTEXT_DOCUMENT_ROOT] => /home/pmwiki/public_html
            [CONTEXT_PREFIX] => 
            [DOCUMENT_ROOT] => /home/pmwiki/public_html
            [GATEWAY_INTERFACE] => CGI/1.1
            [HTTPS] => on
            [HTTP_ACCEPT] => */*
            [HTTP_ACCEPT_ENCODING] => gzip, br, zstd, deflate
            [HTTP_HOST] => www.pmwiki.org
            [HTTP_REFERER] => http://www.pmwiki.org/wiki/Cookbook/Rating2
            [HTTP_USER_AGENT] => Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
            [HTTP_X_HTTPS] => 1
            [PATH] => /bin:/usr/bin
            [PHP_INI_SCAN_DIR] => /opt/cpanel/ea-php70/root/etc:/opt/cpanel/ea-php70/root/etc/php.d:.
            [QUERY_STRING] => n=Cookbook%2fRating2
            [REDIRECT_HTTPS] => on
            [REDIRECT_QUERY_STRING] => n=Cookbook%2fRating2
            [REDIRECT_SCRIPT_URI] => https://www.pmwiki.org/wiki/Cookbook/Rating2
            [REDIRECT_SCRIPT_URL] => /wiki/Cookbook/Rating2
            [REDIRECT_SSL_TLS_SNI] => www.pmwiki.org
            [REDIRECT_STATUS] => 200
            [REDIRECT_UNIQUE_ID] => afJXNMklNFMZF1ZJpJ-zewAAAYI
            [REDIRECT_URL] => /wiki/Cookbook/Rating2
            [REMOTE_ADDR] => 216.73.216.31
            [REMOTE_PORT] => 33435
            [REQUEST_METHOD] => GET
            [REQUEST_SCHEME] => https
            [REQUEST_URI] => /wiki/Cookbook/Rating2
            [SCRIPT_FILENAME] => /home/pmwiki/public_html/index.php
            [SCRIPT_NAME] => /index.php
            [SCRIPT_URI] => https://www.pmwiki.org/wiki/Cookbook/Rating2
            [SCRIPT_URL] => /wiki/Cookbook/Rating2
            [SERVER_ADDR] => 23.254.203.248
            [SERVER_ADMIN] => webmaster@pmwiki.org
            [SERVER_NAME] => www.pmwiki.org
            [SERVER_PORT] => 443
            [SERVER_PROTOCOL] => HTTP/1.1
            [SERVER_SIGNATURE] => 
            [SERVER_SOFTWARE] => Apache
            [SSL_TLS_SNI] => www.pmwiki.org
            [TZ] => America/Los_Angeles
            [UNIQUE_ID] => afJXNMklNFMZF1ZJpJ-zewAAAYI
            [PHP_SELF] => /index.php
            [REQUEST_TIME_FLOAT] => 1777489716.4671
            [REQUEST_TIME] => 1777489716
            [argv] => Array
                (
                    [0] => n=Cookbook%2fRating2
                )

            [argc] => 1
        )

)