summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Smith <chris@jalakai.co.uk>2013-02-03 13:26:12 -0800
committerChristopher Smith <chris@jalakai.co.uk>2013-02-03 13:26:12 -0800
commit2509b6f19785d4c179c3957c17bdde2e2e9d0149 (patch)
tree4ab13af08e8d769e6ef2931579eae282cc0fff49
parent6ecd102555022984aa926a4d423a98c775a06ca4 (diff)
parent646a531a33fe5c5e32a932e2a889c43702505c48 (diff)
downloadrpg-2509b6f19785d4c179c3957c17bdde2e2e9d0149.tar.gz
rpg-2509b6f19785d4c179c3957c17bdde2e2e9d0149.tar.bz2
Merge pull request #164 from splitbrain/diff_recent_prefs
store choices for recent changes and diff views in cookie
-rw-r--r--inc/actions.php16
-rw-r--r--inc/common.php38
-rw-r--r--inc/html.php11
-rw-r--r--inc/template.php6
4 files changed, 66 insertions, 5 deletions
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 db39affc6..28b527633 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -1551,18 +1551,50 @@ 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) {
- if(strpos($_COOKIE['DOKU_PREFS'], $pref) !== false) {
+ $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]);
}
}
}
return $default;
}
+/**
+ * Add a preference to the DokuWiki cookie
+ * (remembering $_COOKIE['DOKU_PREFS'] is urlencoded)
+ */
+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);
+ // urlencode $pref for the comparison
+ $enc_pref = rawurlencode($pref);
+ for($i = 0; $i < $cnt; $i += 2) {
+ if($parts[$i] == $enc_pref) {
+ $parts[$i + 1] = rawurlencode($val);
+ break;
+ }
+ }
+ $cookieVal = implode('#', $parts);
+ } else if (!$orig) {
+ $cookieVal = ($_COOKIE['DOKU_PREFS'] ? $_COOKIE['DOKU_PREFS'].'#' : '').rawurlencode($pref).'#'.rawurlencode($val);
+ }
+
+ if (!empty($cookieVal)) {
+ setcookie('DOKU_PREFS', $cookieVal, time()+365*24*3600, DOKU_BASE, '', ($conf['securecookie'] && is_ssl()));
+ }
+}
+
//Setup VIM: ex: et ts=2 :
diff --git a/inc/html.php b/inc/html.php
index c8b96cbc0..a48f18bff 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 2c083c964..a5bcabf1e 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?