CSV export
* Added checkbox on the main form that causes the plugin to generate a CSV file instead of displaying the results.
This commit is contained in:
parent
014b7cf3fb
commit
5f5b066760
3 changed files with 53 additions and 0 deletions
51
admin.php
51
admin.php
|
@ -110,6 +110,9 @@ class admin_plugin_querychangelog extends DokuWiki_Admin_Plugin {
|
||||||
$this->changes = $this->_getChanges($base_dir);
|
$this->changes = $this->_getChanges($base_dir);
|
||||||
$this->show_form = false;
|
$this->show_form = false;
|
||||||
}
|
}
|
||||||
|
if ($_REQUEST['as_csv']) {
|
||||||
|
$this->_generate_csv();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -263,6 +266,10 @@ class admin_plugin_querychangelog extends DokuWiki_Admin_Plugin {
|
||||||
ptln( ' <td align="right" nowrap><label><span>'.$this->lang['qc_major_only'].':</span></label></td>');
|
ptln( ' <td align="right" nowrap><label><span>'.$this->lang['qc_major_only'].':</span></label></td>');
|
||||||
ptln( ' <td><input type="checkbox" name="qcmo" value="<on>" '.($_REQUEST['qcmo'] == '<on>' ? 'checked="checked"' : '').'"></td>');
|
ptln( ' <td><input type="checkbox" name="qcmo" value="<on>" '.($_REQUEST['qcmo'] == '<on>' ? 'checked="checked"' : '').'"></td>');
|
||||||
ptln( ' </tr>');
|
ptln( ' </tr>');
|
||||||
|
ptln( ' <tr>');
|
||||||
|
ptln( ' <td align="right" nowrap><label><span>'.$this->lang['qc_as_csv'].':</span></label></td>');
|
||||||
|
ptln( ' <td><input type="checkbox" name="as_csv" value="<on>"></td>');
|
||||||
|
ptln( ' </tr>');
|
||||||
ptln( ' <tr><td colspan="5"> </td></tr>');
|
ptln( ' <tr><td colspan="5"> </td></tr>');
|
||||||
|
|
||||||
// Submit
|
// Submit
|
||||||
|
@ -413,4 +420,48 @@ class admin_plugin_querychangelog extends DokuWiki_Admin_Plugin {
|
||||||
|
|
||||||
ptln('</div>');
|
ptln('</div>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate CSV data from the list of changes
|
||||||
|
*
|
||||||
|
* @author Emmanuel Benoît <tseeker@nocternity.net>
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ $lang['qc_users'] = 'From user(s)';
|
||||||
$lang['qc_all_users'] = '[All]';
|
$lang['qc_all_users'] = '[All]';
|
||||||
|
|
||||||
$lang['qc_major_only'] = 'Skip minor changes';
|
$lang['qc_major_only'] = 'Skip minor changes';
|
||||||
|
$lang['qc_as_csv'] = 'Download CSV';
|
||||||
|
|
||||||
$lang['qc_submit'] = 'Submit';
|
$lang['qc_submit'] = 'Submit';
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ $lang['qc_users'] = 'Dûs à(aux) utilisateur(s)';
|
||||||
$lang['qc_all_users'] = '[Tous]';
|
$lang['qc_all_users'] = '[Tous]';
|
||||||
|
|
||||||
$lang['qc_major_only'] = 'Ne pas prendre en compte les changements mineurs';
|
$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';
|
$lang['qc_submit'] = 'Soumettre';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue