diff options
30 files changed, 1539 insertions, 826 deletions
diff --git a/_test/tests/inc/cli_options.test.php b/_test/tests/inc/cli_options.test.php new file mode 100644 index 000000000..ab03ee29b --- /dev/null +++ b/_test/tests/inc/cli_options.test.php @@ -0,0 +1,56 @@ +<?php + +class cli_options extends DokuWikiTest { + + function test_simpleshort() { + $options = new DokuCLI_Options(); + $options->registerOption('exclude', 'exclude files', 'x', 'file'); + + $options->args = array('-x', 'foo', 'bang'); + $options->parseOptions(); + + $this->assertEquals('foo', $options->getOpt('exclude')); + $this->assertEquals(array('bang'), $options->args); + $this->assertFalse($options->getOpt('nothing')); + } + + function test_simplelong1() { + $options = new DokuCLI_Options(); + $options->registerOption('exclude', 'exclude files', 'x', 'file'); + + $options->args = array('--exclude', 'foo', 'bang'); + $options->parseOptions(); + + $this->assertEquals('foo', $options->getOpt('exclude')); + $this->assertEquals(array('bang'), $options->args); + $this->assertFalse($options->getOpt('nothing')); + } + + function test_simplelong2() { + $options = new DokuCLI_Options(); + $options->registerOption('exclude', 'exclude files', 'x', 'file'); + + $options->args = array('--exclude=foo', 'bang'); + $options->parseOptions(); + + $this->assertEquals('foo', $options->getOpt('exclude')); + $this->assertEquals(array('bang'), $options->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'); + + $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'), $options->args); + } +}
\ No newline at end of file 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 <?php -#------------------------------------------------------------------------------ -if ('cli' != php_sapi_name()) die(); - -ini_set('memory_limit','128M'); -if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); -require_once DOKU_INC.'inc/init.php'; -require_once DOKU_INC.'inc/common.php'; -require_once DOKU_INC.'inc/cliopts.php'; - -#------------------------------------------------------------------------------ -function usage($action) { - switch ( $action ) { - case 'checkout': - print "Usage: dwpage.php [opts] checkout <wiki:page> [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=<action>: get help - -f: force obtaining a lock for the page (generally bad idea) -"; - break; - case 'commit': - print "Usage: dwpage.php [opts] -m \"Msg\" commit <working_file> <wiki:page> - - 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=<action>: 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 <wiki:page> - - Obtains or updates a lock for a wiki page - - EXAMPLE - $ ./dwpage.php lock wiki:syntax - - OPTIONS - -h, --help=<action>: get help - -f: force obtaining a lock for the page (generally bad idea) -"; - break; - case 'unlock': - print "Usage: dwpage.php [opts] unlock <wiki:page> - - Removes a lock for a wiki page. - - EXAMPLE - $ ./dwpage.php unlock wiki:syntax - - OPTIONS - -h, --help=<action>: get help - -f: force obtaining a lock for the page (generally bad idea) -"; - break; - default: - print "Usage: dwpage.php [opts] <action> - - 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=<action>: 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 diff --git a/bin/gittool.php b/bin/gittool.php index f9f68ac94..6944dde57 100755 --- a/bin/gittool.php +++ b/bin/gittool.php @@ -1,78 +1,101 @@ #!/usr/bin/php <?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'); -$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 <andi@splitbrain.org> */ -class GitToolCLI { - private $color = true; - - public function cmd_help() { - echo <<<EOF -Usage: gittool.php <command> [parameters] - -Manage git repositories for DokuWiki and its plugins and templates. +class GitToolCLI extends DokuCLI { -EXAMPLE - -$> ./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". + "$> ./bin/gittool.php clone gallery template:ach\n". + "$> ./bin/gittool.php repos\n". + "$> ./bin/gittool.php origin -v" + ); -help - This help screen + $options->registerArgument( + 'command', + 'Command to execute. See below', + true + ); -clone <extensions> - 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 <extensions> - 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> - 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(); + 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); + } } /** @@ -88,7 +111,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 +123,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 +140,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 +156,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 +175,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 +216,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; } } @@ -228,14 +251,14 @@ EOF; $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,7 +271,7 @@ 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), @@ -256,9 +279,9 @@ EOF; ); 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; @@ -304,37 +327,8 @@ EOF; 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 +// Main +$cli = new GitToolCLI(); +$cli->run();
\ No newline at end of file diff --git a/bin/indexer.php b/bin/indexer.php index 6f6b5d9fa..13895c36a 100755 --- a/bin/indexer.php +++ b/bin/indexer.php @@ -1,98 +1,103 @@ #!/usr/bin/php <?php -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/cliopts.php'); -session_write_close(); -// handle options -$short_opts = 'hcuq'; -$long_opts = array('help', 'clear', 'update', 'quiet'); -$OPTS = Doku_Cli_Opts::getOptions(__FILE__,$short_opts,$long_opts); -if ( $OPTS->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; +/** + * Update the Search Index from command line + */ +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 <options> - - 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..672993223 100755 --- a/bin/render.php +++ b/bin/render.php @@ -1,5 +1,10 @@ #!/usr/bin/php <?php +if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__).'/../').'/'); +define('NOSESSION', 1); +require_once(DOKU_INC.'inc/init.php'); + + /** * A simple commandline tool to render some DokuWiki syntax with a given * renderer. @@ -9,59 +14,48 @@ * DokuWiki markup * * @license GPL2 - * @author Andreas Gohr <andi@splitbrain.org> + * @author Andreas Gohr <andi@splitbrain.org> */ -if ('cli' != php_sapi_name()) die(); +class RenderCLI extends DokuCLI { -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'); - -// 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'); } -} + /** + * 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'); -// 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; - -/** - * Print usage info - */ -function _usage(){ - print "Usage: render.php <options> - - Reads DokuWiki syntax from STDIN and renders it with the given renderer - to STDOUT - - OPTIONS - -h, --help show this help and exit - -r, --renderer <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/bin/striplangs.php b/bin/striplangs.php index 2bfddcea4..6335bc84c 100755 --- a/bin/striplangs.php +++ b/bin/striplangs.php @@ -1,148 +1,110 @@ #!/usr/bin/php <?php -/** - * Strip unwanted languages from the DokuWiki install - * - * @author Martin 'E.T.' Misuth <et.github@ethome.sk> - */ -if ('cli' != php_sapi_name()) die(); - -#------------------------------------------------------------------------------ -if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); -require_once DOKU_INC.'inc/cliopts.php'; - -#------------------------------------------------------------------------------ -function usage($show_examples = false) { - print "Usage: striplangs.php [-h [-x]] [-e] [-k lang1[,lang2]..[,langN]] - - Removes all languages from the installation, besides the ones - after the -k option. English language is never removed! +if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__).'/../').'/'); +define('NOSESSION', 1); +require_once(DOKU_INC.'inc/init.php'); - 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); +/** + * Remove unwanted languages from a DokuWiki install + */ +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); + /** + * 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); - while(($cur_dir = $dir->read()) !== false) { - if( $cur_dir != '.' and $cur_dir != '..' and is_dir($path.'/'.$cur_dir)) { + while(($cur_dir = $dir->read()) !== false) { + if($cur_dir != '.' and $cur_dir != '..' and is_dir($path.'/'.$cur_dir)) { - if ( !in_array($cur_dir, $keep_langs, true ) ) { - killDir($path.'/'.$cur_dir); - } - } - } - $dir->close(); -} - -function killDir($dir) { - if (is_dir($dir)) { - $entries = scandir($dir); - - foreach ($entries as $entry) { - if ($entry != "." && $entry != "..") { - if ( is_dir($dir.'/'.$entry) ) { - killDir($dir.'/'.$entry); - } else { - unlink($dir.'/'.$entry); + 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 diff --git a/bin/wantedpages.php b/bin/wantedpages.php index afcb6b271..8fc4ba74f 100755 --- a/bin/wantedpages.php +++ b/bin/wantedpages.php @@ -1,134 +1,133 @@ #!/usr/bin/php <?php -if ('cli' != php_sapi_name()) die(); - -#------------------------------------------------------------------------------ -ini_set('memory_limit','128M'); -if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); -require_once DOKU_INC.'inc/init.php'; -require_once DOKU_INC.'inc/common.php'; -require_once DOKU_INC.'inc/search.php'; -require_once DOKU_INC.'inc/cliopts.php'; +if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__).'/../').'/'); +define('NOSESSION', 1); +require_once(DOKU_INC.'inc/init.php'); + +/** + * Find wanted pages + */ +class WantedPagesCLI extends DokuCLI { + + const DIR_CONTINUE = 1; + const DIR_NS = 2; + const DIR_PAGE = 3; + + /** + * Register options and arguments on the given $options object + * + * @param DokuCLI_Options $options + * @return void + */ + protected function setup(DokuCLI_Options $options) { + $options->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 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 <btcoburn@silicodon.net> * @author Kate Arzamastseva <pshns@ukr.net> */ 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 <btcoburn@silicodon.net> * @author Kate Arzamastseva <pshns@ukr.net> */ 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/cli.php b/inc/cli.php new file mode 100644 index 000000000..25bfddf7d --- /dev/null +++ b/inc/cli.php @@ -0,0 +1,647 @@ +<?php + +/** + * Class DokuCLI + * + * All DokuWiki commandline scripts should inherit from this class and implement the abstract methods. + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +abstract class DokuCLI { + /** @var string the executed script itself */ + protected $bin; + /** @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->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 + * @return void + */ + abstract protected function main(DokuCLI_Options $options); + + /** + * 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(); + + // handle defaults + if($this->options->getOpt('no-colors')) { + $this->colors->disable(); + } + if($this->options->getOpt('help')) { + echo $this->options->help(); + exit(0); + } + + // check arguments + $this->options->checkArguments(); + + // execute + $this->main($this->options); + + exit(0); + } + + /** + * 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_object($error) && is_a($error, 'Exception')) { + /** @var Exception $error */ + $code = $error->getCode(); + $error = $error->getMessage(); + } + if(!$code) $code = DokuCLI_Exception::E_ANY; + + $this->error($error); + exit($code); + } + + /** + * Print an error message + * + * @param $string + */ + public function error($string) { + $this->colors->ptln("E: $string", 'red', STDERR); + } + + /** + * Print a success message + * + * @param $string + */ + public function success($string) { + $this->colors->ptln("S: $string", 'green', STDERR); + } + + /** + * Print an info message + * + * @param $string + */ + public function info($string) { + $this->colors->ptln("I: $string", 'cyan', STDERR); + } + +} + +/** + * Class DokuCLI_Colors + * + * Handles color output on (Linux) terminals + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +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 + * @param resource $channel + */ + public function ptln($line, $color, $channel = STDOUT) { + $this->set($color); + fwrite($channel, 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 <andi@splitbrain.org> + */ +class DokuCLI_Options { + /** @var array keeps the list of options to parse */ + protected $setup; + + /** @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; + + /** + * Constructor + */ + public function __construct() { + $this->setup = array( + '' => array( + 'opts' => array(), + 'args' => array(), + 'help' => '' + ) + ); // default command + + $this->args = $this->readPHPArgv(); + $this->bin = basename(array_shift($this->args)); + + $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|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 + */ + 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() + * + * @throws DokuCLI_Exception + */ + public function checkArguments() { + $argc = count($this->args); + + $req = 0; + foreach($this->setup[$this->command]['args'] as $arg) { + if(!$arg['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 + * + * @throws DokuCLI_Exception + */ + public function parseOptions() { + $non_opts = array(); + + $argc = count($this->args); + for($i = 0; $i < $argc; $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($this->args, $i + 1)); + break; + } + + // '-' is stdin - a normal argument + if($arg == '-') { + $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($this->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]/', $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); + } + $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]/', $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); + } + $this->options[$opt] = $val; + } else { + $this->options[$opt] = true; + } + } + + // parsing is now done, update args array + $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]])) { + // it is a command! + $this->command = array_shift($this->args); + $this->parseOptions(); // 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 string $option + * @param mixed $default what to return if the option was not set + * @return mixed + */ + public function getOpt($option, $default = false) { + if(isset($this->options[$option])) return $this->options[$option]; + return $default; + } + + /** + * 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 + * + * @return string + */ + public function help() { + $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: '.$this->bin; + } else { + $text .= "\n$command"; + } + + if($hasopts) $text .= ' <OPTIONS>'; + + foreach($this->setup[$command]['args'] as $arg) { + if($arg['required']) { + $text .= ' <'.$arg['name'].'>'; + } else { + $text .= ' [<'.$arg['name'].'>]'; + } + } + $text .= "\n"; + + if($this->setup[$command]['help']) { + $text .= "\n"; + $text .= $this->tableFormat( + array(2, 72), + array('', $this->setup[$command]['help']."\n") + ); + } + + if($hasopts) { + $text .= "\n OPTIONS\n\n"; + foreach($this->setup[$command]['opts'] as $long => $opt) { + + $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"; + } + } + + if($hasargs) { + $text .= "\n"; + foreach($this->setup[$command]['args'] as $arg) { + $name = '<'.$arg['name'].'>'; + + $text .= $this->tableFormat( + array(2, 20, 52), + array('', $name, $arg['help']) + ); + } + } + + if($command == '' && $hascommands) { + $text .= "\nThis tool accepts a command as first parameter as outlined below:\n"; + } + } + + 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; + } + + /** + * 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, "\n", 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; + } +} + +/** + * 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 <andi@splitbrain.org> + */ +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/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 <andrei@php.net> * + * @deprecated 2014-05-16 */ class Doku_Cli_Opts { diff --git a/inc/common.php b/inc/common.php index 110b91417..84121fd43 100644 --- a/inc/common.php +++ b/inc/common.php @@ -797,7 +797,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; } diff --git a/inc/infoutils.php b/inc/infoutils.php index 4faaee8ef..db856141f 100644 --- a/inc/infoutils.php +++ b/inc/infoutils.php @@ -394,6 +394,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 * * @author Gary Owen <gary_owen@bigfoot.com> diff --git a/inc/lang/ja/lang.php b/inc/lang/ja/lang.php index 31832c71f..e3eb4c7c7 100644 --- a/inc/lang/ja/lang.php +++ b/inc/lang/ja/lang.php @@ -11,6 +11,7 @@ * @author Satoshi Sahara <sahara.satoshi@gmail.com> * @author Hideaki SAWADA <chuno@live.jp> * @author Hideaki SAWADA <sawadakun@live.jp> + * @author PzF_X <jp_minecraft@yahoo.co.jp> */ $lang['encoding'] = 'utf-8'; $lang['direction'] = 'ltr'; 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])){ 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); } 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 @@ +<?php + +/** + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * + * @author PzF_X <jp_minecraft@yahoo.co.jp> + */ +$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 <sahara.satoshi@gmail.com> * @author Hideaki SAWADA <chuno@live.jp> + * @author PzF_X <jp_minecraft@yahoo.co.jp> */ $lang['account_suffix'] = 'アカウントの接尾語。例:<code>@my.domain.org</code>'; $lang['base_dn'] = 'ベースDN。例:<code>DC=my,DC=domain,DC=org</code>'; @@ -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/auth.php b/lib/plugins/authldap/auth.php index 6c3637e15..0d5e130ea 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; } /** @@ -264,6 +264,62 @@ class auth_plugin_authldap extends DokuWiki_Auth_Plugin { } /** + * 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'); + return false; + } + $dn = $info['dn']; + + // 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(!$loginsticky, 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; + } + } 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 + } + + // 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))); + return false; + } + + return true; + } + + /** * Most values in LDAP are case-insensitive * * @return bool 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 <sahara.satoshi@gmail.com> * @author Hideaki SAWADA <sawadakun@live.jp> * @author Hideaki SAWADA <chuno@live.jp> + * @author PzF_X <jp_minecraft@yahoo.co.jp> */ $lang['server'] = 'LDAPサーバー。ホスト名(<code>localhost</code>)又は完全修飾URL(<code>ldap://server.tld:389</code>)'; $lang['port'] = '上記が完全修飾URLでない場合、LDAPサーバーポート'; @@ -15,8 +16,14 @@ $lang['userfilter'] = 'ユーザーアカウントを探すためのL $lang['groupfilter'] = 'グループを探すLDAP抽出条件。例:<code>(&(objectClass=posixGroup)(|(gidNumber=%{gid})(memberUID=%{user})))</code>'; $lang['version'] = '使用するプロトコルのバージョン。<code>3</code>を設定する必要がある場合があります。'; $lang['starttls'] = 'TLS接続を使用しますか?'; +$lang['referrals'] = '紹介に従いますか?'; +$lang['deref'] = 'どのように間接参照のエイリアスにしますか?'; $lang['binddn'] = '匿名バインドでは不十分な場合、オプションバインドユーザーのDN。例:<code>cn=admin, dc=my, dc=home</code>'; $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/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..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 <chuno@live.jp> + * @author PzF_X <jp_minecraft@yahoo.co.jp> */ $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'] = '同梱'; @@ -83,3 +86,4 @@ $lang['nopluginperms'] = 'プラグインディレクトリが書き込 $lang['git'] = 'この拡張機能は Git 経由でインストールされており、ここで更新すべきでないかもしれません。'; $lang['install_url'] = 'URL からインストール:'; $lang['install_upload'] = '拡張機能をアップロード:'; +$lang['repo_error'] = 'プラグインのリポジトリに接続できません。サーバーが www.dokuwiki.org に接続できることやプロキシの設定を確認して下さい。'; 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 <wllywlnt@yahoo.com> * @author Gerrit Uitslag <klapinklapin@gmail.com> */ -$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 <ricardoguijt@gmail.com> * @author Gerrit <klapinklapin@gmail.com> * @author Remon <no@email.local> + * @author Rene <wllywlnt@yahoo.com> */ -$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 46968ac2d..819e64d7d 100644 --- a/lib/plugins/usermanager/lang/nl/intro.txt +++ b/lib/plugins/usermanager/lang/nl/intro.txt @@ -1 +1 @@ -====== Gebruikersmanager ====== +====== Gebruikersbeheer ====== 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 <ricardoguijt@gmail.com> * @author Gerrit Uitslag <klapinklapin@gmail.com> + * @author Rene <wllywlnt@yahoo.com> */ -$lang['menu'] = 'Gebruikersmanager'; +$lang['menu'] = 'Gebruikersbeheer'; $lang['noauth'] = '(gebruikersauthenticatie niet beschikbaar)'; $lang['nosupport'] = '(gebruikersbeheer niet ondersteund)'; $lang['badauth'] = 'ongeldige authenticatiemethode'; |