Files
oddmuse/modules/mac.pl

96 lines
2.6 KiB
Perl
Raw Normal View History

# Copyright (C) 20052015 Alex Schroeder <alex@gnu.org>
2005-04-05 23:45:59 +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.
2005-04-05 23:45:59 +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.
2005-04-05 23:45:59 +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/>.
2005-04-05 23:45:59 +00:00
2015-03-29 15:16:57 +02:00
use strict;
AddModuleDescription('mac.pl', 'Mac');
2005-04-05 23:45:59 +00:00
2015-04-10 13:31:28 +03:00
our (%InterSite, %IndexHash, @IndexList, @MyInitVariables, $UseGrep, %Namespaces, $NamespaceRoot);
2006-09-02 01:14:31 +00:00
use Unicode::Normalize;
2005-04-05 23:45:59 +00:00
*OldMacAllPagesList = \&AllPagesList;
*AllPagesList = \&NewMacAllPagesList;
2005-04-05 23:45:59 +00:00
sub NewMacAllPagesList {
return @IndexList if @IndexList and not GetParam('refresh', 0);
OldMacAllPagesList(@_);
2005-04-05 23:45:59 +00:00
my @new = ();
%IndexHash = ();
foreach my $id (@IndexList) {
$id = NFC($id);
2005-04-05 23:45:59 +00:00
push(@new, $id);
$IndexHash{$id} = 1;
}
@IndexList = @new;
2005-04-05 23:45:59 +00:00
return @new;
}
*OldMacGrepFiltered = \&GrepFiltered;
*GrepFiltered = \&NewMacGrepFiltered;
sub NewMacGrepFiltered {
my @pages = OldMacGrepFiltered(@_);
foreach my $id (@pages) {
$id = NFC($id);
}
return @pages;
}
push(@MyInitVariables, \&MacFixEncoding);
sub MacFixEncoding {
# disable grep if searching for non-ascii stuff:
# $ mkdir /tmp/dir
# $ echo schroeder > /tmp/dir/schroeder
# $ echo schröder > /tmp/dir/schröder
# $ echo SCHRÖDER > /tmp/dir/SCHRÖDER-UP # don't use SCHRÖDER because of HFS
# $ grep -rli schröder /tmp/dir
# /tmp/dir/schröder
# $ grep -rli SCHRÖDER /tmp/dir
# /tmp/dir/schröder
#
# Why is grep not finding the upper case variant in the SCHRÖDER-UP
# file?
$UseGrep = 0 if GetParam('search', '') =~ /[x{0080}-\x{fffd}]/;
# the rest is only necessary if using namespaces.pl
return unless %Namespaces;
my %hash = ();
for my $key (keys %Namespaces) {
utf8::decode($key);
$key = NFC($key);
$hash{$key} = $NamespaceRoot . '/' . $key . '/';
}
%Namespaces = %hash;
%hash = ();
for my $key (keys %InterSite) {
utf8::decode($key);
$key = NFC($key);
$hash{$key} = $Namespaces{$key} if $Namespaces{$key};
}
%InterSite = %hash;
}
# for drafts.pl
*OldMacDraftFiles = \&DraftFiles;
*DraftFiles = \&NewMacDraftFiles;
sub NewMacDraftFiles {
return map { NFC($_) } OldMacDraftFiles(@_);
}