From 6336a2d677b553bd3004d6cceed2da67bb7e7589 Mon Sep 17 00:00:00 2001 From: "myk%mozilla.org" Date: Wed, 5 May 2004 01:32:14 +0000 Subject: [PATCH] more cleanup from recent changes --- webtools/doctor/Doctor/File.pm | 46 +++---- webtools/doctor/doctor.cgi | 146 +++++++++++----------- webtools/doctor/doctor.css | 7 +- webtools/doctor/templates/code-error.tmpl | 1 + webtools/doctor/templates/committed.tmpl | 15 ++- webtools/doctor/templates/edit.tmpl | 4 +- webtools/doctor/templates/queued.tmpl | 16 ++- webtools/doctor/templates/select.tmpl | 3 +- webtools/doctor/templates/user-error.tmpl | 1 + 9 files changed, 124 insertions(+), 115 deletions(-) diff --git a/webtools/doctor/Doctor/File.pm b/webtools/doctor/Doctor/File.pm index 383e4bda55f8..7cac079d6767 100644 --- a/webtools/doctor/Doctor/File.pm +++ b/webtools/doctor/Doctor/File.pm @@ -54,29 +54,6 @@ sub version { return $self->{_version}; } -sub tempdir { - my $self = shift; - $self->{_tempdir} ||= - File::Temp->tempdir("doctor-XXXXXXXX", TMPDIR => 1, CLEANUP => 1); - return $self->{_tempdir}; -} - -sub line_endings { - my $self = shift; - if (!$self->content) { return undef } - elsif ($self->content =~ /\r\n/s) { return "windows" } - elsif ($self->content =~ /\r[^\n]/s) { return "mac" } - else { return "unix" } -} - -sub linebreak { - my $self = shift; - if (!$self->content) { return undef; } - elsif ($self->content =~ /\r\n/s) { return "\r\n" } - elsif ($self->content =~ /\r[^\n]/s) { return "\r" } - else { return "\n" } -} - sub spec { my $self = shift; # The spec can only be set once. @@ -125,6 +102,29 @@ sub spec { return $self->{_spec}; } +sub tempdir { + my $self = shift; + $self->{_tempdir} ||= + File::Temp->tempdir("doctor-XXXXXXXX", TMPDIR => 1, CLEANUP => 1); + return $self->{_tempdir}; +} + +sub line_endings { + my $self = shift; + if (!$self->content) { return undef } + elsif ($self->content =~ /\r\n/s) { return "windows" } + elsif ($self->content =~ /\r[^\n]/s) { return "mac" } + else { return "unix" } +} + +sub linebreak { + my $self = shift; + if (!$self->content) { return undef; } + elsif ($self->content =~ /\r\n/s) { return "\r\n" } + elsif ($self->content =~ /\r[^\n]/s) { return "\r" } + else { return "\n" } +} + sub url { my $self = shift; # Construct a URL to the file if possible. diff --git a/webtools/doctor/doctor.cgi b/webtools/doctor/doctor.cgi index f350867d4247..3fd2666fa8c0 100755 --- a/webtools/doctor/doctor.cgi +++ b/webtools/doctor/doctor.cgi @@ -133,12 +133,10 @@ sub retrieve { my $disposition = $action eq "download" ? "attachment" : "inline"; - my $length = length($file->content); - print $request->header( - -type => qq|text/html; name="$file->name"|, - -content_disposition => qq|$disposition; filename="$file->name"|, - -content_length => $length ); + -type => "text/html; name=\"" . $file->name . "\"", + -content_disposition => "$disposition; filename=\"" . $file->name . "\"", + -content_length => length($file->content) ); print $file->content; } @@ -146,7 +144,7 @@ sub retrieve { sub diff { my $file = Doctor::File->new($request->param('file')); ValidateVersions($request->param('version'), $file->version); - my $diff = $file->diff($request->param('content')) + my $diff = $file->diff(GetContent()) || "There are no differences between the version in CVS and your revision."; print $request->header(-type=>"text/plain"); @@ -236,6 +234,8 @@ sub queue { ThrowCodeError($@, "Mail Failure"); } + $vars->{file} = $file; + print $request->header; $template->process("queued.tmpl", $vars) || ThrowCodeError($template->error(), "Template Processing Failed"); @@ -251,21 +251,22 @@ sub commit { if ($action eq "commit") { ValidateVersions($request->param('version'), $file->version); - $file->patch($request->param('content')); + $file->patch(GetContent()); } else { - $file->add($request->param("content")); + $file->add(GetContent()); } my ($rv, $output, $errors) = $file->commit($username, $password, $comment); if ($rv != 0) { - ThrowUserError("An error occurred while committing the file.", + ThrowUserError("An error occurred while committing the file: $output $errors", undef, $output, $rv, $errors); } + $vars->{file} = $file; $vars->{output} = $output; $vars->{errors} = $errors; @@ -306,21 +307,20 @@ sub ValidateComment { return $request->param('comment'); } -sub ValidateVersions() -{ - # Throws an error if the version of the file that was edited - # does not match the version in the repository. In the future - # we should try to merge the user's changes if possible. - - my ($oldversion, $newversion) = @_; - - if ($oldversion && $newversion && $oldversion != $newversion) { - ThrowCodeError("You edited version $oldversion of the file, - but version $newversion is in the repository. Reload the edit - page and make your changes again (and bother the authors of this script - to implement change merging - (bug 164342)."); - } +sub ValidateVersions() { + # Throws an error if the version of the file that was edited + # does not match the version in the repository. In the future + # we should try to merge the user's changes if possible. + + my ($oldversion, $newversion) = @_; + + if ($oldversion && $newversion && $oldversion != $newversion) { + ThrowCodeError("You edited version $oldversion of the file, + but version $newversion is in the repository. Reload the edit + page and make your changes again (and bother the authors of this script + to implement change merging + (bug 164342)."); + } } @@ -328,58 +328,56 @@ sub ValidateVersions() # Error Handling ################################################################################ -sub ThrowUserError -{ - # Throw an error about a problem with the user's request. This function - # should avoid mentioning system problems displaying the error message, since - # the user isn't going to care about them and probably doesn't need to deal - # with them after fixing their own mistake. Errors should be gentle on - # the user, since many "user" errors are caused by bad UI that trip them up. - - # !!! Mail code errors to the system administrator! - - ($vars->{'message'}, - $vars->{'title'}, - $vars->{'cvs_command'}, - $vars->{'cvs_error_code'}, - $vars->{'cvs_error_message'}) = @_; - - chdir($HOME); - print $request->header; - $template->process("user-error.tmpl", $vars) - || print( ($vars->{'title'} ? "

$vars->{'title'}

" : "") . - "

$vars->{'message'}

Please go back and try again.

" ); - exit; +sub ThrowUserError { + # Throw an error about a problem with the user's request. This function + # should avoid mentioning system problems displaying the error message, since + # the user isn't going to care about them and probably doesn't need to deal + # with them after fixing their own mistake. Errors should be gentle on + # the user, since many "user" errors are caused by bad UI that trip them up. + + # !!! Mail code errors to the system administrator! + + ($vars->{'message'}, + $vars->{'title'}, + $vars->{'cvs_command'}, + $vars->{'cvs_error_code'}, + $vars->{'cvs_error_message'}) = @_; + + chdir($HOME); + print $request->header; + $template->process("user-error.tmpl", $vars) + || print( ($vars->{'title'} ? "

$vars->{'title'}

" : "") . + "

$vars->{'message'}

Please go back and try again.

" ); + exit; } -sub ThrowCodeError -{ - # Throw error about a problem with the code. This function should be - # apologetic and deferent to the user, since it isn't the user's fault - # the code didn't work. - - # !!! Mail code errors to the system administrator! - - ($vars->{'message'}, $vars->{'title'}) = @_; - - chdir($HOME); - print $request->header; - $template->process("code-error.tmpl", $vars) - || print(" -

- Unfortunately Doctor has experienced an internal error from which - it was unable to recover. More information about the error is - provided below. Please forward this information along with any - other information that would help diagnose and fix this problem - to the system administrator at - $CONFIG{ADMIN_EMAIL}. -

-

- couldn't process error.tmpl template: " . $template->error() . - "; error occurred while trying to display error message: " . - ($vars->{'title'} ? "$vars->{'title'}: ": "") . $vars->{'message'} . - "

"); - exit; +sub ThrowCodeError { + # Throw error about a problem with the code. This function should be + # apologetic and deferent to the user, since it isn't the user's fault + # the code didn't work. + + # !!! Mail code errors to the system administrator! + + ($vars->{'message'}, $vars->{'title'}) = @_; + + chdir($HOME); + print $request->header; + $template->process("code-error.tmpl", $vars) + || print(" +

+ Unfortunately Doctor has experienced an internal error from which + it was unable to recover. More information about the error is + provided below. Please forward this information along with any + other information that would help diagnose and fix this problem + to the system administrator at + $CONFIG{ADMIN_EMAIL}. +

+

+ couldn't process error.tmpl template: " . $template->error() . + "; error occurred while trying to display error message: " . + ($vars->{'title'} ? "$vars->{'title'}: ": "") . $vars->{'message'} . + "

"); + exit; } ################################################################################ diff --git a/webtools/doctor/doctor.css b/webtools/doctor/doctor.css index e220419ea119..78d50229a270 100644 --- a/webtools/doctor/doctor.css +++ b/webtools/doctor/doctor.css @@ -2,11 +2,16 @@ * Banner and Navigation Bar */ -#bannernav { +h1 { + margin-top: 0px; margin-bottom: 5px; + font-size: 24px; font-weight: bold; } +h2 { + font-size: 18px; +} /* * Tabs diff --git a/webtools/doctor/templates/code-error.tmpl b/webtools/doctor/templates/code-error.tmpl index af64a23ddf05..0ad52753c5f1 100644 --- a/webtools/doctor/templates/code-error.tmpl +++ b/webtools/doctor/templates/code-error.tmpl @@ -28,6 +28,7 @@ Doctor - [% title %] + diff --git a/webtools/doctor/templates/committed.tmpl b/webtools/doctor/templates/committed.tmpl index 6f93162dcbf1..68fa150e58f3 100644 --- a/webtools/doctor/templates/committed.tmpl +++ b/webtools/doctor/templates/committed.tmpl @@ -25,24 +25,23 @@ Doctor - [% is_new ? "created" : "committed" %] [%+ file.relative_spec FILTER html %] + - Doctor - [% is_new ? "created" : "committed" %] - [% IF file.url %] +

+ Doctor - [% is_new ? "created" : "committed" %] + [%+ IF file.url %] [% file.relative_spec FILTER html %] [% ELSE %] [% file.relative_spec FILTER html %] [% END %] - +

- [% IF is_new %] - The new file has been committed to the repository. - [% ELSE %] - Your changes have been committed to the repository. - [% END %] + [% IF is_new %] The new file has [% ELSE %] Your changes have [% END %] + been committed to the repository.

Results

diff --git a/webtools/doctor/templates/edit.tmpl b/webtools/doctor/templates/edit.tmpl index 1d9d2f7fb1a9..c3c9c104639a 100644 --- a/webtools/doctor/templates/edit.tmpl +++ b/webtools/doctor/templates/edit.tmpl @@ -51,7 +51,7 @@ -
+

Doctor - [% is_new ? "create" : "edit" %] [%+ IF file.url %] [% file.relative_spec FILTER html %] @@ -64,7 +64,7 @@ [% END %] | -

+