css-install.pl 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. use strict;
  2. use v5.10;
  3. =head1 NAME
  4. css-install - an Oddmuse module that allows users to change the site CSS
  5. =head1 SYNOPSIS
  6. This module allows users to install their own CSS. This is useful for
  7. new wikis, specially if using the I<Namespaces> extension.
  8. =head1 INSTALLATION
  9. Installing a module is easy: Create a modules subdirectory in your
  10. data directory, and put the Perl file in there. It will be loaded
  11. automatically.
  12. =cut
  13. AddModuleDescription('css-install.pl');
  14. =head1 CONFIGURATION
  15. =head2 @CssList
  16. C<@CssList> contains a list of all the recommended CSS URLs.
  17. =cut
  18. our ($q, %Action, @MyAdminCode, $StyleSheet, $StyleSheetPage);
  19. our (@CssList);
  20. # List of Oddmuse CSS URLs
  21. @CssList = qw(http://www.emacswiki.org/css/astrid.css
  22. http://www.emacswiki.org/css/beige-red.css
  23. http://www.emacswiki.org/css/blue.css
  24. http://www.emacswiki.org/css/cali.css
  25. http://www.emacswiki.org/css/green.css
  26. http://www.emacswiki.org/css/hug.css
  27. http://www.emacswiki.org/css/oddmuse.css
  28. http://www.emacswiki.org/css/wikio.css);
  29. push(@MyAdminCode, \&CssInstallMenu);
  30. sub CssInstallMenu {
  31. my ($id, $menuref, $restref) = @_;
  32. push(@$menuref, ScriptLink('action=css', T('Install CSS'), 'css'))
  33. unless $StyleSheet;
  34. }
  35. $Action{css} = \&DoCss;
  36. sub DoCss {
  37. my $css = GetParam('install', '');
  38. if ($css) {
  39. my $data = GetRaw($css);
  40. ReportError(Ts('%s returned no data, or LWP::UserAgent is not available.', $css),
  41. '500 INTERNAL SERVER ERROR') unless $data;
  42. SetParam('text', $data);
  43. DoPost($StyleSheetPage);
  44. } else {
  45. print GetHeader('', T('Install CSS')), $q->start_div({-class=>'content css'}),
  46. $q->p(Ts('Copy one of the following stylesheets to %s:', GetPageLink($StyleSheetPage)));
  47. # undo preview
  48. print GetFormStart(undef, 'GET'), GetHiddenValue('action', 'css');
  49. print GetHiddenValue('css', '');
  50. print $q->submit(-name=>'Reset', -value=>T('Reset'));
  51. print $q->end_form;
  52. # save
  53. print GetFormStart(undef, 'GET'), GetHiddenValue('action', 'css');
  54. print GetHiddenValue('install', '');
  55. print $q->submit(-name=>'Save', -accesskey=>T('s'), -value=>T('Save'));
  56. print $q->end_form;
  57. print $q->end_div();
  58. foreach my $url (@CssList) {
  59. print $q->start_div({-class=>'sheet'}), $q->p(GetUrl($url));
  60. # preview
  61. print GetFormStart(undef, 'GET'), GetHiddenValue('action', 'css');
  62. print GetHiddenValue('css', $url);
  63. print $q->submit(-name=>'Preview', -accesskey=>T('p'), -value=>T('Preview'));
  64. print $q->end_form;
  65. # save
  66. print GetFormStart(undef, 'GET'), GetHiddenValue('action', 'css');
  67. print GetHiddenValue('css', '');
  68. print GetHiddenValue('install', $url);
  69. print $q->submit(-name=>'Save', -accesskey=>T('s'), -value=>T('Save'));
  70. print $q->end_form;
  71. print $q->end_div();
  72. }
  73. print $q->end_div();
  74. PrintFooter();
  75. }
  76. }
  77. =head1 COPYRIGHT AND LICENSE
  78. Copyright (C) 2011 Alex Schroeder <alex@gnu.org>
  79. This program is free software: you can redistribute it and/or modify it under
  80. the terms of the GNU General Public License as published by the Free Software
  81. Foundation, either version 3 of the License, or (at your option) any later
  82. version.
  83. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  84. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  85. PARTICULAR PURPOSE. See the GNU General Public License for more details.
  86. You should have received a copy of the GNU General Public License along with
  87. this program. If not, see <http://www.gnu.org/licenses/>.
  88. =cut