summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_test/tests/inc/cli_options.test.php56
-rwxr-xr-xbin/dwpage.php597
-rwxr-xr-xbin/gittool.php216
-rwxr-xr-xbin/indexer.php175
-rwxr-xr-xbin/render.php94
-rwxr-xr-xbin/striplangs.php214
-rwxr-xr-xbin/wantedpages.php223
-rw-r--r--inc/cli.php647
-rw-r--r--inc/cliopts.php1
-rw-r--r--inc/common.php2
-rw-r--r--inc/load.php4
11 files changed, 1415 insertions, 814 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/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/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])){