r105251 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105250‎ | r105251 | r105252 >
Date:23:54, 5 December 2011
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
have the setup script run via the db update hook, so people do not have to do this separately
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/SemanticMediaWiki.hooks.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/maintenance/SMW_setup.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/maintenance/SMW_setup_1.16.php (added) (history)

Diff [purge]

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 @@
22 <?php
 3+
34 /**
45 * Sets up the storage backend currently selected in LocalSettings.php
56 * (or the default MySQL store if no other store was selected). This
@@ -10,12 +11,12 @@
1112 * then the MW_INSTALL_PATH environment variable must be set.
1213 * See README in the maintenance directory.
1314 *
 15+ * Note: For people still using MediaWiki 1.16.x, there is the SMW_setup_1.16.php script.
 16+ *
1417 * Usage:
1518 * php SMW_refreshData.php [options...]
1619 *
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
2021 * NOTE: specifying user credentials in a command line call will usually store them
2122 * within the shell history file. For security, provide credentials in Adminssetings.php
2223 * instead and ensure that your text editor does not create world-readable backup copies
@@ -25,7 +26,10 @@
2627 * when moving to a new storage engine, and in the rare case of unsinstalling
2728 * SMW. Deleted data can be recreated using this script (setup) and
2829 * SMW_refreshData.php but this may take some time.
 30+ *
2931 * @author Markus Krötzsch
 32+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 33+ *
3034 * @file
3135 * @ingroup SMWMaintenance
3236 */
@@ -36,93 +40,88 @@
3741 * @ingroup SMW
3842 */
3943
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 -
4644 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' );
4947
50 -global $smwgDefaultStore;
 48+class SMWSetupScript extends Maintenance {
5149
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.';
6453
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.' );
6957 }
70 - $smwgDefaultStore = $options['b'];
71 - print "\nSelected storage " . $smwgDefaultStore . " for update!\n\n";
72 -}
7358
 59+ public function execute() {
 60+ global $smwgDefaultStore;
7461
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;
10585 }
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";
110108 }
 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' );
111122 }
112 - echo "\n";
113123 }
114 - // Remove up to here and just uncomment the following line:
115 - // wfCountDown( $delay );
116124
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' );
127125 }
128126
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 @@
7474 function smwfRegisterHooks() {
7575 global $wgHooks, $wgVersion;
7676
 77+ $wgHooks['LoadExtensionSchemaUpdates'][] = 'SMWHooks::onSchemaUpdate';
 78+
7779 // FIXME: The following can be removed when new style magic words are used (introduced in r52503)
7880 $wgHooks['LanguageGetMagic'][] = 'smwfAddMagicWords'; // setup names for parser functions (needed here)
 81+
7982 $wgHooks['ParserTestTables'][] = 'smwfOnParserTestTables';
8083 $wgHooks['AdminLinks'][] = 'smwfAddToAdminLinks';
8184 $wgHooks['PageSchemasRegisterHandlers'][] = 'SMWPageSchemas::registerClass';
@@ -168,6 +171,8 @@
169172 function smwfRegisterClasses() {
170173 global $smwgIP, $wgAutoloadClasses, $wgJobClasses;
171174
 175+ $wgAutoloadClasses['SMWHooks'] = $smwgIP . 'SemanticMediaWiki.hooks.php';
 176+
172177 $incDir = $smwgIP . 'includes/';
173178 $wgAutoloadClasses['SMWCompatibilityHelpers'] = $incDir . 'SMW_CompatibilityHelpers.php';
174179 $wgAutoloadClasses['SMWDataValueFactory'] = $incDir . 'SMW_DataValueFactory.php';
@@ -332,6 +337,9 @@
333338 $wgAutoloadClasses['ApiAskArgs'] = $smwgIP . 'includes/api/ApiAskArgs.php';
334339 $wgAutoloadClasses['ApiSMWInfo'] = $smwgIP . 'includes/api/ApiSMWInfo.php';
335340
 341+ // Maintenance scripts
 342+ $wgAutoloadClasses['SMWSetupScript'] = $smwgIP . 'maintenance/SMW_setup.php';
 343+
336344 // Other extensions
337345 $wgAutoloadClasses['SMWPageSchemas'] = $smwgIP . 'includes/SMW_PageSchemas.php';
338346 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r105253Follow up to r105251;jeroendedauw23:56, 5 December 2011
r105467Follow-up to r105251 - method was only added in MW 1.19yaron22:22, 7 December 2011

Comments

#Comment by Nikerabbit (talk | contribs)   12:32, 7 December 2011

This looks wrong:

+	 * @param DatabaseUpdater $updater|null