Commit fc4a9654 by Scott

Merge branch 'hiddencanonicals' into 1.8

Fixes various issues with hidden follow-on and duplicate questions.
Closes #330.
parents 713d9618 24db479f
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
require_once QA_INCLUDE_DIR.'db/selects.php'; require_once QA_INCLUDE_DIR.'db/selects.php';
require_once QA_INCLUDE_DIR.'pages/question-view.php'; require_once QA_INCLUDE_DIR.'pages/question-view.php';
require_once QA_INCLUDE_DIR.'pages/question-submit.php'; require_once QA_INCLUDE_DIR.'pages/question-submit.php';
require_once QA_INCLUDE_DIR.'util/sort.php';
// Load relevant information about this answer // Load relevant information about this answer
...@@ -85,7 +86,10 @@ ...@@ -85,7 +86,10 @@
foreach ($achildposts as $key => $achildpost) foreach ($achildposts as $key => $achildpost)
$achildposts[$key]=$achildpost+qa_page_q_post_rules($achildpost, $answer, $achildposts, null); $achildposts[$key]=$achildpost+qa_page_q_post_rules($achildpost, $answer, $achildposts, null);
$achildposts = qa_page_q_load_c_follows($question, array(), $achildposts);
$usershtml=qa_userids_handles_html(array_merge(array($answer), $achildposts), true); $usershtml=qa_userids_handles_html(array_merge(array($answer), $achildposts), true);
qa_sort_by($achildposts, 'created');
$a_view=qa_page_q_answer_view($question, $answer, ($answer['postid']==$question['selchildid']) && ($answer['type']=='A'), $a_view=qa_page_q_answer_view($question, $answer, ($answer['postid']==$question['selchildid']) && ($answer['type']=='A'),
$usershtml, false); $usershtml, false);
......
...@@ -34,24 +34,29 @@ ...@@ -34,24 +34,29 @@
$parentid=qa_post_text('c_parentid'); $parentid=qa_post_text('c_parentid');
$userid=qa_get_logged_in_userid(); $userid=qa_get_logged_in_userid();
list($question, $parent, $children)=qa_db_select_with_pending( list($question, $parent, $children, $duplicateposts) = qa_db_select_with_pending(
qa_db_full_post_selectspec($userid, $questionid), qa_db_full_post_selectspec($userid, $questionid),
qa_db_full_post_selectspec($userid, $parentid), qa_db_full_post_selectspec($userid, $parentid),
qa_db_full_child_posts_selectspec($userid, $parentid) qa_db_full_child_posts_selectspec($userid, $parentid),
qa_db_post_duplicates_selectspec($questionid)
); );
if (isset($parent)) { if (isset($parent)) {
$parent=$parent+qa_page_q_post_rules($parent, null, null, $children); $parent = $parent + qa_page_q_post_rules($parent, null, null, $children+$duplicateposts);
// in theory we should retrieve the parent's parent and siblings for the above, but they're not going to be relevant // in theory we should retrieve the parent's parent and siblings for the above, but they're not going to be relevant
foreach ($children as $key => $child) foreach ($children as $key => $child)
$children[$key]=$child+qa_page_q_post_rules($child, $parent, $children, null); $children[$key]=$child+qa_page_q_post_rules($child, $parent, $children, null);
$usershtml=qa_userids_handles_html($children, true); $commentsfollows = $questionid == $parentid
? qa_page_q_load_c_follows($question, $children, array(), $duplicateposts)
: qa_page_q_load_c_follows($question, array(), $children);
qa_sort_by($children, 'created'); $usershtml=qa_userids_handles_html($commentsfollows, true);
$c_list=qa_page_q_comment_follow_list($question, $parent, $children, true, $usershtml, false, null); qa_sort_by($commentsfollows, 'created');
$c_list=qa_page_q_comment_follow_list($question, $parent, $commentsfollows, true, $usershtml, false, null);
$themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-comments', null, null); $themeclass=qa_load_theme_class(qa_get_site_theme(), 'ajax-comments', null, null);
$themeclass->initialize(); $themeclass->initialize();
......
...@@ -369,7 +369,7 @@ ...@@ -369,7 +369,7 @@
$limitsql=isset($limit) ? (' ORDER BY ^posts.postid LIMIT '.(int)$limit) : ''; $limitsql=isset($limit) ? (' ORDER BY ^posts.postid LIMIT '.(int)$limit) : '';
return qa_db_read_all_values(qa_db_query_sub( return qa_db_read_all_values(qa_db_query_sub(
"SELECT ^posts.postid FROM ^posts LEFT JOIN ^posts AS child ON child.parentid=^posts.postid WHERE ^posts.type=$ AND ^posts.postid>=# AND child.postid IS NULL".$limitsql, "SELECT ^posts.postid FROM ^posts LEFT JOIN ^posts AS child ON child.parentid=^posts.postid LEFT JOIN ^posts AS dupe ON dupe.closedbyid=^posts.postid WHERE ^posts.type=$ AND ^posts.postid>=# AND child.postid IS NULL AND dupe.postid IS NULL".$limitsql,
$type.'_HIDDEN', $startpostid $type.'_HIDDEN', $startpostid
)); ));
} }
......
...@@ -662,6 +662,22 @@ ...@@ -662,6 +662,22 @@
} }
/**
* Return the selectspec to retrieve the posts that have been closed as a duplicate of this question, if any
* @param $questionid int The canonical question.
* @return array
*/
function qa_db_post_duplicates_selectspec($questionid)
{
$selectspec = qa_db_posts_basic_selectspec(null, true);
$selectspec['source'] .= " WHERE ^posts.closedbyid=#";
$selectspec['arguments'] = array($questionid);
return $selectspec;
}
function qa_db_post_meta_selectspec($postid, $title) function qa_db_post_meta_selectspec($postid, $title)
/* /*
Return the selectspec to retrieve the metadata value for $postid with key $title Return the selectspec to retrieve the metadata value for $postid with key $title
......
...@@ -46,34 +46,35 @@ ...@@ -46,34 +46,35 @@
} }
function qa_page_q_load_c_follows($question, $childposts, $achildposts) function qa_page_q_load_c_follows($question, $childposts, $achildposts, $duplicateposts=array())
/* /*
Given a $question, its $childposts and its answers $achildposts from the database, Given a $question, its $childposts and its answers $achildposts from the database,
return a list of comments or follow-on questions for that question or its answers return a list of comments or follow-on questions for that question or its answers.
Follow-on and duplicate questions are now returned, with their visibility determined in qa_page_q_comment_follow_list()
*/ */
{ {
$commentsfollows=array(); $commentsfollows=array();
foreach ($childposts as $postid => $post) foreach ($childposts as $postid => $post)
switch ($post['type']) { switch ($post['basetype']) {
case 'Q': // never show follow-on Qs which have been hidden, even to admins case 'Q':
case 'C': case 'C':
case 'C_HIDDEN':
case 'C_QUEUED':
$commentsfollows[$postid]=$post; $commentsfollows[$postid]=$post;
break; break;
} }
foreach ($achildposts as $postid => $post) foreach ($achildposts as $postid => $post)
switch ($post['type']) { switch ($post['basetype']) {
case 'Q': // never show follow-on Qs which have been hidden, even to admins case 'Q':
case 'C': case 'C':
case 'C_HIDDEN':
case 'C_QUEUED':
$commentsfollows[$postid]=$post; $commentsfollows[$postid]=$post;
break; break;
} }
foreach ($duplicateposts as $postid => $post) {
$commentsfollows[$postid] = $post;
}
return $commentsfollows; return $commentsfollows;
} }
...@@ -185,9 +186,10 @@ ...@@ -185,9 +186,10 @@
// Now make any changes based on the child posts // Now make any changes based on the child posts
if (isset($childposts)) if (isset($childposts)) {
foreach ($childposts as $childpost) foreach ($childposts as $childpost) {
if ($childpost['parentid']==$post['postid']) { if ($childpost['parentid']==$post['postid']) {
// this post has comments
$rules['deleteable']=false; $rules['deleteable']=false;
if (($childpost['basetype']=='A') && qa_post_is_by_user($childpost, $userid, $cookieid)) { if (($childpost['basetype']=='A') && qa_post_is_by_user($childpost, $userid, $cookieid)) {
...@@ -199,6 +201,13 @@ ...@@ -199,6 +201,13 @@
} }
} }
if ($childpost['closedbyid'] == $post['postid']) {
// other questions are closed as duplicates of this one
$rules['deleteable'] = false;
}
}
}
// Return the resulting rules // Return the resulting rules
return $rules; return $rules;
...@@ -679,9 +688,20 @@ ...@@ -679,9 +688,20 @@
$showcomments=array(); $showcomments=array();
foreach ($commentsfollows as $commentfollowid => $commentfollow) // $commentsfollows contains ALL comments on the question and all answers, so here we filter the comments viewable for this context
if (($commentfollow['parentid']==$parentid) && $commentfollow['viewable'] && ($commentfollowid!=$formpostid) ) foreach ($commentsfollows as $commentfollowid => $commentfollow) {
$showcomments[$commentfollowid]=$commentfollow; $showcomment = $commentfollow['parentid'] == $parentid && $commentfollow['viewable'] && $commentfollowid != $formpostid;
// show hidden follow-on questions only if the parent is hidden
if ($showcomment && $commentfollow['basetype'] == 'Q' && $commentfollow['hidden']) {
$showcomment = $parent['hidden'];
}
// show questions closed as duplicate of this one, only if this question is hidden
$showduplicate = $question['hidden'] && $commentfollow['closedbyid'] == $parentid;
if ($showcomment || $showduplicate) {
$showcomments[$commentfollowid] = $commentfollow;
}
}
$countshowcomments=count($showcomments); $countshowcomments=count($showcomments);
......
...@@ -41,12 +41,13 @@ ...@@ -41,12 +41,13 @@
// Get information about this question // Get information about this question
list($question, $childposts, $achildposts, $parentquestion, $closepost, $extravalue, $categories, $favorite)=qa_db_select_with_pending( list($question, $childposts, $achildposts, $parentquestion, $closepost, $duplicateposts, $extravalue, $categories, $favorite) = qa_db_select_with_pending(
qa_db_full_post_selectspec($userid, $questionid), qa_db_full_post_selectspec($userid, $questionid),
qa_db_full_child_posts_selectspec($userid, $questionid), qa_db_full_child_posts_selectspec($userid, $questionid),
qa_db_full_a_child_posts_selectspec($userid, $questionid), qa_db_full_a_child_posts_selectspec($userid, $questionid),
qa_db_post_parent_q_selectspec($questionid), qa_db_post_parent_q_selectspec($questionid),
qa_db_post_close_post_selectspec($questionid), qa_db_post_close_post_selectspec($questionid),
qa_db_post_duplicates_selectspec($questionid),
qa_db_post_meta_selectspec($questionid, 'qa_q_extra'), qa_db_post_meta_selectspec($questionid, 'qa_q_extra'),
qa_db_category_nav_selectspec($questionid, true, true, true), qa_db_category_nav_selectspec($questionid, true, true, true),
isset($userid) ? qa_db_is_favorite_selectspec($userid, QA_ENTITY_QUESTION, $questionid) : null isset($userid) ? qa_db_is_favorite_selectspec($userid, QA_ENTITY_QUESTION, $questionid) : null
...@@ -66,9 +67,9 @@ ...@@ -66,9 +67,9 @@
$question['extra']=$extravalue; $question['extra']=$extravalue;
$answers=qa_page_q_load_as($question, $childposts); $answers=qa_page_q_load_as($question, $childposts);
$commentsfollows=qa_page_q_load_c_follows($question, $childposts, $achildposts); $commentsfollows=qa_page_q_load_c_follows($question, $childposts, $achildposts, $duplicateposts);
$question=$question+qa_page_q_post_rules($question, null, null, $childposts); // array union $question=$question+qa_page_q_post_rules($question, null, null, $childposts+$duplicateposts); // array union
if ($question['selchildid'] && (@$answers[$question['selchildid']]['type']!='A')) if ($question['selchildid'] && (@$answers[$question['selchildid']]['type']!='A'))
$question['selchildid']=null; // if selected answer is hidden or somehow not there, consider it not selected $question['selchildid']=null; // if selected answer is hidden or somehow not there, consider it not selected
......
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