From 9ea565a1fb55c747c5a4b95cd51d9037a1b7b378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 26 Mar 2022 15:50:03 +0100 Subject: [PATCH] Source import Imported source code from https://code.google.com/archive/p/querychangelog/ --- admin.php | 416 +++++++++++++++++++++++++++++++++++++ lang/en/lang.php | 47 +++++ lang/en/querychangelog.txt | 10 + lang/fr/lang.php | 47 +++++ lang/fr/querychangelog.txt | 12 ++ style.css | 10 + 6 files changed, 542 insertions(+) create mode 100644 admin.php create mode 100644 lang/en/lang.php create mode 100644 lang/en/querychangelog.txt create mode 100644 lang/fr/lang.php create mode 100644 lang/fr/querychangelog.txt create mode 100644 style.css diff --git a/admin.php b/admin.php new file mode 100644 index 0000000..4176e25 --- /dev/null +++ b/admin.php @@ -0,0 +1,416 @@ + + * @based_on "userhistory" plugin by Ondra Zara + * @based_on "pagemove" plugin by Gary Owen + */ + +if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'admin.php'); +require_once(DOKU_INC.'inc/search.php'); + + +class admin_plugin_querychangelog extends DokuWiki_Admin_Plugin { + var $show_form = true; + var $errors = array(); + var $opts = array(); + var $changes = array(); + + /** + * function constructor + */ + function admin_plugin_querychangelog(){ + // enable direct access to language strings + $this->setupLocale(); + } + + /** + * return some info + */ + function getInfo(){ + return array( + 'author' => 'Vincent de Lagabbe', + 'email' => 'vincent@delagabbe.com', + 'date' => '2009-05-05', + 'name' => 'QueryChangelog', + 'desc' => $this->lang['desc'], + 'url' => 'http://wiki.splitbrain.org/plugin:querychangelog', + ); + } + + function forAdminOnly(){ return false; } + function getMenuText() { + return $this->lang['menu']; + } + + /** + * return sort order for position in admin menu + */ + function getMenuSort() { + return 999; + } + + /** + * handle user request + * + * @author Vincent de Lagabbe + */ + function handle() { + global $lang; + global $ID; + global $opts; + global $conf; + + $opts['ns'] = getNS($ID); + + $opts['startd'] = isset($_REQUEST['startd']) ? $_REQUEST['startd'] : "YYYY-MM-DD HH:MM"; + $opts['endd'] = isset($_REQUEST['endd']) ? $_REQUEST['endd'] : "YYYY-MM-DD HH:MM"; + + if (isset($_REQUEST['base_ns'])) { + if (!checkSecurityToken()) + return; + // get begining date + $date_from = 0; + if ($_REQUEST['qcsd'] == '') { + $date_from = $this->_qc_getstamp($opts['startd']); + if (!$date_from) { + $this->errors[] = $this->lang['qc_err_date']; + } + } + // get ending date + $date_to = time(); + if ($_REQUEST['qced'] == '') { + $date_to = $this->_qc_getstamp($opts['endd']); + if (!$date_to) { + $this->errors[] = $this->lang['qc_err_date']; + } + } + + if ($date_from && $date_to - $date_from <= 0) { + $this->errors[] = $this->lang['qc_err_period']; + } + + // get namespace + $opts['base_ns'] = $_REQUEST['base_ns']; + $base_dir = $this->_ns2path($opts['base_ns']); + if (count($this->errors) == 0) { + // get users + if (!in_array(".", $_REQUEST['qcusers'])) { + $opts['users'] = $_REQUEST['qcusers']; + } + + $opts['major_only'] = $_REQUEST['qcmo'] == ''; + $opts['date_from'] = $date_from; + $opts['date_to'] = $date_to; + $this->changes = $this->_getChanges($base_dir); + $this->show_form = false; + } + } + + } + + /** + * output appropriate html + * + * @author Vincent de Lagabbe + */ + function html() { + global $lang; + global $conf; + global $ID; + global $opts; + global $auth; + + ptln(''); + if ($this->show_form) { + ptln($this->locale_xhtml('querychangelog')); + $this->_qc_form(); + } else { + $href = wl($ID).'?do=admin&page='.$this->getPluginName(); + ptln('

['.$this->lang['qc_back'].']

'); + + // Display the query settings + $start_date = $opts['date_from'] == 0 ? $this->lang['qc_begining'] : strftime($conf['dformat'], $opts['date_from']); + ptln($this->lang['qc_res_from'].': '.$start_date.'
'); + ptln($this->lang['qc_res_to'].': '.strftime($conf['dformat'], $opts['date_to']).'
'); + ptln($this->lang['qc_res_ns'].': '.$opts['base_ns'].'
'); + $str_list = ""; + if (isset($opts['users'])) { + $user_list = $auth->retrieveUsers(); + foreach ($user_list as $user => $info) { + if (in_array($user, $opts['users'])) { + $str_list .= ($info['name'].', '); + } + } + $str_list = substr($str_list, 0, -2); + } else { + $str_list = $this->lang['qc_res_all']; + } + ptln($this->lang['qc_res_users'].': '.$str_list.'
'); + ptln('

