-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecialOffline.php
208 lines (174 loc) · 5.72 KB
/
SpecialOffline.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
/**
* Special:Offline
* Configuration and status reporting for standalone mode.
* Checks that dependencies are installed correctly and the database
* dumps have been prepared.
*/
$wgExtensionCredits['specialpage'][] = array(
'path' => __FILE__,
'name' => 'Wikipedia Offline Patch',
'author' => 'Adam Wight',
'status' => 'beta',
'url' => 'http://code.google.com/p/wikipedia-offline-patch',
'version' => '0.6',
'descriptionmsg' => 'offline_special_desc'
);
$dir = dirname(__FILE__);
$wgExtensionMessagesFiles['SpecialOffline'] = $dir.'/SpecialOffline.i18n.php';
class SpecialOffline extends SpecialPage
{
function SpecialOffline() {
parent::__construct('offline' /*, 'editinterface' */);
}
function execute($param) {
global $wgOut, $wgTitle;
require_once(dirname(__FILE__).'/DumpReader.php');
$this->setHeaders();
$this->outputHeader();
if (isset($GLOBALS['_GET']['reindex']))
{
$wgOut->wrapWikiMsg('$1', 'offline_reindex_begin');
$wgOut->addHTML('XXX web ui unimplemented');
}
else if ($this->runTests())
{
$this->show_config();
}
//TODO report and explain wgOfflineIgnoreLiveData
}
function show_config()
{
global $wgOut, $wgTitle;
$wgOut->wrapWikiMsg('<h1>$1</h1>', 'offline_heading_configuration');
global $wgOfflineWikiPath;
$wgOut->wrapWikiMsg('$1', array('offline_db_path', htmlentities($wgOfflineWikiPath)));
$wgOut->addHTML( '<a href="'.$wgTitle->getLocalURL('reindex').'">'.
wfMsg('offline_reindex_button').'</a>');
}
function runTests() {
global $wgOut, $wgTitle;
$html = <<<EOS
<style type='text/css'>
.status.good {
background-color: rgb(100, 200, 100);
}
.status.collapsed {
display: none;
}
.status {
display: block;
border-style: solid;
padding: 5px;
}
</style>
EOS;
$wgOut->addHTML($html);
$wgOut->wrapWikiMsg('<h1>$1</h1>', 'offline_heading_status');
$wgOut->addHTML('<div class="status"><ul>');
// lookup a real article in the index can be searched
$results = DumpReader::index_search(wfMsg('offline_test_article'));
if (count($results) > 0)
list ($bz_file, $entry_title) = $results[0];
$test_index = isset($bz_file);
$this->printTest($test_index, 'offline_index_test');
if (!$test_index) {
$this->diagnoseIndex();
return false;
}
// tests that bz2 dumpfiles can be opened and read
$xml = DumpReader::load_bz($bz_file, $entry_title);
$test_bz = isset($xml);
$this->printTest($test_bz, 'offline_bzload_test');
if (!$test_bz) {
$this->diagnoseBzload($bz_file);
return false;
}
//report subdirectory setting
// if (substr($bz_file, 0, 1) == 'x') {
// $subdir = dirname($bz_file); //TODO strip absolute components if needed
// $wgOut->addWikiMsg('offline_subdir-status', $subdir);
// $wgOut->addHTML(
// '<label>' . wfMsg('offline_change-subdir') .
// '<input type=text size=20 name="subdir" value="'.$subdir.'">
// <input type=submit name="subdir" value="Change">
// </label/>'
// );
// }
// TODO report language settings and availabilities
//test that a specific article can be loaded
$article_wml = DumpReader::load_article($entry_title);
$test_article = isset($article_wml);
$this->printTest($test_article, 'offline_article_test');
if (!$test_article) {
//TODO diagnose
return false;
}
//TODO test that the wml has not been padded or truncated
//test that our handler is still hooked in
$mw_api_article = new Article(Title::newFromText($entry_title));
$mw_api_article->loadContent();
$content = $mw_api_article->getContent();
//wfDebug('got '.strlen($mw_api_article->mContent).' bytes of wml from cache');
$test_hooks = $mw_api_article->mContentLoaded;
// TODO false positive
$this->printTest($test_hooks, 'offline_hooks_test');
if (!$test_hooks) {
$this->diagnoseHooks();
return false;
}
//TODO test Templates
$wgOut->addHTML('</ul></div>');
$wgOut->wrapWikiMsg('<div class="status good">$1</div>', 'offline_all_tests_pass');
//TODO div collapse or load on demand
//$wgOut->addWikiText($content);
return true;
}
function diagnoseIndex() {
global $wgOut, $wgOfflineWikiPath;
if (!isset($wgOfflineWikiPath)) {
$this->printDiagnostic('offlinewikipath_not_configured');
}
elseif (!is_dir($wgOfflineWikiPath)) {
$this->printDiagnostic(array('offlinewikipath_not_found', $wgOfflineWikiPath));
}
elseif (!is_dir("$wgOfflineWikiPath/db") || !file_exists("$wgOfflineWikiPath/db/termlist.DB")) {
$this->printDiagnostic(array('offline_dbdir_not_found', $wgOfflineWikiPath));
} else {
$this->printDiagnostic('offline_unknown_index_error');
}
}
function diagnoseBzload($bz_file) {
global $wgOut, $wgOfflineWikiPath;
$full_path = $wgOfflineWikiPath.'/'.$bz_file;
if (!extension_loaded('bz2')) {
$this->printDiagnostic('offline_bz2_ext_needed');
}
if (!file_exists($full_path)) {
$this->printDiagnostic(array('offline_bz2_file_gone', $full_path));
}
else {
$this->printDiagnostic(array('offline_unknown_bz2_error', $full_path));
}
}
function diagnoseHooks() {
global $wgOut, $wgMemc;
$key = wfMemcKey('offline','trial');
$wgMemc->set($key, true);
if (!$wgMemc->get($key)) {
$this->printDiagnostic('offline_cache_needed');
}
// check that passing revisiontext through cache will work
}
function printTest($bool, $msg) {
global $wgOut;
if ($bool)
$wgOut->wrapWikiMsg('<div class="result-pass"><li>$1</div>', $msg.'_pass');
else
$wgOut->wrapWikiMsg('<div class="error"><li>$1</div>', $msg.'_fail');
}
function printDiagnostic($msg) {
global $wgOut;
$wgOut->wrapWikiMsg('<div class="errorbox">$1</div>', $msg);
}
}