gotobar.pl 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright (C) 2006-2014 Alex Schroeder <alex@gnu.org>
  2. #
  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. our (%Page, %IndexHash, %AdminPages, $HomePage, $RCName, @MyInitVariables, $LinkPattern, $FreeLinkPattern, $FullUrlPattern, $InterLinkPattern, $UserGotoBar, @UserGotoBarPages);
  17. AddModuleDescription('gotobar.pl', 'Gotobar Extension');
  18. our ($GotobarName);
  19. # Include this page on every page:
  20. $GotobarName = 'GotoBar';
  21. # do this later so that the user can customize $GotobarName
  22. push(@MyInitVariables, \&GotobarInit);
  23. sub GotobarInit {
  24. $GotobarName = FreeToNormal($GotobarName); # spaces to underscores
  25. $AdminPages{$GotobarName} = 1;
  26. if ($IndexHash{$GotobarName}) {
  27. OpenPage($GotobarName);
  28. return if PageMarkedForDeletion();
  29. # Don't use @UserGotoBarPages because this messes up the order of
  30. # links for unsuspecting users.
  31. @UserGotoBarPages = ();
  32. $UserGotoBar = '';
  33. my $count = 0;
  34. while ($Page{text} =~ m/($LinkPattern|\[\[$FreeLinkPattern\]\]|\[\[$FreeLinkPattern\|([^\]]+)\]\]|\[$InterLinkPattern\s+([^\]]+?)\]|\[$FullUrlPattern[|[:space:]]([^\]]+?)\])/g) {
  35. my $page = $2||$3||$4||$6||$8;
  36. my $text = $5||$7||$9;
  37. $UserGotoBar .= ' ' if $UserGotoBar;
  38. if ($6) {
  39. $UserGotoBar .= GetInterLink($page, $text);
  40. } elsif ($8) {
  41. $UserGotoBar .= GetUrl($page, $text);
  42. } else {
  43. $UserGotoBar .= GetPageLink($page, $text);
  44. # The first local page is the homepage, the second local page
  45. # is the list of recent changes.
  46. $count++;
  47. if ($count == 1) {
  48. $HomePage = FreeToNormal($page);
  49. } elsif ($count == 2) {
  50. $RCName = FreeToNormal($page);
  51. }
  52. }
  53. }
  54. }
  55. }