wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / mac.pl
blob66e1e5ca718479457af17e217259bb5078c06b60
1 # Copyright (C) 2005 Alex Schroeder <alex@emacswiki.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the
15 # Free Software Foundation, Inc.
16 # 59 Temple Place, Suite 330
17 # Boston, MA 02111-1307 USA
19 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/mac.pl">mac.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Mac">Mac</a></p>';
21 use Unicode::Normalize;
23 *OldMacAllPagesList = *AllPagesList;
24 *AllPagesList = *NewMacAllPagesList;
26 sub NewMacAllPagesList {
27 $refresh = GetParam('refresh', 0);
28 if ($IndexInit && !$refresh) {
29 return @IndexList;
31 OldMacAllPagesList(@_);
32 my @new = ();
33 %IndexHash = ();
34 foreach my $id (@IndexList) {
35 $id = NFC($id);
36 push(@new, $id);
37 $IndexHash{$id} = 1;
39 @IndexList = @new;
40 return @new;
43 *OldMacGrepFiltered = *GrepFiltered;
44 *GrepFiltered = *NewMacGrepFiltered;
46 sub NewMacGrepFiltered {
47 my @pages = OldMacGrepFiltered(@_);
48 foreach my $id (@pages) {
49 $id = NFC($id);
51 return @pages;
54 push(@MyInitVariables, \&MacFixEncoding);
56 sub MacFixEncoding {
57 # disable grep if searching for non-ascii stuff:
59 # $ mkdir /tmp/dir
60 # $ echo schroeder > /tmp/dir/schroeder
61 # $ echo schröder > /tmp/dir/schröder
62 # $ echo SCHRÖDER > /tmp/dir/SCHRÖDER-UP # don't use SCHRÖDER because of HFS
63 # $ grep -rli schröder /tmp/dir
64 # /tmp/dir/schröder
65 # $ grep -rli SCHRÖDER /tmp/dir
66 # /tmp/dir/schröder
68 # Why is grep not finding the upper case variant in the SCHRÖDER-UP
69 # file?
71 $UseGrep = 0 if GetParam('search', '') =~ /[x{0080}-\x{fffd}]/;
73 # the rest is only necessary if using namespaces.pl
74 return unless %Namespaces;
75 my %hash = ();
76 for my $key (keys %Namespaces) {
77 utf8::decode($key);
78 $key = NFC($key);
79 $hash{$key} = $NamespaceRoot . '/' . $key . '/';
81 %Namespaces = %hash;
82 %hash = ();
83 for my $key (keys %InterSite) {
84 utf8::decode($key);
85 $key = NFC($key);
86 $hash{$key} = $Namespaces{$key} if $Namespaces{$key};
88 %InterSite = %hash;
91 # for drafts.pl
93 *OldMacDraftFiles = *DraftFiles;
94 *DraftFiles = *NewMacDraftFiles;
96 sub NewMacDraftFiles {
97 return map { NFC($_) } OldMacDraftFiles(@_);