r8105 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r8104‎ | r8105 | r8106 >
Date:06:34, 7 April 2005
Author:eloquence
Status:old
Tags:
Comment:
Basic support for text preview (Firefox/Mozilla only for now, but can be
easily made to work with any browser). To do: test this with different
settings constellations to see if the path conversion works properly.
Modified paths:
  • /trunk/extensions/ee/ee.ini (modified) (history)
  • /trunk/extensions/ee/ee.pl (modified) (history)

Diff [purge]

Index: trunk/extensions/ee/ee.pl
@@ -58,7 +58,10 @@
5959 $fileurl=$input->val("File","URL");
6060 $type=$input->val("Process","Type");
6161 $script=$input->val("Process","Script");
 62+$server=$input->val("Process","Server");
 63+$path=$input->val("Process","Path");
6264
 65+
6366 if($type eq "Edit file") {
6467 $filename=substr($fileurl,rindex($fileurl,"/")+1);
6568 } elsif($type eq "Edit text") {
@@ -102,7 +105,8 @@
103106 # Do we need to convert UTF-8 into ISO 8859-1?
104107 if($cfg->val("Settings","Transcode UTF-8") eq "true") {
105108 $transcode=1;
106 - }
 109+ }
 110+ $firefox=$cfg->val("Settings","Firefox");
107111 $ct=$response->header('Content-Type');
108112 $editpage=$response->content;
109113 $editpage=~m|<input type='hidden' value="(.*?)" name="wpEditToken" />|i;
@@ -154,9 +158,11 @@
155159 $hbox2 = Gtk2::HBox->new;
156160 $savebutton = Gtk2::Button->new("Save");
157161 $savecontbutton = Gtk2::Button->new("Save and continue");
 162+ $previewbutton = Gtk2::Button->new("Preview");
158163 $cancelbutton = Gtk2::Button->new("Cancel");
159164 $hbox2->pack_start_defaults($savebutton);
160165 $hbox2->pack_start_defaults($savecontbutton);
 166+ $hbox2->pack_start_defaults($previewbutton);
161167 $hbox2->pack_start_defaults($cancelbutton);
162168 $vbox->pack_start_defaults($hbox);
163169 $vbox->pack_start_defaults($hbox2);
@@ -167,6 +173,7 @@
168174 $window->signal_connect (delete_event => sub {Gtk2->main_quit});
169175 $savebutton->signal_connect (clicked => \&save);
170176 $savecontbutton->signal_connect ( clicked => \&savecont);
 177+ $previewbutton->signal_connect ( clicked => \&preview);
171178 $cancelbutton->signal_connect (clicked => \&cancel);
172179
173180 # Add vbox to window
@@ -181,6 +188,12 @@
182189 save("continue");
183190
184191 }
 192+
 193+sub preview {
 194+ $preview=1;
 195+ save("continue");
 196+}
 197+
185198 sub save {
186199
187200 my $cont=shift;
@@ -195,7 +208,7 @@
196209 if($is_utf8) {
197210 $summary=Encode::encode('utf8',$summary);
198211 }
199 - if($type eq "Edit file") {
 212+ if($type eq "Edit file") {
200213 $response=$browser->post($upload_url,
201214 @ns_headers,Content_Type=>'form-data',Content=>
202215 [
@@ -204,7 +217,7 @@
205218 wpUploadAffirm=>"1",
206219 wpUpload=>"Upload file",
207220 wpIgnoreWarning=>"1"
208 - ]);
 221+ ]);
209222 } elsif($type eq "Edit text") {
210223 open(TEXT,"<$tempdir/".$filename);
211224 $/=undef;
@@ -215,13 +228,34 @@
216229 if($is_utf8 && $transcode) {
217230 Encode::from_to($text,'iso-8859-1','utf8');
218231 }
219 - $response=$browser->post($edit_url,@ns_headers,Content=>
220 - [
221 - wpTextbox1=>$text,
222 - wpSummary=>$summary,
223 - wpEdittime=>$time,
224 - wpEditToken=>$token
225 - ]);
 232+ if($preview) {
 233+ $response=$browser->post($edit_url,@ns_headers,Content=>
 234+ [
 235+ wpTextbox1=>$text,
 236+ wpSummary=>$summary,
 237+ wpEdittime=>$time,
 238+ wpEditToken=>$token,
 239+ wpPreview=>"true",
 240+ ]);
 241+ open(PREVIEW,">$tempdir/preview.htm");
 242+ $preview=$response->content;
 243+ # Replace relative URLs with absolute ones
 244+ $preview=~s|$path|$server$path|gi;
 245+ print PREVIEW $preview;
 246+ if($firefox) {
 247+ print "$firefox\n";
 248+ system(qq|$firefox -remote "openURL(file://$tempdir/preview.htm)"|);
 249+ }
 250+ $preview=0;
 251+ } else {
 252+ $response=$browser->post($edit_url,@ns_headers,Content=>
 253+ [
 254+ wpTextbox1=>$text,
 255+ wpSummary=>$summary,
 256+ wpEdittime=>$time,
 257+ wpEditToken=>$token,
 258+ ]);
 259+ }
226260 } elsif($type eq "Diff") {
227261 die "Diffs not yet supported.\n";
228262 } else {
Index: trunk/extensions/ee/ee.ini
@@ -1,5 +1,7 @@
22 [Settings]
33 Temp Path=/tmp
 4+Transcode UTF-8=false
 5+Firefox=/usr/local/bin/firefox
46
57 [Editors]
68 jpg,png,gif,jpeg=/usr/bin/xpaint

Status & tagging log