WordPress.org

Making WordPress.org

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#551 closed enhancement (fixed)

Voting for Code Reference Examples

Reported by: siobhan Owned by: coffee2code
Milestone: Priority: normal
Component: Developer Hub Keywords:
Cc:

Description

Now that people can add examples, we should make it possible for people to vote up ones that they think are particularly useful.

I suggest that we adopt the approach used by both Stack Exchange and PHP.net, which allows for both upvoting and downvoting.

Stack Exchange:

https://i.cloudup.com/xNtci8-gy3.png

PHP.net

https://i.cloudup.com/MN0qHQ72bK.png

The workflow should be as follows:

Logged in user

  1. User clicks upvote/downvote
  2. Vote counter adjusts accordingly
  3. The example with the most votes should rise to the top, and those with the least should be at the bottom (this could just happen on the next page load)

Logged out user

  1. User clicks upvote/downvote
  2. User is asked to log in to WordPress.org
  3. User logs in
  4. User is redirected back to the location where they were voting
  5. Vote counter adjusts accordingly
  6. The example with the most votes should rise to the top, and those with the least should be at the bottom (this could just happen on the next page load)

Change History (4)

#1 @siobhan
5 years ago

  • Owner set to coffee2code
  • Status changed from new to assigned

#2 @siobhan
5 years ago

  • Cc siobhan added

#3 @coffee2code
5 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 929:

Code Reference: add up/down voting to user contributed notes. Fixes #551

#4 @coffee2code
5 years ago

Overview of voting for user contributed notes:

  • Any logged in user can vote on any approved note.
  • UI highly influenced by the voting on php.net.
  • Voting submits an AJAX request to record the vote. The UI is updated via JS. Works without JS as well.
  • Votes are stored as separate lists of user ids (one for up votes, one for down votes) in comment meta
  • User can change their votes
  • Upon voting: the vote number changes and the chosen vote indicator changes color (green for up, red for down) and ceases to be a link.
  • The number shown is the cumulative result of votes ($upvotes - $downvotes). If you hover over the number, what I call the like percentage is shown: the percentage of total votes that are up votes. (Consistent with php.net.)
    E.g. 6 people up voted, 2 people down voted = Score:4, Like:75%
    E.g. 4 people up voted, 0 people down voted = Score:4, Like:100%

Future consideration:

  • Votes are saved in comment_meta, so we can’t efficiently obtain a list of what a given user voted on. I didn’t feel this was necessary to do. Votes really only matter in the context of the comment/note. If we wanted it, we could also store the list of up and down voted note ids as user meta. (Or a dedicated table.)
  • No special sorting for the notes listings are performed yet. We’d have to decide what factor(s) we’d like to use for sorting before doing so.
  • Applying color or other style changes to voted notes. php.net doesn’t do this, but we could decide on criteria for “good” and “bad” notes and emphasize/deemphasize accordingly. Sorting may be sufficient, though.
  • Alert admins to “bad” notes. Yes, notes are initially moderated, but in the event of moderator oversight or (more likely) that a note becomes stale or wrong over time, do we want down votes to trigger an alert? Or perhaps have an admin view where the most downvoted notes can be listed. Bear in mind votes aren’t timestamped so we can’t gauge the number of down votes over a given period of time.

In rereading the initial proposal, I realize I need to change it so for a logged out visitor, trying to vote redirects them to log in and, upon doing so, proceeds to register their vote. Currently the vote arrow aren't clickable for logged out visitors and have hover text indicating they need to log in before they can vote.

Note: See TracTickets for help on using tickets.