Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarwiechers committed Aug 9, 2020
0 parents commit 84741d9
Show file tree
Hide file tree
Showing 6 changed files with 747 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*~
.*.sw[a-p]
674 changes: 674 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
The points system in [Question2Answer][1] allows for awarding points for
accepting an answer to the user accepting the answer, which serves as an
incentive to actually mark an answer as "best answer." However, the software
awards the points regardless of whether the answer is from the person asking the
question or someone else, and doesn't provide an option to change that behavior.
This might tempt some people to increase their points by posting a lot of
(trivial) questions and accepting their own (trivial) answer.

This plugin changes the default behavior so that points are only awarded to the
user accepting an answer if that answer wasn't posted by themselves.

To activate it, copy the plugin directory to the plugins directory of your
Question2Answer site (or clone this repository there), then log in as the site
admin and enable the plugin under *Admin → Plugins*.
11 changes: 11 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "No Self-Accept Points",
"description": "Don't award points for accepted self-answers.",
"version": "1.0.0",
"date": "2020-08-09",
"author": "Ansgar Wiechers",
"author_uri": "https://ask.planetcobalt.net/",
"license": "GPLv3",
"min_q2a": "1.5",
"load_order": "after_db_init"
}
24 changes: 24 additions & 0 deletions points.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

// don't allow this page to be requested directly from browser
if (!defined('QA_VERSION')) {
header('Location: ../../');
exit;
}

/**
* Override the formula for calculating points for accepting answers to remove
* accepted self-answers.
*/
function qa_db_points_calculations() {
$points_calculations = qa_db_points_calculations_base();

if (array_key_exists('aselects', $points_calculations)) {
$points_calculations['aselects']['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 (answers.userid <> userid_src.userid)";
} else {
// if key 'aselects' is missing: throw a warning, but continue regardless
trigger_error("Missing key 'aselects' in points calculations array", E_USER_WARNING);
}

return $points_calculations;
}
22 changes: 22 additions & 0 deletions qa-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: https://www.gnu.org/licenses/gpl-3.0.html
*/

// don't allow this page to be requested directly from browser
if (!defined('QA_VERSION')) {
header('Location: ../../');
exit;
}

qa_register_plugin_overrides('points.php');

0 comments on commit 84741d9

Please sign in to comment.