4 use splitbrain\phpcli\CLI
;
5 use splitbrain\phpcli\Options
;
7 if (!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__
. '/../') . '/');
8 define('NOSESSION', 1);
9 require_once(DOKU_INC
. 'inc/init.php');
12 * Remove unwanted languages from a DokuWiki install
14 class StripLangsCLI
extends CLI
17 * Register options and arguments on the given $options object
19 * @param Options $options
22 protected function setup(Options
$options)
26 'Remove all languages from the installation, besides the ones specified. English language ' .
30 $options->registerOption(
32 'Comma separated list of languages to keep in addition to English.',
36 $options->registerOption(
38 'Remove all languages except English',
46 * Arguments and options have been parsed when this is run
48 * @param Options $options
51 protected function main(Options
$options)
53 if ($options->getOpt('keep')) {
54 $keep = explode(',', $options->getOpt('keep'));
55 if (!in_array('en', $keep)) $keep[] = 'en';
56 } elseif ($options->getOpt('english-only')) {
59 echo $options->help();
63 // Kill all language directories in /inc/lang and /lib/plugins besides those in $langs array
64 $this->stripDirLangs(realpath(__DIR__
. '/../inc/lang'), $keep);
65 $this->processExtensions(realpath(__DIR__
. '/../lib/plugins'), $keep);
66 $this->processExtensions(realpath(__DIR__
. '/../lib/tpl'), $keep);
70 * Strip languages from extensions
72 * @param string $path path to plugin or template dir
73 * @param array $keep_langs languages to keep
75 protected function processExtensions($path, $keep_langs)
78 $entries = scandir($path);
80 foreach ($entries as $entry) {
81 if ($entry != "." && $entry != "..") {
82 if (is_dir($path . '/' . $entry)) {
83 $plugin_langs = $path . '/' . $entry . '/lang';
85 if (is_dir($plugin_langs)) {
86 $this->stripDirLangs($plugin_langs, $keep_langs);
95 * Strip languages from path
97 * @param string $path path to lang dir
98 * @param array $keep_langs languages to keep
100 protected function stripDirLangs($path, $keep_langs)
104 while (($cur_dir = $dir->read()) !== false) {
105 if ($cur_dir != '.' && $cur_dir != '..' && is_dir($path . '/' . $cur_dir)) {
106 if (!in_array($cur_dir, $keep_langs, true)) {
107 io_rmdir($path . '/' . $cur_dir, true);
115 $cli = new StripLangsCLI();