Changeset 1081


Ignore:
Timestamp:
Jun 16, 2007, 8:45:04 PM (14 years ago)
Author:
Dagfinn Ilmari Mannsåker
Message:

List all contributors in RDF version of nodes (fixes #106)

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r1070 r1081  
    2020          someone tries to view a nonexistent node.
    2121        Validate input geodata (#22)
     22        List all contributors in RDF version of nodes (#106).
    2223
    23240.60    13 May 2007
  • trunk/lib/OpenGuides/RDF.pm

    r1066 r1081  
    8383
    8484    foreach my $var ( qw( phone fax website opening_hours_text address
    85                           postcode city country latitude longitude username
     85                          postcode city country latitude longitude
    8686                          os_x os_y summary ) ) {
    8787        my $val = $metadata{$var}[0] || $defaults{$var} || "";
     
    134134    }
    135135
    136     $tt_vars{user_id} = $tt_vars{username};
    137     $tt_vars{user_id} =~ s/\s/_/g;
    138    
    139136    $tt_vars{node_uri} = $self->{make_node_url}->( $node_name );
    140137    $tt_vars{node_uri_with_version}
     
    158155    }
    159156
     157    my @revisions = $wiki->list_node_all_versions(
     158                                                   name => $node_name,
     159                                                   with_content => 0,
     160                                                   with_metadata => 1,
     161                                                 );
     162
     163    # We want all users who have edited the page listed as contributors,
     164    # but only once each
     165    foreach my $rev ( @revisions ) {
     166        my $username = $rev->{metadata}{username};
     167        next unless defined $username && length $username;
     168
     169        my $user_id = $username;
     170        $user_id =~ s/\s+/_/g;
     171       
     172        $tt_vars{contributors}{$username} ||=
     173            {
     174              username => encode_entities_numeric($username),
     175              user_id  => encode_entities_numeric($user_id),
     176            };
     177    }
     178
    160179    # OK, we've set all our template variables; now process the template.
    161180    my $template_path = $config->template_path;
  • trunk/t/21_rdf.t

    r1063 r1081  
    1616}
    1717
    18 plan tests => 27;
     18plan tests => 28;
    1919
    2020Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     
    2525$config->default_city( "London" );
    2626$config->default_country( "United Kingdom" );
     27$config->geo_handler( 3 );
    2728
    2829eval { require Wiki::Toolkit::Search::Plucene; };
     
    4546
    4647# Test the data for a node that exists.
     48OpenGuides::Test->write_data(
     49        guide              => $guide,
     50        node               => "Calthorpe Arms",
     51        content            => "CAMRA-approved pub near King's Cross",
     52        comment            => "Stub page, please update!",
     53        username           => "Anonymous",
     54        postcode           => "WC1X 8JR",
     55        locales            => "Bloomsbury\r\nSt Pancras",
     56        phone              => "test phone number",
     57        website            => "test website",
     58        hours_text         => "test hours",
     59        latitude           => "51.524193",
     60        longitude          => "-0.114436",
     61        summary            => "a really nice pub",
     62);
     63
    4764OpenGuides::Test->write_data(
    4865        guide              => $guide,
     
    84101like( $rdfxml, qr|<foaf:Person rdf:ID="Kake">|,
    85102    "last username to edit used as contributor" );
     103like( $rdfxml, qr|<foaf:Person rdf:ID="Anonymous">|,
     104    "... as well as previous usernames" );
    86105
    87 like( $rdfxml, qr|<wiki:version>1</wiki:version>|, "version picked up" );
     106like( $rdfxml, qr|<wiki:version>2</wiki:version>|, "version picked up" );
    88107
    89108like( $rdfxml, qr|<rdf:Description rdf:about="">|, "sets the 'about' correctly" );
  • trunk/templates/node_rdf.tt

    r1061 r1081  
    1919    <dcterms:modified>[% timestamp %]</dcterms:modified>
    2020
     21    [% FOREACH contributor = contributors.values %]
    2122    <dc:contributor>
    22       <foaf:Person rdf:ID="[% user_id %]">
    23         <foaf:nick>[% username %]</foaf:nick>
     23      <foaf:Person rdf:ID="[% contributor.user_id %]">
     24        <foaf:nick>[% contributor.username %]</foaf:nick>
    2425      </foaf:Person>
    2526    </dc:contributor>
     27    [% END %]
    2628
    2729    <dc:source rdf:resource="[% node_uri %]" />
Note: See TracChangeset for help on using the changeset viewer.