gotobar.pl 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (C) 2006-2014 Alex Schroeder <alex@gnu.org>
  2. # Copyright (C) 2016 Ingo Belka
  3. #
  4. # This program is free software: you can redistribute it and/or modify it under
  5. # the terms of the GNU General Public License as published by the Free Software
  6. # Foundation, either version 3 of the License, or (at your option) any later
  7. # version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License along with
  14. # this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. our (%Page, %IndexHash, %AdminPages, $HomePage, $RCName, @MyInitVariables, $LinkPattern, $FreeLinkPattern, $FullUrlPattern, $InterLinkPattern, $UserGotoBar, @UserGotoBarPages);
  18. AddModuleDescription('gotobar.pl', 'Gotobar Extension');
  19. our ($GotobarName);
  20. # Include this page on every page:
  21. $GotobarName = 'GotoBar';
  22. our ($GotobarSetHome, $GotobarSetRC);
  23. # 0 does set home-link and/or rc-link automatically, 1 doesn't
  24. # do this later so that the user can customize $GotobarName
  25. push(@MyInitVariables, \&GotobarInit);
  26. sub GotobarInit {
  27. $GotobarName = FreeToNormal($GotobarName); # spaces to underscores
  28. $AdminPages{$GotobarName} = 1;
  29. my $id = GetId();
  30. my $encoded = UrlEncode($id);
  31. if ($IndexHash{$GotobarName}) {
  32. OpenPage($GotobarName);
  33. return if PageMarkedForDeletion();
  34. # Don't use @UserGotoBarPages because this messes up the order of
  35. # links for unsuspecting users.
  36. @UserGotoBarPages = ();
  37. $UserGotoBar = '';
  38. my $text = $Page{text};
  39. $text =~ s/\$\$id\b/$encoded/g;
  40. $text =~ s/\$id\b/$id/g;
  41. my $count = 0;
  42. while ($text =~ m/($LinkPattern|\[\[$FreeLinkPattern\]\]|\[\[$FreeLinkPattern\|([^\]]+)\]\]|\[$InterLinkPattern\s+([^\]]+?)\]|\[$FullUrlPattern[|[:space:]]([^\]]+?)\])/g) {
  43. my $page = $2||$3||$4||$6||$8;
  44. my $text = $5||$7||$9;
  45. $UserGotoBar .= ' ' if $UserGotoBar;
  46. if ($6) {
  47. $UserGotoBar .= GetInterLink($page, $text);
  48. } elsif ($8) {
  49. $UserGotoBar .= GetUrl($page, $text);
  50. } else {
  51. $UserGotoBar .= GetPageLink($page, $text);
  52. # The first local page is the homepage, the second local page
  53. # is the list of recent changes.
  54. $count++;
  55. if ($count == 1) {
  56. unless ($GotobarSetHome) {$HomePage = FreeToNormal($page)};
  57. } elsif ($count == 2) {
  58. unless ($GotobarSetRC) {$RCName = FreeToNormal($page);}
  59. }
  60. }
  61. }
  62. }
  63. }