Commit b74d7099 by pupi1985

Create cache_hiddencount setting and display the count in the admin menu

parent 5baf8603
......@@ -26,29 +26,16 @@ require_once QA_INCLUDE_DIR . 'app/cookies.php';
$entityid = qa_post_text('entityid');
$action = qa_post_text('action');
$version = (int)qa_post_text('version');
switch ($version) {
case 1:
if (!qa_check_form_security_code('admin/click', qa_post_text('code'))) {
$response = array(
'result' => 'error',
'error' => array(
'message' => qa_lang('misc/form_security_reload'),
),
);
} else {
$response = qa_admin_single_click_array($entityid, $action);
}
echo json_encode($response);
break;
default: // prior version
if (!qa_check_form_security_code('admin/click', qa_post_text('code')))
echo "QA_AJAX_RESPONSE\n0\n" . qa_lang('misc/form_security_reload');
elseif (qa_admin_single_click($entityid, $action))
echo "QA_AJAX_RESPONSE\n1\n";
else
echo "QA_AJAX_RESPONSE\n0\n" . qa_lang('main/general_error');
if (!qa_check_form_security_code('admin/click', qa_post_text('code'))) {
$response = array(
'result' => 'error',
'error' => array(
'message' => qa_lang('misc/form_security_reload'),
),
);
} else {
$response = qa_admin_single_click_array($entityid, $action);
}
echo json_encode($response);
......@@ -392,8 +392,10 @@ function qa_admin_sub_navigation()
}
if (!qa_user_maximum_permit_error('permit_hide_show') || !qa_user_maximum_permit_error('permit_delete_hidden')) {
$count = qa_user_permit_error('permit_hide_show') ? 0 : (int)qa_opt('cache_hiddencount');
$navigation['admin/hidden'] = array(
'label' => qa_lang_html('admin/hidden_title'),
'label' => qa_lang_html_sub('admin/hidden_title', '<span class="qa-nav-sub-counter-hidden">' . qa_html(qa_format_number($count)) . '</span>'),
'url' => qa_path_html('admin/hidden'),
);
}
......@@ -663,7 +665,7 @@ function qa_admin_single_click_array($entityid, $action)
$response['domUpdates'] = array(
array(
'selector' => '.qa-nav-sub-counter-moderate',
'html' => max($entityCount - 1, 0),
'html' => max($entityCount, 0),
),
array(
'selector' => '#p' . $entityid,
......@@ -697,12 +699,17 @@ function qa_admin_single_click_array($entityid, $action)
case 'reshow':
case 'delete':
$entityCount = (int)qa_opt('cache_hiddencount');
if (!$post['hidden']) {
$response['result'] = 'error';
$response['error']['type'] = 'post-not-hidden';
$response['error']['message'] = qa_lang_html('main/general_error');
$response['domUpdates'] = array(
array(
'selector' => '.qa-nav-sub-counter-hidden',
'html' => max($entityCount, 0),
),
array(
'selector' => '#p' . $entityid,
'action' => 'conceal',
),
......@@ -722,6 +729,10 @@ function qa_admin_single_click_array($entityid, $action)
$response['result'] = 'success';
$response['domUpdates'] = array(
array(
'selector' => '.qa-nav-sub-counter-hidden',
'html' => max($entityCount - 1, 0),
),
array(
'selector' => '#p' . $entityid,
'action' => 'conceal',
),
......@@ -739,7 +750,7 @@ function qa_admin_single_click_array($entityid, $action)
$response['domUpdates'] = array(
array(
'selector' => '.qa-nav-sub-counter-flagged',
'html' => max($entityCount - 1, 0),
'html' => max($entityCount, 0),
),
array(
'selector' => '#p' . $entityid,
......
......@@ -374,6 +374,10 @@ function qa_question_set_status($oldquestion, $status, $userid, $handle, $cookie
if ($wasqueued || ($status == QA_POST_STATUS_QUEUED))
qa_db_queuedcount_update();
if ($event === 'q_hide' || $event === 'q_reshow') {
qa_db_hiddencount_update();
}
if ($oldquestion['flagcount'])
qa_db_flaggedcount_update();
......@@ -536,6 +540,7 @@ function qa_question_delete($oldquestion, $userid, $handle, $cookieid, $oldclose
qa_db_post_delete($oldquestion['postid']); // also deletes any related voteds due to foreign key cascading
qa_update_counts_for_q(null);
qa_db_category_path_qcount_update($oldpath); // don't do inside qa_update_counts_for_q() since post no longer exists
qa_db_hiddencount_update();
qa_db_points_update_ifuser($oldquestion['userid'], array('qposts', 'aselects', 'qvoteds', 'upvoteds', 'downvoteds'));
foreach ($useridvotes as $voteruserid => $vote) {
......@@ -764,6 +769,10 @@ function qa_answer_set_status($oldanswer, $status, $userid, $handle, $cookieid,
if ($wasqueued || $status == QA_POST_STATUS_QUEUED)
qa_db_queuedcount_update();
if ($event === 'a_hide' || $event === 'a_reshow') {
qa_db_hiddencount_update();
}
if ($oldanswer['flagcount'])
qa_db_flaggedcount_update();
......@@ -846,6 +855,7 @@ function qa_answer_delete($oldanswer, $question, $userid, $handle, $cookieid)
}
qa_update_q_counts_for_a($question['postid']);
qa_db_hiddencount_update();
qa_db_points_update_ifuser($oldanswer['userid'], array('aposts', 'aselecteds', 'avoteds', 'upvoteds', 'downvoteds'));
foreach ($useridvotes as $voteruserid => $vote) {
......@@ -1151,6 +1161,10 @@ function qa_comment_set_status($oldcomment, $status, $userid, $handle, $cookieid
if ($wasqueued || $status == QA_POST_STATUS_QUEUED)
qa_db_queuedcount_update();
if ($event === 'c_hide' || $event === 'c_reshow') {
qa_db_hiddencount_update();
}
if ($oldcomment['flagcount'])
qa_db_flaggedcount_update();
......@@ -1234,6 +1248,7 @@ function qa_comment_delete($oldcomment, $question, $parent, $userid, $handle, $c
qa_post_unindex($oldcomment['postid']);
qa_db_post_delete($oldcomment['postid']);
qa_db_hiddencount_update();
qa_db_points_update_ifuser($oldcomment['userid'], array('cposts'));
qa_db_ccount_update();
......
......@@ -453,3 +453,19 @@ function qa_db_queuedcount_update()
);
}
}
/**
* Update the cached count in the database of the number of posts which are hidden
*/
function qa_db_hiddencount_update()
{
if (qa_should_update_counts()) {
qa_db_query_sub(
"INSERT INTO ^options (title, content) " .
"SELECT 'cache_hiddencount', COUNT(*) FROM ^posts " .
"WHERE type IN ('Q_HIDDEN', 'A_HIDDEN', 'C_HIDDEN') " .
"ON DUPLICATE KEY UPDATE content = VALUES(content)"
);
}
}
......@@ -129,7 +129,7 @@ return array(
'hidden_answers_deleted' => 'Deleted ^1 of ^2 hidden answers without dependents...',
'hidden_comments_deleted' => 'Deleted ^1 of ^2 hidden comments...',
'hidden_questions_deleted' => 'Deleted ^1 of ^2 hidden questions without dependents...',
'hidden_title' => 'Hidden',
'hidden_title' => 'Hidden (^)',
'hotness_factors' => 'Relative importance for question hotness:',
'ip_address_pages' => 'IP address pages',
'layout_title' => 'Layout',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment