2005-01-06 11:35:04 +00:00
|
|
|
# Copyright (C) 2004, 2005 Alex Schroeder <alex@emacswiki.org>
|
2004-04-05 00:37:55 +00:00
|
|
|
#
|
|
|
|
|
# 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
|
|
|
|
|
|
2005-11-07 00:46:15 +00:00
|
|
|
$ModulesDescription .= '<p>$Id: namespaces.pl,v 1.23 2005/11/07 00:46:15 as Exp $</p>';
|
2004-12-21 16:32:33 +00:00
|
|
|
|
|
|
|
|
use vars qw($NamespacesMain $NamespacesSelf $NamespaceCurrent $NamespaceRoot);
|
|
|
|
|
|
|
|
|
|
$NamespacesMain = 'Main'; # to get back to the main namespace
|
|
|
|
|
$NamespacesSelf = 'Self'; # for your own namespace
|
|
|
|
|
$NamespaceCurrent = ''; # will be automatically set to the current namespace, if any
|
|
|
|
|
$NamespaceRoot = ''; # will be automatically set to the original $ScriptName
|
2004-04-05 00:37:55 +00:00
|
|
|
|
2004-04-05 18:02:00 +00:00
|
|
|
my $NamespacesInit = 0;
|
2004-04-05 00:37:55 +00:00
|
|
|
|
2005-10-28 08:06:11 +00:00
|
|
|
# try to do it before any other module starts meddling with the
|
|
|
|
|
# variables (eg. localnames.pl)
|
|
|
|
|
unshift(@MyInitVariables, \&NamespacesInitVariables);
|
2004-04-05 00:37:55 +00:00
|
|
|
|
2005-01-04 09:40:01 +00:00
|
|
|
sub NamespacesInitVariables {
|
2005-10-27 21:58:49 +00:00
|
|
|
my %site = ();
|
2004-04-06 22:18:41 +00:00
|
|
|
# Do this before changing the $DataDir and $ScriptName
|
2005-10-27 21:58:49 +00:00
|
|
|
if (!$Monolithic and $UsePathInfo) {
|
|
|
|
|
$site{$NamespacesMain} = $ScriptName . '/';
|
2004-04-06 22:18:41 +00:00
|
|
|
foreach my $name (glob("$DataDir/*")) {
|
2004-12-21 16:32:33 +00:00
|
|
|
if (-d $name
|
|
|
|
|
and $name =~ m|/($InterSitePattern)$|
|
|
|
|
|
and $name ne $NamespacesMain
|
|
|
|
|
and $name ne $NamespacesSelf) {
|
2005-10-27 21:58:49 +00:00
|
|
|
$site{$1} = $ScriptName . '/' . $1 . '/';
|
2004-04-06 22:18:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-12-20 05:43:37 +00:00
|
|
|
$NamespaceCurrent = '';
|
2005-10-27 21:58:49 +00:00
|
|
|
if (($UsePathInfo
|
2004-12-20 04:35:06 +00:00
|
|
|
# make sure ordinary page names are not matched!
|
|
|
|
|
and $q->path_info() =~ m|^/($InterSitePattern)(/.*)?|
|
|
|
|
|
and ($2 or $q->param or $q->keywords)
|
2004-12-21 16:32:33 +00:00
|
|
|
and ($1 ne $NamespacesMain)
|
|
|
|
|
and ($1 ne $NamespacesSelf))
|
2004-12-20 04:35:06 +00:00
|
|
|
or
|
|
|
|
|
(GetParam('ns', '') =~ m/^($InterSitePattern)$/
|
2004-12-21 16:32:33 +00:00
|
|
|
and ($1 ne $NamespacesMain)
|
|
|
|
|
and ($1 ne $NamespacesSelf))) {
|
2004-12-20 05:43:37 +00:00
|
|
|
$NamespaceCurrent = $1;
|
2004-04-05 00:37:55 +00:00
|
|
|
# Change some stuff from the original InitVariables call:
|
2004-12-20 04:35:06 +00:00
|
|
|
$SiteName .= ' ' . $NamespaceCurrent;
|
2005-03-24 22:49:30 +00:00
|
|
|
$InterWikiMoniker = $NamespaceCurrent;
|
2004-12-20 04:35:06 +00:00
|
|
|
$DataDir .= '/' . $NamespaceCurrent;
|
2004-04-05 00:37:55 +00:00
|
|
|
$PageDir = "$DataDir/page";
|
|
|
|
|
$KeepDir = "$DataDir/keep";
|
|
|
|
|
$RefererDir = "$DataDir/referer";
|
|
|
|
|
$TempDir = "$DataDir/temp";
|
|
|
|
|
$LockDir = "$TempDir/lock";
|
|
|
|
|
$NoEditFile = "$DataDir/noedit";
|
|
|
|
|
$RcFile = "$DataDir/rc.log";
|
|
|
|
|
$RcOldFile = "$DataDir/oldrc.log";
|
|
|
|
|
$IndexFile = "$DataDir/pageidx";
|
|
|
|
|
$VisitorFile = "$DataDir/visitors.log";
|
|
|
|
|
$PermanentAnchorsFile = "$DataDir/permanentanchors";
|
|
|
|
|
# $ConfigFile -- shared
|
|
|
|
|
# $ModuleDir -- shared
|
|
|
|
|
# $NearDir -- shared
|
2004-12-20 04:35:06 +00:00
|
|
|
$NamespaceRoot = $ScriptName;
|
|
|
|
|
$ScriptName .= '/' . $NamespaceCurrent;
|
|
|
|
|
$FullUrl .= '/' . $NamespaceCurrent;
|
|
|
|
|
$WikiDescription .= "<p>Current namespace: $NamespaceCurrent</p>";
|
2004-04-05 00:37:55 +00:00
|
|
|
# override LastUpdate
|
|
|
|
|
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks)
|
|
|
|
|
= stat($IndexFile);
|
|
|
|
|
$LastUpdate = $mtime;
|
|
|
|
|
CreateDir($DataDir); # Create directory if it doesn't exist
|
|
|
|
|
ReportError(Ts('Could not create %s', $DataDir) . ": $!", '500 INTERNAL SERVER ERROR')
|
|
|
|
|
unless -d $DataDir;
|
2004-12-20 05:43:37 +00:00
|
|
|
}
|
2005-10-27 21:58:49 +00:00
|
|
|
$site{$NamespacesSelf} = $ScriptName . '?';
|
|
|
|
|
# reinitialize
|
|
|
|
|
ReInit();
|
|
|
|
|
AllPagesList();
|
|
|
|
|
NearInit();
|
|
|
|
|
PermanentAnchorsInit() if $PermanentAnchors;
|
|
|
|
|
# transfer list of sites
|
|
|
|
|
foreach my $key (keys %site) {
|
|
|
|
|
$InterSite{$key} = $site{$key} unless $InterSite{$key};
|
|
|
|
|
}
|
2004-12-20 05:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*OldNamespaceDoRc = *DoRc;
|
|
|
|
|
*DoRc = *NewNamespaceDoRc;
|
|
|
|
|
|
2005-04-25 21:14:52 +00:00
|
|
|
sub NewNamespaceDoRc { # Copy of DoRc
|
|
|
|
|
my $GetRC = shift;
|
|
|
|
|
my $showHTML = $GetRC eq \&GetRcHtml; # optimized for HTML
|
|
|
|
|
my $starttime = 0;
|
|
|
|
|
if (GetParam('from', 0)) {
|
|
|
|
|
$starttime = GetParam('from', 0);
|
|
|
|
|
} else {
|
|
|
|
|
$starttime = $Now - GetParam('days', $RcDefault) * 86400; # 24*60*60
|
|
|
|
|
}
|
|
|
|
|
# get the list of rc.log and oldrc.log files we need. rcoldfiles is
|
|
|
|
|
# a mapping from rcfiles to rcoldfiles.
|
|
|
|
|
my @rcfiles = ();
|
|
|
|
|
my %rcoldfiles = ();
|
|
|
|
|
my %namespaces = ();
|
2005-04-26 07:44:30 +00:00
|
|
|
if ($NamespaceCurrent or GetParam('local', 0)) {
|
2005-04-25 21:14:52 +00:00
|
|
|
push(@rcfiles, $RcFile);
|
|
|
|
|
$rcoldfiles{$RcFile} = $RcOldFile;
|
2004-12-20 04:35:06 +00:00
|
|
|
} else {
|
2005-04-25 21:14:52 +00:00
|
|
|
push(@rcfiles, $RcFile);
|
|
|
|
|
$rcoldfiles{$RcFile} = $RcOldFile;
|
|
|
|
|
# get the namespaces from the intermap instead of parsing the
|
|
|
|
|
# directory. this reduces the chances of getting different
|
|
|
|
|
# results.
|
|
|
|
|
foreach my $site (keys %InterSite) {
|
|
|
|
|
if ($InterSite{$site} =~ m|^$ScriptName/([^/]*)|) {
|
|
|
|
|
my $ns = $1 or next;
|
|
|
|
|
my $file = "$DataDir/$ns/rc.log";
|
|
|
|
|
push(@rcfiles, $file);
|
|
|
|
|
$namespaces{$file} = $ns;
|
|
|
|
|
$rcoldfiles{$file} = "$DataDir/$ns/oldrc.log";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-04-25 23:02:08 +00:00
|
|
|
# start printing header
|
|
|
|
|
RcHeader() if $showHTML;
|
2005-04-25 21:14:52 +00:00
|
|
|
# now need them line by line, trying to conserve ram instead of
|
|
|
|
|
# optimizing for speed (and slurping them all in). when opening a
|
|
|
|
|
# rcfile, compare the first timestamp with the starttime. if any
|
|
|
|
|
# rcfile exists with no timestamp before the starttime, we need to
|
|
|
|
|
# open its rcoldfile.
|
|
|
|
|
@lines = ();
|
|
|
|
|
foreach my $file (@rcfiles) {
|
|
|
|
|
my ($ts, @new) = NamespaceRcLines($file, $starttime, $namespaces{$file});
|
|
|
|
|
push(@lines, @new);
|
|
|
|
|
if (not $ts or $starttime <= $ts) {
|
|
|
|
|
($ts, @new) = NamespaceRcLines($rcoldfiles{$file}, $starttime, $namespaces{$file});
|
|
|
|
|
push(@lines, @new);
|
2004-12-20 05:43:37 +00:00
|
|
|
}
|
2004-04-05 00:37:55 +00:00
|
|
|
}
|
2005-04-25 23:02:08 +00:00
|
|
|
# We need to resort these lines... <=> forces numerical comparison
|
|
|
|
|
# which is just what we need here, as the timestamp is the first
|
|
|
|
|
# part of the line.
|
|
|
|
|
@lines = sort { $a <=> $b } @lines;
|
|
|
|
|
# end, printing
|
|
|
|
|
local *ValidId = *NamespaceValidId;
|
2005-04-26 07:44:30 +00:00
|
|
|
if (not @lines and $showHTML) {
|
2005-04-25 21:14:52 +00:00
|
|
|
print $q->p($q->strong(Ts('No updates since %s', TimeToText($starttime))));
|
|
|
|
|
} else {
|
|
|
|
|
print &$GetRC(@lines);
|
|
|
|
|
}
|
|
|
|
|
print GetFilterForm() if $showHTML;
|
2004-04-05 00:37:55 +00:00
|
|
|
}
|
2004-12-20 04:35:06 +00:00
|
|
|
|
2005-04-25 21:14:52 +00:00
|
|
|
sub NamespaceRcLines {
|
|
|
|
|
my ($file, $starttime, $ns) = @_;
|
|
|
|
|
open(F,$file) or return (0, ());
|
|
|
|
|
my $line = <F> or return (0, ());
|
2005-06-02 07:43:02 +00:00
|
|
|
chomp($line);
|
2005-06-29 15:58:40 +00:00
|
|
|
my ($ts, $pagename, $minor, $summary, $host, $username, $rest) = split(/$FS/, $line);
|
2005-04-25 21:14:52 +00:00
|
|
|
my $first = $ts;
|
|
|
|
|
my @result = ();
|
|
|
|
|
while ($ts) {
|
2005-04-25 23:02:08 +00:00
|
|
|
# here we add the namespace to the pagename and username, but this
|
|
|
|
|
# will never work, we need to fix this later in ScriptLink!
|
|
|
|
|
push(@result, join($FS, $ts, ($ns ? ($ns . '/' . $pagename) : $pagename), $minor, $summary, $host,
|
2005-06-29 15:58:40 +00:00
|
|
|
($ns && $username ? ($ns . '/' . $username) : $username), $rest))
|
2005-04-25 23:02:08 +00:00
|
|
|
if $ts >= $starttime;
|
2005-04-25 21:14:52 +00:00
|
|
|
$line = <F> or last;
|
2005-06-29 15:58:40 +00:00
|
|
|
chomp($line);
|
2005-04-25 23:02:08 +00:00
|
|
|
($ts, $pagename, $minor, $summary, $host, $username, $rest) = split(/$FS/, $line);
|
2005-04-25 21:14:52 +00:00
|
|
|
}
|
|
|
|
|
return ($first, @result);
|
2004-12-20 04:35:06 +00:00
|
|
|
}
|
|
|
|
|
|
2005-04-25 21:14:52 +00:00
|
|
|
*OldNamespaceScriptLink = *ScriptLink;
|
|
|
|
|
*ScriptLink = *NewNamespaceScriptLink;
|
|
|
|
|
|
|
|
|
|
sub NewNamespaceScriptLink {
|
|
|
|
|
my ($action, @rest) = @_;
|
|
|
|
|
local $ScriptName = $ScriptName;
|
2005-11-07 00:46:15 +00:00
|
|
|
if ($action =~ /^($UrlProtocols)\%3a/) { # URL-encoded URL
|
2005-10-28 14:46:30 +00:00
|
|
|
# do nothing
|
|
|
|
|
} elsif ($action !~ /=/ and $action =~ /(.*?)%2f(.*)/) {
|
2005-04-25 21:14:52 +00:00
|
|
|
$ScriptName .= "/$1";
|
|
|
|
|
$action = $2;
|
|
|
|
|
} elsif ($action =~ /(.*=)(.*?)%2f(.*)/) {
|
|
|
|
|
$ScriptName .= '/' . $2;
|
|
|
|
|
$action = $1 . $3;
|
2004-12-20 04:35:06 +00:00
|
|
|
}
|
2005-04-25 21:14:52 +00:00
|
|
|
return OldNamespaceScriptLink($action, @rest);
|
2004-12-20 04:35:06 +00:00
|
|
|
}
|
2005-04-25 23:02:08 +00:00
|
|
|
|
|
|
|
|
sub NamespaceValidId {
|
|
|
|
|
# don't do this test when printing recent changes because of the
|
|
|
|
|
# spliced in slash -- return nothing.
|
|
|
|
|
}
|