Skip to content

Commit

Permalink
Merge pull request #164 from splitbrain/diff_recent_prefs
Browse files Browse the repository at this point in the history
store choices for recent changes and diff views in cookie
  • Loading branch information
Chris--S committed Feb 3, 2013
2 parents 6ecd102 + 646a531 commit 2509b6f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
16 changes: 16 additions & 0 deletions inc/actions.php
Expand Up @@ -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';
Expand Down
38 changes: 35 additions & 3 deletions inc/common.php
Expand Up @@ -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 :
11 changes: 10 additions & 1 deletion inc/html.php
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion inc/template.php
Expand Up @@ -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?
Expand Down

0 comments on commit 2509b6f

Please sign in to comment.