Skip to content

Commit

Permalink
code reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed May 16, 2014
1 parent e82b082 commit 1c36b3d
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 128 deletions.
84 changes: 42 additions & 42 deletions bin/gittool.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/php
<?php
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');

/**
* Easily manage DokuWiki git repositories
Expand All @@ -19,51 +19,51 @@ class GitToolCLI extends DokuCLI {
*/
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"
"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'
);
}

Expand All @@ -81,7 +81,7 @@ protected function main(DokuCLI_Options $options) {

switch($command) {
case '':
echo $options->help('foo');
echo $options->help();
break;
case 'clone':
$this->cmd_clone($options->args);
Expand Down Expand Up @@ -123,8 +123,8 @@ public function cmd_clone($extensions) {
}

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));
}

/**
Expand Down Expand Up @@ -156,8 +156,8 @@ public function cmd_install($extensions) {
}

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));
}

/**
Expand Down Expand Up @@ -246,9 +246,9 @@ private function downloadExtension($ext) {
*/
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");
Expand All @@ -273,15 +273,15 @@ private function cloneExtension($ext, $repo) {
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;
Expand All @@ -306,7 +306,7 @@ private function getSourceRepo($extension) {
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
Expand All @@ -315,14 +315,14 @@ private function getSourceRepo($extension) {
$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;
Expand Down
25 changes: 14 additions & 11 deletions bin/indexer.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/php
<?php
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');

/**
* Update the Search Index from command line
*/
class IndexerCLI extends DokuCLI {

private $quiet = false;
Expand All @@ -17,19 +20,19 @@ class IndexerCLI extends DokuCLI {
*/
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.'
'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'
);
}

Expand Down Expand Up @@ -58,7 +61,7 @@ function update() {
$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']);
Expand Down
18 changes: 9 additions & 9 deletions bin/render.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/php
<?php
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');


/**
Expand All @@ -14,7 +14,7 @@
* DokuWiki markup
*
* @license GPL2
* @author Andreas Gohr <[email protected]>
* @author Andreas Gohr <[email protected]>
*/
class RenderCLI extends DokuCLI {

Expand All @@ -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');
}
Expand All @@ -49,7 +49,7 @@ protected function main(DokuCLI_Options $options) {

// 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;
Expand Down
45 changes: 24 additions & 21 deletions bin/striplangs.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/php
<?php
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');


/**
* Remove unwanted languages from a DokuWiki install
*/
class StripLangsCLI extends DokuCLI {

/**
Expand All @@ -16,19 +19,19 @@ class StripLangsCLI extends DokuCLI {
protected function setup(DokuCLI_Options $options) {

$options->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'
);
}

Expand All @@ -52,26 +55,26 @@ protected function main(DokuCLI_Options $options) {
}

// 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)) {
$entries = scandir($path);

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);
Expand All @@ -85,17 +88,17 @@ protected function processExtensions($path, $keep_langs) {
/**
* 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);
}
}
}
Expand Down
Loading

0 comments on commit 1c36b3d

Please sign in to comment.