2015-07-28 22:44:53 +02:00
|
|
|
|
# Copyright (C) 2004–2015 Alex Schroeder <alex@gnu.org>
|
2004-02-17 22:38:44 +00:00
|
|
|
|
#
|
2015-03-29 15:07:37 +02: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
|
|
|
|
#
|
2015-03-29 15:07:37 +02: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
|
|
|
|
#
|
2015-03-29 15:07:37 +02: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
|
|
|
|
|
2015-03-29 15:07:37 +02: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('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);
|
2015-03-27 03:01:01 +02:00
|
|
|
|
|
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 {
|
2015-08-23 21:22:12 +03:00
|
|
|
|
if (/\G([A-Za-z\x{0080}-\x{fffd}]+)/cg) {
|
2004-06-17 01:13:18 +00:00
|
|
|
|
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);
|
2004-06-17 01:13:18 +00:00
|
|
|
|
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
|
2004-06-17 01:13:18 +00:00
|
|
|
|
return '';
|
2004-02-17 22:38:44 +00:00
|
|
|
|
}
|
2015-02-27 12:10:18 +02:00
|
|
|
|
return;
|
2004-02-17 22:38:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub LinkAllGetPageLinkIfItExists {
|
|
|
|
|
|
my $id = shift;
|
2015-03-29 15:07:37 +02:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
|
*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) {
|
2004-11-15 00:12:20 +00:00
|
|
|
|
$UserGotoBar .= ' ' if $UserGotoBar;
|
2004-02-17 22:49:24 +00:00
|
|
|
|
$UserGotoBar .= $addition;
|
|
|
|
|
|
}
|
|
|
|
|
|
return OldLinkAllGetGotoBar();
|
2004-02-17 22:38:44 +00:00
|
|
|
|
}
|