Index: trunk/WikiWord/WikiWord/src/main/php/search/wikipics.php |
— | — | @@ -23,27 +23,82 @@ |
24 | 24 | <?php |
25 | 25 | } |
26 | 26 | |
27 | | -function printConceptImageList($concept, $class = "terselist") { |
| 27 | +function getImagesAbout($concept, $max) { |
| 28 | + global $utils, $profiling; |
| 29 | + |
| 30 | + $t = microtime(true); |
| 31 | + $pics = $utils->getImagesAbout($concept, $max); |
| 32 | + $profiling['pics'] += (microtime(true) - $t); |
| 33 | + |
| 34 | + return $pics; |
| 35 | +} |
| 36 | + |
| 37 | +function printConceptImageList($concept, $class = "tersetable", $columns = 5) { |
28 | 38 | global $utils, $wwThumbSize, $wwMaxPreviewImages; |
29 | 39 | |
30 | 40 | if (!$concept) return false; |
31 | 41 | |
32 | 42 | if (is_array($concept) && !isset($concept['id'])) $images = $concept; #XXX: HACK |
33 | | - else $images = $utils->getImagesAbout($concept, $wwMaxPreviewImages); |
| 43 | + else $images = getImagesAbout($concept, $wwMaxPreviewImages); |
34 | 44 | |
| 45 | + if (!$images) return; |
| 46 | + |
| 47 | + $imgList = array_values($images); |
| 48 | + |
35 | 49 | ?> |
36 | | - <ul class="<?php print $class; ?>"> |
| 50 | + <table class="imageTable <?php print $class; ?>"> |
| 51 | + <tbody> |
37 | 52 | <?php |
38 | | - foreach ($images as $img) { |
39 | | - ?><li><?php |
40 | | - print $utils->getThumbnailHTML($img, $wwThumbSize, $wwThumbSize); |
41 | | - ?></li><?php |
| 53 | + $i = 0; |
| 54 | + $c = count($images); |
| 55 | + while ($i < $c) { |
| 56 | + $i = printConceptImageRow($imgList, $i, $columns); |
42 | 57 | } |
43 | 58 | ?> |
44 | | - </ul> |
| 59 | + </tr> |
| 60 | + </tbody> |
| 61 | + </table> |
45 | 62 | <?php |
46 | 63 | } |
47 | 64 | |
| 65 | +function printConceptImageRow($images, $from, $columns = 5) { |
| 66 | + global $wwThumbSize, $utils; |
| 67 | + |
| 68 | + $cw = $wwThumbSize + 20; |
| 69 | + $cwcss = $cw . "px"; |
| 70 | + |
| 71 | + $c = count($images); |
| 72 | + |
| 73 | + $to = $from + $columns; |
| 74 | + if ( $to > $c ) $to = $c; |
| 75 | + |
| 76 | + print "\t<tr class=\"imageRow\">\n"; |
| 77 | + |
| 78 | + for ($i = $from; $i<$to; $i += 1) { |
| 79 | + $img = $images[$i]; |
| 80 | + print "\t\t<td class=\"imageCell\" width=\"$cw\" align=\"left\" valign=\"bottom\" nowrap=\"nowrap\" style=\"width: $cwcss\">"; |
| 81 | + print $utils->getThumbnailHTML($img, $wwThumbSize, $wwThumbSize); |
| 82 | + print "</td>\n"; |
| 83 | + } |
| 84 | + |
| 85 | + print "\n\t</tr>\n"; |
| 86 | + |
| 87 | + print "\t<tr class=\"imageMetaRow\">\n"; |
| 88 | + |
| 89 | + for ($i = $from; $i<$to; $i += 1) { |
| 90 | + $img = $images[$i]; |
| 91 | + $title = str_replace("_", " ", $img['name']); |
| 92 | + |
| 93 | + print "\t\t<td class=\"imageMetaCell\" width=\"$cw\" align=\"left\" valign=\"top\" style=\"width: $cwcss\">"; |
| 94 | + print "<div class=\"imageTitle\">" . htmlspecialchars( $title ) . "</div>"; |
| 95 | + print "</td>\n"; |
| 96 | + } |
| 97 | + |
| 98 | + print "\n\t</tr>\n"; |
| 99 | + |
| 100 | + return $to; |
| 101 | +} |
| 102 | + |
48 | 103 | function getConceptDetailsURL($langs, $concept) { |
49 | 104 | global $wwSelf; |
50 | 105 | |
— | — | @@ -55,6 +110,7 @@ |
56 | 111 | function getConceptDetailsLink($langs, $concept) { |
57 | 112 | global $utils; |
58 | 113 | $name = $utils->pickLocal($concept['name'], $langs); |
| 114 | + $name = str_replace("_", " ", $name); |
59 | 115 | $score = @$concept['score']; |
60 | 116 | |
61 | 117 | $u = getConceptDetailsURL($langs, $concept); |
— | — | @@ -194,7 +250,7 @@ |
195 | 251 | extract( $concept ); |
196 | 252 | $wclass = getWeightClass($score); |
197 | 253 | $lclass = $terse ? "terselist" : "list"; |
198 | | - $gallery = $utils->getImagesAbout($concept, $terse ? $wwMaxPreviewImages : $wwMaxGalleryImages ); |
| 254 | + $gallery = getImagesAbout($concept, $terse ? $wwMaxPreviewImages : $wwMaxGalleryImages ); |
199 | 255 | |
200 | 256 | if (is_array($definition)) $definition = $utils->pickLocal($definition, $langs); |
201 | 257 | |
— | — | @@ -228,12 +284,11 @@ |
229 | 285 | </tr> |
230 | 286 | |
231 | 287 | <tr class="row_images"> |
232 | | - <td></td> |
233 | 288 | <td class="cell_images" colspan="3"> |
234 | 289 | <?php |
235 | 290 | printConceptImageList( $gallery, $terse ? "tersegallery" : "gallery" ); |
236 | 291 | ?> |
237 | | - more...<!-- TODO --> |
| 292 | + <p>more...<!-- TODO --></p> |
238 | 293 | </td> |
239 | 294 | </tr> |
240 | 295 | |
— | — | @@ -278,7 +333,10 @@ |
279 | 334 | $thesaurus->connect($wwDBServer, $wwDBUser, $wwDBPassword, $wwDBDatabase); |
280 | 335 | } |
281 | 336 | |
282 | | -$utils = new WWImages( $thesaurus ); |
| 337 | +if (@$wwFakeImages) $utils = new WWFakeImages( $thesaurus ); |
| 338 | +else $utils = new WWImages( $thesaurus ); |
| 339 | + |
| 340 | + |
283 | 341 | if ( !$utils->db ) $utils->connect($wwDBServer, $wwDBUser, $wwDBPassword, $wwDBDatabase); |
284 | 342 | |
285 | 343 | if (@$_REQUEST['debug']) $utils->debug = true; |
— | — | @@ -290,7 +348,11 @@ |
291 | 349 | |
292 | 350 | $languages = array( $lang, "en", "commons" ); #TODO: make the user define this list |
293 | 351 | |
| 352 | +$profiling['thesaurus'] = 0; |
| 353 | +$profiling['pics'] = 0; |
| 354 | + |
294 | 355 | if (!$error) { |
| 356 | + $t = microtime(true); |
295 | 357 | try { |
296 | 358 | if ($lang && $conceptId) { |
297 | 359 | $result = $thesaurus->getConceptInfo($conceptId, $lang); |
— | — | @@ -301,6 +363,7 @@ |
302 | 364 | } catch (Exception $e) { |
303 | 365 | $error = $e->getMessage(); |
304 | 366 | } |
| 367 | + $profiling['thesaurus'] += (microtime(true) - $t); |
305 | 368 | } |
306 | 369 | |
307 | 370 | |
— | — | @@ -314,6 +377,11 @@ |
315 | 378 | body { font-family: verdana, helvetica, arial, sans-serif; } |
316 | 379 | td { text-align: left; vertical-align: top; } |
317 | 380 | th { text-align: left; vertical-align: top; font-weight:bold; } |
| 381 | + |
| 382 | + a:link, a:visited, a:active { |
| 383 | + color:#2200CC; |
| 384 | + } |
| 385 | + |
318 | 386 | .error { color: red; font-weight: bold; } |
319 | 387 | .weight_huge { font-size: 140%; font-weight:bold; } |
320 | 388 | .weight_big { font-size: 120%; font-weight:bold; } |
— | — | @@ -321,8 +389,10 @@ |
322 | 390 | .weight_some { font-size: 100%; font-weight:bold; } |
323 | 391 | .weight_little { font-size: 90%; font-weight:bold; } |
324 | 392 | .weight_unknown { font-size: 100%; font-weight:bold; } |
325 | | - .row_def td { font-size: 80%; font-style:italic; } |
326 | | - .row_details td { font-size: 80%; } |
| 393 | + .row_def td { font-size: small; font-style:italic; } |
| 394 | + .row_details td { font-size: small; } |
| 395 | + .row_related td { font-size: small; } |
| 396 | + .row_category td { font-size: small; font-weight: bold; } |
327 | 397 | .cell_weight { text-align: right; } |
328 | 398 | .cell_label { text-align: right; } |
329 | 399 | .header { text-align: left; } |
— | — | @@ -331,10 +401,22 @@ |
332 | 402 | .note { font-size:80%; } |
333 | 403 | |
334 | 404 | .tersegallery, .tersegallery li, .terselist, .terselist li { display: inline; margin:0; padding:0; } |
335 | | - .terselist li:before { content:" - " } |
| 405 | + .terselist li:before { content:", " } |
336 | 406 | .terselist li:first-child:before { content:"" } |
337 | 407 | |
338 | 408 | .gallery li { display: inline; padding:0.5ex; margin:0.5ex; } |
| 409 | + .results { margin: 1em; } |
| 410 | + |
| 411 | + .imageCell { |
| 412 | + vertical-align: bottom; |
| 413 | + padding-top: 1em; |
| 414 | + } |
| 415 | + .imageCell img { border: 1px solid; } |
| 416 | + .imageCell, .imageMetaCell { |
| 417 | + font-size:small; |
| 418 | + border-spacing: 1em 0; |
| 419 | + margin: 1em; |
| 420 | + } |
339 | 421 | </style> |
340 | 422 | </head> |
341 | 423 | <body> |
— | — | @@ -362,6 +444,13 @@ |
363 | 445 | </tr> |
364 | 446 | </table> |
365 | 447 | <p class="note">Note: this is a thesaurus lookup, not a full text search. Only exact matches are considered.</p> |
| 448 | + <?php |
| 449 | + if ($utils->debug) { |
| 450 | + print '<input type="hidden" name="debug" value="true"/>'; |
| 451 | + print "<p>debug mode enabled!</p>"; |
| 452 | + flush(); |
| 453 | + } |
| 454 | + ?> |
366 | 455 | </form> |
367 | 456 | </div> |
368 | 457 | <?php |
— | — | @@ -401,6 +490,11 @@ |
402 | 491 | The WikiWord Navigator is part of the <a href="http://wikimedia.de">Wikimedia</a> project <a href="http://brightbyte.de/page/WikiWord">WikiWord</a> |
403 | 492 | <p> |
404 | 493 | </body> |
| 494 | +<?php |
| 495 | +foreach ( $profiling as $key => $value ) { |
| 496 | + print "<!-- $key: $value sec -->\n"; |
| 497 | +} |
| 498 | +?> |
405 | 499 | </html> |
406 | 500 | <?php |
407 | 501 | $utils->close(); |
Index: trunk/WikiWord/WikiWord/src/main/php/common/wwimages.php |
— | — | @@ -501,3 +501,104 @@ |
502 | 502 | return $html; |
503 | 503 | } |
504 | 504 | } |
| 505 | + |
| 506 | +class WWFakeImages extends WWImages { |
| 507 | + |
| 508 | + function __construct($thesaurus) { |
| 509 | + WWImages::__construct($thesaurus); |
| 510 | + |
| 511 | + $this->somePics = array( |
| 512 | + "Carrots_of_many_colors.jpg", |
| 513 | + "Infantryman_in_1942_with_M1_Garand,_Fort_Knox,_KY.jpg", |
| 514 | + "Wilhelmshaven_Meerjungfrau.jpg", |
| 515 | + ); |
| 516 | + |
| 517 | + $this->morePics = array( |
| 518 | + "Yellow_Tiger_Moth_Góraszka.JPG", |
| 519 | + "Mauritania_boy1.jpg", |
| 520 | + "Mavericks_Surf_Contest_2010b.jpg", |
| 521 | + ); |
| 522 | + |
| 523 | + $this->fewPics = array( |
| 524 | + $this->somePics[0], |
| 525 | + $this->morePics[0], |
| 526 | + ); |
| 527 | + |
| 528 | + $this->allPics = array_merge($this->somePics, $this->morePics); |
| 529 | + } |
| 530 | + |
| 531 | + function queryImagesOnPage($lang, $ns, $title, $commonsOnly = false) { |
| 532 | + throw new Exception( __METHOD__ . " not implemented" ); |
| 533 | + } |
| 534 | + |
| 535 | + function getImagesOnPage($lang, $ns, $title, $commonsOnly = false) { |
| 536 | + return $this->somePics; |
| 537 | + } |
| 538 | + |
| 539 | + function queryImagesOnPageTemplates($lang, $ns, $title, $commonsOnly = false) { |
| 540 | + throw new Exception( __METHOD__ . " not implemented" ); |
| 541 | + } |
| 542 | + |
| 543 | + function getImagesOnPageTemplates($lang, $ns, $title, $commonsOnly = false) { |
| 544 | + return $this->fewPics; |
| 545 | + } |
| 546 | + |
| 547 | + function queryImagesInCategory($lang, $title) { |
| 548 | + throw new Exception( __METHOD__ . " not implemented" ); |
| 549 | + } |
| 550 | + |
| 551 | + function getImagesInCategory($lang, $title) { |
| 552 | + return $this->allPics; |
| 553 | + } |
| 554 | + |
| 555 | + function queryTagsForImages($lang, $images, $tagTable) { |
| 556 | + throw new Exception( __METHOD__ . " not implemented" ); |
| 557 | + } |
| 558 | + |
| 559 | + function getTagsForImages($lang, $images, $tagTable) { |
| 560 | + return array("Quux", "Xyzzy"); |
| 561 | + } |
| 562 | + |
| 563 | + function queryTemplatesOnImagePage($lang, $image) { |
| 564 | + throw new Exception( __METHOD__ . " not implemented" ); |
| 565 | + } |
| 566 | + |
| 567 | + function getTemplatesOnImagePage($lang, $image) { |
| 568 | + return array("Quux", "Xyzzy"); |
| 569 | + } |
| 570 | + |
| 571 | + function queryCategoriesOfImagePage($lang, $image) { |
| 572 | + throw new Exception( __METHOD__ . " not implemented" ); |
| 573 | + } |
| 574 | + |
| 575 | + function getCategoriesOfImagePage($lang, $image) { |
| 576 | + return array("Splorg", "Snork"); |
| 577 | + } |
| 578 | + |
| 579 | + function queryImagesOnPagesGlobally( $concepts ) { |
| 580 | + throw new Exception( __METHOD__ . " not implemented" ); |
| 581 | + } |
| 582 | + |
| 583 | + function getImagesOnPagesGlobally( $concepts ) { |
| 584 | + return $this->allPics; |
| 585 | + } |
| 586 | + |
| 587 | + function queryGlobalUsageCounts( $images, $wikis = ".*wiki" ) { |
| 588 | + throw new Exception( __METHOD__ . " not implemented" ); |
| 589 | + } |
| 590 | + |
| 591 | + function getGlobalUsageCounts( $images, $wikis = ".*wiki" ) { |
| 592 | + if (!$images) return array(); |
| 593 | + |
| 594 | + foreach ($images as $current) { |
| 595 | + $imageUsage[$current] = array( |
| 596 | + "xx" => 2, |
| 597 | + "yy" => 3, |
| 598 | + "zz" => 6, |
| 599 | + "*max*" => 6 |
| 600 | + ); |
| 601 | + } |
| 602 | + |
| 603 | + return $imageUsage; |
| 604 | + } |
| 605 | +} |
\ No newline at end of file |
Index: trunk/WikiWord/WikiWord/src/main/php/common/wwutils.php |
— | — | @@ -23,7 +23,8 @@ |
24 | 24 | if ($db == NULL && isset($this)) $db = $this->db; |
25 | 25 | |
26 | 26 | if ($this->debug) { |
27 | | - print "\n<br/>" . htmlspecialchars($sql) . "<br/>\n"; |
| 27 | + print "\n<pre>" . htmlspecialchars($sql) . "</pre>\n"; |
| 28 | + flush(); |
28 | 29 | } |
29 | 30 | |
30 | 31 | if (!$db) { |