gotobar.pl 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. if ($IndexHash{$GotobarName}) {
  30. OpenPage($GotobarName);
  31. return if PageMarkedForDeletion();
  32. # Don't use @UserGotoBarPages because this messes up the order of
  33. # links for unsuspecting users.
  34. @UserGotoBarPages = ();
  35. $UserGotoBar = '';
  36. my $count = 0;
  37. while ($Page{text} =~ m/($LinkPattern|\[\[$FreeLinkPattern\]\]|\[\[$FreeLinkPattern\|([^\]]+)\]\]|\[$InterLinkPattern\s+([^\]]+?)\]|\[$FullUrlPattern[|[:space:]]([^\]]+?)\])/g) {
  38. my $page = $2||$3||$4||$6||$8;
  39. my $text = $5||$7||$9;
  40. $UserGotoBar .= ' ' if $UserGotoBar;
  41. if ($6) {
  42. $UserGotoBar .= GetInterLink($page, $text);
  43. } elsif ($8) {
  44. $UserGotoBar .= GetUrl($page, $text);
  45. } else {
  46. $UserGotoBar .= GetPageLink($page, $text);
  47. # The first local page is the homepage, the second local page
  48. # is the list of recent changes.
  49. $count++;
  50. if ($count == 1) {
  51. unless ($GotobarSetHome) {$HomePage = FreeToNormal($page)};
  52. } elsif ($count == 2) {
  53. unless ($GotobarSetRC) {$RCName = FreeToNormal($page);}
  54. }
  55. }
  56. }
  57. }
  58. }