#!/usr/bin/perl # TmNetWiki version 0.4 (September 11, 2002) # Copyright (C) 2002 Adam Brate # # Based on the GPLed UseModWiki 0.92 # Copyright (C) 2000-2001 Clifford A. Adams # or # Based on the GPLed AtisWiki 0.3 (C) 1998 Markus Denker # # ...which was based on # the LGPLed CVWiki CVS-patches (C) 1997 Peter Merel # and The Original WikiWikiWeb (C) Ward Cunningham # (code reused with permission) # Email and ThinLine options by Jim Mahoney # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the # Free Software Foundation, Inc. # 59 Temple Place, Suite 330 # Boston, MA 02111-1307 USA package Wiki::browse; use strict; # needs subs Wiki::page: GetPageFile, OpenPage # Wiki::utility: FreeToNormal, GetParam, QuoteHtml # Wiki::error: ValidIdOrDie, # Wiki::history: DoHistory, # Wiki::text: OpenDefaultText, # Wiki::keep: OpenKeptRevisions, OpenKeptRevision, # Wiki::template: GetHeader, GetFooterText, # Wiki::wiki: WikiToHtml, # Wiki::translate: Ts, T # Wiki::cache: UpdateHtmlCache, GetRedirectPage # Wiki::rc: DoRc GetRc # Wiki::index: AllPagesList # Wiki::diff: GetDiffHTML # Wiki::user: UserCanEdit # Wiki::users: GetUsers # needs consts $HomePage, $FreeLinks, $NotFoundPg, $RCName, $EmbedWiki, # $UseCache # needs vars %Text, %KeptRevisions use base 'Exporter'; use Wiki::consts; use Wiki::page; use Wiki::utility; use Wiki::error; use Wiki::history; use Wiki::text; use Wiki::keep; use Wiki::template; use Wiki::wiki; use Wiki::translate; use Wiki::cache; use Wiki::rc; use Wiki::index; use Wiki::diff; use Wiki::user; use Wiki::users; #if ($^V and $^V gt v5.6.0) { # our @EXPORT; #else { use vars qw(@EXPORT); #} @EXPORT = qw( DoBrowseRequest ReBrowsePage ); sub BrowsePage; sub ReBrowsePage; sub DoRandom; sub DoBrowseRequest { my ($id, $action, $text); if (!$q->param) { # No parameter &BrowsePage($Consts->{HomePage}); return 1; } $id = &GetParam('keywords', ''); if ($id) { # Just script?PageName if ($Consts->{FreeLinks} && (!-f &GetPageFile($id))) { $id = &FreeToNormal($id); } if (($Consts->{NotFoundPg} ne '') && (!-f &GetPageFile($id))) { $id = $Consts->{NotFoundPg}; } &BrowsePage($id) if &ValidIdOrDie($id); return 1; } $action = lc(&GetParam('action', '')); $id = &GetParam('id', ''); if ($action eq 'browse') { if ($Consts->{FreeLinks} && (!-f &GetPageFile($id))) { $id = &FreeToNormal($id); } if (($Consts->{NotFoundPg} ne '') && (!-f &GetPageFile($id))) { $id = $Consts->{NotFoundPg}; } &BrowsePage($id) if &ValidIdOrDie($id); return 1; } elsif ($action eq 'rc') { &BrowsePage($Consts->{RCName}); return 1; } elsif ($action eq 'random') { &DoRandom(); return 1; } elsif ($action eq 'history') { &DoHistory($id) if &ValidIdOrDie($id); return 1; } return 0; # Request not handled } sub BrowsePage { my ($id) = @_; my ($fullHtml, $oldId, $allDiff, $showDiff, $openKept); my ($header,$revisionText,$body,$rcText,$footer); my ($revision, $goodRevision, $diffRevision, $newText); my ($page,$textpage,$section,$keptRevisions); $page = &OpenPage($id); $textpage = &OpenDefaultText(); $newText = $textpage->{text}->{'text'}; # For differences $openKept = 0; $revision = &GetParam('revision', ''); $revision =~ s/\D//g; # Remove non-numeric chars $goodRevision = $revision; # Non-blank only if exists if ($revision ne '') { $keptRevisions = &OpenKeptRevisions('text_default'); $openKept = 1; if (!defined($keptRevisions->{$revision})) { $goodRevision = ''; } else { $textpage = &OpenKeptRevision($revision); } } # Handle a single-level redirect $oldId = &GetParam('oldid', ''); if (($oldId eq '') && (&IsRedirect($id))) { $oldId = $id; $id = &IsRedirect($id); # IsRedirect returns the redirected id if (&ValidId($id) eq '') { # Later consider revision in rebrowse? &ReBrowsePage($id, $oldId, 0); return; } else { # Not a valid target, so continue as normal page $id = $oldId; $oldId = ''; } } $MainPage = $id; $MainPage =~ s|/.*||; # Only the main page name (remove subpage) $header = &GetHeader($id, &QuoteHtml($id), $oldId,$goodRevision); if ($revision ne '') { # Later maybe add edit time? if ($goodRevision ne '') { $revisionText = '' . Ts('Showing revision %s', $revision) . "
"; } else { $revisionText = '' . Ts('Revision %s not available', $revision) . ' (' . T('showing current revision instead') . ')
'; } } $allDiff = &GetParam('alldiff', 0); if ($allDiff != 0) { $allDiff = &GetParam('defaultdiff', 1); } if (&IsSamePage($id,$Consts->{RCname}) && &GetParam('norcdiff', 1)) { $allDiff = 0; # Only show if specifically requested } $showDiff = &GetParam('diff', $allDiff); if ($Consts->{UseDiff} && $showDiff) { $diffRevision = $goodRevision; $diffRevision = &GetParam('diffrevision', $diffRevision); # Later try to avoid the following keep-loading if possible? $keptRevisions = &OpenKeptRevisions('text_default') if (!$openKept); # GetDiffHTML requires the %KeptRevisions to be opened. $body .= &GetDiffHTML($showDiff, $id, $diffRevision, $newText); } $body .= &WikiToHTML($textpage->{text}->{'text'},&PageIsLocked($id)); #only do SpecialMarkup if page is locked if (&IsSamePage($id,$Consts->{RCName})) { $rcText = &GetRc(); $footer = "
\n" if (!&GetParam('embed', $Consts->{EmbedWiki})); } elsif (&IsSamePage($id,$Consts->{UsersName})) { $rcText = &GetAuthors(); $footer = "
\n" if (!&GetParam('embed', $Consts->{EmbedWiki})); } elsif (&IsChildPage($id,$Consts->{UsersName})) { # is a user page (my $uname = $id) =~ s|$Consts->{UsersName}/||; $rcText = &GetRc({rcuseronly => $uname}); $footer = "
\n" if (!&GetParam('embed', $Consts->{EmbedWiki})); } else { # if (&UserCanEdit()) { # $fullHtml .= "
\n" if (!&GetParam('embed', $Consts->{EmbedWiki})); } $footer .= &GetFooterText($id, $goodRevision); $fullHtml = &GetTemplate('page',{ id => $id, Consts => $Consts, header => $header, revisionText => $revisionText, body => $body, rcText => $rcText, footer => $footer }); print $fullHtml; return if ($showDiff || ($revision ne '') || &IsSamePage($id,$Consts->{RCName})); # Don't cache special version or Recent Changes page &UpdateHtmlCache($id, $fullHtml) if $UseCache; } sub ReBrowsePage { my ($id, $oldId, $isEdit) = @_; if ($oldId ne "") { # Target of #REDIRECT (loop breaking) print &GetRedirectPage("action=browse&id=$id&oldid=$oldId", $id, $isEdit); } else { print &GetRedirectPage($id, $id, $isEdit); } } sub DoRandom { my ($id, @pageList); @pageList = &AllPagesList(); # Optimize? $id = $pageList[int(rand($#pageList + 1))]; &ReBrowsePage($id, "", 0); } 1;