Author: nick Date: 2006-08-03 15:26:35 +0100 (Thu, 03 Aug 2006) New Revision: 824
Added: trunk/t/71_missing_metadata.t trunk/templates/missing_metadata.tt Modified: trunk/MANIFEST trunk/lib/OpenGuides.pm trunk/templates/admin_home.tt trunk/wiki.cgi Log: Missing metadata support
Modified: trunk/MANIFEST =================================================================== --- trunk/MANIFEST 2006-08-03 13:15:13 UTC (rev 823) +++ trunk/MANIFEST 2006-08-03 14:26:35 UTC (rev 824) @@ -42,6 +42,7 @@ templates/header.tt templates/home_node.tt templates/map_index.tt +templates/missing_metadata.tt templates/navbar.tt templates/needing_moderation.tt templates/newpage.tt @@ -100,5 +101,6 @@ t/67_bug_first_version.t t/68_bug_website_displayed.t t/70_admin_home.t +t/71_missing_metadata.t t/templates/15_test.tt wiki.cgi
Modified: trunk/lib/OpenGuides.pm =================================================================== --- trunk/lib/OpenGuides.pm 2006-08-03 13:15:13 UTC (rev 823) +++ trunk/lib/OpenGuides.pm 2006-08-03 14:26:35 UTC (rev 824) @@ -1132,6 +1132,87 @@ } }
+=item B<show_missing_metadata> +Search for nodes which don't have a certain kind of metadata. Optionally +also excludes Locales and Categories +=cut +sub show_missing_metadata { + my ($self, %args) = @_; + my $return_tt_vars = $args{return_tt_vars} || 0; + my $return_output = $args{return_output} || 0; + + my $wiki = $self->wiki; + my $formatter = $self->wiki->formatter; + my $script_url = $self->config->script_url; + + my ($metadata_type, $metadata_value, $exclude_locales, $exclude_categories) + = @args{ qw( metadata_type metadata_value exclude_locales exclude_categories ) }; + + my @nodes; + my $done_search = 0; + + # Only search if they supplied at least a metadata type + if($metadata_type) { + $done_search = 1; + @nodes = $wiki->list_nodes_by_missing_metadata( + metadata_type => $metadata_type, + metadata_value => $metadata_value, + ignore_case => 1, + ); + + # Do we need to filter some nodes out? + if($exclude_locales || $exclude_categories) { + my @all_nodes = @nodes; + @nodes = (); + + foreach my $node (@all_nodes) { + if($exclude_locales && $node =~ /^Locale /) { next; } + if($exclude_categories && $node =~ /^Category /) { next; } + push @nodes, $node; + } + } + } + + # Build nice edit etc links for our nodes + my @tt_nodes; + for my $node (@nodes) { + my %n; + + # Make the URLs + my $node_param = uri_escape( $formatter->node_name_to_node_param( $node ) ); + + # Save into the hash + $n{'name'} = $node; + $n{'view_url'} = $script_url . "?id=" . $node_param; + $n{'edit_url'} = $script_url . "?id=" . $node_param . ";action=edit"; + push @tt_nodes, %n; + } + + # Set up our TT variables, including the search parameters + my %tt_vars = ( + not_editable => 1, + not_deletable => 1, + deter_robots => 1, + + nodes => @tt_nodes, + done_search => $done_search, + metadata_type => $metadata_type, + metadata_value => $metadata_value, + exclude_locales => $exclude_locales, + exclude_categories => $exclude_categories + ); + return %tt_vars if $return_tt_vars; + + # Render to the page + my $output = $self->process_template( + id => "", + template => "missing_metadata.tt", + tt_vars => %tt_vars, + ); + return $output if $return_output; + print $output; +} + =item B<display_admin_interface> Fetch everything we need to display the admin interface, and passes it off to the template
Added: trunk/t/71_missing_metadata.t =================================================================== --- trunk/t/71_missing_metadata.t 2006-08-03 13:15:13 UTC (rev 823) +++ trunk/t/71_missing_metadata.t 2006-08-03 14:26:35 UTC (rev 824) @@ -0,0 +1,130 @@ +use strict; +use Wiki::Toolkit::Setup::SQLite; +use OpenGuides; +use OpenGuides::Test; +use Test::More tests => 26; + +eval { require DBD::SQLite; }; +my $have_sqlite = $@ ? 0 : 1; + +SKIP: { + skip "DBD::SQLite not installed - no database to test with", 17 + unless $have_sqlite; + + Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); + my $config = OpenGuides::Test->make_basic_config; + $config->script_name( "wiki.cgi" ); + $config->script_url( "http://example.com/" ); + my $guide = OpenGuides->new( config => $config ); + isa_ok( $guide, "OpenGuides" ); + my $wiki = $guide->wiki; + isa_ok( $wiki, "Wiki::Toolkit" ); + + # Clear out the database from any previous runs. + foreach my $del_node ( $wiki->list_all_nodes ) { + print "# Deleting node $del_node\n"; + $wiki->delete_node( $del_node ) or die "Can't delete $del_node"; + } + + + # Add 3 different pages, one of which with two versions + $wiki->write_node( "Test Page", "foo", undef, + { category => "Alpha", lat=>"" } ) + or die "Couldn't write node"; + $wiki->write_node( "Test Page 2", "foo2", undef, + { category => "Alpha", lat=>"22.22" } ) + or die "Couldn't write node"; + $wiki->write_node( "Test Page 3", "foo33", undef, + { category => "Alpha" } ) + or die "Couldn't write node"; + $wiki->write_node( "Category Foo", "foo", undef, + { category => "Categories", lat=>"-8.77" } ) + or die "Couldn't write category"; + $wiki->write_node( "Locale Bar", "foo", undef, + { category => "Locales", lat=>"8.22" } ) + or die "Couldn't write locale"; + my %data = $wiki->retrieve_node( "Locale Bar" ); + $wiki->write_node( "Locale Bar", "foo version 2", $data{checksum}, + { category => "Locales", lat=>"8.88" } ) + or die "Couldn't write locale for the 2nd time"; + + + # Try without search parameters + my %ttvars = eval { + $guide->show_missing_metadata( return_tt_vars=> 1 ); + }; + my @nodes; + is( $@, "", "->show_missing_metadata doesn't die" ); + + is( scalar @{$ttvars{'nodes'}}, 0, "No nodes when no search params" ); + is( $ttvars{'done_search'}, 0, "Didn't search" ); + + + # Now try searching for those without lat + %ttvars = eval { + $guide->show_missing_metadata( + metadata_type => 'lat', + return_tt_vars => 1 + ); + }; + + @nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}}; + is( scalar @nodes, 2, "Two without / with empty lat" ); + is( $ttvars{'done_search'}, 1, "Did search" ); + is( $nodes[0]->{'name'}, "Test Page", "Right nodes" ); + is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" ); + + + # Now try searching for those without lat=22.22 + %ttvars = eval { + $guide->show_missing_metadata( + metadata_type => 'lat', + metadata_value => '22.22', + return_tt_vars => 1 + ); + }; + + @nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}}; + is( scalar @nodes, 4, "Four without that lat" ); + is( $ttvars{'done_search'}, 1, "Did search" ); + is( $nodes[0]->{'name'}, "Category Foo", "Right nodes" ); + is( $nodes[1]->{'name'}, "Locale Bar", "Right nodes" ); + is( $nodes[2]->{'name'}, "Test Page", "Right nodes" ); + is( $nodes[3]->{'name'}, "Test Page 3", "Right nodes" ); + + + # Try again, but exclude locale and category + %ttvars = eval { + $guide->show_missing_metadata( + metadata_type => 'lat', + metadata_value => '22.22', + exclude_locales => 1, + exclude_categories => 2, + return_tt_vars => 1 + ); + }; + + @nodes = sort {$a->{'name'} cmp $b->{'name'}} @{$ttvars{'nodes'}}; + is( scalar @nodes, 2, "Two without that lat" ); + is( $ttvars{'done_search'}, 1, "Did search" ); + is( $nodes[0]->{'name'}, "Test Page", "Right nodes" ); + is( $nodes[1]->{'name'}, "Test Page 3", "Right nodes" ); + + + # Test the normal, HTML version + my $output = eval { + $guide->show_missing_metadata( return_output=>1 ); + }; + is( $@, "", "->how_missing_metadata doesn't die" ); + + like( $output, qr|Missing Metadata|, "Right page" ); + like( $output, qr|Metadata Type|, "Has prompts" ); + unlike( $output, qr|<h3>Pages</h3>|, "Didn't search" ); + + $output = eval { + $guide->show_missing_metadata( return_output=>1, metadata_type=>'lat' ); + }; + is( $@, "", "->how_missing_metadata doesn't die" ); + like( $output, qr|<h3>Pages</h3>|, "searched" ); + like( $output, qr|Test Page|, "had node" ); +}
Modified: trunk/templates/admin_home.tt =================================================================== --- trunk/templates/admin_home.tt 2006-08-03 13:15:13 UTC (rev 823) +++ trunk/templates/admin_home.tt 2006-08-03 14:26:35 UTC (rev 824) @@ -8,6 +8,8 @@ <li><a href="#nodes">Nodes</a></li> <li><a href="#locales">Locales</a></li> <li><a href="#categories">Categories</a></li> + <li><a href="?action=show_needing_moderation">Pages Needing Moderation</a> + <li><a href="?action=show_missing_metadata">Pages Missing Metadata</a> </ul>
<a name="nodes"></a>
Added: trunk/templates/missing_metadata.tt =================================================================== --- trunk/templates/missing_metadata.tt 2006-08-03 13:15:13 UTC (rev 823) +++ trunk/templates/missing_metadata.tt 2006-08-03 14:26:35 UTC (rev 824) @@ -0,0 +1,51 @@ +[% INCLUDE header.tt page_title = "Missing Metadata - $site_name" %] +[% INCLUDE banner.tt %] +<div id="content"> +[% INCLUDE navbar.tt %] +<div id="maincontent"> +<h2>Pages Missing Metadata</h2> + +<form method="get" action="wiki.cgi"> +<div> + <label for="metadata_type">Metadata Type:</label> + <select name="metadata_type"> + <option value="category">Category</option> + <option value="locale">Locale</option> + <option value="address">Address</option> + <option value="postcode">Postcode</option> + <option value="phone">Telephone Number</option> + <option value="latitude">Latitude</option> + <option value="longitude">Longitude</option> + <option value="os_x">OS X</option> + <option value="os_y">OS Y</option> + </select> +</div> +<div> + <label for="metadata_value">Metadata Value:</label> + <input name="metadata_value" value="[% metadata_value %]" /> + <br /> + <i>Optional, eg 'pub' when metadata value is Category</i> +</div> +<div> + <input type="submit" value="Find Nodes" /> +</div> +</form> + +[% IF done_search %] + <h3>Pages</h3> + <a name="nodes"></a> + <table id="nodes"> + <tr><th>Node name</th><th>View</th><th>Edit</th></tr> + [% FOREACH node = nodes %] + <tr> + <td><a href="[% node.view_url %]">[% node.name %]</a></td> + <td><a href="[% node.view_url %]">view</a></td> + <td><a href="[% node.edit_url %]">edit</a></td> + </tr> + [% END %] + </table> +[% END %] + +</div> + +[% INCLUDE footer.tt %]
Modified: trunk/wiki.cgi =================================================================== --- trunk/wiki.cgi 2006-08-03 13:15:13 UTC (rev 823) +++ trunk/wiki.cgi 2006-08-03 14:26:35 UTC (rev 824) @@ -84,6 +84,13 @@ ); } elsif ( $action eq 'admin' ) { $guide->display_admin_interface(); + } elsif ( $action eq 'show_missing_metadata' ) { + $guide->show_missing_metadata( + metadata_type => $q->param("metadata_type"), + metadata_value => $q->param("metadata_value"), + exclude_locales => $q->param("exclude_locales"), + exclude_categories => $q->param("exclude_categories") + ); } elsif ( $action eq 'set_moderation' ) { $guide->set_node_moderation( id => $node,
openguides-commits@lists.openguides.org