Unverified Commit 1b3b746f by Scott Committed by GitHub

Merge pull request #608 from pupi1985/patch-104

Use JSON in admin_click AJAX calls
parents 04fd4dc4 c6bce760
......@@ -112,6 +112,27 @@ function qa_mailing_start(noteid, pauseid)
);
}
function qa_update_dom(response)
{
if (!response.hasOwnProperty('domUpdates')) {
return;
}
for (var i = 0; i < response.domUpdates.length; i++) {
var domUpdate = response.domUpdates[i];
switch (domUpdate.action) {
case 'conceal':
qa_conceal(document.querySelector(domUpdate.selector));
break;
case 'reveal':
qa_reveal(document.querySelector(domUpdate.selector));
break;
default: // replace
$(domUpdate.selector).html(domUpdate.html);
}
}
}
function qa_admin_click(target)
{
var p = target.name.split('_');
......@@ -120,15 +141,15 @@ function qa_admin_click(target)
params.code = target.form.elements.code.value;
qa_ajax_post('click_admin', params,
function(lines) {
if (lines[0] == '1')
qa_conceal(document.getElementById('p' + p[1]), 'admin');
else if (lines[0] == '0') {
alert(lines[1]);
qa_hide_waiting(target);
} else
qa_ajax_error();
}
function (response) {
qa_update_dom(response);
if (response.result === 'error' && response.error.severity === 'fatal') {
alert(response.error.message);
}
qa_hide_waiting(target);
}, 1
);
qa_show_waiting_after(target, false);
......
......@@ -152,22 +152,31 @@ function qa_favorite_click(elem)
return false;
}
function qa_ajax_post(operation, params, callback)
function qa_ajax_post(operation, params, callback, version)
{
$.extend(params, {qa: 'ajax', qa_operation: operation, qa_root: qa_root, qa_request: qa_request});
if (typeof(version) === 'undefined') {
version = 0;
}
$.post(qa_root, params, function(response) {
var header = 'QA_AJAX_RESPONSE';
var headerpos = response.indexOf(header);
$.extend(params, {qa: 'ajax', qa_operation: operation, qa_root: qa_root, qa_request: qa_request, version: version});
if (headerpos >= 0)
callback(response.substr(headerpos + header.length).replace(/^\s+/, '').split("\n"));
else
callback([]);
$.post(qa_root, params, function (response) {
if (version === 0) {
var header = 'QA_AJAX_RESPONSE';
var headerpos = response.indexOf(header);
}, 'text').fail(function(jqXHR) {
if (headerpos >= 0)
callback(response.substr(headerpos + header.length).replace(/^\s+/, '').split("\n"));
else
callback([]);
} else {
callback(response);
}
},
version === 0 ? 'text' : 'json'
).fail(function (jqXHR) {
if (jqXHR.readyState > 0)
callback([])
qa_ajax_error();
});
}
......
......@@ -27,9 +27,15 @@ require_once QA_INCLUDE_DIR . 'app/cookies.php';
$entityid = qa_post_text('entityid');
$action = qa_post_text('action');
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)) // permission check happens in here
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);
......@@ -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)"
);
}
}
......@@ -37,7 +37,7 @@ return array(
'after_x' => 'After "^"',
'after_x_tab' => 'After "^" tab',
'approve_user_popup' => 'Approve user',
'approve_users_title' => 'Approve users',
'approve_users_title' => 'Approve users (^)',
'basic_editor' => 'Basic Editor',
'before_main_menu' => 'Before tabs at top',
'blobs_directory_error' => 'The directory ^ defined as QA_BLOBS_DIRECTORY is not writable by the web server.',
......@@ -121,7 +121,7 @@ return array(
'field_single_line' => 'Single line of text',
'field_type' => 'Content type:',
'first' => 'First',
'flagged_title' => 'Flagged',
'flagged_title' => 'Flagged (^)',
'form_security_expired' => 'Form security code expired - please try again',
'from_anon' => 'From anonymous:',
'from_users' => 'From users:',
......@@ -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',
......@@ -145,7 +145,7 @@ return array(
'maintenance_admin_only' => 'Your site is in ^1maintenance^2 and is currently inaccessible to regular users.',
'maximum_x' => ' (max ^)',
'memcached_error' => 'Memcached error: ^',
'moderate_title' => 'Moderate',
'moderate_title' => 'Moderate (^)',
'module_x_database_init' => 'The ^1 ^2 module requires some ^3database initialization^4.',
'most_flagged_title' => 'Flagged content',
'mysql_version' => 'MySQL version:',
......@@ -215,6 +215,7 @@ return array(
'recalc_stop' => 'Stop recalculating',
'recent_approve_title' => 'Recent content waiting for approval',
'recent_hidden_title' => 'Recent hidden content',
'recent_users_title' => 'Recent users waiting for approval',
'recount_posts' => 'Recount posts',
'recount_posts_as_recounted' => 'Recounted answers and hotness for ^1 of ^2 posts...',
'recount_posts_complete' => 'All posts were successfully recounted.',
......
......@@ -60,7 +60,7 @@ $pageerror = qa_admin_check_clicks();
$qa_content = qa_content_prepare();
$qa_content['title'] = qa_lang_html('admin/approve_users_title');
$qa_content['title'] = qa_lang_html('admin/recent_users_title');
$qa_content['error'] = isset($pageerror) ? $pageerror : qa_admin_page_error();
$qa_content['message_list'] = array(
......
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