Index: trunk/WikiWord/WikiWord/src/main/php/wwutils.php |
— | — | @@ -1,22 +1,30 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class WWUtil { |
5 | | - static function connect($server, $user, $password, $database) { |
| 4 | +class WWUtils { |
| 5 | + var $debug = false; |
| 6 | + var $db = NULL; |
| 7 | + |
| 8 | + function connect($server, $user, $password, $database) { |
6 | 9 | $db = mysql_connect($server, $user, $password) or die("Connection Failure to Database: " . mysql_error()); |
7 | 10 | mysql_select_db($database, $db) or die ("Database not found: " . mysql_error()); |
8 | 11 | mysql_query("SET NAMES UTF8;", $db) or die ("Database not found: " . mysql_error()); |
9 | 12 | |
10 | | - if (isset($this)) $this->db = $db; |
| 13 | + $this->db = $db; |
| 14 | + |
11 | 15 | return $db; |
12 | 16 | } |
13 | 17 | |
14 | | - static function query($sql, $db = NULL) { |
15 | | - if ($db == NULL && isset($this)) $db = $this->$db; |
| 18 | + function query($sql, $db = NULL) { |
| 19 | + if ($db == NULL && isset($this)) $db = $this->db; |
16 | 20 | |
17 | | - if ($debug) { |
| 21 | + if ($this->debug) { |
18 | 22 | print htmlspecialchars($sql); |
19 | 23 | } |
20 | 24 | |
| 25 | + if (!$db) { |
| 26 | + throw new Exception("not connected!"); |
| 27 | + } |
| 28 | + |
21 | 29 | $result = mysql_query($sql, $db); |
22 | 30 | |
23 | 31 | if(!$result) { |
— | — | @@ -28,12 +36,18 @@ |
29 | 37 | return $result; |
30 | 38 | } |
31 | 39 | |
| 40 | + function close() { |
| 41 | + if ($this->db) mysql_close($this->db); |
| 42 | + $this->db = NULL; |
| 43 | + } |
| 44 | + |
32 | 45 | function queryConceptsForTerm($lang, $term) { |
33 | 46 | global $wwTablePrefix; |
34 | 47 | |
35 | 48 | $term = trim($term); |
36 | 49 | |
37 | | - $sql = "SELECT * FROM {$wwTablePrefix}_{$lang}_meaning " |
| 50 | + $sql = "SELECT M.*, definition FROM {$wwTablePrefix}_{$lang}_meaning as M" |
| 51 | + . " JOIN {$wwTablePrefix}_{$lang}_definition as D ON M.concept = D.concept " |
38 | 52 | . " WHERE term_text = \"" . mysql_real_escape_string($term) . "\"" |
39 | 53 | . " ORDER BY freq DESC " |
40 | 54 | . " LIMIT 100"; |
— | — | @@ -47,6 +61,7 @@ |
48 | 62 | $term = trim($term); |
49 | 63 | |
50 | 64 | $sql = "SELECT * FROM {$wwTablePrefix}_{$lang}_concept_info " |
| 65 | + . " JOIN {$wwTablePrefix}_{$lang}_definition as D ON M.concept = D.concept " |
51 | 66 | . " WHERE concept = $id "; |
52 | 67 | |
53 | 68 | return $this->query($sql); |
Index: trunk/WikiWord/WikiWord/src/main/php/wikiword.php |
— | — | @@ -9,6 +9,8 @@ |
10 | 10 | $term = @$_REQUEST['term']; |
11 | 11 | $lang = @$_REQUEST['lang']; |
12 | 12 | |
| 13 | +if (!isset($wwSelf)) $wwSelf = @$_SERVER["PHP_SELF"]; |
| 14 | + |
13 | 15 | $error = NULL; |
14 | 16 | |
15 | 17 | if ($lang && !isset($wwLanguages[$lang])) { |
— | — | @@ -19,23 +21,29 @@ |
20 | 22 | $utils = new WWUtils(); |
21 | 23 | $utils->connect($wwDBServer, $wwDBUser, $wwDBPassword, $wwDBDatabase); |
22 | 24 | |
| 25 | +if (@$_REQUEST['debug']) $utils->debug = true; |
| 26 | + |
| 27 | +$result = NULL; |
| 28 | + |
23 | 29 | if (!$error) { |
24 | 30 | try { |
25 | | - if ($id) { |
| 31 | + if ($concept) { |
26 | 32 | if ($lang) { |
27 | | - $result = $utils->queryLocalConceptInfo($lang, $id); |
| 33 | + $result = $utils->queryLocalConceptInfo($lang, $concept); |
28 | 34 | } else { |
29 | | - $result = $utils->queryGlobalConceptInfo($id); |
| 35 | + $result = $utils->queryGlobalConceptInfo($concept); |
30 | 36 | } |
31 | 37 | } else if ($lang) { |
32 | | - $result = $utils->queryConceptsForTerm($lang, $id); |
| 38 | + $result = $utils->queryConceptsForTerm($lang, $term); |
33 | 39 | } |
34 | 40 | } catch (Exception $e) { |
35 | 41 | $error = $e->getMessage(); |
36 | 42 | } |
37 | 43 | } |
38 | 44 | |
39 | | -function printLocalConcept($lang, $row) { |
| 45 | +function printLocalConcept($lang, $row, $pos = 0) { |
| 46 | + global $wwSelf; |
| 47 | + |
40 | 48 | extract($row); |
41 | 49 | |
42 | 50 | if (!isset($weight) && isset($freq)) $weight = $freq; |
— | — | @@ -43,12 +51,26 @@ |
44 | 52 | $wu = "http://$lang.wikipedia.org/wiki/" . urlencode($concept_name); |
45 | 53 | $cu = "$wwSelf?id=" . urlencode($concept) . "&lang=" . urlencode($lang); |
46 | 54 | |
47 | | - print "\t\t<li>"; |
48 | | - if (isset($weight) && !empty($weight)) print "<b>" . htmlspecialchars($weight) . "</b> "; |
49 | | - print "<big><b><a href=\"".htmlspecialchars($wu)."\">".htmlspecialchars($concept_name)."</a></b></big> "; |
50 | | - print " (<a href=\"".htmlspecialchars($cu)."\">#".htmlspecialchars($concept)."</a>) "; |
51 | | - if (isset($definition) && !empty($definition)) print "<br/><small>" . htmlspecialchars($definition) . "</small>"; |
52 | | - print "</li>\n"; |
| 55 | + if (!$weight) $wclass = "x"; |
| 56 | + else if ($weight>1000) $wclass = "huge"; |
| 57 | + else if ($weight>100) $wclass = "big"; |
| 58 | + else if ($weight>10) $wclass = "normal"; |
| 59 | + else if ($weight>2) $wclass = "some"; |
| 60 | + else $wclass = "little"; |
| 61 | + |
| 62 | + ?> |
| 63 | + <tr class="row_item"> |
| 64 | + <td class="col_weight <?php print "weight_$wclass"; ?>"><?php print htmlspecialchars($weight); ?></td> |
| 65 | + <td class="col_name <?php print "weight_$wclass"; ?>"><a href="<?php print htmlspecialchars($wu); ?>"><?php print htmlspecialchars($concept_name); ?></a></td> |
| 66 | + <td class="col_concept <?php print "weight_$wclass"; ?>">(#<a href="<?php print htmlspecialchars($cu); ?>"><?php print htmlspecialchars($concept); ?></a>)</td> |
| 67 | + </tr> |
| 68 | + <tr class="row_def"> |
| 69 | + <td></td> |
| 70 | + <td colspan="2"><?php print htmlspecialchars($definition); ?></td> |
| 71 | + </tr> |
| 72 | + <?php |
| 73 | + if ($weight && $weight<2 && $pos>=3) return false; |
| 74 | + else return true; |
53 | 75 | } |
54 | 76 | |
55 | 77 | ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
— | — | @@ -56,18 +78,30 @@ |
57 | 79 | <head> |
58 | 80 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
59 | 81 | <title>WikiWord Navigator</title> |
| 82 | + |
| 83 | + <style type="text/css"> |
| 84 | + .error { color: red; font-weight: bold; } |
| 85 | + .weight_huge { font-size: 140%; font-weight:bold; } |
| 86 | + .weight_big { font-size: 120%; font-weight:bold; } |
| 87 | + .weight_normal { font-size: 110%; font-weight:bold; } |
| 88 | + .weight_some { font-size: 100%; font-weight:normal; } |
| 89 | + .weight_little { font-size: 90%; font-weight:normal; } |
| 90 | + .row_def td { font-size: 80%; } |
| 91 | + .col_weight td { text-align: right; } |
| 92 | + </style> |
60 | 93 | </head> |
61 | 94 | <body> |
62 | 95 | <h1>WikiWord Navigator</h1> |
63 | 96 | <p>Experimental proof of concept <a href="http://brightbyte.de/page/WikiWord">WikiWord</a> navigator.</p> |
64 | 97 | |
65 | | - <form name="search"> |
| 98 | + <form name="search" action="<?php print $wwSelf; ?>"> |
66 | 99 | <p> |
67 | | - <lable for="term">Term: </label><input type="text" name="term" id="term" length="24" value="<?php print htmlspecialchars($term); ?>"/> |
68 | | - <lable for="term">Language: </label> |
| 100 | + <label for="term">Term: </label><input type="text" name="term" id="term" size="24" value="<?php print htmlspecialchars($term); ?>"/> |
| 101 | + <label for="term">Language: </label> |
69 | 102 | <?php WWUtils::printSelector("lang", $wwLanguages, $lang) ?> |
70 | 103 | <input type="submit" value="go"/> |
71 | 104 | </p> |
| 105 | + <p>Note: this is a thesaurus lookup, not a full text search. Only exact matches are considered, matching is case-sensitive.</p> |
72 | 106 | </form> |
73 | 107 | <?php |
74 | 108 | if ($error) { |
— | — | @@ -78,18 +112,20 @@ |
79 | 113 | <?php |
80 | 114 | if ($result) { |
81 | 115 | ?> |
82 | | - <ul> |
| 116 | + <table border="0" class="results"> |
83 | 117 | <?php |
84 | 118 | $count = 0; |
85 | 119 | while ($row = mysql_fetch_assoc($result)) { |
86 | | - if ($lang) printLocalConcept($lang, $row); |
87 | | - else printGlobalConcept($lang, $row); |
88 | 120 | $count += 1; |
| 121 | + if ($lang) $continue= printLocalConcept($lang, $row, $count); |
| 122 | + else $continue= printGlobalConcept($lang, $row, $count); |
| 123 | + |
| 124 | + if (!$continue) break; |
89 | 125 | } |
90 | 126 | |
91 | 127 | mysql_free_result($result); |
92 | 128 | ?> |
93 | | - </ul> |
| 129 | + </table> |
94 | 130 | |
95 | 131 | <p>Found <?php print $count; ?> items.</p> |
96 | 132 | |
— | — | @@ -97,7 +133,7 @@ |
98 | 134 | } |
99 | 135 | ?> |
100 | 136 | </body> |
101 | | - |
| 137 | +</html> |
102 | 138 | <?php |
103 | | -mysql_close($db); |
| 139 | +$utils->close(); |
104 | 140 | ?> |
\ No newline at end of file |