4 use splitbrain\phpcli\CLI
;
5 use splitbrain\phpcli\Options
;
7 if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__
) . '/../') . '/');
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) {
25 'Remove all languages from the installation, besides the ones specified. English language ' .
29 $options->registerOption(
31 'Comma separated list of languages to keep in addition to English.',
35 $options->registerOption(
37 'Remove all languages except English',
45 * Arguments and options have been parsed when this is run
47 * @param Options $options
50 protected function main(Options
$options) {
51 if($options->getOpt('keep')) {
52 $keep = explode(',', $options->getOpt('keep'));
53 if(!in_array('en', $keep)) $keep[] = 'en';
54 } elseif($options->getOpt('english-only')) {
57 echo $options->help();
61 // Kill all language directories in /inc/lang and /lib/plugins besides those in $langs array
62 $this->stripDirLangs(realpath(dirname(__FILE__
) . '/../inc/lang'), $keep);
63 $this->processExtensions(realpath(dirname(__FILE__
) . '/../lib/plugins'), $keep);
64 $this->processExtensions(realpath(dirname(__FILE__
) . '/../lib/tpl'), $keep);
68 * Strip languages from extensions
70 * @param string $path path to plugin or template dir
71 * @param array $keep_langs languages to keep
73 protected function processExtensions($path, $keep_langs) {
75 $entries = scandir($path);
77 foreach($entries as $entry) {
78 if($entry != "." && $entry != "..") {
79 if(is_dir($path . '/' . $entry)) {
81 $plugin_langs = $path . '/' . $entry . '/lang';
83 if(is_dir($plugin_langs)) {
84 $this->stripDirLangs($plugin_langs, $keep_langs);
93 * Strip languages from path
95 * @param string $path path to lang dir
96 * @param array $keep_langs languages to keep
98 protected function stripDirLangs($path, $keep_langs) {
101 while(($cur_dir = $dir->read()) !== false) {
102 if($cur_dir != '.' and $cur_dir != '..' and is_dir($path . '/' . $cur_dir)) {
104 if(!in_array($cur_dir, $keep_langs, true)) {
105 io_rmdir($path . '/' . $cur_dir, true);
113 $cli = new StripLangsCLI();