3 if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__
).'/../').'/');
4 define('NOSESSION', 1);
5 require_once(DOKU_INC
.'inc/init.php');
9 * Remove unwanted languages from a DokuWiki install
11 class StripLangsCLI
extends DokuCLI
{
14 * Register options and arguments on the given $options object
16 * @param DokuCLI_Options $options
19 protected function setup(DokuCLI_Options
$options) {
22 'Remove all languages from the installation, besides the ones specified. English language '.
26 $options->registerOption(
28 'Comma separated list of languages to keep in addition to English.',
32 $options->registerOption(
34 'Remove all languages except English',
42 * Arguments and options have been parsed when this is run
44 * @param DokuCLI_Options $options
47 protected function main(DokuCLI_Options
$options) {
48 if($options->getOpt('keep')) {
49 $keep = explode(',', $options->getOpt('keep'));
50 if(!in_array('en', $keep)) $keep[] = 'en';
51 } elseif($options->getOpt('english-only')) {
54 echo $options->help();
58 // Kill all language directories in /inc/lang and /lib/plugins besides those in $langs array
59 $this->stripDirLangs(realpath(dirname(__FILE__
).'/../inc/lang'), $keep);
60 $this->processExtensions(realpath(dirname(__FILE__
).'/../lib/plugins'), $keep);
61 $this->processExtensions(realpath(dirname(__FILE__
).'/../lib/tpl'), $keep);
65 * Strip languages from extensions
67 * @param string $path path to plugin or template dir
68 * @param array $keep_langs languages to keep
70 protected function processExtensions($path, $keep_langs) {
72 $entries = scandir($path);
74 foreach($entries as $entry) {
75 if($entry != "." && $entry != "..") {
76 if(is_dir($path.'/'.$entry)) {
78 $plugin_langs = $path.'/'.$entry.'/lang';
80 if(is_dir($plugin_langs)) {
81 $this->stripDirLangs($plugin_langs, $keep_langs);
90 * Strip languages from path
92 * @param string $path path to lang dir
93 * @param array $keep_langs languages to keep
95 protected function stripDirLangs($path, $keep_langs) {
98 while(($cur_dir = $dir->read()) !== false) {
99 if($cur_dir != '.' and $cur_dir != '..' and is_dir($path.'/'.$cur_dir)) {
101 if(!in_array($cur_dir, $keep_langs, true)) {
102 io_rmdir($path.'/'.$cur_dir, true);
110 $cli = new StripLangsCLI();