Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
1ef5dfe5
Commit
1ef5dfe5
authored
Jul 29, 2017
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle basic logic for comment voting
parent
426ba54c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
214 additions
and
63 deletions
+214
-63
options.php
qa-include/app/options.php
+41
-27
votes.php
qa-include/app/votes.php
+41
-29
AppOptionsTest.php
qa-tests/AppOptionsTest.php
+10
-5
AppVotesTest.php
qa-tests/AppVotesTest.php
+118
-0
qa-styles.css
qa-theme/SnowFlat/qa-styles.css
+3
-1
qa-theme.php
qa-theme/SnowFlat/qa-theme.php
+1
-1
No files found.
qa-include/app/options.php
View file @
1ef5dfe5
...
@@ -657,10 +657,10 @@ function qa_get_vote_view($postorbasetype, $full = false, $enabledif = true)
...
@@ -657,10 +657,10 @@ function qa_get_vote_view($postorbasetype, $full = false, $enabledif = true)
// The 'level' and 'approve' permission errors are taken care of by disabling the voting buttons.
// The 'level' and 'approve' permission errors are taken care of by disabling the voting buttons.
// Others are reported to the user after they click, in qa_vote_error_html(...)
// Others are reported to the user after they click, in qa_vote_error_html(...)
if
(
is_array
(
$postorbasetype
))
{
// deal with dual-use parameter
// deal with dual-use parameter
if
(
is_array
(
$postorbasetype
))
{
$basetype
=
$postorbasetype
[
'basetype'
];
$basetype
=
$postorbasetype
[
'basetype'
];
$post
=
$postorbasetype
;
$post
=
$postorbasetype
;
}
else
{
}
else
{
$basetype
=
$postorbasetype
;
$basetype
=
$postorbasetype
;
$post
=
null
;
$post
=
null
;
...
@@ -668,36 +668,50 @@ function qa_get_vote_view($postorbasetype, $full = false, $enabledif = true)
...
@@ -668,36 +668,50 @@ function qa_get_vote_view($postorbasetype, $full = false, $enabledif = true)
$disabledsuffix
=
''
;
$disabledsuffix
=
''
;
if
(
$basetype
==
'Q'
||
$basetype
==
'A'
)
{
switch
(
$basetype
)
$view
=
$basetype
==
'A'
?
qa_opt
(
'voting_on_as'
)
:
qa_opt
(
'voting_on_qs'
);
{
case
'Q'
:
$view
=
qa_opt
(
'voting_on_qs'
);
$permitOpt
=
'permit_vote_q'
;
break
;
case
'A'
:
$view
=
qa_opt
(
'voting_on_as'
);
$permitOpt
=
'permit_vote_a'
;
break
;
case
'C'
:
$view
=
qa_opt
(
'voting_on_cs'
);
$permitOpt
=
'permit_vote_c'
;
break
;
default
:
$view
=
false
;
break
;
}
if
(
!
$view
)
{
return
false
;
}
if
(
!
(
$enabledif
&&
(
$basetype
==
'A'
||
$full
||
!
qa_opt
(
'voting_on_q_page_only'
))))
if
(
!
$enabledif
||
(
$basetype
==
'Q'
&&
!
$full
&&
qa_opt
(
'voting_on_q_page_only'
)))
{
$disabledsuffix
=
'-disabled-page'
;
$disabledsuffix
=
'-disabled-page'
;
}
else
{
$permiterror
=
isset
(
$post
)
?
qa_user_post_permit_error
(
$permitOpt
,
$post
)
:
qa_user_permit_error
(
$permitOpt
);
if
(
$permiterror
==
'level'
)
$disabledsuffix
=
'-disabled-level'
;
elseif
(
$permiterror
==
'approve'
)
$disabledsuffix
=
'-disabled-approve'
;
else
{
else
{
if
(
$basetype
==
'A'
)
$permiterrordown
=
isset
(
$post
)
?
qa_user_post_permit_error
(
'permit_vote_down'
,
$post
)
:
qa_user_permit_error
(
'permit_vote_down'
);
$permiterror
=
isset
(
$post
)
?
qa_user_post_permit_error
(
'permit_vote_a'
,
$post
)
:
qa_user_permit_error
(
'permit_vote_a'
);
else
$permiterror
=
isset
(
$post
)
?
qa_user_post_permit_error
(
'permit_vote_q'
,
$post
)
:
qa_user_permit_error
(
'permit_vote_q'
);
if
(
$permiterror
==
'level'
)
$disabledsuffix
=
'-disabled-level'
;
elseif
(
$permiterror
==
'approve'
)
$disabledsuffix
=
'-disabled-approve'
;
else
{
$permiterrordown
=
isset
(
$post
)
?
qa_user_post_permit_error
(
'permit_vote_down'
,
$post
)
:
qa_user_permit_error
(
'permit_vote_down'
);
if
(
$permiterrordown
==
'level'
)
$disabledsuffix
=
'-uponly-level'
;
elseif
(
$permiterrordown
==
'approve'
)
$disabledsuffix
=
'-uponly-approve'
;
}
}
}
else
if
(
$permiterrordown
==
'level'
)
$view
=
false
;
$disabledsuffix
=
'-uponly-level'
;
elseif
(
$permiterrordown
==
'approve'
)
$disabledsuffix
=
'-uponly-approve'
;
}
}
return
$view
?
((
qa_opt
(
'votes_separated'
)
?
'updown'
:
'net'
)
.
$disabledsuffix
)
:
false
;
return
(
qa_opt
(
'votes_separated'
)
?
'updown'
:
'net'
)
.
$disabledsuffix
;
}
}
...
...
qa-include/app/votes.php
View file @
1ef5dfe5
...
@@ -52,42 +52,54 @@ function qa_vote_error_html($post, $vote, $userid, $topage)
...
@@ -52,42 +52,54 @@ function qa_vote_error_html($post, $vote, $userid, $topage)
return
qa_lang_html
(
'main/vote_disabled_queued'
);
return
qa_lang_html
(
'main/vote_disabled_queued'
);
}
}
$allowVoting
=
qa_opt
(
$post
[
'basetype'
]
==
'Q'
?
'voting_on_qs'
:
'voting_on_as'
);
switch
(
$post
[
'basetype'
])
{
case
'Q'
:
$allowVoting
=
qa_opt
(
'voting_on_qs'
);
break
;
case
'A'
:
$allowVoting
=
qa_opt
(
'voting_on_as'
);
break
;
case
'C'
:
$allowVoting
=
qa_opt
(
'voting_on_cs'
);
break
;
default
:
$allowVoting
=
false
;
break
;
}
if
(
(
$post
[
'basetype'
]
===
'Q'
||
$post
[
'basetype'
]
===
'A'
)
&&
$allowVoting
&&
if
(
!
$allowVoting
||
(
isset
(
$post
[
'userid'
])
&&
isset
(
$userid
)
&&
$post
[
'userid'
]
==
$userid
))
{
(
!
isset
(
$post
[
'userid'
])
||
!
isset
(
$userid
)
||
$post
[
'userid'
]
!=
$userid
)
// voting option should not have been presented (but could happen due to options change
)
)
{
return
qa_lang_html
(
'main/vote_not_allowed'
);
$permiterror
=
qa_user_post_permit_error
((
$post
[
'basetype'
]
==
'Q'
)
?
'permit_vote_q'
:
'permit_vote_a'
,
$post
,
QA_LIMIT_VOTES
);
}
$errordownonly
=
!
$permiterror
&&
$vote
<
0
;
$permiterror
=
qa_user_post_permit_error
((
$post
[
'basetype'
]
==
'Q'
)
?
'permit_vote_q'
:
'permit_vote_a'
,
$post
,
QA_LIMIT_VOTES
);
if
(
$errordownonly
)
{
$permiterror
=
qa_user_post_permit_error
(
'permit_vote_down'
,
$post
);
}
switch
(
$permiterror
)
{
$errordownonly
=
!
$permiterror
&&
$vote
<
0
;
case
false
:
if
(
$errordownonly
)
{
return
false
;
$permiterror
=
qa_user_post_permit_error
(
'permit_vote_down'
,
$post
)
;
break
;
}
case
'login'
:
switch
(
$permiterror
)
{
return
qa_insert_login_links
(
qa_lang_html
(
'main/vote_must_login'
),
$topage
);
case
false
:
break
;
return
false
;
break
;
case
'confirm
'
:
case
'login
'
:
return
qa_insert_login_links
(
qa_lang_html
(
$errordownonly
?
'main/vote_down_must_confirm'
:
'main/vote_must_confirm
'
),
$topage
);
return
qa_insert_login_links
(
qa_lang_html
(
'main/vote_must_login
'
),
$topage
);
break
;
break
;
case
'limit
'
:
case
'confirm
'
:
return
qa_lang_html
(
'main/vote_limit'
);
return
qa_insert_login_links
(
qa_lang_html
(
$errordownonly
?
'main/vote_down_must_confirm'
:
'main/vote_must_confirm'
),
$topage
);
break
;
break
;
default
:
case
'limit'
:
return
qa_lang_html
(
'users/no_permission
'
);
return
qa_lang_html
(
'main/vote_limit
'
);
break
;
break
;
}
}
else
{
default
:
// voting option should not have been presented (but could happen due to options change)
return
qa_lang_html
(
'users/no_permission'
);
return
qa_lang_html
(
'main/vote_not_allowed'
)
;
break
;
}
}
}
}
...
...
qa-tests/AppOptionsTest.php
View file @
1ef5dfe5
...
@@ -10,8 +10,9 @@ class AppOptionsTest extends PHPUnit_Framework_TestCase
...
@@ -10,8 +10,9 @@ class AppOptionsTest extends PHPUnit_Framework_TestCase
'voting_on_cs'
=>
1
,
'voting_on_cs'
=>
1
,
'voting_on_q_page_only'
=>
1
,
'voting_on_q_page_only'
=>
1
,
'votes_separated'
=>
0
,
'votes_separated'
=>
0
,
'permit_vote_a'
=>
QA_PERMIT_USERS
,
'permit_vote_q'
=>
QA_PERMIT_USERS
,
'permit_vote_q'
=>
QA_PERMIT_USERS
,
'permit_vote_a'
=>
QA_PERMIT_USERS
,
'permit_vote_c'
=>
QA_PERMIT_USERS
,
'permit_vote_down'
=>
QA_PERMIT_USERS
,
'permit_vote_down'
=>
QA_PERMIT_USERS
,
);
);
...
@@ -61,14 +62,16 @@ class AppOptionsTest extends PHPUnit_Framework_TestCase
...
@@ -61,14 +62,16 @@ class AppOptionsTest extends PHPUnit_Framework_TestCase
$this
->
assertSame
(
'net-disabled-page'
,
qa_get_vote_view
(
'A'
,
true
,
false
));
$this
->
assertSame
(
'net-disabled-page'
,
qa_get_vote_view
(
'A'
,
true
,
false
));
$this
->
assertSame
(
'net-disabled-page'
,
qa_get_vote_view
(
'A'
,
false
,
false
));
$this
->
assertSame
(
'net-disabled-page'
,
qa_get_vote_view
(
'A'
,
false
,
false
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'C'
,
true
));
$this
->
assertSame
(
'net'
,
qa_get_vote_view
(
'C'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'C'
,
false
));
$this
->
assertSame
(
'net'
,
qa_get_vote_view
(
'C'
,
false
));
$qa_options_cache
[
'voting_on_qs'
]
=
0
;
$qa_options_cache
[
'voting_on_qs'
]
=
0
;
$qa_options_cache
[
'voting_on_as'
]
=
0
;
$qa_options_cache
[
'voting_on_as'
]
=
0
;
$qa_options_cache
[
'voting_on_cs'
]
=
0
;
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'Q'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'Q'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'A'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'A'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'C'
,
true
));
}
}
/**
/**
...
@@ -92,13 +95,15 @@ class AppOptionsTest extends PHPUnit_Framework_TestCase
...
@@ -92,13 +95,15 @@ class AppOptionsTest extends PHPUnit_Framework_TestCase
$this
->
assertSame
(
'updown-disabled-page'
,
qa_get_vote_view
(
'A'
,
true
,
false
));
$this
->
assertSame
(
'updown-disabled-page'
,
qa_get_vote_view
(
'A'
,
true
,
false
));
$this
->
assertSame
(
'updown-disabled-page'
,
qa_get_vote_view
(
'A'
,
false
,
false
));
$this
->
assertSame
(
'updown-disabled-page'
,
qa_get_vote_view
(
'A'
,
false
,
false
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'C'
,
true
));
$this
->
assertSame
(
'updown'
,
qa_get_vote_view
(
'C'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'C'
,
false
));
$this
->
assertSame
(
'updown'
,
qa_get_vote_view
(
'C'
,
false
));
$qa_options_cache
[
'voting_on_qs'
]
=
0
;
$qa_options_cache
[
'voting_on_qs'
]
=
0
;
$qa_options_cache
[
'voting_on_as'
]
=
0
;
$qa_options_cache
[
'voting_on_as'
]
=
0
;
$qa_options_cache
[
'voting_on_cs'
]
=
0
;
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'Q'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'Q'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'A'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'A'
,
true
));
$this
->
assertSame
(
false
,
qa_get_vote_view
(
'C'
,
true
));
}
}
...
...
qa-tests/AppVotesTest.php
0 → 100644
View file @
1ef5dfe5
<?php
require_once
QA_INCLUDE_DIR
.
'app/votes.php'
;
require_once
QA_INCLUDE_DIR
.
'app/options.php'
;
class
AppVotesTest
extends
PHPUnit_Framework_TestCase
{
private
$voteviewOpts
=
array
(
'voting_on_qs'
=>
1
,
'voting_on_as'
=>
1
,
'voting_on_cs'
=>
1
,
// 'voting_on_q_page_only' => 1,
// 'votes_separated' => 0,
'permit_vote_q'
=>
QA_PERMIT_USERS
,
'permit_vote_a'
=>
QA_PERMIT_USERS
,
'permit_vote_c'
=>
QA_PERMIT_USERS
,
'permit_vote_down'
=>
QA_PERMIT_USERS
,
);
private
$mockQuestion
=
array
(
'postid'
=>
16349
,
'categoryid'
=>
''
,
'type'
=>
'Q'
,
'basetype'
=>
'Q'
,
'hidden'
=>
0
,
'queued'
=>
0
,
'acount'
=>
13
,
'selchildid'
=>
''
,
'closedbyid'
=>
''
,
'upvotes'
=>
1
,
'downvotes'
=>
0
,
'netvotes'
=>
1
,
'views'
=>
20
,
'hotness'
=>
33319100000
,
'flagcount'
=>
0
,
'title'
=>
'To be or not to be?'
,
'tags'
=>
'question,answer'
,
'created'
=>
1344623702
,
'name'
=>
''
,
'categoryname'
=>
''
,
'categorybackpath'
=>
''
,
'categoryids'
=>
''
,
'uservote'
=>
1
,
'userflag'
=>
0
,
'userfavoriteq'
=>
'0'
,
'content'
=>
'That is the question.'
,
'notify'
=>
''
,
'updated'
=>
1409375832
,
'updatetype'
=>
'E'
,
'format'
=>
''
,
'lastuserid'
=>
21981
,
'lastip'
=>
''
,
'parentid'
=>
''
,
'lastviewip'
=>
''
,
'userid'
=>
1
,
'cookieid'
=>
''
,
'createip'
=>
''
,
'points'
=>
140
,
'flags'
=>
0
,
'level'
=>
0
,
'email'
=>
'21981@example.com'
,
'handle'
=>
'QuestionAsker'
,
'avatarblobid'
=>
''
,
'avatarwidth'
=>
''
,
'avatarheight'
=>
''
,
'lasthandle'
=>
'QuestionAsker'
,
);
private
$mockUser
=
array
(
'userid'
=>
1
,
'passsalt'
=>
null
,
'passcheck'
=>
null
,
'passhash'
=>
'passhash'
,
'email'
=>
'email'
,
'level'
=>
120
,
'emailcode'
=>
''
,
'handle'
=>
'admin'
,
'created'
=>
''
,
'sessioncode'
=>
''
,
'sessionsource'
=>
null
,
'flags'
=>
265
,
'loggedin'
=>
''
,
'loginip'
=>
''
,
'written'
=>
''
,
'writeip'
=>
''
,
'avatarblobid'
=>
''
,
'avatarwidth'
=>
''
,
'avatarheight'
=>
''
,
'points'
=>
100
,
'wallposts'
=>
6
,
);
/**
* Test voteview where upvotes/downvotes are combined
*/
public
function
test__qa_vote_error_html
()
{
// set options/lang/user cache to bypass database
global
$qa_options_cache
,
$qa_curr_ip_blocked
,
$qa_cached_logged_in_user
,
$qa_phrases_full
;
$qa_options_cache
=
array_merge
(
$qa_options_cache
,
$this
->
voteviewOpts
);
$qa_curr_ip_blocked
=
false
;
$qa_cached_logged_in_user
=
$this
->
mockUser
;
$qa_phrases_full
[
'main'
][
'vote_not_allowed'
]
=
'Voting on this is not allowed'
;
$qa_phrases_full
[
'main'
][
'vote_disabled_hidden'
]
=
'You cannot vote on hidden posts'
;
$topage
=
'123/to-be-or-not-to-be'
;
$this
->
assertSame
(
$qa_phrases_full
[
'main'
][
'vote_not_allowed'
],
qa_vote_error_html
(
$this
->
mockQuestion
,
1
,
1
,
$topage
));
$hiddenQ
=
$this
->
mockQuestion
;
$hiddenQ
[
'hidden'
]
=
1
;
$this
->
assertSame
(
$qa_phrases_full
[
'main'
][
'vote_disabled_hidden'
],
qa_vote_error_html
(
$hiddenQ
,
1
,
17
,
$topage
));
// can't test more right now due to qa_user_limits_remaining() call from qa_user_permit_error()
}
}
qa-theme/SnowFlat/qa-styles.css
View file @
1ef5dfe5
...
@@ -2643,7 +2643,6 @@ input[type="submit"], button {
...
@@ -2643,7 +2643,6 @@ input[type="submit"], button {
width
:
12px
;
width
:
12px
;
height
:
8px
;
height
:
8px
;
left
:
0
;
left
:
0
;
transform
:
scale
(
0.75
);
}
}
.qa-c-list-item
.qa-vote-first-button
{
.qa-c-list-item
.qa-vote-first-button
{
top
:
0
;
top
:
0
;
...
@@ -2651,6 +2650,9 @@ input[type="submit"], button {
...
@@ -2651,6 +2650,9 @@ input[type="submit"], button {
.qa-c-list-item
.qa-vote-second-button
{
.qa-c-list-item
.qa-vote-second-button
{
top
:
12px
;
top
:
12px
;
}
}
.qa-c-list-item
.qa-vote-one-button
{
top
:
6px
;
}
.qa-c-list-item
.qa-vote-up-button
{
.qa-c-list-item
.qa-vote-up-button
{
background-position
:
-32px
0
;
background-position
:
-32px
0
;
...
...
qa-theme/SnowFlat/qa-theme.php
View file @
1ef5dfe5
...
@@ -495,7 +495,7 @@ class qa_html_theme extends qa_html_theme_base
...
@@ -495,7 +495,7 @@ class qa_html_theme extends qa_html_theme_base
*/
*/
public
function
vote_count
(
$post
)
public
function
vote_count
(
$post
)
{
{
if
(
$post
[
'raw'
][
'basetype'
]
===
'C'
&&
$post
[
'
netvotes_view'
][
'data
'
]
==
0
)
{
if
(
$post
[
'raw'
][
'basetype'
]
===
'C'
&&
$post
[
'
raw'
][
'netvotes
'
]
==
0
)
{
$post
[
'netvotes_view'
][
'data'
]
=
''
;
$post
[
'netvotes_view'
][
'data'
]
=
''
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment