From 496e3a6f34d97e44e44340c1fbd2d3cbc262c05c Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 17 Mar 2014 23:03:53 +0100 Subject: completely new base for CLI scripts This introduces an abstract base class that command line tools need to inherit from. It provides a simple framework for registering accepted command line options and provides commonly needed things like help output and colored text. Existing CLI scripts still need to be converted. --- _test/tests/inc/cli_options.test.php | 56 ++++ inc/cli.php | 590 +++++++++++++++++++++++++++++++++++ inc/load.php | 4 + 3 files changed, 650 insertions(+) create mode 100644 _test/tests/inc/cli_options.test.php create mode 100644 inc/cli.php diff --git a/_test/tests/inc/cli_options.test.php b/_test/tests/inc/cli_options.test.php new file mode 100644 index 000000000..1d121d7ce --- /dev/null +++ b/_test/tests/inc/cli_options.test.php @@ -0,0 +1,56 @@ +registerOption('exclude', 'exclude files', 'x', true); + + $args = array('-x', 'foo', 'bang'); + $options->parseOptions($args); + + $this->assertEquals('foo', $options->getOpt('exclude')); + $this->assertEquals(array('bang'), $args); + $this->assertFalse($options->getOpt('nothing')); + } + + function test_simplelong1() { + $options = new DokuCLI_Options(); + $options->registerOption('exclude', 'exclude files', 'x', true); + + $args = array('--exclude', 'foo', 'bang'); + $options->parseOptions($args); + + $this->assertEquals('foo', $options->getOpt('exclude')); + $this->assertEquals(array('bang'), $args); + $this->assertFalse($options->getOpt('nothing')); + } + + function test_simplelong2() { + $options = new DokuCLI_Options(); + $options->registerOption('exclude', 'exclude files', 'x', true); + + $args = array('--exclude=foo', 'bang'); + $options->parseOptions($args); + + $this->assertEquals('foo', $options->getOpt('exclude')); + $this->assertEquals(array('bang'), $args); + $this->assertFalse($options->getOpt('nothing')); + } + + function test_complex() { + $options = new DokuCLI_Options(); + + $options->registerOption('plugins', 'run on plugins only', 'p'); + $options->registerCommand('status', 'display status info'); + $options->registerOption('long', 'display long lines', 'l', false, 'status'); + + $args = array('-p', 'status', '--long', 'foo'); + $options->parseOptions($args); + + $this->assertEquals('status', $options->getCmd()); + $this->assertTrue($options->getOpt('plugins')); + $this->assertTrue($options->getOpt('long')); + $this->assertEquals(array('foo'), $args); + } +} \ No newline at end of file diff --git a/inc/cli.php b/inc/cli.php new file mode 100644 index 000000000..2827ae233 --- /dev/null +++ b/inc/cli.php @@ -0,0 +1,590 @@ + + */ +abstract class DokuCLI { + /** @var string the executed script itself */ + protected $bin; + /** @var array list of non-option arguments */ + protected $args; + /** @var DokuCLI_Options the option parser */ + protected $options; + /** @var DokuCLI_Colors */ + public $colors; + + /** + * constructor + * + * Initialize the arguments, set up helper classes and set up the CLI environment + */ + public function __construct() { + set_exception_handler(array($this, 'fatal')); + + $this->args = $this->readPHPArgv(); + $this->bin = basename(array_shift($this->args)); + + $this->options = new DokuCLI_Options(); + $this->colors = new DokuCLI_Colors(); + } + + /** + * Register options and arguments on the given $options object + * + * @param DokuCLI_Options $options + * @return void + */ + abstract protected function setup(DokuCLI_Options $options); + + /** + * Your main program + * + * Arguments and options have been parsed when this is run + * + * @param DokuCLI_Options $options + * @param array $args + * @return void + */ + abstract protected function main(DokuCLI_Options $options, &$args); + + /** + * Execute the CLI program + * + * Executes the setup() routine, adds default options, initiate the options parsing and argument checking + * and finally executes main() + */ + public function run() { + if('cli' != php_sapi_name()) throw new DokuCLI_Exception('This has to be run from the command line'); + + // setup + $this->setup($this->options); + $this->options->registerOption( + 'no-colors', + 'Do not use any colors in output. Useful when piping output to other tools or files.' + ); + $this->options->registerOption( + 'help', + 'Display this help screen and exit immeadiately.', + 'h' + ); + + // parse + $this->options->parseOptions($this->args); + + // handle defaults + if($this->options->getOpt('no-colors')) { + $this->colors->disable(); + } + if($this->options->getOpt('help')) { + $this->options->help($this->bin); + exit(0); + } + + // check arguments + $this->options->checkArguments($this->args); + + // execute + $this->main($this->options, $this->args); + } + + /** + * Exits the program on a fatal error + * + * @param Exception|string $error either an exception or an error message + */ + public function fatal($error) { + $code = 0; + if(is_a($error, 'Exception')) { + /** @var Exception $error */ + $code = $error->getCode(); + $error = $error->getMessage(); + } + if(!$code) $code = DokuCLI_Exception::E_ANY; + + $this->colors->ptln($error, 'red'); + exit($code); + } + + /** + * Print an error message + * + * @param $string + */ + public function error($string) { + $this->colors->ptln("E: $string", 'red'); + } + + /** + * Print a success message + * + * @param $string + */ + public function success($string) { + $this->colors->ptln("S: $string", 'green'); + } + + /** + * Print an info message + * + * @param $string + */ + public function info($string) { + $this->colors->ptln("I: $string", 'cyan'); + } + + /** + * Safely read the $argv PHP array across different PHP configurations. + * Will take care on register_globals and register_argc_argv ini directives + * + * @throws DokuCLI_Exception + * @return array the $argv PHP array or PEAR error if not registered + */ + private function readPHPArgv() { + global $argv; + if(!is_array($argv)) { + if(!@is_array($_SERVER['argv'])) { + if(!@is_array($GLOBALS['HTTP_SERVER_VARS']['argv'])) { + throw new DokuCLI_Exception( + "Could not read cmd args (register_argc_argv=Off?)", + DOKU_CLI_OPTS_ARG_READ + ); + } + return $GLOBALS['HTTP_SERVER_VARS']['argv']; + } + return $_SERVER['argv']; + } + return $argv; + } +} + +/** + * Class DokuCLI_Colors + * + * Handles color output on (Linux) terminals + * + * @author Andreas Gohr + */ +class DokuCLI_Colors { + /** @var array known color names */ + protected $colors = array( + 'reset' => "\33[0m", + 'black' => "\33[0;30m", + 'darkgray' => "\33[1;30m", + 'blue' => "\33[0;34m", + 'lightblue' => "\33[1;34m", + 'green' => "\33[0;32m", + 'lightgreen' => "\33[1;32m", + 'cyan' => "\33[0;36m", + 'lightcyan' => "\33[1;36m", + 'red' => "\33[0;31m", + 'lightred' => "\33[1;31m", + 'purple' => "\33[0;35m", + 'lightpurple' => "\33[1;35m", + 'brown' => "\33[0;33m", + 'yellow' => "\33[1;33m", + 'lightgray' => "\33[0;37m", + 'white' => "\33[1;37m", + ); + + /** @var bool should colors be used? */ + protected $enabled = true; + + /** + * Constructor + * + * Tries to disable colors for non-terminals + */ + public function __construct() { + if(function_exists('posix_isatty') && !posix_isatty(STDOUT)) { + $this->enabled = false; + return; + } + if(!getenv('TERM')) { + $this->enabled = false; + return; + } + } + + /** + * enable color output + */ + public function enable() { + $this->enabled = true; + } + + /** + * disable color output + */ + public function disable() { + $this->enabled = false; + } + + /** + * Convenience function to print a line in a given color + * + * @param $line + * @param $color + */ + public function ptln($line, $color) { + $this->set($color); + echo rtrim($line) . "\n"; + $this->reset(); + } + + /** + * Set the given color for consecutive output + * + * @param string $color one of the supported color names + * @throws DokuCLI_Exception + */ + public function set($color) { + if(!$this->enabled) return; + if(!isset($this->colors[$color])) throw new DokuCLI_Exception("No such color $color"); + echo $this->colors[$color]; + } + + /** + * reset the terminal color + */ + public function reset() { + $this->set('reset'); + } +} + +/** + * Class DokuCLI_Options + * + * Parses command line options passed to the CLI script. Allows CLI scripts to easily register all accepted options and + * commands and even generates a help text from this setup. + * + * @author Andreas Gohr + */ +class DokuCLI_Options { + /** @var array $setup keeps the list of options to parse */ + protected $setup; + + /** @var array $options store parsed options */ + protected $options; + + protected $command = ''; + + public function __construct() { + $this->setup = array( + '' => array( + 'opts' => array(), + 'args' => array(), + 'help' => '' + ) + ); // default command + + $this->options = array(); + } + + /** + * Sets the help text for the tool itself + * + * @param string $help + */ + public function setHelp($help) { + $this->setup['']['help'] = $help; + } + + /** + * Register the names of arguments for help generation and number checking + * + * This has to be called in the order arguments are expected + * + * @param string $arg argument name (just for help) + * @param string $help help text + * @param bool $required is this a required argument + * @param string $command if theses apply to a sub command only + * @throws DokuCLI_Exception + */ + public function registerArgument($arg, $help, $required = true, $command = '') { + if(!isset($this->setup[$command])) throw new DokuCLI_Exception("Command $command not registered"); + + $this->setup[$command]['args'][] = array( + 'name' => $arg, + 'help' => $help, + 'required' => $required + ); + } + + /** + * This registers a sub command + * + * Sub commands have their own options and use their own function (not main()) + * + * @param string $command + * @param string $help + * @throws DokuCLI_Exception + */ + public function registerCommand($command, $help) { + if(isset($this->setup[$command])) throw new DokuCLI_Exception("Command $command already registered"); + + $this->setup[$command] = array( + 'opts' => array(), + 'args' => array(), + 'help' => $help + ); + + } + + /** + * Register an option for option parsing and help generation + * + * @param string $long multi character option (specified with --) + * @param string $help help text for this option + * @param string|null $short one character option (specified with -) + * @param bool $needsarg does this option require an argument? + * @param string $command what command does this option apply to + * @throws DokuCLI_Exception + */ + public function registerOption($long, $help, $short = null, $needsarg = false, $command = '') { + if(!isset($this->setup[$command])) throw new DokuCLI_Exception("Command $command not registered"); + + $this->setup[$command]['opts'][$long] = array( + 'needsarg' => $needsarg, + 'help' => $help, + 'short' => $short + ); + + if($short) { + if(strlen($short) > 1) throw new DokuCLI_Exception("Short options should be exactly one ASCII character"); + + $this->setup[$command]['short'][$short] = $long; + } + } + + /** + * Checks the actual number of arguments against the required number + * + * Throws an exception if arguments are missing. Called from parseOptions() + * + * @param array $args + * @throws DokuCLI_Exception + */ + public function checkArguments($args) { + $argc = count($args); + + $req = 0; + foreach($this->setup[$this->command]['args'] as $arg) { + if(!$args['required']) break; // last required arguments seen + $req++; + } + + if($req > $argc) throw new DokuCLI_Exception("Not enough arguments", DokuCLI_Exception::E_OPT_ARG_REQUIRED); + } + + /** + * Parses the given arguments for known options and command + * + * The given $args array should NOT contain the executed file as first item anymore! The $args + * array is stripped from any options and possible command. All found otions can be accessed via the + * getOpt() function + * + * Note that command options will overwrite any global options with the same name + * + * @param array $args + * @throws DokuCLI_Exception + */ + public function parseOptions(&$args) { + $non_opts = array(); + + $argc = count($args); + for($i = 0; $i < $argc; $i++) { + $arg = $args[$i]; + + // The special element '--' means explicit end of options. Treat the rest of the arguments as non-options + // and end the loop. + if($arg == '--') { + $non_opts = array_merge($non_opts, array_slice($args, $i + 1)); + break; + } + + // '-' is stdin - a normal argument + if($arg == '-') { + $non_opts = array_merge($non_opts, array_slice($args, $i)); + break; + } + + // first non-option + if($arg{0} != '-') { + $non_opts = array_merge($non_opts, array_slice($args, $i)); + break; + } + + // long option + if(strlen($arg) > 1 && $arg{1} == '-') { + list($opt, $val) = explode('=', substr($arg, 2), 2); + + if(!isset($this->setup[$this->command]['opts'][$opt])) { + throw new DokuCLI_Exception("No such option $arg", DokuCLI_Exception::E_UNKNOWN_OPT); + } + + // argument required? + if($this->setup[$this->command]['opts'][$opt]['needsarg']) { + if(is_null($val) && $i + 1 < $argc && !preg_match('/^--?[\w]/', $args[$i + 1])) { + $val = $args[++$i]; + } + if(is_null($val)) { + throw new DokuCLI_Exception("Option $arg requires an argument", DokuCLI_Exception::E_OPT_ARG_REQUIRED); + } + $this->options[$opt] = $val; + } else { + $this->options[$opt] = true; + } + + continue; + } + + // short option + $opt = substr($arg, 1); + if(!isset($this->setup[$this->command]['short'][$opt])) { + throw new DokuCLI_Exception("No such option $arg", DokuCLI_Exception::E_UNKNOWN_OPT); + } else { + $opt = $this->setup[$this->command]['short'][$opt]; // store it under long name + } + + // argument required? + if($this->setup[$this->command]['opts'][$opt]['needsarg']) { + $val = null; + if($i + 1 < $argc && !preg_match('/^--?[\w]/', $args[$i + 1])) { + $val = $args[++$i]; + } + if(is_null($val)) { + throw new DokuCLI_Exception("Option $arg requires an argument", DokuCLI_Exception::E_OPT_ARG_REQUIRED); + } + $this->options[$opt] = $val; + } else { + $this->options[$opt] = true; + } + } + + // parsing is now done, update args array + $args = $non_opts; + + // if not done yet, check if first argument is a command and reexecute argument parsing if it is + if(!$this->command && $args && isset($this->setup[$args[0]])) { + // it is a command! + $this->command = array_shift($args); + $this->parseOptions($args); // second pass + } + } + + /** + * Get the value of the given option + * + * Please note that all options are accessed by their long option names regardless of how they were + * specified on commandline. + * + * Can only be used after parseOptions() has been run + * + * @param $option + * @return mixed + */ + public function getOpt($option) { + if(isset($this->options[$option])) return $this->options[$option]; + return false; + } + + /** + * Return the found command if any + * + * @return string + */ + public function getCmd() { + return $this->command; + } + + /** + * Builds a help screen from the available options. You may want to call it from -h or on error + * + * @param string $bin name of the script itself + * @return string + */ + public function help($bin) { + $text = ''; + + $hascommands = (count($this->setup) > 1); + foreach($this->setup as $command => $config) { + $hasopts = (bool) $this->setup[$command]['opts']; + $hasargs = (bool) $this->setup[$command]['args']; + + if(!$command) { + $text .= 'USAGE: ' . $bin; + } else { + $text .= "\n$command"; + } + + if($hasopts) $text .= ' '; + foreach($this->setup[$command]['args'] as $arg) { + if($arg['required']) { + $text .= ' <' . $arg['name'] . '>'; + } else { + $text .= ' [<' . $arg['name'] . '>]'; + } + } + $text .= "\n\n"; + + if($this->setup[$command]['help']) { + $text .= ' ' . $this->setup[$command]['help'] . "\n\n"; + } + + if($hasopts) { + $text .= " OPTIONS\n\n"; + + foreach($this->setup[$command]['opts'] as $long => $opt) { + + $name = "--$long"; + if($opt['short']) $name = '-' . $opt['short'] . ' ' . $name; + if($opt['needsarg']) $name .= ' '; + + $text .= sprintf(" %-15s %s\n", $name, $opt['help']); + + } + } + + if($hasargs) { + $text .= " ARGUMENTS\n\n"; + foreach($this->setup[$command]['args'] as $arg) { + $name = '<' . $arg['name'] . '>'; + $text .= sprintf(" %-15s %s\n", $name, $arg['help']); + } + } + + if($command == '' && $hascommands){ + $text .= "\n\nThis tool accepts a command as first parameter as outlined below:\n"; + } + } + + return $text; + } + +} + +/** + * Class DokuCLI_Exception + * + * The code is used as exit code for the CLI tool. This should probably be extended. Many cases just fall back to the + * E_ANY code. + * + * @author Andreas Gohr + */ +class DokuCLI_Exception extends Exception { + const E_ANY = -1; // no error code specified + const E_UNKNOWN_OPT = 1; //Unrecognized option + const E_OPT_ARG_REQUIRED = 2; //Option requires argument + const E_OPT_ARG_DENIED = 3; //Option not allowed argument + const E_OPT_ABIGUOUS = 4; //Option abiguous + const E_ARG_READ = 5; //Could not read argv + + public function __construct($message = "", $code = 0, Exception $previous = null) { + if(!$code) $code = DokuCLI_Exception::E_ANY; + parent::__construct($message, $code, $previous); + } +} diff --git a/inc/load.php b/inc/load.php index f1deffe19..ac2812a0b 100644 --- a/inc/load.php +++ b/inc/load.php @@ -102,6 +102,10 @@ function load_autoload($name){ 'Doku_Renderer_xhtmlsummary' => DOKU_INC.'inc/parser/xhtmlsummary.php', 'Doku_Renderer_metadata' => DOKU_INC.'inc/parser/metadata.php', + 'DokuCLI' => DOKU_INC.'inc/cli.php', + 'DokuCLI_Options' => DOKU_INC.'inc/cli.php', + 'DokuCLI_Colors' => DOKU_INC.'inc/cli.php', + ); if(isset($classes[$name])){ -- cgit v1.2.3 From 9fb664942d6f51d48d02b592980455259907d9a5 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 19 Mar 2014 11:52:22 +0100 Subject: converted git tool to new CLI base --- bin/gittool.php | 231 ++++++++++++++++++++++++++++---------------------------- inc/cli.php | 125 +++++++++++++++--------------- 2 files changed, 181 insertions(+), 175 deletions(-) diff --git a/bin/gittool.php b/bin/gittool.php index f9f68ac94..b429c8d1a 100755 --- a/bin/gittool.php +++ b/bin/gittool.php @@ -3,78 +3,108 @@ if('cli' != php_sapi_name()) die(); ini_set('memory_limit', '128M'); -if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__).'/../').'/'); +if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/'); define('NOSESSION', 1); -require_once(DOKU_INC.'inc/init.php'); +require_once(DOKU_INC . 'inc/init.php'); -$GitToolCLI = new GitToolCLI(); -array_shift($argv); -$command = array_shift($argv); - -switch($command) { - case '': - case 'help': - $GitToolCLI->cmd_help(); - break; - case 'clone': - $GitToolCLI->cmd_clone($argv); - break; - case 'install': - $GitToolCLI->cmd_install($argv); - break; - case 'repo': - case 'repos': - $GitToolCLI->cmd_repos(); - break; - default: - $GitToolCLI->cmd_git($command, $argv); -} /** * Easily manage DokuWiki git repositories * * @author Andreas Gohr */ -class GitToolCLI { - private $color = true; - - public function cmd_help() { - echo << [parameters] - -Manage git repositories for DokuWiki and its plugins and templates. - -EXAMPLE +class GitToolCLI extends DokuCLI { -$> ./bin/gittool.php clone gallery template:ach -$> ./bin/gittool.php repos -$> ./bin/gittool.php origin -v - -COMMANDS + /** + * Register options and arguments on the given $options object + * + * @param DokuCLI_Options $options + * @return void + */ + protected function setup(DokuCLI_Options $options) { + $options->setHelp( + "Manage git repositories for DokuWiki and its plugins and templates.\n\n" . + "EXAMPLE\n\n" . + "$> ./bin/gittool.php clone gallery template:ach\n" . + "$> ./bin/gittool.php repos\n" . + "$> ./bin/gittool.php origin -v\n" + ); -help - This help screen + $options->registerArgument( + 'command', + 'Command to execute. See below', + true + ); -clone - Tries to install a known plugin or template (prefix with template:) via - git. Uses the DokuWiki.org plugin repository to find the proper git - repository. Multiple extensions can be given as parameters + $options->registerCommand( + 'clone', + 'Tries to install a known plugin or template (prefix with template:) via git. Uses the DokuWiki.org ' . + 'plugin repository to find the proper git repository. Multiple extensions can be given as parameters' + ); + $options->registerArgument( + 'extension', + 'name of the extension to install, prefix with \'template:\' for templates', + true, + 'clone' + ); -install - The same as clone, but when no git source repository can be found, the - extension is installed via download + $options->registerCommand( + 'install', + 'The same as clone, but when no git source repository can be found, the extension is installed via ' . + 'download' + ); + $options->registerArgument( + 'extension', + 'name of the extension to install, prefix with \'template:\' for templates', + true, + 'install' + ); -repos - Lists all git repositories found in this DokuWiki installation + $options->registerCommand( + 'repos', + 'Lists all git repositories found in this DokuWiki installation' + ); - - Any unknown commands are assumed to be arguments to git and will be - executed in all repositories found within this DokuWiki installation + $options->registerCommand( + '*', + 'Any unknown commands are assumed to be arguments to git and will be executed in all repositories ' . + 'found within this DokuWiki installation' + ); + } -EOF; + /** + * Your main program + * + * Arguments and options have been parsed when this is run + * + * @param DokuCLI_Options $options + * @return void + */ + protected function main(DokuCLI_Options $options) { + $command = $options->getCmd(); + if(!$command) $command = array_shift($options->args); + + switch($command) { + case '': + echo $options->help('foo'); + break; + case 'clone': + $this->cmd_clone($options->args); + break; + case 'install': + $this->cmd_install($options->args); + break; + case 'repo': + case 'repos': + $this->cmd_repos(); + break; + default: + $this->cmd_git($command, $options->args); + } } + /** * Tries to install the given extensions using git clone * @@ -88,7 +118,7 @@ EOF; $repo = $this->getSourceRepo($ext); if(!$repo) { - $this->msg_error("could not find a repository for $ext"); + $this->error("could not find a repository for $ext"); $errors[] = $ext; } else { if($this->cloneExtension($ext, $repo)) { @@ -100,8 +130,8 @@ EOF; } echo "\n"; - if($succeeded) $this->msg_success('successfully cloned the following extensions: '.join(', ', $succeeded)); - if($errors) $this->msg_error('failed to clone the following extensions: '.join(', ', $errors)); + if($succeeded) $this->success('successfully cloned the following extensions: ' . join(', ', $succeeded)); + if($errors) $this->error('failed to clone the following extensions: ' . join(', ', $errors)); } /** @@ -117,7 +147,7 @@ EOF; $repo = $this->getSourceRepo($ext); if(!$repo) { - $this->msg_info("could not find a repository for $ext"); + $this->info("could not find a repository for $ext"); if($this->downloadExtension($ext)) { $succeeded[] = $ext; } else { @@ -133,8 +163,8 @@ EOF; } echo "\n"; - if($succeeded) $this->msg_success('successfully installed the following extensions: '.join(', ', $succeeded)); - if($errors) $this->msg_error('failed to install the following extensions: '.join(', ', $errors)); + if($succeeded) $this->success('successfully installed the following extensions: ' . join(', ', $succeeded)); + if($errors) $this->error('failed to install the following extensions: ' . join(', ', $errors)); } /** @@ -152,19 +182,19 @@ EOF; foreach($repos as $repo) { if(!@chdir($repo)) { - $this->msg_error("Could not change into $repo"); + $this->error("Could not change into $repo"); continue; } echo "\n"; - $this->msg_info("executing $shell in $repo"); + $this->info("executing $shell in $repo"); $ret = 0; system($shell, $ret); if($ret == 0) { - $this->msg_success("git succeeded in $repo"); + $this->success("git succeeded in $repo"); } else { - $this->msg_error("git failed in $repo"); + $this->error("git failed in $repo"); } } } @@ -193,23 +223,23 @@ EOF; $url = $plugin->getDownloadURL(); if(!$url) { - $this->msg_error("no download URL for $ext"); + $this->error("no download URL for $ext"); return false; } $ok = false; try { - $this->msg_info("installing $ext via download from $url"); + $this->info("installing $ext via download from $url"); $ok = $plugin->installFromURL($url); } catch(Exception $e) { - $this->msg_error($e->getMessage()); + $this->error($e->getMessage()); } if($ok) { - $this->msg_success("installed $ext via download"); + $this->success("installed $ext via download"); return true; } else { - $this->msg_success("failed to install $ext via download"); + $this->success("failed to install $ext via download"); return false; } } @@ -223,19 +253,19 @@ EOF; */ private function cloneExtension($ext, $repo) { if(substr($ext, 0, 9) == 'template:') { - $target = fullpath(tpl_incdir().'../'.substr($ext, 9)); + $target = fullpath(tpl_incdir() . '../' . substr($ext, 9)); } else { - $target = DOKU_PLUGIN.$ext; + $target = DOKU_PLUGIN . $ext; } - $this->msg_info("cloning $ext from $repo to $target"); + $this->info("cloning $ext from $repo to $target"); $ret = 0; system("git clone $repo $target", $ret); if($ret === 0) { - $this->msg_success("cloning of $ext succeeded"); + $this->success("cloning of $ext succeeded"); return true; } else { - $this->msg_error("cloning of $ext failed"); + $this->error("cloning of $ext failed"); return false; } } @@ -248,17 +278,17 @@ EOF; * @return array */ private function findRepos() { - $this->msg_info('Looking for .git directories'); + $this->info('Looking for .git directories'); $data = array_merge( - glob(DOKU_INC.'.git', GLOB_ONLYDIR), - glob(DOKU_PLUGIN.'*/.git', GLOB_ONLYDIR), - glob(fullpath(tpl_incdir().'../').'/*/.git', GLOB_ONLYDIR) + glob(DOKU_INC . '.git', GLOB_ONLYDIR), + glob(DOKU_PLUGIN . '*/.git', GLOB_ONLYDIR), + glob(fullpath(tpl_incdir() . '../') . '/*/.git', GLOB_ONLYDIR) ); if(!$data) { - $this->msg_error('Found no .git directories'); + $this->error('Found no .git directories'); } else { - $this->msg_success('Found '.count($data).' .git directories'); + $this->success('Found ' . count($data) . ' .git directories'); } $data = array_map('fullpath', array_map('dirname', $data)); return $data; @@ -283,7 +313,7 @@ EOF; if(preg_match('/github\.com\/([^\/]+)\/([^\/]+)/i', $repourl, $m)) { $user = $m[1]; $repo = $m[2]; - return 'https://github.com/'.$user.'/'.$repo.'.git'; + return 'https://github.com/' . $user . '/' . $repo . '.git'; } // match gitorious repos @@ -292,49 +322,20 @@ EOF; $repo = $m[2]; if(!$repo) $repo = $user; - return 'https://git.gitorious.org/'.$user.'/'.$repo.'.git'; + return 'https://git.gitorious.org/' . $user . '/' . $repo . '.git'; } // match bitbucket repos - most people seem to use mercurial there though if(preg_match('/bitbucket\.org\/([^\/]+)\/([^\/]+)/i', $repourl, $m)) { $user = $m[1]; $repo = $m[2]; - return 'https://bitbucket.org/'.$user.'/'.$repo.'.git'; + return 'https://bitbucket.org/' . $user . '/' . $repo . '.git'; } return false; } +} - /** - * Print an error message - * - * @param $string - */ - private function msg_error($string) { - if($this->color) echo "\033[31m"; // red - echo "E: $string\n"; - if($this->color) echo "\033[37m"; // reset - } - /** - * Print a success message - * - * @param $string - */ - private function msg_success($string) { - if($this->color) echo "\033[32m"; // green - echo "S: $string\n"; - if($this->color) echo "\033[37m"; // reset - } - - /** - * Print an info message - * - * @param $string - */ - private function msg_info($string) { - if($this->color) echo "\033[36m"; // cyan - echo "I: $string\n"; - if($this->color) echo "\033[37m"; // reset - } -} \ No newline at end of file +$GitToolCLI = new GitToolCLI(); +$GitToolCLI->run(); \ No newline at end of file diff --git a/inc/cli.php b/inc/cli.php index 2827ae233..2cba828f0 100644 --- a/inc/cli.php +++ b/inc/cli.php @@ -10,8 +10,6 @@ abstract class DokuCLI { /** @var string the executed script itself */ protected $bin; - /** @var array list of non-option arguments */ - protected $args; /** @var DokuCLI_Options the option parser */ protected $options; /** @var DokuCLI_Colors */ @@ -25,8 +23,6 @@ abstract class DokuCLI { public function __construct() { set_exception_handler(array($this, 'fatal')); - $this->args = $this->readPHPArgv(); - $this->bin = basename(array_shift($this->args)); $this->options = new DokuCLI_Options(); $this->colors = new DokuCLI_Colors(); @@ -46,10 +42,9 @@ abstract class DokuCLI { * Arguments and options have been parsed when this is run * * @param DokuCLI_Options $options - * @param array $args * @return void */ - abstract protected function main(DokuCLI_Options $options, &$args); + abstract protected function main(DokuCLI_Options $options); /** * Execute the CLI program @@ -73,22 +68,24 @@ abstract class DokuCLI { ); // parse - $this->options->parseOptions($this->args); + $this->options->parseOptions(); // handle defaults if($this->options->getOpt('no-colors')) { $this->colors->disable(); } if($this->options->getOpt('help')) { - $this->options->help($this->bin); + echo $this->options->help($this->bin); exit(0); } // check arguments - $this->options->checkArguments($this->args); + $this->options->checkArguments(); // execute - $this->main($this->options, $this->args); + $this->main($this->options); + + exit(0); } /** @@ -98,7 +95,7 @@ abstract class DokuCLI { */ public function fatal($error) { $code = 0; - if(is_a($error, 'Exception')) { + if(is_object($error) && is_a($error, 'Exception')) { /** @var Exception $error */ $code = $error->getCode(); $error = $error->getMessage(); @@ -136,29 +133,6 @@ abstract class DokuCLI { $this->colors->ptln("I: $string", 'cyan'); } - /** - * Safely read the $argv PHP array across different PHP configurations. - * Will take care on register_globals and register_argc_argv ini directives - * - * @throws DokuCLI_Exception - * @return array the $argv PHP array or PEAR error if not registered - */ - private function readPHPArgv() { - global $argv; - if(!is_array($argv)) { - if(!@is_array($_SERVER['argv'])) { - if(!@is_array($GLOBALS['HTTP_SERVER_VARS']['argv'])) { - throw new DokuCLI_Exception( - "Could not read cmd args (register_argc_argv=Off?)", - DOKU_CLI_OPTS_ARG_READ - ); - } - return $GLOBALS['HTTP_SERVER_VARS']['argv']; - } - return $_SERVER['argv']; - } - return $argv; - } } /** @@ -264,14 +238,21 @@ class DokuCLI_Colors { * @author Andreas Gohr */ class DokuCLI_Options { - /** @var array $setup keeps the list of options to parse */ + /** @var array keeps the list of options to parse */ protected $setup; - /** @var array $options store parsed options */ - protected $options; + /** @var array store parsed options */ + protected $options = array(); + /** @var string current parsed command if any */ protected $command = ''; + /** @var array passed non-option arguments*/ + public $args = array(); + + /** @var string the executed script */ + protected $bin; + public function __construct() { $this->setup = array( '' => array( @@ -281,6 +262,9 @@ class DokuCLI_Options { ) ); // default command + $this->args = $this->readPHPArgv(); + $this->bin = basename(array_shift($this->args)); + $this->options = array(); } @@ -317,7 +301,7 @@ class DokuCLI_Options { /** * This registers a sub command * - * Sub commands have their own options and use their own function (not main()) + * Sub commands have their own options and use their own function (not main()). * * @param string $command * @param string $help @@ -365,15 +349,14 @@ class DokuCLI_Options { * * Throws an exception if arguments are missing. Called from parseOptions() * - * @param array $args * @throws DokuCLI_Exception */ - public function checkArguments($args) { - $argc = count($args); + public function checkArguments() { + $argc = count($this->args); $req = 0; foreach($this->setup[$this->command]['args'] as $arg) { - if(!$args['required']) break; // last required arguments seen + if(!$arg['required']) break; // last required arguments seen $req++; } @@ -389,32 +372,31 @@ class DokuCLI_Options { * * Note that command options will overwrite any global options with the same name * - * @param array $args * @throws DokuCLI_Exception */ - public function parseOptions(&$args) { + public function parseOptions() { $non_opts = array(); - $argc = count($args); + $argc = count($this->args); for($i = 0; $i < $argc; $i++) { - $arg = $args[$i]; + $arg = $this->args[$i]; // The special element '--' means explicit end of options. Treat the rest of the arguments as non-options // and end the loop. if($arg == '--') { - $non_opts = array_merge($non_opts, array_slice($args, $i + 1)); + $non_opts = array_merge($non_opts, array_slice($this->args, $i + 1)); break; } // '-' is stdin - a normal argument if($arg == '-') { - $non_opts = array_merge($non_opts, array_slice($args, $i)); + $non_opts = array_merge($non_opts, array_slice($this->args, $i)); break; } // first non-option if($arg{0} != '-') { - $non_opts = array_merge($non_opts, array_slice($args, $i)); + $non_opts = array_merge($non_opts, array_slice($this->args, $i)); break; } @@ -428,8 +410,8 @@ class DokuCLI_Options { // argument required? if($this->setup[$this->command]['opts'][$opt]['needsarg']) { - if(is_null($val) && $i + 1 < $argc && !preg_match('/^--?[\w]/', $args[$i + 1])) { - $val = $args[++$i]; + if(is_null($val) && $i + 1 < $argc && !preg_match('/^--?[\w]/', $this->args[$i + 1])) { + $val = $this->args[++$i]; } if(is_null($val)) { throw new DokuCLI_Exception("Option $arg requires an argument", DokuCLI_Exception::E_OPT_ARG_REQUIRED); @@ -453,8 +435,8 @@ class DokuCLI_Options { // argument required? if($this->setup[$this->command]['opts'][$opt]['needsarg']) { $val = null; - if($i + 1 < $argc && !preg_match('/^--?[\w]/', $args[$i + 1])) { - $val = $args[++$i]; + if($i + 1 < $argc && !preg_match('/^--?[\w]/', $this->args[$i + 1])) { + $val = $this->args[++$i]; } if(is_null($val)) { throw new DokuCLI_Exception("Option $arg requires an argument", DokuCLI_Exception::E_OPT_ARG_REQUIRED); @@ -466,13 +448,13 @@ class DokuCLI_Options { } // parsing is now done, update args array - $args = $non_opts; + $this->args = $non_opts; // if not done yet, check if first argument is a command and reexecute argument parsing if it is - if(!$this->command && $args && isset($this->setup[$args[0]])) { + if(!$this->command && $this->args && isset($this->setup[$this->args[0]]) ) { // it is a command! - $this->command = array_shift($args); - $this->parseOptions($args); // second pass + $this->command = array_shift($this->args); + $this->parseOptions(); // second pass } } @@ -504,10 +486,9 @@ class DokuCLI_Options { /** * Builds a help screen from the available options. You may want to call it from -h or on error * - * @param string $bin name of the script itself * @return string */ - public function help($bin) { + public function help() { $text = ''; $hascommands = (count($this->setup) > 1); @@ -516,7 +497,7 @@ class DokuCLI_Options { $hasargs = (bool) $this->setup[$command]['args']; if(!$command) { - $text .= 'USAGE: ' . $bin; + $text .= 'USAGE: ' . $this->bin; } else { $text .= "\n$command"; } @@ -565,6 +546,30 @@ class DokuCLI_Options { return $text; } + /** + * Safely read the $argv PHP array across different PHP configurations. + * Will take care on register_globals and register_argc_argv ini directives + * + * @throws DokuCLI_Exception + * @return array the $argv PHP array or PEAR error if not registered + */ + private function readPHPArgv() { + global $argv; + if(!is_array($argv)) { + if(!@is_array($_SERVER['argv'])) { + if(!@is_array($GLOBALS['HTTP_SERVER_VARS']['argv'])) { + throw new DokuCLI_Exception( + "Could not read cmd args (register_argc_argv=Off?)", + DOKU_CLI_OPTS_ARG_READ + ); + } + return $GLOBALS['HTTP_SERVER_VARS']['argv']; + } + return $_SERVER['argv']; + } + return $argv; + } + } /** -- cgit v1.2.3 From ae1ce4a68df467af30fafe2e47a3c11983d7f8be Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 19 Mar 2014 22:56:29 +0100 Subject: wrap help texts to fit typial terminal width --- bin/gittool.php | 5 +---- inc/cli.php | 67 +++++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/bin/gittool.php b/bin/gittool.php index b429c8d1a..cb4ef3484 100755 --- a/bin/gittool.php +++ b/bin/gittool.php @@ -8,7 +8,6 @@ define('NOSESSION', 1); require_once(DOKU_INC . 'inc/init.php'); - /** * Easily manage DokuWiki git repositories * @@ -25,10 +24,9 @@ class GitToolCLI extends DokuCLI { protected function setup(DokuCLI_Options $options) { $options->setHelp( "Manage git repositories for DokuWiki and its plugins and templates.\n\n" . - "EXAMPLE\n\n" . "$> ./bin/gittool.php clone gallery template:ach\n" . "$> ./bin/gittool.php repos\n" . - "$> ./bin/gittool.php origin -v\n" + "$> ./bin/gittool.php origin -v" ); $options->registerArgument( @@ -104,7 +102,6 @@ class GitToolCLI extends DokuCLI { } } - /** * Tries to install the given extensions using git clone * diff --git a/inc/cli.php b/inc/cli.php index 2cba828f0..6380c9174 100644 --- a/inc/cli.php +++ b/inc/cli.php @@ -23,7 +23,6 @@ abstract class DokuCLI { public function __construct() { set_exception_handler(array($this, 'fatal')); - $this->options = new DokuCLI_Options(); $this->colors = new DokuCLI_Colors(); } @@ -247,7 +246,7 @@ class DokuCLI_Options { /** @var string current parsed command if any */ protected $command = ''; - /** @var array passed non-option arguments*/ + /** @var array passed non-option arguments */ public $args = array(); /** @var string the executed script */ @@ -451,7 +450,7 @@ class DokuCLI_Options { $this->args = $non_opts; // if not done yet, check if first argument is a command and reexecute argument parsing if it is - if(!$this->command && $this->args && isset($this->setup[$this->args[0]]) ) { + if(!$this->command && $this->args && isset($this->setup[$this->args[0]])) { // it is a command! $this->command = array_shift($this->args); $this->parseOptions(); // second pass @@ -502,7 +501,6 @@ class DokuCLI_Options { $text .= "\n$command"; } - if($hasopts) $text .= ' '; foreach($this->setup[$command]['args'] as $arg) { if($arg['required']) { $text .= ' <' . $arg['name'] . '>'; @@ -510,36 +508,45 @@ class DokuCLI_Options { $text .= ' [<' . $arg['name'] . '>]'; } } - $text .= "\n\n"; + $text .= "\n"; if($this->setup[$command]['help']) { - $text .= ' ' . $this->setup[$command]['help'] . "\n\n"; + $text .= "\n"; + $text .= $this->tableFormat( + array(2, 72), + array('', $this->setup[$command]['help'] . "\n") + ); } if($hasopts) { - $text .= " OPTIONS\n\n"; - + $text .= "\n"; foreach($this->setup[$command]['opts'] as $long => $opt) { $name = "--$long"; if($opt['short']) $name = '-' . $opt['short'] . ' ' . $name; if($opt['needsarg']) $name .= ' '; - $text .= sprintf(" %-15s %s\n", $name, $opt['help']); - + $text .= $this->tableFormat( + array(2, 20, 52), + array('', $name, $opt['help']) + ); } } if($hasargs) { - $text .= " ARGUMENTS\n\n"; + $text .= "\n"; foreach($this->setup[$command]['args'] as $arg) { $name = '<' . $arg['name'] . '>'; - $text .= sprintf(" %-15s %s\n", $name, $arg['help']); + + $text .= $this->tableFormat( + array(2, 20, 52), + array('', $name, $arg['help']) + ); } } - if($command == '' && $hascommands){ - $text .= "\n\nThis tool accepts a command as first parameter as outlined below:\n"; + if($command == '' && $hascommands) { + $text .= "\nThis tool accepts a command as first parameter as outlined below:\n"; } } @@ -570,6 +577,38 @@ class DokuCLI_Options { return $argv; } + /** + * Displays text in multiple word wrapped columns + * + * @param array $widths list of column widths (in characters) + * @param array $texts list of texts for each column + * @return string + */ + private function tableFormat($widths, $texts) { + $wrapped = array(); + $maxlen = 0; + + foreach($widths as $col => $width) { + $wrapped[$col] = explode("\n", wordwrap($texts[$col], $width - 1, true)); // -1 char border + $len = count($wrapped[$col]); + if($len > $maxlen) $maxlen = $len; + + } + + $out = ''; + for($i = 0; $i < $maxlen; $i++) { + foreach($widths as $col => $width) { + if(isset($wrapped[$col][$i])) { + $val = $wrapped[$col][$i]; + } else { + $val = ''; + } + $out .= sprintf('%-' . $width . 's', $val); + } + $out .= "\n"; + } + return $out; + } } /** -- cgit v1.2.3 From 193eb41176fb95f01489814bcc879dc500257c84 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 20 Mar 2014 19:41:27 +0100 Subject: fixed broken wordwrapping --- inc/cli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/cli.php b/inc/cli.php index 6380c9174..e8c2c9f3e 100644 --- a/inc/cli.php +++ b/inc/cli.php @@ -589,7 +589,7 @@ class DokuCLI_Options { $maxlen = 0; foreach($widths as $col => $width) { - $wrapped[$col] = explode("\n", wordwrap($texts[$col], $width - 1, true)); // -1 char border + $wrapped[$col] = explode("\n", wordwrap($texts[$col], $width - 1, "\n", true)); // -1 char border $len = count($wrapped[$col]); if($len > $maxlen) $maxlen = $len; -- cgit v1.2.3 From 99c6702358b65e9f98d1799d261b4dcc7b88d414 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 20 Mar 2014 19:43:48 +0100 Subject: removed superflous argument --- inc/cli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/cli.php b/inc/cli.php index e8c2c9f3e..84aad3411 100644 --- a/inc/cli.php +++ b/inc/cli.php @@ -74,7 +74,7 @@ abstract class DokuCLI { $this->colors->disable(); } if($this->options->getOpt('help')) { - echo $this->options->help($this->bin); + echo $this->options->help(); exit(0); } -- cgit v1.2.3 From b0b7909bdd454e9614f4ffe34f384b0da0ce4585 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 20 Mar 2014 20:55:57 +0100 Subject: converted some more CLI tools, minor CLI class updates --- bin/gittool.php | 10 +--- bin/indexer.php | 176 ++++++++++++++++++++++++++++---------------------------- bin/render.php | 92 ++++++++++++++--------------- inc/cli.php | 25 +++++--- 4 files changed, 152 insertions(+), 151 deletions(-) diff --git a/bin/gittool.php b/bin/gittool.php index cb4ef3484..fca76768d 100755 --- a/bin/gittool.php +++ b/bin/gittool.php @@ -1,13 +1,9 @@ #!/usr/bin/php run(); \ No newline at end of file +// Main +$cli = new GitToolCLI(); +$cli->run(); \ No newline at end of file diff --git a/bin/indexer.php b/bin/indexer.php index 6f6b5d9fa..76269f95a 100755 --- a/bin/indexer.php +++ b/bin/indexer.php @@ -1,98 +1,100 @@ #!/usr/bin/php isError() ) { - fwrite( STDERR, $OPTS->getMessage() . "\n"); - _usage(); - exit(1); -} -$CLEAR = false; -$QUIET = false; -$INDEXER = null; -foreach ($OPTS->options as $key => $val) { - switch ($key) { - case 'h': - case 'help': - _usage(); - exit; - case 'c': - case 'clear': - $CLEAR = true; - break; - case 'q': - case 'quiet': - $QUIET = true; - break; +if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/'); +define('NOSESSION', 1); +require_once(DOKU_INC . 'inc/init.php'); + +class IndexerCLI extends DokuCLI { + + private $quiet = false; + private $clear = false; + + /** + * Register options and arguments on the given $options object + * + * @param DokuCLI_Options $options + * @return void + */ + protected function setup(DokuCLI_Options $options) { + $options->setHelp( + 'Updates the searchindex by indexing all new or changed pages. When the -c option is ' . + 'given the index is cleared first.' + ); + + $options->registerOption( + 'clear', + 'clear the index before updating', + 'c' + ); + $options->registerOption( + 'quiet', + 'don\'t produce any output', + 'q' + ); } -} - -#------------------------------------------------------------------------------ -# Action - -if($CLEAR) _clearindex(); -_update(); - - - -#------------------------------------------------------------------------------ - -function _usage() { - print "Usage: indexer.php - - Updates the searchindex by indexing all new or changed pages - when the -c option is given the index is cleared first. - OPTIONS - -h, --help show this help and exit - -c, --clear clear the index before updating - -q, --quiet don't produce any output -"; -} - -function _update(){ - global $conf; - $data = array(); - _quietecho("Searching pages... "); - search($data,$conf['datadir'],'search_allpages',array('skipacl' => true)); - _quietecho(count($data)." pages found.\n"); - - foreach($data as $val){ - _index($val['id']); + /** + * Your main program + * + * Arguments and options have been parsed when this is run + * + * @param DokuCLI_Options $options + * @return void + */ + protected function main(DokuCLI_Options $options) { + $this->clear = $options->getOpt('clear'); + $this->quiet = $options->getOpt('quiet'); + + if($this->clear) $this->clearindex(); + + $this->update(); } -} -function _index($id){ - global $CLEAR; - global $QUIET; + /** + * Update the index + */ + function update() { + global $conf; + $data = array(); + $this->quietecho("Searching pages... "); + search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true)); + $this->quietecho(count($data) . " pages found.\n"); + + foreach($data as $val) { + $this->index($val['id']); + } + } - _quietecho("$id... "); - idx_addPage($id, !$QUIET, $CLEAR); - _quietecho("done.\n"); -} + /** + * Index the given page + * + * @param string $id + */ + function index($id) { + $this->quietecho("$id... "); + idx_addPage($id, !$this->quiet, $this->clear); + $this->quietecho("done.\n"); + } -/** - * Clear all index files - */ -function _clearindex(){ - _quietecho("Clearing index... "); - idx_get_indexer()->clear(); - _quietecho("done.\n"); -} + /** + * Clear all index files + */ + function clearindex() { + $this->quietecho("Clearing index... "); + idx_get_indexer()->clear(); + $this->quietecho("done.\n"); + } -function _quietecho($msg) { - global $QUIET; - if(!$QUIET) echo $msg; + /** + * Print message if not supressed + * + * @param string $msg + */ + function quietecho($msg) { + if(!$this->quiet) echo $msg; + } } -//Setup VIM: ex: et ts=2 : +// Main +$cli = new IndexerCLI(); +$cli->run(); \ No newline at end of file diff --git a/bin/render.php b/bin/render.php index d30ef2958..01fd16cdd 100755 --- a/bin/render.php +++ b/bin/render.php @@ -1,5 +1,10 @@ #!/usr/bin/php */ -if ('cli' != php_sapi_name()) die(); - -ini_set('memory_limit','128M'); -if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); -define('NOSESSION',1); -require_once(DOKU_INC.'inc/init.php'); -require_once(DOKU_INC.'inc/common.php'); -require_once(DOKU_INC.'inc/parserutils.php'); -require_once(DOKU_INC.'inc/cliopts.php'); +class RenderCLI extends DokuCLI { -// handle options -$short_opts = 'hr:'; -$long_opts = array('help','renderer:'); -$OPTS = Doku_Cli_Opts::getOptions(__FILE__,$short_opts,$long_opts); -if ( $OPTS->isError() ) { - fwrite( STDERR, $OPTS->getMessage() . "\n"); - _usage(); - exit(1); -} -$RENDERER = 'xhtml'; -foreach ($OPTS->options as $key => $val) { - switch ($key) { - case 'h': - case 'help': - _usage(); - exit; - case 'r': - case 'renderer': - $RENDERER = $val; + /** + * Register options and arguments on the given $options object + * + * @param DokuCLI_Options $options + * @return void + */ + protected function setup(DokuCLI_Options $options) { + $options->setHelp( + 'A simple commandline tool to render some DokuWiki syntax with a given renderer.' . + "\n\n" . + 'This may not work for plugins that expect a certain environment to be ' . + 'set up before rendering, but should work for most or even all standard ' . + 'DokuWiki markup' + ); + $options->registerOption('renderer', 'The renderer mode to use. Defaults to xhtml', 'r', 'mode'); } -} - -// do the action -$source = stream_get_contents(STDIN); -$info = array(); -$result = p_render($RENDERER,p_get_instructions($source),$info); -if(is_null($result)) die("No such renderer $RENDERER\n"); -echo $result; + /** + * Your main program + * + * Arguments and options have been parsed when this is run + * + * @param DokuCLI_Options $options + * @throws DokuCLI_Exception + * @return void + */ + protected function main(DokuCLI_Options $options) { + $renderer = $options->getOpt('renderer', 'xhtml'); -/** - * Print usage info - */ -function _usage(){ - print "Usage: render.php - - Reads DokuWiki syntax from STDIN and renders it with the given renderer - to STDOUT - - OPTIONS - -h, --help show this help and exit - -r, --renderer the render mode (default: xhtml) -"; + // do the action + $source = stream_get_contents(STDIN); + $info = array(); + $result = p_render($renderer, p_get_instructions($source), $info); + if(is_null($result)) throw new DokuCLI_Exception("No such renderer $renderer"); + echo $result; + } } + +// Main +$cli = new RenderCLI(); +$cli->run(); \ No newline at end of file diff --git a/inc/cli.php b/inc/cli.php index 84aad3411..c51d9b7d2 100644 --- a/inc/cli.php +++ b/inc/cli.php @@ -323,7 +323,7 @@ class DokuCLI_Options { * @param string $long multi character option (specified with --) * @param string $help help text for this option * @param string|null $short one character option (specified with -) - * @param bool $needsarg does this option require an argument? + * @param bool|string $needsarg does this option require an argument? give it a name here * @param string $command what command does this option apply to * @throws DokuCLI_Exception */ @@ -465,12 +465,13 @@ class DokuCLI_Options { * * Can only be used after parseOptions() has been run * - * @param $option + * @param string $option + * @param mixed $default what to return if the option was not set * @return mixed */ - public function getOpt($option) { + public function getOpt($option, $default = false) { if(isset($this->options[$option])) return $this->options[$option]; - return false; + return $default; } /** @@ -501,6 +502,8 @@ class DokuCLI_Options { $text .= "\n$command"; } + if($hasopts) $text .= ' '; + foreach($this->setup[$command]['args'] as $arg) { if($arg['required']) { $text .= ' <' . $arg['name'] . '>'; @@ -519,17 +522,23 @@ class DokuCLI_Options { } if($hasopts) { - $text .= "\n"; + $text .= "\n OPTIONS\n\n"; foreach($this->setup[$command]['opts'] as $long => $opt) { - $name = "--$long"; - if($opt['short']) $name = '-' . $opt['short'] . ' ' . $name; - if($opt['needsarg']) $name .= ' '; + $name = ''; + if($opt['short']) { + $name .= '-' . $opt['short']; + if($opt['needsarg']) $name .= ' <'.$opt['needsarg'].'>'; + $name .= ', '; + } + $name .= "--$long"; + if($opt['needsarg']) $name .= ' <'.$opt['needsarg'].'>'; $text .= $this->tableFormat( array(2, 20, 52), array('', $name, $opt['help']) ); + $text .= "\n"; } } -- cgit v1.2.3 From d48bcdb42c1e80fa258ebbd70d9fe6f649237a78 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 20 Mar 2014 21:01:06 +0100 Subject: fixed tests --- _test/tests/inc/cli_options.test.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/_test/tests/inc/cli_options.test.php b/_test/tests/inc/cli_options.test.php index 1d121d7ce..ab03ee29b 100644 --- a/_test/tests/inc/cli_options.test.php +++ b/_test/tests/inc/cli_options.test.php @@ -4,37 +4,37 @@ class cli_options extends DokuWikiTest { function test_simpleshort() { $options = new DokuCLI_Options(); - $options->registerOption('exclude', 'exclude files', 'x', true); + $options->registerOption('exclude', 'exclude files', 'x', 'file'); - $args = array('-x', 'foo', 'bang'); - $options->parseOptions($args); + $options->args = array('-x', 'foo', 'bang'); + $options->parseOptions(); $this->assertEquals('foo', $options->getOpt('exclude')); - $this->assertEquals(array('bang'), $args); + $this->assertEquals(array('bang'), $options->args); $this->assertFalse($options->getOpt('nothing')); } function test_simplelong1() { $options = new DokuCLI_Options(); - $options->registerOption('exclude', 'exclude files', 'x', true); + $options->registerOption('exclude', 'exclude files', 'x', 'file'); - $args = array('--exclude', 'foo', 'bang'); - $options->parseOptions($args); + $options->args = array('--exclude', 'foo', 'bang'); + $options->parseOptions(); $this->assertEquals('foo', $options->getOpt('exclude')); - $this->assertEquals(array('bang'), $args); + $this->assertEquals(array('bang'), $options->args); $this->assertFalse($options->getOpt('nothing')); } function test_simplelong2() { $options = new DokuCLI_Options(); - $options->registerOption('exclude', 'exclude files', 'x', true); + $options->registerOption('exclude', 'exclude files', 'x', 'file'); - $args = array('--exclude=foo', 'bang'); - $options->parseOptions($args); + $options->args = array('--exclude=foo', 'bang'); + $options->parseOptions(); $this->assertEquals('foo', $options->getOpt('exclude')); - $this->assertEquals(array('bang'), $args); + $this->assertEquals(array('bang'), $options->args); $this->assertFalse($options->getOpt('nothing')); } @@ -45,12 +45,12 @@ class cli_options extends DokuWikiTest { $options->registerCommand('status', 'display status info'); $options->registerOption('long', 'display long lines', 'l', false, 'status'); - $args = array('-p', 'status', '--long', 'foo'); - $options->parseOptions($args); + $options->args = array('-p', 'status', '--long', 'foo'); + $options->parseOptions(); $this->assertEquals('status', $options->getCmd()); $this->assertTrue($options->getOpt('plugins')); $this->assertTrue($options->getOpt('long')); - $this->assertEquals(array('foo'), $args); + $this->assertEquals(array('foo'), $options->args); } } \ No newline at end of file -- cgit v1.2.3 From 352ec8ce2a661a326f2f6cb747d43bb60119fb3e Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 22 Mar 2014 16:45:54 +0100 Subject: refactored bin/striplangs.php to new CLI interface --- bin/striplangs.php | 215 ++++++++++++++++++++++------------------------------- 1 file changed, 87 insertions(+), 128 deletions(-) diff --git a/bin/striplangs.php b/bin/striplangs.php index 2bfddcea4..8567551ec 100755 --- a/bin/striplangs.php +++ b/bin/striplangs.php @@ -1,148 +1,107 @@ #!/usr/bin/php - */ -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 installation, 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\n"; - 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); +if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/'); +define('NOSESSION', 1); +require_once(DOKU_INC . 'inc/init.php'); + + +class StripLangsCLI extends DokuCLI { + + /** + * Register options and arguments on the given $options object + * + * @param DokuCLI_Options $options + * @return void + */ + protected function setup(DokuCLI_Options $options) { + + $options->setHelp( + 'Remove all languages from the installation, besides the ones specified. English language ' . + 'is never removed!' + ); + + $options->registerOption( + 'keep', + 'Comma separated list of languages to keep in addition to English.', + 'k' + ); + $options->registerOption( + 'english-only', + 'Remove all languages except English', + 'e' + ); } - 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) ) { + /** + * Your main program + * + * Arguments and options have been parsed when this is run + * + * @param DokuCLI_Options $options + * @return void + */ + protected function main(DokuCLI_Options $options) { + if($options->getOpt('keep')) { + $keep = explode(',', $options->getOpt('keep')); + if(!in_array('en', $keep)) $keep[] = 'en'; + } elseif($options->getOpt('english-only')) { + $keep = array('en'); + } else { + echo $options->help(); + exit(0); + } - $plugin_langs = $path.'/'.$entry.'/lang'; + // Kill all language directories in /inc/lang and /lib/plugins besides those in $langs array + $this->stripDirLangs(realpath(dirname(__FILE__) . '/../inc/lang'), $keep); + $this->processExtensions(realpath(dirname(__FILE__) . '/../lib/plugins'), $keep); + $this->processExtensions(realpath(dirname(__FILE__) . '/../lib/tpl'), $keep); + } - if ( is_dir( $plugin_langs ) ) { - stripDirLangs($plugin_langs, $keep_langs); + /** + * Strip languages from extensions + * + * @param string $path path to plugin or template dir + * @param array $keep_langs languages to keep + */ + protected function processExtensions($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)) { + $this->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)) { + /** + * Strip languages from path + * + * @param string $path path to lang dir + * @param array $keep_langs languages to keep + */ + protected function stripDirLangs($path, $keep_langs) { + $dir = dir($path); - if ( !in_array($cur_dir, $keep_langs, true ) ) { - killDir($path.'/'.$cur_dir); - } - } - } - $dir->close(); -} + while(($cur_dir = $dir->read()) !== false) { + if($cur_dir != '.' and $cur_dir != '..' and is_dir($path . '/' . $cur_dir)) { -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); + if(!in_array($cur_dir, $keep_langs, true)) { + io_rmdir($path . '/' . $cur_dir, true); } } } - 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'; + $dir->close(); } -} 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); +$cli = new StripLangsCLI(); +$cli->run(); \ No newline at end of file -- cgit v1.2.3 From e8bb93a50f98b9389d6bdca6124744208cde7728 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 22 Mar 2014 17:23:06 +0100 Subject: refactored bin/wantedpages.php to new CLI interface --- bin/wantedpages.php | 220 ++++++++++++++++++++++++++-------------------------- 1 file changed, 108 insertions(+), 112 deletions(-) diff --git a/bin/wantedpages.php b/bin/wantedpages.php index afcb6b271..879291957 100755 --- a/bin/wantedpages.php +++ b/bin/wantedpages.php @@ -1,134 +1,130 @@ #!/usr/bin/php setHelp( + 'Outputs a list of wanted pages (pages which have internal links but do not yet exist).' + ); + $options->registerArgument( + 'namespace', + 'The namespace to lookup. Defaults to root namespace', + false + ); + } -#------------------------------------------------------------------------------ -function usage() { - print "Usage: wantedpages.php [wiki:namespace] + /** + * Your main program + * + * Arguments and options have been parsed when this is run + * + * @param DokuCLI_Options $options + * @return void + */ + protected function main(DokuCLI_Options $options) { + + if($options->args) { + $startdir = dirname(wikiFN($options->args[0] . ':xxx')); + } else { + $startdir = dirname(wikiFN('xxx')); + } - Outputs a list of wanted pages (pages which have - internal links but do not yet exist). + $this->info("searching $startdir"); - If the optional [wiki:namespace] is not provided, - defaults to the root wiki namespace + $wanted_pages = array(); - OPTIONS - -h, --help get help -"; -} - -#------------------------------------------------------------------------------ -define ('DW_DIR_CONTINUE',1); -define ('DW_DIR_NS',2); -define ('DW_DIR_PAGE',3); + foreach($this->get_pages($startdir) as $page) { + $wanted_pages = array_merge($wanted_pages, $this->internal_links($page)); + } + $wanted_pages = array_unique($wanted_pages); + sort($wanted_pages); -#------------------------------------------------------------------------------ -function dw_dir_filter($entry, $basepath) { - if ($entry == '.' || $entry == '..' ) { - return DW_DIR_CONTINUE; - } - if ( is_dir($basepath . '/' . $entry) ) { - if ( strpos($entry, '_') === 0 ) { - return DW_DIR_CONTINUE; + foreach($wanted_pages as $page) { + print $page . "\n"; } - return DW_DIR_NS; - } - if ( preg_match('/\.txt$/',$entry) ) { - return DW_DIR_PAGE; } - return DW_DIR_CONTINUE; -} -#------------------------------------------------------------------------------ -function dw_get_pages($dir) { - static $trunclen = null; - if ( !$trunclen ) { - global $conf; - $trunclen = strlen($conf['datadir'].':'); + protected function dir_filter($entry, $basepath) { + if($entry == '.' || $entry == '..') { + return WantedPagesCLI::DIR_CONTINUE; + } + if(is_dir($basepath . '/' . $entry)) { + if(strpos($entry, '_') === 0) { + return WantedPagesCLI::DIR_CONTINUE; + } + return WantedPagesCLI::DIR_NS; + } + if(preg_match('/\.txt$/', $entry)) { + return WantedPagesCLI::DIR_PAGE; + } + return WantedPagesCLI::DIR_CONTINUE; } - if ( !is_dir($dir) ) { - fwrite( STDERR, "Unable to read directory $dir\n"); - exit(1); - } + protected function get_pages($dir) { + static $trunclen = null; + if(!$trunclen) { + global $conf; + $trunclen = strlen($conf['datadir'] . ':'); + } - $pages = array(); - $dh = opendir($dir); - while ( false !== ( $entry = readdir($dh) ) ) { - $status = dw_dir_filter($entry, $dir); - if ( $status == DW_DIR_CONTINUE ) { - continue; - } else if ( $status == DW_DIR_NS ) { - $pages = array_merge($pages, dw_get_pages($dir . '/' . $entry)); - } else { - $page = array( - 'id' => pathID(substr($dir.'/'.$entry,$trunclen)), - 'file'=> $dir.'/'.$entry, + if(!is_dir($dir)) { + throw new DokuCLI_Exception("Unable to read directory $dir"); + } + + $pages = array(); + $dh = opendir($dir); + while(false !== ($entry = readdir($dh))) { + $status = $this->dir_filter($entry, $dir); + if($status == WantedPagesCLI::DIR_CONTINUE) { + continue; + } else if($status == WantedPagesCLI::DIR_NS) { + $pages = array_merge($pages, $this->get_pages($dir . '/' . $entry)); + } else { + $page = array( + 'id' => pathID(substr($dir . '/' . $entry, $trunclen)), + 'file' => $dir . '/' . $entry, ); - $pages[] = $page; + $pages[] = $page; + } } + closedir($dh); + return $pages; } - closedir($dh); - return $pages; -} -#------------------------------------------------------------------------------ -function dw_internal_links($page) { - global $conf; - $instructions = p_get_instructions(file_get_contents($page['file'])); - $links = array(); - $cns = getNS($page['id']); - $exists = false; - foreach($instructions as $ins){ - if($ins[0] == 'internallink' || ($conf['camelcase'] && $ins[0] == 'camelcaselink') ){ - $mid = $ins[1][0]; - resolve_pageid($cns,$mid,$exists); - if ( !$exists ) { - list($mid) = explode('#',$mid); //record pages without hashs - $links[] = $mid; + function internal_links($page) { + global $conf; + $instructions = p_get_instructions(file_get_contents($page['file'])); + $links = array(); + $cns = getNS($page['id']); + $exists = false; + foreach($instructions as $ins) { + if($ins[0] == 'internallink' || ($conf['camelcase'] && $ins[0] == 'camelcaselink')) { + $mid = $ins[1][0]; + resolve_pageid($cns, $mid, $exists); + if(!$exists) { + list($mid) = explode('#', $mid); //record pages without hashs + $links[] = $mid; + } } } + return $links; } - return $links; } -#------------------------------------------------------------------------------ -$OPTS = Doku_Cli_Opts::getOptions(__FILE__,'h',array('help')); - -if ( $OPTS->isError() ) { - fwrite( STDERR, $OPTS->getMessage() . "\n"); - exit(1); -} - -if ( $OPTS->has('h') or $OPTS->has('help') ) { - usage(); - exit(0); -} - -$START_DIR = $conf['datadir']; - -if ( $OPTS->numArgs() == 1 ) { - $START_DIR .= '/' . $OPTS->arg(0); -} - -#------------------------------------------------------------------------------ -$WANTED_PAGES = array(); - -foreach ( dw_get_pages($START_DIR) as $WIKI_PAGE ) { - $WANTED_PAGES = array_merge($WANTED_PAGES,dw_internal_links($WIKI_PAGE)); -} -$WANTED_PAGES = array_unique($WANTED_PAGES); -sort($WANTED_PAGES); - -foreach ( $WANTED_PAGES as $WANTED_PAGE ) { - print $WANTED_PAGE."\n"; -} -exit(0); +// Main +$cli = new WantedPagesCLI(); +$cli->run(); \ No newline at end of file -- cgit v1.2.3 From 272e9decc1b5a964c3303ffe8b5d52e9e08fde68 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 22 Mar 2014 17:23:35 +0100 Subject: CLI: send messages to STDERR --- inc/cli.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/inc/cli.php b/inc/cli.php index c51d9b7d2..f2da6a49d 100644 --- a/inc/cli.php +++ b/inc/cli.php @@ -111,7 +111,7 @@ abstract class DokuCLI { * @param $string */ public function error($string) { - $this->colors->ptln("E: $string", 'red'); + $this->colors->ptln("E: $string", 'red', STDERR); } /** @@ -120,7 +120,7 @@ abstract class DokuCLI { * @param $string */ public function success($string) { - $this->colors->ptln("S: $string", 'green'); + $this->colors->ptln("S: $string", 'green', STDERR); } /** @@ -129,7 +129,7 @@ abstract class DokuCLI { * @param $string */ public function info($string) { - $this->colors->ptln("I: $string", 'cyan'); + $this->colors->ptln("I: $string", 'cyan', STDERR); } } @@ -201,10 +201,11 @@ class DokuCLI_Colors { * * @param $line * @param $color + * @param resource $channel */ - public function ptln($line, $color) { + public function ptln($line, $color, $channel=STDOUT) { $this->set($color); - echo rtrim($line) . "\n"; + fwrite($channel, rtrim($line) . "\n"); $this->reset(); } -- cgit v1.2.3 From 06da270e039cf517a6bd847ca0cd4a7819c9f879 Mon Sep 17 00:00:00 2001 From: Axel Angel Date: Sun, 4 May 2014 11:46:35 +0200 Subject: Authldap: implement change password in modifyUser --- lib/plugins/authldap/auth.php | 55 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/plugins/authldap/auth.php b/lib/plugins/authldap/auth.php index 6c3637e15..13ffb8be2 100644 --- a/lib/plugins/authldap/auth.php +++ b/lib/plugins/authldap/auth.php @@ -36,8 +36,8 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { return; } - // auth_ldap currently just handles authentication, so no - // capabilities are set + // Add the capabilities to change the password + $this->cando['modPass'] = true; } /** @@ -263,6 +263,57 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { return $info; } + /** + * Definition of the function modifyUser in order to modify the password + */ + + function modifyUser($user,$changes){ + + // open the connection to the ldap + if(!$this->_openLDAP()){ + msg('LDAP cannot connect: '. htmlspecialchars(ldap_error($this->con))); + return false; + } + + // find the information about the user, in particular the "dn" + $info = $this->getUserData($user,true); + if(empty($info['dn'])) { + msg('LDAP cannot find your user dn: '. htmlspecialchars($info['dn'])); + return false; + } else { + $dn = $info['dn']; + } + + // find the new password and encrypt it whit SSHA + if(empty($changes['pass'])) { + msg('The new password is not allow because it\'s empty'); + return false; + } else { + mt_srand((double)microtime()*1000000); + $salt = pack("CCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand()); + $hash = "{SSHA}" . base64_encode(pack("H*", sha1($changes['pass'] . $salt)) . $salt); + } + + // find the old password of the user + list($loginuser,$loginsticky,$loginpass) = auth_getCookie(); + $secret = auth_cookiesalt(!$sticky, true); //bind non-sticky to session + $pass = auth_decrypt($loginpass, $secret); + + // bind with the ldap + if(!@ldap_bind($this->con,$dn,$pass)){ + msg('LDAP user bind failed: '. htmlspecialchars($dn) .': '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + return false; + } + + // change the password + if(!@ldap_mod_replace($this->con, $dn,array('userpassword' => $hash))){ + msg('LDAP mod replace failed: '. htmlspecialchars($dn) .': '.htmlspecialchars(ldap_error($this->con))); + return false; + } + + return true; + } + /** * Most values in LDAP are case-insensitive * -- cgit v1.2.3 From 719c6730c7da93e830205e42dc230de831446e8f Mon Sep 17 00:00:00 2001 From: Axel Angel Date: Sun, 4 May 2014 12:26:13 +0200 Subject: Allow authldap to change password with ldap superuser only if necessary --- lib/plugins/authldap/auth.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/plugins/authldap/auth.php b/lib/plugins/authldap/auth.php index 13ffb8be2..5bdaf0446 100644 --- a/lib/plugins/authldap/auth.php +++ b/lib/plugins/authldap/auth.php @@ -296,13 +296,25 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { // find the old password of the user list($loginuser,$loginsticky,$loginpass) = auth_getCookie(); - $secret = auth_cookiesalt(!$sticky, true); //bind non-sticky to session - $pass = auth_decrypt($loginpass, $secret); + if ($loginuser !== null) { // the user is currently logged in + $secret = auth_cookiesalt(!$sticky, true); + $pass = auth_decrypt($loginpass, $secret); - // bind with the ldap - if(!@ldap_bind($this->con,$dn,$pass)){ - msg('LDAP user bind failed: '. htmlspecialchars($dn) .': '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); - return false; + // bind with the ldap + if(!@ldap_bind($this->con, $dn, $pass)){ + msg('LDAP user bind failed: '. htmlspecialchars($dn) .': '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + return false; + } + } elseif ($this->getConf('binddn') && $this->getConf('bindpw')) { + // we are changing the password on behalf of the user (eg: forgotten password) + // bind with the superuser ldap + if (!@ldap_bind($this->con, $this->getConf('binddn'), $this->getConf('bindpw'))){ + $this->_debug('LDAP bind as superuser: '.htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__); + return false; + } + } + else { + return false; // no otherway } // change the password -- cgit v1.2.3 From 67723447f02824ff2df7daa0f1f97d8b289c5d7a Mon Sep 17 00:00:00 2001 From: Axel Angel Date: Sun, 4 May 2014 19:54:37 +0200 Subject: Hash and salt password with PassHash::ssha Moved the block closer to the variable use (indent clearer) --- lib/plugins/authldap/auth.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/plugins/authldap/auth.php b/lib/plugins/authldap/auth.php index 5bdaf0446..ecbbc2a3a 100644 --- a/lib/plugins/authldap/auth.php +++ b/lib/plugins/authldap/auth.php @@ -288,10 +288,6 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { if(empty($changes['pass'])) { msg('The new password is not allow because it\'s empty'); return false; - } else { - mt_srand((double)microtime()*1000000); - $salt = pack("CCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand()); - $hash = "{SSHA}" . base64_encode(pack("H*", sha1($changes['pass'] . $salt)) . $salt); } // find the old password of the user @@ -317,6 +313,10 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { return false; // no otherway } + // Generate the salted hashed password for LDAP + $phash = new PassHash(); + $hash = $phash->hash_ssha($changes['pass']); + // change the password if(!@ldap_mod_replace($this->con, $dn,array('userpassword' => $hash))){ msg('LDAP mod replace failed: '. htmlspecialchars($dn) .': '.htmlspecialchars(ldap_error($this->con))); -- cgit v1.2.3 From 8f2ea93bb09b8744de56a8797176d3a209c2e8d7 Mon Sep 17 00:00:00 2001 From: Axel Angel Date: Thu, 8 May 2014 12:19:39 +0200 Subject: Simplify code and remove unreachable check --- lib/plugins/authldap/auth.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/plugins/authldap/auth.php b/lib/plugins/authldap/auth.php index ecbbc2a3a..bda8f2abe 100644 --- a/lib/plugins/authldap/auth.php +++ b/lib/plugins/authldap/auth.php @@ -278,17 +278,10 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { // find the information about the user, in particular the "dn" $info = $this->getUserData($user,true); if(empty($info['dn'])) { - msg('LDAP cannot find your user dn: '. htmlspecialchars($info['dn'])); - return false; - } else { - $dn = $info['dn']; - } - - // find the new password and encrypt it whit SSHA - if(empty($changes['pass'])) { - msg('The new password is not allow because it\'s empty'); + msg('LDAP cannot find your user dn'); return false; } + $dn = $info['dn']; // find the old password of the user list($loginuser,$loginsticky,$loginpass) = auth_getCookie(); -- cgit v1.2.3 From 1419a485e3ac0c507ef073f0b816bd41f7e4a5cd Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 10 May 2014 15:49:53 +0200 Subject: log deprecated function calls FS#2399 This introduces a new dbg_deprecated() function which allows for easy marking of deprecated functions. Each call is logged to the debuglog when debuggin is enabled. --- inc/TarLib.class.php | 2 ++ inc/changelog.php | 6 ++++-- inc/infoutils.php | 26 ++++++++++++++++++++++++++ inc/plugin.php | 1 + inc/subscription.php | 1 + 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/inc/TarLib.class.php b/inc/TarLib.class.php index ae08039ec..dd319a79a 100644 --- a/inc/TarLib.class.php +++ b/inc/TarLib.class.php @@ -26,6 +26,8 @@ class TarLib { public $_result = true; function __construct($file, $comptype = TarLib::COMPRESS_AUTO, $complevel = 9) { + dbg_deprecated('class Tar'); + if(!$file) $this->error('__construct', '$file'); $this->file = $file; diff --git a/inc/changelog.php b/inc/changelog.php index de06c9683..f0788d896 100644 --- a/inc/changelog.php +++ b/inc/changelog.php @@ -1004,12 +1004,13 @@ class MediaChangelog extends ChangeLog { * changelog files, only the chunk containing the * requested changelog line is read. * - * @deprecated 20-11-2013 + * @deprecated 2013-11-20 * * @author Ben Coburn * @author Kate Arzamastseva */ function getRevisionInfo($id, $rev, $chunk_size = 8192, $media = false) { + dbg_deprecated('class PageChangeLog or class MediaChanglog'); if($media) { $changelog = new MediaChangeLog($id, $chunk_size); } else { @@ -1036,12 +1037,13 @@ function getRevisionInfo($id, $rev, $chunk_size = 8192, $media = false) { * backwards in chunks until the requested number of changelog * lines are recieved. * - * @deprecated 20-11-2013 + * @deprecated 2013-11-20 * * @author Ben Coburn * @author Kate Arzamastseva */ function getRevisions($id, $first, $num, $chunk_size = 8192, $media = false) { + dbg_deprecated('class PageChangeLog or class MediaChanglog'); if($media) { $changelog = new MediaChangeLog($id, $chunk_size); } else { diff --git a/inc/infoutils.php b/inc/infoutils.php index 0992040d9..807323715 100644 --- a/inc/infoutils.php +++ b/inc/infoutils.php @@ -383,6 +383,32 @@ function dbglog($msg,$header=''){ } } +/** + * Log accesses to deprecated fucntions to the debug log + * + * @param string $alternative The function or method that should be used instead + */ +function dbg_deprecated($alternative = '') { + global $conf; + if(!$conf['allowdebug']) return; + + $backtrace = debug_backtrace(); + array_shift($backtrace); + $self = array_shift($backtrace); + $call = array_shift($backtrace); + + $called = trim($self['class'].'::'.$self['function'].'()', ':'); + $caller = trim($call['class'].'::'.$call['function'].'()', ':'); + + $msg = $called.' is deprecated. It was called from '; + $msg .= $caller.' in '.$call['file'].':'.$call['line']; + if($alternative) { + $msg .= ' '.$alternative.' should be used instead!'; + } + + dbglog($msg); +} + /** * Print a reversed, prettyprinted backtrace * diff --git a/inc/plugin.php b/inc/plugin.php index 7de4fbd74..e0112ef56 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -252,6 +252,7 @@ class DokuWiki_Plugin { */ function __call($name, $arguments) { if($name == 'render'){ + dbg_deprecated('render_text()'); if(!isset($arguments[1])) $arguments[1] = 'xhtml'; return $this->render_text($arguments[0], $arguments[1]); } diff --git a/inc/subscription.php b/inc/subscription.php index 298e7c12b..a6f3dec44 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -700,6 +700,7 @@ class Subscription { * @deprecated 2012-12-07 */ function subscription_addresslist(&$data) { + dbg_deprecated('class Subscription'); $sub = new Subscription(); $sub->notifyaddresses($data); } -- cgit v1.2.3 From 0712fefaefb6c7857ccc3455db2d8d269fb3ed16 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 16 May 2014 08:35:38 +0200 Subject: don't unlock based on empty session --- inc/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/common.php b/inc/common.php index 9fbebde94..c960c8739 100644 --- a/inc/common.php +++ b/inc/common.php @@ -796,7 +796,7 @@ function checklock($id) { //my own lock @list($ip, $session) = explode("\n", io_readFile($lock)); - if($ip == $INPUT->server->str('REMOTE_USER') || $ip == clientIP() || $session == session_id()) { + if($ip == $INPUT->server->str('REMOTE_USER') || $ip == clientIP() || (session_id() && $session == session_id())) { return false; } -- cgit v1.2.3 From e82b082ef3300c5b2d8f03f74873ef31f0b57933 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 16 May 2014 09:09:17 +0200 Subject: refactored dwpage.php to new CLI --- bin/dwpage.php | 597 ++++++++++++++++++++++++++------------------------------- 1 file changed, 268 insertions(+), 329 deletions(-) diff --git a/bin/dwpage.php b/bin/dwpage.php index 96f6d3ef9..a777fd3e1 100755 --- a/bin/dwpage.php +++ b/bin/dwpage.php @@ -1,378 +1,317 @@ #!/usr/bin/php [working_file] - - Checks out a file from the repository, using the wiki id and obtaining - a lock for the page. - If a working_file is specified, this is where the page is copied to. - Otherwise defaults to the same as the wiki page in the current - working directory. - - EXAMPLE - $ ./dwpage.php checkout wiki:syntax ./new_syntax.txt - - OPTIONS - -h, --help=: get help - -f: force obtaining a lock for the page (generally bad idea) -"; - break; - case 'commit': - print "Usage: dwpage.php [opts] -m \"Msg\" commit - - Checks in the working_file into the repository using the specified - wiki id, archiving the previous version. - - EXAMPLE - $ ./dwpage.php -m \"Some message\" commit ./new_syntax.txt wiki:syntax - - OPTIONS - -h, --help=: get help - -f: force obtaining a lock for the page (generally bad idea) - -t, trivial: minor change - -m (required): Summary message describing the change -"; - break; - case 'lock': - print "Usage: dwpage.php [opts] lock - - Obtains or updates a lock for a wiki page - - EXAMPLE - $ ./dwpage.php lock wiki:syntax - - OPTIONS - -h, --help=: get help - -f: force obtaining a lock for the page (generally bad idea) -"; - break; - case 'unlock': - print "Usage: dwpage.php [opts] unlock - - Removes a lock for a wiki page. - - EXAMPLE - $ ./dwpage.php unlock wiki:syntax - - OPTIONS - -h, --help=: get help - -f: force obtaining a lock for the page (generally bad idea) -"; - break; - default: - print "Usage: dwpage.php [opts] - - Utility to help command line Dokuwiki page editing, allow - pages to be checked out for editing then committed after changes - - Normal operation would be; - - - - ACTIONS - checkout: see $ dwpage.php --help=checkout - commit: see $ dwpage.php --help=commit - lock: see $ dwpage.php --help=lock - - OPTIONS - -h, --help=: get help - e.g. $ ./dwpage.php -hcommit - e.g. $ ./dwpage.php --help=commit -"; - break; +if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__).'/../').'/'); +define('NOSESSION', 1); +require_once(DOKU_INC.'inc/init.php'); + +/** + * Checkout and commit pages from the command line while maintaining the history + */ +class PageCLI extends DokuCLI { + + protected $force = false; + protected $username = ''; + + /** + * Register options and arguments on the given $options object + * + * @param DokuCLI_Options $options + * @return void + */ + protected function setup(DokuCLI_Options $options) { + /* global */ + $options->registerOption( + 'force', + 'force obtaining a lock for the page (generally bad idea)', + 'f' + ); + $options->registerOption( + 'user', + 'work as this user. defaults to current CLI user', + 'u' + ); + $options->setHelp( + 'Utility to help command line Dokuwiki page editing, allow '. + 'pages to be checked out for editing then committed after changes' + ); + + /* checkout command */ + $options->registerCommand( + 'checkout', + 'Checks out a file from the repository, using the wiki id and obtaining '. + 'a lock for the page. '."\n". + 'If a working_file is specified, this is where the page is copied to. '. + 'Otherwise defaults to the same as the wiki page in the current '. + 'working directory.' + ); + $options->registerArgument( + 'wikipage', + 'The wiki page to checkout', + true, + 'checkout' + ); + $options->registerArgument( + 'workingfile', + 'How to name the local checkout', + false, + 'checkout' + ); + + /* commit command */ + $options->registerCommand( + 'commit', + 'Checks in the working_file into the repository using the specified '. + 'wiki id, archiving the previous version.' + ); + $options->registerArgument( + 'workingfile', + 'The local file to commit', + true, + 'commit' + ); + $options->registerArgument( + 'wikipage', + 'The wiki page to create or update', + true, + 'commit' + ); + $options->registerOption( + 'message', + 'Summary describing the change (required)', + 'm', + 'summary', + 'commit' + ); + $options->registerOption( + 'trivial', + 'minor change', + 't', + false, + 'commit' + ); + + /* lock command */ + $options->registerCommand( + 'lock', + 'Obtains or updates a lock for a wiki page' + ); + $options->registerArgument( + 'wikipage', + 'The wiki page to lock', + true, + 'lock' + ); + + /* unlock command */ + $options->registerCommand( + 'unlock', + 'Removes a lock for a wiki page.' + ); + $options->registerArgument( + 'wikipage', + 'The wiki page to unlock', + true, + 'unlock' + ); } -} - -#------------------------------------------------------------------------------ -function getUser() { - $user = getenv('USER'); - if (empty ($user)) { - $user = getenv('USERNAME'); - } else { - return $user; - } - if (empty ($user)) { - $user = 'admin'; - } - return $user; -} - -#------------------------------------------------------------------------------ -function getSuppliedArgument($OPTS, $short, $long) { - $arg = $OPTS->get($short); - if ( is_null($arg) ) { - $arg = $OPTS->get($long); - } - return $arg; -} - -#------------------------------------------------------------------------------ -function obtainLock($WIKI_ID) { - - global $USERNAME; - - if ( !file_exists(wikiFN($WIKI_ID)) ) { - fwrite( STDERR, "$WIKI_ID does not yet exist\n"); - } - - $_SERVER['REMOTE_USER'] = $USERNAME; - if ( checklock($WIKI_ID) ) { - fwrite( STDERR, "Page $WIKI_ID is already locked by another user\n"); - exit(1); - } - - lock($WIKI_ID); - - $_SERVER['REMOTE_USER'] = '_'.$USERNAME.'_'; - - if ( checklock($WIKI_ID) != $USERNAME ) { - - fwrite( STDERR, "Unable to obtain lock for $WIKI_ID\n" ); - exit(1); - - } -} - -#------------------------------------------------------------------------------ -function clearLock($WIKI_ID) { - - global $USERNAME ; - if ( !file_exists(wikiFN($WIKI_ID)) ) { - fwrite( STDERR, "$WIKI_ID does not yet exist\n"); - } - - $_SERVER['REMOTE_USER'] = $USERNAME; - if ( checklock($WIKI_ID) ) { - fwrite( STDERR, "Page $WIKI_ID is locked by another user\n"); - exit(1); - } - - unlock($WIKI_ID); - - if ( file_exists(wikiLockFN($WIKI_ID)) ) { - fwrite( STDERR, "Unable to clear lock for $WIKI_ID\n" ); - exit(1); - } - -} - -#------------------------------------------------------------------------------ -function deleteLock($WIKI_ID) { - - $wikiLockFN = wikiLockFN($WIKI_ID); - - if ( file_exists($wikiLockFN) ) { - if ( !unlink($wikiLockFN) ) { - fwrite( STDERR, "Unable to delete $wikiLockFN\n" ); - exit(1); + /** + * Your main program + * + * Arguments and options have been parsed when this is run + * + * @param DokuCLI_Options $options + * @return void + */ + protected function main(DokuCLI_Options $options) { + $this->force = $options->getOpt('force', false); + $this->username = $options->getOpt('user', $this->getUser()); + + $command = $options->getCmd(); + switch($command) { + case 'checkout': + $wiki_id = array_shift($options->args); + $localfile = array_shift($options->args); + $this->commandCheckout($wiki_id, $localfile); + break; + case 'commit': + $localfile = array_shift($options->args); + $wiki_id = array_shift($options->args); + $this->commandCommit( + $localfile, + $wiki_id, + $options->getOpt('message', ''), + $options->getOpt('trivial', false) + ); + break; + case 'lock': + $wiki_id = array_shift($options->args); + $this->obtainLock($wiki_id); + $this->success("$wiki_id locked"); + break; + case 'unlock': + $wiki_id = array_shift($options->args); + $this->clearLock($wiki_id); + $this->success("$wiki_id unlocked"); + break; + default: + echo $options->help(); } } -} - -#------------------------------------------------------------------------------ -$USERNAME = getUser(); -$CWD = getcwd(); -$SYSTEM_ID = '127.0.0.1'; - -#------------------------------------------------------------------------------ -$OPTS = Doku_Cli_Opts::getOptions( - __FILE__, - 'h::fm:u:s:t', - array( - 'help==', - 'user=', - 'system=', - 'trivial', - ) -); - -if ( $OPTS->isError() ) { - print $OPTS->getMessage()."\n"; - exit(1); -} - -if ( $OPTS->has('h') or $OPTS->has('help') or !$OPTS->hasArgs() ) { - usage(getSuppliedArgument($OPTS,'h','help')); - exit(0); -} - -if ( $OPTS->has('u') or $OPTS->has('user') ) { - $USERNAME = getSuppliedArgument($OPTS,'u','user'); -} - -if ( $OPTS->has('s') or $OPTS->has('system') ) { - $SYSTEM_ID = getSuppliedArgument($OPTS,'s','system'); -} + /** + * Check out a file + * + * @param string $wiki_id + * @param string $localfile + */ + protected function commandCheckout($wiki_id, $localfile) { + global $conf; -#------------------------------------------------------------------------------ -switch ( $OPTS->arg(0) ) { + $wiki_id = cleanID($wiki_id); + $wiki_fn = wikiFN($wiki_id); - #---------------------------------------------------------------------- - case 'checkout': - - $WIKI_ID = $OPTS->arg(1); - - if ( !$WIKI_ID ) { - fwrite( STDERR, "Wiki page ID required\n"); - exit(1); + if(!file_exists($wiki_fn)) { + $this->fatal("$wiki_id does not yet exist"); } - $WIKI_FN = wikiFN($WIKI_ID); - - if ( !file_exists($WIKI_FN) ) { - fwrite( STDERR, "$WIKI_ID does not yet exist\n"); - exit(1); + if(empty($localfile)) { + $localfile = getcwd().'/'.utf8_basename($wiki_fn); } - $TARGET_FN = $OPTS->arg(2); - - if ( empty($TARGET_FN) ) { - $TARGET_FN = getcwd().'/'.utf8_basename($WIKI_FN); + if(!file_exists(dirname($localfile))) { + $this->fatal("Directory ".dirname($localfile)." does not exist"); } - if ( !file_exists(dirname($TARGET_FN)) ) { - fwrite( STDERR, "Directory ".dirname($TARGET_FN)." does not exist\n"); - exit(1); + if(stristr(realpath(dirname($localfile)), realpath($conf['datadir'])) !== false) { + $this->fatal("Attempt to check out file into data directory - not allowed"); } - if ( stristr( realpath(dirname($TARGET_FN)), realpath($conf['datadir']) ) !== false ) { - fwrite( STDERR, "Attempt to check out file into data directory - not allowed\n"); - exit(1); - } + $this->obtainLock($wiki_id); - if ( $OPTS->has('f') ) { - deleteLock($WIKI_ID); + if(!copy($wiki_fn, $localfile)) { + $this->clearLock($wiki_id); + $this->fatal("Unable to copy $wiki_fn to $localfile"); } - obtainLock($WIKI_ID); + $this->success("$wiki_id > $localfile"); + } - # Need to lock the file first? - if ( !copy($WIKI_FN, $TARGET_FN) ) { - fwrite( STDERR, "Unable to copy $WIKI_FN to $TARGET_FN\n"); - clearLock($WIKI_ID); - exit(1); + /** + * Save a file as a new page revision + * + * @param string $localfile + * @param string $wiki_id + * @param string $message + * @param bool $minor + */ + protected function commandCommit($localfile, $wiki_id, $message, $minor) { + $wiki_id = cleanID($wiki_id); + $message = trim($message); + + if(!file_exists($localfile)) { + $this->fatal("$localfile does not exist"); } - print "$WIKI_ID > $TARGET_FN\n"; - exit(0); + if(!is_readable($localfile)) { + $this->fatal("Cannot read from $localfile"); + } - break; + if(!$message) { + $this->fatal("Summary message required"); + } - #---------------------------------------------------------------------- - case 'commit': + $this->obtainLock($wiki_id); - $TARGET_FN = $OPTS->arg(1); + saveWikiText($wiki_id, file_get_contents($localfile), $message, $minor); - if ( !$TARGET_FN ) { - fwrite( STDERR, "Target filename required\n"); - exit(1); - } + $this->clearLock($wiki_id); - if ( !file_exists($TARGET_FN) ) { - fwrite( STDERR, "$TARGET_FN does not exist\n"); - exit(1); - } + $this->success("$localfile > $wiki_id"); + } - if ( !is_readable($TARGET_FN) ) { - fwrite( STDERR, "Cannot read from $TARGET_FN\n"); + /** + * Lock the given page or exit + * + * @param string $wiki_id + */ + protected function obtainLock($wiki_id) { + if($this->force) $this->deleteLock($wiki_id); + + $_SERVER['REMOTE_USER'] = $this->username; + if(checklock($wiki_id)) { + $this->error("Page $wiki_id is already locked by another user"); exit(1); } - $WIKI_ID = $OPTS->arg(2); + lock($wiki_id); - if ( !$WIKI_ID ) { - fwrite( STDERR, "Wiki page ID required\n"); + $_SERVER['REMOTE_USER'] = '_'.$this->username.'_'; + if(checklock($wiki_id) != $this->username) { + $this->error("Unable to obtain lock for $wiki_id "); + var_dump(checklock($wiki_id)); exit(1); } + } - if ( !$OPTS->has('m') ) { - fwrite( STDERR, "Summary message required\n"); + /** + * Clear the lock on the given page + * + * @param string $wiki_id + */ + protected function clearLock($wiki_id) { + if($this->force) $this->deleteLock($wiki_id); + + $_SERVER['REMOTE_USER'] = $this->username; + if(checklock($wiki_id)) { + $this->error("Page $wiki_id is locked by another user"); exit(1); } - if ( $OPTS->has('f') ) { - deleteLock($WIKI_ID); - } + unlock($wiki_id); - $_SERVER['REMOTE_USER'] = $USERNAME; - if ( checklock($WIKI_ID) ) { - fwrite( STDERR, "$WIKI_ID is locked by another user\n"); + if(file_exists(wikiLockFN($wiki_id))) { + $this->error("Unable to clear lock for $wiki_id"); exit(1); } + } - obtainLock($WIKI_ID); - - saveWikiText($WIKI_ID, file_get_contents($TARGET_FN), $OPTS->get('m'), $OPTS->has('t')); - - clearLock($WIKI_ID); - - exit(0); - - break; - - #---------------------------------------------------------------------- - case 'lock': - - $WIKI_ID = $OPTS->arg(1); - - if ( !$WIKI_ID ) { - fwrite( STDERR, "Wiki page ID required\n"); - exit(1); - } - - if ( $OPTS->has('f') ) { - deleteLock($WIKI_ID); - } - - obtainLock($WIKI_ID); - - print "Locked : $WIKI_ID\n"; - exit(0); - - break; - - #---------------------------------------------------------------------- - case 'unlock': - - $WIKI_ID = $OPTS->arg(1); - - if ( !$WIKI_ID ) { - fwrite( STDERR, "Wiki page ID required\n"); - exit(1); + /** + * Forcefully remove a lock on the page given + * + * @param string $wiki_id + */ + protected function deleteLock($wiki_id) { + $wikiLockFN = wikiLockFN($wiki_id); + + if(file_exists($wikiLockFN)) { + if(!unlink($wikiLockFN)) { + $this->error("Unable to delete $wikiLockFN"); + exit(1); + } } + } - if ( $OPTS->has('f') ) { - deleteLock($WIKI_ID); + /** + * Get the current user's username from the environment + * + * @return string + */ + protected function getUser() { + $user = getenv('USER'); + if(empty ($user)) { + $user = getenv('USERNAME'); } else { - clearLock($WIKI_ID); + return $user; } - - print "Unlocked : $WIKI_ID\n"; - exit(0); - - break; - - #---------------------------------------------------------------------- - default: - - fwrite( STDERR, "Invalid action ".$OPTS->arg(0)."\n" ); - exit(1); - - break; - + if(empty ($user)) { + $user = 'admin'; + } + return $user; + } } + +// Main +$cli = new PageCLI(); +$cli->run(); \ No newline at end of file -- cgit v1.2.3 From 1c36b3d86f90185519cadaad85251922dc771fe1 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 16 May 2014 09:11:15 +0200 Subject: code reformat --- bin/gittool.php | 84 ++++++++++++++++++++++++++--------------------------- bin/indexer.php | 25 +++++++++------- bin/render.php | 18 ++++++------ bin/striplangs.php | 45 ++++++++++++++-------------- bin/wantedpages.php | 29 +++++++++--------- inc/cli.php | 67 ++++++++++++++++++++++-------------------- 6 files changed, 140 insertions(+), 128 deletions(-) diff --git a/bin/gittool.php b/bin/gittool.php index fca76768d..6944dde57 100755 --- a/bin/gittool.php +++ b/bin/gittool.php @@ -1,8 +1,8 @@ #!/usr/bin/php setHelp( - "Manage git repositories for DokuWiki and its plugins and templates.\n\n" . - "$> ./bin/gittool.php clone gallery template:ach\n" . - "$> ./bin/gittool.php repos\n" . - "$> ./bin/gittool.php origin -v" + "Manage git repositories for DokuWiki and its plugins and templates.\n\n". + "$> ./bin/gittool.php clone gallery template:ach\n". + "$> ./bin/gittool.php repos\n". + "$> ./bin/gittool.php origin -v" ); $options->registerArgument( - 'command', - 'Command to execute. See below', - true + 'command', + 'Command to execute. See below', + true ); $options->registerCommand( - 'clone', - 'Tries to install a known plugin or template (prefix with template:) via git. Uses the DokuWiki.org ' . - 'plugin repository to find the proper git repository. Multiple extensions can be given as parameters' + 'clone', + 'Tries to install a known plugin or template (prefix with template:) via git. Uses the DokuWiki.org '. + 'plugin repository to find the proper git repository. Multiple extensions can be given as parameters' ); $options->registerArgument( - 'extension', - 'name of the extension to install, prefix with \'template:\' for templates', - true, - 'clone' + 'extension', + 'name of the extension to install, prefix with \'template:\' for templates', + true, + 'clone' ); $options->registerCommand( - 'install', - 'The same as clone, but when no git source repository can be found, the extension is installed via ' . - 'download' + 'install', + 'The same as clone, but when no git source repository can be found, the extension is installed via '. + 'download' ); $options->registerArgument( - 'extension', - 'name of the extension to install, prefix with \'template:\' for templates', - true, - 'install' + 'extension', + 'name of the extension to install, prefix with \'template:\' for templates', + true, + 'install' ); $options->registerCommand( - 'repos', - 'Lists all git repositories found in this DokuWiki installation' + 'repos', + 'Lists all git repositories found in this DokuWiki installation' ); $options->registerCommand( - '*', - 'Any unknown commands are assumed to be arguments to git and will be executed in all repositories ' . - 'found within this DokuWiki installation' + '*', + 'Any unknown commands are assumed to be arguments to git and will be executed in all repositories '. + 'found within this DokuWiki installation' ); } @@ -81,7 +81,7 @@ class GitToolCLI extends DokuCLI { switch($command) { case '': - echo $options->help('foo'); + echo $options->help(); break; case 'clone': $this->cmd_clone($options->args); @@ -123,8 +123,8 @@ class GitToolCLI extends DokuCLI { } echo "\n"; - if($succeeded) $this->success('successfully cloned the following extensions: ' . join(', ', $succeeded)); - if($errors) $this->error('failed to clone the following extensions: ' . join(', ', $errors)); + if($succeeded) $this->success('successfully cloned the following extensions: '.join(', ', $succeeded)); + if($errors) $this->error('failed to clone the following extensions: '.join(', ', $errors)); } /** @@ -156,8 +156,8 @@ class GitToolCLI extends DokuCLI { } echo "\n"; - if($succeeded) $this->success('successfully installed the following extensions: ' . join(', ', $succeeded)); - if($errors) $this->error('failed to install the following extensions: ' . join(', ', $errors)); + if($succeeded) $this->success('successfully installed the following extensions: '.join(', ', $succeeded)); + if($errors) $this->error('failed to install the following extensions: '.join(', ', $errors)); } /** @@ -246,9 +246,9 @@ class GitToolCLI extends DokuCLI { */ private function cloneExtension($ext, $repo) { if(substr($ext, 0, 9) == 'template:') { - $target = fullpath(tpl_incdir() . '../' . substr($ext, 9)); + $target = fullpath(tpl_incdir().'../'.substr($ext, 9)); } else { - $target = DOKU_PLUGIN . $ext; + $target = DOKU_PLUGIN.$ext; } $this->info("cloning $ext from $repo to $target"); @@ -273,15 +273,15 @@ class GitToolCLI extends DokuCLI { private function findRepos() { $this->info('Looking for .git directories'); $data = array_merge( - glob(DOKU_INC . '.git', GLOB_ONLYDIR), - glob(DOKU_PLUGIN . '*/.git', GLOB_ONLYDIR), - glob(fullpath(tpl_incdir() . '../') . '/*/.git', GLOB_ONLYDIR) + glob(DOKU_INC.'.git', GLOB_ONLYDIR), + glob(DOKU_PLUGIN.'*/.git', GLOB_ONLYDIR), + glob(fullpath(tpl_incdir().'../').'/*/.git', GLOB_ONLYDIR) ); if(!$data) { $this->error('Found no .git directories'); } else { - $this->success('Found ' . count($data) . ' .git directories'); + $this->success('Found '.count($data).' .git directories'); } $data = array_map('fullpath', array_map('dirname', $data)); return $data; @@ -306,7 +306,7 @@ class GitToolCLI extends DokuCLI { if(preg_match('/github\.com\/([^\/]+)\/([^\/]+)/i', $repourl, $m)) { $user = $m[1]; $repo = $m[2]; - return 'https://github.com/' . $user . '/' . $repo . '.git'; + return 'https://github.com/'.$user.'/'.$repo.'.git'; } // match gitorious repos @@ -315,14 +315,14 @@ class GitToolCLI extends DokuCLI { $repo = $m[2]; if(!$repo) $repo = $user; - return 'https://git.gitorious.org/' . $user . '/' . $repo . '.git'; + return 'https://git.gitorious.org/'.$user.'/'.$repo.'.git'; } // match bitbucket repos - most people seem to use mercurial there though if(preg_match('/bitbucket\.org\/([^\/]+)\/([^\/]+)/i', $repourl, $m)) { $user = $m[1]; $repo = $m[2]; - return 'https://bitbucket.org/' . $user . '/' . $repo . '.git'; + return 'https://bitbucket.org/'.$user.'/'.$repo.'.git'; } return false; diff --git a/bin/indexer.php b/bin/indexer.php index 76269f95a..13895c36a 100755 --- a/bin/indexer.php +++ b/bin/indexer.php @@ -1,9 +1,12 @@ #!/usr/bin/php setHelp( - 'Updates the searchindex by indexing all new or changed pages. When the -c option is ' . - 'given the index is cleared first.' + 'Updates the searchindex by indexing all new or changed pages. When the -c option is '. + 'given the index is cleared first.' ); $options->registerOption( - 'clear', - 'clear the index before updating', - 'c' + 'clear', + 'clear the index before updating', + 'c' ); $options->registerOption( - 'quiet', - 'don\'t produce any output', - 'q' + 'quiet', + 'don\'t produce any output', + 'q' ); } @@ -58,7 +61,7 @@ class IndexerCLI extends DokuCLI { $data = array(); $this->quietecho("Searching pages... "); search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true)); - $this->quietecho(count($data) . " pages found.\n"); + $this->quietecho(count($data)." pages found.\n"); foreach($data as $val) { $this->index($val['id']); diff --git a/bin/render.php b/bin/render.php index 01fd16cdd..672993223 100755 --- a/bin/render.php +++ b/bin/render.php @@ -1,8 +1,8 @@ #!/usr/bin/php + * @author Andreas Gohr */ class RenderCLI extends DokuCLI { @@ -26,11 +26,11 @@ class RenderCLI extends DokuCLI { */ protected function setup(DokuCLI_Options $options) { $options->setHelp( - 'A simple commandline tool to render some DokuWiki syntax with a given renderer.' . - "\n\n" . - 'This may not work for plugins that expect a certain environment to be ' . - 'set up before rendering, but should work for most or even all standard ' . - 'DokuWiki markup' + 'A simple commandline tool to render some DokuWiki syntax with a given renderer.'. + "\n\n". + 'This may not work for plugins that expect a certain environment to be '. + 'set up before rendering, but should work for most or even all standard '. + 'DokuWiki markup' ); $options->registerOption('renderer', 'The renderer mode to use. Defaults to xhtml', 'r', 'mode'); } @@ -49,7 +49,7 @@ class RenderCLI extends DokuCLI { // do the action $source = stream_get_contents(STDIN); - $info = array(); + $info = array(); $result = p_render($renderer, p_get_instructions($source), $info); if(is_null($result)) throw new DokuCLI_Exception("No such renderer $renderer"); echo $result; diff --git a/bin/striplangs.php b/bin/striplangs.php index 8567551ec..6335bc84c 100755 --- a/bin/striplangs.php +++ b/bin/striplangs.php @@ -1,10 +1,13 @@ #!/usr/bin/php setHelp( - 'Remove all languages from the installation, besides the ones specified. English language ' . - 'is never removed!' + 'Remove all languages from the installation, besides the ones specified. English language '. + 'is never removed!' ); $options->registerOption( - 'keep', - 'Comma separated list of languages to keep in addition to English.', - 'k' + 'keep', + 'Comma separated list of languages to keep in addition to English.', + 'k' ); $options->registerOption( - 'english-only', - 'Remove all languages except English', - 'e' + 'english-only', + 'Remove all languages except English', + 'e' ); } @@ -52,16 +55,16 @@ class StripLangsCLI extends DokuCLI { } // Kill all language directories in /inc/lang and /lib/plugins besides those in $langs array - $this->stripDirLangs(realpath(dirname(__FILE__) . '/../inc/lang'), $keep); - $this->processExtensions(realpath(dirname(__FILE__) . '/../lib/plugins'), $keep); - $this->processExtensions(realpath(dirname(__FILE__) . '/../lib/tpl'), $keep); + $this->stripDirLangs(realpath(dirname(__FILE__).'/../inc/lang'), $keep); + $this->processExtensions(realpath(dirname(__FILE__).'/../lib/plugins'), $keep); + $this->processExtensions(realpath(dirname(__FILE__).'/../lib/tpl'), $keep); } /** * Strip languages from extensions * - * @param string $path path to plugin or template dir - * @param array $keep_langs languages to keep + * @param string $path path to plugin or template dir + * @param array $keep_langs languages to keep */ protected function processExtensions($path, $keep_langs) { if(is_dir($path)) { @@ -69,9 +72,9 @@ class StripLangsCLI extends DokuCLI { foreach($entries as $entry) { if($entry != "." && $entry != "..") { - if(is_dir($path . '/' . $entry)) { + if(is_dir($path.'/'.$entry)) { - $plugin_langs = $path . '/' . $entry . '/lang'; + $plugin_langs = $path.'/'.$entry.'/lang'; if(is_dir($plugin_langs)) { $this->stripDirLangs($plugin_langs, $keep_langs); @@ -85,17 +88,17 @@ class StripLangsCLI extends DokuCLI { /** * Strip languages from path * - * @param string $path path to lang dir - * @param array $keep_langs languages to keep + * @param string $path path to lang dir + * @param array $keep_langs languages to keep */ protected 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($cur_dir != '.' and $cur_dir != '..' and is_dir($path.'/'.$cur_dir)) { if(!in_array($cur_dir, $keep_langs, true)) { - io_rmdir($path . '/' . $cur_dir, true); + io_rmdir($path.'/'.$cur_dir, true); } } } diff --git a/bin/wantedpages.php b/bin/wantedpages.php index 879291957..8fc4ba74f 100755 --- a/bin/wantedpages.php +++ b/bin/wantedpages.php @@ -1,9 +1,12 @@ #!/usr/bin/php setHelp( - 'Outputs a list of wanted pages (pages which have internal links but do not yet exist).' + 'Outputs a list of wanted pages (pages which have internal links but do not yet exist).' ); $options->registerArgument( - 'namespace', - 'The namespace to lookup. Defaults to root namespace', - false + 'namespace', + 'The namespace to lookup. Defaults to root namespace', + false ); } @@ -38,7 +41,7 @@ class WantedPagesCLI extends DokuCLI { protected function main(DokuCLI_Options $options) { if($options->args) { - $startdir = dirname(wikiFN($options->args[0] . ':xxx')); + $startdir = dirname(wikiFN($options->args[0].':xxx')); } else { $startdir = dirname(wikiFN('xxx')); } @@ -54,7 +57,7 @@ class WantedPagesCLI extends DokuCLI { sort($wanted_pages); foreach($wanted_pages as $page) { - print $page . "\n"; + print $page."\n"; } } @@ -62,7 +65,7 @@ class WantedPagesCLI extends DokuCLI { if($entry == '.' || $entry == '..') { return WantedPagesCLI::DIR_CONTINUE; } - if(is_dir($basepath . '/' . $entry)) { + if(is_dir($basepath.'/'.$entry)) { if(strpos($entry, '_') === 0) { return WantedPagesCLI::DIR_CONTINUE; } @@ -78,7 +81,7 @@ class WantedPagesCLI extends DokuCLI { static $trunclen = null; if(!$trunclen) { global $conf; - $trunclen = strlen($conf['datadir'] . ':'); + $trunclen = strlen($conf['datadir'].':'); } if(!is_dir($dir)) { @@ -92,11 +95,11 @@ class WantedPagesCLI extends DokuCLI { if($status == WantedPagesCLI::DIR_CONTINUE) { continue; } else if($status == WantedPagesCLI::DIR_NS) { - $pages = array_merge($pages, $this->get_pages($dir . '/' . $entry)); + $pages = array_merge($pages, $this->get_pages($dir.'/'.$entry)); } else { $page = array( - 'id' => pathID(substr($dir . '/' . $entry, $trunclen)), - 'file' => $dir . '/' . $entry, + 'id' => pathID(substr($dir.'/'.$entry, $trunclen)), + 'file' => $dir.'/'.$entry, ); $pages[] = $page; } diff --git a/inc/cli.php b/inc/cli.php index f2da6a49d..25bfddf7d 100644 --- a/inc/cli.php +++ b/inc/cli.php @@ -57,13 +57,13 @@ abstract class DokuCLI { // setup $this->setup($this->options); $this->options->registerOption( - 'no-colors', - 'Do not use any colors in output. Useful when piping output to other tools or files.' + 'no-colors', + 'Do not use any colors in output. Useful when piping output to other tools or files.' ); $this->options->registerOption( - 'help', - 'Display this help screen and exit immeadiately.', - 'h' + 'help', + 'Display this help screen and exit immeadiately.', + 'h' ); // parse @@ -101,7 +101,7 @@ abstract class DokuCLI { } if(!$code) $code = DokuCLI_Exception::E_ANY; - $this->colors->ptln($error, 'red'); + $this->error($error); exit($code); } @@ -199,13 +199,13 @@ class DokuCLI_Colors { /** * Convenience function to print a line in a given color * - * @param $line - * @param $color + * @param $line + * @param $color * @param resource $channel */ - public function ptln($line, $color, $channel=STDOUT) { + public function ptln($line, $color, $channel = STDOUT) { $this->set($color); - fwrite($channel, rtrim($line) . "\n"); + fwrite($channel, rtrim($line)."\n"); $this->reset(); } @@ -253,6 +253,9 @@ class DokuCLI_Options { /** @var string the executed script */ protected $bin; + /** + * Constructor + */ public function __construct() { $this->setup = array( '' => array( @@ -282,10 +285,10 @@ class DokuCLI_Options { * * This has to be called in the order arguments are expected * - * @param string $arg argument name (just for help) - * @param string $help help text - * @param bool $required is this a required argument - * @param string $command if theses apply to a sub command only + * @param string $arg argument name (just for help) + * @param string $help help text + * @param bool $required is this a required argument + * @param string $command if theses apply to a sub command only * @throws DokuCLI_Exception */ public function registerArgument($arg, $help, $required = true, $command = '') { @@ -321,11 +324,11 @@ class DokuCLI_Options { /** * Register an option for option parsing and help generation * - * @param string $long multi character option (specified with --) - * @param string $help help text for this option - * @param string|null $short one character option (specified with -) + * @param string $long multi character option (specified with --) + * @param string $help help text for this option + * @param string|null $short one character option (specified with -) * @param bool|string $needsarg does this option require an argument? give it a name here - * @param string $command what command does this option apply to + * @param string $command what command does this option apply to * @throws DokuCLI_Exception */ public function registerOption($long, $help, $short = null, $needsarg = false, $command = '') { @@ -467,7 +470,7 @@ class DokuCLI_Options { * Can only be used after parseOptions() has been run * * @param string $option - * @param mixed $default what to return if the option was not set + * @param mixed $default what to return if the option was not set * @return mixed */ public function getOpt($option, $default = false) { @@ -498,7 +501,7 @@ class DokuCLI_Options { $hasargs = (bool) $this->setup[$command]['args']; if(!$command) { - $text .= 'USAGE: ' . $this->bin; + $text .= 'USAGE: '.$this->bin; } else { $text .= "\n$command"; } @@ -507,9 +510,9 @@ class DokuCLI_Options { foreach($this->setup[$command]['args'] as $arg) { if($arg['required']) { - $text .= ' <' . $arg['name'] . '>'; + $text .= ' <'.$arg['name'].'>'; } else { - $text .= ' [<' . $arg['name'] . '>]'; + $text .= ' [<'.$arg['name'].'>]'; } } $text .= "\n"; @@ -517,8 +520,8 @@ class DokuCLI_Options { if($this->setup[$command]['help']) { $text .= "\n"; $text .= $this->tableFormat( - array(2, 72), - array('', $this->setup[$command]['help'] . "\n") + array(2, 72), + array('', $this->setup[$command]['help']."\n") ); } @@ -528,7 +531,7 @@ class DokuCLI_Options { $name = ''; if($opt['short']) { - $name .= '-' . $opt['short']; + $name .= '-'.$opt['short']; if($opt['needsarg']) $name .= ' <'.$opt['needsarg'].'>'; $name .= ', '; } @@ -536,8 +539,8 @@ class DokuCLI_Options { if($opt['needsarg']) $name .= ' <'.$opt['needsarg'].'>'; $text .= $this->tableFormat( - array(2, 20, 52), - array('', $name, $opt['help']) + array(2, 20, 52), + array('', $name, $opt['help']) ); $text .= "\n"; } @@ -546,11 +549,11 @@ class DokuCLI_Options { if($hasargs) { $text .= "\n"; foreach($this->setup[$command]['args'] as $arg) { - $name = '<' . $arg['name'] . '>'; + $name = '<'.$arg['name'].'>'; $text .= $this->tableFormat( - array(2, 20, 52), - array('', $name, $arg['help']) + array(2, 20, 52), + array('', $name, $arg['help']) ); } } @@ -591,7 +594,7 @@ class DokuCLI_Options { * Displays text in multiple word wrapped columns * * @param array $widths list of column widths (in characters) - * @param array $texts list of texts for each column + * @param array $texts list of texts for each column * @return string */ private function tableFormat($widths, $texts) { @@ -613,7 +616,7 @@ class DokuCLI_Options { } else { $val = ''; } - $out .= sprintf('%-' . $width . 's', $val); + $out .= sprintf('%-'.$width.'s', $val); } $out .= "\n"; } -- cgit v1.2.3 From b2e7cc706ef0f8a622d9973c418cc40e4addc436 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 16 May 2014 09:13:13 +0200 Subject: deprecated the old CLI opts parser --- inc/cliopts.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/cliopts.php b/inc/cliopts.php index 3eac72e5b..c75a5a93b 100644 --- a/inc/cliopts.php +++ b/inc/cliopts.php @@ -68,6 +68,7 @@ define('DOKU_CLI_OPTS_ARG_READ',5);//Could not read argv * * @author Andrei Zmievski * + * @deprecated 2014-05-16 */ class Doku_Cli_Opts { -- cgit v1.2.3 From e151bd73ba8b0f385b128cfe70c6d6e0eb4b7360 Mon Sep 17 00:00:00 2001 From: Hideaki SAWADA Date: Sat, 17 May 2014 08:11:01 +0200 Subject: translation update --- lib/plugins/extension/lang/ja/intro_install.txt | 2 +- lib/plugins/extension/lang/ja/intro_plugins.txt | 2 +- lib/plugins/extension/lang/ja/intro_templates.txt | 2 +- lib/plugins/extension/lang/ja/lang.php | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/plugins/extension/lang/ja/intro_install.txt b/lib/plugins/extension/lang/ja/intro_install.txt index 889ed6879..9f99b8202 100644 --- a/lib/plugins/extension/lang/ja/intro_install.txt +++ b/lib/plugins/extension/lang/ja/intro_install.txt @@ -1 +1 @@ -ここでは、アップロードするかダウンロードURLを指定して、手動でプラグインやテンプレートをインストールできます。 +アップロードするかダウンロードURLを指定して、手動でプラグインやテンプレートをインストールできます。 diff --git a/lib/plugins/extension/lang/ja/intro_plugins.txt b/lib/plugins/extension/lang/ja/intro_plugins.txt index 9bfc68431..b8251c7e8 100644 --- a/lib/plugins/extension/lang/ja/intro_plugins.txt +++ b/lib/plugins/extension/lang/ja/intro_plugins.txt @@ -1 +1 @@ -このDokuWikiに現在インストールされているプラグインです。ここでは、これらプラグインを有効化、無効化、アンインストールすることができます。同様にプラグインのアップデートも表示されます。アップデート前に、プラグインのマニュアルをお読みください。 \ No newline at end of file +このDokuWikiに現在インストールされているプラグインです。これらプラグインを有効化、無効化、アンインストールできます。更新はできる場合のみ表示されます。更新前に、プラグインの解説をお読みください。 \ No newline at end of file diff --git a/lib/plugins/extension/lang/ja/intro_templates.txt b/lib/plugins/extension/lang/ja/intro_templates.txt index f97694aaa..5de6d2f0d 100644 --- a/lib/plugins/extension/lang/ja/intro_templates.txt +++ b/lib/plugins/extension/lang/ja/intro_templates.txt @@ -1 +1 @@ -このDokuWikiに現在インストールされているテンプレートです。[[?do=admin&page=config|設定管理]]で使用するテンプレートを選択できます。 \ No newline at end of file +このDokuWikiに現在インストールされているテンプレートです。使用するテンプレートは[[?do=admin&page=config|設定管理]]で選択できます。 \ No newline at end of file diff --git a/lib/plugins/extension/lang/ja/lang.php b/lib/plugins/extension/lang/ja/lang.php index b42e4aefd..f1a95f7a2 100644 --- a/lib/plugins/extension/lang/ja/lang.php +++ b/lib/plugins/extension/lang/ja/lang.php @@ -83,3 +83,4 @@ $lang['nopluginperms'] = 'プラグインディレクトリが書き込 $lang['git'] = 'この拡張機能は Git 経由でインストールされており、ここで更新すべきでないかもしれません。'; $lang['install_url'] = 'URL からインストール:'; $lang['install_upload'] = '拡張機能をアップロード:'; +$lang['repo_error'] = 'プラグインのリポジトリに接続できません。サーバーが www.dokuwiki.org に接続できることやプロキシの設定を確認して下さい。'; -- cgit v1.2.3 From 5aa1e6b571d748ca5b0c7684ec6116c9e5f299d4 Mon Sep 17 00:00:00 2001 From: Rene Date: Sat, 17 May 2014 09:36:32 +0200 Subject: translation update --- lib/plugins/extension/lang/nl/lang.php | 2 +- lib/plugins/revert/lang/nl/intro.txt | 2 +- lib/plugins/revert/lang/nl/lang.php | 3 ++- lib/plugins/usermanager/lang/nl/intro.txt | 2 +- lib/plugins/usermanager/lang/nl/lang.php | 3 ++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/plugins/extension/lang/nl/lang.php b/lib/plugins/extension/lang/nl/lang.php index 524c2b2e7..c1c72e812 100644 --- a/lib/plugins/extension/lang/nl/lang.php +++ b/lib/plugins/extension/lang/nl/lang.php @@ -6,7 +6,7 @@ * @author Rene * @author Gerrit Uitslag */ -$lang['menu'] = 'Uitbreidings Beheerder'; +$lang['menu'] = 'Uitbreidingen'; $lang['tab_plugins'] = 'Geïnstalleerde Plugins'; $lang['tab_templates'] = 'Geïnstalleerde Templates'; $lang['tab_search'] = 'Zoek en installeer'; diff --git a/lib/plugins/revert/lang/nl/intro.txt b/lib/plugins/revert/lang/nl/intro.txt index db8f5a06c..efa325839 100644 --- a/lib/plugins/revert/lang/nl/intro.txt +++ b/lib/plugins/revert/lang/nl/intro.txt @@ -1,3 +1,3 @@ -===== Herstelmanager ===== +===== Herstel ===== Deze pagina helpt u bij het herstellen van pagina's na een spam-aanval. Vul een zoekterm in (bijvoorbeeld een spam url) om een lijst te krijgen van bekladde pagina's, bevestig dat de pagina's inderdaad spam bevatten en herstel de wijzigingen. diff --git a/lib/plugins/revert/lang/nl/lang.php b/lib/plugins/revert/lang/nl/lang.php index ee8678e63..d04b96869 100644 --- a/lib/plugins/revert/lang/nl/lang.php +++ b/lib/plugins/revert/lang/nl/lang.php @@ -16,8 +16,9 @@ * @author Ricardo Guijt * @author Gerrit * @author Remon + * @author Rene */ -$lang['menu'] = 'Herstelmanager'; +$lang['menu'] = 'Herstel'; $lang['filter'] = 'Zoek naar bekladde pagina\'s'; $lang['revert'] = 'Herstel geselecteerde pagina\'s'; $lang['reverted'] = '%s hersteld naar revisie %s'; diff --git a/lib/plugins/usermanager/lang/nl/intro.txt b/lib/plugins/usermanager/lang/nl/intro.txt index 7df09dbab..478174ab6 100644 --- a/lib/plugins/usermanager/lang/nl/intro.txt +++ b/lib/plugins/usermanager/lang/nl/intro.txt @@ -1 +1 @@ -==== Gebruikersmanager ===== \ No newline at end of file +==== Gebruikers ===== \ No newline at end of file diff --git a/lib/plugins/usermanager/lang/nl/lang.php b/lib/plugins/usermanager/lang/nl/lang.php index 5cebede89..3f9902e14 100644 --- a/lib/plugins/usermanager/lang/nl/lang.php +++ b/lib/plugins/usermanager/lang/nl/lang.php @@ -15,8 +15,9 @@ * @author Jeroen * @author Ricardo Guijt * @author Gerrit Uitslag + * @author Rene */ -$lang['menu'] = 'Gebruikersmanager'; +$lang['menu'] = 'Gebruikersbeheer'; $lang['noauth'] = '(gebruikersauthenticatie niet beschikbaar)'; $lang['nosupport'] = '(gebruikersbeheer niet ondersteund)'; $lang['badauth'] = 'ongeldige authenticatiemethode'; -- cgit v1.2.3 From f88adfe0b3b6ae718cb4a99c6f8363042c7b0b6e Mon Sep 17 00:00:00 2001 From: PzF_X Date: Sun, 18 May 2014 13:56:03 +0200 Subject: translation update --- inc/lang/ja/lang.php | 1 + lib/plugins/authad/lang/ja/lang.php | 8 ++++++++ lib/plugins/authad/lang/ja/settings.php | 2 ++ lib/plugins/authldap/lang/ja/settings.php | 7 +++++++ lib/plugins/extension/lang/ja/lang.php | 3 +++ 5 files changed, 21 insertions(+) create mode 100644 lib/plugins/authad/lang/ja/lang.php diff --git a/inc/lang/ja/lang.php b/inc/lang/ja/lang.php index f5c2f493f..a8bbe807b 100644 --- a/inc/lang/ja/lang.php +++ b/inc/lang/ja/lang.php @@ -11,6 +11,7 @@ * @author Satoshi Sahara * @author Hideaki SAWADA * @author Hideaki SAWADA + * @author PzF_X */ $lang['encoding'] = 'utf-8'; $lang['direction'] = 'ltr'; diff --git a/lib/plugins/authad/lang/ja/lang.php b/lib/plugins/authad/lang/ja/lang.php new file mode 100644 index 000000000..b40aa5da3 --- /dev/null +++ b/lib/plugins/authad/lang/ja/lang.php @@ -0,0 +1,8 @@ + + */ +$lang['domain'] = 'ログオン時のドメイン'; diff --git a/lib/plugins/authad/lang/ja/settings.php b/lib/plugins/authad/lang/ja/settings.php index f308249ef..118e8348c 100644 --- a/lib/plugins/authad/lang/ja/settings.php +++ b/lib/plugins/authad/lang/ja/settings.php @@ -5,6 +5,7 @@ * * @author Satoshi Sahara * @author Hideaki SAWADA + * @author PzF_X */ $lang['account_suffix'] = 'アカウントの接尾語。例:@my.domain.org'; $lang['base_dn'] = 'ベースDN。例:DC=my,DC=domain,DC=org'; @@ -12,6 +13,7 @@ $lang['domain_controllers'] = 'ドメインコントローラのカンマ区 $lang['admin_username'] = '全ユーザーデータへのアクセス権のある特権Active Directoryユーザー。任意ですが、メール通知の登録等の特定の動作に必要。'; $lang['admin_password'] = '上記ユーザーのパスワード'; $lang['sso'] = 'Kerberos か NTLM を使ったシングルサインオン(SSO)をしますか?'; +$lang['sso_charset'] = 'サーバーは空のUTF-8かLatin-1でKerberosかNTLMユーザネームを送信します。iconv拡張モジュールが必要です。'; $lang['real_primarygroup'] = '"Domain Users" を仮定する代わりに本当のプライマリグループを解決する(低速)'; $lang['use_ssl'] = 'SSL接続を使用しますか?使用した場合、下のSSLを有効にしないでください。'; $lang['use_tls'] = 'TLS接続を使用しますか?使用した場合、上のSSLを有効にしないでください。'; diff --git a/lib/plugins/authldap/lang/ja/settings.php b/lib/plugins/authldap/lang/ja/settings.php index 3c0e08f6a..6cff0ea67 100644 --- a/lib/plugins/authldap/lang/ja/settings.php +++ b/lib/plugins/authldap/lang/ja/settings.php @@ -6,6 +6,7 @@ * @author Satoshi Sahara * @author Hideaki SAWADA * @author Hideaki SAWADA + * @author PzF_X */ $lang['server'] = 'LDAPサーバー。ホスト名(localhost)又は完全修飾URL(ldap://server.tld:389)'; $lang['port'] = '上記が完全修飾URLでない場合、LDAPサーバーポート'; @@ -15,8 +16,14 @@ $lang['userfilter'] = 'ユーザーアカウントを探すためのL $lang['groupfilter'] = 'グループを探すLDAP抽出条件。例:(&(objectClass=posixGroup)(|(gidNumber=%{gid})(memberUID=%{user})))'; $lang['version'] = '使用するプロトコルのバージョン。3を設定する必要がある場合があります。'; $lang['starttls'] = 'TLS接続を使用しますか?'; +$lang['referrals'] = '紹介に従いますか?'; +$lang['deref'] = 'どのように間接参照のエイリアスにしますか?'; $lang['binddn'] = '匿名バインドでは不十分な場合、オプションバインドユーザーのDN。例:cn=admin, dc=my, dc=home'; $lang['bindpw'] = '上記ユーザーのパスワード'; +$lang['userscope'] = 'ユーザー検索の範囲を限定させる'; +$lang['groupscope'] = 'グループ検索の範囲を限定させる'; +$lang['groupkey'] = 'ユーザー属性をグループのメンバーシップから設定します(代わりに標準のADグループ)。 +例えば、部署や電話番号などです。'; $lang['debug'] = 'エラーに関して追加のデバッグ情報を表示する。'; $lang['deref_o_0'] = 'LDAP_DEREF_NEVER'; $lang['deref_o_1'] = 'LDAP_DEREF_SEARCHING'; diff --git a/lib/plugins/extension/lang/ja/lang.php b/lib/plugins/extension/lang/ja/lang.php index f1a95f7a2..dec46d629 100644 --- a/lib/plugins/extension/lang/ja/lang.php +++ b/lib/plugins/extension/lang/ja/lang.php @@ -4,6 +4,7 @@ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * * @author Hideaki SAWADA + * @author PzF_X */ $lang['menu'] = '拡張機能管理'; $lang['tab_plugins'] = 'インストール済プラグイン'; @@ -52,8 +53,10 @@ $lang['provides'] = '提供:'; $lang['status'] = '状態:'; $lang['status_installed'] = 'インストール済'; $lang['status_not_installed'] = '未インストール'; +$lang['status_protected'] = '保護されています'; $lang['status_enabled'] = '有効'; $lang['status_disabled'] = '無効'; +$lang['status_unmodifiable'] = '編集不可'; $lang['status_plugin'] = 'プラグイン'; $lang['status_template'] = 'テンプレート'; $lang['status_bundled'] = '同梱'; -- cgit v1.2.3 From 18496fe0decfb1382393daca3141bf315cda7254 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 18 May 2014 20:33:21 +0200 Subject: fixed undefined variable in LDAP plugin --- lib/plugins/authldap/auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/authldap/auth.php b/lib/plugins/authldap/auth.php index bda8f2abe..0d5e130ea 100644 --- a/lib/plugins/authldap/auth.php +++ b/lib/plugins/authldap/auth.php @@ -286,7 +286,7 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { // find the old password of the user list($loginuser,$loginsticky,$loginpass) = auth_getCookie(); if ($loginuser !== null) { // the user is currently logged in - $secret = auth_cookiesalt(!$sticky, true); + $secret = auth_cookiesalt(!$loginsticky, true); $pass = auth_decrypt($loginpass, $secret); // bind with the ldap -- cgit v1.2.3