Index: trunk/WikiWord/WikiWordWeb/src/main/maintenance/resource-index.sql |
— | — | @@ -10,4 +10,5 @@ |
11 | 11 | insert into {collection}_{thesaurus}_resource_index ( concept, resources ) |
12 | 12 | select concept, group_concat(distinct concat(type, ":", lang, ":", local_resource_name) separator "|" ) as resources |
13 | 13 | from {collection}_{thesaurus}_about as A |
14 | | -where type > 0; |
| 14 | +where type > 0 |
| 15 | +group by concept; |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/wikiword/api.php |
— | — | @@ -36,13 +36,15 @@ |
37 | 37 | } else if ($query == 'concepts') { |
38 | 38 | $term = @$_REQUEST['term']; |
39 | 39 | $norm = @$_REQUEST['norm']; |
| 40 | + $limit = @$_REQUEST['limit']; |
40 | 41 | |
41 | 42 | if ( $norm === null ) $norm = 1; |
| 43 | + if ( $limit === null ) $limit = $wwMaxSearchResults; |
42 | 44 | #$page = @$_REQUEST['page']; |
43 | 45 | |
44 | 46 | if ( $qlang === null ) $result['error'] = array('code' => 150, 'message' => "missing parameter qlang"); |
45 | 47 | else if ( $term !== null ) { |
46 | | - $result['concepts'] = $thesaurus->getConceptsForTerm($qlang, $term, $lang, $norm, $rclang); #TODO: limit! |
| 48 | + $result['concepts'] = $thesaurus->getConceptsForTerm($qlang, $term, $lang, $norm, $rclang, $limit); |
47 | 49 | if ( $result['concepts'] === false || $result['concepts'] === null ) { |
48 | 50 | $result['error'] = array('code' => 210, 'message' => "failed to retrieve concepts for term $langt:$term"); |
49 | 51 | } |
— | — | @@ -107,7 +109,12 @@ |
108 | 110 | $result['error'] = array('code' => 10, 'message' => "bad query: $query"); |
109 | 111 | } |
110 | 112 | } catch (Exception $e) { |
111 | | - $result['error'] = array('code' => 1000, 'message' => "unexpected exception: " . $e->getMessage()); |
| 113 | + $result['error']['code'] = 1000 + $e->getCode(); |
| 114 | + $result['error']['message'] = "unexpected exception: " . $e->getMessage(); |
| 115 | + |
| 116 | + if ( @$wwExceptionDetails ) { |
| 117 | + $result['error']['trace'] = $e->getTrace(); |
| 118 | + }; |
112 | 119 | } |
113 | 120 | |
114 | 121 | $result['time'] = (microtime(true) - $start) . " sec"; |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/response.html.php |
— | — | @@ -125,12 +125,13 @@ |
126 | 126 | global $utils; |
127 | 127 | |
128 | 128 | $name = $utils->pickLocal($concept['name'], $langs); |
129 | | - if ( $name === false || $name === null) return false; |
| 129 | + if ( $name === false || $name === null || $name === "") return false; |
130 | 130 | |
131 | 131 | $name = str_replace("_", " ", $name); |
132 | 132 | $score = @$concept['score']; |
133 | 133 | |
134 | 134 | if ($text === null) $text = $name; |
| 135 | + if ($text === null || $text === false || $text === "") return false; |
135 | 136 | |
136 | 137 | $u = getConceptDetailsURL($langs, $concept); |
137 | 138 | return '<a href="' . htmlspecialchars($u) . '" title="' . htmlspecialchars($name) . ' (score: ' . (int)$score . ')'. '">' . htmlspecialchars($text) . '</a>'; |
— | — | @@ -333,6 +334,7 @@ |
334 | 335 | if (!isset($skinPath)) $skinPath = "$scriptPath/../skin/"; |
335 | 336 | |
336 | 337 | header("Content-Type: text/html; charset=UTF-8"); |
| 338 | +debug("starting HTML output"); |
337 | 339 | ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
338 | 340 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> |
339 | 341 | <head> |
— | — | @@ -373,6 +375,8 @@ |
374 | 376 | ?> |
375 | 377 | <table border="0" class="results" cellspacing="0" summary="search results"> |
376 | 378 | <?php |
| 379 | + debug("processing results"); |
| 380 | + |
377 | 381 | $count = 0; |
378 | 382 | foreach ( $result as $row ) { |
379 | 383 | $count = $count + 1; |
— | — | @@ -380,10 +384,16 @@ |
381 | 385 | |
382 | 386 | ?> |
383 | 387 | <?php |
| 388 | + if ( @$debug ) { |
| 389 | + print "<p class='debug'>procesing concept #".htmlspecialchars($row['id'])."</p>"; |
| 390 | + flush(); |
| 391 | + } |
| 392 | + |
384 | 393 | mangleConcept($row); |
385 | 394 | $continue= printConcept($row, $languages, $terse); |
386 | 395 | |
387 | 396 | if (!$continue) break; |
| 397 | + if ($limit && $count >= $limit) break; |
388 | 398 | ?> |
389 | 399 | |
390 | 400 | <?php |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/search.php |
— | — | @@ -14,6 +14,11 @@ |
15 | 15 | function getImagesAbout($concept, $max) { |
16 | 16 | global $utils, $profiling; |
17 | 17 | |
| 18 | + if ( @$debug ) { |
| 19 | + print "<p class='debug'>fetching images about #".htmlspecialchars($concept['id'])."</p>"; |
| 20 | + flush(); |
| 21 | + } |
| 22 | + |
18 | 23 | $t = microtime(true); |
19 | 24 | $pics = $utils->getImagesAbout($concept, $max); |
20 | 25 | $profiling['pics'] += (microtime(true) - $t); |
— | — | @@ -149,11 +154,23 @@ |
150 | 155 | sortConceptList($concept['broader']); |
151 | 156 | } |
152 | 157 | |
| 158 | +function debug( $msg ) { |
| 159 | + global $debug; |
| 160 | + |
| 161 | + if ( @$debug ) { |
| 162 | + print "<p class='debug'>".htmlspecialchars($msg)."</p>"; |
| 163 | + flush(); |
| 164 | + } |
| 165 | +} |
| 166 | + |
153 | 167 | $conceptId = @$_REQUEST['id']; |
154 | 168 | $term = @$_REQUEST['term']; |
155 | 169 | $lang = @$_REQUEST['lang']; |
156 | 170 | $format = @$_REQUEST['format']; |
| 171 | +$limit = @$_REQUEST['limit']; |
157 | 172 | |
| 173 | +if ( $limit === null ) $limit = $wwMaxSearchResults; |
| 174 | + |
158 | 175 | if ( $term===null ) { |
159 | 176 | $term = @$_SERVER['PATH_INFO']; |
160 | 177 | $term = preg_replace('!^/!', '', $term); |
— | — | @@ -178,6 +195,7 @@ |
179 | 196 | if (!isset($scriptPath)) $scriptPath = dirname($wwSelf); |
180 | 197 | if (!isset($skinPath)) $skinPath = "$scriptPath/../skin/"; |
181 | 198 | |
| 199 | +$debug = false; |
182 | 200 | $error = NULL; |
183 | 201 | |
184 | 202 | if ($lang) { |
— | — | @@ -202,15 +220,18 @@ |
203 | 221 | |
204 | 222 | if ( !$utils->db ) $utils->connect($wwDBServer, $wwDBUser, $wwDBPassword, $wwDBDatabase); |
205 | 223 | |
206 | | -if (@$_REQUEST['debug']) $utils->debug = true; |
| 224 | +if (@$_REQUEST['debug']) { |
| 225 | + $debug = true; |
| 226 | + $utils->debug = true; |
| 227 | + $thesaurus->debug = true; |
| 228 | +} |
207 | 229 | |
208 | | -$limit = 20; |
209 | 230 | $norm = 1; |
210 | 231 | |
211 | 232 | $mode = NULL; |
212 | 233 | $result = NULL; |
213 | 234 | |
214 | | -$fallback_languages = array( "en" ); #TODO: make the user define this list |
| 235 | +$fallback_languages = array( "en", "commons" ); #TODO: make the user define this list |
215 | 236 | |
216 | 237 | if ( $lang ) { |
217 | 238 | $languages = preg_split('![,;/|+]!', $lang); |
— | — | @@ -232,7 +253,7 @@ |
233 | 254 | try { |
234 | 255 | if ($lang && $conceptId) { |
235 | 256 | $mode = "concept"; |
236 | | - $result = $thesaurus->getConceptInfo($conceptId, $lang, null, $allLanguages); |
| 257 | + $result = $thesaurus->getConceptInfo($conceptId, $lang, null, $allLanguages, $wwMax); |
237 | 258 | if ( $result ) $result = array( $result ); //hack |
238 | 259 | } else if ($lang && $term) { |
239 | 260 | $mode = "term"; |
— | — | @@ -244,6 +265,8 @@ |
245 | 266 | $profiling['thesaurus'] += (microtime(true) - $t); |
246 | 267 | } |
247 | 268 | |
| 269 | +debug("generating response"); |
| 270 | + |
248 | 271 | /*if ( $format == "atom" || $format == "xml" || $format == "opensearch" ) include("response.atom.php"); |
249 | 272 | else*/ |
250 | 273 | include("response.html.php"); |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/form.html.php |
— | — | @@ -34,9 +34,9 @@ |
35 | 35 | </table> |
36 | 36 | |
37 | 37 | <?php |
38 | | - if ($utils->debug) { |
| 38 | + if ( @$debug ) { |
39 | 39 | print '<input type="hidden" name="debug" value="true"/>'; |
40 | | - print "<p>debug mode enabled!</p>"; |
| 40 | + print "<p class='debug'>debug mode enabled!</p>"; |
41 | 41 | flush(); |
42 | 42 | } |
43 | 43 | ?> |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/common/wwclient.php |
— | — | @@ -3,6 +3,7 @@ |
4 | 4 | |
5 | 5 | class WWClient { |
6 | 6 | var $api; |
| 7 | + var $debug = false; |
7 | 8 | |
8 | 9 | function __construct( $api ) { |
9 | 10 | $this->api = $api; |
— | — | @@ -29,13 +30,27 @@ |
30 | 31 | $url .= urlencode( $v ); |
31 | 32 | } |
32 | 33 | |
| 34 | + if ($this->debug) { |
| 35 | + $t = microtime(true); |
| 36 | + print "\n<span class='debug'>[fetching " . htmlspecialchars($url) . "]</span>\n"; |
| 37 | + flush(); |
| 38 | + } |
| 39 | + |
33 | 40 | $data = file_get_contents( $url ); //TODO: CURL |
| 41 | + |
34 | 42 | if ( !$data ) throw new Exception("failed to fetch data from $url"); |
35 | 43 | |
36 | 44 | $data = unserialize($data); |
37 | 45 | if ( !$data ) throw new Exception("failed to unserialize data from $url"); |
38 | 46 | |
39 | 47 | if ( @$data['error'] ) throw new Exception("API returned error ".$data['error']['code'].": ".$data['error']['message']."; url: $url"); |
| 48 | + |
| 49 | + if ($this->debug) { |
| 50 | + $t = microtime(true) - $t; |
| 51 | + print "\n<span class='debug'>[took " . $t . " sec]</span>\n"; |
| 52 | + flush(); |
| 53 | + } |
| 54 | + |
40 | 55 | return $data; |
41 | 56 | } |
42 | 57 | |
— | — | @@ -144,6 +159,7 @@ |
145 | 160 | 'lang' => $languages, |
146 | 161 | 'norm' => $norm, |
147 | 162 | 'term' => $term, |
| 163 | + 'limit' => $limit, |
148 | 164 | ); |
149 | 165 | |
150 | 166 | $rs = $this->query( $param ); |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/common/wwutils.php |
— | — | @@ -23,8 +23,9 @@ |
24 | 24 | if ($db == NULL && isset($this)) $db = $this->db; |
25 | 25 | |
26 | 26 | if ($this->debug) { |
27 | | - print "\n<pre>" . htmlspecialchars($sql) . "</pre>\n"; |
| 27 | + print "\n<div class='debug'>SQL: <pre>" . htmlspecialchars($sql) . "</pre></div>\n"; |
28 | 28 | flush(); |
| 29 | + $t = microtime(true); |
29 | 30 | } |
30 | 31 | |
31 | 32 | if (!$db) { |
— | — | @@ -39,6 +40,12 @@ |
40 | 41 | throw new Exception("$error (#$errno);\nlast query: $sql"); |
41 | 42 | } |
42 | 43 | |
| 44 | + if ($this->debug) { |
| 45 | + $t = microtime(true) - $t; |
| 46 | + print "\n<div class='debug'>SQL time: $t</div>\n"; |
| 47 | + flush(); |
| 48 | + } |
| 49 | + |
43 | 50 | return $result; |
44 | 51 | } |
45 | 52 | |
— | — | @@ -155,6 +162,8 @@ |
156 | 163 | } |
157 | 164 | |
158 | 165 | function pickLocal($items, $languages) { |
| 166 | + if ( !is_array($items) ) return $items; |
| 167 | + |
159 | 168 | $lang = $this->pickLanguage($items, $languages); |
160 | 169 | if (!$lang) return false; |
161 | 170 | return $items[$lang]; |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/common/wwthesaurus.php |
— | — | @@ -92,7 +92,7 @@ |
93 | 93 | . " AND S.norm <= " . (int)$norm; |
94 | 94 | |
95 | 95 | $sql .= " ORDER BY S.score DESC, S.concept " |
96 | | - . " LIMIT " . (int)$limit; |
| 96 | + . " LIMIT " . (int)$limit * count( $languages ); |
97 | 97 | |
98 | 98 | #FIXME: query-lang vs. output-languages! |
99 | 99 | |
— | — | @@ -103,7 +103,7 @@ |
104 | 104 | $rs = $this->queryConceptsForTerm($qlang, $term, $languages, $norm, $rclang, $limit); |
105 | 105 | $list = WWUtils::slurpRows($rs); |
106 | 106 | mysql_free_result($rs); |
107 | | - return $this->buildConcepts($list); |
| 107 | + return $this->buildConcepts($list, $limit); |
108 | 108 | } |
109 | 109 | |
110 | 110 | function getPagesForConcept( $id, $lang = null ) { |
— | — | @@ -257,7 +257,7 @@ |
258 | 258 | |
259 | 259 | $rc = array(); |
260 | 260 | foreach ($rr as $r) { |
261 | | - list($t, $lang, $n) = explode(":", $p, 3); |
| 261 | + list($t, $lang, $n) = explode(":", $r, 3); |
262 | 262 | $rc[$lang][$n] = (int)$t; |
263 | 263 | } |
264 | 264 | } |
— | — | @@ -308,11 +308,11 @@ |
309 | 309 | $sql .= " FROM {$wwTablePrefix}_{$wwThesaurusDataset}_concept_info as I "; |
310 | 310 | if ( $rclang ) $sql .= " JOIN {$wwTablePrefix}_{$wwThesaurusDataset}_resource_index as R ON R.concept = I.concept "; |
311 | 311 | |
312 | | - $sql .= " WHERE concept = ".(int)$id; |
| 312 | + $sql .= " WHERE I.concept = ".(int)$id; |
313 | 313 | |
314 | 314 | if ($lang) { |
315 | | - if ( is_array($lang) ) $sql .= " AND lang IN " . $this->quoteSet($lang); |
316 | | - else $sql .= " AND lang = " . $this->quote($lang); |
| 315 | + if ( is_array($lang) ) $sql .= " AND I.lang IN " . $this->quoteSet($lang); |
| 316 | + else $sql .= " AND I.lang = " . $this->quote($lang); |
317 | 317 | } |
318 | 318 | |
319 | 319 | $r = $this->getRows($sql); |
— | — | @@ -321,7 +321,7 @@ |
322 | 322 | return $this->buildConcept($r); |
323 | 323 | } |
324 | 324 | |
325 | | - function buildConcepts($rows) { |
| 325 | + function buildConcepts($rows, $limit = false) { |
326 | 326 | $concepts = array(); |
327 | 327 | $buff = array(); |
328 | 328 | $id = null; |
— | — | @@ -334,6 +334,8 @@ |
335 | 335 | |
336 | 336 | $id = null; |
337 | 337 | $score = null; |
| 338 | + |
| 339 | + if ( $limit && count($concepts) >= $limit ) break; |
338 | 340 | } |
339 | 341 | |
340 | 342 | if ($id === null) { |
— | — | @@ -343,7 +345,7 @@ |
344 | 346 | $buff[] = $row; |
345 | 347 | } |
346 | 348 | |
347 | | - if ($buff) { |
| 349 | + if ($buff && $id && ( !$limit || count($concepts) < $limit ) ) { |
348 | 350 | $concepts[$id] = $this->buildConcept($buff); |
349 | 351 | $buff = array(); |
350 | 352 | } |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/common/wwimages.php |
— | — | @@ -109,7 +109,7 @@ |
110 | 110 | $sql .= " AND P.page_title = " . $this->quote($title); |
111 | 111 | if ($commonsOnly) $sql .= " AND R.img_name IS NULL"; |
112 | 112 | |
113 | | - return $this->queryWiki($lang, $sql); |
| 113 | + return $this->queryWikiFast($lang, $sql); |
114 | 114 | } |
115 | 115 | |
116 | 116 | function getImagesOnPage($lang, $ns, $title, $commonsOnly = false) { |
— | — | @@ -143,7 +143,7 @@ |
144 | 144 | $sql .= " AND P.page_title = " . $this->quote($title); |
145 | 145 | if ($commonsOnly) $sql .= " AND R.img_name IS NULL"; |
146 | 146 | |
147 | | - return $this->queryWiki($lang, $sql); |
| 147 | + return $this->queryWikiFast($lang, $sql); |
148 | 148 | } |
149 | 149 | |
150 | 150 | function getImagesOnPageTemplates($lang, $ns, $title, $commonsOnly = false) { |
— | — | @@ -165,7 +165,7 @@ |
166 | 166 | $sql .= " WHERE C.cl_to = " . $this->quote($title); |
167 | 167 | $sql .= " AND P.page_namespace = " . NS_IMAGE; |
168 | 168 | |
169 | | - return $this->queryWiki($lang, $sql); |
| 169 | + return $this->queryWikiFast($lang, $sql); |
170 | 170 | } |
171 | 171 | |
172 | 172 | function getImagesInCategory($lang, $title) { |
— | — | @@ -208,7 +208,7 @@ |
209 | 209 | $sql .= " FROM $image_table as T "; |
210 | 210 | $sql .= " WHERE T.img_name IN " . $this->quoteSet($images); |
211 | 211 | |
212 | | - return $this->queryWiki($lang, $sql); |
| 212 | + return $this->queryWikiFast($lang, $sql); |
213 | 213 | } |
214 | 214 | |
215 | 215 | function getMetaForImages($lang, $images) { |
— | — | @@ -232,7 +232,7 @@ |
233 | 233 | $sql .= " WHERE P.page_title = " . $this->quote($image); |
234 | 234 | $sql .= " AND P.page_namespace = " . NS_IMAGE; |
235 | 235 | |
236 | | - return $this->queryWiki($lang, $sql); |
| 236 | + return $this->queryWikiFast($lang, $sql); |
237 | 237 | } |
238 | 238 | |
239 | 239 | function getTemplatesOnImagePage($lang, $image) { |
— | — | @@ -254,7 +254,7 @@ |
255 | 255 | $sql .= " WHERE P.page_title = " . $this->quote($image); |
256 | 256 | $sql .= " AND P.page_namespace = " . NS_IMAGE; |
257 | 257 | |
258 | | - return $this->queryWiki($lang, $sql); |
| 258 | + return $this->queryWikiFast($lang, $sql); |
259 | 259 | } |
260 | 260 | |
261 | 261 | function getCategoriesOfImagePage($lang, $image) { |
— | — | @@ -295,6 +295,7 @@ |
296 | 296 | |
297 | 297 | $wikis = array(); |
298 | 298 | $pages = array(); |
| 299 | + $pagesText = ""; |
299 | 300 | |
300 | 301 | foreach ($concepts as $lang => $rc) { |
301 | 302 | if (!isset($wwLanguages[$lang])) continue; |
— | — | @@ -306,12 +307,15 @@ |
307 | 308 | if ( $t != 10) continue; //use only articles |
308 | 309 | $p = "gil_wiki = " . $this->quote($wiki) . " AND gil_page_namespace_id = 0 AND gil_page_title = " . $this->quote($r); |
309 | 310 | $pages[] = $p; |
| 311 | + |
| 312 | + if ($pagesText) $pagesText .= ", "; |
| 313 | + $pagesText .= $wiki . ':' . str_replace('*', '_', $r); |
310 | 314 | } |
311 | 315 | } |
312 | 316 | |
313 | 317 | if (!$pages || !$wikis) return false; |
314 | 318 | |
315 | | - $sql = " /* queryImagesOnPagesGlobally() */ "; |
| 319 | + $sql = " /* queryImagesOnPagesGlobally($pagesText) */ "; |
316 | 320 | $sql .= " SELECT distinct gil_to as image FROM $globalimagelinks_table "; |
317 | 321 | $sql .= " WHERE gil_wiki in " . $this->quoteSet( $wikis ); |
318 | 322 | $sql .= " AND gil_page_namespace_id = 0 "; |
— | — | @@ -331,19 +335,21 @@ |
332 | 336 | return $list; |
333 | 337 | } |
334 | 338 | |
335 | | - function queryGlobalUsageCounts( $images, $wikis = ".*wiki" ) { |
| 339 | + function queryGlobalUsageCounts( $images, $wikis = null ) { |
336 | 340 | if (!$images) return false; |
337 | 341 | |
| 342 | + //FIXME: use pre-calculated usage counts if $wwImageUsageTable is set!!! |
| 343 | + |
338 | 344 | $globalimagelinks_table = $this->getWikiTableName("commons", "globalimagelinks"); |
339 | 345 | |
340 | | - $sql = " /* queryGlobalUsageCounts() */ "; |
| 346 | + $sql = " /* queryGlobalUsageCounts(" . str_replace('*', '_', implode(', ', $images) ) . ") */ "; |
341 | 347 | $sql .= " SELECT gil_to as image, gil_wiki as wiki, count(*) as linkcount FROM $globalimagelinks_table "; |
342 | 348 | $sql .= " WHERE gil_page_namespace_id = 0 "; |
343 | 349 | $sql .= " AND gil_to IN " . $this->quoteSet( $images ); |
344 | 350 | |
345 | 351 | if ( $wikis ) { |
346 | 352 | if ( is_array( $wikis ) ) $sql .= " AND gil_wiki IN " . $this->quoteSet( $wikis ); |
347 | | - else if ( is_array( $wikis ) ) $sql .= " AND gil_wiki REGEX " . $this->quote( '^' . $wikis . '$' ); |
| 353 | + else if ( $wikis ) $sql .= " AND gil_wiki RLIKE " . $this->quote( '^' . $wikis . '$' ); |
348 | 354 | |
349 | 355 | #TODO: could also limit to to x or min size n using toolserver.wiki ! |
350 | 356 | } |
— | — | @@ -351,10 +357,10 @@ |
352 | 358 | $sql .= " GROUP BY gil_to, gil_wiki "; |
353 | 359 | $sql .= " ORDER BY gil_to, gil_wiki "; |
354 | 360 | |
355 | | - return $this->queryWiki("commons", $sql); |
| 361 | + return $this->queryWikiFast("commons", $sql); |
356 | 362 | } |
357 | 363 | |
358 | | - function getGlobalUsageCounts( $images, $wikis = ".*wiki" ) { |
| 364 | + function getGlobalUsageCounts( $images, $wikis = null ) { |
359 | 365 | if (!$images) return array(); |
360 | 366 | |
361 | 367 | $rs = $this->queryGlobalUsageCounts($images, $wikis); |
— | — | @@ -412,7 +418,9 @@ |
413 | 419 | $globalImageList = $this->getImagesOnPagesGlobally($pages); //use wikis for $wwLanguages only |
414 | 420 | |
415 | 421 | //TODO: sanity limit on number of images. $max * 5 ? |
416 | | - $globalImageUsage = $this->getGlobalUsageCounts($globalImageList, ".*wiki"); //use all wikipedias |
| 422 | + //$globalImageUsage = $this->getGlobalUsageCounts($globalImageList, ".*wiki"); //use all wikipedias |
| 423 | + $globalImageUsage = $this->getGlobalUsageCounts($globalImageList, null); //use all wikis |
| 424 | + //FIXME: getGlobalUsageCounts is SLOW!!! |
417 | 425 | |
418 | 426 | foreach ($globalImageUsage as $image => $usage) { |
419 | 427 | $m = @$usage['*max*']; |
— | — | @@ -667,11 +675,11 @@ |
668 | 676 | return $this->allPics; |
669 | 677 | } |
670 | 678 | |
671 | | - function queryGlobalUsageCounts( $images, $wikis = ".*wiki" ) { |
| 679 | + function queryGlobalUsageCounts( $images, $wikis = null ) { |
672 | 680 | throw new Exception( __METHOD__ . " not implemented" ); |
673 | 681 | } |
674 | 682 | |
675 | | - function getGlobalUsageCounts( $images, $wikis = ".*wiki" ) { |
| 683 | + function getGlobalUsageCounts( $images, $wikis = null ) { |
676 | 684 | if (!$images) return array(); |
677 | 685 | |
678 | 686 | foreach ($images as $current) { |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/common/wwwikis.php |
— | — | @@ -24,7 +24,9 @@ |
25 | 25 | } |
26 | 26 | |
27 | 27 | function getWikiInfo($lang) { |
28 | | - global $wwWikiInfoTable, $wwWikiDbName, $wwWikiServerName, $wwCommonsServerName; |
| 28 | + global $wwWikiInfoTable, $wwWikiDbName; |
| 29 | + global $wwWikiServerName, $wwWikiFastServerName; |
| 30 | + global $wwCommonsServerName, $wwCommonsFastServerName; |
29 | 31 | |
30 | 32 | $db = str_replace('{lang}', $lang, $wwWikiDbName); |
31 | 33 | |
— | — | @@ -37,36 +39,56 @@ |
38 | 40 | mysql_free_result($rs); |
39 | 41 | |
40 | 42 | if (!$info) $info = false; |
41 | | - else $info['server'] = str_replace('{num}', $info['server'], $wwWikiServerName); |
| 43 | + else { |
| 44 | + $info['server'] = str_replace('{num}', $info['server'], $wwWikiServerName); |
42 | 45 | |
43 | | - if ($lang == "commons" && $wwCommonsServerName) $info['server'] = $wwCommonsServerName; |
| 46 | + if ( $wwWikiFastServerName ) $info['fast-server'] = str_replace('{num}', $info['server'], $wwWikiServerName); |
| 47 | + else $info['fast-server'] = $info['server']; |
44 | 48 | |
| 49 | + if ($lang == "commons" && $wwCommonsServerName) $info['server'] = $wwCommonsServerName; |
| 50 | + if ($lang == "commons" && $wwCommonsFastServerName) $info['fast-server'] = $wwCommonsFastServerName; |
| 51 | + else $info['fast-server'] = $info['server']; |
| 52 | + } |
| 53 | + |
45 | 54 | return $info; |
46 | 55 | } |
47 | 56 | |
48 | | - function getWikiConnection($lang) { |
49 | | - if (isset($this->wikidbs[$lang])) return $this->wikidbs[$lang]; |
| 57 | + function getWikiConnection($lang, $fast = false) { |
| 58 | + if ( $fast ) $key = "$lang+fast"; |
| 59 | + else $key = $lang; |
50 | 60 | |
| 61 | + if (isset($this->wikidbs[$key])) return $this->wikidbs[$key]; |
| 62 | + |
51 | 63 | $info = $this->getWikiInfo($lang); |
52 | 64 | |
53 | 65 | if (!$info) { |
54 | 66 | $db = false; |
55 | 67 | } else { |
56 | | - $db = mysql_connect($info['server'], $this->dbuser, $this->dbpassword); |
| 68 | + if ($fast && isset($info['fast-server'])) $server = $info['fast-server']; |
| 69 | + else $server = $info['server']; |
| 70 | + |
| 71 | + $db = mysql_connect($server, $this->dbuser, $this->dbpassword); |
57 | 72 | if (!$db) throw new Exception("Connection Failure to Database: " . mysql_error()); |
58 | 73 | if (!mysql_select_db($info['dbname'], $db)) throw new Exception ("Database not found: " . mysql_error()); |
59 | 74 | if (!mysql_query("SET NAMES Latin1;", $db)) throw new Exception ("Database not found: " . mysql_error()); |
60 | 75 | } |
61 | 76 | |
62 | | - $this->wikidbs[$lang] = $db; |
| 77 | + $this->wikidbs[$key] = $db; |
63 | 78 | return $db; |
64 | 79 | } |
65 | 80 | |
66 | 81 | function queryWiki($lang, $sql) { |
67 | | - $db = $this->getWikiConnection($lang); |
| 82 | + $db = $this->getWikiConnection($lang, false); |
68 | 83 | if (!$db) throw new Exception ("Wiki not found: $lang"); |
69 | 84 | |
70 | 85 | return $this->query($sql, $db); |
71 | 86 | } |
72 | 87 | |
| 88 | + function queryWikiFast($lang, $sql) { |
| 89 | + $db = $this->getWikiConnection($lang, true); |
| 90 | + if (!$db) throw new Exception ("Wiki not found: $lang"); |
| 91 | + |
| 92 | + return $this->query($sql, $db); |
| 93 | + } |
| 94 | + |
73 | 95 | } |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/config.sample.php |
— | — | @@ -21,6 +21,8 @@ |
22 | 22 | $wwGalleryColumns = 5; |
23 | 23 | $wwMaxGalleryImages = 200; |
24 | 24 | $wwMaxDetailLinks = 1000; |
| 25 | +$wwMaxSearchResults = 8; |
| 26 | + |
25 | 27 | $wwThumbSize = 120; |
26 | 28 | $wwThumbnailURL = "http://toolserver.org/tsthumb/tsthumb?f={name}&domain=commons.wikimedia.org&w={width}&h={height}"; |
27 | 29 | $wwImagePageURL = "http://commons.wikimedia.org/wiki/File:{name}"; |
— | — | @@ -32,8 +34,10 @@ |
33 | 35 | $wwWikiInfoTable = "toolserver.wiki"; |
34 | 36 | $wwWikiDbName = "{lang}wiki_p"; |
35 | 37 | $wwWikiServerName = "sql-s{num}"; |
| 38 | +$wwWikiFastServerName = "sql-s{num}-fast"; |
36 | 39 | |
37 | 40 | $wwCommonsServerName = null; |
| 41 | +$wwCommonsFastServerName = null; |
38 | 42 | |
39 | 43 | $wwTagsTable = null; |
40 | 44 | |