mac.pl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright (C) 2005–2015 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software: you can redistribute it and/or modify it under
  4. # the terms of the GNU General Public License as published by the Free Software
  5. # Foundation, either version 3 of the License, or (at your option) any later
  6. # version.
  7. #
  8. # This program is distributed in the hope that it will be useful, but WITHOUT
  9. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this program. If not, see <http://www.gnu.org/licenses/>.
  14. use strict;
  15. use v5.10;
  16. AddModuleDescription('mac.pl', 'Mac');
  17. our (%InterSite, %IndexHash, @IndexList, @MyInitVariables, %Namespaces, $NamespaceRoot);
  18. use Unicode::Normalize;
  19. *OldMacAllPagesList = \&AllPagesList;
  20. *AllPagesList = \&NewMacAllPagesList;
  21. sub NewMacAllPagesList {
  22. return @IndexList if @IndexList and not GetParam('refresh', 0);
  23. OldMacAllPagesList(@_);
  24. my @new = ();
  25. %IndexHash = ();
  26. foreach my $id (@IndexList) {
  27. $id = NFC($id);
  28. push(@new, $id);
  29. $IndexHash{$id} = 1;
  30. }
  31. @IndexList = @new;
  32. return @new;
  33. }
  34. *OldMacFiltered = \&Filtered;
  35. *Filtered = \&NewMacFiltered;
  36. sub NewMacFiltered {
  37. my @pages = OldMacFiltered(@_);
  38. foreach my $id (@pages) {
  39. $id = NFC($id);
  40. }
  41. return @pages;
  42. }
  43. push(@MyInitVariables, \&MacFixEncoding);
  44. sub MacFixEncoding {
  45. # the rest is only necessary if using namespaces.pl
  46. return unless %Namespaces;
  47. my %hash = ();
  48. for my $key (keys %Namespaces) {
  49. $key = NFC($key);
  50. $hash{$key} = $NamespaceRoot . '/' . $key . '/';
  51. }
  52. %Namespaces = %hash;
  53. %hash = ();
  54. for my $key (keys %InterSite) {
  55. $key = NFC($key);
  56. $hash{$key} = $Namespaces{$key} if $Namespaces{$key};
  57. }
  58. %InterSite = %hash;
  59. }
  60. # for drafts.pl
  61. *OldMacDraftFiles = \&DraftFiles;
  62. *DraftFiles = \&NewMacDraftFiles;
  63. sub NewMacDraftFiles {
  64. return map { NFC($_) } OldMacDraftFiles(@_);
  65. }