From 3c94d07beba64154ecd707805fa87f2eaf5e4d02 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sat, 26 Jan 2013 16:53:23 +0000 Subject: store choices for recent changes and diff views in cookie (FS#2438 and FS#2700) Note: These changes don't work yet. The cookie is not set and deletes the old one. --- inc/actions.php | 16 ++++++++++++++++ inc/common.php | 26 ++++++++++++++++++++++++++ inc/html.php | 11 ++++++++++- inc/template.php | 6 +++++- 4 files changed, 57 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/actions.php b/inc/actions.php index 4083b0454..e0ad908b7 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -67,6 +67,22 @@ function act_dispatch(){ act_sitemap($ACT); } + //recent changes + if ($ACT == 'recent'){ + $show_changes = $INPUT->str('show_changes'); + if (!empty($show_changes)) { + set_doku_pref('show_changes', $show_changes); + } + } + + //diff + if ($ACT == 'diff'){ + $difftype = $INPUT->str('difftype'); + if (!empty($difftype)) { + set_doku_pref('difftype', $difftype); + } + } + //register if($ACT == 'register' && $INPUT->post->bool('save') && register()){ $ACT = 'login'; diff --git a/inc/common.php b/inc/common.php index bc49e76b2..c74010223 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1560,4 +1560,30 @@ function get_doku_pref($pref, $default) { return $default; } +/** + * Add a preference to the DokuWiki cookie + */ +function set_doku_pref($pref, $val) { + global $conf; + $orig = get_doku_pref($pref, false); + $cookieVal = ''; + + if($orig && ($orig != $val)) { + $parts = explode('#', $_COOKIE['DOKU_PREFS']); + $cnt = count($parts); + for($i = 0; $i < $cnt; $i += 2) { + if($parts[$i] == $pref) { + $parts[$i + 1] = urlencode($val); + } + } + $cookieVal = implode('#', $parts); + } else if (!$orig) { + $cookieVal = $_COOKIE['DOKU_PREFS'].'#'.urlencode($pref).'#'.urlencode($val); + } + + if (!empty($cookieVal)) { + setcookie('DOKU_PREFS', $cookieVal, mktime('+1 year'), DOKU_BASE, '', ($conf['securecookie'] && is_ssl())); + } +} + //Setup VIM: ex: et ts=2 : diff --git a/inc/html.php b/inc/html.php index 5c1c75cf6..444913233 100644 --- a/inc/html.php +++ b/inc/html.php @@ -1088,8 +1088,17 @@ function html_diff($text='',$intro=true,$type=null){ global $REV; global $lang; global $INPUT; + global $INFO; - if(!$type) $type = $INPUT->str('difftype'); + if(!$type) { + $type = $INPUT->str('difftype'); + if (empty($type)) { + $type = get_doku_pref('difftype', $type); + if (empty($type) && $INFO['ismobile']) { + $type = 'inline'; + } + } + } if($type != 'inline') $type = 'sidebyside'; // we're trying to be clever here, revisions to compare can be either diff --git a/inc/template.php b/inc/template.php index 4af35cc2b..aa0fd5c00 100644 --- a/inc/template.php +++ b/inc/template.php @@ -124,7 +124,11 @@ function tpl_content_core() { html_diff(); break; case 'recent': - html_recent($INPUT->extract('first')->int('first'), $INPUT->str('show_changes')); + $show_changes = $INPUT->str('show_changes'); + if (empty($show_changes)) { + $show_changes = get_doku_pref('show_changes', $show_changes); + } + html_recent($INPUT->extract('first')->int('first'), $show_changes); break; case 'index': html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? -- cgit v1.2.3 From c18b2212cfd6c8b085b8f82e0a43fe052c5fb57f Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sat, 26 Jan 2013 17:18:14 +0000 Subject: fixed setting cookie not working --- inc/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/common.php b/inc/common.php index c74010223..e436ec263 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1582,7 +1582,7 @@ function set_doku_pref($pref, $val) { } if (!empty($cookieVal)) { - setcookie('DOKU_PREFS', $cookieVal, mktime('+1 year'), DOKU_BASE, '', ($conf['securecookie'] && is_ssl())); + setcookie('DOKU_PREFS', $cookieVal, strtotime('+1 year'), DOKU_BASE, '', ($conf['securecookie'] && is_ssl())); } } -- cgit v1.2.3 From 50f261f7d8fd4138fab3fca8c9b9eea290a3885b Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sat, 26 Jan 2013 18:24:07 +0100 Subject: Fix set_doku_pref cookie date and value --- inc/common.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/common.php b/inc/common.php index e436ec263..88e60f02c 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1574,15 +1574,16 @@ function set_doku_pref($pref, $val) { for($i = 0; $i < $cnt; $i += 2) { if($parts[$i] == $pref) { $parts[$i + 1] = urlencode($val); + break; } } $cookieVal = implode('#', $parts); } else if (!$orig) { - $cookieVal = $_COOKIE['DOKU_PREFS'].'#'.urlencode($pref).'#'.urlencode($val); + $cookieVal = ($_COOKIE['DOKU_PREFS'] ? $_COOKIE['DOKU_PREFS'].'#' : '').urlencode($pref).'#'.urlencode($val); } if (!empty($cookieVal)) { - setcookie('DOKU_PREFS', $cookieVal, strtotime('+1 year'), DOKU_BASE, '', ($conf['securecookie'] && is_ssl())); + setcookie('DOKU_PREFS', $cookieVal, time()+365*24*3600, DOKU_BASE, '', ($conf['securecookie'] && is_ssl())); } } -- cgit v1.2.3 From c94fb9c2885704fc57d2eaef079f50465715c332 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sun, 3 Feb 2013 17:14:15 +0000 Subject: urldecode DOKU_PREFS cookie values --- inc/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/common.php b/inc/common.php index 88e60f02c..5861e9b90 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1553,7 +1553,7 @@ function get_doku_pref($pref, $default) { $cnt = count($parts); for($i = 0; $i < $cnt; $i += 2) { if($parts[$i] == $pref) { - return $parts[$i + 1]; + return urldecode($parts[$i + 1]); } } } -- cgit v1.2.3 From 66ab63caaa47f880a636d65d332b0faf69f0a77a Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sun, 3 Feb 2013 20:14:15 +0000 Subject: check preferences in cookie against urldecoded key --- inc/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/common.php b/inc/common.php index 5861e9b90..5582838de 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1552,7 +1552,7 @@ function get_doku_pref($pref, $default) { $parts = explode('#', $_COOKIE['DOKU_PREFS']); $cnt = count($parts); for($i = 0; $i < $cnt; $i += 2) { - if($parts[$i] == $pref) { + if(urldecode($parts[$i]) == $pref) { return urldecode($parts[$i + 1]); } } -- cgit v1.2.3 From 02143fe9eb35259159906959a1253735d9df4fe1 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sun, 3 Feb 2013 20:39:04 +0000 Subject: some urldecoding also needed in the cookie setter --- inc/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/common.php b/inc/common.php index 5582838de..2626c0d92 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1572,7 +1572,7 @@ function set_doku_pref($pref, $val) { $parts = explode('#', $_COOKIE['DOKU_PREFS']); $cnt = count($parts); for($i = 0; $i < $cnt; $i += 2) { - if($parts[$i] == $pref) { + if(urldecode($parts[$i]) == $pref) { $parts[$i + 1] = urlencode($val); break; } -- cgit v1.2.3 From 36ec377e95e1b932a063729ea6582386dbafdb91 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 3 Feb 2013 21:06:25 +0000 Subject: update for encoded cookie value & using rawurlencode --- inc/common.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'inc') diff --git a/inc/common.php b/inc/common.php index 2626c0d92..730f4dc80 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1548,12 +1548,14 @@ function valid_input_set($param, $valid_values, $array, $exc = '') { * Read a preference from the DokuWiki cookie */ function get_doku_pref($pref, $default) { - if(strpos($_COOKIE['DOKU_PREFS'], $pref) !== false) { - $parts = explode('#', $_COOKIE['DOKU_PREFS']); + // first, urldecode the cookie value + $doku_prefs = urldecode($_COOKIE['DOKU_PREFS']); + if(strpos($doku_prefs, $pref) !== false) { + $parts = explode('#', $doku_prefs); $cnt = count($parts); for($i = 0; $i < $cnt; $i += 2) { - if(urldecode($parts[$i]) == $pref) { - return urldecode($parts[$i + 1]); + if($parts[$i] == $pref) { + return $parts[$i + 1]; } } } @@ -1562,6 +1564,7 @@ function get_doku_pref($pref, $default) { /** * Add a preference to the DokuWiki cookie + * (remembering $_COOKIE['DOKU_PREFS'] is urlencoded) */ function set_doku_pref($pref, $val) { global $conf; @@ -1571,15 +1574,17 @@ function set_doku_pref($pref, $val) { if($orig && ($orig != $val)) { $parts = explode('#', $_COOKIE['DOKU_PREFS']); $cnt = count($parts); + // urlencode $pref for the comparison + $enc_pref = rawurlencode($pref); for($i = 0; $i < $cnt; $i += 2) { - if(urldecode($parts[$i]) == $pref) { - $parts[$i + 1] = urlencode($val); + if($parts[$i] == $enc_pref) { + $parts[$i + 1] = rawurlencode($val); break; } } $cookieVal = implode('#', $parts); } else if (!$orig) { - $cookieVal = ($_COOKIE['DOKU_PREFS'] ? $_COOKIE['DOKU_PREFS'].'#' : '').urlencode($pref).'#'.urlencode($val); + $cookieVal = ($_COOKIE['DOKU_PREFS'] ? $_COOKIE['DOKU_PREFS'].'#' : '').rawurlencode($pref).'#'.rawurlencode($val); } if (!empty($cookieVal)) { -- cgit v1.2.3 From 646a531a33fe5c5e32a932e2a889c43702505c48 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 3 Feb 2013 21:20:42 +0000 Subject: ensure getter works with keys & values containing '#' --- inc/common.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'inc') diff --git a/inc/common.php b/inc/common.php index 730f4dc80..be369d28a 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1546,16 +1546,16 @@ function valid_input_set($param, $valid_values, $array, $exc = '') { /** * Read a preference from the DokuWiki cookie + * (remembering both keys & values are urlencoded) */ function get_doku_pref($pref, $default) { - // first, urldecode the cookie value - $doku_prefs = urldecode($_COOKIE['DOKU_PREFS']); - if(strpos($doku_prefs, $pref) !== false) { - $parts = explode('#', $doku_prefs); + $enc_pref = urlencode($pref); + if(strpos($_COOKIE['DOKU_PREFS'], $enc_pref) !== false) { + $parts = explode('#', $_COOKIE['DOKU_PREFS']); $cnt = count($parts); for($i = 0; $i < $cnt; $i += 2) { - if($parts[$i] == $pref) { - return $parts[$i + 1]; + if($parts[$i] == $enc_pref) { + return urldecode($parts[$i + 1]); } } } -- cgit v1.2.3