This file is indexed.

/usr/share/perl5/OpenGuides/RDF.pm is in openguides 0.65-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
package OpenGuides::RDF;

use strict;

use OpenGuides::Utils;

use vars qw( $VERSION );
$VERSION = '0.14';

use Time::Piece;
use URI::Escape;
use Carp 'croak';
use HTML::Entities qw( encode_entities_numeric );
use Template;

sub new {
    my ($class, @args) = @_;
    my $self = {};
    bless $self, $class;
    $self->_init(@args);
}

sub _init {
    my ($self, %args) = @_;

    my $wiki = $args{wiki};
    
    unless ( $wiki && UNIVERSAL::isa( $wiki, "Wiki::Toolkit" ) ) {
      croak "No Wiki::Toolkit object supplied.";
    }
    $self->{wiki} = $wiki;

    my $config = $args{config};

    unless ( $config && UNIVERSAL::isa( $config, "OpenGuides::Config" ) ) {
        croak "No OpenGuides::Config object supplied.";
    }
    $self->{config} = $config;

    $self->{make_node_url} = sub {
        my ($node_name, $version) = @_;

        my $config = $self->{config};
    
        my $node_url = $config->script_url . uri_escape($config->script_name) . '?';
        $node_url .= 'id=' if defined $version;
        $node_url .= uri_escape($self->{wiki}->formatter->node_name_to_node_param($node_name));
        $node_url .= ';version=' . uri_escape($version) if defined $version;

        $node_url;
      };  
    $self->{site_name}        = $config->site_name;
    $self->{default_city}     = $config->default_city     || "";
    $self->{default_country}  = $config->default_country  || "";
    $self->{site_description} = $config->site_desc        || "";
    $self->{og_version}       = $args{og_version};

    $self;
}

sub emit_rdfxml {
    my ($self, %args) = @_;

    my $node_name = $args{node};
    my $config = $self->{config};
    my $wiki = $self->{wiki};
    my $formatter = $wiki->formatter;

    my %node_data = $wiki->retrieve_node( $node_name );
    my %metadata = %{ $node_data{metadata} };
    my %tt_vars = (
                    node_name  => $node_name,
                    version    => $node_data{version},
                    site_name  => $self->{site_name},
                    site_desc  => $self->{site_description},
                    og_version => $self->{og_version},
                    config     => $config,
                  );

    my %defaults = (
                     city => $self->{default_city},
                     country => $self->{default_country},
                   );

    foreach my $var ( qw( phone fax website opening_hours_text address
                          postcode city country latitude longitude
                          os_x os_y map_link summary node_image ) ) {
        my $val = $metadata{$var}[0] || $defaults{$var} || "";
        $tt_vars{$var} = $val;
    }

    my @cats = @{ $metadata{category} || [] };
    @cats = map { { name => $_ } } @cats;
    $tt_vars{categories} = \@cats;

    my @locs = @{ $metadata{locale} || [] };
    @locs = map {
                  {
                    name => $_,
                    id   => $formatter->node_name_to_node_param( $_ ),
                  }
                } @locs;
    $tt_vars{locales} = \@locs;

    # Check for geospatialness and define container object as appropriate.
    my $is_geospatial;
    foreach my $var ( qw( os_x os_y latitude longitude address postcode
                          opening_hours_text map_link ) ) {
        $is_geospatial = 1 if $tt_vars{$var};
    }

    $is_geospatial = 1 if scalar @locs;

    $tt_vars{obj_type} = $is_geospatial ? "geo:SpatialThing"
                                        : "rdf:Description";
    $tt_vars{is_geospatial} = $is_geospatial;

    # Fix up lat and long.
    eval {
           @tt_vars{ qw( wgs84_long wgs84_lat ) } =
               OpenGuides::Utils->get_wgs84_coords(
                                             longitude => $tt_vars{longitude},
                                             latitude  => $tt_vars{latitude},
                                             config    => $config );
    };

    # Timestamp of last edited.
    my $timestamp = $node_data{last_modified};
    if ( $timestamp ) {
        # Make a Time::Piece object in order to canonicalise time.  I think.
        my $timestamp_fmt = $Wiki::Toolkit::Store::Database::timestamp_fmt;
        my $time   = Time::Piece->strptime($timestamp, $timestamp_fmt);
        $tt_vars{timestamp} = $time->strftime("%Y-%m-%dT%H:%M:%S");
    }

    $tt_vars{node_uri} = $self->{make_node_url}->( $node_name );
    $tt_vars{node_uri_with_version}
                            = $self->{make_node_url}->( $node_name,
                                                        $tt_vars{version} );

    my $redirect = OpenGuides::Utils->detect_redirect( content =>
                                                         $node_data{content} );
    if ( $redirect ) {
        $tt_vars{redirect} = $config->script_url . $config->script_name
                             . "?id="
                             . $formatter->node_name_to_node_param( $redirect )
                             . ";format=rdf#obj";
    }

    # Escape stuff!
    foreach my $var ( keys %tt_vars ) {
        if ( $tt_vars{$var} ) {
            $tt_vars{$var} = encode_entities_numeric( $tt_vars{$var} );
        }
    }

    my @revisions = $wiki->list_node_all_versions(
                                                   name => $node_name,
                                                   with_content => 0,
                                                   with_metadata => 1,
                                                 );

    # We want all users who have edited the page listed as contributors,
    # but only once each
    foreach my $rev ( @revisions ) {
        my $username = $rev->{metadata}{username};
        next unless defined $username && length $username;

        my $user_id = $username;
        $user_id =~ s/\s+/_/g;
        
        $tt_vars{contributors}{$username} ||=
            {
              username => encode_entities_numeric($username),
              user_id  => encode_entities_numeric($user_id),
            };
    }

    # OK, we've set all our template variables; now process the template.
    my $template_path = $config->template_path;
    my $custom_template_path = $config->custom_template_path || "";
    my $tt = Template->new( {
                    INCLUDE_PATH => "$custom_template_path:$template_path" } );

    $tt_vars{full_cgi_url} = $config->script_url . $config->script_name;

    my $rdf;
    $tt->process( "node_rdf.tt", \%tt_vars, \$rdf );
    $rdf ||= "ERROR: " . $tt->error;
    return $rdf;
}

