1 # Copyright (C) 2011 Alex Schroeder <alex@gnu.org>
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
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.
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/>.
15 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/offline.pl">offline.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Plans">Plans</a></p>';
17 # Based on http://diveintohtml5.org/offline.html
19 push(@MyAdminCode, \
&OfflineMenu
);
22 my ($id, $menuref, $restref) = @_;
24 ScriptLink
('action=browse;id=' . UrlEncode
($id) . ';offline=1',
25 T
('Make available offline'),
29 push(@MyInitVariables, \
&InitOffline
);
32 # Make sure we parse path_info and parameters
34 # Switch to HTML5 if the offline parameter is set
35 if (GetParam
('offline', 0)) {
36 # add link to the manifest listing all the pages
37 my $manifest = ScriptUrl
('action=manifest');
38 $DocumentHeader = qq{<!DOCTYPE HTML
>
39 <html manifest
="$manifest">
41 # HACK ALERT: In order to allow the browser to cache all the pages
42 # listed in the manifest, we need to disable surge protection for
45 # every offline page will link to other offline pages
46 $ScriptName .= '/offline' unless $ScriptName =~ m
!/offline
$!;
47 # add some links for Apple devices (boo!)
48 if ($HtmlHeaders !~ /apple-mobile-web-app-capable/) {
50 <meta name
="apple-mobile-web-app-capable" content
="yes" />
51 <meta name
="apple-mobile-web-app-status-bar-style" content
="black" />
57 $Action{manifest
} = \
&DoManifest
;
59 # List all the pages necessary for the offline application.
61 print GetHttpHeader
('text/cache-manifest');
62 print "CACHE MANIFEST\n";
63 # make sure to list the URLs for the offline version
64 local $ScriptName = $ScriptName . '/offline';
65 # don't forget to URL encode
66 foreach my $id (AllPagesList
()) {
67 print ScriptUrl
(UrlEncode
($id)) . "\n";
69 # Missing pages that should show the default text such as
70 # RecentChanges cannot be added because fetching them results in a
72 # foreach my $id (@UserGotoBarPages) {
73 # print ScriptUrl($id) . "\n" unless $IndexHash{$id};
76 print $StyleSheet . "\n" if $StyleSheet;
77 # FIXME: $StyleSheetPage
78 # FIXME: external images, stuff in $HtmlHeaders
79 # Error message all the stuff that's not available offline.
80 my $offline = ScriptUrl
('action=offline');
89 $Action{offline
} = \
&DoOffline
;
91 # Show an excuse for the pages that have not been cached.
93 ReportError
(T
('Offline'),
95 0, $q->p(T
('You are currently offline and what you requested is not part of the offline application. You need to be online to do this.')));
99 *OldOfflineReBrowsePage
= *ReBrowsePage
;
100 *ReBrowsePage
= *NewOfflineReBrowsePage
;
102 sub NewOfflineReBrowsePage
{
104 if (GetParam
('offline', 0)) {
107 OldOfflineReBrowsePage
(@_);