From 8ca11112ee4ea52f9a3e824ad5d62eadd635cae5 Mon Sep 17 00:00:00 2001 From: Guillaume Turri Date: Sun, 29 Dec 2013 16:20:52 +0100 Subject: Fixed typo --- bin/striplangs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/striplangs.php b/bin/striplangs.php index ac95626c9..2bfddcea4 100755 --- a/bin/striplangs.php +++ b/bin/striplangs.php @@ -15,7 +15,7 @@ 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 instalation, besides the ones + Removes all languages from the installation, besides the ones after the -k option. English language is never removed! OPTIONS -- cgit v1.2.3 From c39ae2c9fac32286855eae27a5caeffb15f2621d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 5 Feb 2014 21:11:16 +0100 Subject: added bin/gittool.php for simpler git management of plugins Makes use of the extension plugin --- bin/gittool.php | 337 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 337 insertions(+) create mode 100755 bin/gittool.php (limited to 'bin') diff --git a/bin/gittool.php b/bin/gittool.php new file mode 100755 index 000000000..26aa1cc0e --- /dev/null +++ b/bin/gittool.php @@ -0,0 +1,337 @@ +#!/usr/bin/php +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 + +$> ./bin/gittool.php clone gallery template:ach +$> ./bin/gittool.php repos +$> ./bin/gittool.php origin -v + +COMMANDS + +help + This help screen + +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 + +install + The same as clone, but when no git source repository can be found, the + extension is installed via download + +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 + +EOF; + } + + /** + * Tries to install the given extensions using git clone + * + * @param $extensions + */ + public function cmd_clone($extensions) { + $errors = array(); + $succeeded = array(); + + foreach($extensions as $ext) { + $repo = $this->getSourceRepo($ext); + + if(!$repo) { + $this->msg_error("could not find a repository for $ext"); + $errors[] = $ext; + } else { + if($this->cloneExtension($ext, $repo)) { + $succeeded[] = $ext; + } else { + $errors[] = $ext; + } + } + } + + 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)); + } + + /** + * Tries to install the given extensions using git clone with fallback to install + * + * @param $extensions + */ + public function cmd_install($extensions) { + $errors = array(); + $succeeded = array(); + + foreach($extensions as $ext) { + $repo = $this->getSourceRepo($ext); + + if(!$repo) { + $this->msg_info("could not find a repository for $ext"); + if($this->downloadExtension($ext)) { + $succeeded[] = $ext; + } else { + $errors[] = $ext; + } + } else { + if($this->cloneExtension($ext, $repo)) { + $succeeded[] = $ext; + } else { + $errors[] = $ext; + } + } + } + + 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)); + } + + /** + * Executes the given git command in every repository + * + * @param $cmd + * @param $arg + */ + public function cmd_git($cmd, $arg) { + $repos = $this->findRepos(); + + $shell = array_merge(array('git', $cmd), $arg); + $shell = array_map('escapeshellarg', $shell); + $shell = join(' ', $shell); + + foreach($repos as $repo) { + if(!@chdir($repo)) { + $this->msg_error("Could not change into $repo"); + continue; + } + + echo "\n"; + $this->msg_info("executing $shell in $repo"); + $ret = 0; + system($shell, $ret); + + if($ret == 0) { + $this->msg_success("git succeeded in $repo"); + } else { + $this->msg_error("git failed in $repo"); + } + } + } + + /** + * Simply lists the repositories + */ + public function cmd_repos() { + $repos = $this->findRepos(); + foreach($repos as $repo) { + echo "$repo\n"; + } + } + + /** + * Install extension from the given download URL + * + * @param string $ext + * @return bool + */ + private function downloadExtension($ext) { + /** @var helper_plugin_extension_extension $plugin */ + $plugin = plugin_load('helper', 'extension_extension'); + if(!$ext) die("extension plugin not available, can't continue"); + $plugin->setExtension($ext); + + $url = $plugin->getDownloadURL(); + if(!$url) { + $this->msg_error("no download URL for $ext"); + return false; + } + + $ok = false; + try { + $this->msg_info("installing $ext via download from $url"); + $ok = $plugin->installFromURL($url); + } catch(Exception $e) { + $this->msg_error($e->getMessage()); + } + + if($ok) { + $this->msg_success("installed $ext via download"); + return true; + } else { + $this->msg_success("failed to install $ext via download"); + return false; + } + } + + /** + * Clones the extension from the given repository + * + * @param string $ext + * @param string $repo + * @return bool + */ + private function cloneExtension($ext, $repo) { + if(substr($ext, 0, 9) == 'template:') { + $target = fullpath(tpl_incdir().'../'.substr($ext, 9)); + } else { + $target = DOKU_PLUGIN.$ext; + } + + $this->msg_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"); + return true; + } else { + $this->msg_error("cloning of $ext failed"); + return false; + } + } + + /** + * Returns all git repositories in this DokuWiki install + * + * Looks in root, template and plugin directories only. + * + * @return array + */ + private function findRepos() { + $this->msg_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) + ); + + if(!$data) { + $this->msg_error('Found no .git directories'); + } else { + $this->msg_success('Found '.count($data).' .git directories'); + } + $data = array_map('dirname', $data); + return $data; + } + + /** + * Returns the repository for the given extension + * + * @param $extension + * @return bool|string + */ + private function getSourceRepo($extension) { + /** @var helper_plugin_extension_extension $ext */ + $ext = plugin_load('helper', 'extension_extension'); + if(!$ext) die("extension plugin not available, can't continue"); + $ext->setExtension($extension); + + // match github repos + if(preg_match('/github\.com\/([^\/]+)\/([^\/]+)/i', $ext->getSourcerepoURL(), $m)) { + $user = $m[1]; + $repo = $m[2]; + return 'https://github.com/'.$user.'/'.$repo.'.git'; + } + + // match gitorious repos + if(preg_match('/gitorious.org\/([^\/]+)\/([^\/]+)?/i', $ext->getSourcerepoURL(), $m)) { + $user = $m[1]; + $repo = $m[2]; + if(!$repo) $repo = $user; + + 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', $ext->getSourcerepoURL(), $m)) { + $user = $m[1]; + $repo = $m[2]; + 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 -- cgit v1.2.3 From 68cf024bfcff59b9a812cfcc53e3520a28c14ead Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 5 Feb 2014 21:42:31 +0100 Subject: check for empty repo --- bin/gittool.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'bin') diff --git a/bin/gittool.php b/bin/gittool.php index 26aa1cc0e..23e8552b4 100755 --- a/bin/gittool.php +++ b/bin/gittool.php @@ -276,15 +276,18 @@ EOF; if(!$ext) die("extension plugin not available, can't continue"); $ext->setExtension($extension); + $repourl = $ext->getSourcerepoURL(); + if(!$repourl) return false; + // match github repos - if(preg_match('/github\.com\/([^\/]+)\/([^\/]+)/i', $ext->getSourcerepoURL(), $m)) { + if(preg_match('/github\.com\/([^\/]+)\/([^\/]+)/i', $repourl, $m)) { $user = $m[1]; $repo = $m[2]; return 'https://github.com/'.$user.'/'.$repo.'.git'; } // match gitorious repos - if(preg_match('/gitorious.org\/([^\/]+)\/([^\/]+)?/i', $ext->getSourcerepoURL(), $m)) { + if(preg_match('/gitorious.org\/([^\/]+)\/([^\/]+)?/i', $repourl, $m)) { $user = $m[1]; $repo = $m[2]; if(!$repo) $repo = $user; @@ -293,7 +296,7 @@ EOF; } // match bitbucket repos - most people seem to use mercurial there though - if(preg_match('/bitbucket\.org\/([^\/]+)\/([^\/]+)/i', $ext->getSourcerepoURL(), $m)) { + if(preg_match('/bitbucket\.org\/([^\/]+)\/([^\/]+)/i', $repourl, $m)) { $user = $m[1]; $repo = $m[2]; return 'https://bitbucket.org/'.$user.'/'.$repo.'.git'; -- cgit v1.2.3 From b0c7084fa9305409ef9717c5c64f9bcd31f8923c Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 14 Feb 2014 10:22:25 +0100 Subject: always fullpath repo dirs --- bin/gittool.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/gittool.php b/bin/gittool.php index 23e8552b4..f9f68ac94 100755 --- a/bin/gittool.php +++ b/bin/gittool.php @@ -260,7 +260,7 @@ EOF; } else { $this->msg_success('Found '.count($data).' .git directories'); } - $data = array_map('dirname', $data); + $data = array_map('fullpath', array_map('dirname', $data)); return $data; } -- 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 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 116 insertions(+), 115 deletions(-) (limited to 'bin') 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 -- 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 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'bin') 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 * -- 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 ++++++++++++++--------------- 3 files changed, 135 insertions(+), 143 deletions(-) (limited to 'bin') 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 -- 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(-) (limited to 'bin') 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(-) (limited to 'bin') 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 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(-) (limited to 'bin') 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 +++++++++--------- 5 files changed, 105 insertions(+), 96 deletions(-) (limited to 'bin') 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; } -- cgit v1.2.3 From 42ea7f447f39fbc2f79eaaec31f8c10ede59c5d0 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 11:30:27 +0200 Subject: Many PHPDocs, some unused and dyn declared vars many PHPDocs some unused variables some dynamically declared variables declared --- bin/gittool.php | 6 +++--- bin/wantedpages.php | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'bin') diff --git a/bin/gittool.php b/bin/gittool.php index 6944dde57..7991a9997 100755 --- a/bin/gittool.php +++ b/bin/gittool.php @@ -101,7 +101,7 @@ class GitToolCLI extends DokuCLI { /** * Tries to install the given extensions using git clone * - * @param $extensions + * @param array $extensions */ public function cmd_clone($extensions) { $errors = array(); @@ -130,7 +130,7 @@ class GitToolCLI extends DokuCLI { /** * Tries to install the given extensions using git clone with fallback to install * - * @param $extensions + * @param array $extensions */ public function cmd_install($extensions) { $errors = array(); @@ -291,7 +291,7 @@ class GitToolCLI extends DokuCLI { * Returns the repository for the given extension * * @param $extension - * @return bool|string + * @return false|string */ private function getSourceRepo($extension) { /** @var helper_plugin_extension_extension $ext */ diff --git a/bin/wantedpages.php b/bin/wantedpages.php index 8fc4ba74f..54bfd4755 100755 --- a/bin/wantedpages.php +++ b/bin/wantedpages.php @@ -61,6 +61,13 @@ class WantedPagesCLI extends DokuCLI { } } + /** + * Determine directions of the search loop + * + * @param string $entry + * @param string $basepath + * @return int + */ protected function dir_filter($entry, $basepath) { if($entry == '.' || $entry == '..') { return WantedPagesCLI::DIR_CONTINUE; @@ -77,6 +84,13 @@ class WantedPagesCLI extends DokuCLI { return WantedPagesCLI::DIR_CONTINUE; } + /** + * Collects recursively the pages in a namespace + * + * @param string $dir + * @return array + * @throws DokuCLI_Exception + */ protected function get_pages($dir) { static $trunclen = null; if(!$trunclen) { @@ -108,6 +122,12 @@ class WantedPagesCLI extends DokuCLI { return $pages; } + /** + * Parse instructions and returns the non-existing links + * + * @param array $page array with page id and file path + * @return array + */ function internal_links($page) { global $conf; $instructions = p_get_instructions(file_get_contents($page['file'])); -- cgit v1.2.3 From 7e8500eea1e53b1de0e0f70400664afa442cd08d Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Thu, 2 Oct 2014 14:55:24 +0200 Subject: PHPDocs and some improvements --- bin/gittool.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/gittool.php b/bin/gittool.php index 7991a9997..cbadb5bfa 100755 --- a/bin/gittool.php +++ b/bin/gittool.php @@ -206,12 +206,13 @@ class GitToolCLI extends DokuCLI { * Install extension from the given download URL * * @param string $ext - * @return bool + * @return bool|null */ private function downloadExtension($ext) { /** @var helper_plugin_extension_extension $plugin */ $plugin = plugin_load('helper', 'extension_extension'); if(!$ext) die("extension plugin not available, can't continue"); + $plugin->setExtension($ext); $url = $plugin->getDownloadURL(); @@ -297,6 +298,7 @@ class GitToolCLI extends DokuCLI { /** @var helper_plugin_extension_extension $ext */ $ext = plugin_load('helper', 'extension_extension'); if(!$ext) die("extension plugin not available, can't continue"); + $ext->setExtension($extension); $repourl = $ext->getSourcerepoURL(); -- cgit v1.2.3 From 47914fdf9a86d3ce2b75fc6f7743bc604711e6aa Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 17 Oct 2014 17:25:20 +0200 Subject: -k requires parameter. fixes #902 --- bin/striplangs.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/striplangs.php b/bin/striplangs.php index 6335bc84c..82d27d462 100755 --- a/bin/striplangs.php +++ b/bin/striplangs.php @@ -26,7 +26,8 @@ class StripLangsCLI extends DokuCLI { $options->registerOption( 'keep', 'Comma separated list of languages to keep in addition to English.', - 'k' + 'k', + 'langcodes' ); $options->registerOption( 'english-only', -- cgit v1.2.3 From bf00b3965f373b9497752ef97b25d9f29be35ca0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 9 Feb 2015 10:22:12 +0100 Subject: fix username handling in dwpage CLI tool. closes #1019 --- bin/dwpage.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/dwpage.php b/bin/dwpage.php index a777fd3e1..d7f6e9bb8 100755 --- a/bin/dwpage.php +++ b/bin/dwpage.php @@ -28,7 +28,8 @@ class PageCLI extends DokuCLI { $options->registerOption( 'user', 'work as this user. defaults to current CLI user', - 'u' + 'u', + 'username' ); $options->setHelp( 'Utility to help command line Dokuwiki page editing, allow '. @@ -239,6 +240,7 @@ class PageCLI extends DokuCLI { 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); @@ -246,7 +248,6 @@ class PageCLI extends DokuCLI { lock($wiki_id); - $_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)); -- cgit v1.2.3