Index: trunk/extensions/Offline/CachedStorage.php |
— | — | @@ -6,42 +6,42 @@ |
7 | 7 | class CachedStorage |
8 | 8 | { |
9 | 9 | static function fetchIdByTitle($title) { |
10 | | - global $wgRevisionCacheExpiry, $wgMemc; |
11 | | - if ($wgRevisionCacheExpiry) { // TODO a better test for caching |
12 | | - $titlekey = wfMemcKey( 'textid', 'titlehash', md5($title) ); |
13 | | - $textid = $wgMemc->get($titlekey); |
14 | | - if (is_int($textid) && $textid > 0) |
15 | | - return $textid; |
16 | | - } |
17 | | - return false; |
| 10 | + global $wgRevisionCacheExpiry, $wgMemc; |
| 11 | + if ($wgRevisionCacheExpiry) { // TODO a better test for caching |
| 12 | + $titlekey = wfMemcKey( 'textid', 'titlehash', md5($title) ); |
| 13 | + $textid = $wgMemc->get($titlekey); |
| 14 | + if (is_int($textid) && $textid > 0) |
| 15 | + return $textid; |
| 16 | + } |
| 17 | + return false; |
18 | 18 | } |
19 | 19 | |
20 | 20 | static function set($title, $content) { |
21 | | - global $wgRevisionCacheExpiry, $wgMemc; |
22 | | - if (!$wgRevisionCacheExpiry) // caching is not possible |
23 | | - return false; |
| 21 | + global $wgRevisionCacheExpiry, $wgMemc; |
| 22 | + if (!$wgRevisionCacheExpiry) // caching is not possible |
| 23 | + return false; |
24 | 24 | |
25 | | - // we need to assign a sequence to revision text, because |
26 | | - // Article::loadContent expects page.text_id to be an integer. |
27 | | - $seq_key = wfMemcKey('offline', 'textid_seq'); |
28 | | - if (!$wgMemc->get($seq_key)) |
29 | | - $wgMemc->set($seq_key, 1); // and clear the cache?? |
| 25 | + // we need to assign a sequence to revision text, because |
| 26 | + // Article::loadContent expects page.text_id to be an integer. |
| 27 | + $seq_key = wfMemcKey('offline', 'textid_seq'); |
| 28 | + if (!$wgMemc->get($seq_key)) |
| 29 | + $wgMemc->set($seq_key, 1); // and clear the cache?? |
30 | 30 | |
31 | | - $textid = $wgMemc->incr($seq_key); |
| 31 | + $textid = $wgMemc->incr($seq_key); |
32 | 32 | |
33 | | - // cache a lookup from title to fake textid |
34 | | - $titlekey = wfMemcKey( 'textid', 'titlehash', md5($title) ); |
35 | | - $wgMemc->set( $titlekey, $textid, $wgRevisionCacheExpiry ); |
| 33 | + // cache a lookup from title to fake textid |
| 34 | + $titlekey = wfMemcKey( 'textid', 'titlehash', md5($title) ); |
| 35 | + $wgMemc->set( $titlekey, $textid, $wgRevisionCacheExpiry ); |
36 | 36 | |
37 | | - // TODO interfering with the cache is necessary to avoid a |
38 | | - // second query on Revision::newFromId. It would be much |
39 | | - // smarter to directly retrieve article markup, and optionally |
40 | | - // cache in the usual way. |
41 | | - $textkey = wfMemcKey( 'revisiontext', 'textid', $textid ); |
42 | | - $wgMemc->delete( $textkey ); |
43 | | - $wgMemc->set( $textkey, $content, $wgRevisionCacheExpiry ); |
44 | | - //wfDebug('Stuffing the cache with '.strlen($content).' bytes, at id='.$textid."\n"); |
| 37 | + // TODO interfering with the cache is necessary to avoid a |
| 38 | + // second query on Revision::newFromId. It would be much |
| 39 | + // smarter to directly retrieve article markup, and optionally |
| 40 | + // cache in the usual way. |
| 41 | + $textkey = wfMemcKey( 'revisiontext', 'textid', $textid ); |
| 42 | + $wgMemc->delete( $textkey ); |
| 43 | + $wgMemc->set( $textkey, $content, $wgRevisionCacheExpiry ); |
| 44 | + //wfDebug('Stuffing the cache with '.strlen($content).' bytes, at id='.$textid."\n"); |
45 | 45 | |
46 | | - return $textid; |
| 46 | + return $textid; |
47 | 47 | } |
48 | 48 | } |
Index: trunk/extensions/Offline/Offline.i18n.php |
— | — | @@ -41,6 +41,46 @@ |
42 | 42 | 'offline_live_data_preferred' => 'Matches from the so-called live database will be preferred over dump text.', |
43 | 43 | ); |
44 | 44 | |
| 45 | +$messages['qqq'] = array( |
| 46 | + 'offline_desc' => '', |
| 47 | + 'offline' => 'Title on the Special page', |
| 48 | + 'offline_special_desc' => '', |
| 49 | + |
| 50 | + 'offline_heading_status' => '', |
| 51 | + |
| 52 | + 'offline_test_article' => 'an entry known to exist in your language wiki', |
| 53 | + 'offline_bad_test_article' => '', |
| 54 | + |
| 55 | + 'offline_index_test_pass' => '', |
| 56 | + 'offline_index_test_fail' => '', |
| 57 | + 'offlinewikipath_not_configured' => '', |
| 58 | + 'offlinewikipath_not_found' => '', |
| 59 | + 'offline_dbdir_not_found' => '', |
| 60 | + 'offline_unknown_index_error' => '', |
| 61 | + |
| 62 | + 'offline_bzload_test_pass' => '', |
| 63 | + 'offline_bzload_test_fail' => '', |
| 64 | + 'offline_bz2_ext_needed' => '', |
| 65 | + 'offline_bz2_file_gone' => '', |
| 66 | + 'offline_unknown_bz2_error' => '', |
| 67 | + |
| 68 | + 'offline_article_test_pass' => '', |
| 69 | + 'offline_article_test_fail' => '', |
| 70 | + |
| 71 | + 'offline_hooks_test_pass' => '', |
| 72 | + 'offline_hooks_test_fail' => '', |
| 73 | + 'offline_cache_needed' => '', |
| 74 | + |
| 75 | + 'offline_all_tests_pass' => '', |
| 76 | + |
| 77 | + // user preferences |
| 78 | + 'offline_subdir_status' => '', |
| 79 | + 'offline_change_subdir' => '', |
| 80 | + |
| 81 | + 'offline_change_language' => '', |
| 82 | + 'offline_live_data_preferred' => '', |
| 83 | +); |
| 84 | + |
45 | 85 | $messages['tl'] = array( |
46 | 86 | 'offline_test_article' => 'Myanmar', // a word likely to be found |
47 | 87 | ); |
Index: trunk/extensions/Offline/DatabaseBz2.php |
— | — | @@ -26,56 +26,58 @@ |
27 | 27 | |
28 | 28 | class DatabaseBz2 extends Database |
29 | 29 | { |
30 | | - function select( $table, $fields, $conds='', $fname = 'Database::select', $options = array() ) { |
31 | | - require_once(dirname(__FILE__).'/DumpReader.php'); |
32 | | - require_once(dirname(__FILE__).'/CachedStorage.php'); |
33 | | - $row = array(); |
34 | | - $title = false; |
35 | | - if (isset($conds['page_title'])) { |
36 | | - $title = $conds['page_title']; |
37 | | - if ($conds['page_namespace'] && MWNamespace::getCanonicalName($conds['page_namespace'])) |
38 | | - $title = MWNamespace::getCanonicalName($conds['page_namespace']).':'.$title; |
39 | | - } |
| 30 | + function select( $table, $fields, $conds='', $fname = 'Database::select', $options = array() ) |
| 31 | + { |
| 32 | + require_once(dirname(__FILE__).'/DumpReader.php'); |
| 33 | + require_once(dirname(__FILE__).'/CachedStorage.php'); |
| 34 | + $row = array(); |
| 35 | + $title = false; |
| 36 | + if (isset($conds['page_title'])) { |
| 37 | + $title = $conds['page_title']; |
| 38 | + if ($conds['page_namespace'] && MWNamespace::getCanonicalName($conds['page_namespace'])) |
| 39 | + $title = MWNamespace::getCanonicalName($conds['page_namespace']).':'.$title; |
| 40 | + } |
40 | 41 | |
41 | | - if ($title && ($table == 'page' || (is_array($table) && in_array('page', $table)))) { |
42 | | - if (preg_match('/Template:Pp-/i', $title)) |
43 | | - return false; |
| 42 | + if ($title && ($table == 'page' || (is_array($table) && in_array('page', $table)))) |
| 43 | + { |
| 44 | + if (preg_match('/Template:Pp-/i', $title)) |
| 45 | + return false; |
44 | 46 | |
45 | | - $textid = CachedStorage::fetchIdByTitle($title); |
46 | | - if (!$textid) { |
47 | | - $content = DumpReader::load_article($title); |
48 | | - if (!$content) { |
| 47 | + $textid = CachedStorage::fetchIdByTitle($title); |
| 48 | + if (!$textid) { |
| 49 | + $content = DumpReader::load_article($title); |
| 50 | + if (!$content) { |
49 | 51 | wfDebug('no content for '.$title); |
50 | | - return false; |
51 | | - } |
52 | | - $textid = CachedStorage::set($title, $content); |
53 | | - } |
54 | | - } elseif (isset($conds['rev_id'])) { |
55 | | - $textid = $conds['rev_id']; |
56 | | - } |
| 52 | + return false; |
| 53 | + } |
| 54 | + $textid = CachedStorage::set($title, $content); |
| 55 | + } |
| 56 | + } elseif (isset($conds['rev_id'])) { |
| 57 | + $textid = $conds['rev_id']; |
| 58 | + } |
57 | 59 | |
58 | | - if (!isset($textid)) |
59 | | - return $this->resultObject(array()); |
| 60 | + if (!isset($textid)) |
| 61 | + return $this->resultObject(array()); |
60 | 62 | |
61 | | - if ($table == 'page') { |
62 | | - // Given a page_title, get the id of text content. For efficiency, |
63 | | - // we fetch the text and store it by ID to access in case 2. |
64 | | - $row = array_fill_keys($fields, ''); |
65 | | - $row['page_id'] = $textid; |
66 | | - $row['page_title'] = $title; |
67 | | - $row['page_latest'] = $textid; |
68 | | - } |
69 | | - elseif ($table == array('page', 'revision')) { |
70 | | - // Redundantly return textid which is cache key to article wml. |
71 | | - $fields[] = 'rev_user'; |
72 | | - $fields[] = 'rev_user_text'; |
73 | | - $row = array_fill_keys($fields, ''); |
74 | | - $row['rev_id'] = $textid; |
75 | | - $row['rev_text_id'] = $textid; |
76 | | - } |
77 | | - else { print_r($table); print_r($conds); } |
| 63 | + if ($table == 'page') { |
| 64 | + // Given a page_title, get the id of text content. For efficiency, |
| 65 | + // we fetch the text and store it by ID to access in case 2. |
| 66 | + $row = array_fill_keys($fields, ''); |
| 67 | + $row['page_id'] = $textid; |
| 68 | + $row['page_title'] = $title; |
| 69 | + $row['page_latest'] = $textid; |
| 70 | + } |
| 71 | + elseif ($table == array('page', 'revision')) { |
| 72 | + // Redundantly return textid which is cache key to article wml. |
| 73 | + $fields[] = 'rev_user'; |
| 74 | + $fields[] = 'rev_user_text'; |
| 75 | + $row = array_fill_keys($fields, ''); |
| 76 | + $row['rev_id'] = $textid; |
| 77 | + $row['rev_text_id'] = $textid; |
| 78 | + } |
| 79 | + else { print_r($table); print_r($conds); } |
78 | 80 | |
79 | | - return $this->resultObject($row); |
| 81 | + return $this->resultObject($row); |
80 | 82 | } |
81 | 83 | |
82 | 84 | |
— | — | @@ -85,470 +87,470 @@ |
86 | 88 | #------------------------------------------------------------------------------ |
87 | 89 | # Accessors |
88 | 90 | #------------------------------------------------------------------------------ |
89 | | - function failFunction( $function = NULL ) { |
90 | | - return null; |
91 | | - } |
| 91 | + function failFunction( $function = NULL ) { |
| 92 | + return null; |
| 93 | + } |
92 | 94 | |
93 | | - function setOutputPage( $out ) { |
94 | | - return null; |
95 | | - } |
| 95 | + function setOutputPage( $out ) { |
| 96 | + return null; |
| 97 | + } |
96 | 98 | |
97 | | - function debug( $debug = NULL ) { |
98 | | - return null; |
99 | | - } |
| 99 | + function debug( $debug = NULL ) { |
| 100 | + return null; |
| 101 | + } |
100 | 102 | |
101 | | - function bufferResults( $buffer = NULL ) { |
102 | | - return null; |
103 | | - } |
| 103 | + function bufferResults( $buffer = NULL ) { |
| 104 | + return null; |
| 105 | + } |
104 | 106 | |
105 | | - function ignoreErrors( $ignoreErrors = NULL ) { |
106 | | - return true; |
107 | | - } |
| 107 | + function ignoreErrors( $ignoreErrors = NULL ) { |
| 108 | + return true; |
| 109 | + } |
108 | 110 | |
109 | | - function trxLevel( $level = NULL ) { |
110 | | - return 0; |
111 | | - } |
| 111 | + function trxLevel( $level = NULL ) { |
| 112 | + return 0; |
| 113 | + } |
112 | 114 | |
113 | | - function errorCount( $count = NULL ) { |
114 | | - return 0; |
115 | | - } |
| 115 | + function errorCount( $count = NULL ) { |
| 116 | + return 0; |
| 117 | + } |
116 | 118 | |
117 | | - function getLBInfo( $name = NULL ) { |
118 | | - return true; |
119 | | - } |
| 119 | + function getLBInfo( $name = NULL ) { |
| 120 | + return true; |
| 121 | + } |
120 | 122 | |
121 | | - function setLBInfo( $name, $value = NULL ) { |
122 | | - return true; |
123 | | - } |
| 123 | + function setLBInfo( $name, $value = NULL ) { |
| 124 | + return true; |
| 125 | + } |
124 | 126 | |
125 | | - function cascadingDeletes() { |
126 | | - return false; |
127 | | - } |
| 127 | + function cascadingDeletes() { |
| 128 | + return false; |
| 129 | + } |
128 | 130 | |
129 | | - function cleanupTriggers() { |
130 | | - return false; |
131 | | - } |
| 131 | + function cleanupTriggers() { |
| 132 | + return false; |
| 133 | + } |
132 | 134 | |
133 | | - function strictIPs() { |
134 | | - return false; |
135 | | - } |
| 135 | + function strictIPs() { |
| 136 | + return false; |
| 137 | + } |
136 | 138 | |
137 | | - function realTimestamps() { |
138 | | - return false; |
139 | | - } |
| 139 | + function realTimestamps() { |
| 140 | + return false; |
| 141 | + } |
140 | 142 | |
141 | | - function implicitGroupby() { |
142 | | - return true; |
143 | | - } |
| 143 | + function implicitGroupby() { |
| 144 | + return true; |
| 145 | + } |
144 | 146 | |
145 | | - function implicitOrderby() { |
146 | | - return true; |
147 | | - } |
| 147 | + function implicitOrderby() { |
| 148 | + return true; |
| 149 | + } |
148 | 150 | |
149 | | - function searchableIPs() { |
150 | | - return false; |
151 | | - } |
| 151 | + function searchableIPs() { |
| 152 | + return false; |
| 153 | + } |
152 | 154 | |
153 | | - function functionalIndexes() { |
154 | | - return false; |
155 | | - } |
| 155 | + function functionalIndexes() { |
| 156 | + return false; |
| 157 | + } |
156 | 158 | |
157 | | - function lastQuery() { |
158 | | - return true; |
159 | | - } |
160 | | - function isOpen() { |
161 | | - return true; |
162 | | - } |
| 159 | + function lastQuery() { |
| 160 | + return true; |
| 161 | + } |
| 162 | + function isOpen() { |
| 163 | + return true; |
| 164 | + } |
163 | 165 | |
164 | | - function setFlag( $flag ) { |
165 | | - return true; |
166 | | - } |
| 166 | + function setFlag( $flag ) { |
| 167 | + return true; |
| 168 | + } |
167 | 169 | |
168 | | - function clearFlag( $flag ) { |
169 | | - return true; |
170 | | - } |
| 170 | + function clearFlag( $flag ) { |
| 171 | + return true; |
| 172 | + } |
171 | 173 | |
172 | | - function getFlag( $flag ) { |
173 | | - return true; |
174 | | - } |
| 174 | + function getFlag( $flag ) { |
| 175 | + return true; |
| 176 | + } |
175 | 177 | |
176 | | - function getProperty( $name ) { |
177 | | - return true; |
178 | | - } |
| 178 | + function getProperty( $name ) { |
| 179 | + return true; |
| 180 | + } |
179 | 181 | |
180 | 182 | |
181 | | - function __construct( $server = false, $user = false, $password = false, $dbName = false, |
182 | | - $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) { |
183 | | - null; |
184 | | - } |
| 183 | + function __construct( $server = false, $user = false, $password = false, $dbName = false, |
| 184 | + $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) { |
| 185 | + null; |
| 186 | + } |
185 | 187 | |
186 | | - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 ) { |
187 | | - return new Database( $server, $user, $password, $dbName, $failFunction, $flags ); |
188 | | - } |
| 188 | + static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 ) { |
| 189 | + return new Database( $server, $user, $password, $dbName, $failFunction, $flags ); |
| 190 | + } |
189 | 191 | |
190 | | - function open( $server, $user, $password, $dbName ) { |
| 192 | + function open( $server, $user, $password, $dbName ) { |
191 | 193 | //TODO test article load using TestDumpReader |
192 | | - return true; |
193 | | - } |
| 194 | + return true; |
| 195 | + } |
194 | 196 | |
195 | | - function close() { |
196 | | - return true; |
197 | | - } |
| 197 | + function close() { |
| 198 | + return true; |
| 199 | + } |
198 | 200 | |
199 | | - function reportConnectionError( $error = 'Unknown error' ) { |
200 | | - return null; |
201 | | - } |
| 201 | + function reportConnectionError( $error = 'Unknown error' ) { |
| 202 | + return null; |
| 203 | + } |
202 | 204 | |
203 | | - public function query( $sql, $fname = '', $tempIgnore = false ) { |
204 | | - return null; |
205 | | - } |
| 205 | + public function query( $sql, $fname = '', $tempIgnore = false ) { |
| 206 | + return null; |
| 207 | + } |
206 | 208 | |
207 | | - function doQuery( $sql ) { |
208 | | - return true; |
209 | | - } |
| 209 | + function doQuery( $sql ) { |
| 210 | + return true; |
| 211 | + } |
210 | 212 | |
211 | | - function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) { |
212 | | - return null; |
213 | | - } |
| 213 | + function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) { |
| 214 | + return null; |
| 215 | + } |
214 | 216 | |
215 | 217 | |
216 | | - function prepare( $sql, $func = 'Database::prepare' ) { |
217 | | - return null; |
218 | | - } |
| 218 | + function prepare( $sql, $func = 'Database::prepare' ) { |
| 219 | + return null; |
| 220 | + } |
219 | 221 | |
220 | | - function freePrepared( $prepared ) { |
221 | | - return null; |
222 | | - } |
| 222 | + function freePrepared( $prepared ) { |
| 223 | + return null; |
| 224 | + } |
223 | 225 | |
224 | | - function execute( $prepared, $args = null ) { |
225 | | - return true; |
226 | | - } |
| 226 | + function execute( $prepared, $args = null ) { |
| 227 | + return true; |
| 228 | + } |
227 | 229 | |
228 | | - function safeQuery( $query, $args = null ) { |
229 | | - return true; |
230 | | - } |
| 230 | + function safeQuery( $query, $args = null ) { |
| 231 | + return true; |
| 232 | + } |
231 | 233 | |
232 | | - function fillPrepared( $preparedQuery, $args ) { |
233 | | - return true; |
234 | | - } |
| 234 | + function fillPrepared( $preparedQuery, $args ) { |
| 235 | + return true; |
| 236 | + } |
235 | 237 | |
236 | | - function fillPreparedArg( $matches ) { |
237 | | - return true; |
238 | | - } |
| 238 | + function fillPreparedArg( $matches ) { |
| 239 | + return true; |
| 240 | + } |
239 | 241 | |
240 | | - function freeResult( $res ) { |
241 | | - return null; |
242 | | - } |
| 242 | + function freeResult( $res ) { |
| 243 | + return null; |
| 244 | + } |
243 | 245 | |
244 | | - function fetchObject( $res ) { |
245 | | - // cast to object |
246 | | - if (!$res) |
247 | | - return false; |
| 246 | + function fetchObject( $res ) { |
| 247 | + // cast to object |
| 248 | + if (!$res) |
| 249 | + return false; |
248 | 250 | |
249 | | - $array = $res->result; |
250 | | - if(!is_array($array)) { |
251 | | - return $array; |
252 | | - } |
253 | | - |
254 | | - $object = new stdClass(); |
255 | | - if (is_array($array) && count($array) > 0) { |
256 | | - foreach ($array as $name=>$value) { |
257 | | - if (!empty($name)) { |
258 | | - $object->$name = $value; |
259 | | - } |
260 | | - } |
261 | | - return $object; |
262 | | - } |
263 | | - else { |
264 | | - return false; |
265 | | - } |
266 | | - } |
| 251 | + $array = $res->result; |
| 252 | + if(!is_array($array)) { |
| 253 | + return $array; |
| 254 | + } |
| 255 | + |
| 256 | + $object = new stdClass(); |
| 257 | + if (is_array($array) && count($array) > 0) { |
| 258 | + foreach ($array as $name=>$value) { |
| 259 | + if (!empty($name)) { |
| 260 | + $object->$name = $value; |
| 261 | + } |
| 262 | + } |
| 263 | + return $object; |
| 264 | + } |
| 265 | + else { |
| 266 | + return false; |
| 267 | + } |
| 268 | + } |
267 | 269 | |
268 | | - function fetchRow( $res ) { |
269 | | - return null; |
270 | | - } |
| 270 | + function fetchRow( $res ) { |
| 271 | + return null; |
| 272 | + } |
271 | 273 | |
272 | | - function numRows( $res ) { |
273 | | - return 0; |
274 | | - } |
| 274 | + function numRows( $res ) { |
| 275 | + return 0; |
| 276 | + } |
275 | 277 | |
276 | | - function numFields( $res ) { |
277 | | - return 0; |
278 | | - } |
| 278 | + function numFields( $res ) { |
| 279 | + return 0; |
| 280 | + } |
279 | 281 | |
280 | | - function fieldName( $res, $n ) { |
281 | | - return true; |
282 | | - } |
| 282 | + function fieldName( $res, $n ) { |
| 283 | + return true; |
| 284 | + } |
283 | 285 | |
284 | | - function insertId() { |
285 | | - return null; |
286 | | - } |
| 286 | + function insertId() { |
| 287 | + return null; |
| 288 | + } |
287 | 289 | |
288 | | - function dataSeek( $res, $row ) { |
289 | | - return true; |
290 | | - } |
| 290 | + function dataSeek( $res, $row ) { |
| 291 | + return true; |
| 292 | + } |
291 | 293 | |
292 | | - function lastErrno() { |
293 | | - return null; |
294 | | - } |
| 294 | + function lastErrno() { |
| 295 | + return null; |
| 296 | + } |
295 | 297 | |
296 | | - function lastError() { |
297 | | - return null; |
298 | | - } |
| 298 | + function lastError() { |
| 299 | + return null; |
| 300 | + } |
299 | 301 | |
300 | | - function affectedRows() { |
301 | | - return 0; |
302 | | - } |
| 302 | + function affectedRows() { |
| 303 | + return 0; |
| 304 | + } |
303 | 305 | |
304 | | - function set( $table, $var, $value, $cond, $fname = 'Database::set' ) { |
305 | | - return null; |
306 | | - } |
| 306 | + function set( $table, $var, $value, $cond, $fname = 'Database::set' ) { |
| 307 | + return null; |
| 308 | + } |
307 | 309 | |
308 | | - function selectField( $table, $var, $cond='', $fname = 'Database::selectField', $options = array() ) { |
309 | | - return $this->fetchObject($this->select($table, array($var), $cond)); |
310 | | - } |
| 310 | + function selectField( $table, $var, $cond='', $fname = 'Database::selectField', $options = array() ) { |
| 311 | + return $this->fetchObject($this->select($table, array($var), $cond)); |
| 312 | + } |
311 | 313 | |
312 | | - function makeSelectOptions( $options ) { |
313 | | - return null; |
314 | | - } |
| 314 | + function makeSelectOptions( $options ) { |
| 315 | + return null; |
| 316 | + } |
315 | 317 | |
316 | | - function selectRow( $table, $vars, $conds, $fname = 'Database::selectRow', $options = array() ) { |
317 | | - return $this->fetchObject($this->select($table, $vars, $conds)); |
318 | | - } |
| 318 | + function selectRow( $table, $vars, $conds, $fname = 'Database::selectRow', $options = array() ) { |
| 319 | + return $this->fetchObject($this->select($table, $vars, $conds)); |
| 320 | + } |
319 | 321 | |
320 | | - function estimateRowCount( $table, $vars='*', $conds='', $fname = 'Database::estimateRowCount', $options = array() ) { |
321 | | - return 0; |
322 | | - } |
323 | | - |
| 322 | + function estimateRowCount( $table, $vars='*', $conds='', $fname = 'Database::estimateRowCount', $options = array() ) { |
| 323 | + return 0; |
| 324 | + } |
| 325 | + |
324 | 326 | |
325 | | - static function generalizeSQL( $sql ) { |
326 | | - return null; |
327 | | - } |
| 327 | + static function generalizeSQL( $sql ) { |
| 328 | + return null; |
| 329 | + } |
328 | 330 | |
329 | | - function fieldExists( $table, $field, $fname = 'Database::fieldExists' ) { |
330 | | - return null; |
331 | | - } |
| 331 | + function fieldExists( $table, $field, $fname = 'Database::fieldExists' ) { |
| 332 | + return null; |
| 333 | + } |
332 | 334 | |
333 | | - function indexExists( $table, $index, $fname = 'Database::indexExists' ) { |
334 | | - return null; |
335 | | - } |
| 335 | + function indexExists( $table, $index, $fname = 'Database::indexExists' ) { |
| 336 | + return null; |
| 337 | + } |
336 | 338 | |
337 | 339 | |
338 | | - function indexInfo( $table, $index, $fname = 'Database::indexInfo' ) { |
339 | | - return null; |
340 | | - } |
| 340 | + function indexInfo( $table, $index, $fname = 'Database::indexInfo' ) { |
| 341 | + return null; |
| 342 | + } |
341 | 343 | |
342 | | - function tableExists( $table ) { |
343 | | - return null; |
344 | | - } |
| 344 | + function tableExists( $table ) { |
| 345 | + return null; |
| 346 | + } |
345 | 347 | |
346 | | - function fieldInfo( $table, $field ) { |
347 | | - return null; |
348 | | - } |
| 348 | + function fieldInfo( $table, $field ) { |
| 349 | + return null; |
| 350 | + } |
349 | 351 | |
350 | | - function fieldType( $res, $index ) { |
351 | | - return null; |
352 | | - } |
| 352 | + function fieldType( $res, $index ) { |
| 353 | + return null; |
| 354 | + } |
353 | 355 | |
354 | | - function indexUnique( $table, $index ) { |
355 | | - return null; |
356 | | - } |
| 356 | + function indexUnique( $table, $index ) { |
| 357 | + return null; |
| 358 | + } |
357 | 359 | |
358 | | - function insert( $table, $a, $fname = 'Database::insert', $options = array() ) { |
359 | | - return null; |
360 | | - } |
| 360 | + function insert( $table, $a, $fname = 'Database::insert', $options = array() ) { |
| 361 | + return null; |
| 362 | + } |
361 | 363 | |
362 | | - function makeUpdateOptions( $options ) { |
363 | | - return null; |
364 | | - } |
| 364 | + function makeUpdateOptions( $options ) { |
| 365 | + return null; |
| 366 | + } |
365 | 367 | |
366 | | - function update( $table, $values, $conds, $fname = 'Database::update', $options = array() ) { |
367 | | - return null; |
368 | | - } |
| 368 | + function update( $table, $values, $conds, $fname = 'Database::update', $options = array() ) { |
| 369 | + return null; |
| 370 | + } |
369 | 371 | |
370 | | - function makeList( $a, $mode = LIST_COMMA ) { |
371 | | - return null; |
372 | | - } |
| 372 | + function makeList( $a, $mode = LIST_COMMA ) { |
| 373 | + return null; |
| 374 | + } |
373 | 375 | |
374 | | - function selectDB( $db ) { |
375 | | - return null; |
376 | | - } |
| 376 | + function selectDB( $db ) { |
| 377 | + return null; |
| 378 | + } |
377 | 379 | |
378 | | - function tableName( $name ) { |
379 | | - return null; |
380 | | - } |
| 380 | + function tableName( $name ) { |
| 381 | + return null; |
| 382 | + } |
381 | 383 | |
382 | | - public function tableNames() { |
383 | | - return null; |
384 | | - } |
| 384 | + public function tableNames() { |
| 385 | + return null; |
| 386 | + } |
385 | 387 | |
386 | | - public function tableNamesN() { |
387 | | - return null; |
388 | | - } |
| 388 | + public function tableNamesN() { |
| 389 | + return null; |
| 390 | + } |
389 | 391 | |
390 | | - function tableNamesWithUseIndex( $tables, $use_index ) { |
391 | | - return null; |
392 | | - } |
| 392 | + function tableNamesWithUseIndex( $tables, $use_index ) { |
| 393 | + return null; |
| 394 | + } |
393 | 395 | |
394 | | - function strencode( $s ) { |
395 | | - return true; |
396 | | - } |
| 396 | + function strencode( $s ) { |
| 397 | + return true; |
| 398 | + } |
397 | 399 | |
398 | | - function addQuotes( $s ) { |
399 | | - return true; |
400 | | - } |
| 400 | + function addQuotes( $s ) { |
| 401 | + return true; |
| 402 | + } |
401 | 403 | |
402 | | - function escapeLike( $s ) { |
403 | | - return true; |
404 | | - } |
| 404 | + function escapeLike( $s ) { |
| 405 | + return true; |
| 406 | + } |
405 | 407 | |
406 | | - function nextSequenceValue( $seqName ) { |
407 | | - return null; |
408 | | - } |
| 408 | + function nextSequenceValue( $seqName ) { |
| 409 | + return null; |
| 410 | + } |
409 | 411 | |
410 | | - function useIndexClause( $index ) { |
411 | | - return true; |
412 | | - } |
| 412 | + function useIndexClause( $index ) { |
| 413 | + return true; |
| 414 | + } |
413 | 415 | |
414 | | - function replace( $table, $uniqueIndexes, $rows, $fname = 'Database::replace' ) { |
415 | | - return null; |
416 | | - } |
| 416 | + function replace( $table, $uniqueIndexes, $rows, $fname = 'Database::replace' ) { |
| 417 | + return null; |
| 418 | + } |
417 | 419 | |
418 | | - function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'Database::deleteJoin' ) { |
419 | | - return null; |
420 | | - } |
| 420 | + function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'Database::deleteJoin' ) { |
| 421 | + return null; |
| 422 | + } |
421 | 423 | |
422 | | - function textFieldSize( $table, $field ) { |
423 | | - return null; |
424 | | - } |
| 424 | + function textFieldSize( $table, $field ) { |
| 425 | + return null; |
| 426 | + } |
425 | 427 | |
426 | | - function lowPriorityOption() { |
427 | | - } |
| 428 | + function lowPriorityOption() { |
| 429 | + } |
428 | 430 | |
429 | | - function delete( $table, $conds, $fname = 'Database::delete' ) { |
430 | | - return true; |
431 | | - } |
| 431 | + function delete( $table, $conds, $fname = 'Database::delete' ) { |
| 432 | + return true; |
| 433 | + } |
432 | 434 | |
433 | | - function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = 'Database::insertSelect', |
434 | | - $insertOptions = array(), $selectOptions = array() ) |
435 | | - { |
436 | | - return null; |
437 | | - } |
| 435 | + function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = 'Database::insertSelect', |
| 436 | + $insertOptions = array(), $selectOptions = array() ) |
| 437 | + { |
| 438 | + return null; |
| 439 | + } |
438 | 440 | |
439 | | - function limitResult($sql, $limit, $offset=false) { |
440 | | - return null; |
441 | | - } |
| 441 | + function limitResult($sql, $limit, $offset=false) { |
| 442 | + return null; |
| 443 | + } |
442 | 444 | |
443 | | - function limitResultForUpdate($sql, $num) { |
444 | | - return null; |
445 | | - } |
| 445 | + function limitResultForUpdate($sql, $num) { |
| 446 | + return null; |
| 447 | + } |
446 | 448 | |
447 | | - function conditional( $cond, $trueVal, $falseVal ) { |
448 | | - return null; |
449 | | - } |
| 449 | + function conditional( $cond, $trueVal, $falseVal ) { |
| 450 | + return null; |
| 451 | + } |
450 | 452 | |
451 | | - function wasDeadlock() { |
452 | | - return null; |
453 | | - } |
| 453 | + function wasDeadlock() { |
| 454 | + return null; |
| 455 | + } |
454 | 456 | |
455 | | - function deadlockLoop() { |
456 | | - return null; |
457 | | - } |
| 457 | + function deadlockLoop() { |
| 458 | + return null; |
| 459 | + } |
458 | 460 | |
459 | | - function masterPosWait( $file, $pos, $timeout ) { |
460 | | - return null; |
461 | | - } |
| 461 | + function masterPosWait( $file, $pos, $timeout ) { |
| 462 | + return null; |
| 463 | + } |
462 | 464 | |
463 | | - function getSlavePos() { |
464 | | - return null; |
465 | | - } |
| 465 | + function getSlavePos() { |
| 466 | + return null; |
| 467 | + } |
466 | 468 | |
467 | | - function getMasterPos() { |
468 | | - return null; |
469 | | - } |
| 469 | + function getMasterPos() { |
| 470 | + return null; |
| 471 | + } |
470 | 472 | |
471 | | - function begin( $fname = 'Database::begin' ) { |
472 | | - } |
| 473 | + function begin( $fname = 'Database::begin' ) { |
| 474 | + } |
473 | 475 | |
474 | | - function commit( $fname = 'Database::commit' ) { |
475 | | - } |
| 476 | + function commit( $fname = 'Database::commit' ) { |
| 477 | + } |
476 | 478 | |
477 | | - function rollback( $fname = 'Database::rollback' ) { |
478 | | - } |
| 479 | + function rollback( $fname = 'Database::rollback' ) { |
| 480 | + } |
479 | 481 | |
480 | | - function immediateBegin( $fname = 'Database::immediateBegin' ) { |
481 | | - } |
| 482 | + function immediateBegin( $fname = 'Database::immediateBegin' ) { |
| 483 | + } |
482 | 484 | |
483 | | - function immediateCommit( $fname = 'Database::immediateCommit' ) { |
484 | | - } |
| 485 | + function immediateCommit( $fname = 'Database::immediateCommit' ) { |
| 486 | + } |
485 | 487 | |
486 | | - function timestamp( $ts=0 ) { |
487 | | - } |
| 488 | + function timestamp( $ts=0 ) { |
| 489 | + } |
488 | 490 | |
489 | | - function timestampOrNull( $ts = null ) { |
490 | | - } |
| 491 | + function timestampOrNull( $ts = null ) { |
| 492 | + } |
491 | 493 | |
492 | | - function resultObject( $result ) { |
493 | | - return new ResultWrapper($this, $result); |
494 | | - } |
| 494 | + function resultObject( $result ) { |
| 495 | + return new ResultWrapper($this, $result); |
| 496 | + } |
495 | 497 | |
496 | | - function aggregateValue ($valuedata,$valuename='value') { |
497 | | - } |
| 498 | + function aggregateValue ($valuedata,$valuename='value') { |
| 499 | + } |
498 | 500 | |
499 | | - static function getSoftwareLink() { |
500 | | - return "[http://www.mysql.com/ MySQL]"; |
501 | | - } |
| 501 | + static function getSoftwareLink() { |
| 502 | + return "[http://www.mysql.com/ MySQL]"; |
| 503 | + } |
502 | 504 | |
503 | | - function getServerVersion() { |
504 | | - } |
| 505 | + function getServerVersion() { |
| 506 | + } |
505 | 507 | |
506 | | - function ping() { |
507 | | - return true; |
508 | | - } |
| 508 | + function ping() { |
| 509 | + return true; |
| 510 | + } |
509 | 511 | |
510 | | - function getLag() { |
511 | | - return 0; |
512 | | - } |
| 512 | + function getLag() { |
| 513 | + return 0; |
| 514 | + } |
513 | 515 | |
514 | | - function getStatus($which="%") { |
515 | | - return true; |
516 | | - } |
| 516 | + function getStatus($which="%") { |
| 517 | + return true; |
| 518 | + } |
517 | 519 | |
518 | | - function maxListLen() { |
519 | | - return 0; |
520 | | - } |
| 520 | + function maxListLen() { |
| 521 | + return 0; |
| 522 | + } |
521 | 523 | |
522 | | - function encodeBlob($b) { |
523 | | - return $b; |
524 | | - } |
| 524 | + function encodeBlob($b) { |
| 525 | + return $b; |
| 526 | + } |
525 | 527 | |
526 | | - function decodeBlob($b) { |
527 | | - return $b; |
528 | | - } |
| 528 | + function decodeBlob($b) { |
| 529 | + return $b; |
| 530 | + } |
529 | 531 | |
530 | | - public function setTimeout( $timeout ) { |
531 | | - } |
| 532 | + public function setTimeout( $timeout ) { |
| 533 | + } |
532 | 534 | |
533 | | - function sourceFile( $filename, $lineCallback = false, $resultCallback = false ) { |
534 | | - return null; |
535 | | - } |
| 535 | + function sourceFile( $filename, $lineCallback = false, $resultCallback = false ) { |
| 536 | + return null; |
| 537 | + } |
536 | 538 | |
537 | | - function sourceStream( $fp, $lineCallback = false, $resultCallback = false ) { |
538 | | - return true; |
539 | | - } |
| 539 | + function sourceStream( $fp, $lineCallback = false, $resultCallback = false ) { |
| 540 | + return true; |
| 541 | + } |
540 | 542 | |
541 | 543 | |
542 | | - protected function replaceVars( $ins ) { |
543 | | - return true; |
544 | | - } |
| 544 | + protected function replaceVars( $ins ) { |
| 545 | + return true; |
| 546 | + } |
545 | 547 | |
546 | | - protected function tableNameCallback( $matches ) { |
547 | | - } |
| 548 | + protected function tableNameCallback( $matches ) { |
| 549 | + } |
548 | 550 | |
549 | | - /* |
550 | | - * Build a concatenation list to feed into a SQL query |
551 | | - */ |
552 | | - function buildConcat( $stringList ) { |
553 | | - return true; |
554 | | - } |
| 551 | + /* |
| 552 | + * Build a concatenation list to feed into a SQL query |
| 553 | + */ |
| 554 | + function buildConcat( $stringList ) { |
| 555 | + return true; |
| 556 | + } |
555 | 557 | } |
Index: trunk/extensions/Offline/Offline.php |
— | — | @@ -29,16 +29,16 @@ |
30 | 30 | |
31 | 31 | // TODO -> mediawiki: |
32 | 32 | if ( !$wgDBservers ) { |
33 | | - global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype, $wgDebugDumpSql; |
34 | | - $wgDBservers = array(array( |
35 | | - 'host' => $wgDBserver, |
36 | | - 'user' => $wgDBuser, |
37 | | - 'password' => $wgDBpassword, |
38 | | - 'dbname' => $wgDBname, |
39 | | - 'type' => $wgDBtype, |
40 | | - 'load' => 1, |
41 | | - 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT |
42 | | - )); |
| 33 | + global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype, $wgDebugDumpSql; |
| 34 | + $wgDBservers = array(array( |
| 35 | + 'host' => $wgDBserver, |
| 36 | + 'user' => $wgDBuser, |
| 37 | + 'password' => $wgDBpassword, |
| 38 | + 'dbname' => $wgDBname, |
| 39 | + 'type' => $wgDBtype, |
| 40 | + 'load' => 1, |
| 41 | + 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT |
| 42 | + )); |
43 | 43 | } |
44 | 44 | |
45 | 45 | |
— | — | @@ -46,12 +46,12 @@ |
47 | 47 | // Dump reader will be called through a very single-minded sql api. |
48 | 48 | //$wgDBservers[] = array( // fixme: you can only do this if your primary db will successfully connect(). |
49 | 49 | $wgDBservers[] = array( |
50 | | - 'dbname' => $wgOfflineWikiPath, |
51 | | - 'type' => 'bz2', |
52 | | - 'load' => 1, |
53 | | - 'host' => false, |
54 | | - 'user' => false, |
55 | | - 'flags' => false, |
56 | | - 'password' => false, |
| 50 | + 'dbname' => $wgOfflineWikiPath, |
| 51 | + 'type' => 'bz2', |
| 52 | + 'load' => 1, |
| 53 | + 'host' => false, |
| 54 | + 'user' => false, |
| 55 | + 'flags' => false, |
| 56 | + 'password' => false, |
57 | 57 | ); |
58 | 58 | } |
Index: trunk/extensions/Offline/SearchBz2.php |
— | — | @@ -10,97 +10,97 @@ |
11 | 11 | * @ingroup Search |
12 | 12 | */ |
13 | 13 | class SearchBz2 extends SearchEngine { |
14 | | - var $strictMatching = true; |
15 | | - static $mMinSearchLength; |
| 14 | + var $strictMatching = true; |
| 15 | + static $mMinSearchLength; |
16 | 16 | |
17 | | - function __construct( $db ) { |
18 | | - $this->db = $db; |
19 | | - } |
| 17 | + function __construct( $db ) { |
| 18 | + $this->db = $db; |
| 19 | + } |
20 | 20 | |
21 | | - /** |
22 | | - * Parse the user's query and transform it into an SQL fragment which will |
23 | | - * become part of a WHERE clause |
24 | | - */ |
25 | | - function parseQuery( $filteredText, $fulltext ) { |
26 | | - return $filteredText; |
27 | | - } |
28 | | - |
29 | | - /** |
30 | | - * Perform a full text search query and return a result set. |
31 | | - * |
32 | | - * @param $term String: raw search term |
33 | | - * @return MySQLSearchResultSet |
34 | | - */ |
35 | | - function searchText( $term ) { |
36 | | - return $this->searchInternal( $term, true ); |
37 | | - } |
| 21 | + /** |
| 22 | + * Parse the user's query and transform it into an SQL fragment which will |
| 23 | + * become part of a WHERE clause |
| 24 | + */ |
| 25 | + function parseQuery( $filteredText, $fulltext ) { |
| 26 | + return $filteredText; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Perform a full text search query and return a result set. |
| 31 | + * |
| 32 | + * @param $term String: raw search term |
| 33 | + * @return MySQLSearchResultSet |
| 34 | + */ |
| 35 | + function searchText( $term ) { |
| 36 | + return $this->searchInternal( $term, true ); |
| 37 | + } |
38 | 38 | |
39 | | - /** |
40 | | - * Perform a title-only search query and return a result set. |
41 | | - * |
42 | | - * @param $term String: raw search term |
43 | | - * @return Bz2SearchResultSet |
44 | | - */ |
45 | | - function searchTitle( $term ) { |
46 | | - return $this->searchInternal( $term, false ); |
47 | | - } |
48 | | - |
49 | | - protected function searchInternal( $term, $fulltext ) { |
50 | | - global $wgCountTotalSearchHits; |
51 | | - |
52 | | - require_once(dirname(__FILE__).'/DumpReader.php'); |
53 | | - $results = DumpReader::index_search($term); |
| 39 | + /** |
| 40 | + * Perform a title-only search query and return a result set. |
| 41 | + * |
| 42 | + * @param $term String: raw search term |
| 43 | + * @return Bz2SearchResultSet |
| 44 | + */ |
| 45 | + function searchTitle( $term ) { |
| 46 | + return $this->searchInternal( $term, false ); |
| 47 | + } |
| 48 | + |
| 49 | + protected function searchInternal( $term, $fulltext ) { |
| 50 | + global $wgCountTotalSearchHits; |
| 51 | + |
| 52 | + require_once(dirname(__FILE__).'/DumpReader.php'); |
| 53 | + $results = DumpReader::index_search($term); |
54 | 54 | |
55 | | - return new Bz2SearchResultSet( $results, $term); |
56 | | - } |
| 55 | + return new Bz2SearchResultSet( $results, $term); |
| 56 | + } |
57 | 57 | // TODO |
58 | | -// function queryNamespaces() { |
| 58 | +// function queryNamespaces() { |
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | 62 | * @ingroup Search |
63 | 63 | */ |
64 | 64 | class Bz2SearchResultSet extends SearchResultSet { |
65 | | - function Bz2SearchResultSet($results, $terms) { |
66 | | - $this->mTotalHits = count($results); |
67 | | - $this->mResultSet = $results; |
68 | | - $this->mTerms = $terms; |
69 | | - } |
| 65 | + function Bz2SearchResultSet($results, $terms) { |
| 66 | + $this->mTotalHits = count($results); |
| 67 | + $this->mResultSet = $results; |
| 68 | + $this->mTerms = $terms; |
| 69 | + } |
70 | 70 | |
71 | | - function termMatches() { |
72 | | - return $this->mTerms; |
73 | | - } |
| 71 | + function termMatches() { |
| 72 | + return $this->mTerms; |
| 73 | + } |
74 | 74 | |
75 | | - function numRows() { |
76 | | - return $this->getTotalHits(); |
77 | | - } |
| 75 | + function numRows() { |
| 76 | + return $this->getTotalHits(); |
| 77 | + } |
78 | 78 | |
79 | | - function getTotalHits() { |
80 | | - return $this->mTotalHits; |
81 | | - } |
| 79 | + function getTotalHits() { |
| 80 | + return $this->mTotalHits; |
| 81 | + } |
82 | 82 | |
83 | | - function next() { |
84 | | - if ($this->mResultSet === false || count($this->mResultSet) < 1) |
85 | | - return false; |
| 83 | + function next() { |
| 84 | + if ($this->mResultSet === false || count($this->mResultSet) < 1) |
| 85 | + return false; |
86 | 86 | |
87 | | - $result = array_pop($this->mResultSet); |
88 | | - if ($result === false) |
89 | | - return false; |
| 87 | + $result = array_pop($this->mResultSet); |
| 88 | + if ($result === false) |
| 89 | + return false; |
90 | 90 | |
91 | | - list ($bzfile, $offset, $title) = $result; |
| 91 | + list ($bzfile, $offset, $title) = $result; |
92 | 92 | |
93 | | - $matches = array(); |
94 | | - $row = new stdClass(); |
95 | | - if (preg_match('/([^:]*):([^:]+)$/', $title, $matches)) { |
| 93 | + $matches = array(); |
| 94 | + $row = new stdClass(); |
| 95 | + if (preg_match('/([^:]*):([^:]+)$/', $title, $matches)) { |
96 | 96 | //TODO lookup index |
97 | | - $row->page_namespace = $matches[1]; |
98 | | - $row->page_title = $matches[2]; |
99 | | - } else { |
100 | | - $row->page_namespace = NS_MAIN; |
101 | | - $row->page_title = $title; |
102 | | - } |
| 97 | + $row->page_namespace = $matches[1]; |
| 98 | + $row->page_title = $matches[2]; |
| 99 | + } else { |
| 100 | + $row->page_namespace = NS_MAIN; |
| 101 | + $row->page_title = $title; |
| 102 | + } |
103 | 103 | |
104 | 104 | //wfDebug('GOT'.$row->page_namespace .' : '. $row->page_title .'('.$bzfile.')'); |
105 | | - return new SearchResult($row); |
106 | | - } |
| 105 | + return new SearchResult($row); |
| 106 | + } |
107 | 107 | } |
Index: trunk/extensions/Offline/SpecialOffline.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | 'url' => 'http://code.google.com/p/wikipedia-offline-patch', |
16 | 16 | 'version' => '0.6', |
17 | 17 | 'descriptionmsg' => 'offline_special_desc' |
18 | | - ); |
| 18 | +); |
19 | 19 | |
20 | 20 | $dir = dirname(__FILE__); |
21 | 21 | $wgExtensionMessagesFiles['SpecialOffline'] = $dir.'/SpecialOffline.i18n.php'; |
— | — | @@ -22,145 +22,145 @@ |
23 | 23 | class SpecialOffline extends SpecialPage |
24 | 24 | { |
25 | 25 | function SpecialOffline() { |
26 | | - parent::__construct('offline' /*, 'editinterface' */); |
| 26 | + parent::__construct('offline' /*, 'editinterface' */); |
27 | 27 | } |
28 | 28 | |
29 | 29 | function execute($param) { |
30 | | - global $wgOut, $wgTitle; |
| 30 | + global $wgOut, $wgTitle; |
31 | 31 | |
32 | | - require_once(dirname(__FILE__).'/DumpReader.php'); |
| 32 | + require_once(dirname(__FILE__).'/DumpReader.php'); |
33 | 33 | |
34 | | - $this->setHeaders(); |
35 | | - $this->outputHeader(); |
| 34 | + $this->setHeaders(); |
| 35 | + $this->outputHeader(); |
36 | 36 | |
37 | | - $this->runTests(); |
| 37 | + $this->runTests(); |
38 | 38 | |
39 | | - //TODO report and explain wgOfflineIgnoreLiveData |
| 39 | + //TODO report and explain wgOfflineIgnoreLiveData |
40 | 40 | } |
41 | 41 | |
42 | 42 | function runTests() { |
43 | | - global $wgOut, $wgTitle; |
| 43 | + global $wgOut, $wgTitle; |
44 | 44 | |
45 | | - $wgOut->wrapWikiMsg('<h1>$1</h1>', 'offline_heading_status'); |
| 45 | + $wgOut->wrapWikiMsg('<h1>$1</h1>', 'offline_heading_status'); |
46 | 46 | |
47 | | - $wgOut->addHTML('<ul>'); |
48 | | - // lookup a real article in the index can be searched |
49 | | - $results = DumpReader::index_search(wfMsg('offline_test_article')); |
50 | | - if (count($results) > 0) |
51 | | - list ($bz_file, $offset, $entry_title) = $results[0]; |
| 47 | + $wgOut->addHTML('<ul>'); |
| 48 | + // lookup a real article in the index can be searched |
| 49 | + $results = DumpReader::index_search(wfMsg('offline_test_article')); |
| 50 | + if (count($results) > 0) |
| 51 | + list ($bz_file, $offset, $entry_title) = $results[0]; |
52 | 52 | |
53 | | - $test_index = isset($bz_file); |
54 | | - $this->printTest($test_index, 'offline_index_test'); |
55 | | - if (!$test_index) { |
56 | | - $this->diagnoseIndex(); |
57 | | - return; |
58 | | - } |
| 53 | + $test_index = isset($bz_file); |
| 54 | + $this->printTest($test_index, 'offline_index_test'); |
| 55 | + if (!$test_index) { |
| 56 | + $this->diagnoseIndex(); |
| 57 | + return; |
| 58 | + } |
59 | 59 | |
60 | | - // tests that bz2 dumpfiles can be opened and read |
61 | | - $xml = DumpReader::load_bz($bz_file, $entry_title); |
62 | | - $test_bz = isset($xml); |
63 | | - $this->printTest($test_bz, 'offline_bzload_test'); |
64 | | - if (!$test_bz) { |
65 | | - $this->diagnoseBzload($bz_file); |
66 | | - return; |
67 | | - } |
68 | | - //report subdirectory setting |
69 | | -// if (substr($bz_file, 0, 1) == 'x') { |
70 | | -// $subdir = dirname($bz_file); //TODO strip absolute components if needed |
71 | | -// $wgOut->addWikiMsg('offline_subdir-status', $subdir); |
72 | | -// $wgOut->addHTML( |
73 | | -// '<label>' . wfMsg('offline_change-subdir') . |
74 | | -// '<input type=text size=20 name="subdir" value="'.$subdir.'"> |
75 | | -// <input type=submit name="subdir" value="Change"> |
76 | | -// </label/>' |
77 | | -// ); |
78 | | -// } |
| 60 | + // tests that bz2 dumpfiles can be opened and read |
| 61 | + $xml = DumpReader::load_bz($bz_file, $entry_title); |
| 62 | + $test_bz = isset($xml); |
| 63 | + $this->printTest($test_bz, 'offline_bzload_test'); |
| 64 | + if (!$test_bz) { |
| 65 | + $this->diagnoseBzload($bz_file); |
| 66 | + return; |
| 67 | + } |
| 68 | + //report subdirectory setting |
| 69 | +// if (substr($bz_file, 0, 1) == 'x') { |
| 70 | +// $subdir = dirname($bz_file); //TODO strip absolute components if needed |
| 71 | +// $wgOut->addWikiMsg('offline_subdir-status', $subdir); |
| 72 | +// $wgOut->addHTML( |
| 73 | +// '<label>' . wfMsg('offline_change-subdir') . |
| 74 | +// '<input type=text size=20 name="subdir" value="'.$subdir.'"> |
| 75 | +// <input type=submit name="subdir" value="Change"> |
| 76 | +// </label/>' |
| 77 | +// ); |
| 78 | +// } |
79 | 79 | |
80 | | - // TODO report language settings and availabilities |
| 80 | + // TODO report language settings and availabilities |
81 | 81 | |
82 | | - //test that a specific article can be loaded |
83 | | - $article_wml = DumpReader::load_article($entry_title); |
84 | | - $test_article = isset($article_wml); |
85 | | - $this->printTest($test_article, 'offline_article_test'); |
86 | | - if (!$test_article) { |
87 | | - //TODO diagnose |
88 | | - return; |
89 | | - } |
90 | | - //TODO test that the wml has not been padded or truncated |
| 82 | + //test that a specific article can be loaded |
| 83 | + $article_wml = DumpReader::load_article($entry_title); |
| 84 | + $test_article = isset($article_wml); |
| 85 | + $this->printTest($test_article, 'offline_article_test'); |
| 86 | + if (!$test_article) { |
| 87 | + //TODO diagnose |
| 88 | + return; |
| 89 | + } |
| 90 | + //TODO test that the wml has not been padded or truncated |
91 | 91 | |
92 | | - //test that our handler is still hooked in |
93 | | - $mw_api_article = new Article(Title::newFromText($entry_title)); |
94 | | - $mw_api_article->loadContent(); |
95 | | - $content = $mw_api_article->getContent(); |
| 92 | + //test that our handler is still hooked in |
| 93 | + $mw_api_article = new Article(Title::newFromText($entry_title)); |
| 94 | + $mw_api_article->loadContent(); |
| 95 | + $content = $mw_api_article->getContent(); |
96 | 96 | //wfDebug('got '.strlen($mw_api_article->mContent).' bytes of wml from cache'); |
97 | | - $test_hooks = $mw_api_article->mContentLoaded; |
98 | | - // TODO false positive |
99 | | - $this->printTest($test_hooks, 'offline_hooks_test'); |
100 | | - if (!$test_hooks) { |
101 | | - $this->diagnoseHooks(); |
102 | | - return; |
103 | | - } |
| 97 | + $test_hooks = $mw_api_article->mContentLoaded; |
| 98 | + // TODO false positive |
| 99 | + $this->printTest($test_hooks, 'offline_hooks_test'); |
| 100 | + if (!$test_hooks) { |
| 101 | + $this->diagnoseHooks(); |
| 102 | + return; |
| 103 | + } |
104 | 104 | |
105 | | - //TODO test Templates |
| 105 | + //TODO test Templates |
106 | 106 | |
107 | | - $wgOut->addHTML('</ul>'); |
| 107 | + $wgOut->addHTML('</ul>'); |
108 | 108 | |
109 | | - $wgOut->wrapWikiMsg('<i>$1</i>', 'offline_all_tests_pass'); |
110 | | - //TODO div collapse or load on demand |
111 | | - //$wgOut->addWikiText($content); |
| 109 | + $wgOut->wrapWikiMsg('<i>$1</i>', 'offline_all_tests_pass'); |
| 110 | + //TODO div collapse or load on demand |
| 111 | + //$wgOut->addWikiText($content); |
112 | 112 | } |
113 | 113 | |
114 | 114 | function diagnoseIndex() { |
115 | | - global $wgOut, $wgOfflineWikiPath; |
| 115 | + global $wgOut, $wgOfflineWikiPath; |
116 | 116 | |
117 | | - if (!isset($wgOfflineWikiPath)) { |
118 | | - $this->printDiagnostic('offlinewikipath_not_configured'); |
119 | | - } |
120 | | - elseif (!is_dir($wgOfflineWikiPath)) { |
121 | | - $this->printDiagnostic(array('offlinewikipath_not_found', $wgOfflineWikiPath)); |
122 | | - } |
123 | | - elseif (!is_dir("$wgOfflineWikiPath/db") || !file_exists("$wgOfflineWikiPath/db/termlist.DB")) { |
124 | | - $this->printDiagnostic(array('offline_dbdir_not_found', $wgOfflineWikiPath)); |
125 | | - } else { |
126 | | - $this->printDiagnostic('offline_unknown_index_error'); |
127 | | - } |
| 117 | + if (!isset($wgOfflineWikiPath)) { |
| 118 | + $this->printDiagnostic('offlinewikipath_not_configured'); |
| 119 | + } |
| 120 | + elseif (!is_dir($wgOfflineWikiPath)) { |
| 121 | + $this->printDiagnostic(array('offlinewikipath_not_found', $wgOfflineWikiPath)); |
| 122 | + } |
| 123 | + elseif (!is_dir("$wgOfflineWikiPath/db") || !file_exists("$wgOfflineWikiPath/db/termlist.DB")) { |
| 124 | + $this->printDiagnostic(array('offline_dbdir_not_found', $wgOfflineWikiPath)); |
| 125 | + } else { |
| 126 | + $this->printDiagnostic('offline_unknown_index_error'); |
| 127 | + } |
128 | 128 | } |
129 | 129 | |
130 | 130 | function diagnoseBzload($bz_file) { |
131 | | - global $wgOut, $wgOfflineWikiPath; |
132 | | - |
133 | | - $full_path = $wgOfflineWikiPath.'/'.$bz_file; |
134 | | - if (!extension_loaded('bz2')) { |
135 | | - $this->printDiagnostic('offline_bz2_ext_needed'); |
136 | | - } |
137 | | - if (!file_exists($full_path)) { |
138 | | - $this->printDiagnostic(array('offline_bz2_file_gone', $full_path)); |
139 | | - } |
140 | | - else { |
141 | | - $this->printDiagnostic(array('offline_unknown_bz2_error', $full_path)); |
142 | | - } |
| 131 | + global $wgOut, $wgOfflineWikiPath; |
| 132 | + |
| 133 | + $full_path = $wgOfflineWikiPath.'/'.$bz_file; |
| 134 | + if (!extension_loaded('bz2')) { |
| 135 | + $this->printDiagnostic('offline_bz2_ext_needed'); |
| 136 | + } |
| 137 | + if (!file_exists($full_path)) { |
| 138 | + $this->printDiagnostic(array('offline_bz2_file_gone', $full_path)); |
| 139 | + } |
| 140 | + else { |
| 141 | + $this->printDiagnostic(array('offline_unknown_bz2_error', $full_path)); |
| 142 | + } |
143 | 143 | } |
144 | 144 | |
145 | 145 | function diagnoseHooks() { |
146 | | - global $wgOut, $wgMemc; |
147 | | - $key = wfMemcKey('offline','trial'); |
148 | | - $wgMemc->set($key, true); |
149 | | - if (!$wgMemc->get($key)) { |
150 | | - $this->printDiagnostic('offline_cache_needed'); |
151 | | - } |
152 | | - // check that passing revisiontext through cache will work |
| 146 | + global $wgOut, $wgMemc; |
| 147 | + $key = wfMemcKey('offline','trial'); |
| 148 | + $wgMemc->set($key, true); |
| 149 | + if (!$wgMemc->get($key)) { |
| 150 | + $this->printDiagnostic('offline_cache_needed'); |
| 151 | + } |
| 152 | + // check that passing revisiontext through cache will work |
153 | 153 | } |
154 | 154 | |
155 | 155 | function printTest($bool, $msg) { |
156 | | - global $wgOut; |
157 | | - if ($bool) |
158 | | - $wgOut->wrapWikiMsg('<div class="result-pass"><li>$1</div>', $msg.'_pass'); |
159 | | - else |
160 | | - $wgOut->wrapWikiMsg('<div class="error"><li>$1</div>', $msg.'_fail'); |
| 156 | + global $wgOut; |
| 157 | + if ($bool) |
| 158 | + $wgOut->wrapWikiMsg('<div class="result-pass"><li>$1</div>', $msg.'_pass'); |
| 159 | + else |
| 160 | + $wgOut->wrapWikiMsg('<div class="error"><li>$1</div>', $msg.'_fail'); |
161 | 161 | } |
162 | 162 | |
163 | 163 | function printDiagnostic($msg) { |
164 | | - global $wgOut; |
165 | | - $wgOut->wrapWikiMsg('<div class="errorbox">$1</div>', $msg); |
| 164 | + global $wgOut; |
| 165 | + $wgOut->wrapWikiMsg('<div class="errorbox">$1</div>', $msg); |
166 | 166 | } |
167 | 167 | } |
Index: trunk/extensions/Offline/DumpReader.php |
— | — | @@ -9,13 +9,13 @@ |
10 | 10 | $article_wml = null; |
11 | 11 | $results = self::index_search($title); |
12 | 12 | if (count($results) > 0) { |
13 | | - $archive_file = $results[0][0]; |
14 | | - $plaintext_offset = $results[0][1]; |
15 | | - $title = $results[0][2]; |
| 13 | + $archive_file = $results[0][0]; |
| 14 | + $plaintext_offset = $results[0][1]; |
| 15 | + $title = $results[0][2]; |
16 | 16 | |
17 | | - $article_wml = self::load_all_data($title, $archive_file); |
| 17 | + $article_wml = self::load_all_data($title, $archive_file); |
18 | 18 | } else { |
19 | | - $article_wml = ""; //TODO or null? |
| 19 | + $article_wml = ""; //TODO or null? |
20 | 20 | } |
21 | 21 | $article_wml = htmlspecialchars_decode($article_wml); |
22 | 22 | return $article_wml; |
— | — | @@ -28,21 +28,21 @@ |
29 | 29 | $matches = array(); |
30 | 30 | $all_chunk_data = self::load_bz($file_name); |
31 | 31 | if (preg_match("/<title>".preg_quote($title, '/')."<\/title>.*?<text[^>]*>(.*)/s", |
32 | | - $all_chunk_data, $matches)) |
| 32 | + $all_chunk_data, $matches)) |
33 | 33 | { |
34 | | - $all_chunk_data = $matches[1]; |
35 | | - while (isset($all_chunk_data)) { |
36 | | - $end_pos = strpos($all_chunk_data, '</text>'); |
37 | | - if ($end_pos !== FALSE) { |
38 | | - $article_wml .= substr($all_chunk_data, 0, $end_pos); |
39 | | - break; |
40 | | - } |
41 | | - $article_wml .= $all_chunk_data; |
| 34 | + $all_chunk_data = $matches[1]; |
| 35 | + while (isset($all_chunk_data)) { |
| 36 | + $end_pos = strpos($all_chunk_data, '</text>'); |
| 37 | + if ($end_pos !== FALSE) { |
| 38 | + $article_wml .= substr($all_chunk_data, 0, $end_pos); |
| 39 | + break; |
| 40 | + } |
| 41 | + $article_wml .= $all_chunk_data; |
42 | 42 | |
43 | | - wfDebug('continuing into next bz2 chunk'); |
44 | | - $file_name = self::increment_file($file_name); |
45 | | - $all_chunk_data = self::load_bz($file_name); |
46 | | - } |
| 43 | + wfDebug('continuing into next bz2 chunk'); |
| 44 | + $file_name = self::increment_file($file_name); |
| 45 | + $all_chunk_data = self::load_bz($file_name); |
| 46 | + } |
47 | 47 | } |
48 | 48 | return $article_wml; |
49 | 49 | } |
— | — | @@ -61,7 +61,7 @@ |
62 | 62 | |
63 | 63 | $out = ""; |
64 | 64 | while ($bz && !feof($bz)) { |
65 | | - $out .= bzread($bz, 8192); |
| 65 | + $out .= bzread($bz, 8192); |
66 | 66 | } |
67 | 67 | bzclose($bz); |
68 | 68 | return $out; |
— | — | @@ -91,21 +91,21 @@ |
92 | 92 | $matches = $enquire->get_mset(0, 25); |
93 | 93 | |
94 | 94 | if (0 /*SCORING*/) { |
95 | | - $scores = array(); |
96 | | - for ($i = $matches->begin(); !$i->equals($matches->end()); $i->next()) |
97 | | - { |
98 | | - $row = $i->get_document(); |
99 | | - $str = $i->get_percent()."% [".$row->get_data()."]"; |
100 | | - $scores[] = $str; |
101 | | - if (1/*DEBUG*/) wfDebug("$str\n"); |
102 | | - } |
| 95 | + $scores = array(); |
| 96 | + for ($i = $matches->begin(); !$i->equals($matches->end()); $i->next()) |
| 97 | + { |
| 98 | + $row = $i->get_document(); |
| 99 | + $str = $i->get_percent()."% [".$row->get_data()."]"; |
| 100 | + $scores[] = $str; |
| 101 | + if (1/*DEBUG*/) wfDebug("$str\n"); |
| 102 | + } |
103 | 103 | } |
104 | 104 | |
105 | 105 | $result = array(); |
106 | 106 | for ($i = $matches->begin(); !$i->equals($matches->end()); $i->next()) |
107 | | - { |
108 | | - $entry = $i->get_document()->get_data(); |
109 | | - $result[] = explode(':', $entry, 3); |
| 107 | + { |
| 108 | + $entry = $i->get_document()->get_data(); |
| 109 | + $result[] = explode(':', $entry, 3); |
110 | 110 | } |
111 | 111 | # not in Xapian 1.0.X |
112 | 112 | #$db->close(); |
— | — | @@ -113,8 +113,8 @@ |
114 | 114 | return $result; |
115 | 115 | |
116 | 116 | } catch (Exception $e) { |
117 | | - wfDebug(__METHOD__.':'.$e->getMessage()); |
118 | | - return null; |
| 117 | + wfDebug(__METHOD__.':'.$e->getMessage()); |
| 118 | + return null; |
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
— | — | @@ -124,11 +124,11 @@ |
125 | 125 | $matches = array(); |
126 | 126 | // TODO fails on 99 ... |
127 | 127 | if (preg_match('/(.*?)([1-9][0-9]*)(.*?)$/', $fname, $matches)) { |
128 | | - $i = $matches[2]; |
129 | | - return preg_replace("/$i/", $i + 1, $fname); |
| 128 | + $i = $matches[2]; |
| 129 | + return preg_replace("/$i/", $i + 1, $fname); |
130 | 130 | } else { |
131 | | - wfDebug('Failed to grok your wiki-splits filename pattern'); |
132 | | - return false; |
| 131 | + wfDebug('Failed to grok your wiki-splits filename pattern'); |
| 132 | + return false; |
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |