use strict; BEGIN { push @INC, "/nfs/pdx/disks/nhm.arch.futwiki.1/twiki/lib"; } use TWiki; use TWiki::Render; { package Runt_TWiki_Session; use TWiki; @Runt_TWiki_Session::ISA = "TWiki"; sub new { my $class = shift; #my $twiki_session = TWiki::new("", ""); my $twiki_session = {}; $twiki_session->{plugins} = new TWiki::Plugins( $twiki_session ); $twiki_session->{prefs} = new TWiki::Prefs( $twiki_session ); $twiki_session->{prefs}->{PREFS} = []; $twiki_session->{client} = new Runt_Client; bless $twiki_session, $class; return $twiki_session; } 1; } { package My_TWiki_Renderer; use TWiki::Render; @My_TWiki_Renderer::ISA = "TWiki::Render"; sub new { my $class = shift; my $this = {}; bless $this, $class; $this->{session} = new Runt_TWiki_Session; $this->{wiki_link_list} = new Wiki_Link_List; return $this; } sub render_text_extracting_links { my $this = shift; my ($text,$web,$topic) = @_; $this->{current_web} = $web; $this->{current_topic} = $topic; # Call TWiki::Renderer::getRenderedVersion $this->getRenderedVersion($text,$web,$topic); delete $this->{current_topic}; delete $this->{current_web}; } sub _renderWikiWord { my ($this, $theWeb, $theTopic, $theLinkText, $theAnchor, $doLinkToMissingPages, $doKeepWeb) = @_; #print "calling _renderWikiWord(-,'$theWeb','$theTopic','$theLinkText','$theAnchor',...)\n"; # filter out links known to be bogus # TBD - why is TWiki reporting these to me? return if( $theTopic =~ m/^[A-Z0-9]*$/ ); # Track link $this->{wiki_link_list}->add(web=>$theWeb,topic=>$theTopic,anchor=>$theAnchor, in_current_web=>($this->{current_web} eq $theWeb), ); } 1; } { package Wiki_Link_List; sub new { my $class = shift; my $this = {}; $this->{m_wiki_link_list} = []; bless $this, $class; return $this; } sub add { my $this = shift; my %link_item = @_; die "Wiki_Link_List::add(...) expected keys web and topic, got ", join(' ',%link_item), "\n" if( !exists $link_item{web} || !exists $link_item{topic} ); my $wll = $this->{m_wiki_link_list}; push @$wll,\%link_item; } sub sorted_list_of_wiki_link_paths_helper { my $this = shift; my %opts = @_; my %refd = (); foreach my $li ( @{$this->{m_wiki_link_list}} ) { my $fullpath; if( $opts{full_web_path} ) { if( $li->{web} eq "" ) { # special case for blank web # TBD: special case for blank theTopic? } else { $fullpath = "$li->{web}/"; } } elsif( $opts{elide_current_web_path} ) { if( !$li->{in_current_web} ) { $fullpath = "$li->{web}/"; } } else { # no prepending of path? } $fullpath .= "$li->{topic}"; # TBD: create a version that includes anchors? { # Change from /-path notation to Wiki's dot notation $fullpath =~ s|/|.|g; } $refd{$fullpath}++; } return sort keys %refd; } sub sorted_list_of_full_web_paths { my $this = shift; return $this->sorted_list_of_wiki_link_paths_helper(full_web_path=>1); } sub sorted_list_of_web_paths_eliding_current_web_path { my $this = shift; return $this->sorted_list_of_wiki_link_paths_helper(elide_current_web_path=>1); } # TBD short, with web path only if specified # TBD w/wo anchors } { package Runt_Client; use TWiki::Client; @My_TWiki_Renderer::ISA = "TWiki::Render"; sub new { my $class = shift; my $this = {}; bless $this, $class; return $this; } sub endRenderingHandler {} 1; } sub test { my $renderer = new My_TWiki_Renderer; $renderer->getRenderedVersion("Here is text with a WikiWord in it.","theWeb","theTopic"); }