accesskeys.pl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (C) 2014 Alex-Daniel Jakimenko <alex.jakimenko@gmail.com>
  2. # Copyright (C) 2014 Alex Schroeder <alex@gnu.org>
  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('accesskeys.pl', 'Links With AccessKeys Extension');
  17. our (@MyRules, $FreeLinkPattern);
  18. push(@MyRules, \&LinksWithAccessKeys);
  19. sub LinksWithAccessKeys {
  20. if (m/\G(\[\[$FreeLinkPattern\{(.)\}\]\])/cg) {
  21. my ($id, $key) = ($2, $3);
  22. Dirty($1);
  23. $id = FreeToNormal($id);
  24. my ($class, $resolved, $title, $exists) = ResolveId($id);
  25. my $text = NormalToFree($id);
  26. if ($resolved) { # anchors don't exist as pages, therefore do not use $exists
  27. print ScriptLink(UrlEncode($resolved), $text, $class, undef, $title, $key);
  28. } else {
  29. print "[[" . QuoteHtml($text) . GetEditLink($id, '?') . "]]";
  30. }
  31. return ''; # this is a dirty rule that depends the definition of other pages
  32. }
  33. return; # the rule didn't match
  34. }