Index: trunk/phase3/includes/Status.php |
— | — | @@ -179,19 +179,15 @@ |
180 | 180 | } |
181 | 181 | } |
182 | 182 | if ( count( $this->errors ) == 1 ) { |
183 | | - $params = array_map( 'wfEscapeWikiText', $this->cleanParams( $this->errors[0]['params'] ) ); |
184 | | - $s = wfMsgReal( $this->errors[0]['message'], $params, true, false, false ); |
| 183 | + $s = $this->getWikiTextForError( $this->errors[0], $this->errors[0] ); |
185 | 184 | if ( $shortContext ) { |
186 | 185 | $s = wfMsgNoTrans( $shortContext, $s ); |
187 | 186 | } elseif ( $longContext ) { |
188 | 187 | $s = wfMsgNoTrans( $longContext, "* $s\n" ); |
189 | 188 | } |
190 | 189 | } else { |
191 | | - $s = ''; |
192 | | - foreach ( $this->errors as $error ) { |
193 | | - $params = array_map( 'wfEscapeWikiText', $this->cleanParams( $error['params'] ) ); |
194 | | - $s .= '* ' . wfMsgReal( $error['message'], $params, true, false, false ) . "\n"; |
195 | | - } |
| 190 | + $s = '* '. implode("\n* ", |
| 191 | + $this->getWikiTextArray( $this->errors ) ) . "\n"; |
196 | 192 | if ( $longContext ) { |
197 | 193 | $s = wfMsgNoTrans( $longContext, $s ); |
198 | 194 | } elseif ( $shortContext ) { |
— | — | @@ -202,6 +198,41 @@ |
203 | 199 | } |
204 | 200 | |
205 | 201 | /** |
| 202 | + * Return the wiki text for a single error. |
| 203 | + * @param $error Mixed With an array & two values keyed by |
| 204 | + * 'message' and 'params', use those keys-value pairs. |
| 205 | + * Otherwise, if its an array, just use the first value as the |
| 206 | + * message and the remaining items as the params. |
| 207 | + * |
| 208 | + * @return String |
| 209 | + */ |
| 210 | + protected function getWikiTextForError( $error ) { |
| 211 | + if ( is_array( $error ) ) { |
| 212 | + if ( isset( $error['message'] ) && isset( $error['params'] ) ) { |
| 213 | + return wfMsgReal( $error['message'], |
| 214 | + array_map( 'wfEscapeWikiText', $this->cleanParams( $error['params'] ) ), |
| 215 | + true, false, false ); |
| 216 | + } else { |
| 217 | + $message = array_shift($error); |
| 218 | + return wfMsgReal( $message, |
| 219 | + array_map( 'wfEscapeWikiText', $this->cleanParams( $error ) ), |
| 220 | + true, false, false ); |
| 221 | + } |
| 222 | + } else { |
| 223 | + return wfMsgReal( $error, array(), true, false, false); |
| 224 | + } |
| 225 | + } |
| 226 | + |
| 227 | + /** |
| 228 | + * Return an array with the wikitext for each item in the array. |
| 229 | + * @param $errors Array |
| 230 | + * @return Array |
| 231 | + */ |
| 232 | + function getWikiTextArray( $errors ) { |
| 233 | + return array_map( array( $this, 'getWikiTextForError' ), $errors ); |
| 234 | + } |
| 235 | + |
| 236 | + /** |
206 | 237 | * Merge another status object into this one |
207 | 238 | * |
208 | 239 | * @param $other Other Status object |
— | — | @@ -223,17 +254,37 @@ |
224 | 255 | * @return Array |
225 | 256 | */ |
226 | 257 | function getErrorsArray() { |
| 258 | + return $this->getStatArray( "error" ); |
| 259 | + } |
| 260 | + |
| 261 | + /** |
| 262 | + * Get the list of warnings (but not errors) |
| 263 | + * |
| 264 | + * @return Array |
| 265 | + */ |
| 266 | + function getWarningsArray() { |
| 267 | + return $this->getStatArray( "warning" ); |
| 268 | + } |
| 269 | + |
| 270 | + /** |
| 271 | + * Returns a list of status messages of the given type |
| 272 | + * @param $type String |
| 273 | + * |
| 274 | + * @return Array |
| 275 | + */ |
| 276 | + protected function getStatArray( $type ) { |
227 | 277 | $result = array(); |
228 | 278 | foreach ( $this->errors as $error ) { |
229 | | - if ( $error['type'] == 'error' ) |
230 | | - if( $error['params'] ) |
| 279 | + if ( $error['type'] === $type ) { |
| 280 | + if( $error['params'] ) { |
231 | 281 | $result[] = array_merge( array( $error['message'] ), $error['params'] ); |
232 | | - else |
| 282 | + } else { |
233 | 283 | $result[] = $error['message']; |
| 284 | + } |
| 285 | + } |
234 | 286 | } |
235 | 287 | return $result; |
236 | 288 | } |
237 | | - |
238 | 289 | /** |
239 | 290 | * Returns true if the specified message is present as a warning or error |
240 | 291 | * |
Index: trunk/phase3/includes/installer/CliInstallerOutput.php |
— | — | @@ -1,79 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * Output class modelled on OutputPage. |
6 | | - * |
7 | | - * I've opted to use a distinct class rather than derive from OutputPage here in |
8 | | - * the interests of separation of concerns: if we used a subclass, there would be |
9 | | - * quite a lot of things you could do in OutputPage that would break the installer, |
10 | | - * that wouldn't be immediately obvious. |
11 | | - */ |
12 | | -class CliInstallerOutput { |
13 | | - |
14 | | - function __construct( $parent ) { |
15 | | - $this->parent = $parent; |
16 | | - } |
17 | | - |
18 | | - function addHTML( $html ) { |
19 | | - $this->contents .= $html; |
20 | | - } |
21 | | - |
22 | | - function addWikiText( $text ) { |
23 | | - $this->addHTML( $this->parent->parse( $text ) ); |
24 | | - } |
25 | | - |
26 | | - function addHTMLNoFlush( $html ) { |
27 | | - $this->contents .= $html; |
28 | | - } |
29 | | - |
30 | | - function addWarning( $msg ) { |
31 | | - $this->warnings .= "<p>$msg</p>\n"; |
32 | | - } |
33 | | - |
34 | | - function addWarningMsg( $msg /*, ... */ ) { |
35 | | - $params = func_get_args(); |
36 | | - array_shift( $params ); |
37 | | - $this->addWarning( wfMsg( $msg, $params ) ); |
38 | | - } |
39 | | - |
40 | | - function redirect( $url ) { |
41 | | - if ( $this->headerDone ) { |
42 | | - throw new MWException( __METHOD__ . ' called after sending headers' ); |
43 | | - } |
44 | | - $this->redirectTarget = $url; |
45 | | - } |
46 | | - |
47 | | - function output() { |
48 | | - $this->flush(); |
49 | | - } |
50 | | - |
51 | | - function useShortHeader( $use = true ) { |
52 | | - } |
53 | | - |
54 | | - function flush() { |
55 | | - echo html_entity_decode( strip_tags( $this->contents ), ENT_QUOTES ); |
56 | | - flush(); |
57 | | - $this->contents = ''; |
58 | | - } |
59 | | - |
60 | | - function getDir() { |
61 | | - global $wgLang; |
62 | | - if( !is_object( $wgLang ) || !$wgLang->isRtl() ) |
63 | | - return 'ltr'; |
64 | | - else |
65 | | - return 'rtl'; |
66 | | - } |
67 | | - |
68 | | - function getLanguageCode() { |
69 | | - global $wgLang; |
70 | | - if( !is_object( $wgLang ) ) |
71 | | - return 'en'; |
72 | | - else |
73 | | - return $wgLang->getCode(); |
74 | | - } |
75 | | - |
76 | | - function outputWarnings() { |
77 | | - $this->addHTML( $this->warnings ); |
78 | | - $this->warnings = ''; |
79 | | - } |
80 | | -} |
Index: trunk/phase3/includes/installer/Installer.php |
— | — | @@ -233,21 +233,9 @@ |
234 | 234 | foreach ( $this->defaultVarNames as $var ) { |
235 | 235 | $this->settings[$var] = $GLOBALS[$var]; |
236 | 236 | } |
237 | | - |
238 | | - $this->parserTitle = Title::newFromText( 'Installer' ); |
239 | | - $this->parserOptions = new ParserOptions; |
240 | | - $this->parserOptions->setEditSection( false ); |
241 | | - } |
242 | | - |
243 | | - /* |
244 | | - * Set up our database objects. They need to inject some of their |
245 | | - * own configuration into our global context. Usually this'll just be |
246 | | - * things like the default $wgDBname. |
247 | | - */ |
248 | | - function setupDatabaseObjects() { |
249 | 237 | foreach ( $this->dbTypes as $type ) { |
250 | 238 | $installer = $this->getDBInstaller( $type ); |
251 | | - if ( !$installer->isCompiled() ) { |
| 239 | + if ( !$installer ) { |
252 | 240 | continue; |
253 | 241 | } |
254 | 242 | $defaults = $installer->getGlobalDefaults(); |
— | — | @@ -259,6 +247,10 @@ |
260 | 248 | } |
261 | 249 | } |
262 | 250 | } |
| 251 | + |
| 252 | + $this->parserTitle = Title::newFromText( 'Installer' ); |
| 253 | + $this->parserOptions = new ParserOptions; |
| 254 | + $this->parserOptions->setEditSection( false ); |
263 | 255 | } |
264 | 256 | |
265 | 257 | /** |
— | — | @@ -286,9 +278,15 @@ |
287 | 279 | if ( !$type ) { |
288 | 280 | $type = $this->getVar( 'wgDBtype' ); |
289 | 281 | } |
| 282 | + $type = strtolower($type); |
| 283 | + |
290 | 284 | if ( !isset( $this->dbInstallers[$type] ) ) { |
291 | 285 | $class = ucfirst( $type ). 'Installer'; |
292 | | - $this->dbInstallers[$type] = new $class( $this ); |
| 286 | + if ($class::isCompiled()) { |
| 287 | + $this->dbInstallers[$type] = new $class( $this ); |
| 288 | + } else { |
| 289 | + $this->dbInstallers[$type] = false; |
| 290 | + } |
293 | 291 | } |
294 | 292 | return $this->dbInstallers[$type]; |
295 | 293 | } |
— | — | @@ -410,7 +408,7 @@ |
411 | 409 | foreach ( $this->dbTypes as $name ) { |
412 | 410 | $db = $this->getDBInstaller( $name ); |
413 | 411 | $readableName = wfMsg( 'config-type-' . $name ); |
414 | | - if ( $db->isCompiled() ) { |
| 412 | + if ( $db ) { |
415 | 413 | $compiledDBs[] = $name; |
416 | 414 | $goodNames[] = $readableName; |
417 | 415 | } |
— | — | @@ -901,8 +899,13 @@ |
902 | 900 | } |
903 | 901 | |
904 | 902 | public function installDatabase() { |
905 | | - $installer = $this->getDBInstaller( $this->getVar( 'wgDBtype' ) ); |
906 | | - $status = $installer->setupDatabase(); |
| 903 | + $type = $this->getVar( 'wgDBtype' ); |
| 904 | + $installer = $this->getDBInstaller( $type ); |
| 905 | + if(!$installer) { |
| 906 | + $status = Status::newFatal( "config-no-db", $type ); |
| 907 | + } else { |
| 908 | + $status = $installer->setupDatabase(); |
| 909 | + } |
907 | 910 | return $status; |
908 | 911 | } |
909 | 912 | |
— | — | @@ -1046,4 +1049,18 @@ |
1047 | 1050 | $GLOBALS['wgShowSQLErrors'] = true; |
1048 | 1051 | $GLOBALS['wgShowDBErrorBacktrace'] = true; |
1049 | 1052 | } |
| 1053 | + |
| 1054 | + /** |
| 1055 | + * Add an installation step following the given step. |
| 1056 | + * @param $findStep String the step to find. Use NULL to put the step at the beginning. |
| 1057 | + * @param $callback array |
| 1058 | + */ |
| 1059 | + function addInstallStepFollowing( $findStep, $callback ) { |
| 1060 | + $where = 0; |
| 1061 | + if( $findStep !== null ) $where = array_search( $findStep, $this->installSteps ); |
| 1062 | + |
| 1063 | + array_splice( $this->installSteps, $where, 0, $callback ); |
| 1064 | + } |
| 1065 | + |
| 1066 | + |
1050 | 1067 | } |
Index: trunk/phase3/includes/installer/SqliteInstaller.php |
— | — | @@ -10,8 +10,8 @@ |
11 | 11 | return 'sqlite'; |
12 | 12 | } |
13 | 13 | |
14 | | - function isCompiled() { |
15 | | - return $this->checkExtension( 'pdo_sqlite' ); |
| 14 | + static function isCompiled() { |
| 15 | + return self::checkExtension( 'pdo_sqlite' ); |
16 | 16 | } |
17 | 17 | |
18 | 18 | function getGlobalDefaults() { |
Index: trunk/phase3/includes/installer/MysqlInstaller.php |
— | — | @@ -39,19 +39,24 @@ |
40 | 40 | return; |
41 | 41 | } |
42 | 42 | |
| 43 | + if ( $this->parent->getVar( 'wgDBtype' ) !== $this->getName() ) { |
| 44 | + return; |
| 45 | + } |
| 46 | + |
43 | 47 | # Add our user callback to installSteps, right before the tables are created. |
44 | | - $where_tables = array_search( "tables", $this->parent->installSteps ); |
| 48 | + |
| 49 | + debug_print_backtrace(); |
45 | 50 | $callback = array( |
46 | 51 | array( |
47 | 52 | 'name' => 'user', |
48 | 53 | 'callback' => array( &$this, 'setupUser' ), |
49 | 54 | ) |
50 | 55 | ); |
51 | | - array_splice( $this->parent->installSteps, $where_tables, 0, $callback ); |
| 56 | + $this->parent->addInstallStepFollowing( "tables", $callback ); |
52 | 57 | } |
53 | | - |
54 | | - function isCompiled() { |
55 | | - return $this->checkExtension( 'mysql' ); |
| 58 | + |
| 59 | + static function isCompiled() { |
| 60 | + return self::checkExtension( 'mysql' ); |
56 | 61 | } |
57 | 62 | |
58 | 63 | function getGlobalDefaults() { |
Index: trunk/phase3/includes/installer/OracleInstaller.php |
— | — | @@ -19,8 +19,8 @@ |
20 | 20 | return 'oracle'; |
21 | 21 | } |
22 | 22 | |
23 | | - function isCompiled() { |
24 | | - return $this->checkExtension( 'oci8' ); |
| 23 | + static function isCompiled() { |
| 24 | + return self::checkExtension( 'oci8' ); |
25 | 25 | } |
26 | 26 | |
27 | 27 | function getConnectForm() { |
Index: trunk/phase3/includes/installer/PostgresInstaller.php |
— | — | @@ -25,8 +25,8 @@ |
26 | 26 | return 'postgres'; |
27 | 27 | } |
28 | 28 | |
29 | | - function isCompiled() { |
30 | | - return $this->checkExtension( 'pgsql' ); |
| 29 | + static function isCompiled() { |
| 30 | + return self::checkExtension( 'pgsql' ); |
31 | 31 | } |
32 | 32 | |
33 | 33 | function getConnectForm() { |
Index: trunk/phase3/includes/installer/CliInstaller.php |
— | — | @@ -68,17 +68,24 @@ |
69 | 69 | * Main entry point. |
70 | 70 | */ |
71 | 71 | function execute( ) { |
72 | | - foreach( $this->getInstallSteps() as $step ) { |
73 | | - $this->showMessage("Installing $step... "); |
| 72 | + foreach( $this->getInstallSteps() as $stepObj ) { |
| 73 | + $step = is_array( $stepObj ) ? $stepObj['name'] : $stepObj; |
| 74 | + $this->showMessage( wfMsg( "config-install-$step") . |
| 75 | + wfMsg( 'ellipsis' ) . wfMsg( 'word-separator' ) ); |
74 | 76 | $func = 'install' . ucfirst( $step ); |
75 | 77 | $status = $this->{$func}(); |
| 78 | + $warnings = $status->getWarningsArray(); |
76 | 79 | if ( !$status->isOk() ) { |
77 | 80 | $this->showStatusMessage( $status ); |
| 81 | + echo "\n"; |
78 | 82 | exit; |
79 | | - } elseif ( !$status->isGood() ) { |
80 | | - $this->showStatusMessage( $status ); |
| 83 | + } elseif ( count($warnings) !== 0 ) { |
| 84 | + foreach ( $status->getWikiTextArray( $warnings ) as $w ) { |
| 85 | + $this->showMessage( $w . wfMsg( 'ellipsis') . |
| 86 | + wfMsg( 'word-separator' ) ); |
| 87 | + } |
81 | 88 | } |
82 | | - $this->showMessage("done\n"); |
| 89 | + $this->showMessage( wfMsg( 'config-install-step-done' ) ."\n"); |
83 | 90 | } |
84 | 91 | } |
85 | 92 | |
Index: trunk/phase3/includes/installer/InstallerDBType.php |
— | — | @@ -24,7 +24,7 @@ |
25 | 25 | /** |
26 | 26 | * @return true if the client library is compiled in |
27 | 27 | */ |
28 | | - abstract function isCompiled(); |
| 28 | + abstract static function isCompiled(); |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Get an array of MW configuration globals that will be configured by this class. |
— | — | @@ -126,7 +126,7 @@ |
127 | 127 | * Convenience function |
128 | 128 | * Check if a named extension is present |
129 | 129 | */ |
130 | | - function checkExtension( $name ) { |
| 130 | + static function checkExtension( $name ) { |
131 | 131 | wfSuppressWarnings(); |
132 | 132 | $compiled = wfDl( $name ); |
133 | 133 | wfRestoreWarnings(); |