This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes

Question2Answer can award points for accepting an answer, but it does that regardless of whether the accepted answer was posted by the person asking the question or someone else.

How can I prevent a user from increasing their reputation by posting questions and accepting their own answers?

in Scripting by (30) 5

Your answer


Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
By submitting this post you agree to our Terms & Conditions.
To avoid this verification in future, please log in or register.

1 Answer

0 votes
Best answer

Unfortunately the configuration doesn't provide an option to disable awarding points only for accepting self-answers. You can set the amount of points awarded for accepting an answer to zero, but that would disable reputation for accepting an answer entirely.

If you want reputation to be gained only for accepting someone else's answer you need to modify the code. The relevant part is in the file qa-include/db/points.php. Find the following section in that file (for version 1.8.5 it's lines 77 through 80):

'aselects' => array(
  'multiple' => $options['points_multiple'] * $options['points_select_a'],
  'formula' => "COUNT(*) AS aselects FROM ^posts AS userid_src WHERE userid~ AND type='Q' AND selchildid IS NOT NULL",

and change it to this:

'aselects' => array(
  'multiple' => $options['points_multiple'] * $options['points_select_a'],
  'formula' => "COUNT(*) AS aselects FROM ^posts AS userid_src JOIN ^posts AS answers ON userid_src.selchildid=answers.postid WHERE userid_src.userid~ AND userid_src.type='Q' AND (userid_src.userid<>answers.userid)",

The formula gets expanded to

  COUNT(*) AS aselects
FROM qa_posts AS userid_src
  JOIN qa_posts AS answers ON userid_src.selchildid=answers.postid
WHERE userid_src.userid BETWEEN # AND # AND
  userid_src.type='Q' AND
GROUP BY userid

which joins the posts table with itself by matching the field selchildid of the question records to the field postid of the answer records. The clause userid_src.userid<>answers.userid ensures that only records are selected where the user posting the question is different from the user posting the answer. The query then groups the results by user ID and returns a recordset with user IDs and the number of answers they accepted.

With that said, note that patching the core application code has the disadvantage that your changes will be lost after updating to a new version. A better approach would be to create a custom plugin where you can override the routine that generates the associative array with the points calculation queries.

In your override function you'd essentially just call the original function (append the suffix _base to the function name to do so), then update the formula for the aselects key and return the modified associative array:

function qa_db_points_calculations() {
  $points_calculations = qa_db_points_calculations_base();
  $points_calculations['aselects']['formula'] = "COUNT(*) AS aselects FROM ...";
  return $points_calculations;

The complete plugin can be downloaded from here.

by (30) 5
edited by