r64805 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64804‎ | r64805 | r64806 >
Date:16:54, 9 April 2010
Author:daniel
Status:deferred
Tags:
Comment:
wikipics is getting there. slowly.
Modified paths:
  • /trunk/WikiWord/WikiWord/src/main/php/common/wwimages.php (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/php/common/wwutils.php (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/php/search/wikipics.php (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWord/src/main/php/search/wikipics.php
@@ -23,27 +23,82 @@
2424 <?php
2525 }
2626
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) {
2838 global $utils, $wwThumbSize, $wwMaxPreviewImages;
2939
3040 if (!$concept) return false;
3141
3242 if (is_array($concept) && !isset($concept['id'])) $images = $concept; #XXX: HACK
33 - else $images = $utils->getImagesAbout($concept, $wwMaxPreviewImages);
 43+ else $images = getImagesAbout($concept, $wwMaxPreviewImages);
3444
 45+ if (!$images) return;
 46+
 47+ $imgList = array_values($images);
 48+
3549 ?>
36 - <ul class="<?php print $class; ?>">
 50+ <table class="imageTable <?php print $class; ?>">
 51+ <tbody>
3752 <?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);
4257 }
4358 ?>
44 - </ul>
 59+ </tr>
 60+ </tbody>
 61+ </table>
4562 <?php
4663 }
4764
 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+
48103 function getConceptDetailsURL($langs, $concept) {
49104 global $wwSelf;
50105
@@ -55,6 +110,7 @@
56111 function getConceptDetailsLink($langs, $concept) {
57112 global $utils;
58113 $name = $utils->pickLocal($concept['name'], $langs);
 114+ $name = str_replace("_", " ", $name);
59115 $score = @$concept['score'];
60116
61117 $u = getConceptDetailsURL($langs, $concept);
@@ -194,7 +250,7 @@
195251 extract( $concept );
196252 $wclass = getWeightClass($score);
197253 $lclass = $terse ? "terselist" : "list";
198 - $gallery = $utils->getImagesAbout($concept, $terse ? $wwMaxPreviewImages : $wwMaxGalleryImages );
 254+ $gallery = getImagesAbout($concept, $terse ? $wwMaxPreviewImages : $wwMaxGalleryImages );
199255
200256 if (is_array($definition)) $definition = $utils->pickLocal($definition, $langs);
201257
@@ -228,12 +284,11 @@
229285 </tr>
230286
231287 <tr class="row_images">
232 - <td></td>
233288 <td class="cell_images" colspan="3">
234289 <?php
235290 printConceptImageList( $gallery, $terse ? "tersegallery" : "gallery" );
236291 ?>
237 - more...<!-- TODO -->
 292+ <p>more...<!-- TODO --></p>
238293 </td>
239294 </tr>
240295
@@ -278,7 +333,10 @@
279334 $thesaurus->connect($wwDBServer, $wwDBUser, $wwDBPassword, $wwDBDatabase);
280335 }
281336
282 -$utils = new WWImages( $thesaurus );
 337+if (@$wwFakeImages) $utils = new WWFakeImages( $thesaurus );
 338+else $utils = new WWImages( $thesaurus );
 339+
 340+
283341 if ( !$utils->db ) $utils->connect($wwDBServer, $wwDBUser, $wwDBPassword, $wwDBDatabase);
284342
285343 if (@$_REQUEST['debug']) $utils->debug = true;
@@ -290,7 +348,11 @@
291349
292350 $languages = array( $lang, "en", "commons" ); #TODO: make the user define this list
293351
 352+$profiling['thesaurus'] = 0;
 353+$profiling['pics'] = 0;
 354+
294355 if (!$error) {
 356+ $t = microtime(true);
295357 try {
296358 if ($lang && $conceptId) {
297359 $result = $thesaurus->getConceptInfo($conceptId, $lang);
@@ -301,6 +363,7 @@
302364 } catch (Exception $e) {
303365 $error = $e->getMessage();
304366 }
 367+ $profiling['thesaurus'] += (microtime(true) - $t);
305368 }
306369
307370
@@ -314,6 +377,11 @@
315378 body { font-family: verdana, helvetica, arial, sans-serif; }
316379 td { text-align: left; vertical-align: top; }
317380 th { text-align: left; vertical-align: top; font-weight:bold; }
 381+
 382+ a:link, a:visited, a:active {
 383+ color:#2200CC;
 384+ }
 385+
318386 .error { color: red; font-weight: bold; }
319387 .weight_huge { font-size: 140%; font-weight:bold; }
320388 .weight_big { font-size: 120%; font-weight:bold; }
@@ -321,8 +389,10 @@
322390 .weight_some { font-size: 100%; font-weight:bold; }
323391 .weight_little { font-size: 90%; font-weight:bold; }
324392 .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; }
327397 .cell_weight { text-align: right; }
328398 .cell_label { text-align: right; }
329399 .header { text-align: left; }
@@ -331,10 +401,22 @@
332402 .note { font-size:80%; }
333403
334404 .tersegallery, .tersegallery li, .terselist, .terselist li { display: inline; margin:0; padding:0; }
335 - .terselist li:before { content:" - " }
 405+ .terselist li:before { content:", " }
336406 .terselist li:first-child:before { content:"" }
337407
338408 .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+ }
339421 </style>
340422 </head>
341423 <body>
@@ -362,6 +444,13 @@
363445 </tr>
364446 </table>
365447 <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+ ?>
366455 </form>
367456 </div>
368457 <?php
@@ -401,6 +490,11 @@
402491 The WikiWord Navigator is part of the <a href="http://wikimedia.de">Wikimedia</a> project <a href="http://brightbyte.de/page/WikiWord">WikiWord</a>
403492 <p>
404493 </body>
 494+<?php
 495+foreach ( $profiling as $key => $value ) {
 496+ print "<!-- $key: $value sec -->\n";
 497+}
 498+?>
405499 </html>
406500 <?php
407501 $utils->close();
Index: trunk/WikiWord/WikiWord/src/main/php/common/wwimages.php
@@ -501,3 +501,104 @@
502502 return $html;
503503 }
504504 }
 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 @@
2424 if ($db == NULL && isset($this)) $db = $this->db;
2525
2626 if ($this->debug) {
27 - print "\n<br/>" . htmlspecialchars($sql) . "<br/>\n";
 27+ print "\n<pre>" . htmlspecialchars($sql) . "</pre>\n";
 28+ flush();
2829 }
2930
3031 if (!$db) {

Status & tagging log