r65694 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65693‎ | r65694 | r65695 >
Date:15:35, 30 April 2010
Author:daniel
Status:deferred
Tags:
Comment:
split wikipics search into modules
Modified paths:
  • /trunk/WikiWord/WikiWordWeb/src/main/www/skin (added) (history)
  • /trunk/WikiWord/WikiWordWeb/src/main/www/skin/styles.css (added) (history)
  • /trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/form.html.php (added) (history)
  • /trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/response.html.php (added) (history)
  • /trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/search.php (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/response.html.php
@@ -0,0 +1,405 @@
 2+<?php
 3+if (!defined("WIKIPICS")) die("not a valid entry point");
 4+
 5+function printConceptList($langs, $concepts, $class, $limit = false) {
 6+ if (!$concepts) return false;
 7+
 8+ if (!$limit || $limit > count($concepts)) $limit = count($concepts);
 9+
 10+ $i = 0;
 11+ ?>
 12+ <ul class="<?php print $class; ?>">
 13+ <?php
 14+ foreach ($concepts as $c) {
 15+ $link = getConceptDetailsLink($langs, $c);
 16+ if (!$link) continue;
 17+
 18+ ?><li><?php
 19+ print $link;
 20+
 21+ $i += 1;
 22+ if ($i >= $limit) break;
 23+ ?></li><?php
 24+ }
 25+ ?>
 26+ </ul>
 27+ <?php
 28+
 29+ return $i < count($concepts);
 30+}
 31+
 32+function printConceptImageList($concept, $terse = false, $columns = 5, $limit = false ) {
 33+ global $utils, $wwThumbSize;
 34+
 35+ if (!$concept) return false;
 36+
 37+ if (is_array($concept) && !isset($concept['id'])) $images = $concept; #XXX: HACK
 38+ else $images = getImagesAbout($concept, $max ? $max +1 : false);
 39+
 40+ if (!$images) return;
 41+
 42+ $class = $terse ? "terseImageTable" : "";
 43+
 44+ $imgList = array_values($images);
 45+
 46+ $cw = $wwThumbSize + 32; //FIXME: magic number, use config!
 47+
 48+ ?>
 49+ <table class="imageTable <?php print $class; ?>" summary="images" width="<?php print $columns*$cw; ?>">
 50+ <colgroup span="<?php print $columns; ?>" width="<?php print $cw; ?>">
 51+ </colgroup>
 52+
 53+ <?php
 54+ $i = 0;
 55+ $c = count($images);
 56+ if (!$limit || $limit > $c) $limit = $c;
 57+
 58+ while ($i < $limit) {
 59+ $i = printConceptImageRow($imgList, $i, $terse, $columns, $limit);
 60+ }
 61+ ?>
 62+ </table>
 63+ <?php
 64+
 65+ return $i < $c;
 66+}
 67+
 68+function printConceptImageRow($images, $from, $terse, $columns = 5, $limit = false) {
 69+ global $wwThumbSize, $utils;
 70+
 71+ $cw = $wwThumbSize + 32; //FIXME: magic number, use config!
 72+ $cwcss = $cw . "px";
 73+
 74+ $to = $from + $columns;
 75+ if ( $to > $limit ) $to = $limit;
 76+
 77+ print "\t<tr class=\"imageRow\">\n";
 78+
 79+ for ($i = $from; $i<$to; $i += 1) {
 80+ $img = $images[$i];
 81+ print "\t\t<td class=\"imageCell\" width=\"$cw\" align=\"left\" valign=\"bottom\" nowrap=\"nowrap\" style=\"width: $cwcss\"><div class=\"clipBox\" style=\"width:$cwcss; max-width:$cwcss;\">";
 82+ print $utils->getThumbnailHTML($img, $wwThumbSize, $wwThumbSize);
 83+ print "</div></td>\n";
 84+ }
 85+
 86+ print "\n\t</tr>\n";
 87+
 88+ if (!$terse) {
 89+ print "\t<tr class=\"imageMetaRow\">\n";
 90+
 91+ for ($i = $from; $i<$to; $i += 1) {
 92+ $img = $images[$i];
 93+
 94+ $title = $img['name'];
 95+ $title = str_replace("_", " ", $title);
 96+ $title = preg_replace("/\\.[^.]+$/", "", $title);
 97+
 98+ $info = getImageInfo($img);
 99+ $labels = getImageLabels($img);
 100+
 101+ print "\t\t<td class=\"imageMetaCell\" width=\"$cw\" align=\"left\" valign=\"top\" style=\"width: $cwcss\"><div class=\"clipBox\" style=\"width:$cwcss; max-width:$cwcss;\">";
 102+ print "<div class=\"imageTitle\" title=\"" . htmlspecialchars( $img['name'] ) . "\">" . htmlspecialchars( $title ) . "</div>";
 103+
 104+ if ($info) {
 105+ print "<div class=\"imageInfo\">";
 106+ printList($info, false, "terselist");
 107+ print "</div>";
 108+ }
 109+
 110+ if ($labels) {
 111+ print "<div class=\"imageLabels\">";
 112+ printList($labels, false, "terselist");
 113+ print "</div>";
 114+ }
 115+
 116+ print "</div></td>\n";
 117+ }
 118+
 119+ print "\n\t</tr>\n";
 120+ }
 121+
 122+ return $to;
 123+}
 124+
 125+function getConceptDetailsLink($langs, $concept, $text = NULL) {
 126+ global $utils;
 127+
 128+ $name = $utils->pickLocal($concept['name'], $langs);
 129+ if ( $name === false || $name === null) return false;
 130+
 131+ $name = str_replace("_", " ", $name);
 132+ $score = @$concept['score'];
 133+
 134+ if ($text === null) $text = $name;
 135+
 136+ $u = getConceptDetailsURL($langs, $concept);
 137+ return '<a href="' . htmlspecialchars($u) . '" title="' . htmlspecialchars($name) . ' (score: ' . (int)$score . ')'. '">' . htmlspecialchars($text) . '</a>';
 138+}
 139+
 140+function getConceptPageLinks($lang, $concept) {
 141+ $urls = getConceptPageURLs($lang, $concept);
 142+ if (!$urls) return false;
 143+
 144+ foreach ($urls as $page => $u) {
 145+ $links[] = '<a href="' . htmlspecialchars($u) . '" title="' . htmlspecialchars( str_replace("_", " ", $page) ) . '">' . htmlspecialchars( $lang . ":" . str_replace("_", " ", $page) ) . '</a>';
 146+ }
 147+
 148+ return $links;
 149+}
 150+
 151+function getAllConceptPageLinks($concept) {
 152+ $links = array();
 153+
 154+ foreach ( $concept['languages'] as $lang ) {
 155+ $ll = getConceptPageLinks($lang, $concept);
 156+ if ($ll) $links[$lang] = $ll;
 157+ }
 158+
 159+ return $links;
 160+}
 161+
 162+function printList($items, $escape = true, $class = "list") {
 163+ ?>
 164+ <ul class="<?php print htmlspecialchars($class); ?>">
 165+ <?php
 166+ foreach ($items as $item) {
 167+ if ( !$item ) continue;
 168+ if ( $escape ) $item = htmlspecialchars($item);
 169+ print "<li>" . trim($item) . "</li>";
 170+ }
 171+ ?>
 172+ </ul>
 173+ <?php
 174+}
 175+
 176+function printConceptPageList( $langs, $concept, $class, $limit = false ) {
 177+ $linksByLanguage = getAllConceptPageLinks($concept);
 178+
 179+ $i = 0;
 180+ $more = false;
 181+ ?>
 182+ <ul class="<?php print htmlspecialchars($class); ?>">
 183+ <?php
 184+ foreach ( $linksByLanguage as $lang => $links ) {
 185+ foreach ($links as $link ) {
 186+ print "<li>" . trim($link) . "</li>";
 187+
 188+ $i += 1;
 189+ if ($limit && $i >= $limit) break;
 190+ }
 191+
 192+ if ($limit && $i >= $limit) {
 193+ $more = true;
 194+ break;
 195+ }
 196+ }
 197+ ?>
 198+ </ul>
 199+ <?php
 200+
 201+ return $more;
 202+}
 203+
 204+
 205+function printDefList($items, $scapeKeys = true, $escapeValues = true, $class = "list") {
 206+ ?>
 207+ <dl class="<?php print htmlspecialchars($class); ?>">
 208+ <?php
 209+ foreach ($items as $key => $item) {
 210+ if ( $escapeKeys ) $key = htmlspecialchars($key);
 211+ print "\t\t<dt>" . $key . "</dt>\n";
 212+
 213+ if ( $escapeValues ) $item = htmlspecialchars($item);
 214+ print "\t\t\t<dd>" . $item . "</dd>\n";
 215+ }
 216+ ?>
 217+ </sl>
 218+ <?php
 219+}
 220+
 221+function getWeightClass($weight) {
 222+ if (!isset($weight) || !$weight) {
 223+ return "unknown";
 224+ $weight = NULL;
 225+ }
 226+ else if ($weight>1000) return "huge";
 227+ else if ($weight>100) return "big";
 228+ else if ($weight>10) return "normal";
 229+ else if ($weight>2) return "some";
 230+ else return "little";
 231+}
 232+
 233+
 234+function printConcept($concept, $langs, $terse = true) {
 235+ global $utils, $wwMaxPreviewImages, $wwMaxGalleryImages, $wwMaxPreviewLinks, $wwMaxDetailLinks, $wwGalleryColumns;
 236+
 237+ extract( $concept );
 238+ if (@$score) $wclass = getWeightClass($score);
 239+ else $wclass = "";
 240+
 241+ #$lclass = $terse ? "terselist" : "list";
 242+ $lclass = "terselist";
 243+
 244+ $name = $utils->pickLocal($concept['name'], $langs);
 245+ $name = str_replace("_", " ", $name);
 246+
 247+ $gallery = getImagesAbout($concept, $terse ? $wwMaxPreviewImages*2 : $wwMaxGalleryImages+1 );
 248+
 249+ if (empty($definition)) $definition = "";
 250+ else if (is_array($definition)) $definition = $utils->pickLocal($definition, $langs);
 251+
 252+ ?>
 253+ <tr class="row_head">
 254+ <td colspan="3">
 255+ <h1 class="name <?php print "weight_$wclass"; ?>"><?php print getConceptDetailsLink($langs, $concept); ?>:</h1>
 256+ <p class="definition"><?php print htmlspecialchars($definition); ?></p>
 257+ </td>
 258+ </tr>
 259+
 260+ <tr class="row_images">
 261+ <td class="cell_images" colspan="2">
 262+ <?php
 263+ if (!$gallery) print "<p class=\"notice\">No images found for concept <em>".htmlspecialchars($name)."</em>.</p>";
 264+ else $more = printConceptImageList( $gallery, $terse, $wwGalleryColumns, $terse ? $wwMaxPreviewImages : $wwMaxGalleryImages );
 265+ ?>
 266+ </td>
 267+ <?php if ($gallery) { ?>
 268+ <td class="cell_more_images" colspan="1" width="100%" style="vertical-align:bottom; padding: 1ex; font-size:normal;">
 269+ <?php if ($terse) print " <div><strong class=\"more\">[" . getConceptDetailsLink($langs, $concept, "more/details...") . "]</strong></div>"; ?>
 270+ </td>
 271+ <?php } ?>
 272+ </tr>
 273+
 274+ <?php if (@$concept['narrower']) { ?>
 275+ <tr class="row_narrower">
 276+ <td class="cell_related" colspan="3">
 277+ <strong class="label">Narrower:</strong>
 278+ <?php
 279+ $more = printConceptList( $langs, $concept['narrower'], $lclass, $terse ? $wwMaxPreviewLinks : $wwMaxDetailLinks );
 280+ ?>
 281+ <?php if ($terse && $more) print " <strong class=\"more\">[" . getConceptDetailsLink($langs, $concept, "more...") . "]</strong>"; ?>
 282+ </td>
 283+ </tr>
 284+ <?php } ?>
 285+
 286+ <?php
 287+ $related = getRelatedConceptList($concept);
 288+ if ($related) {
 289+ ?>
 290+ <tr class="row_related">
 291+ <td class="cell_related" colspan="3">
 292+ <strong class="label">Related:</strong>
 293+ <?php
 294+ $more = printConceptList( $langs, $related, $lclass, $terse ? $wwMaxPreviewLinks : $wwMaxDetailLinks );
 295+ ?>
 296+ <?php if ($terse && $more) print " <strong class=\"more\">[" . getConceptDetailsLink($langs, $concept, "more...") . "]</strong>"; ?>
 297+ </td>
 298+ </tr>
 299+ <?php } ?>
 300+
 301+ <?php if (@$concept['broader']) { ?>
 302+ <tr class="row_category">
 303+ <td class="cell_related" colspan="3">
 304+ <strong class="label">Broader:</strong>
 305+ <?php
 306+ $more = printConceptList( $langs, $concept['broader'], $lclass, $terse ? $wwMaxPreviewLinks : $wwMaxDetailLinks );
 307+ ?>
 308+ <?php if ($terse && $more) print " <strong class=\"more\">[" . getConceptDetailsLink($langs, $concept, "more...") . "]</strong>"; ?>
 309+ </td>
 310+ </tr>
 311+ <?php } ?>
 312+
 313+ <?php if (!$terse && @$concept['pages']) { ?>
 314+ <tr class="row_pages">
 315+ <td class="cell_pages wikipages" colspan="3">
 316+ <strong class="label">Wiki pages:</strong> <?php $more = printConceptPageList( $langs, $concept, $lclass, $terse ? $wwMaxPreviewLinks : $wwMaxDetailLinks ); ?>
 317+ <?php if ($terse && $more) print " <strong class=\"more\">[" . getConceptDetailsLink($langs, $concept, "more...") . "]</strong>"; ?>
 318+ </td>
 319+ </tr>
 320+ <?php } ?>
 321+
 322+ <tr class="row_blank">
 323+ <td class="cell_blank" colspan="3">
 324+ &nbsp;
 325+ </td>
 326+ </tr>
 327+
 328+ <?php
 329+ if (isset($score) && $score && $score<2 && $pos>=3) return false;
 330+ else return true;
 331+}
 332+
 333+header("Content-Type: text/html; charset=UTF-8");
 334+?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 335+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
 336+<head>
 337+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 338+ <title>WikiPics: multilingual search for Wikimedia Commons</title>
 339+ <link rel="stylesheet" href="../skin/styles.css" type="text/css" media="all" />
 340+</head>
 341+<body>
 342+ <div class="header">
 343+ <div style="float:left">Wikipics 0.1&alpha; (experimental)</div>
 344+ <div style="float:right"><a href="http://wikimedia.de">Wikimedia Deutschland e.V.</a></div>
 345+ <!-- <h1>WikiWord Navigator</h1>
 346+ <p>Experimental semantic navigator and thesaurus interface for Wikipedia.</p>
 347+ <p>The WikiWord Navigator was created as part of the WikiWord project run by <a href="http://wikimedia.de">Wikimedia Deutschland e.V.</a>.
 348+ It is based on a <a href="http://brightbyte.de/page/WikiWord">diploma thesis</a> by Daniel Kinzler, and runs on the <a href="http://toolserver.org/">Wikimedia Toolserver</a>. WikiWord is an ongoing research project. Please contact <a href="http://brightbyte.de/page/Special:Contact">Daniel Kinzler</a> for more information.</p> --> &nbsp;
 349+ </div>
 350+
 351+ <?php include("form.html.php"); ?>
 352+<?php
 353+if ($error) {
 354+ print "<p class=\"error\">".htmlspecialchars($error)."</p>";
 355+}
 356+
 357+if (!$result && $mode) {
 358+ if ($mode=="concept") print "<p class=\"error\">".htmlspecialchars($error)."</p>";
 359+ else if ($mode=="term") print "<p class=\"notice\">No meanings found for term <em>".htmlspecialchars($term)."</em>.</p>";
 360+}
 361+?>
 362+
 363+<?php
 364+if ($result && $mode) {
 365+ if ( $mode == 'concept' ) $terse = false;
 366+ else if ( $mode == 'term' ) $terse = true;
 367+?>
 368+ <table border="0" class="results" cellspacing="0" summary="search results">
 369+<?php
 370+ $count = 0;
 371+ foreach ( $result as $row ) {
 372+ $count = $count + 1;
 373+ $row['pos'] = $count;
 374+
 375+?>
 376+ <?php
 377+ mangleConcept($row);
 378+ $continue= printConcept($row, $languages, $terse);
 379+
 380+ if (!$continue) break;
 381+ ?>
 382+
 383+<?php
 384+ } #concept loop
 385+
 386+?>
 387+ </table>
 388+<?php
 389+} #if results
 390+?>
 391+
 392+<div class="footer">
 393+<p>Wikipics is provided by <a href="http://wikimedia.de">Wikimedia Deutschland</a> as part of the <a href="http://brightbyte.de/page/WikiWord">WikiWord</a> project.</p>
 394+
 395+</div>
 396+</body>
 397+<?php
 398+foreach ( $profiling as $key => $value ) {
 399+ print "<!-- $key: $value sec -->\n";
 400+}
 401+?>
 402+</html>
 403+<?php
 404+$utils->close();
 405+?>
 406+
Index: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/search.php
@@ -1,5 +1,6 @@
22 <?php
3 -
 3+define("WIKIPICS", 1);
 4+define("WIKIWORD", 1);
45 $IP = dirname( dirname(__FILE__) );
56
67 require_once("$IP/config.php");
@@ -8,33 +9,6 @@
910 if ($wwAPI) require_once("$IP/common/wwclient.php");
1011 else require_once("$IP/common/wwthesaurus.php");
1112
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;
18 - ?>
19 - <ul class="<?php print $class; ?>">
20 - <?php
21 - foreach ($concepts as $c) {
22 - $link = getConceptDetailsLink($langs, $c);
23 - if (!$link) continue;
24 -
25 - ?><li><?php
26 - print $link;
27 -
28 - $i += 1;
29 - if ($i >= $limit) break;
30 - ?></li><?php
31 - }
32 - ?>
33 - </ul>
34 - <?php
35 -
36 - return $i < count($concepts);
37 -}
38 -
3913 function getImagesAbout($concept, $max) {
4014 global $utils, $profiling;
4115
@@ -45,99 +19,6 @@
4620 return $pics;
4721 }
4822
49 -function printConceptImageList($concept, $terse = false, $columns = 5, $limit = false ) {
50 - global $utils, $wwThumbSize;
51 -
52 - if (!$concept) return false;
53 -
54 - if (is_array($concept) && !isset($concept['id'])) $images = $concept; #XXX: HACK
55 - else $images = getImagesAbout($concept, $max ? $max +1 : false);
56 -
57 - if (!$images) return;
58 -
59 - $class = $terse ? "terseImageTable" : "";
60 -
61 - $imgList = array_values($images);
62 -
63 - $cw = $wwThumbSize + 32; //FIXME: magic number, use config!
64 -
65 - ?>
66 - <table class="imageTable <?php print $class; ?>" summary="images" width="<?php print $columns*$cw; ?>">
67 - <colgroup span="<?php print $columns; ?>" width="<?php print $cw; ?>">
68 - </colgroup>
69 -
70 - <?php
71 - $i = 0;
72 - $c = count($images);
73 - if (!$limit || $limit > $c) $limit = $c;
74 -
75 - while ($i < $limit) {
76 - $i = printConceptImageRow($imgList, $i, $terse, $columns, $limit);
77 - }
78 - ?>
79 - </table>
80 - <?php
81 -
82 - return $i < $c;
83 -}
84 -
85 -function printConceptImageRow($images, $from, $terse, $columns = 5, $limit = false) {
86 - global $wwThumbSize, $utils;
87 -
88 - $cw = $wwThumbSize + 32; //FIXME: magic number, use config!
89 - $cwcss = $cw . "px";
90 -
91 - $to = $from + $columns;
92 - if ( $to > $limit ) $to = $limit;
93 -
94 - print "\t<tr class=\"imageRow\">\n";
95 -
96 - for ($i = $from; $i<$to; $i += 1) {
97 - $img = $images[$i];
98 - print "\t\t<td class=\"imageCell\" width=\"$cw\" align=\"left\" valign=\"bottom\" nowrap=\"nowrap\" style=\"width: $cwcss\"><div class=\"clipBox\" style=\"width:$cwcss; max-width:$cwcss;\">";
99 - print $utils->getThumbnailHTML($img, $wwThumbSize, $wwThumbSize);
100 - print "</div></td>\n";
101 - }
102 -
103 - print "\n\t</tr>\n";
104 -
105 - if (!$terse) {
106 - print "\t<tr class=\"imageMetaRow\">\n";
107 -
108 - for ($i = $from; $i<$to; $i += 1) {
109 - $img = $images[$i];
110 -
111 - $title = $img['name'];
112 - $title = str_replace("_", " ", $title);
113 - $title = preg_replace("/\\.[^.]+$/", "", $title);
114 -
115 - $info = getImageInfo($img);
116 - $labels = getImageLabels($img);
117 -
118 - print "\t\t<td class=\"imageMetaCell\" width=\"$cw\" align=\"left\" valign=\"top\" style=\"width: $cwcss\"><div class=\"clipBox\" style=\"width:$cwcss; max-width:$cwcss;\">";
119 - print "<div class=\"imageTitle\" title=\"" . htmlspecialchars( $img['name'] ) . "\">" . htmlspecialchars( $title ) . "</div>";
120 -
121 - if ($info) {
122 - print "<div class=\"imageInfo\">";
123 - printList($info, false, "terselist");
124 - print "</div>";
125 - }
126 -
127 - if ($labels) {
128 - print "<div class=\"imageLabels\">";
129 - printList($labels, false, "terselist");
130 - print "</div>";
131 - }
132 -
133 - print "</div></td>\n";
134 - }
135 -
136 - print "\n\t</tr>\n";
137 - }
138 -
139 - return $to;
140 -}
141 -
14223 function getImageInfo($img) {
14324 if (empty($img['meta'])) return false;
14425
@@ -185,21 +66,6 @@
18667 return "$wwSelf?id=" . urlencode($concept['id']) . "&lang=" . urlencode($langs);
18768 }
18869
189 -function getConceptDetailsLink($langs, $concept, $text = NULL) {
190 - global $utils;
191 -
192 - $name = $utils->pickLocal($concept['name'], $langs);
193 - if ( $name === false || $name === null) return false;
194 -
195 - $name = str_replace("_", " ", $name);
196 - $score = @$concept['score'];
197 -
198 - if ($text === null) $text = $name;
199 -
200 - $u = getConceptDetailsURL($langs, $concept);
201 - return '<a href="' . htmlspecialchars($u) . '" title="' . htmlspecialchars($name) . ' (score: ' . (int)$score . ')'. '">' . htmlspecialchars($text) . '</a>';
202 -}
203 -
20470 function pickPage( $pages ) {
20571 if (!$pages) return false;
20672
@@ -225,70 +91,6 @@
22692 return $urls;
22793 }
22894
229 -function getConceptPageLinks($lang, $concept) {
230 - $urls = getConceptPageURLs($lang, $concept);
231 - if (!$urls) return false;
232 -
233 - foreach ($urls as $page => $u) {
234 - $links[] = '<a href="' . htmlspecialchars($u) . '" title="' . htmlspecialchars( str_replace("_", " ", $page) ) . '">' . htmlspecialchars( $lang . ":" . str_replace("_", " ", $page) ) . '</a>';
235 - }
236 -
237 - return $links;
238 -}
239 -
240 -function getAllConceptPageLinks($concept) {
241 - $links = array();
242 -
243 - foreach ( $concept['languages'] as $lang ) {
244 - $ll = getConceptPageLinks($lang, $concept);
245 - if ($ll) $links[$lang] = $ll;
246 - }
247 -
248 - return $links;
249 -}
250 -
251 -function printList($items, $escape = true, $class = "list") {
252 - ?>
253 - <ul class="<?php print htmlspecialchars($class); ?>">
254 - <?php
255 - foreach ($items as $item) {
256 - if ( !$item ) continue;
257 - if ( $escape ) $item = htmlspecialchars($item);
258 - print "<li>" . trim($item) . "</li>";
259 - }
260 - ?>
261 - </ul>
262 - <?php
263 -}
264 -
265 -function printConceptPageList( $langs, $concept, $class, $limit = false ) {
266 - $linksByLanguage = getAllConceptPageLinks($concept);
267 -
268 - $i = 0;
269 - $more = false;
270 - ?>
271 - <ul class="<?php print htmlspecialchars($class); ?>">
272 - <?php
273 - foreach ( $linksByLanguage as $lang => $links ) {
274 - foreach ($links as $link ) {
275 - print "<li>" . trim($link) . "</li>";
276 -
277 - $i += 1;
278 - if ($limit && $i >= $limit) break;
279 - }
280 -
281 - if ($limit && $i >= $limit) {
282 - $more = true;
283 - break;
284 - }
285 - }
286 - ?>
287 - </ul>
288 - <?php
289 -
290 - return $more;
291 -}
292 -
29395 function array_key_diff($base, $other) {
29496 $keys = array_keys($other);
29597 foreach ($keys as $k) {
@@ -309,35 +111,6 @@
310112 sortConceptList($related);
311113 return $related;
312114 }
313 -
314 -function printDefList($items, $scapeKeys = true, $escapeValues = true, $class = "list") {
315 - ?>
316 - <dl class="<?php print htmlspecialchars($class); ?>">
317 - <?php
318 - foreach ($items as $key => $item) {
319 - if ( $escapeKeys ) $key = htmlspecialchars($key);
320 - print "\t\t<dt>" . $key . "</dt>\n";
321 -
322 - if ( $escapeValues ) $item = htmlspecialchars($item);
323 - print "\t\t\t<dd>" . $item . "</dd>\n";
324 - }
325 - ?>
326 - </sl>
327 - <?php
328 -}
329 -
330 -function getWeightClass($weight) {
331 - if (!isset($weight) || !$weight) {
332 - return "unknown";
333 - $weight = NULL;
334 - }
335 - else if ($weight>1000) return "huge";
336 - else if ($weight>100) return "big";
337 - else if ($weight>10) return "normal";
338 - else if ($weight>2) return "some";
339 - else return "little";
340 -}
341 -
342115 function stripSections(&$concepts) {
343116 foreach ($concepts as $k => $c) {
344117 foreach ($c['name'] as $l => $n) {
@@ -374,110 +147,20 @@
375148 sortConceptList($concept['broader']);
376149 }
377150
378 -function printConcept($concept, $langs, $terse = true) {
379 - global $utils, $wwMaxPreviewImages, $wwMaxGalleryImages, $wwMaxPreviewLinks, $wwMaxDetailLinks, $wwGalleryColumns;
380 -
381 - extract( $concept );
382 - if (@$score) $wclass = getWeightClass($score);
383 - else $wclass = "";
384 -
385 - #$lclass = $terse ? "terselist" : "list";
386 - $lclass = "terselist";
387 -
388 - $name = $utils->pickLocal($concept['name'], $langs);
389 - $name = str_replace("_", " ", $name);
390 -
391 - $gallery = getImagesAbout($concept, $terse ? $wwMaxPreviewImages*2 : $wwMaxGalleryImages+1 );
392 -
393 - if (empty($definition)) $definition = "";
394 - else if (is_array($definition)) $definition = $utils->pickLocal($definition, $langs);
395 -
396 - ?>
397 - <tr class="row_head">
398 - <td colspan="3">
399 - <h1 class="name <?php print "weight_$wclass"; ?>"><?php print getConceptDetailsLink($langs, $concept); ?>:</h1>
400 - <p class="definition"><?php print htmlspecialchars($definition); ?></p>
401 - </td>
402 - </tr>
403 -
404 - <tr class="row_images">
405 - <td class="cell_images" colspan="2">
406 - <?php
407 - if (!$gallery) print "<p class=\"notice\">No images found for concept <em>".htmlspecialchars($name)."</em>.</p>";
408 - else $more = printConceptImageList( $gallery, $terse, $wwGalleryColumns, $terse ? $wwMaxPreviewImages : $wwMaxGalleryImages );
409 - ?>
410 - </td>
411 - <?php if ($gallery) { ?>
412 - <td class="cell_more_images" colspan="1" width="100%" style="vertical-align:bottom; padding: 1ex; font-size:normal;">
413 - <?php if ($terse) print " <div><strong class=\"more\">[" . getConceptDetailsLink($langs, $concept, "more/details...") . "]</strong></div>"; ?>
414 - </td>
415 - <?php } ?>
416 - </tr>
417 -
418 - <?php if (@$concept['narrower']) { ?>
419 - <tr class="row_narrower">
420 - <td class="cell_related" colspan="3">
421 - <strong class="label">Narrower:</strong>
422 - <?php
423 - $more = printConceptList( $langs, $concept['narrower'], $lclass, $terse ? $wwMaxPreviewLinks : $wwMaxDetailLinks );
424 - ?>
425 - <?php if ($terse && $more) print " <strong class=\"more\">[" . getConceptDetailsLink($langs, $concept, "more...") . "]</strong>"; ?>
426 - </td>
427 - </tr>
428 - <?php } ?>
429 -
430 - <?php
431 - $related = getRelatedConceptList($concept);
432 - if ($related) {
433 - ?>
434 - <tr class="row_related">
435 - <td class="cell_related" colspan="3">
436 - <strong class="label">Related:</strong>
437 - <?php
438 - $more = printConceptList( $langs, $related, $lclass, $terse ? $wwMaxPreviewLinks : $wwMaxDetailLinks );
439 - ?>
440 - <?php if ($terse && $more) print " <strong class=\"more\">[" . getConceptDetailsLink($langs, $concept, "more...") . "]</strong>"; ?>
441 - </td>
442 - </tr>
443 - <?php } ?>
444 -
445 - <?php if (@$concept['broader']) { ?>
446 - <tr class="row_category">
447 - <td class="cell_related" colspan="3">
448 - <strong class="label">Broader:</strong>
449 - <?php
450 - $more = printConceptList( $langs, $concept['broader'], $lclass, $terse ? $wwMaxPreviewLinks : $wwMaxDetailLinks );
451 - ?>
452 - <?php if ($terse && $more) print " <strong class=\"more\">[" . getConceptDetailsLink($langs, $concept, "more...") . "]</strong>"; ?>
453 - </td>
454 - </tr>
455 - <?php } ?>
456 -
457 - <?php if (!$terse && @$concept['pages']) { ?>
458 - <tr class="row_pages">
459 - <td class="cell_pages wikipages" colspan="3">
460 - <strong class="label">Wiki pages:</strong> <?php $more = printConceptPageList( $langs, $concept, $lclass, $terse ? $wwMaxPreviewLinks : $wwMaxDetailLinks ); ?>
461 - <?php if ($terse && $more) print " <strong class=\"more\">[" . getConceptDetailsLink($langs, $concept, "more...") . "]</strong>"; ?>
462 - </td>
463 - </tr>
464 - <?php } ?>
465 -
466 - <tr class="row_blank">
467 - <td class="cell_blank" colspan="3">
468 - &nbsp;
469 - </td>
470 - </tr>
471 -
472 - <?php
473 - if (isset($score) && $score && $score<2 && $pos>=3) return false;
474 - else return true;
475 -}
476 -
477151 $conceptId = @$_REQUEST['id'];
478152 $term = @$_REQUEST['term'];
479153 $lang = @$_REQUEST['lang'];
480154
481 -if ($term!==NULL && preg_match('/^\s*#(\d+)\s*$/', $term, $m)) {
 155+if ( $term===null ) {
 156+ $term = @$_SERVER['PATH_INFO'];
 157+}
 158+
 159+if ($lang===null && $term!==null && preg_match('/^\s*(.+)[:](.+)\s*$/', $term, $m)) {
 160+ $lang = $m[1];
 161+ $term = $m[2];
 162+}
 163+
 164+if ($conceptId===null && $term!==null && preg_match('/^\s*[#$](\d+)\s*$/', $term, $m)) {
482165 $conceptId = $m[1];
483166 $term = NULL;
484167 }
@@ -541,8 +224,8 @@
542225 $result = $thesaurus->getConceptInfo($conceptId, $allLanguages);
543226 if ( $result ) $result = array( $result ); //hack
544227 } else if ($lang && $term) {
545 - $mode = "term";
546 - $result = $thesaurus->getConceptsForTerm($lang, $term, $allLanguages, $norm, $limit);
 228+ $mode = "term";
 229+ $result = $thesaurus->getConceptsForTerm($lang, $term, $allLanguages, $norm, $limit);
547230 }
548231 } catch (Exception $e) {
549232 $error = $e->getMessage();
@@ -550,207 +233,4 @@
551234 $profiling['thesaurus'] += (microtime(true) - $t);
552235 }
553236
554 -
555 -?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
556 -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
557 -<head>
558 - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
559 - <title>WikiPics: multilingual search for Wikimedia Commons</title>
560 -
561 - <style type="text/css">
562 - html, body { font-family: verdana, helvetica, arial, sans-serif; font-size:10pt; margin: 0; padding: 0; }
563 -
564 - a, a:link, a:visited, a:active, a:hover {
565 - color:#2200CC;
566 - }
567 -
568 - a, a:link, a:visited {
569 - text-decoration: none;
570 - }
571 -
572 - a:active, a:hover {
573 - text-decoration: underline;
574 - }
575 -
576 - .error { color: red; font-weight: bold; }
577 - .weight_huge { font-size: 140%; font-weight:bold; }
578 - .weight_big { font-size: 120%; font-weight:bold; }
579 - .weight_normal { font-size: 110%; font-weight:bold; }
580 - .weight_some { font-size: 100%; font-weight:bold; }
581 - .weight_little { font-size: 90%; font-weight:bold; }
582 - .weight_unknown { font-size: 100%; font-weight:bold; }
583 -
584 - /*
585 - .row_def td { font-size: small; font-style:italic; }
586 - .row_details td { font-size: small; }
587 - */
588 -
589 - .row_head td { font-size: small; }
590 -
591 - .row_head td { border-top: 1px solid #6B90DA; background-color: #F0F7F9; padding: 0.5ex; }
592 - .row_head h1, .row_head h2, .row_head h3 { padding: 0; margin: 0; font-size: inherit; font-weight: inherit; }
593 - .row_head p { padding: 0; margin: 0; font-size: inherit; }
594 - .row_head .name { font-weight: bold; display:inline; font-size: large; }
595 - .row_head .definition { font-style: italic; display:inline; }
596 - .row_head .wikipages { font-style: inherit; display:inline; }
597 -
598 - .row_images td { vertical-align: bottom; }
599 -
600 - .row_related td, .row_category, .row_narrower, .row_pages { font-size: small; background-color: #F0F7F9; }
601 - .row_blank td { font-size: small; }
602 -
603 - /*
604 - .cell_weight { text-align: right; }
605 - .cell_label { text-align: right; font-weight: bold; }
606 - */
607 -
608 - .label { font-weight: bold; }
609 - .note { font-size:small; }
610 -
611 - .header { font-size:small; text-align: left; margin:0 0 1ex 0; padding:0.5ex; border-bottom: 1px solid #C9D7F1; }
612 -
613 - .inputform { text-align: left; margin:0 1ex; }
614 - .inputform td { text-align: left; vertical-align: bottom; padding: 0.5ex; }
615 - .inputform td.note { font-size:small; }
616 - .inputform th { text-align: left; vertical-align: bottom; }
617 -
618 -
619 - .footer { font-size:small; text-align: center; margin:1ex 0 0 0; padding: 0; border-top: 1px solid #C9D7F1; }
620 -
621 - .tersegallery, .tersegallery li, .terselist, .terselist li { display: inline; margin:0; padding:0; }
622 - .terselist li:before { content:", " }
623 - .terselist li:first-child:before { content:"" }
624 -
625 - .gallery li { display: inline; padding:0.5ex; margin:0.5ex; }
626 -
627 - .results { margin: 1em; }
628 - .results td { text-align: left; vertical-align: top; }
629 - .results th { text-align: left; vertical-align: top; font-weight:bold; }
630 -
631 - .imageTable td.imageCell {
632 - vertical-align: bottom;
633 - padding-top: 0.5em;
634 - padding-right: 1em;
635 - font-size: small;
636 - }
637 -
638 - .imageTable td.imageCell img {
639 - font-size:50%;
640 - }
641 -
642 - .imageTable td.imageMetaCell {
643 - vertical-align: top;
644 - padding-bottom: 0.5em;
645 - padding-right: 1em;
646 - font-size:small;
647 - }
648 -
649 - .clipBox {
650 - overflow: hidden;
651 - }
652 -
653 - .imageTable td.imageCell img { border: 1px solid; }
654 -
655 - .imageInfo { color: #676767 }
656 - .imageLabels { color: #676767; font-size:80%; }
657 - </style>
658 -</head>
659 -<body>
660 - <div class="header">
661 - <div style="float:left">Wikipics 0.1&alpha; (experimental)</div>
662 - <div style="float:right"><a href="http://wikimedia.de">Wikimedia Deutschland e.V.</a></div>
663 - <!-- <h1>WikiWord Navigator</h1>
664 - <p>Experimental semantic navigator and thesaurus interface for Wikipedia.</p>
665 - <p>The WikiWord Navigator was created as part of the WikiWord project run by <a href="http://wikimedia.de">Wikimedia Deutschland e.V.</a>.
666 - It is based on a <a href="http://brightbyte.de/page/WikiWord">diploma thesis</a> by Daniel Kinzler, and runs on the <a href="http://toolserver.org/">Wikimedia Toolserver</a>. WikiWord is an ongoing research project. Please contact <a href="http://brightbyte.de/page/Special:Contact">Daniel Kinzler</a> for more information.</p> --> &nbsp;
667 - </div>
668 -
669 - <div class="inputform" >
670 - <form name="search" action="<?php print $wwSelf; ?>">
671 - <table border="0" class="inputgrid" summary="input form">
672 - <tr>
673 - <td>
674 - <?php
675 - $u = $utils->getThumbnailURL("Commons_logo_optimized.svg", 60);
676 - print "<img class=\"logo\" alt=\"Wikimedia Commons Logo\" src=\"".htmlspecialchars($u)."\" title=\"Search Wikimedia Commons\" align=\"bottom\"/>";
677 - ?>
678 - </td>
679 - <td>
680 - <label for="term" style="display:none">Term: </label><input type="text" name="term" id="term" size="24" value="<?php print htmlspecialchars($term); ?>"/>
681 - </td>
682 - <td>
683 - <label for="term" style="display:none">Language: </label>
684 - <?php WWUtils::printSelector("lang", $wwLanguages, $lang) ?>
685 - </td>
686 - <td>
687 - <input type="submit" name="go" value="go"/>
688 - </td>
689 - <td class="note">
690 - <small>Note: this is a thesaurus lookup, not a full text search. Multiple words are handeled as a single phrase. Only exact matches of complete phrases will be found. </small>
691 - </td>
692 - </tr>
693 - </table>
694 -
695 - <?php
696 - if ($utils->debug) {
697 - print '<input type="hidden" name="debug" value="true"/>';
698 - print "<p>debug mode enabled!</p>";
699 - flush();
700 - }
701 - ?>
702 - </form>
703 - </div>
704 -<?php
705 -if ($error) {
706 - print "<p class=\"error\">".htmlspecialchars($error)."</p>";
707 -}
708 -
709 -if (!$result && $mode) {
710 - if ($mode=="concept") print "<p class=\"error\">".htmlspecialchars($error)."</p>";
711 - else if ($mode=="term") print "<p class=\"notice\">No meanings found for term <em>".htmlspecialchars($term)."</em>.</p>";
712 -}
713 -?>
714 -
715 -<?php
716 -if ($result && $mode) {
717 - if ( $mode == 'concept' ) $terse = false;
718 - else if ( $mode == 'term' ) $terse = true;
719 -?>
720 - <table border="0" class="results" cellspacing="0" summary="search results">
721 -<?php
722 - $count = 0;
723 - foreach ( $result as $row ) {
724 - $count = $count + 1;
725 - $row['pos'] = $count;
726 -
727 -?>
728 - <?php
729 - mangleConcept($row);
730 - $continue= printConcept($row, $languages, $terse);
731 -
732 - if (!$continue) break;
733 - ?>
734 -
735 -<?php
736 - } #concept loop
737 -
738 -?>
739 - </table>
740 -<?php
741 -} #if results
742 -?>
743 -
744 -<div class="footer">
745 -<p>Wikipics is provided by <a href="http://wikimedia.de">Wikimedia Deutschland</a> as part of the <a href="http://brightbyte.de/page/WikiWord">WikiWord</a> project.</p>
746 -
747 -</div>
748 -</body>
749 -<?php
750 -foreach ( $profiling as $key => $value ) {
751 - print "<!-- $key: $value sec -->\n";
752 -}
753 -?>
754 -</html>
755 -<?php
756 -$utils->close();
757 -?>
\ No newline at end of file
 237+include("response.html.php");
Index: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/form.html.php
@@ -0,0 +1,39 @@
 2+<?php
 3+if (!defined("WIKIPICS")) die("not a valid entry point");
 4+
 5+?>
 6+<div class="inputform" >
 7+ <form name="search" action="<?php print $wwSelf; ?>">
 8+ <table border="0" class="inputgrid" summary="input form">
 9+ <tr>
 10+ <td>
 11+ <?php
 12+ $u = $utils->getThumbnailURL("Commons_logo_optimized.svg", 60);
 13+ print "<img class=\"logo\" alt=\"Wikimedia Commons Logo\" src=\"".htmlspecialchars($u)."\" title=\"Search Wikimedia Commons\" align=\"bottom\"/>";
 14+ ?>
 15+ </td>
 16+ <td>
 17+ <label for="term" style="display:none">Term: </label><input type="text" name="term" id="term" size="24" value="<?php print htmlspecialchars($term); ?>"/>
 18+ </td>
 19+ <td>
 20+ <label for="term" style="display:none">Language: </label>
 21+ <?php WWUtils::printSelector("lang", $wwLanguages, $lang) ?>
 22+ </td>
 23+ <td>
 24+ <input type="submit" name="go" value="go"/>
 25+ </td>
 26+ <td class="note">
 27+ <small>Note: this is a thesaurus lookup, not a full text search. Multiple words are handeled as a single phrase. Only exact matches of complete phrases will be found. </small>
 28+ </td>
 29+ </tr>
 30+ </table>
 31+
 32+ <?php
 33+ if ($utils->debug) {
 34+ print '<input type="hidden" name="debug" value="true"/>';
 35+ print "<p>debug mode enabled!</p>";
 36+ flush();
 37+ }
 38+ ?>
 39+ </form>
 40+ </div>
Index: trunk/WikiWord/WikiWordWeb/src/main/www/skin/styles.css
@@ -0,0 +1,95 @@
 2+ html, body { font-family: verdana, helvetica, arial, sans-serif; font-size:10pt; margin: 0; padding: 0; }
 3+
 4+ a, a:link, a:visited, a:active, a:hover {
 5+ color:#2200CC;
 6+ }
 7+
 8+ a, a:link, a:visited {
 9+ text-decoration: none;
 10+ }
 11+
 12+ a:active, a:hover {
 13+ text-decoration: underline;
 14+ }
 15+
 16+ .error { color: red; font-weight: bold; }
 17+ .weight_huge { font-size: 140%; font-weight:bold; }
 18+ .weight_big { font-size: 120%; font-weight:bold; }
 19+ .weight_normal { font-size: 110%; font-weight:bold; }
 20+ .weight_some { font-size: 100%; font-weight:bold; }
 21+ .weight_little { font-size: 90%; font-weight:bold; }
 22+ .weight_unknown { font-size: 100%; font-weight:bold; }
 23+
 24+ /*
 25+ .row_def td { font-size: small; font-style:italic; }
 26+ .row_details td { font-size: small; }
 27+ */
 28+
 29+ .row_head td { font-size: small; }
 30+
 31+ .row_head td { border-top: 1px solid #6B90DA; background-color: #F0F7F9; padding: 0.5ex; }
 32+ .row_head h1, .row_head h2, .row_head h3 { padding: 0; margin: 0; font-size: inherit; font-weight: inherit; }
 33+ .row_head p { padding: 0; margin: 0; font-size: inherit; }
 34+ .row_head .name { font-weight: bold; display:inline; font-size: large; }
 35+ .row_head .definition { font-style: italic; display:inline; }
 36+ .row_head .wikipages { font-style: inherit; display:inline; }
 37+
 38+ .row_images td { vertical-align: bottom; }
 39+
 40+ .row_related td, .row_category, .row_narrower, .row_pages { font-size: small; background-color: #F0F7F9; }
 41+ .row_blank td { font-size: small; }
 42+
 43+ /*
 44+ .cell_weight { text-align: right; }
 45+ .cell_label { text-align: right; font-weight: bold; }
 46+ */
 47+
 48+ .label { font-weight: bold; }
 49+ .note { font-size:small; }
 50+
 51+ .header { font-size:small; text-align: left; margin:0 0 1ex 0; padding:0.5ex; border-bottom: 1px solid #C9D7F1; }
 52+
 53+ .inputform { text-align: left; margin:0 1ex; }
 54+ .inputform td { text-align: left; vertical-align: bottom; padding: 0.5ex; }
 55+ .inputform td.note { font-size:small; }
 56+ .inputform th { text-align: left; vertical-align: bottom; }
 57+
 58+
 59+ .footer { font-size:small; text-align: center; margin:1ex 0 0 0; padding: 0; border-top: 1px solid #C9D7F1; }
 60+
 61+ .tersegallery, .tersegallery li, .terselist, .terselist li { display: inline; margin:0; padding:0; }
 62+ .terselist li:before { content:", " }
 63+ .terselist li:first-child:before { content:"" }
 64+
 65+ .gallery li { display: inline; padding:0.5ex; margin:0.5ex; }
 66+
 67+ .results { margin: 1em; }
 68+ .results td { text-align: left; vertical-align: top; }
 69+ .results th { text-align: left; vertical-align: top; font-weight:bold; }
 70+
 71+ .imageTable td.imageCell {
 72+ vertical-align: bottom;
 73+ padding-top: 0.5em;
 74+ padding-right: 1em;
 75+ font-size: small;
 76+ }
 77+
 78+ .imageTable td.imageCell img {
 79+ font-size:50%;
 80+ }
 81+
 82+ .imageTable td.imageMetaCell {
 83+ vertical-align: top;
 84+ padding-bottom: 0.5em;
 85+ padding-right: 1em;
 86+ font-size:small;
 87+ }
 88+
 89+ .clipBox {
 90+ overflow: hidden;
 91+ }
 92+
 93+ .imageTable td.imageCell img { border: 1px solid; }
 94+
 95+ .imageInfo { color: #676767 }
 96+ .imageLabels { color: #676767; font-size:80%; }

Status & tagging log