2015-07-28 22:44:53 +02:00
|
|
|
|
# Copyright (C) 2004–2015 Alex Schroeder <alex@gnu.org>
|
2004-02-09 20:51:40 +00:00
|
|
|
|
#
|
2009-12-06 19:26:33 +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 3 of the License, or (at your option) any later
|
|
|
|
|
|
# version.
|
2004-02-09 20:51:40 +00:00
|
|
|
|
#
|
2009-12-06 19:26:33 +00:00
|
|
|
|
# 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.
|
2004-02-09 20:51:40 +00:00
|
|
|
|
#
|
2009-12-06 19:26:33 +00:00
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-02-09 20:51:40 +00:00
|
|
|
|
|
2015-03-28 14:55:25 +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('anchors.pl', 'Local Anchor Extension');
|
2004-02-09 20:51:40 +00:00
|
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
|
our ($q, %Page, $FootnoteNumber, $FreeLinkPattern, @MyRules, $BracketWiki);
|
2004-02-09 20:51:40 +00:00
|
|
|
|
push(@MyRules, \&AnchorsRule);
|
|
|
|
|
|
|
2004-02-09 21:02:46 +00:00
|
|
|
|
sub AnchorsRule {
|
2015-08-23 21:22:12 +03:00
|
|
|
|
if (m/\G\[\[\#$FreeLinkPattern\]\]/cg) {
|
2004-08-17 15:00:42 +00:00
|
|
|
|
return $q->a({-href=>'#' . FreeToNormal($1), -class=>'local anchor'}, $1);
|
2015-08-23 21:22:12 +03:00
|
|
|
|
} elsif ($BracketWiki && m/\G\[\[\#$FreeLinkPattern\|([^\]]+)\]\]/cg) {
|
2005-03-31 19:32:21 +00:00
|
|
|
|
return $q->a({-href=>'#' . FreeToNormal($1), -class=>'local anchor'}, $2);
|
2015-08-23 21:22:12 +03:00
|
|
|
|
} elsif ($BracketWiki && m/\G(\[\[$FreeLinkPattern\#$FreeLinkPattern\|([^\]]+)\]\])/cg
|
|
|
|
|
|
or m/\G(\[\[\[$FreeLinkPattern\#$FreeLinkPattern\]\]\])/cg
|
|
|
|
|
|
or m/\G(\[\[$FreeLinkPattern\#$FreeLinkPattern\]\])/cg) {
|
2004-08-06 22:44:26 +00:00
|
|
|
|
# This one is not a dirty rule because the output is always a page
|
|
|
|
|
|
# link, never an edit link (unlike normal free links).
|
2004-08-06 22:19:16 +00:00
|
|
|
|
my $bracket = (substr($1, 0, 3) eq '[[[');
|
|
|
|
|
|
my $id = $2 . '#' . $3;
|
|
|
|
|
|
my $text = $4;
|
2004-08-06 22:44:26 +00:00
|
|
|
|
my $class = 'local anchor';
|
2004-08-06 22:19:16 +00:00
|
|
|
|
my $title = '';
|
|
|
|
|
|
$id = FreeToNormal($id);
|
|
|
|
|
|
if (!$text && $bracket) {
|
|
|
|
|
|
$text = BracketLink(++$FootnoteNumber); # s/_/ /g happens further down!
|
|
|
|
|
|
$class .= ' number';
|
2015-03-28 14:55:25 +01:00
|
|
|
|
# Since we're displaying a number such as [1], the title attribute should tell us where this will go.
|
|
|
|
|
|
$title = "$2 ($3)";
|
|
|
|
|
|
# The user might have writen [[[FooBar#one two]]] or [[[FooBar#one_two]]]
|
|
|
|
|
|
$title =~ s/_/ /g;
|
2004-08-06 22:19:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
$text = $id unless $text;
|
|
|
|
|
|
$text =~ s/_/ /g;
|
|
|
|
|
|
return ScriptLink(UrlEncode($id), $text, $class, undef, $title);
|
2015-08-23 21:22:12 +03:00
|
|
|
|
} elsif (m/\G\[\:$FreeLinkPattern\]/cg) {
|
2009-12-06 19:26:33 +00:00
|
|
|
|
return $q->a({-name=>FreeToNormal($1), -class=>'anchor'}, '');
|
2004-02-09 20:51:40 +00:00
|
|
|
|
}
|
2015-02-27 12:10:18 +02:00
|
|
|
|
return;
|
2004-02-09 20:51:40 +00:00
|
|
|
|
}
|
2015-03-30 22:09:45 +02:00
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
|
*OldAnchorsBrowsePage=\&BrowsePage;
|
|
|
|
|
|
*BrowsePage=\&NewAnchorsBrowsePage;
|
2015-03-30 22:09:45 +02:00
|
|
|
|
|
|
|
|
|
|
sub NewAnchorsBrowsePage {
|
|
|
|
|
|
my ($id) = @_;
|
|
|
|
|
|
OpenPage($id);
|
|
|
|
|
|
if (not GetParam('revision', '')
|
|
|
|
|
|
and not GetParam('oldid', '')
|
|
|
|
|
|
and $Page{text} =~ /^\#REDIRECT\s+\[\[$FreeLinkPattern\#$FreeLinkPattern\]\]/) {
|
|
|
|
|
|
return ReBrowsePage(FreeToNormal($1 . '#' . $2), $id);
|
|
|
|
|
|
}
|
|
|
|
|
|
return OldAnchorsBrowsePage(@_);
|
|
|
|
|
|
}
|