Update of /cvs/scoop/scoop/lib/Scoop/Admin
In directory lithium.sabren.com:/tmp/cvs-serv19425/lib/Scoop/Admin
Modified Files:
Special.pm
Log Message:
Bugs 196 and 202: special page and boxtool fixes, respectively.
-janra
Index: Special.pm
===================================================================
RCS file: /cvs/scoop/scoop/lib/Scoop/Admin/Special.pm,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** Special.pm 14 Oct 2005 20:07:09 -0000 1.13
--- Special.pm 7 Jan 2006 01:05:16 -0000 1.14
***************
*** 12,16 ****
sub _get_special_form {
my $S = shift;
! my $msg = shift || ' ';
my $id = $S->{CGI}->param('id');
my $pageid = $S->{CGI}->param('pageid');
--- 12,17 ----
sub _get_special_form {
my $S = shift;
! my $keys = {};
! $keys->{msg} = shift || ' ';
my $id = $S->{CGI}->param('id');
my $pageid = $S->{CGI}->param('pageid');
***************
*** 19,27 ****
my $check_html = $S->{CGI}->param('html_check') || 0;
my $spell_check = $S->{CGI}->param('spell_check') || 0;
if ($id eq '' && !$get) {
$id = $pageid;
}
! my ($page_selector, $page_data) = $S->_special_page_selector($id);
$page_data->{content} =~ s/\|/\\\|/g;
--- 20,38 ----
my $check_html = $S->{CGI}->param('html_check') || 0;
my $spell_check = $S->{CGI}->param('spell_check') || 0;
+ my $direct_link = $S->{CGI}->param('direct_link');
if ($id eq '' && !$get) {
$id = $pageid;
}
! $keys->{id} = $id;
!
! my $page_data;
! ($keys->{page_list}, $page_data) = $S->_special_page_selector($id);
!
! unless ($page_data) {
! $page_data->{content} = $S->{CGI}->param('content');
! $page_data->{title} = $S->{CGI}->param('title');
! $page_data->{description} = $S->{CGI}->param('description');
! }
$page_data->{content} =~ s/\|/\\\|/g;
***************
*** 35,105 ****
$page_data->{content} =~ s/\</</g;
$page_data->{content} =~ s/\>/>/g;
- my $preview;
if ($id && !$delete) {
! $preview = qq|
! <tr>
! <td>%%norm_font%%View <a href="%%rootdir%%/special/$id" target="new">$page_data->{title}</a> (opens in new window)%%norm_font_end%%</td>
! </tr>|;
}
! my $chkhtml_checked = $check_html ? ' checked="checked"' : '';
! my $splchk_checked = $spell_check ? ' checked="checked"' : '';
! my $upload_page = $S->display_upload_form(0,'content');
! $upload_page = "<tr><td>$upload_page</td></tr>" unless $upload_page eq '';
!
! my $page = qq|
! <form name="special" action="%%rootdir%%/" method="post" enctype="multipart/form-data">
! <input type="hidden" name="op" value="admin" />
! <input type="hidden" name="tool" value="special" />
! <table width="100%" border="0" cellpadding="0" cellspacing="0">
! <tr bgcolor="%%title_bgcolor%%">
! <td>%%title_font%%Edit Special Pages%%title_font_end%%</td>
! </tr>
! <tr><td>%%title_font%%<font color="#FF0000">$msg</font>%%title_font_end%%</td>
! $preview
! <tr>
! <td>%%norm_font%%<b>Page:</b> $page_selector <input type="submit" name="get" value="Get Page" />%%norm_font_end%%</td>
! </tr>|;
! if ($id && !$delete) {
! $page .= qq|
! <tr>
! <td>%%norm_font%%<input type="checkbox" name="delete" value="1" /> Delete this page%%norm_font_end%%</td>
! </tr>|;
}
! $page .= qq|
! <tr>
! <td>%%norm_font%%<b>Page ID:</b> <input type="text" name="pageid" value="$page_data->{pageid}" size="40" />%%norm_font_end%%</td>
! </tr>
! <tr>
! <td>%%norm_font%%<b>Title:</b> <input type="text" name="title" value="$page_data->{title}" size="40" />%%norm_font_end%%</td>
! </tr>
! <tr>
! <td><input type="checkbox" name="html_check" value="1"$chkhtml_checked /> %%norm_font%%Check the HTML of this page%%norm_font_end%%</td>
! </tr>|;
if ($S->spellcheck_enabled()) {
! $page .= qq|
! <tr>
! <td><input type="checkbox" name="spell_check" value="1"$splchk_checked /> %%norm_font%%Spellcheck this page%%norm_font_end%%</td>
! </tr>|;
}
! $page .= qq|
! <tr>
! <td>%%norm_font%%<b>Description:</b></td>
! </tr>
! <tr>
! <td>%%norm_font%%<textarea cols="50" rows="3" name="description" wrap="soft">$page_data->{description}</textarea>%%norm_font_end%%</td>
! </tr>
! <tr>
! <td>%%norm_font%%<b>Content:</b></td>
! </tr>
! <tr>
! <td>%%norm_font%%<textarea cols="50" rows="25" name="content" wrap="soft">$page_data->{content}</textarea>%%norm_font_end%%</td>
! </tr>
! $upload_page
! <tr>
! <td>%%norm_font%%<input type="submit" name="write" value="Save Page"> <input type="reset" />%%norm_font_end%%</td>
! </tr>
! </table>
! </form>|;
return $page;
--- 46,76 ----
$page_data->{content} =~ s/\</</g;
$page_data->{content} =~ s/\>/>/g;
if ($id && !$delete) {
! $keys->{preview} = $S->interpolate($S->{UI}->{BLOCKS}->{special_edit_preview}, {pageid => $keys->{id}, title => $page_data->{title}});
! $keys->{delete} = $S->{UI}->{BLOCKS}->{special_edit_delete};
}
!
! $keys->{chkhtml_checked} = $check_html ? ' checked="checked"' : '';
!
! unless ($get) {
! $keys->{directlink_checked} = $direct_link ? ' checked="checked"' : '';
}
!
! $keys->{directlink_checked} ||= ($S->check_for_special_alias($keys->{id})) ? ' checked="checked"' : '';
!
if ($S->spellcheck_enabled()) {
! $keys->{spellcheck} = $spell_check ? $S->interpolate($S->{UI}->{BLOCKS}->{special_edit_spellcheck}, {splchk_checked => ' checked="checked"'}) : $S->{UI}->{BLOCKS}->{special_edit_spellcheck};
}
!
! my $upload_page = $S->display_upload_form(0,'content');
! warn "Upload page: $upload_page\n";
! $keys->{upload_page} = $S->interpolate($S->{UI}->{BLOCKS}->{special_edit_upload}, {upload_form => $upload_page}) unless $upload_page eq '';
!
! foreach my $k (keys %{$page_data}) {
! $keys->{$k} = $page_data->{$k};
! }
!
! my $page = $S->interpolate($S->{UI}->{BLOCKS}->{special_edit_form}, $keys);
return $page;
***************
*** 151,155 ****
my $check_html = $S->{CGI}->param('html_check');
my $spell_check = $S->{CGI}->param('spell_check');
!
my $q_id = $S->{DBH}->quote($pageid);
# get this out of the way first, since it doesn't depend on anything else
--- 122,127 ----
my $check_html = $S->{CGI}->param('html_check');
my $spell_check = $S->{CGI}->param('spell_check');
! my $direct_link = $S->{CGI}->param('direct_link');
!
my $q_id = $S->{DBH}->quote($pageid);
# get this out of the way first, since it doesn't depend on anything else
***************
*** 160,164 ****
});
$sth->finish;
!
return "Page \"$title\" deleted.";
}
--- 132,139 ----
});
$sth->finish;
!
! # Remove the special op alias, if there is one
! $S->special_remove_op_alias($pageid);
!
return "Page \"$title\" deleted.";
}
***************
*** 213,217 ****
--- 188,200 ----
$errs .= $sc_errs;
}
+
+ # add special op alias, if requested
+ $errs .= $S->special_add_op_alias($pageid) if $direct_link;
+ # Or, do we need to remove an op alias?
+ if ($S->check_for_special_alias($pageid) && !$direct_link) {
+ $S->special_remove_op_alias($pageid);
+ }
+
return $errs if $errs;
***************
*** 236,240 ****
}
$sth->finish;
!
return "Page \"$title\" updated. $files_written" if $rv;
my $err = $S->{DBH}->errstr;
--- 219,223 ----
}
$sth->finish;
!
return "Page \"$title\" updated. $files_written" if $rv;
my $err = $S->{DBH}->errstr;
***************
*** 242,244 ****
--- 225,320 ----
}
+
+ sub special_remove_op_alias {
+ my $S = shift;
+ my $id = shift;
+
+ return unless $id;
+
+ my @aliases = split /\s+/, $S->{OPS}->{special}->{aliases};
+
+ my @new_aliases;
+ foreach my $a (@aliases) {
+ next if $a eq $id;
+ push @new_aliases, $a;
+ }
+
+ my $aliases = join ' ', @new_aliases;
+ $S->update_special_aliases($aliases);
+
+ return;
+ }
+
+ sub special_add_op_alias {
+ my $S = shift;
+ my $id = shift;
+
+ return unless $id;
+
+ # Look for an existing op named this
+ my $collision = $S->check_op_collision($id);
+ return "<br>Error: Can't add direct alias. It conflicts with an existing op." if ($collision);
+
+ # Look for a special page alias already, and if it's there just return.
+ my $exists = $S->check_for_special_alias($id);
+ return if $exists;
+
+ # Ok, no collision and no extant alias, so add one
+ my $aliases = "$id " . $S->{OPS}->{special}->{aliases};
+ $S->update_special_aliases($aliases);
+
+ return;
+ }
+
+ sub update_special_aliases {
+ my $S = shift;
+ my $aliases = shift;
+ my $q_aliases = $S->dbh->quote($aliases);
+
+ my ($rv,$sth) = $S->db_update({
+ WHAT => 'ops',
+ SET => qq|aliases = $q_aliases|,
+ WHERE => 'op = "special"'
+ });
+ $sth->finish();
+
+ # Clear the cache
+ $S->cache->clear({resource => 'ops', element => 'OPS'});
+ $S->cache->stamp_cache('ops', time(), 1);
+ $S->_load_ops();
+
+ return;
+ }
+
+ sub check_op_collision {
+ my $S = shift;
+ my $id = shift;
+
+ return unless $id;
+
+ foreach my $op (keys %{$S->{OPS}}) {
+ next if $op eq 'special';
+ return 1 if $op eq $id;
+ my @aliases = split /\s+/, $S->{OPS}->{$op}->{aliases};
+ foreach my $alias (@aliases) {
+ return 1 if $alias eq $id;
+ }
+ }
+
+ return 0;
+ }
+
+ sub check_for_special_alias {
+ my $S = shift;
+ my $id = shift;
+ return unless $id;
+
+ foreach my $alias (split /\s+/, $S->{OPS}->{special}->{aliases}) {
+ return 1 if $alias eq $id;
+ }
+
+ return 0;
+ }
+
+
1;