Changeset 1015


Ignore:
Timestamp:
Apr 3, 2007, 2:13:11 AM (15 years ago)
Author:
kake
Message:

Add config options to let admins omit category and/or locale pages from the list of pages that can be returned by the Random Page link (first half of ticket #200).

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Build.PL

    r1004 r1015  
    4242      moderation_requires_password enable_node_image enable_common_categories
    4343      enable_common_locales recent_changes_on_home_page
     44      random_page_omits_locales random_page_omits_categories
    4445      content_above_navbar_in_html show_gmap_in_node_display);
    4546
     
    9697   custom_lib_path use_plucene indexing_directory enable_page_deletion
    9798   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
    99101   site_desc default_city default_country contact_email default_language
    100102   formatting_rules_node backlinks_in_title gmaps_api_key centre_long
  • trunk/Changes

    r1014 r1015  
    77        Move random page functionality from wiki.cgi into OpenGuides.pm and
    88          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.
    911        Use full URLs for all links in navbar, so people can INCLUDE navbar.tt
    1012          in their own scripts.  (May revisit this later using "base href".)
  • trunk/INSTALL

    r965 r1015  
    156156
    157157Answer "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
     163Answer "y" or "n".  The defaults are "n", which means that Random Page is as
     164likely to return a category or locale page as anything else.  If the category
     165and locale pages on your Guide are generally just lists of things in that
     166category/locale, you probably want to pick "y" here.  If, on the other hand,
     167your category/locale pages generally have substantial content of their own,
     168you may prefer to choose "n".
    158169
    159170
  • trunk/lib/OpenGuides.pm

    r1014 r1015  
    343343sub display_random_page {
    344344    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    }
    346377    my $node = $nodes[ rand @nodes ];
    347378    my $output = $self->redirect_to_node( $node );
  • trunk/lib/OpenGuides/Config.pm

    r1003 r1015  
    1212   custom_lib_path use_plucene indexing_directory enable_page_deletion
    1313   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
    1516   site_desc default_city default_country contact_email
    1617   default_language http_charset ping_services
     
    8384                     navbar_on_home_page => 1,
    8485                     recent_changes_on_home_page => 1,
     86                     random_page_omits_locales => 0,
     87                     random_page_omits_categories => 0,
    8588                     content_above_navbar_in_html => 0,
    8689                     home_name => "Home",
     
    159162        navbar_on_home_page => "Do you want the navigation bar included on the home page?",
    160163        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?",
    161166        content_above_navbar_in_html => "Do you want the content to appear above the navbar in the HTML?",
    162167        home_name => "What should the home page of the wiki be called?",
     
    254259=item * recent_changes_on_home_page (default: true)
    255260
     261=item * random_page_omits_locales (default: false)
     262
     263=item * random_page_omits_categories (default: false)
     264
    256265=item * content_above_navbar_in_html (default: false)
    257266
  • trunk/t/57_random_page.t

    r1014 r1015  
    1111}
    1212
    13 plan tests => 2;
     13plan tests => 4;
    1414
    15 # Clear out the database from any previous runs.
    16 unlink "t/node.db";
    17 unlink <t/indexes/*>;
     15my ( $config, $guide, $wiki );
    1816
    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.
     18refresh_db();
     19$config = OpenGuides::Test->make_basic_config;
    2120$config->script_url( "http://www.example.com/" );
    2221$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;
    2524
    2625# Write some data.
     
    4140      "->display_random_page makes a redirect" );
    4241
    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 );
     42my $node = get_node_from_output( $output );
    4843print "# Random node chosen: $node\n";
    4944ok( $nodes{$node}, "...to an existing node" );
     45
     46# Clear the database and write some data including categories and locales.
     47refresh_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.
     55OpenGuides::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 );
     72print "# Random node chosen: $node\n";
     73isnt( $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 );
     85print "# Random node chosen: $node\n";
     86isnt( $node, "Category Pubs", "category nodes not picked up as random page "
     87                       . "(this test may sometimes pass when it shouldn't)" );
     88
     89sub refresh_db {
     90    unlink "t/node.db";
     91    unlink <t/indexes/*>;
     92    Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
     93}
     94
     95sub 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}
Note: See TracChangeset for help on using the changeset viewer.