Index: trunk/extensions/SemanticMediaWiki/SemanticMediaWiki.hooks.php |
— | — | @@ -0,0 +1,35 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Static class for hooks handled by the Semantic MediaWiki extension. |
| 6 | + * |
| 7 | + * @since 1.7 |
| 8 | + * |
| 9 | + * @file SemanticMediaWiki.hooks.php |
| 10 | + * @ingroup SMW |
| 11 | + * |
| 12 | + * @licence GNU GPL v3+ |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +final class SMWHooks { |
| 16 | + |
| 17 | + /** |
| 18 | + * Schema update to set up the needed database tables. |
| 19 | + * @see https://www.mediawiki.org/wiki/Manual:Hooks/LoadExtensionSchemaUpdates |
| 20 | + * |
| 21 | + * @since 0.1 |
| 22 | + * |
| 23 | + * @param DatabaseUpdater $updater|null |
| 24 | + * |
| 25 | + * @return true |
| 26 | + */ |
| 27 | + public static function onSchemaUpdate( /* DatabaseUpdater */ $updater = null ) { |
| 28 | + // $updater can be null in MW 1.16.x. This can be removed when dropping 1.16 compat. |
| 29 | + if ( !is_null( $updater ) ) { |
| 30 | + $updater->addPostDatabaseUpdateMaintenance( 'SMWSetupScript' ); |
| 31 | + } |
| 32 | + |
| 33 | + return true; |
| 34 | + } |
| 35 | + |
| 36 | +} |
Index: trunk/extensions/SemanticMediaWiki/maintenance/SMW_setup_1.16.php |
— | — | @@ -0,0 +1,130 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Sets up the storage backend currently selected in LocalSettings.php |
| 5 | + * (or the default MySQL store if no other store was selected). This |
| 6 | + * is equivalent to clicking the respective button on the page |
| 7 | + * Special:SMWAdmin. However, the latter may timeout if the setup involves |
| 8 | + * migrating a lot of existing data. |
| 9 | + * |
| 10 | + * Note: This is an older version of the setup script for people still using MediaWiki 1.16.x. |
| 11 | + * |
| 12 | + * Note: if SMW is not installed in its standard path under ./extensions |
| 13 | + * then the MW_INSTALL_PATH environment variable must be set. |
| 14 | + * See README in the maintenance directory. |
| 15 | + * |
| 16 | + * Usage: |
| 17 | + * php SMW_refreshData.php [options...] |
| 18 | + * |
| 19 | + * -b <backend> Execute the operation for the storage backend of the given name |
| 20 | + * -user <dbuser> Database user account to use for changing DB layout |
| 21 | + * -password <dbpassword> Password for user account |
| 22 | + * NOTE: specifying user credentials in a command line call will usually store them |
| 23 | + * within the shell history file. For security, provide credentials in Adminssetings.php |
| 24 | + * instead and ensure that your text editor does not create world-readable backup copies |
| 25 | + * when modifying this file. |
| 26 | + * |
| 27 | + * --delete Delete all SMW data, uninstall the selected storage backend. This is useful |
| 28 | + * when moving to a new storage engine, and in the rare case of unsinstalling |
| 29 | + * SMW. Deleted data can be recreated using this script (setup) and |
| 30 | + * SMW_refreshData.php but this may take some time. |
| 31 | + * @author Markus Krötzsch |
| 32 | + * @file |
| 33 | + * @ingroup SMWMaintenance |
| 34 | + */ |
| 35 | + |
| 36 | +/** |
| 37 | + * @defgroup SMWMaintenance SMWMaintenance |
| 38 | + * This group contains all parts of SMW that are maintenance scripts. |
| 39 | + * @ingroup SMW |
| 40 | + */ |
| 41 | + |
| 42 | +/** |
| 43 | + * no guarantees, but look in the usual place for commandLine.inc, so this |
| 44 | + * so it will work most of the time |
| 45 | + */ |
| 46 | +$optionsWithArgs = array( 'b', 'user', 'password' ); |
| 47 | + |
| 48 | +require_once ( getenv( 'MW_INSTALL_PATH' ) !== false |
| 49 | + ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc" |
| 50 | + : dirname( __FILE__ ) . '/../../../maintenance/commandLine.inc' ); |
| 51 | + |
| 52 | +global $smwgDefaultStore; |
| 53 | + |
| 54 | +/* user/password in LocalSettings probably don't have the rights we need, |
| 55 | + * so allow override |
| 56 | + * Note: the preferred method is to use AdminSettings.php to provide such credentials |
| 57 | + */ |
| 58 | +if ( isset( $options['user'] ) ) { |
| 59 | + global $wgDBuser; |
| 60 | + $wgDBuser = $options['user']; |
| 61 | +} |
| 62 | +if ( isset( $options['password'] ) ) { |
| 63 | + global $wgDBuser; |
| 64 | + $wgDBpassword = $options['password']; |
| 65 | +} |
| 66 | + |
| 67 | +$alternativestore = false; |
| 68 | +if ( array_key_exists( 'b', $options ) ) { |
| 69 | + if ( $smwgDefaultStore != $options['b'] ) { |
| 70 | + $alternativestore = true; |
| 71 | + } |
| 72 | + $smwgDefaultStore = $options['b']; |
| 73 | + print "\nSelected storage " . $smwgDefaultStore . " for update!\n\n"; |
| 74 | +} |
| 75 | + |
| 76 | + |
| 77 | +global $smwgIP; |
| 78 | +if ( !isset( $smwgIP ) ) { |
| 79 | + $smwgIP = dirname( __FILE__ ) . '/../'; |
| 80 | +} |
| 81 | + |
| 82 | +require_once( $smwgIP . 'includes/SMW_GlobalFunctions.php' ); |
| 83 | + |
| 84 | +if ( array_key_exists( 'delete', $options ) ) { |
| 85 | + print "\n Deleting all stored data for $smwgDefaultStore completely!\n \n\n"; |
| 86 | + if ( $alternativestore ) { |
| 87 | + print " This store is currently not used by SMW. Deleting it\n should not cause problems in the wiki.\n\n"; |
| 88 | + $delay = 5; |
| 89 | + } else { |
| 90 | + print " WARNING: This store is currently used by SMW! Deleting it\n will cause problems in the wiki if SMW is enabled.\n\n"; |
| 91 | + $delay = 20; |
| 92 | + } |
| 93 | + |
| 94 | + print "Abort with CTRL-C in the next $delay seconds ... "; |
| 95 | + |
| 96 | + // TODO |
| 97 | + // Remove the following section and replace it with a simple |
| 98 | + // wfCountDown as soon as we switch to MediaWiki 1.16. |
| 99 | + // Currently, wfCountDown is only supported from |
| 100 | + // revision 51650 (Jun 9 2009) onward. |
| 101 | + if ( function_exists( 'wfCountDown' ) ) { |
| 102 | + wfCountDown( $delay ); |
| 103 | + } else { |
| 104 | + for ( $i = $delay; $i >= 0; $i-- ) { |
| 105 | + if ( $i != $delay ) { |
| 106 | + echo str_repeat( "\x08", strlen( $i + 1 ) ); |
| 107 | + } |
| 108 | + echo $i; |
| 109 | + flush(); |
| 110 | + if ( $i ) { |
| 111 | + sleep( 1 ); |
| 112 | + } |
| 113 | + } |
| 114 | + echo "\n"; |
| 115 | + } |
| 116 | + // Remove up to here and just uncomment the following line: |
| 117 | + // wfCountDown( $delay ); |
| 118 | + |
| 119 | + smwfGetStore()->drop( true ); |
| 120 | + wfRunHooks( 'smwDropTables' ); |
| 121 | + print "\n"; |
| 122 | + while ( ob_get_level() > 0 ) { // be sure to have some buffer, otherwise some PHPs complain |
| 123 | + ob_end_flush(); |
| 124 | + } |
| 125 | + echo "\n All storage structures for $smwgDefaultStore have been deleted.\n You can recreate them with this script, and then use\n SMW_refreshData.php to rebuild their contents."; |
| 126 | +} else { |
| 127 | + smwfGetStore()->setup(); |
| 128 | + wfRunHooks( 'smwInitializeTables' ); |
| 129 | +} |
| 130 | + |
| 131 | +print "\n\nDone.\n"; |
Index: trunk/extensions/SemanticMediaWiki/maintenance/SMW_setup.php |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Sets up the storage backend currently selected in LocalSettings.php |
5 | 6 | * (or the default MySQL store if no other store was selected). This |
— | — | @@ -10,12 +11,12 @@ |
11 | 12 | * then the MW_INSTALL_PATH environment variable must be set. |
12 | 13 | * See README in the maintenance directory. |
13 | 14 | * |
| 15 | + * Note: For people still using MediaWiki 1.16.x, there is the SMW_setup_1.16.php script. |
| 16 | + * |
14 | 17 | * Usage: |
15 | 18 | * php SMW_refreshData.php [options...] |
16 | 19 | * |
17 | | - * -b <backend> Execute the operation for the storage backend of the given name |
18 | | - * -user <dbuser> Database user account to use for changing DB layout |
19 | | - * -password <dbpassword> Password for user account |
| 20 | + * -password Password for user account |
20 | 21 | * NOTE: specifying user credentials in a command line call will usually store them |
21 | 22 | * within the shell history file. For security, provide credentials in Adminssetings.php |
22 | 23 | * instead and ensure that your text editor does not create world-readable backup copies |
— | — | @@ -25,7 +26,10 @@ |
26 | 27 | * when moving to a new storage engine, and in the rare case of unsinstalling |
27 | 28 | * SMW. Deleted data can be recreated using this script (setup) and |
28 | 29 | * SMW_refreshData.php but this may take some time. |
| 30 | + * |
29 | 31 | * @author Markus Krötzsch |
| 32 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 33 | + * |
30 | 34 | * @file |
31 | 35 | * @ingroup SMWMaintenance |
32 | 36 | */ |
— | — | @@ -36,93 +40,88 @@ |
37 | 41 | * @ingroup SMW |
38 | 42 | */ |
39 | 43 | |
40 | | -/** |
41 | | - * no guarantees, but look in the usual place for commandLine.inc, so this |
42 | | - * so it will work most of the time |
43 | | - */ |
44 | | -$optionsWithArgs = array( 'b', 'user', 'password' ); |
45 | | - |
46 | 44 | require_once ( getenv( 'MW_INSTALL_PATH' ) !== false |
47 | | - ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc" |
48 | | - : dirname( __FILE__ ) . '/../../../maintenance/commandLine.inc' ); |
| 45 | + ? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php' |
| 46 | + : dirname( __FILE__ ) . '/../../../maintenance/Maintenance.php' ); |
49 | 47 | |
50 | | -global $smwgDefaultStore; |
| 48 | +class SMWSetupScript extends Maintenance { |
51 | 49 | |
52 | | -/* user/password in LocalSettings probably don't have the rights we need, |
53 | | - * so allow override |
54 | | - * Note: the preferred method is to use AdminSettings.php to provide such credentials |
55 | | - */ |
56 | | -if ( isset( $options['user'] ) ) { |
57 | | - global $wgDBuser; |
58 | | - $wgDBuser = $options['user']; |
59 | | -} |
60 | | -if ( isset( $options['password'] ) ) { |
61 | | - global $wgDBuser; |
62 | | - $wgDBpassword = $options['password']; |
63 | | -} |
| 50 | + public function __construct() { |
| 51 | + parent::__construct(); |
| 52 | + $this->mDescription = 'Sets up the SMW storage backend currently selected in LocalSettings.php.'; |
64 | 53 | |
65 | | -$alternativestore = false; |
66 | | -if ( array_key_exists( 'b', $options ) ) { |
67 | | - if ( $smwgDefaultStore != $options['b'] ) { |
68 | | - $alternativestore = true; |
| 54 | + $this->addArg( 'backend', 'Execute the operation for the storage backend of the given name.', false ); |
| 55 | + |
| 56 | + $this->addOption( 'delete', 'Delete all SMW data, uninstall the selected storage backend.' ); |
69 | 57 | } |
70 | | - $smwgDefaultStore = $options['b']; |
71 | | - print "\nSelected storage " . $smwgDefaultStore . " for update!\n\n"; |
72 | | -} |
73 | 58 | |
| 59 | + public function execute() { |
| 60 | + global $smwgDefaultStore; |
74 | 61 | |
75 | | -global $smwgIP; |
76 | | -if ( !isset( $smwgIP ) ) { |
77 | | - $smwgIP = dirname( __FILE__ ) . '/../'; |
78 | | -} |
79 | | - |
80 | | -require_once( $smwgIP . 'includes/SMW_GlobalFunctions.php' ); |
81 | | - |
82 | | -if ( array_key_exists( 'delete', $options ) ) { |
83 | | - print "\n Deleting all stored data for $smwgDefaultStore completely!\n \n\n"; |
84 | | - if ( $alternativestore ) { |
85 | | - print " This store is currently not used by SMW. Deleting it\n should not cause problems in the wiki.\n\n"; |
86 | | - $delay = 5; |
87 | | - } else { |
88 | | - print " WARNING: This store is currently used by SMW! Deleting it\n will cause problems in the wiki if SMW is enabled.\n\n"; |
89 | | - $delay = 20; |
90 | | - } |
91 | | - |
92 | | - print "Abort with CTRL-C in the next $delay seconds ... "; |
93 | | - |
94 | | - // TODO |
95 | | - // Remove the following section and replace it with a simple |
96 | | - // wfCountDown as soon as we switch to MediaWiki 1.16. |
97 | | - // Currently, wfCountDown is only supported from |
98 | | - // revision 51650 (Jun 9 2009) onward. |
99 | | - if ( function_exists( 'wfCountDown' ) ) { |
100 | | - wfCountDown( $delay ); |
101 | | - } else { |
102 | | - for ( $i = $delay; $i >= 0; $i-- ) { |
103 | | - if ( $i != $delay ) { |
104 | | - echo str_repeat( "\x08", strlen( $i + 1 ) ); |
| 62 | + $alternativestore = $this->getArg( 'backend', false ); |
| 63 | + $alternativestore = $alternativestore !== false && $alternativestore !== $smwgDefaultStore; |
| 64 | + |
| 65 | + if ( $alternativestore !== false ) { |
| 66 | + $smwgDefaultStore = $this->getArg( 'backend', false ); |
| 67 | + print "\nSelected storage " . $smwgDefaultStore . " for update!\n\n"; |
| 68 | + } |
| 69 | + |
| 70 | + global $smwgIP; |
| 71 | + if ( !isset( $smwgIP ) ) { |
| 72 | + $smwgIP = dirname( __FILE__ ) . '/../'; |
| 73 | + } |
| 74 | + |
| 75 | + require_once( $smwgIP . 'includes/SMW_GlobalFunctions.php' ); |
| 76 | + |
| 77 | + if ( $this->hasOption( 'delete' ) ) { |
| 78 | + print "\n Deleting all stored data for $smwgDefaultStore completely!\n \n\n"; |
| 79 | + if ( $alternativestore ) { |
| 80 | + print " This store is currently not used by SMW. Deleting it\n should not cause problems in the wiki.\n\n"; |
| 81 | + $delay = 5; |
| 82 | + } else { |
| 83 | + print " WARNING: This store is currently used by SMW! Deleting it\n will cause problems in the wiki if SMW is enabled.\n\n"; |
| 84 | + $delay = 20; |
105 | 85 | } |
106 | | - echo $i; |
107 | | - flush(); |
108 | | - if ( $i ) { |
109 | | - sleep( 1 ); |
| 86 | + |
| 87 | + print "Abort with CTRL-C in the next $delay seconds ... "; |
| 88 | + |
| 89 | + // TODO |
| 90 | + // Remove the following section and replace it with a simple |
| 91 | + // wfCountDown as soon as we switch to MediaWiki 1.16. |
| 92 | + // Currently, wfCountDown is only supported from |
| 93 | + // revision 51650 (Jun 9 2009) onward. |
| 94 | + if ( function_exists( 'wfCountDown' ) ) { |
| 95 | + wfCountDown( $delay ); |
| 96 | + } else { |
| 97 | + for ( $i = $delay; $i >= 0; $i-- ) { |
| 98 | + if ( $i != $delay ) { |
| 99 | + echo str_repeat( "\x08", strlen( $i + 1 ) ); |
| 100 | + } |
| 101 | + echo $i; |
| 102 | + flush(); |
| 103 | + if ( $i ) { |
| 104 | + sleep( 1 ); |
| 105 | + } |
| 106 | + } |
| 107 | + echo "\n"; |
110 | 108 | } |
| 109 | + // Remove up to here and just uncomment the following line: |
| 110 | + // wfCountDown( $delay ); |
| 111 | + |
| 112 | + smwfGetStore()->drop( true ); |
| 113 | + wfRunHooks( 'smwDropTables' ); |
| 114 | + print "\n"; |
| 115 | + while ( ob_get_level() > 0 ) { // be sure to have some buffer, otherwise some PHPs complain |
| 116 | + ob_end_flush(); |
| 117 | + } |
| 118 | + echo "\n All storage structures for $smwgDefaultStore have been deleted.\n You can recreate them with this script, and then use\n SMW_refreshData.php to rebuild their contents."; |
| 119 | + } else { |
| 120 | + smwfGetStore()->setup(); |
| 121 | + wfRunHooks( 'smwInitializeTables' ); |
111 | 122 | } |
112 | | - echo "\n"; |
113 | 123 | } |
114 | | - // Remove up to here and just uncomment the following line: |
115 | | - // wfCountDown( $delay ); |
116 | 124 | |
117 | | - smwfGetStore()->drop( true ); |
118 | | - wfRunHooks( 'smwDropTables' ); |
119 | | - print "\n"; |
120 | | - while ( ob_get_level() > 0 ) { // be sure to have some buffer, otherwise some PHPs complain |
121 | | - ob_end_flush(); |
122 | | - } |
123 | | - echo "\n All storage structures for $smwgDefaultStore have been deleted.\n You can recreate them with this script, and then use\n SMW_refreshData.php to rebuild their contents."; |
124 | | -} else { |
125 | | - smwfGetStore()->setup(); |
126 | | - wfRunHooks( 'smwInitializeTables' ); |
127 | 125 | } |
128 | 126 | |
129 | | -print "\n\nDone.\n"; |
| 127 | +$maintClass = 'SMWSetupScript'; |
| 128 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php |
— | — | @@ -73,8 +73,11 @@ |
74 | 74 | function smwfRegisterHooks() { |
75 | 75 | global $wgHooks, $wgVersion; |
76 | 76 | |
| 77 | + $wgHooks['LoadExtensionSchemaUpdates'][] = 'SMWHooks::onSchemaUpdate'; |
| 78 | + |
77 | 79 | // FIXME: The following can be removed when new style magic words are used (introduced in r52503) |
78 | 80 | $wgHooks['LanguageGetMagic'][] = 'smwfAddMagicWords'; // setup names for parser functions (needed here) |
| 81 | + |
79 | 82 | $wgHooks['ParserTestTables'][] = 'smwfOnParserTestTables'; |
80 | 83 | $wgHooks['AdminLinks'][] = 'smwfAddToAdminLinks'; |
81 | 84 | $wgHooks['PageSchemasRegisterHandlers'][] = 'SMWPageSchemas::registerClass'; |
— | — | @@ -168,6 +171,8 @@ |
169 | 172 | function smwfRegisterClasses() { |
170 | 173 | global $smwgIP, $wgAutoloadClasses, $wgJobClasses; |
171 | 174 | |
| 175 | + $wgAutoloadClasses['SMWHooks'] = $smwgIP . 'SemanticMediaWiki.hooks.php'; |
| 176 | + |
172 | 177 | $incDir = $smwgIP . 'includes/'; |
173 | 178 | $wgAutoloadClasses['SMWCompatibilityHelpers'] = $incDir . 'SMW_CompatibilityHelpers.php'; |
174 | 179 | $wgAutoloadClasses['SMWDataValueFactory'] = $incDir . 'SMW_DataValueFactory.php'; |
— | — | @@ -332,6 +337,9 @@ |
333 | 338 | $wgAutoloadClasses['ApiAskArgs'] = $smwgIP . 'includes/api/ApiAskArgs.php'; |
334 | 339 | $wgAutoloadClasses['ApiSMWInfo'] = $smwgIP . 'includes/api/ApiSMWInfo.php'; |
335 | 340 | |
| 341 | + // Maintenance scripts |
| 342 | + $wgAutoloadClasses['SMWSetupScript'] = $smwgIP . 'maintenance/SMW_setup.php'; |
| 343 | + |
336 | 344 | // Other extensions |
337 | 345 | $wgAutoloadClasses['SMWPageSchemas'] = $smwgIP . 'includes/SMW_PageSchemas.php'; |
338 | 346 | } |