Changeset 1014


Ignore:
Timestamp:
Apr 3, 2007, 1:02:45 AM (15 years ago)
Author:
kake
Message:

Move random page functionality from wiki.cgi into OpenGuides.pm and add some tests.

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r1012 r1014  
    55
    660.60
     7        Move random page functionality from wiki.cgi into OpenGuides.pm and
     8          add some tests.
    79        Use full URLs for all links in navbar, so people can INCLUDE navbar.tt
    810          in their own scripts.  (May revisit this later using "base href".)
  • trunk/MANIFEST

    r997 r1014  
    117117t/55_node_history.t
    118118t/56_diffs_with_macros.t
     119t/57_random_page.t
    119120t/61_bug_textareas.t
    120121t/62_bug_trailing_whitespace.t
  • trunk/lib/OpenGuides.pm

    r1008 r1014  
    329329        print $output;
    330330    }
     331}
     332
     333=item B<display_random_page>
     334
     335  $guide->display_random_page;
     336
     337Display a random page.  As with other methods, the
     338C<return_output> parameter can be used to return the output instead of
     339printing it to STDOUT.
     340
     341=cut
     342
     343sub display_random_page {
     344    my ( $self, %args ) = @_;
     345    my @nodes = $self->wiki->list_all_nodes();
     346    my $node = $nodes[ rand @nodes ];
     347    my $output = $self->redirect_to_node( $node );
     348    return $output if $args{return_output};
     349    print $output;
    331350}
    332351
  • trunk/wiki.cgi

    r991 r1014  
    8686                          );
    8787    } elsif ($action eq 'random') {
    88         my @nodes = $wiki->list_all_nodes();
    89         $node = $nodes[int(rand(scalar(@nodes) + 1)) + 1];
    90         print $guide->redirect_to_node($node);
     88        print $guide->display_random_page;
    9189    } elsif ($action eq 'find_within_distance') {
    9290        $guide->find_within_distance(
Note: See TracChangeset for help on using the changeset viewer.