aboutsummaryrefslogtreecommitdiff
path: root/mod/dokuwiki/vendors/dokuwiki/bin
diff options
context:
space:
mode:
Diffstat (limited to 'mod/dokuwiki/vendors/dokuwiki/bin')
-rwxr-xr-xmod/dokuwiki/vendors/dokuwiki/bin/dwpage.php378
-rwxr-xr-xmod/dokuwiki/vendors/dokuwiki/bin/indexer.php172
-rwxr-xr-xmod/dokuwiki/vendors/dokuwiki/bin/wantedpages.php134
3 files changed, 684 insertions, 0 deletions
diff --git a/mod/dokuwiki/vendors/dokuwiki/bin/dwpage.php b/mod/dokuwiki/vendors/dokuwiki/bin/dwpage.php
new file mode 100755
index 000000000..f664770bf
--- /dev/null
+++ b/mod/dokuwiki/vendors/dokuwiki/bin/dwpage.php
@@ -0,0 +1,378 @@
+#!/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;
+ }
+}
+
+#------------------------------------------------------------------------------
+function getUser() {
+ $user = getenv('USER');
+ if (empty ($username)) {
+ $user = getenv('USERNAME');
+ } else {
+ return $user;
+ }
+ if (empty ($username)) {
+ $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);
+ }
+ }
+
+}
+
+#------------------------------------------------------------------------------
+$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');
+}
+
+#------------------------------------------------------------------------------
+switch ( $OPTS->arg(0) ) {
+
+ #----------------------------------------------------------------------
+ case 'checkout':
+
+ $WIKI_ID = $OPTS->arg(1);
+
+ if ( !$WIKI_ID ) {
+ fwrite( STDERR, "Wiki page ID required\n");
+ exit(1);
+ }
+
+ $WIKI_FN = wikiFN($WIKI_ID);
+
+ if ( !file_exists($WIKI_FN) ) {
+ fwrite( STDERR, "$WIKI_ID does not yet exist\n");
+ exit(1);
+ }
+
+ $TARGET_FN = $OPTS->arg(2);
+
+ if ( empty($TARGET_FN) ) {
+ $TARGET_FN = getcwd().'/'.basename($WIKI_FN);
+ }
+
+ if ( !file_exists(dirname($TARGET_FN)) ) {
+ fwrite( STDERR, "Directory ".dirname($TARGET_FN)." does not exist\n");
+ exit(1);
+ }
+
+ 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);
+ }
+
+ if ( $OPTS->has('f') ) {
+ deleteLock($WIKI_ID);
+ }
+
+ obtainLock($WIKI_ID);
+
+ # 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);
+ }
+
+ print "$WIKI_ID > $TARGET_FN\n";
+ exit(0);
+
+ break;
+
+ #----------------------------------------------------------------------
+ case 'commit':
+
+ $TARGET_FN = $OPTS->arg(1);
+
+ if ( !$TARGET_FN ) {
+ fwrite( STDERR, "Target filename required\n");
+ exit(1);
+ }
+
+ if ( !file_exists($TARGET_FN) ) {
+ fwrite( STDERR, "$TARGET_FN does not exist\n");
+ exit(1);
+ }
+
+ if ( !is_readable($TARGET_FN) ) {
+ fwrite( STDERR, "Cannot read from $TARGET_FN\n");
+ exit(1);
+ }
+
+ $WIKI_ID = $OPTS->arg(2);
+
+ if ( !$WIKI_ID ) {
+ fwrite( STDERR, "Wiki page ID required\n");
+ exit(1);
+ }
+
+ if ( !$OPTS->has('m') ) {
+ fwrite( STDERR, "Summary message required\n");
+ exit(1);
+ }
+
+ if ( $OPTS->has('f') ) {
+ deleteLock($WIKI_ID);
+ }
+
+ $_SERVER['REMOTE_USER'] = $USERNAME;
+ if ( checklock($WIKI_ID) ) {
+ fwrite( STDERR, "$WIKI_ID is locked by another user\n");
+ 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);
+ }
+
+ if ( $OPTS->has('f') ) {
+ deleteLock($WIKI_ID);
+ } else {
+ clearLock($WIKI_ID);
+ }
+
+ print "Unlocked : $WIKI_ID\n";
+ exit(0);
+
+ break;
+
+ #----------------------------------------------------------------------
+ default:
+
+ fwrite( STDERR, "Invalid action ".$OPTS->arg(0)."\n" );
+ exit(1);
+
+ break;
+
+}
+
diff --git a/mod/dokuwiki/vendors/dokuwiki/bin/indexer.php b/mod/dokuwiki/vendors/dokuwiki/bin/indexer.php
new file mode 100755
index 000000000..55f3608d5
--- /dev/null
+++ b/mod/dokuwiki/vendors/dokuwiki/bin/indexer.php
@@ -0,0 +1,172 @@
+#!/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/pageutils.php');
+require_once(DOKU_INC.'inc/search.php');
+require_once(DOKU_INC.'inc/indexer.php');
+require_once(DOKU_INC.'inc/auth.php');
+require_once(DOKU_INC.'inc/cliopts.php');
+session_write_close();
+
+// Version tag used to force rebuild on upgrade
+// Need to keep in sync with lib/exe/indexer.php
+if(!defined('INDEXER_VERSION')) define('INDEXER_VERSION', 2);
+
+// 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;
+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;
+ }
+}
+
+#------------------------------------------------------------------------------
+# 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;
+
+ // upgrade to version 2
+ if (!@file_exists($conf['indexdir'].'/pageword.idx')){
+ _lock();
+ idx_upgradePageWords();
+ _unlock();
+ }
+
+ $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']);
+ }
+}
+
+function _index($id){
+ global $CLEAR;
+
+ // if not cleared only update changed and new files
+ if(!$CLEAR){
+ $idxtag = metaFN($id,'.indexed');
+ if(@file_exists($idxtag)){
+ if(io_readFile($idxtag) >= INDEXER_VERSION){
+ $last = @filemtime(metaFN($id,'.indexed'));
+ if($last > @filemtime(wikiFN($id))) return;
+ }
+ }
+ }
+
+ _lock();
+ _quietecho("$id... ");
+ idx_addPage($id);
+ io_saveFile(metaFN($id,'.indexed'),INDEXER_VERSION);
+ _quietecho("done.\n");
+ _unlock();
+}
+
+/**
+ * lock the indexer system
+ */
+function _lock(){
+ global $conf;
+ $lock = $conf['lockdir'].'/_indexer.lock';
+ $said = false;
+ while(!@mkdir($lock, $conf['dmode'])){
+ if(time()-@filemtime($lock) > 60*5){
+ // looks like a stale lock - remove it
+ @rmdir($lock);
+ }else{
+ if($said){
+ _quietecho(".");
+ }else{
+ _quietecho("Waiting for lockfile (max. 5 min)");
+ $said = true;
+ }
+ sleep(15);
+ }
+ }
+ if($conf['dperm']) chmod($lock, $conf['dperm']);
+ if($said) _quietecho("\n");
+}
+
+/**
+ * unlock the indexer sytem
+ */
+function _unlock(){
+ global $conf;
+ $lock = $conf['lockdir'].'/_indexer.lock';
+ @rmdir($lock);
+}
+
+/**
+ * Clear all index files
+ */
+function _clearindex(){
+ global $conf;
+ _lock();
+ _quietecho("Clearing index... ");
+ io_saveFile($conf['indexdir'].'/page.idx','');
+ $dir = @opendir($conf['indexdir']);
+ if($dir!==false){
+ while(($f = readdir($dir)) !== false){
+ if(substr($f,-4)=='.idx' &&
+ (substr($f,0,1)=='i' || substr($f,0,1)=='w'))
+ @unlink($conf['indexdir']."/$f");
+ }
+ }
+ _quietecho("done.\n");
+ _unlock();
+}
+
+function _quietecho($msg) {
+ global $QUIET;
+ if(!$QUIET) echo $msg;
+}
+
+//Setup VIM: ex: et ts=2 enc=utf-8 :
diff --git a/mod/dokuwiki/vendors/dokuwiki/bin/wantedpages.php b/mod/dokuwiki/vendors/dokuwiki/bin/wantedpages.php
new file mode 100755
index 000000000..30171fc15
--- /dev/null
+++ b/mod/dokuwiki/vendors/dokuwiki/bin/wantedpages.php
@@ -0,0 +1,134 @@
+#!/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';
+
+#------------------------------------------------------------------------------
+function usage() {
+ print "Usage: wantedpages.php [wiki:namespace]
+
+ Outputs a list of wanted pages (pages which have
+ internal links but do not yet exist).
+
+ If the optional [wiki:namespace] is not provided,
+ defaults to the root wiki namespace
+
+ OPTIONS
+ -h, --help get help
+";
+}
+
+#------------------------------------------------------------------------------
+define ('DW_DIR_CONTINUE',1);
+define ('DW_DIR_NS',2);
+define ('DW_DIR_PAGE',3);
+
+#------------------------------------------------------------------------------
+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;
+ }
+ 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'].':');
+ }
+
+ if ( !is_dir($dir) ) {
+ fwrite( STDERR, "Unable to read directory $dir\n");
+ exit(1);
+ }
+
+ $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,
+ );
+ $pages[] = $page;
+ }
+ }
+ 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;
+ }
+ }
+ }
+ 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);