=head1 NAME

OpenGuides::RDF - An OpenGuides plugin to output RDF/XML.

=head1 DESCRIPTION

Does all the RDF stuff for OpenGuides.  Distributed and installed as
part of the OpenGuides project, not intended for independent
installation.  This documentation is probably only useful to OpenGuides
developers.

=head1 SYNOPSIS

    use Wiki::Toolkit;
    use OpenGuides::Config;
    use OpenGuides::RDF;

    my $wiki = Wiki::Toolkit->new( ... );
    my $config = OpenGuides::Config->new( file => "wiki.conf" );
    my $rdf_writer = OpenGuides::RDF->new( wiki   => $wiki,
                                         config => $config ); 

    # RDF version of a node.
    print "Content-Type: application/rdf+xml\n\n";
    print $rdf_writer->emit_rdfxml( node => "Masala Zone, N1 0NU" );

=head1 METHODS

=over 4

=item B<new>

    my $rdf_writer = OpenGuides::RDF->new( wiki   => $wiki,
                                           config => $config ); 

C<wiki> must be a L<Wiki::Toolkit> object and C<config> must be an
L<OpenGuides::Config> object.  Both arguments mandatory.


=item B<emit_rdfxml>

    $wiki->write_node( "Masala Zone, N1 0NU",
		     "Quick and tasty Indian food",
		     $checksum,
		     { comment  => "New page",
		       username => "Kake",
		       locale   => "Islington" }
    );

    print "Content-Type: application/rdf+xml\n\n";
    print $rdf_writer->emit_rdfxml( node => "Masala Zone, N1 0NU" );

B<Note:> Some of the fields emitted by the RDF/XML generator are taken
from the node metadata. The form of this metadata is I<not> mandated
by L<Wiki::Toolkit>. Your wiki application should make sure to store some or
all of the following metadata when calling C<write_node>:

=over 4

=item B<postcode> - The postcode or zip code of the place discussed by the node.  Defaults to the empty string.

=item B<city> - The name of the city that the node is in.  If not supplied, then the value of C<default_city> in the config object supplied to C<new>, if available, otherwise the empty string.

=item B<country> - The name of the country that the node is in.  If not supplied, then the value of C<default_country> in the config object supplied to C<new> will be used, if available, otherwise the empty string.

=item B<username> - An identifier for the person who made the latest edit to the node.  This person will be listed as a contributor (Dublin Core).  Defaults to empty string.

=item B<locale> - The value of this can be a scalar or an arrayref, since some places have a plausible claim to being in more than one locale.  Each of these is put in as a C<Neighbourhood> attribute.

=item B<phone> - Only one number supported at the moment.  No validation.

=item B<website> - No validation.

=item B<opening_hours_text> - A freeform text field.

=back

=back

=head1 SEE ALSO

=over 4

=item * L<Wiki::Toolkit>

=item * L<http://openguides.org/>

=item * L<http://chefmoz.org/>

=back

=head1 AUTHOR

The OpenGuides Project (openguides-dev@lists.openguides.org)

=head1 COPYRIGHT

Copyright (C) 2003-2009 The OpenGuides Project.  All Rights Reserved.

This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=head1 CREDITS

Code in this module written by Kake Pugh and Earle Martin.  Dan Brickley, Matt 
Biddulph and other inhabitants of #swig on irc.freenode.net gave useful feedback 
and advice.

=cut

1;