Opened 15 years ago
Closed 15 years ago
#10397 closed defect (bug) (fixed)
Start of week and WEEK mysql date function
Reported by: | arena | Owned by: | |
---|---|---|---|
Milestone: | 3.0 | Priority: | normal |
Severity: | major | Version: | 2.9 |
Component: | Date/Time | Keywords: | has-patch dev-feedack |
Focuses: | Cc: |
Description
In wp-includes/general-template.php :
$start_of_week = get_option('start_of_week'); $query = "SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, ........
last argument value can lead to malfunction
see http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_week
Attachments (3)
Change History (23)
#1
@
15 years ago
- Component changed from General to Date/Time
- Milestone changed from Unassigned to 2.9
#5
@
15 years ago
function wp_get_archives() uses unsafe queries all over the place. It's adviseable to replace them according to the project's database guidelines.
#6
@
15 years ago
- Milestone changed from Future Release to 2.9.1
- Severity changed from normal to critical
#7
@
15 years ago
- Keywords has-patch tested added
- Version set to 2.9
For the tickets ground cause I've applied a patch which already run tested here (at least as far as I was able to). Waiting for a review.
#10
follow-ups:
↓ 11
↓ 12
@
15 years ago
- Keywords needs-patch added; has-patch tested removed
Patch has a few issues.. Ignoring the fact the syntax is still wrong. One of the WEEK functions is still the same, and you cant jam a "LIMIT 1234" into a %d
Out of curiosity, why does WordPress have the option for start of week?
#11
in reply to:
↑ 10
@
15 years ago
Replying to dd32:
Out of curiosity, why does WordPress have the option for start of week?
in some languages, the week "starts" on a monday rather than on a sunday.
#12
in reply to:
↑ 10
@
15 years ago
Replying to dd32:
Patch has a few issues.. Ignoring the fact the syntax is still wrong. One of the WEEK functions is still the same, and you cant jam a "LIMIT 1234" into a %d
Out of curiosity, why does WordPress have the option for start of week?
As far as i have seen this is for some archive stuff, but quite sure 99% of wp users don't use it !!!
#13
follow-up:
↓ 15
@
15 years ago
in some languages, the week "starts" on a monday rather than on a sunday.
I was mainly wondering why we support it starting on Thursday.. I know Sunday and Monday are used - thus the support for it in WEEK, But wasnt aware of anything else.
#14
@
15 years ago
- Milestone changed from 2.9.1 to 3.0
- Severity changed from critical to major
I'm changing the milestone of this to 3.0, This code has been exactly the same since 2.1(earliest the file exists) so its not a regression.
The prepare()'s can be done at the same time, Since they're not using user-provided data (Rather, administrative options), I feel that this is not a change required in the maintainence release - I'll leave that open for a core dev to determine however.
'start_of_week'
does however need to have a intval()
applied to it on the sanitization list.. I'm going to create a new ticket for that - See #11623
#15
in reply to:
↑ 13
;
follow-up:
↓ 16
@
15 years ago
Replying to arena:
@hackre
The point of this ticket is that get_option('start_of_week') can retrieve a value of 0 to 6 (Sunday to Saturday).
WEEK(post_date, $start_of_week) only accept following values :
...
Right, that does not match to each other. So my patch was completely bogus. What's needed is a proper translation from the WP 0-6 value (0: Sunday, 1: Monday, ... and 6: Saturday) to something usefull in a/the mysql query (I'm seeing nothing of that on the mysql manual page related to the date/time functions).
Replying to dd32:
in some languages, the week "starts" on a monday rather than on a sunday.
I was mainly wondering why we support it starting on Thursday.. I know Sunday and Monday are used - thus the support for it in WEEK, But wasnt aware of anything else.
Maybe this can be properly verified against valid sources (I share that opinion but I'd like not to introduce problems here) and if so, it will save us a lot because those arguments can then be properly alligned. Maybe we should reduce that dropdown to two values: Sunday = 0 and Monday = 1.
#16
in reply to:
↑ 15
@
15 years ago
Replying to hakre:
(I'm seeing nothing of that on the mysql manual page related to the date/time functions).
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_week
#17
@
15 years ago
if WordPress wants to support iso 8601 as the default
When using "WEEK" MySql function, second argument should have the value : 3
(there are no 0 (zero) week in iso 8601).
"WEEK" MySql function is used in two wp files :
wp-includes/general-template.php
wp-includes/query.php
More info :
http://en.wikipedia.org/wiki/ISO_8601
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_week
#18
@
15 years ago
- Keywords has-patch added; needs-patch removed
10397.diff
- Simplifies
get_weekstartend()
and makes it actually work for weirdstart_of_week
values. - Introduces
_wp_mysql_week()
to output the appropriate MySQLWEEK()
expression given thestart_of_week
value. - Fixes the
w
parameter ofWP_Query
to match the date ranges output bywp_get_archives( weekly )
. This means different blogs will display posts from different datetime ranges for queries likeyear=2010&w=17
. This seems ok to me: different blogs already display posts from different datetime ranges for every time based query because of time zone differences.
Content of $info (sample)