Ticket #81: ticket_81.patch
| File ticket_81.patch, 15.0 kB (added by grimoire, 3 years ago) |
|---|
-
trunk/templates/node.tt
26 26 [% END %] 27 27 28 28 [% IF current %] 29 [% IF backlinks_in_title AND is_indexable_node %] 30 <h2 class="node_name"><a href="[% cgi_url %]?action=index;index_type=[% CGI.escape(index_type) %];index_value=[% CGI.escape(index_value) %]">[% node_name %]</a></h2> 31 [% ELSIF backlinks_in_title %] 29 [% IF backlinks_in_title %] 32 30 <h2 class="node_name"><a href="[% cgi_url %]?action=show_backlinks&id=[% CGI.escape(node_name) %]">[% node_name %]</a></h2> 33 31 [% ELSE %] 34 32 <h2 class="node_name">[% node_name %]</h2> -
trunk/INSTALL
249 249 National Grid, Geography::NationalGrid::IE to use the Irish National 250 250 Grid, and Geo::Coordinates::UTM to use a UTM ellipsoid. 251 251 252 253 "Prefix to add to automatically generated category names?" 254 "Prefix to add to automatically generated locale names?" 255 256 If a user specifies a category or locale for a node which does not exist, a 257 node for that category or locale will be automatically generated. By default, a 258 category of "Foo" will lead to a node titled "Category Foo", and a locale of 259 "Bar" will lead to a node titled "Category Bar". These options allow this 260 behaviour to be changed. 261 252 262 * Dependency errors 253 263 254 264 If, after you have answered these questions, the build script complains -
trunk/lib/OpenGuides/Config.pm
12 12 formatting_rules_node formatting_rules_link backlinks_in_title template_path 13 13 custom_template_path geo_handler ellipsoid gmaps_api_key centre_long 14 14 centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84 15 category_prefix locale_prefix 15 16 ); 16 17 my @questions = map { $_ . "__qu" } @variables; 17 18 OpenGuides::Config->mk_accessors( @variables ); … … 82 83 centre_lat => 0, 83 84 default_gmaps_zoom => 5, 84 85 default_gmaps_search_zoom => 3, 85 force_wgs84 => 0 86 force_wgs84 => 0, 87 category_prefix => "Category ", 88 locale_prefix => "Locale ", 86 89 ); 87 90 88 91 # See if we already have some config variables set. … … 145 148 centre_lat => "What is the latitude of the centre point of a map to draw for your guide? (This question can be ignored if you aren't using Google Maps)", 146 149 default_gmaps_zoom => "What default zoom level shall we use for Google Maps? (This question can be ignored if you aren't using Google Maps)", 147 150 default_gmaps_search_zoom => "What default zoom level shall we use for Google Maps in the search results? (This question can be ignored if you aren't using Google Maps)", 148 force_wgs84 => "Forcibly treat stored lat/long data as if they used the WGS84 ellipsoid?" 151 force_wgs84 => "Forcibly treat stored lat/long data as if they used the WGS84 ellipsoid?", 152 category_prefix => "Prefix to add to automatically generated category names?", 153 locale_prefix => "Prefix to add to automatically generated locale names?" 149 154 ); 150 155 151 156 foreach my $var ( keys %questions ) { … … 246 251 247 252 =item * force_wgs84 248 253 254 =item * category_prefix 255 256 =item * locale_prefix 257 249 258 =back 250 259 251 260 =head1 AUTHOR -
trunk/lib/OpenGuides/Template.pm
268 268 split("\r\n", $locales_text); 269 269 } 270 270 271 my $category_prefix = ( $config->category_prefix ne '' ? $config->category_prefix . ' ' : ''); 272 my $locale_prefix = ( $config->locale_prefix ne '' ? $config->locale_prefix . ' ' : ''); 273 271 274 my @categories = map { { name => $_, 272 url => "$script_name? Category_"273 . uri_escape($formatter->node_name_to_node_param($ _)) } } @catlist;275 url => "$script_name?" 276 . uri_escape($formatter->node_name_to_node_param($category_prefix . $_)) } } @catlist; 274 277 275 278 my @locales = map { { name => $_, 276 url => "$script_name? Locale_"277 . uri_escape($formatter->node_name_to_node_param($ _)) } } @loclist;279 url => "$script_name?" 280 . uri_escape($formatter->node_name_to_node_param($locale_prefix . $_)) } } @loclist; 278 281 279 282 # The 'website' attribute might contain a URL so we wiki-format it here 280 283 # rather than just CGI::escapeHTMLing it all in the template. -
trunk/lib/OpenGuides/Utils.pm
113 113 my $script_name = $config->script_name; 114 114 my $search_url = $config->script_url . "search.cgi"; 115 115 116 my $locale_prefix = $config->locale_prefix; 117 my $category_prefix = $config->category_prefix; 118 116 119 my %macros = ( 117 120 '@SEARCHBOX' => 118 121 qq(<form action="$search_url" method="get"><input type="text" size="20" name="search"><input type="submit" name="Go" value="Search"></form>), … … 127 130 my $link_title = $_[2] || "View all pages in $_[0] $_[1]"; 128 131 return qq(<a href="$script_name?action=index;index_type=) . uri_escape(lc($_[0])) . qq(;index_value=) . uri_escape($_[1]) . qq(">$link_title</a>); 129 132 }, 133 qr/\@LOCALE_LINK\s+\[\[($locale_prefix)\s*([^\]|]+)\|?([^\]]+)?\]\]/ => 134 sub { 135 # We may be being called by CGI::Wiki::Plugin::Diff, 136 # which doesn't know it has to pass us $wiki - and 137 # we don't use it anyway. 138 if ( UNIVERSAL::isa( $_[0], "CGI::Wiki" ) ) { 139 shift; # just throw it away 140 } 141 my $localename = $_[0] || "Locale"; 142 my $link_title = $_[2] || "View all pages in $localename $_[1]"; 143 return qq(<a href="$script_name?action=index;index_type=category;index_value=) . uri_escape($_[1]) . qq(">$link_title</a>); 144 }, 145 qr/\@CATEGORY_LINK\s+\[\[($category_prefix)\s*([^\]|]+)\|?([^\]]+)?\]\]/ => 146 sub { 147 # We may be being called by CGI::Wiki::Plugin::Diff, 148 # which doesn't know it has to pass us $wiki - and 149 # we don't use it anyway. 150 if ( UNIVERSAL::isa( $_[0], "CGI::Wiki" ) ) { 151 shift; # just throw it away 152 } 153 my $categoryname = $_[0] || "Category"; 154 my $link_title = $_[2] || "View all pages in $categoryname $_[1]"; 155 return qq(<a href="$script_name?action=index;index_type=category;index_value=) . uri_escape($_[1]) . qq(">$link_title</a>); 156 }, 130 157 qr/\@INDEX_LIST\s+\[\[(Category|Locale)\s+([^\]]+)]]/ => 131 158 sub { 132 159 my ($wiki, $type, $value) = @_; … … 135 162 # which doesn't know it has to pass us $wiki 136 163 unless ( UNIVERSAL::isa( $wiki, "CGI::Wiki" ) ) { 137 164 return "(unprocessed INDEX_LIST macro)"; 138 }165 } 139 166 140 167 my @nodes = sort $wiki->list_nodes_by_metadata( 141 168 metadata_type => $type, … … 154 181 link => $node, 155 182 ) 156 183 . "\n"; 157 }184 } 158 185 return $return; 159 186 }, 160 187 qr/\@RSS\s+(.+)/ => sub { -
trunk/lib/OpenGuides.pm
147 147 148 148 my %tt_vars; 149 149 150 if ( $id =~ /^(Category|Locale) (.*)$/ ) {151 my $type = $1;152 $tt_vars{is_indexable_node} = 1;153 $tt_vars{index_type} = lc($type);154 $tt_vars{index_value} = $2;155 $tt_vars{"rss_".lc($type)."_url"} =156 $config->script_name . "?action=rc;format=rss;"157 . lc($type) . "=" . lc(CGI->escape($2));158 }159 160 150 my %current_data = $wiki->retrieve_node( $id ); 161 151 my $current_version = $current_data{version}; 162 152 undef $version if ($version && $version == $current_version); … … 492 482 sub show_index { 493 483 my ($self, %args) = @_; 494 484 my $wiki = $self->wiki; 485 my $config = $self->config; 495 486 my $formatter = $wiki->formatter; 496 487 my %tt_vars; 497 488 my @selnodes; … … 512 503 metadata_value => $args{value}, 513 504 ignore_case => 1 514 505 ); 515 my $name = ucfirst($args{type}) . " $args{value}"; 506 my $name_prefix; 507 my $type_prefix; 508 if ( $args{type} eq 'category' or $args{type} eq 'locale' ) { 509 $type_prefix = $config->category_prefix; 510 $type_prefix .= ' ' if ( $type_prefix ne '' ); 511 $name_prefix = $type_prefix || $args{type}; 512 } else { 513 # Not sure this should ever be reached, actually 514 $type_prefix = ucfirst($args{type}) . ' '; 515 $name_prefix = $type_prefix; 516 } 516 517 my $url = $self->config->script_name 517 518 . "?" 518 . ucfirst( $args{type} )519 . "_"520 519 . uri_escape( 521 $formatter->node_name_to_node_param($ args{value})520 $formatter->node_name_to_node_param($type_prefix . $args{value}) 522 521 ); 523 522 $tt_vars{criterion} = { 524 523 type => $args{type}, 525 524 value => $args{value}, # for RDF version 526 name => CGI->escapeHTML( $name),525 name => CGI->escapeHTML($name_prefix . ' ' . $args{value}), 527 526 url => $url 528 527 }; 529 528 $tt_vars{not_editable} = 1; … … 759 758 $metadata{longitude} = delete $metadata{longitude_unmunged} 760 759 if $metadata{longitude_unmunged}; 761 760 762 # Check to make sure all the indexable nodes are created 763 foreach my $type (qw(Category Locale)) { 764 my $lctype = lc($type); 765 foreach my $index (@{$metadata{$lctype}}) { 766 $index =~ s/(.*)/\u$1/; 767 my $node = $type . " " . $index; 768 # Uppercase the node name before checking for existence 769 $node =~ s/ (\S+)/ \u$1/g; 770 unless ( $wiki->node_exists($node) ) { 771 my $category = $type eq "Category" ? "Category" : "Locales"; 772 $wiki->write_node( 773 $node, 774 "\@INDEX_LINK [[$node]]", 775 undef, 776 { 777 username => "Auto Create", 778 comment => "Auto created $lctype stub page", 779 category => $category 780 } 781 ); 761 # We must look at the categories and locales for our new nodes, and make 762 # sure that the nodes referenced are in category "Category" or "Locale" 763 # respectively. 764 765 foreach my $type (qw/category locale/) { 766 my $prefix = $type eq 'category' ? $config->category_prefix : $config->locale_prefix; 767 $prefix .= ' ' if ( $prefix ne '' ); 768 # Look at all entries for "Categories" or "Locales" for our new node 769 foreach my $index (@{$metadata{$type}}) { 770 my $nodename = $prefix . $index; 771 my $category = $type eq 'category' ? 'Category' : 'Locales'; 772 if ( $wiki->node_exists($nodename) ) { 773 # We need to make sure that this node is in the relevant category 774 my %referencednode = $wiki->retrieve_node($nodename); 775 if ( not grep { $_ eq $category } @{$referencednode{metadata}{category}} ) { 776 # Add the required Category to the node, and write it 777 my $uctype = uc($type); 778 $referencednode{content} .= "\n\@${uctype}_LINK [[$nodename]]"; 779 push @{$referencednode{metadata}{category}}, $category; 780 $referencednode{metadata}{username} = "Auto Create"; 781 $referencednode{metadata}{comment} = "Added to $type $category"; 782 $referencednode{metadata}{major_change} = 0; 783 my $conflict = $wiki->write_node ( 784 $nodename, 785 $referencednode{content}, 786 $referencednode{checksum}, 787 $referencednode{metadata} 788 ); 789 if ( $conflict == 0 ) { 790 warn "Conflict while adding category $category to node $nodename, failing silently"; 791 } 792 } 793 } else { 794 # There is no node for our new node's category or locale, we must create it 795 my $uctype = uc($type); 796 $wiki->write_node ( 797 $nodename, 798 "\@${uctype}_LINK [[$nodename]]", 799 undef, 800 { 801 username => "Auto Create", 802 comment => "Auto created $type stub page", 803 category => $category 804 } 805 ); 782 806 } 783 807 } 784 808 } 785 809 786 810 foreach my $var ( qw( summary username comment edit_type ) ) { 787 811 $metadata{$var} = $q->param($var) || ""; 788 812 } -
trunk/Changes
1 1 0.52 2 Added configuration options "category_prefix" and "locale_prefix", used 3 for automatically generated categories and locales, and to generate 4 links within nodes. 5 Added macros @CATEGORY_LINK and @LOCALE_LINK to replace @INDEX_LINK 2 6 IMPORTANT CHANGE: "supersearch.cgi" is now simply "search.cgi". If you 3 7 have customisations to your templates, you may need to make changes 4 8 to reflect this.
