Index: trunk/WikiWord/WikiWordWeb/src/main/www/wikiword/api.php |
— | — | @@ -0,0 +1,140 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +$IP = dirname(__FILE__); |
| 5 | + |
| 6 | +require_once("$IP/config.php"); |
| 7 | +require_once("$IP/wwthesaurus.php"); |
| 8 | + |
| 9 | +$query = @$_REQUEST['query']; |
| 10 | + |
| 11 | +if ( $query ) { |
| 12 | + $lang = @$_REQUEST['lang']; |
| 13 | + $qlang = @$_REQUEST['qlang']; |
| 14 | + $format = @$_REQUEST['format']; |
| 15 | + if ( !$format ) $format = 'phps'; |
| 16 | + |
| 17 | + if ($lang) $lang = preg_replace('[^\\w\\d_]', '', $lang); |
| 18 | + if ($qlang) $qlang = preg_replace('[^\\w\\d_]', '', $qlang); |
| 19 | + |
| 20 | + if ($lang) { |
| 21 | + $lang = preg_split('![\\s,;|/:]\\s*!', $lang); |
| 22 | + if ( !$qlang ) $qlang = $lang[0]; |
| 23 | + if (count($lang) == 1) $lang = $lang[0]; |
| 24 | + } |
| 25 | + |
| 26 | + $result = array( 'query' => $query ); |
| 27 | + $start = microtime(true); |
| 28 | + |
| 29 | + try { |
| 30 | + $thesaurus = new WWThesaurus(); |
| 31 | + $db = $thesaurus->connect($wwDBServer, $wwDBUser, $wwDBPassword, $wwDBDatabase); |
| 32 | + |
| 33 | + if ( !$db ) { |
| 34 | + $result['error'] = array('code' => 1010, 'message' => "failed to connect to thesaurus database"); |
| 35 | + } else if ($query == 'concepts') { |
| 36 | + $term = @$_REQUEST['term']; |
| 37 | + $norm = @$_REQUEST['norm']; |
| 38 | + |
| 39 | + if ( $norm === null ) $norm = 1; |
| 40 | + #$page = @$_REQUEST['page']; |
| 41 | + |
| 42 | + if ( $qlang === null ) $result['error'] = array('code' => 150, 'message' => "missing parameter qlang"); |
| 43 | + else if ( $term !== null ) { |
| 44 | + $result['concepts'] = $thesaurus->getConceptsForTerm($qlang, $term, $lang, $norm); #TODO: limit! |
| 45 | + if ( $result['concepts'] === false || $result['concepts'] === null ) { |
| 46 | + $result['error'] = array('code' => 210, 'message' => "failed to retrieve concepts for term $langt:$term"); |
| 47 | + } |
| 48 | + } /*else if ( $page !== null ) { |
| 49 | + $result['concepts'] = $thesaurus->getConceptsForPage($lang, $page); |
| 50 | + if ( $result['concepts'] === false || $result['concepts'] === null ) { |
| 51 | + $result['error'] = array('code' => 250, 'message' => "failed to retrieve concepts for page $langt:$page"); |
| 52 | + } |
| 53 | + } */else { |
| 54 | + $result['error'] = array('code' => 110, 'message' => "missing parameter term"); |
| 55 | + } |
| 56 | + } else if ($query == 'concept' || $query == 'info') { |
| 57 | + $gcid = @$_REQUEST['gcid']; |
| 58 | + if (!$gcid) $gcid = @$_REQUEST['id']; |
| 59 | + |
| 60 | + if ( $gcid === null ) { |
| 61 | + $result['error'] = array('code' => 120, 'message' => "missing parameter gcid"); |
| 62 | + } else { |
| 63 | + $result['concept'] = $thesaurus->getConceptInfo($gcid, $lang); #TODO: limit! |
| 64 | + if ( $result['concept'] === false || $result['concept'] === null ) { |
| 65 | + $result['error'] = array('code' => 210, 'message' => "concept not found: $gcid"); |
| 66 | + } |
| 67 | + } |
| 68 | + } else if ($query == 'properties') { |
| 69 | + $gcid = @$_REQUEST['gcid']; |
| 70 | + if (!$gcid) $gcid = @$_REQUEST['id']; |
| 71 | + |
| 72 | + $props = @$_REQUEST['props']; |
| 73 | + |
| 74 | + if ( $gcid === null ) $result['error'] = array('code' => 120, 'message' => "missing parameter gcid"); |
| 75 | + else if ( $props === null ) $result['error'] = array('code' => 130, 'message' => "missing parameter props"); |
| 76 | + else { |
| 77 | + $props = preg_split('![\\s,;|/:]\\s*!', $props); |
| 78 | + |
| 79 | + $info = $thesaurus->getConcept($gcid, $lang); |
| 80 | + |
| 81 | + if ( !$info ) $result['error'] = array('code' => 100, 'message' => "concept not found: $gcid"); |
| 82 | + else { |
| 83 | + $result = array_merge($result, $info); |
| 84 | + |
| 85 | + foreach ( $props as $p ) { |
| 86 | + $m = "get" . ucfirst($p) . "ForConcept"; |
| 87 | + if ( !method_exists($thesaurus, $m) ) { |
| 88 | + $result['error'] = array('code' => 190, 'message' => "unknown property: $p"); |
| 89 | + break; |
| 90 | + } |
| 91 | + |
| 92 | + $result[$p] = $thesaurus->$m($gcid, $lang); |
| 93 | + |
| 94 | + if ( $result[$p] === false || $result[$p] === null ) { |
| 95 | + $result['error'] = array('code' => 220, 'message' => "failed to retrieve property $p for concept $gcid"); |
| 96 | + break; |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + if (!isset($result['id'])) $result['id'] = $gcid; |
| 101 | + if (!isset($result['lang'])) $result['lang'] = $lang; |
| 102 | + } |
| 103 | + } |
| 104 | + } else { |
| 105 | + $result['error'] = array('code' => 10, 'message' => "bad query: $query"); |
| 106 | + } |
| 107 | + } catch (Exception $e) { |
| 108 | + $result['error'] = array('code' => 1000, 'message' => "unexpected exception: " . $e->getMessage()); |
| 109 | + } |
| 110 | + |
| 111 | + $result['time'] = (microtime(true) - $start) . " sec"; |
| 112 | + |
| 113 | + if ( isset($result['error']) ) { |
| 114 | + #TODO: HTTP error codce would be nice, but causes file_get_contents to swallow the data. |
| 115 | + # need to use CURL in client! |
| 116 | + #header("Status: 400 Bad Request", true, 400); |
| 117 | + } |
| 118 | + |
| 119 | + #TODO: JSON (+YAML?), WDDX |
| 120 | + if ($format == 'phps') { |
| 121 | + header("Content-Type: application/vnd.php.serialized"); #as proposed by http://www.alvestrand.no/pipermail/ietf-types/2004-August/001259.html |
| 122 | + $data = serialize($result); |
| 123 | + echo $data; |
| 124 | + } else if ($format == 'php') { |
| 125 | + header("Content-Type: text/php; charset=UTF-8"); |
| 126 | + var_export($result); |
| 127 | + } else if ($format == 'text') { |
| 128 | + header("Content-Type: text/plain; charset=UTF-8"); |
| 129 | + print_r($result); |
| 130 | + } else { |
| 131 | + header("Content-Type: text/plain; charset=UTF-8"); |
| 132 | + header("Status: 400 Bad Request", true, 400); |
| 133 | + echo "Bad format: $format"; |
| 134 | + } |
| 135 | + |
| 136 | + exit(); |
| 137 | +} |
| 138 | + |
| 139 | +header("Content-Type: text/plain; charset=UTF-8"); |
| 140 | +?> |
| 141 | +WikiWord REST API |
\ No newline at end of file |
Property changes on: trunk/WikiWord/WikiWordWeb/src/main/www/wikiword/api.php |
___________________________________________________________________ |
Name: svn:mergeinfo |
1 | 142 | + |
Property changes on: trunk/WikiWord/WikiWordWeb/src/main/www/wikiword |
___________________________________________________________________ |
Name: svn:mergeinfo |
2 | 143 | + |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/search.php |
— | — | @@ -0,0 +1,756 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +$IP = dirname( dirname(__FILE__) ); |
| 5 | + |
| 6 | +require_once("$IP/config.php"); |
| 7 | +require_once("$IP/common/wwimages.php"); |
| 8 | + |
| 9 | +if ($wwAPI) require_once("$IP/common/wwclient.php"); |
| 10 | +else require_once("$IP/common/wwthesaurus.php"); |
| 11 | + |
| 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 | + |
| 39 | +function getImagesAbout($concept, $max) { |
| 40 | + global $utils, $profiling; |
| 41 | + |
| 42 | + $t = microtime(true); |
| 43 | + $pics = $utils->getImagesAbout($concept, $max); |
| 44 | + $profiling['pics'] += (microtime(true) - $t); |
| 45 | + |
| 46 | + return $pics; |
| 47 | +} |
| 48 | + |
| 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 | + |
| 142 | +function getImageInfo($img) { |
| 143 | + if (empty($img['meta'])) return false; |
| 144 | + |
| 145 | + $info = array(); |
| 146 | + extract($img['meta']); |
| 147 | + |
| 148 | + $info[] = htmlspecialchars("$img_minor_mime"); |
| 149 | + |
| 150 | + if ( $img_media_type == "BITMAP" ) { |
| 151 | + $info[] = htmlspecialchars("{$img_width}x{$img_height}"); |
| 152 | + } |
| 153 | + |
| 154 | + if ( $img_size > 1024*1024 ) $info[] = htmlspecialchars(sprintf("%1.0fM", $img_size / (1024.0*1024.0))); |
| 155 | + else if ( $img_size > 1024 ) $info[] = htmlspecialchars(sprintf("%1.0fK", $img_size / 1024.0)); |
| 156 | + else $info[] = htmlspecialchars(sprintf("%dB", $img_size)); |
| 157 | + |
| 158 | + return $info; |
| 159 | +} |
| 160 | + |
| 161 | +function getImageLabels($img) { |
| 162 | + global $wwLabelPatterns; |
| 163 | + |
| 164 | + if (!$wwLabelPatterns || empty($img['tags'])) return false; |
| 165 | + |
| 166 | + $labels = array(); |
| 167 | + |
| 168 | + foreach ( $img['tags'] as $tag ) { |
| 169 | + foreach ( $wwLabelPatterns as $pattern => $label ) { |
| 170 | + if ( preg_match($pattern, $tag) ) { |
| 171 | + $labels[$label] = "<span title=\"".htmlspecialchars($tag)."\">".htmlspecialchars($label)."</span>"; |
| 172 | + break; |
| 173 | + } |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | + $labels = array_values($labels); |
| 178 | + return $labels; |
| 179 | +} |
| 180 | + |
| 181 | +function getConceptDetailsURL($langs, $concept) { |
| 182 | + global $wwSelf; |
| 183 | + |
| 184 | + if ( is_array($langs) ) $langs = implode('|', $langs); |
| 185 | + |
| 186 | + return "$wwSelf?id=" . urlencode($concept['id']) . "&lang=" . urlencode($langs); |
| 187 | +} |
| 188 | + |
| 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 | + |
| 204 | +function pickPage( $pages ) { |
| 205 | + if (!$pages) return false; |
| 206 | + |
| 207 | + foreach ( $pages as $page => $type ) { |
| 208 | + if ($type == 10) return $page; |
| 209 | + } |
| 210 | + |
| 211 | + return $pages[0]; |
| 212 | +} |
| 213 | + |
| 214 | +function getConceptPageURLs($lang, $concept) { |
| 215 | + if (!isset($concept['pages'][$lang]) || !$concept['pages'][$lang]) return false; |
| 216 | + |
| 217 | + if ($lang == 'commons') $domain = 'commons.wikimedia.org'; |
| 218 | + else $domain = "$lang.wikipedia.org"; |
| 219 | + |
| 220 | + $urls = array(); |
| 221 | + foreach ($concept['pages'][$lang] as $page => $type) { |
| 222 | + $u = "http://$domain/wiki/" . urlencode($page); |
| 223 | + $urls[$page] = $u; |
| 224 | + } |
| 225 | + |
| 226 | + return $urls; |
| 227 | +} |
| 228 | + |
| 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 | + |
| 293 | +function array_key_diff($base, $other) { |
| 294 | + $keys = array_keys($other); |
| 295 | + foreach ($keys as $k) { |
| 296 | + unset($base[$k]); |
| 297 | + } |
| 298 | + |
| 299 | + return $base; |
| 300 | +} |
| 301 | + |
| 302 | +function getRelatedConceptList( $concept ) { |
| 303 | + $related = array(); |
| 304 | + if ( @$concept['similar'] ) $related += $concept['similar']; |
| 305 | + if ( @$concept['related'] ) $related += $concept['related']; |
| 306 | + |
| 307 | + if (isset($concept['broader'])) $related = array_key_diff($related, $concept['broader']); |
| 308 | + if (isset($concept['narrower'])) $related = array_key_diff($related, $concept['narrower']); |
| 309 | + |
| 310 | + sortConceptList($related); |
| 311 | + return $related; |
| 312 | +} |
| 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 | + |
| 342 | +function stripSections(&$concepts) { |
| 343 | + foreach ($concepts as $k => $c) { |
| 344 | + foreach ($c['name'] as $l => $n) { |
| 345 | + if (preg_match('/#/', $n)) { |
| 346 | + unset($concepts[$k]); |
| 347 | + break; |
| 348 | + } |
| 349 | + } |
| 350 | + } |
| 351 | +} |
| 352 | + |
| 353 | +function compareConceptScoreAndName($a, $b) { |
| 354 | + if (isset($a['score']) && isset($b['score']) && $a['score'] != $b['score']) { |
| 355 | + if ( $a['score'] > $b['score'] ) return 1; |
| 356 | + else return -1; |
| 357 | + } else { |
| 358 | + if ( $a['name'] > $b['name'] ) return 1; //XXX: unicode collation?? |
| 359 | + else return -1; |
| 360 | + } |
| 361 | + |
| 362 | + return 0; |
| 363 | +} |
| 364 | + |
| 365 | +function sortConceptList(&$concepts) { |
| 366 | + usort($concepts, 'compareConceptScoreAndName'); |
| 367 | +} |
| 368 | + |
| 369 | +function mangleConcept(&$concept) { |
| 370 | + stripSections($concept['narrower']); |
| 371 | + |
| 372 | + sortConceptList($concept['narrower']); |
| 373 | + sortConceptList($concept['related']); |
| 374 | + sortConceptList($concept['similar']); |
| 375 | + sortConceptList($concept['broader']); |
| 376 | +} |
| 377 | + |
| 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 | + |
| 469 | + </td> |
| 470 | + </tr> |
| 471 | + |
| 472 | + <?php |
| 473 | + if (isset($score) && $score && $score<2 && $pos>=3) return false; |
| 474 | + else return true; |
| 475 | +} |
| 476 | + |
| 477 | +$conceptId = @$_REQUEST['id']; |
| 478 | +$term = @$_REQUEST['term']; |
| 479 | +$lang = @$_REQUEST['lang']; |
| 480 | + |
| 481 | +if ($term!==NULL && preg_match('/^\s*#(\d+)\s*$/', $term, $m)) { |
| 482 | + $conceptId = $m[1]; |
| 483 | + $term = NULL; |
| 484 | +} |
| 485 | + |
| 486 | +if (!isset($wwSelf)) $wwSelf = @$_SERVER["PHP_SELF"]; |
| 487 | + |
| 488 | +$error = NULL; |
| 489 | + |
| 490 | +if ($lang) { |
| 491 | + $ll = preg_split('![,;/|+]!', $lang); |
| 492 | + foreach ($ll as $l) { |
| 493 | + if (!isset($wwLanguages[$l]) && $l != "commons") { |
| 494 | + $error = "bad language code: $l"; |
| 495 | + $lang = NULL; |
| 496 | + } |
| 497 | + } |
| 498 | +} |
| 499 | + |
| 500 | +if ($wwAPI) $thesaurus = new WWClient($wwAPI); |
| 501 | +else { |
| 502 | + $thesaurus = new WWThesaurus(); |
| 503 | + $thesaurus->connect($wwDBServer, $wwDBUser, $wwDBPassword, $wwDBDatabase); |
| 504 | +} |
| 505 | + |
| 506 | +if (@$wwFakeImages) $utils = new WWFakeImages( $thesaurus ); |
| 507 | +else $utils = new WWImages( $thesaurus ); |
| 508 | + |
| 509 | + |
| 510 | +if ( !$utils->db ) $utils->connect($wwDBServer, $wwDBUser, $wwDBPassword, $wwDBDatabase); |
| 511 | + |
| 512 | +if (@$_REQUEST['debug']) $utils->debug = true; |
| 513 | + |
| 514 | +$limit = 20; |
| 515 | +$norm = 1; |
| 516 | + |
| 517 | +$mode = NULL; |
| 518 | +$result = NULL; |
| 519 | + |
| 520 | +$fallback_languages = array( "en", "commons" ); #TODO: make the user define this list |
| 521 | + |
| 522 | +if ( $lang ) { |
| 523 | + $languages = explode( '|', $lang ); |
| 524 | + $languages = array_merge( $languages, $fallback_languages ); |
| 525 | + $languages = array_unique( $languages ); |
| 526 | +} else { |
| 527 | + $languages = $fallback_languages; |
| 528 | +} |
| 529 | + |
| 530 | +$lang = $languages[0]; |
| 531 | + |
| 532 | +$allLanguages = array_keys($wwLanguages); |
| 533 | + |
| 534 | +$profiling['thesaurus'] = 0; |
| 535 | +$profiling['pics'] = 0; |
| 536 | + |
| 537 | +if (!$error) { |
| 538 | + $t = microtime(true); |
| 539 | + try { |
| 540 | + if ($lang && $conceptId) { |
| 541 | + $mode = "concept"; |
| 542 | + $result = $thesaurus->getConceptInfo($conceptId, $allLanguages); |
| 543 | + if ( $result ) $result = array( $result ); //hack |
| 544 | + } else if ($lang && $term) { |
| 545 | + $mode = "term"; |
| 546 | + $result = $thesaurus->getConceptsForTerm($lang, $term, $allLanguages, $norm, $limit); |
| 547 | + } |
| 548 | + } catch (Exception $e) { |
| 549 | + $error = $e->getMessage(); |
| 550 | + } |
| 551 | + $profiling['thesaurus'] += (microtime(true) - $t); |
| 552 | +} |
| 553 | + |
| 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α (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> --> |
| 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 |
Property changes on: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics/search.php |
___________________________________________________________________ |
Name: svn:mergeinfo |
1 | 758 | + |
Property changes on: trunk/WikiWord/WikiWordWeb/src/main/www/wikipics |
___________________________________________________________________ |
Name: svn:mergeinfo |
2 | 759 | + |
Index: trunk/WikiWord/WikiWordWeb/src/main/www/config.sample.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -#$wwAPI = "http://wikiword.wikimedia.de/api.php"; |
| 4 | +#$wwAPI = "http://wikiword.wikimedia.de/wikiword/api.php"; |
5 | 5 | $wwAPI = false; |
6 | 6 | $wwAllowTranslate = false; |
7 | 7 | $wwImageSearch = null; //NOTE: trinary: true forces image searche, false disables it. null makes it optional. |
Property changes on: trunk/WikiWord/WikiWordWeb/src/main/www |
___________________________________________________________________ |
Name: svn:ignore |
8 | 8 | + config.php |