2005-04-08 21:23:43 +00:00
|
|
|
# Copyright (C) 2004, 2005 Fletcher T. Penney <fletcher@freeshell.org>
|
2005-04-05 21:18:57 +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
|
2016-08-16 14:59:13 +02:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
2005-04-05 21:18:57 +00:00
|
|
|
# (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
|
2016-08-16 14:59:13 +02:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-04-05 21:18:57 +00:00
|
|
|
|
2015-03-28 16:11:03 +01:00
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2014-08-21 22:23:23 +02:00
|
|
|
AddModuleDescription('clustermap.pl', 'ClusterMap Module');
|
2005-04-05 21:18:57 +00:00
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
our ($q, %Action, %Page, $OpenPageName, @MyRules, @MyAdminCode, $HomePage, $DeletedPage, $RCName, $InterMap, $BannedContent, $BannedHosts, %AdminPages, $RssExclude, @AdminPages, $NearMap);
|
|
|
|
|
our ($ClusterMapPage, %ClusterMap, $ClusterMapTOC, $FilterUnclusteredRegExp, @ClusterMapAdminPages, $PrintTOCAnchor);
|
2005-04-05 21:18:57 +00:00
|
|
|
|
2015-03-28 16:11:03 +01:00
|
|
|
my %Unclustered = ();
|
|
|
|
|
|
2005-08-17 13:42:02 +00:00
|
|
|
$ClusterMapPage = "Site_Map" unless defined $ClusterMapPage;
|
2005-04-05 21:18:57 +00:00
|
|
|
|
2005-04-08 21:01:42 +00:00
|
|
|
# Don't list the following pages as unclustered
|
|
|
|
|
# By default, journal pages and Comment pages
|
|
|
|
|
$FilterUnclusteredRegExp = '\d\d\d\d-\d\d-\d\d|\d* *Comments on .*'
|
|
|
|
|
unless defined $FilterUnclusteredRegExp;
|
|
|
|
|
|
2005-04-21 16:17:18 +00:00
|
|
|
# The following pages are added to the AdminPage list and
|
|
|
|
|
# are not classified as unclustered.
|
|
|
|
|
# They are also added to the Important Pages list on the administration page
|
|
|
|
|
@ClusterMapAdminPages = ( $HomePage, $DeletedPage, $BannedContent,
|
2005-08-04 18:41:26 +00:00
|
|
|
$BannedHosts, $InterMap, $NearMap, $RCName, $RssExclude)
|
2015-03-27 03:01:01 +02:00
|
|
|
|
|
|
|
|
unless @ClusterMapAdminPages;
|
|
|
|
|
|
2005-04-05 21:18:57 +00:00
|
|
|
$ClusterMapTOC = 1 unless defined $ClusterMapTOC;
|
|
|
|
|
$PrintTOCAnchor = 0;
|
|
|
|
|
|
|
|
|
|
%ClusterMap = ();
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
*OldPrintRcHtml = \&PrintRcHtml;
|
|
|
|
|
*PrintRcHtml = \&ClusterMapPrintRcHtml;
|
2005-04-05 21:18:57 +00:00
|
|
|
|
|
|
|
|
push(@MyAdminCode, \&ClusterMapAdminRule);
|
|
|
|
|
|
|
|
|
|
$Action{clustermap} = \&DoClusterMap;
|
|
|
|
|
|
|
|
|
|
$Action{unclustered} = \&DoUnclustered;
|
|
|
|
|
|
|
|
|
|
push(@MyRules, \&ClusterMapRule);
|
|
|
|
|
|
2007-02-13 00:22:47 +00:00
|
|
|
foreach (@ClusterMapAdminPages){
|
|
|
|
|
$AdminPages{$_} = 1;
|
|
|
|
|
}
|
2005-04-21 16:17:18 +00:00
|
|
|
|
2005-04-05 21:18:57 +00:00
|
|
|
sub ClusterMapRule {
|
2015-08-23 21:22:12 +03:00
|
|
|
if (/\G^([\n\r]*\<\s*clustermap\s*\>\s*)$/cgm) {
|
2005-04-05 21:18:57 +00:00
|
|
|
Dirty($1);
|
|
|
|
|
my $oldpos = pos;
|
2015-03-27 03:01:01 +02:00
|
|
|
my $oldstr = $_;
|
2005-04-05 21:18:57 +00:00
|
|
|
CreateClusterMap();
|
|
|
|
|
print "</p>"; # Needed to clean up, but could cause problems
|
2005-04-21 16:17:18 +00:00
|
|
|
# if <clustermap> isn't put into a new paragraph
|
2005-04-05 21:18:57 +00:00
|
|
|
PrintClusterMap();
|
|
|
|
|
pos = $oldpos;
|
2005-08-17 13:42:02 +00:00
|
|
|
$oldstr =~ s/.*?\<\s*clustermap\s*\>//s;
|
2005-04-05 21:18:57 +00:00
|
|
|
$_ = $oldstr;
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2015-02-27 12:10:18 +02:00
|
|
|
return;
|
2005-04-05 21:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub DoClusterMap {
|
|
|
|
|
# Get list of all clusters
|
|
|
|
|
# For each cluster, get list of all pages in that cluster
|
|
|
|
|
# Create map, using body of cluster pages, followed by titles of pages
|
|
|
|
|
# within that cluster
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2005-04-05 21:18:57 +00:00
|
|
|
print GetHeader('',$ClusterMapPage,'');
|
|
|
|
|
|
|
|
|
|
CreateClusterMap();
|
|
|
|
|
if ($ClusterMapTOC) {
|
|
|
|
|
my $TOCCount = 0;
|
2007-03-11 04:17:05 +00:00
|
|
|
print '<div class="toc"><h2>Categories</h2><ol>';
|
2005-04-05 21:18:57 +00:00
|
|
|
foreach my $cluster ( sort keys %ClusterMap) {
|
2007-03-11 04:17:05 +00:00
|
|
|
$cluster =~ s/_/ /g;
|
2005-04-05 21:18:57 +00:00
|
|
|
print "<li><a href=\"#toc$TOCCount\">$cluster</a></li>";
|
|
|
|
|
$TOCCount++;
|
|
|
|
|
}
|
|
|
|
|
print '</ol></div>';
|
|
|
|
|
$PrintTOCAnchor = 1;
|
|
|
|
|
}
|
2015-03-27 03:01:01 +02:00
|
|
|
print '<div class="content">';
|
|
|
|
|
PrintClusterMap();
|
|
|
|
|
|
2005-04-05 21:18:57 +00:00
|
|
|
print '</div>';
|
|
|
|
|
PrintFooter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub DoUnclustered {
|
|
|
|
|
print GetHeader('','Pages without a Cluster','');
|
|
|
|
|
print '<div class="content">';
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2005-04-05 21:18:57 +00:00
|
|
|
CreateClusterMap();
|
|
|
|
|
PrintUnclusteredMap();
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2005-04-05 21:18:57 +00:00
|
|
|
print '</div>';
|
|
|
|
|
PrintFooter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub PrintClusterMap {
|
|
|
|
|
my $TOCCount = 0;
|
|
|
|
|
foreach my $cluster (sort keys %ClusterMap) {
|
|
|
|
|
local %Page;
|
|
|
|
|
local $OpenPageName='';
|
2005-08-19 23:46:32 +00:00
|
|
|
my $free = $cluster;
|
|
|
|
|
$free =~ s/_/ /g;
|
2005-04-05 21:18:57 +00:00
|
|
|
|
|
|
|
|
OpenPage($cluster);
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2005-08-19 23:46:32 +00:00
|
|
|
if ( FreeToNormal(GetCluster($Page{text})) eq $cluster ) {
|
2005-04-05 21:18:57 +00:00
|
|
|
# Don't display the page name twice if the cluster page is also
|
|
|
|
|
# a member of the cluster
|
2007-04-02 14:45:00 +00:00
|
|
|
$Page{text} =~ s/^\[*($cluster|$free)\]*\n*//s;
|
2005-04-05 21:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($PrintTOCAnchor) {
|
2005-08-19 23:46:32 +00:00
|
|
|
print $q->h1("<a id=\"toc$TOCCount\"></a>" . GetPageOrEditLink($free, $free));
|
2005-04-05 21:18:57 +00:00
|
|
|
$TOCCount++;
|
|
|
|
|
|
|
|
|
|
} else {
|
2005-08-19 23:46:32 +00:00
|
|
|
print $q->h1(GetPageOrEditLink($free, $free));
|
2005-04-05 21:18:57 +00:00
|
|
|
}
|
|
|
|
|
PrintWikiToHTML($Page{text}, 0);
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2005-04-05 21:18:57 +00:00
|
|
|
print "<ul>";
|
|
|
|
|
foreach my $page (sort keys %{$ClusterMap{$cluster}}) {
|
|
|
|
|
my $title = $page;
|
|
|
|
|
$title =~ s/_/ /g;
|
|
|
|
|
print "<li>" . ScriptLink($page, $title, 'local') . "</li>";
|
|
|
|
|
}
|
|
|
|
|
print "</ul>";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub CreateClusterMap {
|
|
|
|
|
my @pages = AllPagesList();
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2005-07-31 22:57:35 +00:00
|
|
|
local %Page;
|
|
|
|
|
local $OpenPageName='';
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2005-04-05 21:18:57 +00:00
|
|
|
foreach my $page ( @pages) {
|
|
|
|
|
OpenPage($page);
|
2005-08-19 23:11:44 +00:00
|
|
|
my $cluster = FreeToNormal(GetCluster($Page{text}));
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2005-04-21 16:17:18 +00:00
|
|
|
next if ($cluster eq $DeletedPage); # Don't map Deleted Pages
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2005-08-04 18:41:26 +00:00
|
|
|
next if (TextIsFile($Page{text})); # Don't map files
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2005-04-21 16:17:18 +00:00
|
|
|
if ($cluster eq "") { # Grab Unclustered Pages
|
2005-04-05 21:18:57 +00:00
|
|
|
$Unclustered{$page} = 1;
|
2005-04-21 16:17:18 +00:00
|
|
|
next;
|
|
|
|
|
}
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2005-08-19 23:46:32 +00:00
|
|
|
if ($cluster ne FreeToNormal($page)) { # Create Cluster Map
|
2005-04-21 16:17:18 +00:00
|
|
|
$ClusterMap{$cluster}{$page} = 1;
|
2005-04-05 21:18:57 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2005-04-21 16:17:18 +00:00
|
|
|
# Strip out Admin Pages
|
|
|
|
|
foreach my $page (@AdminPages) {
|
|
|
|
|
delete($Unclustered{$page});
|
|
|
|
|
}
|
2005-04-05 21:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-26 23:10:25 +03:00
|
|
|
sub ClusterMapPrintRcHtml {
|
2005-04-05 21:18:57 +00:00
|
|
|
my ( @options ) = @_;
|
2015-03-28 16:11:03 +01:00
|
|
|
my $cluster = GetParam('rcclusteronly');
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2005-04-05 21:18:57 +00:00
|
|
|
if ($cluster ne "") {
|
|
|
|
|
CreateClusterMap();
|
|
|
|
|
print "Pages in this cluster:";
|
|
|
|
|
print "<ul>";
|
2015-04-28 00:03:11 +03:00
|
|
|
foreach my $page (sort keys %{$ClusterMap{$cluster}}) {
|
2005-04-05 21:18:57 +00:00
|
|
|
my $title = $page;
|
|
|
|
|
$title =~ s/_/ /g;
|
|
|
|
|
print "<li>" . ScriptLink($page, $title, 'local') . "</li>";
|
|
|
|
|
}
|
|
|
|
|
print "</ul>";
|
|
|
|
|
}
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2014-09-26 23:10:25 +03:00
|
|
|
OldPrintRcHtml(@options);
|
2005-04-05 21:18:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub PrintUnclusteredMap {
|
|
|
|
|
print "<ul>";
|
2015-03-27 03:01:01 +02:00
|
|
|
foreach my $page (sort keys %Unclustered) {
|
2005-04-05 21:18:57 +00:00
|
|
|
my $title = $page;
|
|
|
|
|
$title =~ s/_/ /g;
|
2005-04-08 21:01:42 +00:00
|
|
|
if ($title !~ /^($FilterUnclusteredRegExp)$/) {
|
|
|
|
|
print "<li>" . ScriptLink($page, $title, 'local') . "</li>";
|
|
|
|
|
}
|
2005-04-05 21:18:57 +00:00
|
|
|
}
|
|
|
|
|
print "</ul>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub ClusterMapAdminRule {
|
2015-03-28 16:11:03 +01:00
|
|
|
my ($id, $menuref) = @_;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2006-08-06 11:46:12 +00:00
|
|
|
push(@$menuref, ScriptLink('action=clustermap', T('Clustermap'), 'clustermap'));
|
|
|
|
|
push(@$menuref, ScriptLink('action=unclustered', T('Pages without a Cluster'), 'unclustered'));
|
2005-07-31 22:57:35 +00:00
|
|
|
}
|
2005-08-17 13:42:02 +00:00
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
*OldBrowseResolvedPage = \&BrowseResolvedPage;
|
|
|
|
|
*BrowseResolvedPage = \&ClusterMapBrowseResolvedPage;
|
2005-08-17 13:42:02 +00:00
|
|
|
|
|
|
|
|
sub ClusterMapBrowseResolvedPage {
|
|
|
|
|
my $title = shift;
|
|
|
|
|
$title =~ s/_/ /g;
|
|
|
|
|
my $id = FreeToNormal($title);
|
|
|
|
|
if ($id eq $ClusterMapPage) {
|
|
|
|
|
CreateClusterMap();
|
|
|
|
|
print GetHeader('',$title,'');
|
2015-03-27 03:01:01 +02:00
|
|
|
print '<div class="content">';
|
2007-02-13 00:35:07 +00:00
|
|
|
if ($ClusterMapTOC) {
|
|
|
|
|
my $TOCCount = 0;
|
2007-03-11 04:17:05 +00:00
|
|
|
print '<div class="toc"><h2>Categories</h2><ol>';
|
2007-02-13 00:35:07 +00:00
|
|
|
foreach my $cluster ( sort keys %ClusterMap) {
|
2007-03-11 04:17:05 +00:00
|
|
|
$cluster =~ s/_/ /g;
|
2007-02-13 00:35:07 +00:00
|
|
|
print "<li><a href=\"#toc$TOCCount\">$cluster</a></li>";
|
|
|
|
|
$TOCCount++;
|
|
|
|
|
}
|
|
|
|
|
print '</ol></div>';
|
|
|
|
|
$PrintTOCAnchor = 1;
|
2005-10-13 14:01:22 +00:00
|
|
|
}
|
2005-08-17 13:42:02 +00:00
|
|
|
PrintClusterMap();
|
2015-03-27 03:01:01 +02:00
|
|
|
print '</div>';
|
2005-08-17 13:42:02 +00:00
|
|
|
PrintFooter();
|
|
|
|
|
} else {
|
|
|
|
|
OldBrowseResolvedPage($id);
|
|
|
|
|
}
|
2005-08-19 23:11:44 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
*OldPrintWikiToHTML = \&PrintWikiToHTML;
|
|
|
|
|
*PrintWikiToHTML = \&ClusterMapPrintWikiToHTML;
|
2005-08-19 23:11:44 +00:00
|
|
|
|
|
|
|
|
sub ClusterMapPrintWikiToHTML {
|
|
|
|
|
my ($pageText, $savecache, $revision, $islocked) = @_;
|
|
|
|
|
|
|
|
|
|
# Cause an empty page with the name $ClusterMapPage to
|
|
|
|
|
# display a map.
|
|
|
|
|
if (($ClusterMapPage eq $OpenPageName)
|
|
|
|
|
&& ($pageText =~ /^\s*$/s)){
|
|
|
|
|
SetParam('rcclusteronly',0);
|
|
|
|
|
CreateClusterMap();
|
2015-03-27 03:01:01 +02:00
|
|
|
print '<div class="content">';
|
2007-02-13 00:35:07 +00:00
|
|
|
if ($ClusterMapTOC) {
|
|
|
|
|
my $TOCCount = 0;
|
|
|
|
|
print '<div class="toc"><h2>Contents</h2><ol>';
|
|
|
|
|
foreach my $cluster ( sort keys %ClusterMap) {
|
|
|
|
|
print "<li><a href=\"#toc$TOCCount\">$cluster</a></li>";
|
|
|
|
|
$TOCCount++;
|
|
|
|
|
}
|
|
|
|
|
print '</ol></div>';
|
|
|
|
|
$PrintTOCAnchor = 1;
|
2005-10-13 14:09:40 +00:00
|
|
|
}
|
2005-08-19 23:11:44 +00:00
|
|
|
PrintClusterMap();
|
2015-03-27 03:01:01 +02:00
|
|
|
print '</div>';
|
2005-08-19 23:11:44 +00:00
|
|
|
}
|
|
|
|
|
OldPrintWikiToHTML(@_);
|
|
|
|
|
}
|