Index: trunk/extensions/FreqPatternTagCloud/FreqPatternTagCloud.body.php |
— | — | @@ -16,6 +16,8 @@ |
17 | 17 | |
18 | 18 | const ATTRIBUTE_VALUE_INDEX_SPECIALPAGE = "SearchByProperty"; |
19 | 19 | |
| 20 | + const CATEGORY_PAGE = "Category"; |
| 21 | + |
20 | 22 | /** |
21 | 23 | * Maximum font size of tags in px |
22 | 24 | * |
— | — | @@ -82,7 +84,6 @@ |
83 | 85 | $this->printSearchResult($par); |
84 | 86 | } |
85 | 87 | $this->printTagCloud($par); |
86 | | - |
87 | 88 | } |
88 | 89 | |
89 | 90 | /** |
— | — | @@ -94,23 +95,20 @@ |
95 | 96 | public static function getAttributeSuggestions($currentAttributeValue) { |
96 | 97 | $dbr =& wfGetDB( DB_SLAVE ); |
97 | 98 | |
98 | | - if (!($res = mysql_query("SELECT smw_title |
99 | | - FROM ".$dbr->tableName("smw_ids")." |
100 | | - WHERE smw_namespace = 102 |
101 | | - AND LENGTH(smw_iw) = 0 |
102 | | - AND smw_title LIKE '%".mysql_real_escape_string($currentAttributeValue)."%' |
103 | | - ORDER BY smw_title |
104 | | - LIMIT 20"))) { |
105 | | - return "[]"; |
106 | | - } |
| 99 | + $res = $dbr->select("smw_ids", "smw_title", "smw_namespace = 102 AND LENGTH(smw_iw) = 0 AND smw_title LIKE '%".mysql_real_escape_string($currentAttributeValue)."%'", __METHOD__, array("ORDER BY" => "smw_title", "LIMIT" => 20)); |
107 | 100 | |
108 | 101 | $attributes = array(); |
109 | | - while ($row = mysql_fetch_assoc($res)) { |
| 102 | + while ($row = $res->fetchRow()) { |
110 | 103 | $attributes[] = sprintf('"%s"', addcslashes($row['smw_title'], '"')); |
111 | 104 | } |
112 | 105 | |
113 | | - mysql_free_result($res); |
| 106 | + // Category |
| 107 | + if (strpos(wfMsg("categoryname"), $currentAttributeValue) !== false) { |
| 108 | + $attributes[] = sprintf('"%s"', wfMsg("categoryname")); |
| 109 | + } |
114 | 110 | |
| 111 | + $res->free(); |
| 112 | + |
115 | 113 | return sprintf("[%s]", implode(", ", $attributes)); |
116 | 114 | } |
117 | 115 | |
— | — | @@ -124,7 +122,7 @@ |
125 | 123 | $dbr =& wfGetDB( DB_SLAVE ); |
126 | 124 | |
127 | 125 | // Get possible attribute values |
128 | | - if (!($res = mysql_query("SELECT DISTINCT vals.smw_title AS val, atts.smw_title AS att |
| 126 | + $res = $dbr->query("(SELECT DISTINCT vals.smw_title AS val, atts.smw_title AS att |
129 | 127 | FROM ".$dbr->tableName("smw_ids")." vals, ".$dbr->tableName("smw_ids")." atts, ".$dbr->tableName("smw_rels2")." rels |
130 | 128 | WHERE vals.smw_id = rels.o_id |
131 | 129 | AND atts.smw_id = rels.p_id |
— | — | @@ -134,12 +132,17 @@ |
135 | 133 | AND LENGTH(atts.smw_iw) = 0 |
136 | 134 | AND vals.smw_title LIKE '%".mysql_real_escape_string($currentSearchValue)."%' |
137 | 135 | ORDER BY vals.smw_title |
138 | | - LIMIT 20"))) { |
139 | | - return "[]"; |
140 | | - } |
| 136 | + LIMIT 20) UNION ( |
| 137 | + SELECT smw_title AS val, '".wfMsg("categoryname")."' AS att |
| 138 | + FROM ".$dbr->tableName("smw_ids")." |
| 139 | + WHERE smw_title LIKE '%".mysql_real_escape_string($currentSearchValue)."%' |
| 140 | + AND smw_namespace = 14 |
| 141 | + ORDER BY smw_title |
| 142 | + LIMIT 10 |
| 143 | + )"); |
141 | 144 | |
142 | 145 | $suggestions = array(); |
143 | | - while ($row = mysql_fetch_assoc($res)) { |
| 146 | + while ($row = $res->fetchRow()) { |
144 | 147 | // Apply frequent pattern rules |
145 | 148 | $conclusions = FrequentPattern::getConclusions($row['att'], $row['val']); |
146 | 149 | |
— | — | @@ -147,12 +150,12 @@ |
148 | 151 | continue; |
149 | 152 | } else { |
150 | 153 | foreach ($conclusions as $conclusion) { |
151 | | - $suggestions[] = sprintf('{ "label": "%s", "category": "'.addcslashes(wfMsg("SearchSuggestionValue"), '"').'" }', addcslashes($conclusion, '"'), addcslashes($row['val'], '"')); |
| 154 | + $suggestions[] = sprintf('{ "label": "%s", "category": "'.addcslashes(wfMsg("searchSuggestionValue"), '"').'" }', addcslashes($conclusion, '"'), addcslashes($row['val'], '"')); |
152 | 155 | } |
153 | 156 | } |
154 | 157 | } |
155 | 158 | |
156 | | - mysql_free_result($res); |
| 159 | + $res->free(); |
157 | 160 | |
158 | 161 | return sprintf("[%s]", implode(", ", $suggestions)); |
159 | 162 | } |
— | — | @@ -193,11 +196,11 @@ |
194 | 197 | // Add input field |
195 | 198 | if ($wgUser->isAllowed("protect")) { |
196 | 199 | $refreshData = sprintf('<div id="fptc_refresh">%s</div>', |
197 | | - $wgOut->parseInline(sprintf('[[:%s:%s|%s]]', self::SPECIALPAGE_PREFIX, self::MAINTENANCE_SPECIALPAGE, wfMsg("RefreshFrequentPatterns")))); |
| 200 | + $wgOut->parseInline(sprintf('[[:%s:%s|%s]]', self::SPECIALPAGE_PREFIX, self::MAINTENANCE_SPECIALPAGE, wfMsg("refreshFrequentPatterns")))); |
198 | 201 | } else { |
199 | 202 | $refreshData = ""; |
200 | 203 | } |
201 | | - $wgOut->addHTML($refreshData.wfMsg("FormAttributeName").': <input type="text" name="fptc_attributeName" id="fptc_attributeName" value="'.$defaultAttribute.'"><input type="submit" value="'.wfMsg("FormSubmitButton").'" onClick="fptc_relocate();"> |
| 204 | + $wgOut->addHTML($refreshData.wfMsg("formAttributeName").': <input type="text" name="fptc_attributeName" id="fptc_attributeName" value="'.$defaultAttribute.'"><input type="submit" value="'.wfMsg("formSubmitButton").'" onClick="fptc_relocate();"> |
202 | 205 | '); |
203 | 206 | |
204 | 207 | $wgOut->addHTML("<br><br>"); |
— | — | @@ -218,10 +221,10 @@ |
219 | 222 | // Context menu |
220 | 223 | $wgOut->addHTML('<ul id="fptc_contextMenu" class="contextMenu"> |
221 | 224 | <li class="browse"> |
222 | | - <a href="#browse">'.wfMsg("ContextMenu_Browse").'</a> |
| 225 | + <a href="#browse">'.wfMsg("contextMenu_Browse").'</a> |
223 | 226 | </li> |
224 | 227 | <li class="suggestions separator"> |
225 | | - '.wfMsg("ContextMenu_SimilarTags").': |
| 228 | + '.wfMsg("contextMenu_SimilarTags").': |
226 | 229 | </li> |
227 | 230 | </ul>'); |
228 | 231 | |
— | — | @@ -234,7 +237,7 @@ |
235 | 238 | } catch (InvalidAttributeException $e) { |
236 | 239 | if ($attribute) { |
237 | 240 | // Attribute not found -> show error |
238 | | - $wgOut->addHTML('<span style="color:red; font-weight:bold;">'.wfMsg("InvalidAttribute").'</span>'); |
| 241 | + $wgOut->addHTML('<span style="color:red; font-weight:bold;">'.wfMsg("invalidAttribute").'</span>'); |
239 | 242 | } |
240 | 243 | } |
241 | 244 | } |
— | — | @@ -251,7 +254,9 @@ |
252 | 255 | |
253 | 256 | $wgOut->addHTML(sprintf('<div class="fptc_tag" style="font-size:%dpx;">%s</div>', |
254 | 257 | $this->fontSizeMin + ($this->fontSizeMax - $this->fontSizeMin) * $tag->getRate(), |
255 | | - $wgOut->parseInline(sprintf("[[:%s:%s/%s/%s|%s]]", self::SPECIALPAGE_PREFIX, self::ATTRIBUTE_VALUE_INDEX_SPECIALPAGE, $attribute, $tag->getValue(), $tag->getValue())))); |
| 258 | + $attribute == wfMsg("categoryname") |
| 259 | + ? $wgOut->parseInline(sprintf("[[:%s:%s|%s]]", self::CATEGORY_PAGE, $tag->getValue(), $tag->getValue())) |
| 260 | + : $wgOut->parseInline(sprintf("[[:%s:%s/%s/%s|%s]]", self::SPECIALPAGE_PREFIX, self::ATTRIBUTE_VALUE_INDEX_SPECIALPAGE, $attribute, $tag->getValue(), $tag->getValue())))); |
256 | 261 | } |
257 | 262 | |
258 | 263 | /** Prints the result of the search for attribute <code>attribute</code> to <code>$wgOut</code> |
— | — | @@ -274,7 +279,7 @@ |
275 | 280 | try { |
276 | 281 | // Only if suggestions found |
277 | 282 | if ($proposal->getProposal()) { |
278 | | - $wgOut->addHTML(wfMsg("Suggestion")); |
| 283 | + $wgOut->addHTML(wfMsg("suggestion")); |
279 | 284 | } |
280 | 285 | $w=1; |
281 | 286 | foreach ($proposal->getProposal() as $possibleAttribute) { |
— | — | @@ -287,7 +292,7 @@ |
288 | 293 | } |
289 | 294 | |
290 | 295 | } catch (InvalidAttributeException $e) { |
291 | | - $wgOut->addHTML(wfMsg("NoSuggestion")); |
| 296 | + $wgOut->addHTML(wfMsg("noSuggestion")); |
292 | 297 | } |
293 | 298 | if ($proposal->getProposal()) { |
294 | 299 | $wgOut->addHTML("<br><br>"); |
— | — | @@ -296,6 +301,4 @@ |
297 | 302 | } |
298 | 303 | } |
299 | 304 | } |
300 | | -} |
301 | | - |
302 | | -?> |
\ No newline at end of file |
| 305 | +} |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/FreqPatternTagCloud.i18n.php |
— | — | @@ -12,38 +12,39 @@ |
13 | 13 | $messages = array(); |
14 | 14 | |
15 | 15 | $messages['en'] = array( |
16 | | - "ContextMenu_Browse" => "Browse Pages With This Value", |
17 | | - "ContextMenu_SimilarTags" => "Similar Tags", |
18 | | - "FormAttributeName" => "Property", |
19 | | - "FormSubmitButton" => "Submit", |
| 16 | + "categoryname" => "Category", |
| 17 | + "contextMenu_Browse" => "Browse Pages With This Value", |
| 18 | + "contextMenu_SimilarTags" => "Similar Tags", |
| 19 | + "formAttributeName" => "Property", |
| 20 | + "formSubmitButton" => "Submit", |
20 | 21 | "freqpatterntagcloud" => "Frequent Pattern Tag Cloud", |
21 | 22 | "freqpatterntagcloudmaintenance" => "Frequent Pattern Tag Cloud Maintenance", |
22 | | - "InvalidAttribute" => "The entered property is invalid.", |
23 | | - "InsufficientRightsForMaintenance" => "You have to log in as system administrator to view this page.", |
24 | | - "RefreshFrequentPatterns" => "Refresh Data", |
25 | | - "RefreshedFrequentPatterns" => "Frequent pattern rules refreshed.", |
26 | | - "SearchAttributeName" => "Search property", |
27 | | - "SearchButton" => "Search", |
28 | | - "SearchSuggestionValue" => "Similar to \"%s\":", |
29 | | - "Suggestion" => "Do you mean: ", |
30 | | - "NoSuggestion" => "No suggestions found" |
| 23 | + "invalidAttribute" => "The entered property is invalid.", |
| 24 | + "insufficientRightsForMaintenance" => "You have to log in as system administrator to view this page.", |
| 25 | + "refreshFrequentPatterns" => "Refresh Data", |
| 26 | + "refreshedFrequentPatterns" => "Frequent pattern rules refreshed.", |
| 27 | + "searchAttributeName" => "Search property", |
| 28 | + "searchButton" => "Search", |
| 29 | + "searchSuggestionValue" => "Similar to \"%s\":", |
| 30 | + "suggestion" => "Do you mean: ", |
| 31 | + "noSuggestion" => "No suggestions found" |
31 | 32 | ); |
32 | 33 | |
33 | 34 | $messages['de'] = array( |
34 | | - "ContextMenu_Browse" => "Durchsuche Seiten mit diesem Wert", |
35 | | - "ContextMenu_SimilarTags" => "Ähnliche Tags", |
36 | | - "FormAttributeName" => "Attribut", |
37 | | - "FormSubmitButton" => "Eingabe", |
| 35 | + "categoryname" => "Kategorie", |
| 36 | + "contextMenu_Browse" => "Durchsuche Seiten mit diesem Wert", |
| 37 | + "contextMenu_SimilarTags" => "Ähnliche Tags", |
| 38 | + "formAttributeName" => "Attribut", |
| 39 | + "formSubmitButton" => "Eingabe", |
38 | 40 | "freqpatterntagcloud" => "Frequent Pattern Tag Cloud", |
39 | 41 | "freqpatterntagcloudmaintenance" => "Frequent Pattern Tag Cloud Maintenance", |
40 | | - "InvalidAttribute" => "Das eingegebene Attribut ist ungültig.", |
41 | | - "InsufficientRightsForMaintenance" => "Um diese Seite sehen zu können müssen Sie als Systemadministrator angemeldet sein.", |
42 | | - "RefreshFrequentPatterns" => "Aktualisierung der Daten", |
43 | | - "RefreshedFrequentPatterns" => "Regeln für frequent pattern neu generiert.", |
44 | | - "SearchAttributeName" => "Suche nach Attribut", |
45 | | - "SearchButton" => "Suche", |
46 | | - "SearchSuggestionValue" => "Ähnlich zu \"%s\":", |
47 | | - "Suggestion" => "Meinten Sie: ", |
48 | | - "NoSuggestion" => "Keine Vorschläge gefunden" |
49 | | - ); |
50 | | -?> |
\ No newline at end of file |
| 42 | + "invalidAttribute" => "Das eingegebene Attribut ist ungültig.", |
| 43 | + "insufficientRightsForMaintenance" => "Um diese Seite sehen zu können müssen Sie als Systemadministrator angemeldet sein.", |
| 44 | + "refreshFrequentPatterns" => "Aktualisierung der Daten", |
| 45 | + "refreshedFrequentPatterns" => "Regeln für frequent pattern neu generiert.", |
| 46 | + "searchAttributeName" => "Suche nach Attribut", |
| 47 | + "searchButton" => "Suche", |
| 48 | + "searchSuggestionValue" => "Ähnlich zu \"%s\":", |
| 49 | + "suggestion" => "Meinten Sie: ", |
| 50 | + "noSuggestion" => "Keine Vorschläge gefunden" |
| 51 | + ); |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/FreqPatternTagCloud.php |
— | — | @@ -39,12 +39,6 @@ |
40 | 40 | 'version' => '1.0' |
41 | 41 | ); |
42 | 42 | |
43 | | -// Register hook to create new database to store frequent pattern information |
44 | | -$wgHooks['LoadExtensionSchemaUpdates'][] = 'fptc_updateSchema'; |
45 | | - |
46 | | -// Register hook to initialize frequent pattern database |
47 | | -$wgHooks['LoadExtensionSchemaUpdates'][] = 'fptc_initializeRules'; |
48 | | - |
49 | 43 | // Register hook to prepare header files |
50 | 44 | $wgHooks['BeforePageDisplay'][] = 'fptc_initializeHeaders'; |
51 | 45 | |
— | — | @@ -66,19 +60,6 @@ |
67 | 61 | |
68 | 62 | |
69 | 63 | /** |
70 | | - * Initializes frequent pattern rules |
71 | | - * |
72 | | - * @return bool Success |
73 | | - */ |
74 | | -function fptc_initializeRules() { |
75 | | - FrequentPattern::deleteAllRules(); |
76 | | - FrequentPattern::computeAllRules(); |
77 | | - |
78 | | - return true; |
79 | | -} |
80 | | - |
81 | | - |
82 | | -/** |
83 | 64 | * Initializes page headers |
84 | 65 | * |
85 | 66 | * @return bool Success |
— | — | @@ -134,37 +115,4 @@ |
135 | 116 | $wgOut->addScript('<script type="text/javascript" src="'.$wgScriptPath.'/extensions/FreqPatternTagCloud/javascripts/main.js"></script>'); |
136 | 117 | |
137 | 118 | return true; |
138 | | -} |
139 | | - |
140 | | - |
141 | | -/** |
142 | | - * Creates database schema |
143 | | - * |
144 | | - * @return bool Success |
145 | | - */ |
146 | | -function fptc_updateSchema() { |
147 | | - $dbr =& wfGetDB( DB_SLAVE ); |
148 | | - |
149 | | - if (!(mysql_query("CREATE TABLE IF NOT EXISTS `".$dbr->tableName("fptc_associationrules")."` ( |
150 | | - `rule_id` int(11) NOT NULL auto_increment, |
151 | | - `p_id` int(8) NOT NULL COMMENT 'Attribute', |
152 | | - `rule_support` float(5,3) NOT NULL, |
153 | | - `rule_confidence` float(5,3) NOT NULL, |
154 | | - PRIMARY KEY (`rule_id`) |
155 | | - ); |
156 | | - ALTER TABLE `fptc_associationrules` ADD INDEX ( `p_id` );"))) { |
157 | | - throw new SQLException(); |
158 | | - } |
159 | | - if (!(mysql_query("CREATE TABLE IF NOT EXISTS `".$dbr->tableName("fptc_items")."` ( |
160 | | - `o_id` INT( 8 ) NOT NULL , |
161 | | - `rule_id` INT NOT NULL , |
162 | | - `item_order` TINYINT( 1 ) NOT NULL , |
163 | | - PRIMARY KEY ( `o_id` , `rule_id` ) |
164 | | - );"))) { |
165 | | - throw new SQLException(); |
166 | | - } |
167 | | - |
168 | | - return true; |
169 | | -} |
170 | | - |
171 | | -?> |
\ No newline at end of file |
| 119 | +} |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/includes/Tag.php |
— | — | @@ -77,5 +77,3 @@ |
78 | 78 | return $this->_value; |
79 | 79 | } |
80 | 80 | } |
81 | | - |
82 | | -?> |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/includes/exceptions/InvalidAttributeException.php |
— | — | @@ -21,5 +21,3 @@ |
22 | 22 | parent::__construct(sprintf("Attribute '%s' not found", $attribute ? $attribute : "<empty>")); |
23 | 23 | } |
24 | 24 | } |
25 | | - |
26 | | -?> |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/includes/exceptions/SQLException.php |
— | — | @@ -14,5 +14,3 @@ |
15 | 15 | parent::__construct(mysql_error()); |
16 | 16 | } |
17 | 17 | } |
18 | | - |
19 | | -?> |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/includes/computation/exceptions/InvalidItemCollectionException.php |
— | — | @@ -20,5 +20,3 @@ |
21 | 21 | parent::__construct("Item collection must not be empty."); |
22 | 22 | } |
23 | 23 | } |
24 | | - |
25 | | -?> |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/includes/computation/FrequentPatternApriori.php |
— | — | @@ -121,5 +121,3 @@ |
122 | 122 | return $candidates; |
123 | 123 | } |
124 | 124 | } |
125 | | - |
126 | | -?> |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/includes/computation/FrequentPatternAlgorithm.php |
— | — | @@ -140,5 +140,3 @@ |
141 | 141 | return $rules; |
142 | 142 | } |
143 | 143 | } |
144 | | - |
145 | | -?> |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/includes/computation/FrequentPatternRule.php |
— | — | @@ -110,5 +110,3 @@ |
111 | 111 | $this->_confidence = $confidence; |
112 | 112 | } |
113 | 113 | } |
114 | | - |
115 | | -?> |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/includes/computation/FrequentItemset.php |
— | — | @@ -66,5 +66,3 @@ |
67 | 67 | $this->_support = $support; |
68 | 68 | } |
69 | 69 | } |
70 | | - |
71 | | -?> |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/includes/Proposal.php |
— | — | @@ -8,17 +8,17 @@ |
9 | 9 | * @author Andreas Fay, University of Heidelberg |
10 | 10 | * @version 1.0 |
11 | 11 | */ |
12 | | - include_once("exceptions/InvalidAttributeException.php"); |
13 | | - |
14 | | - class Proposal { |
15 | | - |
16 | | - /** |
| 12 | +include_once("exceptions/InvalidAttributeException.php"); |
| 13 | + |
| 14 | +class Proposal { |
| 15 | + |
| 16 | + /** |
17 | 17 | * Attribute name for search |
18 | | - * |
| 18 | + * |
19 | 19 | * @var string |
20 | 20 | */ |
21 | 21 | private $_attribute; |
22 | | - |
| 22 | + |
23 | 23 | /** |
24 | 24 | * Constructor |
25 | 25 | * |
— | — | @@ -30,33 +30,35 @@ |
31 | 31 | $this->_attribute = $attribute; |
32 | 32 | } |
33 | 33 | |
34 | | - /** |
35 | | - * Gets the available proposals computed with wildcard % |
36 | | - * |
37 | | - * @return array Array of attributes |
38 | | - */ |
| 34 | + /** |
| 35 | + * Gets the available proposals computed with wildcard % |
| 36 | + * |
| 37 | + * @return array Array of attributes |
| 38 | + */ |
39 | 39 | public function getProposalWithWildcard() { |
40 | 40 | $dbr =& wfGetDB( DB_SLAVE ); |
41 | 41 | |
42 | 42 | $attribute = $this->getAttribute(); |
43 | 43 | |
44 | 44 | // Search with wildcard '%' |
45 | | - if (!($res = mysql_query("SELECT smw_id, smw_title |
46 | | - FROM ".$dbr->tableName("smw_ids")." |
47 | | - WHERE smw_namespace = 102 |
48 | | - AND LENGTH(smw_iw) = 0 |
49 | | - AND smw_title LIKE '%".mysql_real_escape_string($attribute)."%'"))) { |
50 | | - |
51 | | - throw new SQLException(); |
52 | | - } |
| 45 | + $res = $dbr->query("SELECT smw_id, smw_title |
| 46 | + FROM ".$dbr->tableName("smw_ids")." |
| 47 | + WHERE smw_namespace = 102 |
| 48 | + AND LENGTH(smw_iw) = 0 |
| 49 | + AND smw_title LIKE '%".mysql_real_escape_string($attribute)."%'"); |
53 | 50 | |
54 | 51 | $attributes = array(); |
55 | 52 | |
56 | | - while ($row = mysql_fetch_assoc($res)) { |
| 53 | + while ($row = $res->fetchRow()) { |
57 | 54 | $attributes[] = $row['smw_title']; |
58 | 55 | } |
59 | 56 | |
60 | | - mysql_free_result($res); |
| 57 | + // Category |
| 58 | + if (strpos(wfMsg("categoryname"), $attribute) !== false) { |
| 59 | + $attributes[] = sprintf("%s", wfMsg("categoryname")); |
| 60 | + } |
| 61 | + |
| 62 | + $res->free(); |
61 | 63 | return $attributes; |
62 | 64 | } |
63 | 65 | |
— | — | @@ -73,41 +75,45 @@ |
74 | 76 | $endAttribut = substr ($attribute,strlen($attribute)-2,strlen($attribute)); |
75 | 77 | |
76 | 78 | // Search with regexp for related attributes with the same beginning |
77 | | - if (!($res = mysql_query("SELECT smw_id, smw_title |
78 | | - FROM ".$dbr->tableName("smw_ids")." |
79 | | - WHERE smw_namespace = 102 |
80 | | - AND LENGTH(smw_iw) = 0 |
81 | | - AND smw_title REGEXP '^".$beginAttribut."'"))) { |
82 | | - |
83 | | - throw new SQLException(); |
84 | | - } |
| 79 | + $res = $dbr->query("SELECT smw_id, smw_title |
| 80 | + FROM ".$dbr->tableName("smw_ids")." |
| 81 | + WHERE smw_namespace = 102 |
| 82 | + AND LENGTH(smw_iw) = 0 |
| 83 | + AND smw_title REGEXP '^".$beginAttribut."'"); |
85 | 84 | |
86 | 85 | $attributes_1 = array(); |
87 | 86 | |
88 | | - while ($row = mysql_fetch_assoc($res)) { |
| 87 | + while ($row = $res->fetchRow()) { |
89 | 88 | $attributes_1[] = $row['smw_title']; |
90 | 89 | } |
91 | 90 | |
92 | | - // Search with regexp for related attributes with the same ending |
93 | | - if (!($res = mysql_query("SELECT smw_id, smw_title |
94 | | - FROM ".$dbr->tableName("smw_ids")." |
95 | | - WHERE smw_namespace = 102 |
96 | | - AND LENGTH(smw_iw) = 0 |
97 | | - AND smw_title REGEXP '".$endAttribut."$'"))) { |
98 | | - |
99 | | - throw new SQLException(); |
| 91 | + // Category |
| 92 | + if (strpos(wfMsg("categoryname"), $attribute) === 0) { |
| 93 | + $attributes_1[] = sprintf("%s", wfMsg("categoryname")); |
100 | 94 | } |
101 | 95 | |
| 96 | + // Search with regexp for related attributes with the same ending |
| 97 | + $res = $dbr->query("SELECT smw_id, smw_title |
| 98 | + FROM ".$dbr->tableName("smw_ids")." |
| 99 | + WHERE smw_namespace = 102 |
| 100 | + AND LENGTH(smw_iw) = 0 |
| 101 | + AND smw_title REGEXP '".$endAttribut."$'"); |
| 102 | + |
102 | 103 | $attributes_2 = array(); |
103 | 104 | |
104 | | - while ($row = mysql_fetch_assoc($res)) { |
| 105 | + while ($row = $res->fetchRow()) { |
105 | 106 | $attributes_2[] = $row['smw_title']; |
106 | 107 | } |
107 | 108 | |
| 109 | + // Category |
| 110 | + if (strpos(wfMsg("categoryname"), $attribute) === strlen(wfMsg("categoryname")) - strlen($attribute)) { |
| 111 | + $attributes_2[] = sprintf("%s", wfMsg("categoryname")); |
| 112 | + } |
| 113 | + |
108 | 114 | // Merge both arrays for one return |
109 | 115 | $attributes = array_merge($attributes_1, $attributes_2); |
110 | 116 | |
111 | | - mysql_free_result($res); |
| 117 | + $res->free(); |
112 | 118 | return $attributes; |
113 | 119 | } |
114 | 120 | |
— | — | @@ -129,25 +135,27 @@ |
130 | 136 | $endAttribut = substr ($attribute,strlen($attribute)-2,strlen($attribute)); |
131 | 137 | |
132 | 138 | // Search for related attributes and attributes with the same beginning or ending |
133 | | - if (!($res = mysql_query("SELECT DISTINCT smw_title |
134 | | - FROM ".$dbr->tableName("smw_ids")." |
135 | | - WHERE smw_namespace = 102 |
136 | | - AND LENGTH(smw_iw) = 0 |
137 | | - AND ((smw_title REGEXP '^".$beginAttribut."') |
138 | | - OR (smw_title REGEXP '".$endAttribut."$') |
139 | | - OR (smw_title LIKE '%".mysql_real_escape_string($attribute)."%')) |
140 | | - ORDER BY smw_title asc"))) { |
141 | | - |
142 | | - throw new SQLException(); |
143 | | - } |
| 139 | + $res = $dbr->query("SELECT DISTINCT smw_title |
| 140 | + FROM ".$dbr->tableName("smw_ids")." |
| 141 | + WHERE smw_namespace = 102 |
| 142 | + AND LENGTH(smw_iw) = 0 |
| 143 | + AND ((smw_title REGEXP '^".$beginAttribut."') |
| 144 | + OR (smw_title REGEXP '".$endAttribut."$') |
| 145 | + OR (smw_title LIKE '%".mysql_real_escape_string($attribute)."%')) |
| 146 | + ORDER BY smw_title asc"); |
144 | 147 | |
145 | 148 | $attributes = array(); |
146 | 149 | |
147 | | - while ($row = mysql_fetch_assoc($res)) { |
| 150 | + while ($row = $res->fetchRow()) { |
148 | 151 | $attributes[] = $row['smw_title']; |
149 | 152 | } |
150 | 153 | |
151 | | - mysql_free_result($res); |
| 154 | + // Category |
| 155 | + if (strpos(wfMsg("categoryname"), $beginAttribut) === 0 || strpos(wfMsg("categoryname"), $endAttribut) === strlen(wfMsg("categoryname")) - strlen($endAttribut) || strpos(wfMsg("categoryname"), $attribute) !== false) { |
| 156 | + $attributes[] = sprintf("%s", wfMsg("categoryname")); |
| 157 | + } |
| 158 | + |
| 159 | + $res->free(); |
152 | 160 | return $attributes; |
153 | 161 | } |
154 | 162 | |
— | — | @@ -161,4 +169,3 @@ |
162 | 170 | } |
163 | 171 | } |
164 | 172 | |
165 | | -?> |
Index: trunk/extensions/FreqPatternTagCloud/includes/TagCloud.php |
— | — | @@ -52,27 +52,30 @@ |
53 | 53 | * @return bool |
54 | 54 | */ |
55 | 55 | private function checkAttribute($attribute) { |
| 56 | + // Category |
| 57 | + if (wfMsg("categoryname") == $attribute) { |
| 58 | + return true; |
| 59 | + } |
| 60 | + |
56 | 61 | $dbr =& wfGetDB( DB_SLAVE ); |
57 | 62 | |
58 | | - if (!($res = mysql_query("SELECT smw_id |
59 | | - FROM ".$dbr->tableName("smw_ids")." |
60 | | - WHERE smw_namespace = 102 |
61 | | - AND LENGTH(smw_iw) = 0 |
62 | | - AND smw_title = '".mysql_real_escape_string($attribute)."'"))) { |
63 | | - throw new SQLException(); |
64 | | - } |
| 63 | + $res = $dbr->query("SELECT smw_id |
| 64 | + FROM ".$dbr->tableName("smw_ids")." |
| 65 | + WHERE smw_namespace = 102 |
| 66 | + AND LENGTH(smw_iw) = 0 |
| 67 | + AND smw_title = '".mysql_real_escape_string($attribute)."'"); |
65 | 68 | |
66 | | - if (mysql_num_rows($res) == 0) { |
| 69 | + if ($res->numRows() == 0) { |
67 | 70 | // Attribute not found |
68 | 71 | return false; |
69 | 72 | } |
70 | 73 | |
71 | | - $row = mysql_fetch_row($res); |
| 74 | + $row = $res->fetchRow(); |
72 | 75 | |
73 | 76 | // Assign id |
74 | 77 | $this->_attributeId = $row[0]; |
75 | 78 | |
76 | | - mysql_free_result($res); |
| 79 | + $res->free(); |
77 | 80 | |
78 | 81 | return true; |
79 | 82 | } |
— | — | @@ -87,15 +90,18 @@ |
88 | 91 | $dbr =& wfGetDB( DB_SLAVE ); |
89 | 92 | |
90 | 93 | // Get overall number of attribute values |
91 | | - if (!($res = mysql_query("SELECT COUNT(1) |
92 | | - FROM ".$dbr->tableName("smw_rels2")." |
93 | | - WHERE p_id = ".mysql_real_escape_string($this->_attributeId)))) { |
94 | | - throw new SQLException(); |
| 94 | + if (!$this->_attributeId) { |
| 95 | + $res = $dbr->query("SELECT SUM(cat_pages) |
| 96 | + FROM ".$dbr->tableName("category")); |
| 97 | + } else { |
| 98 | + $res = $dbr->query("SELECT COUNT(1) |
| 99 | + FROM ".$dbr->tableName("smw_rels2")." |
| 100 | + WHERE p_id = ".mysql_real_escape_string($this->_attributeId)); |
95 | 101 | } |
96 | 102 | |
97 | | - $row = mysql_fetch_row($res); |
| 103 | + $row = $res->fetchRow(); |
98 | 104 | $numValues = $row[0]; |
99 | | - mysql_free_result($res); |
| 105 | + $res->free(); |
100 | 106 | |
101 | 107 | if ($numValues == 0) { |
102 | 108 | // Abort because no tags available |
— | — | @@ -103,26 +109,30 @@ |
104 | 110 | } |
105 | 111 | |
106 | 112 | // Get tags |
107 | | - if (!($res = mysql_query("SELECT smw_id, smw_title, (SELECT COUNT(1) FROM ".$dbr->tableName("smw_rels2")." WHERE o_id = smw_id AND p_id = ".mysql_real_escape_string($this->_attributeId).")/$numValues AS rate |
108 | | - FROM ".$dbr->tableName("smw_ids")." |
109 | | - WHERE smw_namespace = 0 |
110 | | - AND LENGTH(smw_iw) = 0 |
111 | | - AND smw_id <> ".mysql_real_escape_string($this->_attributeId)." |
112 | | - ORDER BY smw_title"))) { |
113 | | - throw new SQLException(); |
| 113 | + if (!$this->_attributeId) { |
| 114 | + $res = $dbr->query("SELECT smw_id, smw_title, (SELECT cat_pages FROM ".$dbr->tableName("category")." WHERE cat_title = smw_title)/$numValues AS rate |
| 115 | + FROM ".$dbr->tableName("smw_ids")." |
| 116 | + WHERE smw_namespace = 14 |
| 117 | + AND LENGTH(smw_iw) = 0 |
| 118 | + ORDER BY smw_title"); |
| 119 | + } else { |
| 120 | + $res = $dbr->query("SELECT smw_id, smw_title, (SELECT COUNT(1) FROM ".$dbr->tableName("smw_rels2")." WHERE o_id = smw_id AND p_id = ".mysql_real_escape_string($this->_attributeId).")/$numValues AS rate |
| 121 | + FROM ".$dbr->tableName("smw_ids")." |
| 122 | + WHERE smw_namespace = 0 |
| 123 | + AND LENGTH(smw_iw) = 0 |
| 124 | + AND smw_id <> ".mysql_real_escape_string($this->_attributeId)." |
| 125 | + ORDER BY smw_title"); |
114 | 126 | } |
115 | 127 | |
116 | 128 | $tags = array(); |
117 | | - while ($row = mysql_fetch_assoc($res)) { |
| 129 | + while ($row = $res->fetchRow()) { |
118 | 130 | if (floatval($row['rate']) > 0) { |
119 | 131 | // Only consider relevant tags (because query also fetches tags that do not belong to desired attribute |
120 | 132 | $tags[] = new Tag(intval($row['smw_id']), $row['smw_title'], floatval($row['rate'])); |
121 | 133 | } |
122 | 134 | } |
123 | | - mysql_free_result($res); |
| 135 | + $res->free(); |
124 | 136 | |
125 | 137 | return $tags; |
126 | 138 | } |
127 | | -} |
128 | | - |
129 | | -?> |
\ No newline at end of file |
| 139 | +} |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/includes/Search.php |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | * @var string |
19 | 19 | */ |
20 | 20 | private $_attribute; |
21 | | - |
| 21 | + |
22 | 22 | /** |
23 | 23 | * Constructor |
24 | 24 | * |
— | — | @@ -31,7 +31,7 @@ |
32 | 32 | throw new InvalidAttributeException($attribute); |
33 | 33 | } |
34 | 34 | } |
35 | | - |
| 35 | + |
36 | 36 | /** |
37 | 37 | * Checks whether attribute is correct, i.e. it exists in database; if yes it fetches the name of the attribute |
38 | 38 | * |
— | — | @@ -39,30 +39,33 @@ |
40 | 40 | * @return bool |
41 | 41 | */ |
42 | 42 | private function attributeAvailable($attribute) { |
| 43 | + // Category |
| 44 | + if (wfMsg("categoryname") == $attribute) { |
| 45 | + return true; |
| 46 | + } |
| 47 | + |
43 | 48 | $dbr = & wfGetDB(DB_SLAVE); |
44 | | - |
45 | | - if (!($res = mysql_query("SELECT smw_title |
46 | | - FROM " . $dbr->tableName("smw_ids") . " |
47 | | - WHERE smw_namespace = 102 |
48 | | - AND LENGTH(smw_iw) = 0 |
49 | | - AND smw_title = '" . mysql_real_escape_string($attribute) . "'"))) { |
50 | | - throw new SQLException(); |
51 | | - } |
52 | | - |
53 | | - if (mysql_num_rows($res) == 0) { |
| 49 | + |
| 50 | + $res = $dbr->query("SELECT smw_title |
| 51 | + FROM " . $dbr->tableName("smw_ids") . " |
| 52 | + WHERE smw_namespace = 102 |
| 53 | + AND LENGTH(smw_iw) = 0 |
| 54 | + AND smw_title = '" . mysql_real_escape_string($attribute) . "'"); |
| 55 | + |
| 56 | + if ($res->numRows() == 0) { |
54 | 57 | // Attribute not found |
55 | 58 | return false; |
56 | 59 | } |
57 | | - |
58 | | - $row = mysql_fetch_row($res); |
59 | | - |
| 60 | + |
| 61 | + $row = $res->fetchRow(); |
| 62 | + |
60 | 63 | // Assign name |
61 | 64 | $this->_attribute = $row[0]; |
62 | | - |
63 | | - mysql_free_result($res); |
| 65 | + |
| 66 | + $res->free(); |
64 | 67 | return true; |
65 | 68 | } |
66 | | - |
| 69 | + |
67 | 70 | /** |
68 | 71 | * Gets the available Attribute |
69 | 72 | * |
— | — | @@ -72,4 +75,3 @@ |
73 | 76 | return $this->_attribute; |
74 | 77 | } |
75 | 78 | } |
76 | | -?> |
Index: trunk/extensions/FreqPatternTagCloud/includes/FrequentPattern.php |
— | — | @@ -18,14 +18,14 @@ |
19 | 19 | * |
20 | 20 | * @var float |
21 | 21 | */ |
22 | | - public static $min_confidence = 0.3; |
| 22 | + public static $min_confidence = 0.1; |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Minimum support |
26 | 26 | * |
27 | 27 | * @var float |
28 | 28 | */ |
29 | | - public static $min_support = 0.2; |
| 29 | + public static $min_support = 0.05; |
30 | 30 | |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -37,17 +37,15 @@ |
38 | 38 | public static function computeAllRules() { |
39 | 39 | $dbr =& wfGetDB( DB_SLAVE ); |
40 | 40 | |
41 | | - if (!($res = mysql_query("SELECT smw_id |
42 | | - FROM ".$dbr->tableName("smw_ids")." |
43 | | - WHERE smw_namespace = 102 |
44 | | - AND LENGTH(smw_iw) = 0"))) { |
45 | | - throw new SQLException(); |
46 | | - } |
47 | | - while ($row = mysql_fetch_assoc($res)) { |
| 41 | + $res = $dbr->query("(SELECT smw_id |
| 42 | + FROM ".$dbr->tableName("smw_ids")." |
| 43 | + WHERE smw_namespace = 102 |
| 44 | + AND LENGTH(smw_iw) = 0) UNION (SELECT 0)"); |
| 45 | + while ($row = $res->fetchRow()) { |
48 | 46 | self::computeRules($row['smw_id']); |
49 | 47 | } |
50 | 48 | |
51 | | - mysql_free_result($res); |
| 49 | + $res->free(); |
52 | 50 | } |
53 | 51 | |
54 | 52 | /** |
— | — | @@ -69,56 +67,65 @@ |
70 | 68 | } |
71 | 69 | |
72 | 70 | $dbr =& wfGetDB( DB_SLAVE ); |
| 71 | + $dbw =& wfGetDB( DB_MASTER ); |
73 | 72 | |
74 | 73 | // Compile items = all possible o_ids |
75 | | - if (!($res = mysql_query("SELECT GROUP_CONCAT(DISTINCT o_id) |
76 | | - FROM ".$dbr->tableName("smw_rels2")." |
77 | | - WHERE p_id = ".mysql_real_escape_string($attributeId)." |
78 | | - GROUP BY p_id"))) { |
79 | | - throw new SQLException(); |
| 74 | + if (!$attributeId) { |
| 75 | + $res = $dbr->query("SELECT GROUP_CONCAT(smw_id) |
| 76 | + FROM ".$dbr->tableName("smw_ids")." |
| 77 | + WHERE smw_namespace = 14 |
| 78 | + AND LENGTH(smw_iw) = 0 |
| 79 | + GROUP BY smw_namespace"); |
| 80 | + } else { |
| 81 | + $res = $dbr->query("SELECT GROUP_CONCAT(DISTINCT o_id) |
| 82 | + FROM ".$dbr->tableName("smw_rels2")." |
| 83 | + WHERE p_id = ".mysql_real_escape_string($attributeId)." |
| 84 | + GROUP BY p_id"); |
80 | 85 | } |
81 | | - $row = mysql_fetch_row($res); |
| 86 | + $row = $res->fetchRow(); |
82 | 87 | $items = explode(",", $row[0]); |
83 | | - mysql_free_result($res); |
| 88 | + $res->free(); |
84 | 89 | |
85 | 90 | // Compile transactions = all corelated o_ids (by s_id) |
86 | | - if (!($res = mysql_query("SELECT GROUP_CONCAT(o_id) |
87 | | - FROM ".$dbr->tableName("smw_rels2")." |
88 | | - WHERE p_id = ".mysql_real_escape_string($attributeId)." |
89 | | - GROUP BY s_id"))) { |
90 | | - throw new SQLException(); |
| 91 | + if (!$attributeId) { |
| 92 | + $res = $dbr->query("SELECT GROUP_CONCAT(smw_id) |
| 93 | + FROM ".$dbr->tableName("smw_ids")." ids, ".$dbr->tableName("categorylinks")." catlinks |
| 94 | + WHERE ids.smw_title = catlinks.cl_to |
| 95 | + AND ids.smw_namespace = 14 |
| 96 | + GROUP BY catlinks.cl_from"); |
| 97 | + } else { |
| 98 | + $res = $dbr->query("SELECT GROUP_CONCAT(o_id) |
| 99 | + FROM ".$dbr->tableName("smw_rels2")." |
| 100 | + WHERE p_id = ".mysql_real_escape_string($attributeId)." |
| 101 | + GROUP BY s_id"); |
91 | 102 | } |
92 | 103 | $transactions = array(); |
93 | | - while ($row = mysql_fetch_row($res)) { |
| 104 | + while ($row = $res->fetchRow()) { |
94 | 105 | $transactions[] = explode(",", $row[0]); |
95 | 106 | } |
96 | | - mysql_free_result($res); |
| 107 | + $res->free(); |
97 | 108 | |
98 | 109 | // Run algorithm |
99 | 110 | $algorithm = new FrequentPatternApriori(); |
100 | 111 | $rules = $algorithm->computeRules($items, $transactions, self::$min_support, self::$min_confidence); |
101 | 112 | foreach ($rules as $rule) { |
102 | 113 | // Push rules to db |
103 | | - if (!mysql_query("INSERT INTO ".$dbr->tableName("fptc_associationrules")." (p_id, rule_support, rule_confidence) |
104 | | - VALUES (".mysql_real_escape_string($attributeId).", ".mysql_real_escape_string($rule->getSupport()).", ".mysql_real_escape_string($rule->getConfidence()).")")) { |
105 | | - throw new SQLException(); |
106 | | - } |
107 | | - $ruleId = mysql_insert_id(); |
| 114 | + $dbw->query("INSERT INTO ".$dbw->tableName("fptc_associationrules")." (p_id, rule_support, rule_confidence) |
| 115 | + VALUES (".mysql_real_escape_string($attributeId).", ".mysql_real_escape_string($rule->getSupport()).", ".mysql_real_escape_string($rule->getConfidence()).")"); |
| 116 | + $ruleId = $dbw->insertId(); |
108 | 117 | |
109 | 118 | foreach ($rule->getAssumption() as $item) { |
110 | | - if (!mysql_query("INSERT INTO ".$dbr->tableName("fptc_items")." (o_id, rule_id, item_order) |
111 | | - VALUES (".mysql_real_escape_string($item).", ".mysql_real_escape_string($ruleId).", 0)")) { |
112 | | - throw new SQLException(); |
113 | | - } |
| 119 | + $dbw->query("INSERT INTO ".$dbw->tableName("fptc_items")." (o_id, rule_id, item_order) |
| 120 | + VALUES (".mysql_real_escape_string($item).", ".mysql_real_escape_string($ruleId).", 0)"); |
114 | 121 | } |
115 | 122 | |
116 | 123 | foreach ($rule->getConclusion() as $item) { |
117 | | - if (!mysql_query("INSERT INTO ".$dbr->tableName("fptc_items")." (o_id, rule_id, item_order) |
118 | | - VALUES (".mysql_real_escape_string($item).", ".mysql_real_escape_string($ruleId).", 1)")) { |
119 | | - throw new SQLException(); |
120 | | - } |
| 124 | + $dbw->query("INSERT INTO ".$dbw->tableName("fptc_items")." (o_id, rule_id, item_order) |
| 125 | + VALUES (".mysql_real_escape_string($item).", ".mysql_real_escape_string($ruleId).", 1)"); |
121 | 126 | } |
122 | 127 | } |
| 128 | + |
| 129 | + $dbw->commit(); |
123 | 130 | } |
124 | 131 | |
125 | 132 | /** |
— | — | @@ -128,11 +135,10 @@ |
129 | 136 | * @throws SQLException |
130 | 137 | */ |
131 | 138 | public static function deleteAllRules() { |
132 | | - $dbr =& wfGetDB( DB_SLAVE ); |
| 139 | + $dbw =& wfGetDB( DB_MASTER ); |
133 | 140 | |
134 | | - if (!mysql_query("DELETE FROM ".$dbr->tableName("fptc_associationrules"))) { |
135 | | - throw new SQLException(); |
136 | | - } |
| 141 | + $dbw->query("DELETE FROM ".$dbw->tableName("fptc_associationrules")); |
| 142 | + $dbw->query("DELETE FROM ".$dbw->tableName("fptc_items")); |
137 | 143 | } |
138 | 144 | |
139 | 145 | /** |
— | — | @@ -147,60 +153,64 @@ |
148 | 154 | $dbr =& wfGetDB( DB_SLAVE ); |
149 | 155 | |
150 | 156 | // Get id of attribute |
151 | | - if (!($res = mysql_query("SELECT smw_id |
152 | | - FROM ".$dbr->tableName("smw_ids")." |
153 | | - WHERE smw_title = '".mysql_real_escape_string($attribute)."' |
154 | | - AND smw_namespace = 102 |
155 | | - AND LENGTH(smw_iw) = 0"))) { |
156 | | - throw new SQLException(); |
| 157 | + if (wfMsg("categoryname") == $attribute) { |
| 158 | + $res = $dbr->query("SELECT 0"); |
| 159 | + } else { |
| 160 | + $res = $dbr->query("SELECT smw_id |
| 161 | + FROM ".$dbr->tableName("smw_ids")." |
| 162 | + WHERE smw_title = '".mysql_real_escape_string($attribute)."' |
| 163 | + AND smw_namespace = 102 |
| 164 | + AND LENGTH(smw_iw) = 0"); |
157 | 165 | } |
158 | | - $row = mysql_fetch_row($res); |
| 166 | + $row = $res->fetchRow(); |
159 | 167 | $attributeId = $row[0]; |
160 | | - mysql_free_result($res); |
| 168 | + $res->free(); |
161 | 169 | |
162 | 170 | // Get id of assumption |
163 | | - if (!($res = mysql_query("SELECT smw_id |
164 | | - FROM ".$dbr->tableName("smw_ids")." |
165 | | - WHERE smw_title = '".mysql_real_escape_string($assumption)."' |
166 | | - AND smw_namespace = 0 |
167 | | - AND LENGTH(smw_iw) = 0"))) { |
168 | | - throw new SQLException(); |
169 | | - } |
170 | | - $row = mysql_fetch_row($res); |
| 171 | + if (wfMsg("categoryname") == $attribute) { |
| 172 | + $res = $dbr->query("SELECT smw_id |
| 173 | + FROM ".$dbr->tableName("smw_ids")." |
| 174 | + WHERE smw_title = '".mysql_real_escape_string($assumption)."' |
| 175 | + AND smw_namespace = 14 |
| 176 | + AND LENGTH(smw_iw) = 0"); |
| 177 | + } else { |
| 178 | + $res = $dbr->query("SELECT smw_id |
| 179 | + FROM ".$dbr->tableName("smw_ids")." |
| 180 | + WHERE smw_title = '".mysql_real_escape_string($assumption)."' |
| 181 | + AND smw_namespace = 0 |
| 182 | + AND LENGTH(smw_iw) = 0"); |
| 183 | + } |
| 184 | + $row = $res->fetchRow(); |
171 | 185 | $assumptionId = $row[0]; |
172 | | - mysql_free_result($res); |
| 186 | + $res->free(); |
173 | 187 | |
174 | 188 | // Get rules (only those where assumption is single item) |
175 | | - if (!($res = mysql_query("SELECT rules.rule_id, rule_support, rule_confidence |
176 | | - FROM ".$dbr->tableName("fptc_associationrules")." rules, ".$dbr->tableName("fptc_items")." items |
177 | | - WHERE rules.rule_id = items.rule_id |
178 | | - AND item_order = 0 |
179 | | - AND o_id = ".mysql_real_escape_string($assumptionId)." |
180 | | - AND NOT EXISTS( SELECT 1 FROM ".$dbr->tableName("fptc_items")." WHERE rule_id = rules.rule_id AND item_order = 0 AND o_id != items.o_id ) |
181 | | - ORDER BY rule_support DESC, rule_confidence DESC"))) { |
182 | | - throw new SQLException(); |
183 | | - } |
| 189 | + $res = $dbr->query("SELECT rules.rule_id, rule_support, rule_confidence |
| 190 | + FROM ".$dbr->tableName("fptc_associationrules")." rules, ".$dbr->tableName("fptc_items")." items |
| 191 | + WHERE rules.rule_id = items.rule_id |
| 192 | + AND item_order = 0 |
| 193 | + AND o_id = ".mysql_real_escape_string($assumptionId)." |
| 194 | + AND NOT EXISTS( SELECT 1 FROM ".$dbr->tableName("fptc_items")." WHERE rule_id = rules.rule_id AND item_order = 0 AND o_id != items.o_id ) |
| 195 | + ORDER BY rule_support DESC, rule_confidence DESC"); |
184 | 196 | $conclusions = array(); |
185 | | - while ($row = mysql_fetch_assoc($res)) { |
| 197 | + while ($row = $res->fetchRow()) { |
186 | 198 | // Get conclusions |
187 | | - if (!($resItems = mysql_query("SELECT smw_title |
188 | | - FROM ".$dbr->tableName("smw_ids")." ids, ".$dbr->tableName("fptc_items")." items |
189 | | - WHERE ids.smw_id = items.o_id |
190 | | - AND item_order = 1 |
191 | | - AND rule_id = ".mysql_real_escape_string($row['rule_id'])))) { |
192 | | - throw new SQLException(); |
193 | | - } |
| 199 | + $resItems = $dbr->query("SELECT smw_title |
| 200 | + FROM ".$dbr->tableName("smw_ids")." ids, ".$dbr->tableName("fptc_items")." items |
| 201 | + WHERE ids.smw_id = items.o_id |
| 202 | + AND item_order = 1 |
| 203 | + AND rule_id = ".mysql_real_escape_string($row['rule_id'])); |
194 | 204 | |
195 | 205 | // Only consider rules with single conclusion |
196 | | - if (mysql_num_rows($resItems) > 1) { |
| 206 | + if ($resItems->numRows() > 1) { |
197 | 207 | continue; |
198 | 208 | } |
199 | | - $rowItem = mysql_fetch_assoc($resItems); |
| 209 | + $rowItem = $resItems->fetchRow(); |
200 | 210 | $conclusions[] = $rowItem['smw_title']; |
201 | | - |
202 | | - mysql_free_result($resItems); |
| 211 | + |
| 212 | + $resItems->free(); |
203 | 213 | } |
204 | | - mysql_free_result($res); |
| 214 | + $res->free(); |
205 | 215 | |
206 | 216 | return $conclusions; |
207 | 217 | } |
— | — | @@ -217,22 +227,18 @@ |
218 | 228 | $dbr =& wfGetDB( DB_SLAVE ); |
219 | 229 | |
220 | 230 | // Get rules |
221 | | - if (!($res = mysql_query("SELECT smw_title, rule_id, rule_support, rule_confidence |
222 | | - FROM ".$dbr->tableName("smw_ids")." ids, ".$dbr->tableName("fptc_associationrules")." rules |
223 | | - WHERE ids.smw_id = rules.p_id"))) { |
224 | | - throw new SQLException(); |
225 | | - } |
226 | | - while ($row = mysql_fetch_assoc($res)) { |
| 231 | + $res = $dbr->query("SELECT smw_title, rule_id, rule_support, rule_confidence |
| 232 | + FROM ".$dbr->tableName("smw_ids")." ids, ".$dbr->tableName("fptc_associationrules")." rules |
| 233 | + WHERE ids.smw_id = rules.p_id"); |
| 234 | + while ($row = $res->fetchRow()) { |
227 | 235 | // Get items |
228 | | - if (!($resItems = mysql_query("SELECT smw_title, item_order |
229 | | - FROM ".$dbr->tableName("smw_ids")." ids, ".$dbr->tableName("fptc_items")." items |
230 | | - WHERE ids.smw_id = items.o_id |
231 | | - AND rule_id = ".mysql_real_escape_string($row['rule_id'])))) { |
232 | | - throw new SQLException(); |
233 | | - } |
| 236 | + $resItems = $dbr->query("SELECT smw_title, item_order |
| 237 | + FROM ".$dbr->tableName("smw_ids")." ids, ".$dbr->tableName("fptc_items")." items |
| 238 | + WHERE ids.smw_id = items.o_id |
| 239 | + AND rule_id = ".mysql_real_escape_string($row['rule_id'])); |
234 | 240 | $assumption = array(); |
235 | 241 | $conclusion = array(); |
236 | | - while ($rowItem = mysql_fetch_assoc($resItems)) { |
| 242 | + while ($rowItem = $resItems->fetchRow()) { |
237 | 243 | if ($rowItem['item_order'] == '0') { |
238 | 244 | $assumption[] = $rowItem['smw_title']; |
239 | 245 | } else { |
— | — | @@ -243,8 +249,6 @@ |
244 | 250 | // Display rule |
245 | 251 | $wgOut->addWikiText(sprintf("%s: '%s' => '%s' (Sup: %0.2f, Conf: %0.2f)\n", $row['smw_title'], implode(",", $assumption), implode(",", $conclusion), $row['rule_support'], $row['rule_confidence'])); |
246 | 252 | } |
247 | | - mysql_free_result($res); |
| 253 | + $res->free(); |
248 | 254 | } |
249 | | -} |
250 | | - |
251 | | -?> |
\ No newline at end of file |
| 255 | +} |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/FreqPatternTagCloudMaintenance.php |
— | — | @@ -29,13 +29,22 @@ |
30 | 30 | */ |
31 | 31 | public function execute($par) { |
32 | 32 | global $wgOut, $wgUser; |
| 33 | + $dbr =& wfGetDB( DB_SLAVE ); |
33 | 34 | |
34 | 35 | $this->setHeaders(); |
35 | 36 | |
36 | 37 | if (!$wgUser->isAllowed("protect")) { |
37 | 38 | // No admin |
38 | | - $wgOut->addWikiText(wfMsg("InsufficientRightsForMaintenance")); |
| 39 | + $wgOut->addWikiText(wfMsg("insufficientRightsForMaintenance")); |
39 | 40 | } else { |
| 41 | + // Check if this call is the first |
| 42 | + try { |
| 43 | + $dbr->query("SELECT COUNT(1) FROM ".$dbr->tableName("fptc_associationrules")); |
| 44 | + } catch (exception $e) { |
| 45 | + // Yes: create database tables |
| 46 | + $this->initSchema(); |
| 47 | + } |
| 48 | + |
40 | 49 | // Refresh frequent pattern rules |
41 | 50 | include_once("includes/FrequentPattern.php"); |
42 | 51 | |
— | — | @@ -43,9 +52,34 @@ |
44 | 53 | FrequentPattern::computeAllRules(); |
45 | 54 | |
46 | 55 | // Notify user |
47 | | - $wgOut->addWikiText(wfMsg("RefreshedFrequentPatterns")); |
| 56 | + $wgOut->addWikiText(wfMsg("refreshedFrequentPatterns")); |
48 | 57 | } |
49 | 58 | } |
50 | | -} |
51 | | - |
52 | | -?> |
\ No newline at end of file |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + /** |
| 64 | + * Creates database schema |
| 65 | + * |
| 66 | + * @return void |
| 67 | + */ |
| 68 | + private function initSchema() { |
| 69 | + $dbw =& wfGetDB( DB_MASTER ); |
| 70 | + |
| 71 | + $dbw->query("CREATE TABLE IF NOT EXISTS ".$dbw->tableName("fptc_associationrules")." ( |
| 72 | + `rule_id` int(11) NOT NULL auto_increment, |
| 73 | + `p_id` int(8) NOT NULL COMMENT 'Attribute', |
| 74 | + `rule_support` float(5,3) NOT NULL, |
| 75 | + `rule_confidence` float(5,3) NOT NULL, |
| 76 | + PRIMARY KEY (`rule_id`) |
| 77 | + )"); |
| 78 | + $dbw->query("ALTER TABLE ".$dbw->tableName("fptc_associationrules")." ADD INDEX ( `p_id` );"); |
| 79 | + $dbw->query("CREATE TABLE IF NOT EXISTS ".$dbw->tableName("fptc_items")." ( |
| 80 | + `o_id` INT( 8 ) NOT NULL , |
| 81 | + `rule_id` INT NOT NULL , |
| 82 | + `item_order` TINYINT( 1 ) NOT NULL , |
| 83 | + PRIMARY KEY ( `o_id` , `rule_id` ) |
| 84 | + );"); |
| 85 | + } |
| 86 | +} |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/javascripts/main.js |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | if (action == "browse") { |
49 | 49 | window.location = el.attr("href"); |
50 | 50 | } else if (action == "browse_similar_tag") { |
51 | | - window.location = el.attr("href").replace(new RegExp(el.text()), menu.attr("title")); |
| 51 | + window.location = el.attr("href").replace(new RegExp(encodeURI(el.text())), menu.attr("title")); |
52 | 52 | } |
53 | 53 | }); |
54 | 54 | |