no-question-mark.pl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 2 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, write to the
  15. # Free Software Foundation, Inc.
  16. # 59 Temple Place, Suite 330
  17. # Boston, MA 02111-1307 USA
  18. use strict;
  19. use v5.10;
  20. AddModuleDescription('no-question-mark.pl', 'No Questionmarks Extension');
  21. our ($q, $OpenPageName, $ScriptName, %IndexHash, $FootnoteNumber, $UsePathInfo);
  22. sub GetPageOrEditLink {
  23. my ($id, $text, $bracket, $free) = @_;
  24. $id = FreeToNormal($id);
  25. my ($class, $resolved, $title, $exists) = ResolveId($id);
  26. if (!$text && $resolved && $bracket) {
  27. $text = BracketLink(++$FootnoteNumber); # s/_/ /g happens further down!
  28. $class .= ' number';
  29. $title = $id; # override title
  30. $title =~ s/_/ /g if $free;
  31. }
  32. $text = "[$id]" if not $text and $bracket; # if the page exists with brackets and no text see above
  33. $text = $id if not $text;
  34. $text =~ s/_/ /g;
  35. if ($resolved) { # anchors don't exist as pages, therefore do not use $exists
  36. return ScriptLink(UrlEncode($resolved), $text, $class, undef, $title);
  37. } else {
  38. return GetEditLink($id, $text);
  39. }
  40. }
  41. sub GetDownloadLink {
  42. my ($name, $image, $revision, $alt) = @_;
  43. $alt = $name unless $alt;
  44. $alt =~ s/_/ /g;
  45. my $id = FreeToNormal($name);
  46. # if the page does not exist
  47. return GetEditLink($id, ($image ? T('image') : T('download')) . ':' . $name, 1)
  48. unless $IndexHash{$id};
  49. my $action;
  50. if ($revision) {
  51. $action = "action=download;id=" . UrlEncode($id) . ";revision=$revision";
  52. } elsif ($UsePathInfo) {
  53. $action = "download/" . UrlEncode($id);
  54. } else {
  55. $action = "action=download;id=" . UrlEncode($id);
  56. }
  57. if ($image) {
  58. if ($UsePathInfo and not $revision) {
  59. $action = $ScriptName . '/' . $action;
  60. } else {
  61. $action = $ScriptName . '?' . $action;
  62. }
  63. my $result = $q->img({-src=>$action, -alt=>$alt, -class=>'upload'});
  64. $result = ScriptLink(UrlEncode($id), $result, 'image') unless $id eq $OpenPageName;
  65. return $result;
  66. } else {
  67. return ScriptLink($action, $alt, 'upload');
  68. }
  69. }