Changeset 1015
- Timestamp:
- 04/03/07 02:13:11 (20 months ago)
- Location:
- trunk
- Files:
-
- 6 modified
-
Build.PL (modified) (2 diffs)
-
Changes (modified) (1 diff)
-
INSTALL (modified) (1 diff)
-
lib/OpenGuides.pm (modified) (1 diff)
-
lib/OpenGuides/Config.pm (modified) (4 diffs)
-
t/57_random_page.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Build.PL
r1004 r1015 42 42 moderation_requires_password enable_node_image enable_common_categories 43 43 enable_common_locales recent_changes_on_home_page 44 random_page_omits_locales random_page_omits_categories 44 45 content_above_navbar_in_html show_gmap_in_node_display); 45 46 … … 96 97 custom_lib_path use_plucene indexing_directory enable_page_deletion 97 98 admin_pass stylesheet_url site_name navbar_on_home_page 98 recent_changes_on_home_page content_above_navbar_in_html home_name 99 recent_changes_on_home_page random_page_omits_locales 100 random_page_omits_categories content_above_navbar_in_html home_name 99 101 site_desc default_city default_country contact_email default_language 100 102 formatting_rules_node backlinks_in_title gmaps_api_key centre_long -
trunk/Changes
r1014 r1015 7 7 Move random page functionality from wiki.cgi into OpenGuides.pm and 8 8 add some tests. 9 Add config options to let admins omit category and/or locale pages 10 from the list of pages that can be returned by the Random Page link. 9 11 Use full URLs for all links in navbar, so people can INCLUDE navbar.tt 10 12 in their own scripts. (May revisit this later using "base href".) -
trunk/INSTALL
r965 r1015 156 156 157 157 Answer "y" or "n". 158 159 160 "Do you want the Random Page link to avoid returning a locale page? 161 "Do you want the Random Page link to avoid returning a category page? 162 163 Answer "y" or "n". The defaults are "n", which means that Random Page is as 164 likely to return a category or locale page as anything else. If the category 165 and locale pages on your Guide are generally just lists of things in that 166 category/locale, you probably want to pick "y" here. If, on the other hand, 167 your category/locale pages generally have substantial content of their own, 168 you may prefer to choose "n". 158 169 159 170 -
trunk/lib/OpenGuides.pm
r1014 r1015 343 343 sub display_random_page { 344 344 my ( $self, %args ) = @_; 345 my @nodes = $self->wiki->list_all_nodes(); 345 my $wiki = $self->wiki; 346 my $config = $self->config; 347 348 my @nodes = $wiki->list_all_nodes(); 349 350 my $omit_cats = $config->random_page_omits_categories; 351 my $omit_locs = $config->random_page_omits_locales; 352 353 if ( $omit_cats || $omit_locs ) { 354 my %all_nodes = map { $_ => $_ } @nodes; 355 if ( $omit_cats ) { 356 my @cats = $wiki->list_nodes_by_metadata( 357 metadata_type => "category", 358 metadata_value => "category", 359 ignore_case => 1, 360 ); 361 foreach my $omit ( @cats ) { 362 delete $all_nodes{$omit}; 363 } 364 } 365 if ( $omit_locs ) { 366 my @locs = $wiki->list_nodes_by_metadata( 367 metadata_type => "category", 368 metadata_value => "locales", 369 ignore_case => 1, 370 ); 371 foreach my $omit ( @locs ) { 372 delete $all_nodes{$omit}; 373 } 374 } 375 @nodes = keys %all_nodes; 376 } 346 377 my $node = $nodes[ rand @nodes ]; 347 378 my $output = $self->redirect_to_node( $node ); -
trunk/lib/OpenGuides/Config.pm
r1003 r1015 12 12 custom_lib_path use_plucene indexing_directory enable_page_deletion 13 13 admin_pass stylesheet_url site_name navbar_on_home_page 14 recent_changes_on_home_page content_above_navbar_in_html home_name 14 recent_changes_on_home_page random_page_omits_locales 15 random_page_omits_categories content_above_navbar_in_html home_name 15 16 site_desc default_city default_country contact_email 16 17 default_language http_charset ping_services … … 83 84 navbar_on_home_page => 1, 84 85 recent_changes_on_home_page => 1, 86 random_page_omits_locales => 0, 87 random_page_omits_categories => 0, 85 88 content_above_navbar_in_html => 0, 86 89 home_name => "Home", … … 159 162 navbar_on_home_page => "Do you want the navigation bar included on the home page?", 160 163 recent_changes_on_home_page => "Do you want the ten most recent changes included on the home page?", 164 random_page_omits_locales => "Do you want the \"Random Page\" link to avoid returning a locale page?", 165 random_page_omits_categories => "Do you want the \"Random Page\" link to avoid returning a category page?", 161 166 content_above_navbar_in_html => "Do you want the content to appear above the navbar in the HTML?", 162 167 home_name => "What should the home page of the wiki be called?", … … 254 259 =item * recent_changes_on_home_page (default: true) 255 260 261 =item * random_page_omits_locales (default: false) 262 263 =item * random_page_omits_categories (default: false) 264 256 265 =item * content_above_navbar_in_html (default: false) 257 266 -
trunk/t/57_random_page.t
r1014 r1015 11 11 } 12 12 13 plan tests => 2;13 plan tests => 4; 14 14 15 # Clear out the database from any previous runs. 16 unlink "t/node.db"; 17 unlink <t/indexes/*>; 15 my ( $config, $guide, $wiki ); 18 16 19 Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); 20 my $config = OpenGuides::Test->make_basic_config; 17 # Clear out database from previous runs, set up a guide. 18 refresh_db(); 19 $config = OpenGuides::Test->make_basic_config; 21 20 $config->script_url( "http://www.example.com/" ); 22 21 $config->script_name( "wiki.cgi" ); 23 my$guide = OpenGuides->new( config => $config );24 my$wiki = $guide->wiki;22 $guide = OpenGuides->new( config => $config ); 23 $wiki = $guide->wiki; 25 24 26 25 # Write some data. … … 41 40 "->display_random_page makes a redirect" ); 42 41 43 my $node_param = $output; 44 $node_param =~ s/^.*\?//s; 45 $node_param =~ s/\s+$//; 46 my $formatter = $guide->wiki->formatter; 47 my $node = $formatter->node_param_to_node_name( $node_param ); 42 my $node = get_node_from_output( $output ); 48 43 print "# Random node chosen: $node\n"; 49 44 ok( $nodes{$node}, "...to an existing node" ); 45 46 # Clear the database and write some data including categories and locales. 47 refresh_db(); 48 $config = OpenGuides::Test->make_basic_config; 49 $config->script_url( "http://www.example.com/" ); 50 $config->script_name( "wiki.cgi" ); 51 $guide = OpenGuides->new( config => $config ); 52 $wiki = $guide->wiki; 53 54 # Write data including some categories/locales. 55 OpenGuides::Test->write_data( 56 guide => $guide, 57 node => "Red Lion", 58 locales => "Hammersmith", 59 categories => "Pubs", 60 return_output => 1, 61 ); 62 63 # Check we can turn off locales. 64 $config = OpenGuides::Test->make_basic_config; 65 $config->script_url( "http://www.example.com/" ); 66 $config->script_name( "wiki.cgi" ); 67 $config->random_page_omits_locales( 1 ); 68 $guide = OpenGuides->new( config => $config ); 69 $wiki = $guide->wiki; 70 $output = $guide->display_random_page( return_output => 1 ); 71 $node = get_node_from_output( $output ); 72 print "# Random node chosen: $node\n"; 73 isnt( $node, "Locale Hammersmith", "locale nodes not picked up as random page " 74 . "(this test may sometimes pass when it shouldn't)" ); 75 76 # Check we can turn off categories. 77 $config = OpenGuides::Test->make_basic_config; 78 $config->script_url( "http://www.example.com/" ); 79 $config->script_name( "wiki.cgi" ); 80 $config->random_page_omits_categories( 1 ); 81 $guide = OpenGuides->new( config => $config ); 82 $wiki = $guide->wiki; 83 $output = $guide->display_random_page( return_output => 1 ); 84 $node = get_node_from_output( $output ); 85 print "# Random node chosen: $node\n"; 86 isnt( $node, "Category Pubs", "category nodes not picked up as random page " 87 . "(this test may sometimes pass when it shouldn't)" ); 88 89 sub refresh_db { 90 unlink "t/node.db"; 91 unlink <t/indexes/*>; 92 Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); 93 } 94 95 sub get_node_from_output { 96 my $node_param = shift; 97 $node_param =~ s/^.*\?//s; 98 $node_param =~ s/\s+$//; 99 my $formatter = $guide->wiki->formatter; 100 my $node = $formatter->node_param_to_node_name( $node_param ); 101 return $node; 102 }
