diff --git a/admin.php b/admin.php index 4176e25..88f2e37 100644 --- a/admin.php +++ b/admin.php @@ -110,6 +110,9 @@ class admin_plugin_querychangelog extends DokuWiki_Admin_Plugin { $this->changes = $this->_getChanges($base_dir); $this->show_form = false; } + if ($_REQUEST['as_csv']) { + $this->_generate_csv(); + } } } @@ -263,6 +266,10 @@ class admin_plugin_querychangelog extends DokuWiki_Admin_Plugin { ptln( ' '); ptln( ' ' ? 'checked="checked"' : '').'">'); ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); ptln( '  '); // Submit @@ -413,4 +420,48 @@ class admin_plugin_querychangelog extends DokuWiki_Admin_Plugin { ptln(''); } + + /** + * Generate CSV data from the list of changes + * + * @author Emmanuel Benoît + */ + function _generate_csv() { + global $conf; + global $lang; + global $auth; + global $ID; + + $titles = []; + $users = []; + $xhtml_renderer = p_get_renderer('xhtml'); + + header('Content-type: text/csv;charset=utf-8'); + header('Content-Disposition: attachment; filename="changes.csv"'); + $fd = fopen('php://output', 'w'); + fputcsv($fd, [ + 'date', 'time', 'minor', 'pageid', 'pagetitle', 'userid', 'username', 'ip' + ]); + foreach($this->changes as $change){ + $id = $change['id']; + $user = $change['user']; + if (!array_key_exists($id, $titles)) { + resolve_pageid(getNS($id), $id, $exists, $change['date'], true); + $titles[$id] = p_get_first_heading($id); + } + if (!array_key_exists($user, $users)) { + $users[$user] = $auth->getUserData($user); + } + fputcsv($fd, [ + strftime('%y-%m-%d', $change['date']), + strftime('%T', $change['date']), + $change['type'] === 'e' ? 'y' : 'n', + $id, $titles[$id], + $user, $users[$user]['name'], + $change['ip'], + ]); + } + fclose($fd); + die; + } } diff --git a/lang/en/lang.php b/lang/en/lang.php index e98e8a0..baaa325 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -28,6 +28,7 @@ $lang['qc_users'] = 'From user(s)'; $lang['qc_all_users'] = '[All]'; $lang['qc_major_only'] = 'Skip minor changes'; +$lang['qc_as_csv'] = 'Download CSV'; $lang['qc_submit'] = 'Submit'; diff --git a/lang/fr/lang.php b/lang/fr/lang.php index 2bdde99..b0df501 100644 --- a/lang/fr/lang.php +++ b/lang/fr/lang.php @@ -28,6 +28,7 @@ $lang['qc_users'] = 'Dûs à(aux) utilisateur(s)'; $lang['qc_all_users'] = '[Tous]'; $lang['qc_major_only'] = 'Ne pas prendre en compte les changements mineurs'; +$lang['qc_as_csv'] = 'Télécharger sous forme de CSV'; $lang['qc_submit'] = 'Soumettre';