no-question-mark.pl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright (C) 2006 Alex Schroeder <alex@emacswiki.org>
  2. #
  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 3 of the License, or
  6. # (at your option) any later version.
  7. #
  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.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('no-question-mark.pl', 'No Questionmarks Extension');
  18. our ($q, $OpenPageName, $ScriptName, %IndexHash, $FootnoteNumber, $UsePathInfo);
  19. sub GetPageOrEditLink {
  20. my ($id, $text, $bracket, $free) = @_;
  21. $id = FreeToNormal($id);
  22. my ($class, $resolved, $title, $exists) = ResolveId($id);
  23. if (!$text && $resolved && $bracket) {
  24. $text = BracketLink(++$FootnoteNumber); # s/_/ /g happens further down!
  25. $class .= ' number';
  26. $title = $id; # override title
  27. $title =~ s/_/ /g if $free;
  28. }
  29. $text = "[$id]" if not $text and $bracket; # if the page exists with brackets and no text see above
  30. $text = $id if not $text;
  31. $text =~ s/_/ /g;
  32. if ($resolved) { # anchors don't exist as pages, therefore do not use $exists
  33. return ScriptLink(UrlEncode($resolved), $text, $class, undef, $title);
  34. } else {
  35. return GetEditLink($id, $text);
  36. }
  37. }
  38. sub GetDownloadLink {
  39. my ($name, $image, $revision, $alt) = @_;
  40. $alt = $name unless $alt;
  41. $alt =~ s/_/ /g;
  42. my $id = FreeToNormal($name);
  43. # if the page does not exist
  44. return GetEditLink($id, ($image ? T('image') : T('download')) . ':' . $name, 1)
  45. unless $IndexHash{$id};
  46. my $action;
  47. if ($revision) {
  48. $action = "action=download;id=" . UrlEncode($id) . ";revision=$revision";
  49. } elsif ($UsePathInfo) {
  50. $action = "download/" . UrlEncode($id);
  51. } else {
  52. $action = "action=download;id=" . UrlEncode($id);
  53. }
  54. if ($image) {
  55. if ($UsePathInfo and not $revision) {
  56. $action = $ScriptName . '/' . $action;
  57. } else {
  58. $action = $ScriptName . '?' . $action;
  59. }
  60. my $result = $q->img({-src=>$action, -alt=>$alt, -class=>'upload'});
  61. $result = ScriptLink(UrlEncode($id), $result, 'image') unless $id eq $OpenPageName;
  62. return $result;
  63. } else {
  64. return ScriptLink($action, $alt, 'upload');
  65. }
  66. }