'.$this->lang['qc_res_title'].'

'); + + // Display the changelog + if (count($this->changes) == 0) { + ptln($this->lang['qc_res_nc'].'

'); + } else { + $this->_show_changes(); + } + } + ptln(''); + } + + + /** + * show the query changelog form + * + * @author Gary Owen + * @author Vincent de Lagabbe + */ + function _qc_form() { + global $ID; + global $lang; + global $conf; + global $opts; + global $auth; + + ptln('

'); + ptln(' '); + ptln('
'); + formSecurityToken(); + ptln('
'); + // output hidden values to ensure dokuwiki will return back to this plugin + ptln(' '); + ptln(' '); + ptln(' '); + ptln(' '); + + //Show any errors + if (count($this->errors) > 0) { + ptln (''); + } + // Start and End dates Selection + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + + + // NS Selection + $namesp = array( 0 => '' ); //Include root in namespace list + search($namesp,$conf['metadir'],'search_namespaces',$opts); + sort($namesp); + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + + // User(s) selection + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + + // Major changes / all changes switch + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( ' '); + + // Submit + ptln( ' '); + ptln( ' '); + ptln( ' '); + ptln( '
'); + foreach($this->errors as $error) + ptln ($error.'
'); + ptln ('
' ? 'CHECKED' : '').'>
'.$this->lang['qc_begining'].'
 
' ? 'CHECKED' : '').'>
'.$this->lang['qc_now'].'
 
 
 
 
 
' ? 'checked="checked"' : '').'">
 
'); + ptln( '
'); + ptln( '
'); + ptln( '
'); + } + + /** + * Convert namespace to its corresponding path in meta + */ + function _ns2path($ns) { + global $conf ; + + if ($ns == ':' || $ns == '') + return $conf ['metadir'] ; + $ns = trim ($ns, ':') ; + $path = $conf ['metadir'] . '/' . str_replace (':', '/', $ns) ; + + return $path ; + } + + /** + * Convert the user input date into a UNIX timestamps. + * + * @author Vincent de Lagabbe + */ + function _qc_getstamp($str_date) { + $date = array(); + $tstamp = false; + + if (0 == preg_match('/([0-9]{4})-([01][0-9])-([0-3][0-9]) ([0-2][0-9]):([0-6][0-9])/', $str_date, $date)) { + return false; + } + $tstamp = mktime($date[4], $date[5], 0, $date[2], $date[3], $date[1]); + return $tstamp; + } + + /** + * Get the changelogs entries according to the user query + * + * @author Ondra Zara + * @author Vincent de Lagabbe + */ + function _getChanges($base_dir, $user = 0) { + global $conf; + global $opts; + + function globr($dir, $pattern) { + $files = glob($dir.'/'.$pattern); + foreach (glob($dir.'/*', GLOB_ONLYDIR) as $subdir) { + $subfiles = globr($subdir, $pattern); + $files = array_merge($files, $subfiles); + } + return $files; + } + + $changes = array(); + $alllist = globr($base_dir, '*.changes'); + $skip = array('_comments.changes', '_dokuwiki.changes'); + + for ($i = 0; $i < count($alllist); $i++) { + $fullname = $alllist[$i]; + if (in_array(basename($fullname), $skip)) { + continue; + } + $f = file($fullname); + for ($j = 0; $j < count($f); $j++) { + $change = parseChangelogLine($f[$j]); + if ($opts['major_only'] && $change['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) { + continue; + } elseif (isset($opts['users']) && !in_array($change['user'], $opts['users'])) { + continue; + } if ($change['date'] > $opts['date_from'] && + $change['date'] < $opts['date_to']) { + $changes[] = $change; + } + } /* for all lines */ + } /* for all files */ + + function cmp($a,$b) { + $time1 = $a['date']; + $time2 = $b['date']; + if ($time1 == $time2) { return 0; } + return ($time1 < $time2 ? 1 : -1); + } + + uasort($changes, 'cmp'); + + return $changes; + } + + /** + * Display the changes as DK + * + * @author Ondra Zara + * @author Vincent de Lagabbe + */ + function _show_changes() { + global $conf; + global $lang; + + ptln('
'); + ptln(''); + + ptln('
'); + } +} diff --git a/lang/en/lang.php b/lang/en/lang.php new file mode 100644 index 0000000..e98e8a0 --- /dev/null +++ b/lang/en/lang.php @@ -0,0 +1,47 @@ + + */ + +$lang['encoding'] = 'utf-8'; +$lang['direction'] = 'ltr'; + +// for admin plugins, the menu prompt to be displayed in the admin menu +// if set here, the plugin doesn't need to override the getMenuText() method +$lang['menu'] = 'Query Changelog'; +$lang['desc'] = 'Configurable access to the whole changelog'; + +$lang['qc_from'] = 'From'; +$lang['qc_to'] = 'To'; +$lang['qc_date'] = 'Date'; +$lang['qc_begining'] = 'Wiki birth'; +$lang['qc_now'] = 'Now'; + +$lang['qc_base_ns'] = 'Base namespace'; +$lang['qc_root'] = '[Root namespace]'; +$lang['qc_current'] = '(Current)'; + +$lang['qc_users'] = 'From user(s)'; +$lang['qc_all_users'] = '[All]'; + +$lang['qc_major_only'] = 'Skip minor changes'; + +$lang['qc_submit'] = 'Submit'; + +$lang['qc_err_date'] = 'Invalid date'; +$lang['qc_err_period'] = 'Start date must be before end date'; + +$lang['qc_back'] = 'Back'; + +$lang['qc_res_nc'] = 'No changes found'; +$lang['qc_res_title'] = 'Changelog'; +$lang['qc_res_ns'] = 'In namespace'; +$lang['qc_res_from'] = 'Changelog start date'; +$lang['qc_res_to'] = 'Changelog end date'; +$lang['qc_res_users'] = 'From user(s)'; +$lang['qc_res_all'] = 'All'; + +?> diff --git a/lang/en/querychangelog.txt b/lang/en/querychangelog.txt new file mode 100644 index 0000000..695c9e3 --- /dev/null +++ b/lang/en/querychangelog.txt @@ -0,0 +1,10 @@ +===== Query Changlog ===== + +Display the a changelog according to the parameters defined below. + +Date format must be respected, the time is given in 24-hours format +and can be omitted. + +:!: This may take a **very** long time if perfomed on a namespace +containing a lot of pages! (All the '.changes' files within the base +namespace and its subnamespaces are scanned) diff --git a/lang/fr/lang.php b/lang/fr/lang.php new file mode 100644 index 0000000..2bdde99 --- /dev/null +++ b/lang/fr/lang.php @@ -0,0 +1,47 @@ + + */ + +$lang['encoding'] = 'utf-8'; +$lang['direction'] = 'ltr'; + +// for admin plugins, the menu prompt to be displayed in the admin menu +// if set here, the plugin doesn't need to override the getMenuText() method +$lang['menu'] = 'Query Changelog'; +$lang['desc'] = 'Accès paramétrable à tout l\'historique des modifications'; + +$lang['qc_from'] = 'Depuis'; +$lang['qc_to'] = 'Jusqu\'à'; +$lang['qc_date'] = 'Date'; +$lang['qc_begining'] = 'Démarrage du Wiki'; +$lang['qc_now'] = 'Maintenant'; + +$lang['qc_base_ns'] = 'Restreindre au namespace'; +$lang['qc_root'] = '[namespace racine]'; +$lang['qc_current'] = '(Courant)'; + +$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_submit'] = 'Soumettre'; + +$lang['qc_err_date'] = 'Date invalide'; +$lang['qc_err_period'] = 'La date de début doit être avant la date de fin'; + +$lang['qc_back'] = 'Retour'; + +$lang['qc_res_nc'] = 'Aucun changement trouvé'; +$lang['qc_res_title'] = 'Journal des modifications'; +$lang['qc_res_ns'] = 'Dans le namespace'; +$lang['qc_res_from'] = 'Date de début du journal'; +$lang['qc_res_to'] = 'Date de fin du journal'; +$lang['qc_res_users'] = 'Par le(s) utiliateurs'; +$lang['qc_res_all'] = 'Tous'; + +?> diff --git a/lang/fr/querychangelog.txt b/lang/fr/querychangelog.txt new file mode 100644 index 0000000..b5d0f49 --- /dev/null +++ b/lang/fr/querychangelog.txt @@ -0,0 +1,12 @@ +===== Query Changlog ===== + +Affiche un journal des modifications selon les paramètres définis +ci-dessous. + +Le format de date doit être respecté, l'heure entrée en format +24h. Cette dernière peut être omise. + +:!: La génération peut prendre **très** longtemps si elle est +effectuée sur un namespace contenant de nombreuses pages ! (Tous les +fichiers '.changes' du namespace et de ses sous dossiers sont +analysés) diff --git a/style.css b/style.css new file mode 100644 index 0000000..36ddcec --- /dev/null +++ b/style.css @@ -0,0 +1,10 @@ +div.dokuwiki table { + font-size: 100%; + border: 0; +} + +div.dokuwiki tr, +div.dokuwiki td, +div.dokuwiki th { + border: 0; +} \ No newline at end of file