r64835 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64834‎ | r64835 | r64836 >
Date:21:45, 9 April 2010
Author:daniel
Status:deferred
Tags:
Comment:
wikipics layout
Modified paths:
  • /trunk/WikiWord/WikiWord/src/main/php/common/wwimages.php (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/php/config.sample.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
@@ -8,19 +8,28 @@
99 if ($wwAPI) require_once("$IP/common/wwclient.php");
1010 else require_once("$IP/common/wwthesaurus.php");
1111
12 -function printConceptList($langs, $concepts, $class) {
13 - if (!$concepts) return;
 12+function printConceptList($langs, $concepts, $class, $limit = false) {
 13+ if (!$concepts) return false;
 14+
 15+ if (!$limit || $limit > count($concepts)) $limit = count($concepts);
 16+
 17+ $i = 0;
1418 ?>
1519 <ul class="<?php print $class; ?>">
1620 <?php
1721 foreach ($concepts as $c) {
1822 ?><li><?php
1923 print getConceptDetailsLink($langs, $c);
 24+
 25+ $i += 1;
 26+ if ($i >= $limit) break;
2027 ?></li><?php
2128 }
2229 ?>
2330 </ul>
2431 <?php
 32+
 33+ return $i < count($concepts);
2534 }
2635
2736 function getImagesAbout($concept, $max) {
@@ -33,44 +42,43 @@
3443 return $pics;
3544 }
3645
37 -function printConceptImageList($concept, $class = "tersetable", $columns = 5) {
38 - global $utils, $wwThumbSize, $wwMaxPreviewImages;
 46+function printConceptImageList($concept, $class = "tersetable", $columns = 5, $limit = false ) {
 47+ global $utils, $wwThumbSize;
3948
4049 if (!$concept) return false;
4150
4251 if (is_array($concept) && !isset($concept['id'])) $images = $concept; #XXX: HACK
43 - else $images = getImagesAbout($concept, $wwMaxPreviewImages);
 52+ else $images = getImagesAbout($concept, $max ? $max +1 : false);
4453
4554 if (!$images) return;
4655
4756 $imgList = array_values($images);
4857
4958 ?>
50 - <table class="imageTable <?php print $class; ?>">
51 - <tbody>
 59+ <table class="imageTable <?php print $class; ?>" summary="images">
5260 <?php
5361 $i = 0;
5462 $c = count($images);
55 - while ($i < $c) {
56 - $i = printConceptImageRow($imgList, $i, $columns);
 63+ if (!$limit || $limit > $c) $limit = $c;
 64+
 65+ while ($i < $limit) {
 66+ $i = printConceptImageRow($imgList, $i, $limit, $columns);
5767 }
5868 ?>
59 - </tr>
60 - </tbody>
6169 </table>
6270 <?php
 71+
 72+ return $i < $c;
6373 }
6474
65 -function printConceptImageRow($images, $from, $columns = 5) {
 75+function printConceptImageRow($images, $from, $limit, $columns = 5) {
6676 global $wwThumbSize, $utils;
6777
6878 $cw = $wwThumbSize + 20;
6979 $cwcss = $cw . "px";
7080
71 - $c = count($images);
72 -
7381 $to = $from + $columns;
74 - if ( $to > $c ) $to = $c;
 82+ if ( $to > $limit ) $to = $limit;
7583
7684 print "\t<tr class=\"imageRow\">\n";
7785
@@ -87,8 +95,11 @@
8896
8997 for ($i = $from; $i<$to; $i += 1) {
9098 $img = $images[$i];
91 - $title = str_replace("_", " ", $img['name']);
9299
 100+ $title = $img['name'];
 101+ $title = str_replace("_", " ", $title);
 102+ $title = preg_replace("/\\.[^.]+$/", "", $title);
 103+
93104 print "\t\t<td class=\"imageMetaCell\" width=\"$cw\" align=\"left\" valign=\"top\" style=\"width: $cwcss\">";
94105 print "<div class=\"imageTitle\">" . htmlspecialchars( $title ) . "</div>";
95106 print "</td>\n";
@@ -107,14 +118,17 @@
108119 return "$wwSelf?id=" . urlencode($concept['id']) . "&lang=" . urlencode($langs);
109120 }
110121
111 -function getConceptDetailsLink($langs, $concept) {
 122+function getConceptDetailsLink($langs, $concept, $text = NULL) {
112123 global $utils;
 124+
113125 $name = $utils->pickLocal($concept['name'], $langs);
114126 $name = str_replace("_", " ", $name);
115127 $score = @$concept['score'];
 128+
 129+ if ($text === null) $text = $name;
116130
117131 $u = getConceptDetailsURL($langs, $concept);
118 - return '<a href="' . htmlspecialchars($u) . '" title="' . htmlspecialchars($name) . ' (score: ' . (int)$score . ')'. '">' . htmlspecialchars($name) . '</a>';
 132+ return '<a href="' . htmlspecialchars($u) . '" title="' . htmlspecialchars($name) . ' (score: ' . (int)$score . ')'. '">' . htmlspecialchars($text) . '</a>';
119133 }
120134
121135 function pickPage( $pages ) {
@@ -177,19 +191,32 @@
178192 <?php
179193 }
180194
181 -function printConceptPageList( $langs, $concept, $class ) {
 195+function printConceptPageList( $langs, $concept, $class, $limit = false ) {
182196 $linksByLanguage = getAllConceptPageLinks($concept);
 197+
 198+ $i = 0;
 199+ $more = false;
183200 ?>
184201 <ul class="<?php print htmlspecialchars($class); ?>">
185202 <?php
186203 foreach ( $linksByLanguage as $lang => $links ) {
187204 foreach ($links as $link ) {
188205 print "\t\t<li>" . $link . "</li>\n";
 206+
 207+ $i += 1;
 208+ if ($limit && $i >= $limit) break;
189209 }
 210+
 211+ if ($limit && $i >= $limit) {
 212+ $more = true;
 213+ break;
 214+ }
190215 }
191216 ?>
192217 </ul>
193218 <?php
 219+
 220+ return $more;
194221 }
195222
196223 function array_key_diff($base, $other) {
@@ -201,7 +228,7 @@
202229 return $base;
203230 }
204231
205 -function printRelatedConceptList( $langs, $concept, $class = "" ) {
 232+function getRelatedConceptList( $concept ) {
206233 $related = array();
207234 if ( @$concept['similar'] ) $related += $concept['similar'];
208235 if ( @$concept['related'] ) $related += $concept['related'];
@@ -209,13 +236,9 @@
210237
211238 if (isset($concept['broader'])) $related = array_key_diff($related, $concept['broader']);
212239
213 - printConceptList($langs, $related, $class);
 240+ return $related;
214241 }
215242
216 -function printConceptCategoryList( $langs, $concept, $class = "" ) {
217 - if (isset($concept['broader'])) printConceptList($langs, $concept['broader'], $class);
218 -}
219 -
220243 function printDefList($items, $scapeKeys = true, $escapeValues = true, $class = "list") {
221244 ?>
222245 <dl class="<?php print htmlspecialchars($class); ?>">
@@ -245,12 +268,12 @@
246269 }
247270
248271 function printConcept($concept, $langs, $terse = true) {
249 - global $utils, $wwMaxPreviewImages, $wwMaxGalleryImages;
 272+ global $utils, $wwMaxPreviewImages, $wwMaxGalleryImages, $wwMaxPreviewLinks, $wwGalleryColumns;
250273
251274 extract( $concept );
252275 $wclass = getWeightClass($score);
253276 $lclass = $terse ? "terselist" : "list";
254 - $gallery = getImagesAbout($concept, $terse ? $wwMaxPreviewImages : $wwMaxGalleryImages );
 277+ $gallery = getImagesAbout($concept, $terse ? $wwMaxPreviewImages*2 : $wwMaxGalleryImages+1 );
255278
256279 if (is_array($definition)) $definition = $utils->pickLocal($definition, $langs);
257280
@@ -259,39 +282,54 @@
260283 <td colspan="3">
261284 <h1 class="name <?php print "weight_$wclass"; ?>"><?php print getConceptDetailsLink($langs, $concept); ?>:</h1>
262285 <p class="definition"><?php print htmlspecialchars($definition); ?></p>
263 - <div class="wikipages">Pages: <?php printConceptPageList($langs, $concept, $lclass) ?></div>
 286+ <div class="wikipages"><strong class="label">Pages:</strong> <?php printConceptPageList( $langs, $concept, $lclass, $terse ? $wwMaxPreviewLinks : $wwMaxDetailLinks ) ?></div>
264287 </td>
265288 </tr>
266289
267290 <tr class="row_images">
268 - <td class="cell_images" colspan="3">
 291+ <td class="cell_images" colspan="2">
269292 <?php
270 - printConceptImageList( $gallery, $terse ? "tersegallery" : "gallery" );
 293+ $more = printConceptImageList( $gallery, $terse ? "tersegallery" : "gallery", $wwGalleryColumns, $terse ? $wwMaxPreviewImages : $wwMaxGalleryImages );
271294 ?>
272 - <p>more...<!-- TODO --></p>
273295 </td>
 296+ <td class="cell_more_images" colspan="1" width="100%" style="vertical-align:bottom; padding: 1ex; font-size:normal;">
 297+ <?php if ($terse && $more) print " <div><strong class=\"more\">[" . getConceptDetailsLink($langs, $concept, "more...") . "]</strong></div>"; ?>
 298+ </td>
274299 </tr>
275300
 301+ <?php
 302+ $related = getRelatedConceptList($concept);
 303+ if ($related) {
 304+ ?>
276305 <tr class="row_related">
277306 <td class="cell_related" colspan="3">
278 - Related:
 307+ <strong class="label">Related:</strong>
279308 <?php
280 - printRelatedConceptList( $langs, $concept, $lclass );
 309+ $more = printConceptList( $langs, $related, $lclass, $terse ? $wwMaxPreviewLinks : $wwMaxDetailLinks );
281310 ?>
282 - <p>more...<!-- TODO --></p>
 311+ <?php if ($terse && $more) print " <strong class=\"more\">[" . getConceptDetailsLink($langs, $concept, "more...") . "]</strong>"; ?>
283312 </td>
284313 </tr>
 314+ <?php } ?>
285315
 316+ <?php if (@$concept['broader']) { ?>
286317 <tr class="row_category">
287318 <td class="cell_related" colspan="3">
288 - Broader:
 319+ <strong class="label">Broader:</strong>
289320 <?php
290 - printConceptCategoryList( $langs, $concept, $lclass );
 321+ $more = printConceptList( $langs, $concept['broader'], $lclass, $terse ? $wwMaxPreviewLinks : $wwMaxDetailLinks );
291322 ?>
292 - <p>more...<!-- TODO --></p>
 323+ <?php if ($terse && $more) print " <strong class=\"more\">[" . getConceptDetailsLink($langs, $concept, "more...") . "]</strong>"; ?>
293324 </td>
294325 </tr>
 326+ <?php } ?>
295327
 328+ <tr class="row_blank">
 329+ <td class="cell_blank" colspan="3">
 330+ &nbsp;
 331+ </td>
 332+ </tr>
 333+
296334 <?php
297335 if (isset($score) && $score && $score<2 && $pos>=3) return false;
298336 else return true;
@@ -354,7 +392,7 @@
355393 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
356394 <head>
357395 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
358 - <title>WikiWord Navigator</title>
 396+ <title>WikiPics: multilingual search for Wikimedia Commons</title>
359397
360398 <style type="text/css">
361399 body { font-family: verdana, helvetica, arial, sans-serif; }
@@ -393,21 +431,29 @@
394432 .row_head .definition { font-style: italic; display:inline; }
395433 .row_head .wikipages { font-style: inherit; display:inline; }
396434
397 - .row_related td { font-size: small; }
398 - .row_category td { font-size: small; }
 435+ .row_images td { vertical-align: bottom; }
 436+
 437+ .row_related td { font-size: small; background-color: #F0F7F9; }
 438+ .row_category td { font-size: small; background-color: #F0F7F9; }
 439+ .row_blank td { font-size: small; }
 440+
 441+ /*
399442 .cell_weight { text-align: right; }
400 - .cell_label { text-align: right; }
 443+ .cell_label { text-align: right; font-weight: bold; }
 444+ */
401445
402 - .header { text-align: left; margin:0; padding: 0; border-bottom: 1px solid #C9D7F1; }
 446+ .label { font-weight: bold; }
 447+ .note { font-size:small; }
403448
 449+ .header { font-size:small; text-align: left; margin:0 0 1ex 0; padding: 0; border-bottom: 1px solid #C9D7F1; }
 450+
404451 .inputform { text-align: left; margin:0 1ex; }
405452 .inputform td { text-align: left; vertical-align: bottom; padding: 0.5ex; }
406453 .inputform td.note { font-size:small; }
407454 .inputform th { text-align: left; vertical-align: bottom; }
408455
409456
410 - .footer { font-size:80%; text-align: center; border-top: 1px solid #666666; }
411 - .note { font-size:80%; }
 457+ .footer { font-size:small; text-align: center; margin:1ex 0 0 0; padding: 0; border-top: 1px solid #C9D7F1; }
412458
413459 .tersegallery, .tersegallery li, .terselist, .terselist li { display: inline; margin:0; padding:0; }
414460 .terselist li:before { content:", " }
@@ -419,12 +465,12 @@
420466 .results td { text-align: left; vertical-align: top; }
421467 .results th { text-align: left; vertical-align: top; font-weight:bold; }
422468
423 - .imageCell {
 469+ .imageTable td.imageCell {
424470 vertical-align: bottom;
425471 padding-top: 1em;
426472 }
427 - .imageCell img { border: 1px solid; }
428 - .imageCell, .imageMetaCell {
 473+ .imageTable td.imageCell img { border: 1px solid; }
 474+ .imageTable td.imageCell, .imageTable td.imageMetaCell {
429475 font-size:small;
430476 border-spacing: 1em 0;
431477 margin: 1em;
@@ -441,12 +487,12 @@
442488
443489 <div class="inputform" >
444490 <form name="search" action="<?php print $wwSelf; ?>">
445 - <table border="0" class="inputgrid">
 491+ <table border="0" class="inputgrid" summary="input form">
446492 <tr>
447493 <td>
448494 <?php
449495 $u = $utils->getThumbnailURL("Commons_logo_optimized.svg", 60);
450 - print "<img class=\"logo\" src=\"".htmlspecialchars($u)."\" title=\"Search Wikimedia Commons\" valign=\"bottom\"/>";
 496+ print "<img class=\"logo\" alt=\"Wikimedia Commons Logo\" src=\"".htmlspecialchars($u)."\" title=\"Search Wikimedia Commons\" align=\"bottom\"/>";
451497 ?>
452498 </td>
453499 <td>
@@ -484,32 +530,37 @@
485531 if ($result) {
486532 if ( $conceptId ) $terse = false;
487533 else $terse = true;
488 -
 534+?>
 535+ <table border="0" class="results" cellspacing="0" summary="search results">
 536+<?php
489537 $count = 0;
490538 foreach ( $result as $row ) {
491539 $count = $count + 1;
492540 $row['pos'] = $count;
493541
494542 ?>
495 - <table border="0" class="results">
496543 <?php
497544 $continue= printConcept($row, $languages, $terse);
498545
499546 if (!$continue) break;
500547 ?>
501 - </table>
502548
503549 <?php
504550 } #concept loop
505551
 552+?>
 553+ </table>
 554+<?php
 555+
506556 if ($term) { ?>
507557 <p>Found <?php print $count; ?> items.</p>
508558 <?php }
509559 } ?>
510560
511 -<p class="footer">
512 -The WikiWord Navigator is part of the <a href="http://wikimedia.de">Wikimedia</a> project <a href="http://brightbyte.de/page/WikiWord">WikiWord</a>
513 -<p>
 561+<div class="footer">
 562+<p>The WikiWord Navigator is part of the <a href="http://wikimedia.de">Wikimedia</a> project <a href="http://brightbyte.de/page/WikiWord">WikiWord</a></p>
 563+
 564+</div>
514565 </body>
515566 <?php
516567 foreach ( $profiling as $key => $value ) {
Index: trunk/WikiWord/WikiWord/src/main/php/common/wwimages.php
@@ -511,12 +511,16 @@
512512 "Carrots_of_many_colors.jpg",
513513 "Infantryman_in_1942_with_M1_Garand,_Fort_Knox,_KY.jpg",
514514 "Wilhelmshaven_Meerjungfrau.jpg",
 515+ "Sunrise_over_Veterans_Park_2420.jpg",
 516+ "Halde_Rheinpreußen,_Grubenlampe,_III_retouched.jpg",
515517 );
516518
517519 $this->morePics = array(
518520 "Yellow_Tiger_Moth_Góraszka.JPG",
519521 "Mauritania_boy1.jpg",
520522 "Mavericks_Surf_Contest_2010b.jpg",
 523+ "Sellers_translating_along_truss_during_EVA-3_on_STS-121.jpg",
 524+ "Fruitbowlwithmelons.jpg",
521525 );
522526
523527 $this->fewPics = array(
Index: trunk/WikiWord/WikiWord/src/main/php/config.sample.php
@@ -16,8 +16,11 @@
1717
1818 #error_reporting(E_ALL);
1919
20 -$wwMaxPreviewImages = 8;
 20+$wwMaxPreviewImages = 5;
 21+$wwMaxPreviewLinks = 20;
 22+$wwGalleryColumns = 5;
2123 $wwMaxGalleryImages = 200;
 24+$wwMaxDetailLinks = 1000;
2225 $wwThumbSize = 120;
2326 $wwThumbnailURL = "http://toolserver.org/tsthumb/tsthumb?f={name}&domain=commons.wikimedia.org&w={width}&h={height}";
2427 $wwImagePageURL = "http://commons.wikimedia.org/wiki/File:{name}";

Status & tagging log