2005-01-06 16:34:44 +00:00
|
|
|
# Copyright (C) 2004, 2005 Alex Schroeder <alex@emacswiki.org>
|
2004-01-30 21:35:44 +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
|
2004-01-30 21:35:44 +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/>.
|
2004-01-30 21:35:44 +00:00
|
|
|
|
2015-03-27 03:01:01 +02:00
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
|
|
|
|
AddModuleDescription('page-type.pl', 'Page Type Extension');
|
|
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
our ($q, %AdminPages, @MyInitVariables, $LinkPattern, $FreeLinks, $FreeLinkPattern, $WikiLinks);
|
|
|
|
|
our ($PageTypesName);
|
2004-01-30 11:53:18 +00:00
|
|
|
|
|
|
|
|
# You need to define the available types on the following page.
|
|
|
|
|
|
|
|
|
|
$PageTypesName = 'PageTypes';
|
|
|
|
|
|
2005-01-06 16:34:44 +00:00
|
|
|
# do this later so that the user can customize $SidebarName
|
|
|
|
|
push(@MyInitVariables, \&PageTypeInit);
|
|
|
|
|
|
|
|
|
|
sub PageTypeInit {
|
|
|
|
|
$PageTypesName = FreeToNormal($PageTypesName); # spaces to underscores
|
2006-07-15 23:13:37 +00:00
|
|
|
$AdminPages{$PageTypesName} = 1; # mod_perl!
|
2005-01-06 16:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
2004-01-30 11:53:18 +00:00
|
|
|
# A page type has to appear as a bullet list item on the page.
|
|
|
|
|
#
|
|
|
|
|
# Example list defining three types:
|
|
|
|
|
#
|
|
|
|
|
# * foo
|
|
|
|
|
# * bar
|
|
|
|
|
# * quux baz
|
|
|
|
|
|
|
|
|
|
# The page type will be prepended to the beginning of a page. If you
|
|
|
|
|
# have page clustering enabled (see the manual), then the page type
|
|
|
|
|
# will automatically act as a cluster.
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
*OldPageTypeDoPost = \&DoPost;
|
|
|
|
|
*DoPost = \&NewPageTypeDoPost;
|
2004-01-30 11:53:18 +00:00
|
|
|
|
|
|
|
|
sub NewPageTypeDoPost {
|
|
|
|
|
my $id = shift;
|
|
|
|
|
my $type = GetParam('types', '');
|
|
|
|
|
if ($type and $type ne T('None')) {
|
|
|
|
|
$type = "[[$type]]" unless $WikiLinks and $type =~ /^$LinkPattern$/;
|
|
|
|
|
my $text = $type . "\n\n" . GetParam('text','');
|
2005-12-18 20:25:41 +00:00
|
|
|
# We can't use SetParam(), because we're trying to override a
|
|
|
|
|
# parameter used by the script. GetParam prefers the actual
|
|
|
|
|
# script parameters to parameters set by the cookie (which is what
|
|
|
|
|
# SetParam manipulates). We also need to unquote, because
|
|
|
|
|
# GetParam automatically unquotes.
|
|
|
|
|
$q->param(-name=>'text', -value=>UnquoteHtml($text));
|
2004-01-30 11:53:18 +00:00
|
|
|
}
|
|
|
|
|
OldPageTypeDoPost($id);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
*OldPageTypeGetTextArea = \&GetTextArea;
|
|
|
|
|
*GetTextArea = \&NewPageTypeGetTextArea;
|
2004-01-30 11:53:18 +00:00
|
|
|
|
|
|
|
|
sub NewPageTypeGetTextArea {
|
|
|
|
|
my ($name, $text) = @_;
|
|
|
|
|
return OldPageTypeGetTextArea(@_) if ($name ne 'text'); # comment box!
|
|
|
|
|
my @types = (T('None'),);
|
|
|
|
|
# read categories
|
|
|
|
|
foreach (split ('\n', GetPageContent($PageTypesName))) {
|
|
|
|
|
if ($WikiLinks and (m/^\*[ \t]($LinkPattern)/)) {
|
|
|
|
|
push (@types, $1);
|
|
|
|
|
} elsif ($FreeLinks and (m/^\*[ \t]\[\[($FreeLinkPattern)\]\]/)) {
|
|
|
|
|
push (@types, $1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
my $cluster;
|
|
|
|
|
# This duplicates GetCluster code so that this works even when
|
|
|
|
|
# $PageCluster==0.
|
|
|
|
|
$cluster = $1 if ($WikiLinks && $text =~ /^$LinkPattern\n/)
|
|
|
|
|
or ($FreeLinks && $text =~ /^\[\[$FreeLinkPattern\]\]\n/);
|
|
|
|
|
if (grep(/^$cluster$/, @types)) {
|
|
|
|
|
$text =~ s/^.*\n+//; # delete cluster line, and clean up further empty lines
|
|
|
|
|
} else {
|
|
|
|
|
$cluster = T('None');
|
|
|
|
|
}
|
|
|
|
|
#build the new input
|
|
|
|
|
my $html = OldPageTypeGetTextArea($name, $text);
|
|
|
|
|
my $list = T('Type') . ': <select name="types">';
|
|
|
|
|
foreach my $type (@types) {
|
|
|
|
|
if ($type eq $cluster) {
|
|
|
|
|
$list .= "<option value=\"$type\" selected>$type";
|
|
|
|
|
} else {
|
|
|
|
|
$list .= "<option value=\"$type\">$type";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$list .= "</select>";
|
|
|
|
|
$html .= $q->p($list);
|
|
|
|
|
return $html;
|
|
|
|
|
}
|