Author: dom Date: 2007-06-11 21:37:06 +0100 (Mon, 11 Jun 2007) New Revision: 1068
Modified: trunk/lib/OpenGuides.pm trunk/lib/OpenGuides/Utils.pm Log: Add framework for generic content/metadata validation into commit_node
Modified: trunk/lib/OpenGuides/Utils.pm =================================================================== --- trunk/lib/OpenGuides/Utils.pm 2007-06-11 03:24:22 UTC (rev 1067) +++ trunk/lib/OpenGuides/Utils.pm 2007-06-11 20:37:06 UTC (rev 1068) @@ -355,6 +355,26 @@ } }
+=item B<validate_edit> + + eval { OpenGuides::Utils->validate_edit( + id => $node, + content => $content + metadata => %new_metadata + ) }; + +Checks supplied content for general validity. If anything is invalid, +dies with an error string suitable for reporting to the user. + +=cut + +sub validate_edit { + my ( $self, %args ) = @_; + die "Content missing\n" unless $args{content}; + die "Metadata missing\n" unless $args{metadata}; + +}; + =back
=head1 AUTHOR
Modified: trunk/lib/OpenGuides.pm =================================================================== --- trunk/lib/OpenGuides.pm 2007-06-11 03:24:22 UTC (rev 1067) +++ trunk/lib/OpenGuides.pm 2007-06-11 20:37:06 UTC (rev 1068) @@ -1335,6 +1335,26 @@ } $new_metadata{host} = $ENV{REMOTE_ADDR};
+ # General validation + eval { OpenGuides::Utils->validate_edit( + content => $content, + metadata => %new_metadata + ) }; + + if ( $@ ) { + my $output = OpenGuides::Template->output( + wiki => $self->wiki, + config => $config, + template => "validate_edit_failed.tt", + vars => { + message => $@ + } + ); + return $output if $return_output; + print $output; + return; + } + # Wiki::Toolkit::Plugin::RSS::ModWiki wants "major_change" to be set. $new_metadata{major_change} = ( $new_metadata{edit_type} eq "Normal edit" ) ? 1
openguides-commits@lists.openguides.org