Files
oddmuse/modules/link-all.pl

63 lines
1.8 KiB
Perl
Raw Normal View History

# Copyright (C) 20042015 Alex Schroeder <alex@gnu.org>
2004-02-17 22:38: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 the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
2004-02-17 22:38:44 +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-17 22:38:44 +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-17 22:38:44 +00:00
use strict;
use v5.10;
AddModuleDescription('link-all.pl', 'Link All Words Extension');
2004-02-17 22:38:44 +00:00
2015-04-10 13:31:28 +03:00
our (%IndexHash, %RuleOrder, @MyRules, $UserGotoBar, $ScriptName);
2004-02-17 22:38:44 +00:00
push(@MyRules, \&LinkAllRule);
2004-07-14 14:51:23 +00:00
$RuleOrder{\&LinkAllRule} = 1000;
2004-02-17 22:38:44 +00:00
sub LinkAllRule {
if (/\G([A-Za-z\x{0080}-\x{fffd}]+)/cg) {
my $oldpos = pos;
2004-02-17 22:38:44 +00:00
Dirty($1);
# print the word, or the link to the word
print LinkAllGetPageLinkIfItExists($1);
pos = $oldpos; # protect against changes in pos
2004-02-17 22:38:44 +00:00
# the block is cached so we don't return anything
return '';
2004-02-17 22:38:44 +00:00
}
return;
2004-02-17 22:38:44 +00:00
}
sub LinkAllGetPageLinkIfItExists {
my $id = shift;
AllPagesList();
2004-02-17 22:38:44 +00:00
if ($IndexHash{$id}) {
return GetPageLink($id);
} elsif (GetParam('define', 0)) {
return GetEditLink($id, $id);
} else {
return $id;
}
}
*OldLinkAllGetGotoBar = \&GetGotoBar;
*GetGotoBar = \&NewLinkAllGetGotoBar;
2004-02-17 22:38:44 +00:00
sub NewLinkAllGetGotoBar {
my $id = shift;
2004-02-17 22:53:36 +00:00
my $define = T('Define');
my $addition = "<a href=\"$ScriptName?action=browse;id=$id;define=1\">$define</a>";
2004-02-17 22:49:24 +00:00
if (index($UserGotoBar, $addition) < 0) {
$UserGotoBar .= ' ' if $UserGotoBar;
2004-02-17 22:49:24 +00:00
$UserGotoBar .= $addition;
}
return OldLinkAllGetGotoBar();
2004-02-17 22:38:44 +00:00
}