[dokuwiki] Re: graphics in articles

  • From: Jon Buckingham <jon.buckingham@xxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Thu, 25 Jan 2007 15:11:19 +0000

Simple answer: yes, it is a disjoint process, and
you don't get revision histories for "media" either.

But overall we find it a huge net benefit still to use
an on-line documentation such as dokuwiki.

Regarding source, we always upload the source and link it at the
top of every page which has media links.
This in itself can be painful, since one source may
generate several images, and when you change them, you have to upload
them manually with many mouse clicks one by one.

So we use a script for this (which is written for linux systems)
which makes media uploading of modified diagrams a lot easier.

It basically uses rsync, and the source is appended.

Jon B

#!/usr/bin/perl

#####################################################################################
#
#--
#-- Usage : dokumediaupdate [ -h ] [ -s server ] [ -m module ] [ -n namespace ] 
file...
#--
#--        options: -h            help page
#--                 -s server     Server name.
#--                 -m module     Rsync module name for dokuwiki. Default: 
dokuwiki
#--                 -n namespace  Optional namespace (or part of namespace).
#--                               By default, namespace will be found 
automatically.
#--                               If more than one file of same name found,
#--                               then namespace has to be specified.
#--                               format: wiki/dir1/dir2 or wiki:dir1:dir2
#--
#--  Function:
#--    Copies (using rsync) specified local files to dokuwiki server.
#--
#--  Design Details:
#--    Uses rsync server running on the remote server.
#--    Remote server rsyncd.conf looks something like...
#--       pid file = /var/run/rsyncd.pid
#--       [dokuwiki]
#--       path = /home/wwwrnd/public_html/dokuwiki-2006-11-06/data/media
#--       hosts allow = *.my.domain  ## Put your domains here
#--       hosts deny  = *
#--       uid = apache
#--       gid = apache
#--       read only = no
#--       transfer logging = yes
#--       use chroot = no
#--
#
#####################################################################################

#####################################################################################
#
# Globals, defaults etc
#
#####################################################################################

use warnings;

require "getopts.pl";

############################### GLOBALS ##########################

my $progname  = $0;
my $exit_code = 0;
my $server    = "my.server.here";  ## Modify for your server
my $module    = "dokuwiki";
my $namespace;

############################### USAGE Subroutine ##########################

sub usage { $MyName = $progname;
            open MyName;
            while (<MyName>)
               {
               print if s/^#--//;
               }
          }

####################### Case conversion #############################3
sub tolower {
   my ($str) = @_;
   $str =~ tr/A-Z/a-z/;
   return $str;
   }

sub toupper {
   my ($str) = @_;
   $str =~ tr/a-z/A-Z/;
   return $str;
   }

####################### Integer conversion Subroutine ##########################

sub convint {
   my ($val) = @_;
   if ($val =~ /^0x/) {
      return oct($val);   ### oct does hex aswell!!
      }
   else {
      return $val;
      }
   }

######################## Convert value to binary string ##################
# params: val  - convint format integer to convert
#         bits - number of binary bits to display
sub convbin {
   my ($val, $bits) = @_;
   my $retval = "";

   local ($intval) = &convint($val);
   for ($i=$bits-1; $i >= 0; $i--) {
      $retval = $retval . (($intval >> $i) & 1 == 1 ? "1" : "0");
      }
   return $retval;
   }


############################### Parse options #########################
#
# At the end of this operation, ARGV will have been left shifted to
# get rid of options used.
#

{
   no warnings;

   if (&Getopts('hs:m:n:')) {
      if (defined $opt_h) { &usage ; exit 0; }
      if (defined $opt_s) { $server = $opt_s; }
      if (defined $opt_m) { $module = $opt_m; }
      if (defined $opt_n) { $namespace = $opt_n; $namespace =~ s#:#/#g;}
      }
   else {
      &usage;
      exit 1;
      }
}

#### Allow cmd line opts also - NB: these override.

my %updatefile;

foreach my $file (@ARGV) {
   if ($file =~ m#([^/]+)$#) {  ## Get basename
      $updatefile{$1}{path} = $file;
      }
   }

#####################################################################################
#
# Main bit
#
#####################################################################################

##===================================================================================
##
## Find files on wiki server
##
##===================================================================================

open(WIKI_FILES, "rsync --recursive ${server}::$module |") or die "ERROR: 
$progname: rsync --recursive ${server}::$module $!\n";

my @wiki_files;

while (<WIKI_FILES>) {
   if (m/(\S+)\s*$/) { ## Get last word in ls -l format
      push @wiki_files, $1;
      }
   }

foreach my $file (keys %updatefile) {
   if (my @filematches = grep(/$file/, @wiki_files)) {
      $updatefile{$file}{matches} = \@filematches;
      }
   else {
      warn "WARNING: $progname: Could not find $file on ${server}::$module\n";
      }
   }

##===================================================================================
##
## Update found files on wiki server
##
##===================================================================================

foreach my $file (keys %updatefile) {
   my $remotepath;
   if (defined $updatefile{$file}{matches}) {
      if ($#{$updatefile{$file}{matches}} == 0) {
         $remotepath = $updatefile{$file}{matches}->[0];
         }
      elsif ($namespace) {
         if (my (@matches) = grep /$namespace/, @{$updatefile{$file}{matches}}) 
{
            if ($#matches == 0) {
               $remotepath = $matches[0];
               }
            elsif ($#matches == -1) {
               warn("WARNING: $progname: No namespace matches for $file.\n");
               }
            else {
               warn("WARNING: $progname: Several possibilities for $file\n"
                    . join ("\n", @matches)
                    . "\n$file not updated - try a more specific namespace next 
time.\n\n"
                   );
               }
            }
         }
      else {
         warn("WARNING: $progname: Several possibilities for $file\n"
              . join ("\n", @{$updatefile{$file}{matches}})
              . "\n$file not updated - specify namespace next time.\n\n"
             );
         }
      }
   if ($remotepath) {
      my ($dir) = ($remotepath =~ m#^(\S+)/[^/]+$#); ## Get directory name
      print ("Rsyncing $file to ${server}::$module/$dir ... ");
      if (system("rsync -t $file ${server}::$module/$dir") == 0) {
         print "ok\n";
         }
      else {
         print "FAILED\n";
         }
      }
   }

exit $exit_code;





-- 
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: