Index: trunk/extensions/FreqPatternTagCloud/FreqPatternTagCloudMaintenance.php |
— | — | @@ -1,85 +1,45 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | 4 | * Frequent Pattern Tag Cloud Plug-in |
6 | 5 | * Special page for maintenance |
7 | | - * |
| 6 | + * |
8 | 7 | * @author Tobias Beck, University of Heidelberg |
9 | 8 | * @author Andreas Fay, University of Heidelberg |
10 | 9 | * @version 1.0 |
11 | 10 | */ |
12 | 11 | |
13 | 12 | class FreqPatternTagCloudMaintenance extends SpecialPage { |
14 | | - |
| 13 | + |
15 | 14 | /** |
16 | | - * Constructor |
17 | | - * |
18 | | - * @return void |
| 15 | + * Constructor -- set up the new special page |
19 | 16 | */ |
20 | 17 | public function __construct() { |
21 | | - parent::__construct("FreqPatternTagCloudMaintenance"); |
| 18 | + parent::__construct( 'FreqPatternTagCloudMaintenance' ); |
22 | 19 | } |
23 | | - |
24 | | - |
| 20 | + |
25 | 21 | /** |
26 | 22 | * Executes special page (will be called when accessing special page) |
27 | 23 | * |
28 | | - * @param string $par Content of GET-Parameter |
29 | | - * @return void |
| 24 | + * @param $par Mixed: parameter passed to the special page or null |
30 | 25 | */ |
31 | | - public function execute($par) { |
| 26 | + public function execute( $par ) { |
32 | 27 | global $wgOut, $wgUser; |
33 | | - $dbr =& wfGetDB( DB_SLAVE ); |
34 | | - |
| 28 | + |
35 | 29 | $this->setHeaders(); |
36 | | - |
37 | | - if (!$wgUser->isAllowed("protect")) { |
| 30 | + |
| 31 | + if ( !$wgUser->isAllowed( 'protect' ) ) { |
38 | 32 | // No admin |
39 | | - $wgOut->addWikiText(wfMsg("fptc-insufficient-rights-for-maintenance")); |
| 33 | + $wgOut->addWikiMsg( 'fptc-insufficient-rights-for-maintenance' ); |
40 | 34 | } 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 | | - |
49 | 35 | // Refresh frequent pattern rules |
50 | | - include_once("includes/FrequentPattern.php"); |
51 | | - |
| 36 | + include_once( "includes/FrequentPattern.php" ); |
| 37 | + |
52 | 38 | FrequentPattern::deleteAllRules(); |
53 | 39 | FrequentPattern::computeAllRules(); |
54 | | - |
| 40 | + |
55 | 41 | // Notify user |
56 | | - $wgOut->addWikiText(wfMsg("fptc-refreshed-frequent-patterns")); |
| 42 | + $wgOut->addWikiMsg( 'fptc-refreshed-frequent-patterns' ); |
57 | 43 | } |
58 | 44 | } |
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 | | - } |
| 45 | + |
86 | 46 | } |
\ No newline at end of file |
Index: trunk/extensions/FreqPatternTagCloud/freqpatterntagcloud.sql |
— | — | @@ -0,0 +1,15 @@ |
| 2 | +CREATE TABLE IF NOT EXISTS /*_*/fptc_associationrules ( |
| 3 | + `rule_id` int(11) NOT NULL PRIMARY KEY auto_increment, |
| 4 | + `p_id` int(8) NOT NULL COMMENT 'Attribute', |
| 5 | + `rule_support` float(5,3) NOT NULL, |
| 6 | + `rule_confidence` float(5,3) NOT NULL |
| 7 | +)/*$wgDBTableOptions*/; |
| 8 | + |
| 9 | +CREATE INDEX /*i*/p_id ON fptc_associationrules (p_id); |
| 10 | + |
| 11 | +CREATE TABLE IF NOT EXISTS /*_*/fptc_items ( |
| 12 | + `o_id` INT(8) NOT NULL, |
| 13 | + `rule_id` INT NOT NULL, |
| 14 | + `item_order` TINYINT(1) NOT NULL, |
| 15 | + PRIMARY KEY ( `o_id` , `rule_id` ) |
| 16 | +)/*$wgDBTableOptions*/; |
\ No newline at end of file |
Property changes on: trunk/extensions/FreqPatternTagCloud/freqpatterntagcloud.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 17 | + native |
Index: trunk/extensions/FreqPatternTagCloud/FreqPatternTagCloud.php |
— | — | @@ -35,6 +35,8 @@ |
36 | 36 | // Register hook to prepare header files |
37 | 37 | $wgHooks['BeforePageDisplay'][] = 'fptc_initializeHeaders'; |
38 | 38 | |
| 39 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'fptc_applySchemaChanges'; |
| 40 | + |
39 | 41 | // Register files |
40 | 42 | $wgAutoloadClasses['FreqPatternTagCloud'] = FPTC_PATH_HOME . 'FreqPatternTagCloud.body.php'; |
41 | 43 | $wgExtensionMessagesFiles['FreqPatternTagCloud'] = FPTC_PATH_HOME . 'FreqPatternTagCloud.i18n.php'; |
— | — | @@ -83,4 +85,25 @@ |
84 | 86 | $wgOut->addScriptFile( $wgScriptPath . '/extensions/FreqPatternTagCloud/javascripts/main.js' ); |
85 | 87 | |
86 | 88 | return true; |
| 89 | +} |
| 90 | + |
| 91 | + |
| 92 | +/** |
| 93 | + * Applies the schema changes when the user runs maintenance/update.php. |
| 94 | + * |
| 95 | + * @param $updater Object: instance of DatabaseUpdater |
| 96 | + * @return Boolean: true |
| 97 | + */ |
| 98 | +function fptc_applySchemaChanges( $updater = null ) { |
| 99 | + $dir = dirname( __FILE__ ); |
| 100 | + $file = "$dir/freqpatterntagcloud.sql"; |
| 101 | + if ( $updater === null ) { |
| 102 | + global $wgExtNewTables; |
| 103 | + $wgExtNewTables[] = array( 'fptc_associationrules', $file ); |
| 104 | + $wgExtNewTables[] = array( 'fptc_items', $file ); |
| 105 | + } else { |
| 106 | + $updater->addExtensionUpdate( array( 'addTable', 'fptc_associationrules', $file, true ) ); |
| 107 | + $updater->addExtensionUpdate( array( 'addTable', 'fptc_items', $file, true ) ); |
| 108 | + } |
| 109 | + return true; |
87 | 110 | } |
\ No newline at end of file |