Index: trunk/WikiWord/WikiWord/src/main/php/api.php |
— | — | @@ -45,6 +45,8 @@ |
46 | 46 | } |
47 | 47 | } else if ($query == 'properties') { |
48 | 48 | $gcid = @$_REQUEST['gcid']; |
| 49 | + if (!$gcid) $gcid = @$_REQUEST['id']; |
| 50 | + |
49 | 51 | $props = @$_REQUEST['props']; |
50 | 52 | |
51 | 53 | if ( $gcid === null ) $result['error'] = array('code' => 120, 'message' => "missing parameter gcid"); |
— | — | @@ -52,19 +54,29 @@ |
53 | 55 | else { |
54 | 56 | $props = preg_split('![\\s,;|/:]\\s*!', $props); |
55 | 57 | |
56 | | - foreach ( $props as $p ) { |
57 | | - $m = "get" . ucfirst($p) . "ForConcept"; |
58 | | - if ( !method_exists($thesaurus, $m) ) { |
59 | | - $result['error'] = array('code' => 190, 'message' => "unknown property: $p"); |
60 | | - break; |
61 | | - } |
| 58 | + $info = $thesaurus->getConcept($gcid, $lang); |
62 | 59 | |
63 | | - $result[$p] = $thesaurus->$m($gcid, $lang); |
| 60 | + if ( !$info ) $result['error'] = array('code' => 100, 'message' => "concept not found: $gcid"); |
| 61 | + else { |
| 62 | + $result = array_merge($result, $info); |
64 | 63 | |
65 | | - if ( $result[$p] === false || $result[$p] === null ) { |
66 | | - $result['error'] = array('code' => 220, 'message' => "failed to retrieve property $p for concept $gcid"); |
67 | | - break; |
| 64 | + foreach ( $props as $p ) { |
| 65 | + $m = "get" . ucfirst($p) . "ForConcept"; |
| 66 | + if ( !method_exists($thesaurus, $m) ) { |
| 67 | + $result['error'] = array('code' => 190, 'message' => "unknown property: $p"); |
| 68 | + break; |
| 69 | + } |
| 70 | + |
| 71 | + $result[$p] = $thesaurus->$m($gcid, $lang); |
| 72 | + |
| 73 | + if ( $result[$p] === false || $result[$p] === null ) { |
| 74 | + $result['error'] = array('code' => 220, 'message' => "failed to retrieve property $p for concept $gcid"); |
| 75 | + break; |
| 76 | + } |
68 | 77 | } |
| 78 | + |
| 79 | + if (!isset($result['id'])) $result['id'] = $gcid; |
| 80 | + if (!isset($result['lang'])) $result['lang'] = $lang; |
69 | 81 | } |
70 | 82 | } |
71 | 83 | } else { |
Index: trunk/WikiWord/WikiWord/src/main/php/wwclient.php |
— | — | @@ -32,6 +32,11 @@ |
33 | 33 | return getPagesForConcept($id); |
34 | 34 | } |
35 | 35 | |
| 36 | + function getConcept( $id, $lang = null ) { |
| 37 | + $p = $this->getConceptProperties( $id, '', $lang ); |
| 38 | + return $p['pages']; |
| 39 | + } |
| 40 | + |
36 | 41 | function getPagesForConcept( $id, $lang = null ) { |
37 | 42 | $p = $this->getConceptProperties( $id, 'pages', $lang ); |
38 | 43 | return $p['pages']; |
— | — | @@ -78,8 +83,8 @@ |
79 | 84 | } |
80 | 85 | |
81 | 86 | function getConceptInfo( $id, $lang = null ) { |
82 | | - if ( $lang ) return $this->getConceptProperties( "definition,broader,narrower,related" ); |
83 | | - else return $this->getConceptProperties( "broader,narrower,related" ); |
| 87 | + if ( $lang ) return $this->getConceptProperties( $id, "definition,broader,narrower,related", $lang ); |
| 88 | + else return $this->getConceptProperties( $id, "broader,narrower,related" ); |
84 | 89 | } |
85 | 90 | |
86 | 91 | function getConceptProperties( $id, $props, $lang = null ) { |
— | — | @@ -93,6 +98,9 @@ |
94 | 99 | |
95 | 100 | $rs = $this->query( $param ); |
96 | 101 | |
| 102 | + if (!isset($rs['id'])) $rs['id'] = $id; |
| 103 | + if (!isset($rs['lang'])) $rs['lang'] = $lang; |
| 104 | + |
97 | 105 | return $rs; |
98 | 106 | } |
99 | 107 | |
Index: trunk/WikiWord/WikiWord/src/main/php/wikiword.php |
— | — | @@ -45,7 +45,7 @@ |
46 | 46 | } |
47 | 47 | |
48 | 48 | function printLocalConceptLink($lang, $row) { |
49 | | - global $wwSelf; |
| 49 | + global $wwSelf, $images; |
50 | 50 | |
51 | 51 | extract($row); |
52 | 52 | |
— | — | @@ -56,16 +56,21 @@ |
57 | 57 | if (!isset($concept) && isset($id)) $concept = $id; |
58 | 58 | if (!isset($concept)) $concept = NULL; |
59 | 59 | |
60 | | - $wu = $concept_name ? "http://$lang.wikipedia.org/wiki/" . urlencode($concept_name) : NULL; |
| 60 | + if ($lang == 'commons') $domain = 'commons.wikimedia.org'; |
| 61 | + else $domain = "$lang.wikipedia.org"; |
| 62 | + |
| 63 | + $wu = $concept_name ? "http://$domain/wiki/" . urlencode($concept_name) : NULL; |
61 | 64 | $cu = "$wwSelf?id=" . urlencode($concept) . "&lang=" . urlencode($lang); |
62 | 65 | |
| 66 | + if ($images) $cu .= "&images=1"; |
| 67 | + |
63 | 68 | ?> |
64 | 69 | <li> |
65 | 70 | <?php if ($concept_name) { ?> |
66 | | - <a href="<?php print htmlspecialchars($wu); ?>"><?php print htmlspecialchars($concept_name); ?></a> |
| 71 | + <a href="<?php print htmlspecialchars($cu); ?>"><?php print htmlspecialchars($concept_name); ?></a> |
67 | 72 | <?php } ?> |
68 | 73 | <?php if ($concept) { ?> |
69 | | - (#<a href="<?php print htmlspecialchars($cu); ?>"><?php print htmlspecialchars($concept); ?></a>) |
| 74 | + (<a href="<?php print htmlspecialchars($wu); ?>" title="<?php print htmlspecialchars($concept_name); ?>">wiki page</a>) |
70 | 75 | <?php } ?> |
71 | 76 | </li> |
72 | 77 | <?php |
— | — | @@ -116,7 +121,9 @@ |
117 | 122 | |
118 | 123 | if (!isset($row['weight']) && isset($row['freq'])) $row['weight'] = $row['freq']; |
119 | 124 | if (!isset($row['weight']) && isset($row['conf'])) $row['weight'] = $row['conf']; |
| 125 | + if (isset($row['local_concept_name'])) $row['concept_name'] = $row['local_concept_name']; |
120 | 126 | if (!isset($row['concept_name']) && isset($row['name'])) $row['concept_name'] = $row['name']; |
| 127 | + if (!isset($row['concept_name']) && isset($row['global_concept_name'])) $row['concept_name'] = $row['global_concept_name']; |
121 | 128 | if (!isset($row['reference_id']) && isset($row['global_id'])) $row['reference_id'] = $row['global_id']; |
122 | 129 | if (!isset($row['reference_id']) && isset($row['global_concept'])) $row['reference_id'] = $row['global_concept']; |
123 | 130 | if (!isset($row['reference_id']) && isset($row['concept'])) $row['reference_id'] = $row['concept']; |
— | — | @@ -144,8 +151,8 @@ |
145 | 152 | return $row; |
146 | 153 | } |
147 | 154 | |
148 | | -function printLocalConcept($a_lang, $a_row, $b_lang, $b_row, $pos = 0) { |
149 | | - global $wwSelf, $images; |
| 155 | +function printLocalConcept($a_lang, $a_row, $b_lang, $b_row, $pos = 0, $images) { |
| 156 | + global $wwSelf; |
150 | 157 | |
151 | 158 | $a_row = normalizeConceptRow($a_lang, $a_row); |
152 | 159 | $b_row = normalizeConceptRow($b_lang, $b_row); |
— | — | @@ -157,15 +164,13 @@ |
158 | 165 | <tr class="row_item"> |
159 | 166 | <td class="cell_weight <?php print "weight_$a_wclass"; ?>"><?php print htmlspecialchars($a_weight); ?></td> |
160 | 167 | <td colspan="3" class="cell_name <?php print "weight_$a_wclass"; ?>"> |
161 | | - <a href="<?php print htmlspecialchars($a_wu); ?>"><?php print htmlspecialchars($a_concept_name); ?></a> |
162 | | - <span class="conceptref">(#<a href="<?php print htmlspecialchars($a_cu); ?>"><?php print htmlspecialchars($a_reference_id); ?></a>)</span> |
163 | | - <span class="galleryref">(<a href="<?php print htmlspecialchars($a_gu); ?>"><?php print htmlspecialchars("gallery"); ?></a>)</span> |
| 168 | + <a href="<?php print htmlspecialchars($a_cu); ?>"><?php print htmlspecialchars($a_concept_name); ?></a> |
| 169 | + <span class="conceptref">(<a href="<?php print htmlspecialchars($a_wu); ?>" title="<?php print htmlspecialchars($a_concept_name); ?>">wiki page</a>)</span> |
164 | 170 | </td> |
165 | 171 | <?php if ($b_row) { ?> |
166 | 172 | <td colspan="3" class="cell_name <?php print "weight_$b_wclass"; ?>"> |
167 | | - <a href="<?php print htmlspecialchars($b_wu); ?>"><?php print htmlspecialchars($b_concept_name); ?></a> |
168 | | - <span class="conceptref">(#<a href="<?php print htmlspecialchars($b_cu); ?>"><?php print htmlspecialchars($b_reference_id); ?></a>)</span> |
169 | | - <span class="galleryref">(<a href="<?php print htmlspecialchars($a_gu); ?>"><?php print htmlspecialchars("gallery"); ?></a>)</span> |
| 173 | + <a href="<?php print htmlspecialchars($b_cu); ?>"><?php print htmlspecialchars($b_concept_name); ?></a> |
| 174 | + <span class="conceptref">(<a href="<?php print htmlspecialchars($b_wu); ?>" title="<?php print htmlspecialchars($b_concept_name); ?>">wiki page</a>)</span> |
170 | 175 | </td> |
171 | 176 | <?php } ?> |
172 | 177 | </tr> |
— | — | @@ -260,7 +265,7 @@ |
261 | 266 | $term = @$_REQUEST['term']; |
262 | 267 | $lang = @$_REQUEST['lang']; |
263 | 268 | $tolang = @$_REQUEST['tolang']; |
264 | | -$images = @$_REQUEST['images'] || $wwImageSearch; |
| 269 | +$images = (@$_REQUEST['images'] || $wwImageSearch === true ) && !($wwImageSearch === false); |
265 | 270 | |
266 | 271 | if (!isset($_REQUEST['translate'])) $tolang = NULL; |
267 | 272 | if ($lang == $tolang) $tolang = NULL; |
— | — | @@ -288,7 +293,6 @@ |
289 | 294 | $limit = 20; |
290 | 295 | |
291 | 296 | $result = NULL; |
292 | | -$gallery = NULL; |
293 | 297 | |
294 | 298 | if (!$error) { |
295 | 299 | try { |
— | — | @@ -297,9 +301,7 @@ |
298 | 302 | if ( $result ) $result = array( $result ); //hack |
299 | 303 | } else if ($lang && $term) { |
300 | 304 | $result = $thesaurus->getConceptsForTerm($lang, $term, $limit); |
301 | | - } else if ($concept && $images) { |
302 | | - $gallery = $utils->getImagesAbout($concept); |
303 | | - } |
| 305 | + } |
304 | 306 | } catch (Exception $e) { |
305 | 307 | $error = $e->getMessage(); |
306 | 308 | } |
— | — | @@ -361,7 +363,7 @@ |
362 | 364 | <td> |
363 | 365 | <input type="submit" name="go" value="go"/> |
364 | 366 | </td> |
365 | | - <?php if (!$wwImageSearch) { ?> |
| 367 | + <?php if ($wwImageSearch === null) { ?> |
366 | 368 | <td> |
367 | 369 | <label for="images">Images: </label> |
368 | 370 | <input type="checkbox" name="images" value="Images" <?php print $images ? " checked=\"checked\"" : ""?>/> |
— | — | @@ -393,14 +395,63 @@ |
394 | 396 | ?> |
395 | 397 | |
396 | 398 | <?php |
397 | | -if ($result) { |
398 | | - if ($concept) $title = "Concept #$concept"; |
399 | | - else if ($tolang) $title = "$lang: $term -> $tolang"; |
400 | | - else $title = "$lang: $term"; |
| 399 | +if ($result && $concept) { |
| 400 | + foreach ( $result as $row ) { |
| 401 | + if (@$row['id']) $id = $row['id']; |
| 402 | + else if (@$row['concept']) $id = $row['concept']; |
| 403 | + else $id = "concept"; |
| 404 | + |
| 405 | + if (@$row['local_concept_name']) $title = $row['local_concept_name']; |
| 406 | + else if (@$row['concept_name']) $title = $row['concept_name']; |
| 407 | + else if (@$row['name']) $title = $row['name']; |
| 408 | + else if ($id) $title = "Concept #$id"; |
| 409 | + else if ($concept) $title = "Concept #$concept"; |
| 410 | + |
401 | 411 | ?> |
| 412 | + <div id="<?php print htmlspecialchars("concept-$id")?>"> |
402 | 413 | <h2><?php print htmlspecialchars($title); ?></h2> |
| 414 | + |
| 415 | + <?php |
| 416 | + if ($images) $gallery = $utils->getImagesAbout($id); |
| 417 | + else $images = NULL; |
| 418 | + |
| 419 | + if ($gallery) { |
| 420 | + $title = "Gallery #$concept"; |
| 421 | + ?> |
| 422 | + <h2><?php print htmlspecialchars($title); ?></h2> |
| 423 | + <div border="0" class="gallery"> |
| 424 | + <?php |
| 425 | + printConceptImageList($gallery, "gallery"); |
| 426 | + ?> |
| 427 | + </div> |
| 428 | + |
| 429 | + <p>Found <?php print count($gallery); ?> images.</p> |
| 430 | + |
| 431 | + <?php |
| 432 | + } |
| 433 | + ?> |
| 434 | + |
403 | 435 | <table border="0" class="results"> |
404 | 436 | <?php |
| 437 | + if ($lang) { |
| 438 | + $continue= printLocalConcept($lang, $row, NULL, NULL, 0, false); |
| 439 | + } |
| 440 | + //else $continue= printGlobalConcept($lang, $row, $count); |
| 441 | + |
| 442 | + if (!$continue) break; |
| 443 | + ?> |
| 444 | + </table> |
| 445 | + </div> |
| 446 | + |
| 447 | +<?php |
| 448 | + } #concept loop |
| 449 | +} else if ($result && $term) { |
| 450 | + if ($tolang) $title = "$lang: $term -> $tolang"; |
| 451 | + else if ($term) $title = "$lang: $term"; |
| 452 | +?> |
| 453 | + <h2><?php print htmlspecialchars($title); ?></h2> |
| 454 | + <table border="0" class="results"> |
| 455 | + <?php |
405 | 456 | $count = 0; |
406 | 457 | foreach ( $result as $row ) { |
407 | 458 | $count += 1; |
— | — | @@ -411,14 +462,14 @@ |
412 | 463 | if ($tolang && isset($row['global_concept'])) { |
413 | 464 | $toresult = $utils->queryConceptInfo($row['global_concept'], $tolang); |
414 | 465 | while ($torow = mysql_fetch_assoc($toresult)) { |
415 | | - $continue= printLocalConcept($lang, $row, $tolang, $torow, $count); |
| 466 | + $continue= printLocalConcept($lang, $row, $tolang, $torow, $count, $images); |
416 | 467 | $show_single = false; |
417 | 468 | } |
418 | 469 | mysql_free_result($toresult); |
419 | 470 | } |
420 | 471 | |
421 | 472 | if ($show_single) { |
422 | | - $continue= printLocalConcept($lang, $row, NULL, NULL, $count); |
| 473 | + $continue= printLocalConcept($lang, $row, NULL, NULL, $count, $images); |
423 | 474 | } |
424 | 475 | } |
425 | 476 | //else $continue= printGlobalConcept($lang, $row, $count); |
— | — | @@ -434,24 +485,6 @@ |
435 | 486 | } |
436 | 487 | ?> |
437 | 488 | |
438 | | -<?php |
439 | | -if ($gallery) { |
440 | | - $title = "Gallery #$concept"; |
441 | | -?> |
442 | | - <h2><?php print htmlspecialchars($title); ?></h2> |
443 | | - <div border="0" class="results"> |
444 | | - <?php |
445 | | - printConceptImageList($gallery, "gallery"); |
446 | | - ?> |
447 | | - </div> |
448 | | - |
449 | | - <p>Found <?php print count($gallery); ?> images.</p> |
450 | | - |
451 | | -<?php |
452 | | -} |
453 | | -?> |
454 | | - |
455 | | - |
456 | 489 | <p class="footer"> |
457 | 490 | The WikiWord Navigator is part of the <a href="http://wikimedia.de">Wikimedia</a> project <a href="http://brightbyte.de/page/WikiWord">WikiWord</a> |
458 | 491 | <p> |
Index: trunk/WikiWord/WikiWord/src/main/php/wwthesaurus.php |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | }*/ |
86 | 86 | |
87 | 87 | function getConceptInfo( $id, $lang = null ) { |
88 | | - $result = array(); |
| 88 | + $result = $this->getConcept($id, $lang); |
89 | 89 | |
90 | 90 | $result['broader'] = $this->getBroaderForConcept($id); |
91 | 91 | $result['narrower'] = $this->getNarrowerForConcept($id); |
— | — | @@ -161,6 +161,22 @@ |
162 | 162 | } |
163 | 163 | |
164 | 164 | ///////////////////////////////////////////////////////// |
| 165 | + function getConcept( $id, $lang = null, $limit = 100 ) { |
| 166 | + global $wwTablePrefix, $wwThesaurusDataset; |
| 167 | + |
| 168 | + if ($lang) $sql = "SELECT C.*, O.* FROM {$wwTablePrefix}_{$wwThesaurusDataset}_concept as C " |
| 169 | + . " LEFT JOIN {$wwTablePrefix}_{$wwThesaurusDataset}_origin as O " |
| 170 | + . " ON C.id = O.global_concept " . " AND O.lang = \"".mysql_real_escape_string($lang)."\"" |
| 171 | + . " WHERE C.id = ".(int)$id ; |
| 172 | + else $sql = "SELECT C.* FROM {$wwTablePrefix}_{$wwThesaurusDataset}_concept as C " |
| 173 | + . " WHERE C.id = ".(int)$id; |
| 174 | + |
| 175 | + $r = $this->getRows($sql); |
| 176 | + |
| 177 | + if ( !$r ) return false; |
| 178 | + else return $r[0]; |
| 179 | + } |
| 180 | + |
165 | 181 | function getRelatedForConcept( $id, $lang = null, $limit = 100 ) { |
166 | 182 | global $wwTablePrefix, $wwThesaurusDataset; |
167 | 183 | |
Index: trunk/WikiWord/WikiWord/src/main/php/config.sample.php |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | #$wwAPI = "http://wikiword.wikimedia.de/api.php"; |
5 | 5 | $wwAPI = false; |
6 | 6 | $wwAllowTranslate = false; |
7 | | -$wwImageSearch = false; |
| 7 | +$wwImageSearch = null; //NOTE: trinary: true forces image searche, false disables it. null makes it optional. |
8 | 8 | |
9 | 9 | $wwDBServer = "localhost"; |
10 | 10 | $wwDBUser = "wikiword"; |