Index: trunk/phase3/extensions/ee/ee.pl |
— | — | @@ -0,0 +1,166 @@ |
| 2 | +#!/usr/bin/perl |
| 3 | +# To do: |
| 4 | +# - Preview |
| 5 | +# - Summaries via GTK |
| 6 | +# - Diffs |
| 7 | +# - Deal with UTF-8/iso8559-1 where possible |
| 8 | +# |
| 9 | +use Config::IniFiles; # Module for config files in .ini syntax |
| 10 | +use LWP::UserAgent; # Web agent module |
| 11 | +use URI::Escape; # urlencode functions |
| 12 | + |
| 13 | +# Pfad der Konfigurationsdatei ggf. anpassen! |
| 14 | +$cfgfile=$ENV{HOME}."/.ee-helper/ee.ini"; |
| 15 | + |
| 16 | +my $cfg = new Config::IniFiles( -file => $cfgfile ); |
| 17 | +my $args=join(" ",@ARGV); |
| 18 | + |
| 19 | +my $tempdir=$cfg->val("Settings","Temp Path") or |
| 20 | +die "No path for temporary files specified. Please edit $cfgfile and add an entry like this: |
| 21 | +[Settings] |
| 22 | +Temp Path=/tmp\n"; |
| 23 | + |
| 24 | +# Slashes am Ende entfernen |
| 25 | +$/="/"; |
| 26 | +chomp($tempdir); |
| 27 | + |
| 28 | +#open(DEBUGLOG,">$tempdir/debug.log"); |
| 29 | + |
| 30 | +#-------- debug the input file |
| 31 | +# open(INPUT,"<$args"); |
| 32 | +# $/=undef; # slurp mode |
| 33 | +# while(<INPUT>) { |
| 34 | +# $inputfile=$_; |
| 35 | +# } |
| 36 | +# print DEBUGLOG $inputfile; |
| 37 | +# close(DEBUGLOG); |
| 38 | +# exit 0; |
| 39 | + |
| 40 | +if(-e $args) { |
| 41 | + $input = new Config::IniFiles( -file => $args ); |
| 42 | +} else { |
| 43 | + print "No input file specified.\n"; |
| 44 | + print "Syntax: perl ee.pl <Resource description file>\n"; |
| 45 | + exit 1; |
| 46 | +} |
| 47 | +$browser=LWP::UserAgent->new(); |
| 48 | +$browser->cookie_jar( {} ); |
| 49 | +@ns_headers = ( |
| 50 | + 'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20041107 Firefox/1.0', |
| 51 | + 'Accept' => 'image/gif, image/x-xbitmap, image/jpeg, |
| 52 | + image/pjpeg, image/png, */*', |
| 53 | + 'Accept-Charset' => 'iso-8859-1,*,utf-8', |
| 54 | + 'Accept-Language' => 'en-US', |
| 55 | +); |
| 56 | + |
| 57 | + |
| 58 | +$fileurl=$input->val("File","URL"); |
| 59 | +$type=$input->val("Process","Type"); |
| 60 | +$script=$input->val("Process","Script"); |
| 61 | + |
| 62 | +if($type eq "Edit file") { |
| 63 | + $filename=substr($fileurl,rindex($fileurl,"/")+1); |
| 64 | +} elsif($type eq "Edit text") { |
| 65 | + $fileurl=~m|\?title=(.*?)\&action=|i; |
| 66 | + $pagetitle=$1; |
| 67 | + $filename=uri_unescape($pagetitle); |
| 68 | + $filename=$filename.".wiki"; |
| 69 | +} |
| 70 | + |
| 71 | +$login_url=$script."?title=Special:Userlogin&action=submitlogin"; |
| 72 | +$upload_url=$script."?title=Special:Upload"; |
| 73 | +$edit_url=$script."?title=$pagetitle&action=submit"; |
| 74 | + |
| 75 | +@sections=$cfg->Sections(); |
| 76 | +foreach $section(@sections) { |
| 77 | + if($search=$cfg->val($section,"URL")) { |
| 78 | + if(index($fileurl,$search)>=0) { |
| 79 | + $username=$cfg->val($section,"Username"); |
| 80 | + $password=$cfg->val($section,"Password"); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | +} |
| 85 | + |
| 86 | +# Log into server |
| 87 | +$response=$browser->post($login_url,@ns_headers, |
| 88 | +Content=>[wpName=>$username,wpPassword=>$password,wpRemember=>"1",wpLoginAttempt=>"Log in"]); |
| 89 | +if($response->code!=302 && !$ignore_login_error) { |
| 90 | + die "Could not login with username '$username' and password '$password'.\n" |
| 91 | +} |
| 92 | + |
| 93 | +$response=$browser->get($fileurl); |
| 94 | +if($type eq "Edit file") { |
| 95 | + |
| 96 | + open(OUTPUT,">$tempdir/".$filename); |
| 97 | + print OUTPUT $response->content; |
| 98 | + close(OUTPUT); |
| 99 | + |
| 100 | +}elsif($type eq "Edit text") { |
| 101 | + |
| 102 | + $editpage=$response->content; |
| 103 | + $editpage=~m|<input type='hidden' value="(.*?)" name="wpEditToken" />|i; |
| 104 | + $token=$1; |
| 105 | + $editpage=~m|<textarea.*?name="wpTextbox1".*?>(.*?)</textarea>|is; |
| 106 | + $text=$1; |
| 107 | + $editpage=~m|<input type='hidden' value="(.*?)" name="wpEdittime" />|i; |
| 108 | + $time=$1; |
| 109 | + open(OUTPUT,">$tempdir/".$filename); |
| 110 | + print OUTPUT $text; |
| 111 | + close(OUTPUT); |
| 112 | + |
| 113 | +} |
| 114 | + |
| 115 | +$ext=$input->val("File","Extension"); |
| 116 | +# Search for extension-associated application |
| 117 | + |
| 118 | +@extensionlists=$cfg->Parameters("Editors"); |
| 119 | +foreach $extensionlist(@extensionlists) { |
| 120 | + @exts=split(",",$extensionlist); |
| 121 | + foreach $extensionfromlist(@exts) { |
| 122 | + if ($extensionfromlist eq $ext) { |
| 123 | + $app=$cfg->val("Editors",$extensionlist); |
| 124 | + } |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +system("$app $tempdir/$filename"); |
| 129 | +# Some programs terminate immediately .. this is a quick hack to deal |
| 130 | +# with them; optimally, we shouldn't proceed after the GTK summary |
| 131 | +# box, though. |
| 132 | +#system("kdialog --msgbox 'Text editor terminated.'"); |
| 133 | + |
| 134 | +if($type eq "Edit file") { |
| 135 | + $response=$browser->post($upload_url, |
| 136 | + @ns_headers,Content_Type=>'form-data',Content=> |
| 137 | + [ |
| 138 | + wpUploadFile=>["$tempdir/".$filename], |
| 139 | + wpUploadDescription=>"Uploaded with External-Editor by Erik Moeller", |
| 140 | + wpUploadAffirm=>"1", |
| 141 | + wpUpload=>"Upload file", |
| 142 | + wpIgnoreWarning=>"1" |
| 143 | + ]); |
| 144 | +} elsif($type eq "Edit text") { |
| 145 | + open(TEXT,"<$tempdir/".$filename); |
| 146 | + $/=undef; |
| 147 | + while(<TEXT>) { |
| 148 | + $text=$_; |
| 149 | + } |
| 150 | + close(TEXT); |
| 151 | + $response=$browser->post($edit_url,@ns_headers,Content=> |
| 152 | + [ |
| 153 | + wpTextbox1=>$text, |
| 154 | + wpSummary=>"Edited with External-Editor by Erik Moeller", |
| 155 | + wpEdittime=>$time, |
| 156 | + wpEditToken=>$token |
| 157 | + ]); |
| 158 | +} elsif($type eq "Diff") { |
| 159 | + die "Diffs not yet supported.\n"; |
| 160 | +} else { |
| 161 | + |
| 162 | + die "Undefined or unknown process in input file."; |
| 163 | +} |
| 164 | + |
| 165 | + |
| 166 | +#close(DEBUGLOG); |
| 167 | +exit 0; |
\ No newline at end of file |
Property changes on: trunk/phase3/extensions/ee/ee.pl |
___________________________________________________________________ |
Added: svn:keywords |
1 | 168 | + Author Date Id Revision |
Added: svn:eol-style |
2 | 169 | + native |
Added: svn:executable |
3 | 170 | + * |
Index: trunk/phase3/extensions/ee/README.de |
— | — | @@ -0,0 +1,25 @@ |
| 2 | +External Editor Helper application (EE) |
| 3 | +Erik Moeller, 2005 |
| 4 | + |
| 5 | +Lizenz: Public domain |
| 6 | + |
| 7 | +Funktion: Erlaubt die Verwendung beliebiger externer Applikationen zur |
| 8 | +Bearbeitung oder Anzeige von Ressourcen im Web, z.B. in einem Wiki. |
| 9 | + |
| 10 | +Anwendungsbeispiel: Sie m�chten ein Bild in einem Wiki bearbeiten. |
| 11 | +Wenn das Wiki die Verwendung von application/external-editor unterstuezt, |
| 12 | +sollten Sie in der Naehe des Bildes einen entsprechenden Bearbeitungs-Link |
| 13 | +finden. Nachdem Sie diesen Link anklicken, schickt das Wiki eine |
| 14 | +Ressourcen-Beschreibungsdatei an den Web-Browser, die den MIME-Typ |
| 15 | +application/external-editor hat. Der Web-Browser laedt darauf hin diese |
| 16 | +Hilfsapplikation, die wiederum das Bild herunter laedt und das gewuenschte |
| 17 | +Bildbearbeitungsprogramm startet. Nach dem Speichern der Datei wird die |
| 18 | +veraenderte Datei ueber ein definiertes Interface wieder zurueck auf den |
| 19 | +Server geladen. |
| 20 | + |
| 21 | +Benutzung: Verknuepfen Sie in Ihrem Web-Browser ee.pl mit dem MIME-Typ |
| 22 | +application/external-editor. Konfigurieren Sie Editoren und Anzeige- |
| 23 | +programme, in dem Sie in ee.cfg Applikationen mit MIME-Typen |
| 24 | +assoziieren. Um Dateien hochzuladen, muessen auch Authentifizierungs- |
| 25 | +Informationen fuer die gewuenschten Websites in der Konfigurationsdatei |
| 26 | +eingetragen werden. |
\ No newline at end of file |
Property changes on: trunk/phase3/extensions/ee/README.de |
___________________________________________________________________ |
Added: svn:keywords |
1 | 27 | + Author Date Id Revision |
Added: svn:eol-style |
2 | 28 | + native |
Index: trunk/phase3/extensions/ee/ee.ini |
— | — | @@ -0,0 +1,13 @@ |
| 2 | +[Settings] |
| 3 | +Temp Path=/tmp |
| 4 | + |
| 5 | +[Editors] |
| 6 | +jpg,png,gif,jpeg=/usr/bin/xpaint |
| 7 | +ogg,mp3,wav=/usr/bin/audacity |
| 8 | +svg=/usr/bin/inkscape |
| 9 | +wiki=/usr/bin/kwrite |
| 10 | + |
| 11 | +[Testwiki] |
| 12 | +URL=localhost/wiki |
| 13 | +Username=Admin |
| 14 | +Password=admin |
\ No newline at end of file |
Property changes on: trunk/phase3/extensions/ee/ee.ini |
___________________________________________________________________ |
Added: svn:keywords |
1 | 15 | + Author Date Id Revision |
Added: svn:eol-style |
2 | 16 | + native |
Index: trunk/phase3/extensions/ee/README |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +External Editor Helper application (EE) |
| 3 | +Erik Moeller, 2005 |
| 4 | + |
| 5 | +License: Public domain |
| 6 | + |
| 7 | +Purpose: Allows the use of arbitrary external applications for editing |
| 8 | +or viewing resources on the web, e.g. in a wiki. |
| 9 | + |
| 10 | +Example: You want to edit a picture in a wiki. If the wiki supports the |
| 11 | +use of application/external-editor, you should find an editing link next |
| 12 | +to the image. After you click that link, the wiki sends a resource |
| 13 | +description file to the web browser which has the MIME type |
| 14 | +application/external-editor. The web browser knows that this MIME type |
| 15 | +is associated with the helper application ee.pl, which downloads the image, |
| 16 | +starts the image editing application, and uploads the image back to the |
| 17 | +server upon save. |
| 18 | + |
| 19 | +Usage: Associate the MIME type application/external-editor in your web |
| 20 | +browser with ee.pl. Configure the editors and viewing programs by |
| 21 | +editing the file ~/.ee-helper/ee.ini (in your home directory); an |
| 22 | +example should be part of the archive containing this program. To |
| 23 | +save files back to the server, you also have to add authentication |
| 24 | +information to the configuration file. |
| 25 | + |
Property changes on: trunk/phase3/extensions/ee/README |
___________________________________________________________________ |
Added: svn:keywords |
1 | 26 | + Author Date Id Revision |
Added: svn:eol-style |
2 | 27 | + native |