summaryrefslogtreecommitdiff
path: root/lib/plugins/safefnrecode
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2011-04-03 21:55:50 +0200
committerAndreas Gohr <andi@splitbrain.org>2011-04-03 21:55:50 +0200
commitb9d65e9d8e82713e04ebf1172d9c94fddb38df83 (patch)
treee0bd252f0b4c754f3ece631ea9290b4543e29710 /lib/plugins/safefnrecode
parentefb973f8a33b893d0a4d46d6b733530833c4ad41 (diff)
downloadrpg-b9d65e9d8e82713e04ebf1172d9c94fddb38df83.tar.gz
rpg-b9d65e9d8e82713e04ebf1172d9c94fddb38df83.tar.bz2
Temporary conversion plugin for new fnencode FS#2197
This plugin converts existing filenames that were stored using the option "safe" in fnencode from using the dot (.) as post_indicator to using a bracket (]) as post_insdicator. It will also add a post_indicator at the end of the file name should it be missing (Bug FS#2122). This plugin needs testing by people using the safe encode option!
Diffstat (limited to 'lib/plugins/safefnrecode')
-rw-r--r--lib/plugins/safefnrecode/action.php68
-rw-r--r--lib/plugins/safefnrecode/plugin.info.txt7
2 files changed, 75 insertions, 0 deletions
diff --git a/lib/plugins/safefnrecode/action.php b/lib/plugins/safefnrecode/action.php
new file mode 100644
index 000000000..6d869c532
--- /dev/null
+++ b/lib/plugins/safefnrecode/action.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * DokuWiki Plugin safefnrecode (Action Component)
+ *
+ * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+
+// must be run within Dokuwiki
+if (!defined('DOKU_INC')) die();
+
+require_once DOKU_PLUGIN.'action.php';
+
+class action_plugin_safefnrecode extends DokuWiki_Action_Plugin {
+
+ public function register(Doku_Event_Handler &$controller) {
+
+ $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'handle_indexer_tasks_run');
+
+ }
+
+ public function handle_indexer_tasks_run(Doku_Event &$event, $param) {
+ global $conf;
+ if($conf['fnencode'] != 'safe') return;
+
+ if(!file_exists($conf['datadir'].'_safefn.recoded')){
+ $this->recode($conf['datadir']);
+ touch($conf['datadir'].'_safefn.recoded');
+ }
+
+ if(!file_exists($conf['olddir'].'_safefn.recoded')){
+ $this->recode($conf['olddir']);
+ touch($conf['olddir'].'_safefn.recoded');
+ }
+
+ if(!file_exists($conf['metadir'].'_safefn.recoded')){
+ $this->recode($conf['metadir']);
+ touch($conf['metadir'].'_safefn.recoded');
+ }
+
+ if(!file_exists($conf['mediadir'].'_safefn.recoded')){
+ $this->recode($conf['metadir']);
+ touch($conf['metadir'].'_safefn.recoded');
+ }
+
+ }
+
+ /**
+ * Recursive function to rename all safe encoded files to use the new
+ * square bracket post indicator
+ */
+ private function recode($dir){
+ $dh = opendir($dir);
+ if(!$dh) return;
+ while (($file = readdir($dh)) !== false) {
+ if($file == '.' || $file == '..') continue; # cur and upper dir
+ if(is_dir("$dir/$file")) $this->recode("$dir/$file"); #recurse
+ if(strpos('%',$file) === false) continue; # no encoding used
+ $new = preg_replace('/(%.*?)\./','\1]',$file); # new post indicator
+ if(preg_match('/%[^\.]+$/',$new)) $new .= ']'; # fix end FS#2122
+ rename("$dir/$file","$dir/$new"); # rename it
+ }
+ closedir($dh);
+ }
+
+}
+
+// vim:ts=4:sw=4:et:
diff --git a/lib/plugins/safefnrecode/plugin.info.txt b/lib/plugins/safefnrecode/plugin.info.txt
new file mode 100644
index 000000000..b1600060c
--- /dev/null
+++ b/lib/plugins/safefnrecode/plugin.info.txt
@@ -0,0 +1,7 @@
+base safefnrecode
+author Andreas Gohr
+email andi@splitbrain.org
+date 2011-04-03
+name safefnrecode plugin
+desc Changes existing page and foldernames for the change in the safe filename encoding
+url http://www.dokuwiki.org/plugin:safefnrecode