diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/indexer.php | 27 | ||||
-rw-r--r-- | bin/striplangs.php | 148 |
2 files changed, 160 insertions, 15 deletions
diff --git a/bin/indexer.php b/bin/indexer.php index 48e98b571..6ee0a9e8d 100755 --- a/bin/indexer.php +++ b/bin/indexer.php @@ -13,10 +13,6 @@ require_once(DOKU_INC.'inc/auth.php'); require_once(DOKU_INC.'inc/cliopts.php'); session_write_close(); -// Version tag used to force rebuild on upgrade -// Need to keep in sync with lib/exe/indexer.php -if(!defined('INDEXER_VERSION')) define('INDEXER_VERSION', 2); - // handle options $short_opts = 'hcuq'; $long_opts = array('help', 'clear', 'update', 'quiet'); @@ -28,6 +24,7 @@ if ( $OPTS->isError() ) { } $CLEAR = false; $QUIET = false; +$INDEXER = null; foreach ($OPTS->options as $key => $val) { switch ($key) { case 'h': @@ -70,6 +67,9 @@ function _usage() { function _update(){ global $conf; + global $INDEXER; + + $INDEXER = idx_get_indexer(); $data = array(); _quietecho("Searching pages... "); @@ -82,25 +82,21 @@ function _update(){ } function _index($id){ + global $INDEXER; global $CLEAR; + global $QUIET; // if not cleared only update changed and new files - if(!$CLEAR){ + if($CLEAR){ $idxtag = metaFN($id,'.indexed'); if(@file_exists($idxtag)){ - if(io_readFile($idxtag) >= INDEXER_VERSION){ - $last = @filemtime(metaFN($id,'.indexed')); - if($last > @filemtime(wikiFN($id))) return; - } + @unlink($idxtag); } } - _lock(); _quietecho("$id... "); - idx_addPage($id); - io_saveFile(metaFN($id,'.indexed'),INDEXER_VERSION); + idx_addPage($id, !$QUIET); _quietecho("done.\n"); - _unlock(); } /** @@ -145,7 +141,7 @@ function _clearindex(){ _lock(); _quietecho("Clearing index... "); io_saveFile($conf['indexdir'].'/page.idx',''); - io_saveFile($conf['indexdir'].'/title.idx',''); + //io_saveFile($conf['indexdir'].'/title.idx',''); $dir = @opendir($conf['indexdir']); if($dir!==false){ while(($f = readdir($dir)) !== false){ @@ -154,6 +150,7 @@ function _clearindex(){ @unlink($conf['indexdir']."/$f"); } } + @unlink($conf['indexdir'].'/lengths.idx'); _quietecho("done.\n"); _unlock(); } @@ -163,4 +160,4 @@ function _quietecho($msg) { if(!$QUIET) echo $msg; } -//Setup VIM: ex: et ts=2 enc=utf-8 : +//Setup VIM: ex: et ts=2 : diff --git a/bin/striplangs.php b/bin/striplangs.php new file mode 100644 index 000000000..288859c6a --- /dev/null +++ b/bin/striplangs.php @@ -0,0 +1,148 @@ +#!/usr/bin/php +<?php +/** + * Strip unwanted languages from the DokuWiki install + * + * @author Martin 'E.T.' Misuth <et.github@ethome.sk> + */ +if ('cli' != php_sapi_name()) die(); + +#------------------------------------------------------------------------------ +if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); +require_once DOKU_INC.'inc/cliopts.php'; + +#------------------------------------------------------------------------------ +function usage($show_examples = false) { + print "Usage: striplangs.php [-h [-x]] [-e] [-k lang1[,lang2]..[,langN]] + + Removes all languages from the instalation, besides the ones + after the -k option. English language is never removed! + + OPTIONS + -h, --help get this help + -x, --examples get also usage examples + -k, --keep comma separated list of languages, -e is always implied + -e, --english keeps english, dummy to use without -k"; + if ( $show_examples ) { + print "\n + EXAMPLES + Strips all languages, but keeps 'en' and 'de': + striplangs -k de + + Strips all but 'en','ca-valencia','cs','de','is','sk': + striplangs --keep ca-valencia,cs,de,is,sk + + Strips all but 'en': + striplangs -e + + No option specified, prints usage and throws error: + striplangs\n"; + } +} + +function getSuppliedArgument($OPTS, $short, $long) { + $arg = $OPTS->get($short); + if ( is_null($arg) ) { + $arg = $OPTS->get($long); + } + return $arg; +} + +function processPlugins($path, $keep_langs) { + if (is_dir($path)) { + $entries = scandir($path); + + foreach ($entries as $entry) { + if ($entry != "." && $entry != "..") { + if ( is_dir($path.'/'.$entry) ) { + + $plugin_langs = $path.'/'.$entry.'/lang'; + + if ( is_dir( $plugin_langs ) ) { + stripDirLangs($plugin_langs, $keep_langs); + } + } + } + } + } +} + +function stripDirLangs($path, $keep_langs) { + $dir = dir($path); + + while(($cur_dir = $dir->read()) !== false) { + if( $cur_dir != '.' and $cur_dir != '..' and is_dir($path.'/'.$cur_dir)) { + + if ( !in_array($cur_dir, $keep_langs, true ) ) { + killDir($path.'/'.$cur_dir); + } + } + } + $dir->close(); +} + +function killDir($dir) { + if (is_dir($dir)) { + $entries = scandir($dir); + + foreach ($entries as $entry) { + if ($entry != "." && $entry != "..") { + if ( is_dir($dir.'/'.$entry) ) { + killDir($dir.'/'.$entry); + } else { + unlink($dir.'/'.$entry); + } + } + } + reset($entries); + rmdir($dir); + } +} +#------------------------------------------------------------------------------ + +// handle options +$short_opts = 'hxk:e'; +$long_opts = array('help', 'examples', 'keep=','english'); + +$OPTS = Doku_Cli_Opts::getOptions(__FILE__, $short_opts, $long_opts); + +if ( $OPTS->isError() ) { + fwrite( STDERR, $OPTS->getMessage() . "\n"); + exit(1); +} + +// handle '--examples' option +$show_examples = ( $OPTS->has('x') or $OPTS->has('examples') ) ? true : false; + +// handle '--help' option +if ( $OPTS->has('h') or $OPTS->has('help') ) { + usage($show_examples); + exit(0); +} + +// handle both '--keep' and '--english' options +if ( $OPTS->has('k') or $OPTS->has('keep') ) { + $preserved_langs = getSuppliedArgument($OPTS,'k','keep'); + $langs = explode(',', $preserved_langs); + + // ! always enforce 'en' lang when using '--keep' (DW relies on it) + if ( !isset($langs['en']) ) { + $langs[]='en'; + } +} elseif ( $OPTS->has('e') or $OPTS->has('english') ) { + // '--english' was specified strip everything besides 'en' + $langs = array ('en'); +} else { + // no option was specified, print usage but don't do anything as + // this run might not be intented + usage(); + print "\n + ERROR + No option specified, use either -h -x to get more info, + or -e to strip every language besides english.\n"; + exit(1); +} + +// Kill all language directories in /inc/lang and /lib/plugins besides those in $langs array +stripDirLangs(realpath(dirname(__FILE__).'/../inc/lang'), $langs); +processPlugins(realpath(dirname(__FILE__).'/../lib/plugins'), $langs); |