Index: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/opensearch_description.php |
— | — | @@ -0,0 +1,23 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +if (!isset($scriptPath)) $scriptPath = "./"; |
| 5 | +if (!isset($skinPath)) $skinPath = "$scriptPath/../skin/"; |
| 6 | + |
| 7 | +if( @$_GET( 'ctype' ) == 'application/xml' ) { |
| 8 | + // Makes testing tweaks about a billion times easier |
| 9 | + $ctype = 'application/xml'; |
| 10 | +} else { |
| 11 | + $ctype = 'application/opensearchdescription+xml'; |
| 12 | +} |
| 13 | + |
| 14 | +header("Content-Type: $ctype; charset=UTF-8"); |
| 15 | +?><?xml version="1.0"?> |
| 16 | +<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/"> |
| 17 | + <ShortName>WikiPics</ShortName> |
| 18 | + <Description>WikiPics: Multilingual Search for Wikimedia Commons</Description> |
| 19 | + <Image height="16" width="16" type="image/x-icon"><?php print "$skinPath/favicon.ico"; ?></Image> |
| 20 | + <Url type="text/html" method="get" template="<?php print "$scriptPath/search.php?lang={language}&term={searchTerms}"; ?>" /> |
| 21 | + <Url type="application/json" method="get" template="<?php print "$scriptPath/search.php?lang={language}&term={searchTerms}&format=json"; ?>" /> |
| 22 | + <Url type="application/atom+xml" method="get" template="<?php print "$scriptPath/search.php?lang={language}&term={searchTerms}&format=atom"; ?>" /> |
| 23 | + <moz:SearchForm><?php print "$scriptPath/search.php"; ?></moz:SearchForm> |
| 24 | +</OpenSearchDescription> |
\ No newline at end of file |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/response.atom.php |
— | — | @@ -0,0 +1,350 @@ |
| 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 | + |
| 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 | +if( @$_GET( 'ctype' ) == 'application/xml' ) { |
| 334 | + // Makes testing tweaks about a billion times easier |
| 335 | + $ctype = 'application/xml'; |
| 336 | +} else { |
| 337 | + $ctype = 'application/atom+xml'; |
| 338 | +} |
| 339 | + |
| 340 | +if (!isset($scriptPath)) $scriptPath = "./"; |
| 341 | +if (!isset($skinPath)) $skinPath = "$scriptPath/../skin/"; |
| 342 | + |
| 343 | +header("Content-Type: $ctype; charset=$ctype"); |
| 344 | +?><?xml version="1.0" encoding="UTF-8"?> |
| 345 | + <feed xmlns="http://www.w3.org/2005/Atom" |
| 346 | + xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"> |
| 347 | + <link rel="search" |
| 348 | + href="http://example.com/opensearchdescription.xml" |
| 349 | + type="application/opensearchdescription+xml" |
| 350 | + title="Content Search" /> |
| 351 | +</xml> |
Property changes on: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/response.atom.php |
___________________________________________________________________ |
Name: svn:mergeinfo |
1 | 352 | + |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/response.html.php |
— | — | @@ -329,13 +329,20 @@ |
330 | 330 | else return true; |
331 | 331 | } |
332 | 332 | |
| 333 | +if (!isset($scriptPath)) $scriptPath = "./"; |
| 334 | +if (!isset($skinPath)) $skinPath = "$scriptPath/../skin/"; |
| 335 | + |
333 | 336 | header("Content-Type: text/html; charset=UTF-8"); |
334 | 337 | ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
335 | 338 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> |
336 | 339 | <head> |
337 | 340 | <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" /> |
| 341 | + <title>WikiPics: Multilingual Search for Wikimedia Commons</title> |
| 342 | + <link rel="stylesheet" href="<?php print "$skinPath/styles.css"; ?>" type="text/css" media="all" /> |
| 343 | + <link rel="search" |
| 344 | + type="application/opensearchdescription+xml" |
| 345 | + href="<?php print "$scriptPath/opensearch_description.xml"; ?>" |
| 346 | + title="Image Search" /> |
340 | 347 | </head> |
341 | 348 | <body> |
342 | 349 | <div class="header"> |
— | — | @@ -399,7 +406,4 @@ |
400 | 407 | } |
401 | 408 | ?> |
402 | 409 | </html> |
403 | | -<?php |
404 | | -$utils->close(); |
405 | | -?> |
406 | 410 | |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/search.php |
— | — | @@ -150,6 +150,7 @@ |
151 | 151 | $conceptId = @$_REQUEST['id']; |
152 | 152 | $term = @$_REQUEST['term']; |
153 | 153 | $lang = @$_REQUEST['lang']; |
| 154 | +$format = @$_REQUEST['format']; |
154 | 155 | |
155 | 156 | if ( $term===null ) { |
156 | 157 | $term = @$_SERVER['PATH_INFO']; |
— | — | @@ -233,4 +234,10 @@ |
234 | 235 | $profiling['thesaurus'] += (microtime(true) - $t); |
235 | 236 | } |
236 | 237 | |
237 | | -include("response.html.php"); |
| 238 | +if (!isset($scriptPath)) $scriptPath = "./"; |
| 239 | +if (!isset($skinPath)) $skinPath = "$scriptPath/../skin/"; |
| 240 | + |
| 241 | +if ( $format == "atom" || $format == "xml" || $format == "opensearch" ) include("response.atom.php"); |
| 242 | +else include("response.html.php"); |
| 243 | + |
| 244 | +$utils->close(); |