r70152 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70151‎ | r70152 | r70153 >
Date:18:18, 29 July 2010
Author:mah
Status:ok
Tags:
Comment:
white-spaced only changes
Modified paths:
  • /trunk/phase3/includes/installer/Installer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/installer/Installer.php
@@ -2,56 +2,56 @@
33
44 /**
55 * Base installer class.
6 - *
 6+ *
77 * This class provides the base for installation and update functionality
88 * for both MediaWiki core and extensions.
9 - *
 9+ *
1010 * @since 1.17
1111 */
1212 abstract class Installer {
13 -
 13+
1414 /**
1515 * TODO: make protected?
16 - *
 16+ *
1717 * @var array
1818 */
19 - public $settings;
20 -
 19+ public $settings;
 20+
2121 /**
2222 * Cached DB installer instances, access using getDBInstaller().
23 - *
 23+ *
2424 * @var array
2525 */
2626 protected $dbInstallers = array();
2727
2828 /**
2929 * Minimum memory size in MB.
30 - *
 30+ *
3131 * @var integer
3232 */
33 - protected $minMemorySize = 50;
34 -
 33+ protected $minMemorySize = 50;
 34+
3535 /**
3636 * Cached Title, used by parse().
37 - *
 37+ *
3838 * @var Title
3939 */
4040 protected $parserTitle;
41 -
 41+
4242 /**
4343 * Cached ParserOptions, used by parse().
44 - *
 44+ *
4545 * @var ParserOptions
46 - */
47 - protected $parserOptions;
48 -
 46+ */
 47+ protected $parserOptions;
 48+
4949 /**
5050 * Known database types. These correspond to the class names <type>Installer,
5151 * and are also MediaWiki database types valid for $wgDBtype.
5252 *
5353 * To add a new type, create a <type>Installer class and a Database<type>
5454 * class, and add a config-type-<type> message to MessagesEn.php.
55 - *
 55+ *
5656 * @var array
5757 */
5858 protected $dbTypes = array(
@@ -60,12 +60,12 @@
6161 'sqlite',
6262 'oracle'
6363 );
64 -
 64+
6565 /**
6666 * A list of environment check methods called by doEnvironmentChecks().
6767 * These may output warnings using showMessage(), and/or abort the
6868 * installation process by returning false.
69 - *
 69+ *
7070 * @var array
7171 */
7272 protected $envChecks = array(
@@ -89,8 +89,8 @@
9090 'envCheckShellLocale',
9191 'envCheckUploadsDirectory',
9292 'envCheckLibicu'
93 - );
94 -
 93+ );
 94+
9595 /**
9696 * UI interface for displaying a short message
9797 * The parameters are like parameters to wfMsg().
@@ -98,23 +98,23 @@
9999 * output format such as HTML or text before being sent to the user.
100100 */
101101 public abstract function showMessage( $msg /*, ... */ );
102 -
 102+
103103 /**
104104 * Constructor, always call this from child classes.
105105 */
106 - public function __construct() {
 106+ public function __construct() {
107107 // Disable the i18n cache and LoadBalancer
108108 Language::getLocalisationCache()->disableBackend();
109109 LBFactory::disableBackend();
110110 }
111 -
 111+
112112 /**
113113 * Get a list of known DB types.
114114 */
115115 public function getDBTypes() {
116116 return $this->dbTypes;
117 - }
118 -
 117+ }
 118+
119119 /**
120120 * Do initial checks of the PHP environment. Set variables according to
121121 * the observed environment.
@@ -125,35 +125,35 @@
126126 *
127127 * Under the web subclass, it can already be assumed that PHP 5+ is in use
128128 * and that sessions are working.
129 - *
 129+ *
130130 * @return boolean
131131 */
132132 public function doEnvironmentChecks() {
133133 $this->showMessage( 'config-env-php', phpversion() );
134134
135135 $good = true;
136 -
 136+
137137 foreach ( $this->envChecks as $check ) {
138138 $status = $this->$check();
139139 if ( $status === false ) {
140140 $good = false;
141141 }
142142 }
143 -
 143+
144144 $this->setVar( '_Environment', $good );
145 -
 145+
146146 if ( $good ) {
147147 $this->showMessage( 'config-env-good' );
148148 } else {
149149 $this->showMessage( 'config-env-bad' );
150150 }
151 -
 151+
152152 return $good;
153153 }
154154
155155 /**
156156 * Set a MW configuration variable, or internal installer configuration variable.
157 - *
 157+ *
158158 * @param $name String
159159 * @param $value Mixed
160160 */
@@ -165,10 +165,10 @@
166166 * Get an MW configuration variable, or internal installer configuration variable.
167167 * The defaults come from $GLOBALS (ultimately DefaultSettings.php).
168168 * Installer variables are typically prefixed by an underscore.
169 - *
 169+ *
170170 * @param $name String
171171 * @param $default Mixed
172 - *
 172+ *
173173 * @return mixed
174174 */
175175 public function getVar( $name, $default = null ) {
@@ -177,34 +177,34 @@
178178 } else {
179179 return $this->settings[$name];
180180 }
181 - }
182 -
 181+ }
 182+
183183 /**
184184 * Get an instance of DatabaseInstaller for the specified DB type.
185 - *
 185+ *
186186 * @param $type Mixed: DB installer for which is needed, false to use default.
187 - *
 187+ *
188188 * @return DatabaseInstaller
189189 */
190190 public function getDBInstaller( $type = false ) {
191191 if ( !$type ) {
192192 $type = $this->getVar( 'wgDBtype' );
193193 }
194 -
 194+
195195 $type = strtolower( $type );
196196
197197 if ( !isset( $this->dbInstallers[$type] ) ) {
198198 $class = ucfirst( $type ). 'Installer';
199199 $this->dbInstallers[$type] = new $class( $this );
200200 }
201 -
 201+
202202 return $this->dbInstallers[$type];
203 - }
204 -
 203+ }
 204+
205205 /**
206206 * Determine if LocalSettings exists. If it does, return an appropriate
207207 * status for whether we should can upgrade or not.
208 - *
 208+ *
209209 * @return Status
210210 */
211211 public function getLocalSettingsStatus() {
@@ -224,17 +224,17 @@
225225 $status->fatal( 'config-localsettings-noupgrade' );
226226 }
227227 }
228 -
 228+
229229 return $status;
230 - }
231 -
 230+ }
 231+
232232 /**
233233 * Get a fake password for sending back to the user in HTML.
234234 * This is a security mechanism to avoid compromise of the password in the
235235 * event of session ID compromise.
236 - *
 236+ *
237237 * @param $realPassword String
238 - *
 238+ *
239239 * @return string
240240 */
241241 public function getFakePassword( $realPassword ) {
@@ -244,7 +244,7 @@
245245 /**
246246 * Set a variable which stores a password, except if the new value is a
247247 * fake password in which case leave it as it is.
248 - *
 248+ *
249249 * @param $name String
250250 * @param $value Mixed
251251 */
@@ -252,7 +252,7 @@
253253 if ( !preg_match( '/^\*+$/', $value ) ) {
254254 $this->setVar( $name, $value );
255255 }
256 - }
 256+ }
257257
258258 /**
259259 * On POSIX systems return the primary group of the webserver we're running under.
@@ -278,8 +278,8 @@
279279 $group = $getpwuid['name'];
280280
281281 return $group;
282 - }
283 -
 282+ }
 283+
284284 /**
285285 * Convert wikitext $text to HTML.
286286 *
@@ -298,26 +298,26 @@
299299 */
300300 public function parse( $text, $lineStart = false ) {
301301 global $wgParser;
302 -
 302+
303303 try {
304304 $out = $wgParser->parse( $text, $this->parserTitle, $this->parserOptions, $lineStart );
305305 $html = $out->getText();
306306 } catch ( DBAccessError $e ) {
307307 $html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text );
308 -
 308+
309309 if ( !empty( $this->debug ) ) {
310310 $html .= "<!--\n" . $e->getTraceAsString() . "\n-->";
311311 }
312312 }
313 -
 313+
314314 return $html;
315 - }
316 -
 315+ }
 316+
317317 /**
318318 * TODO: document
319 - *
 319+ *
320320 * @param DatabaseInstaller $installer
321 - *
 321+ *
322322 * @return Status
323323 */
324324 public function installDatabase( DatabaseInstaller &$installer ) {
@@ -327,38 +327,38 @@
328328 } else {
329329 $status = $installer->setupDatabase();
330330 }
331 -
 331+
332332 return $status;
333333 }
334334
335335 /**
336336 * TODO: document
337 - *
 337+ *
338338 * @param DatabaseInstaller $installer
339 - *
 339+ *
340340 * @return Status
341341 */
342342 public function installTables( DatabaseInstaller &$installer ) {
343343 $status = $installer->createTables();
344 -
 344+
345345 if( $status->isOK() ) {
346346 LBFactory::enableBackend();
347347 }
348 -
 348+
349349 return $status;
350350 }
351351
352352 /**
353353 * TODO: document
354 - *
 354+ *
355355 * @param DatabaseInstaller $installer
356 - *
 356+ *
357357 * @return Status
358 - */
 358+ */
359359 public function installInterwiki( DatabaseInstaller &$installer ) {
360360 return $installer->populateInterwikiTable();
361 - }
362 -
 361+ }
 362+
363363 /**
364364 * Exports all wg* variables stored by the installer into global scope.
365365 */
@@ -368,45 +368,45 @@
369369 $GLOBALS[$name] = $value;
370370 }
371371 }
372 - }
373 -
 372+ }
 373+
374374 /**
375375 * Check if we're installing the latest version.
376376 */
377377 public function envLatestVersion() {
378378 global $wgVersion;
379 -
 379+
380380 $latestInfoUrl = 'http://www.mediawiki.org/w/api.php?action=mwreleases&format=json';
381381 $latestInfo = Http::get( $latestInfoUrl );
382 -
 382+
383383 if( !$latestInfo ) {
384384 $this->showMessage( 'config-env-latest-can-not-check', $latestInfoUrl );
385385 return;
386386 }
387 -
 387+
388388 $this->setVar( '_ExternalHTTP', true );
389389 $latestInfo = FormatJson::decode($latestInfo);
390 -
 390+
391391 if ($latestInfo === false || !isset( $latestInfo->mwreleases ) ) {
392392 # For when the request is successful but there's e.g. some silly man in
393393 # the middle firewall blocking us, e.g. one of those annoying airport ones
394394 $this->showMessage( 'config-env-latest-data-invalid', $latestInfoUrl );
395395 return;
396396 }
397 -
 397+
398398 foreach( $latestInfo->mwreleases as $rel ) {
399399 if( isset( $rel->current ) ) {
400400 $currentVersion = $rel->version;
401401 }
402402 }
403 -
 403+
404404 if( version_compare( $wgVersion, $currentVersion, '<' ) ) {
405405 $this->showMessage( 'config-env-latest-old' );
406406 $this->showHelpBox( 'config-env-latest-help', $wgVersion, $currentVersion );
407407 } elseif( version_compare( $wgVersion, $currentVersion, '>' ) ) {
408408 $this->showMessage( 'config-env-latest-new' );
409409 }
410 -
 410+
411411 $this->showMessage( 'config-env-latest-ok' );
412412 }
413413
@@ -415,31 +415,31 @@
416416 */
417417 public function envCheckDB() {
418418 global $wgLang;
419 -
 419+
420420 $compiledDBs = array();
421421 $goodNames = array();
422422 $allNames = array();
423 -
 423+
424424 foreach ( $this->dbTypes as $name ) {
425425 $db = $this->getDBInstaller( $name );
426426 $readableName = wfMsg( 'config-type-' . $name );
427 -
 427+
428428 if ( $db->isCompiled() ) {
429429 $compiledDBs[] = $name;
430430 $goodNames[] = $readableName;
431431 }
432 -
 432+
433433 $allNames[] = $readableName;
434434 }
435 -
 435+
436436 $this->setVar( '_CompiledDBs', $compiledDBs );
437 -
 437+
438438 if ( !$compiledDBs ) {
439439 $this->showMessage( 'config-no-db' );
440440 $this->showHelpBox( 'config-no-db-help', $wgLang->commaList( $allNames ) );
441441 return false;
442442 }
443 -
 443+
444444 $this->showMessage( 'config-have-db', $wgLang->commaList( $goodNames ) );
445445 }
446446
@@ -528,21 +528,21 @@
529529 */
530530 public function envCheckMemory() {
531531 $limit = ini_get( 'memory_limit' );
532 -
 532+
533533 if ( !$limit || $limit == -1 ) {
534534 $this->showMessage( 'config-memory-none' );
535535 return true;
536536 }
537 -
 537+
538538 $n = intval( $limit );
539 -
 539+
540540 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $limit ), $m ) ) {
541541 $n = intval( $m[1] * ( 1024 * 1024 ) );
542542 }
543 -
 543+
544544 if( $n < $this->minMemorySize * 1024 * 1024 ) {
545545 $newLimit = "{$this->minMemorySize}M";
546 -
 546+
547547 if( ini_set( "memory_limit", $newLimit ) === false ) {
548548 $this->showMessage( 'config-memory-bad', $limit );
549549 } else {
@@ -559,18 +559,18 @@
560560 */
561561 public function envCheckCache() {
562562 $caches = array();
563 -
 563+
564564 foreach ( $this->objectCaches as $name => $function ) {
565565 if ( function_exists( $function ) ) {
566566 $caches[$name] = true;
567567 $this->showMessage( 'config-' . $name );
568568 }
569569 }
570 -
 570+
571571 if ( !$caches ) {
572572 $this->showMessage( 'config-no-cache' );
573573 }
574 -
 574+
575575 $this->setVar( '_Caches', $caches );
576576 }
577577
@@ -588,55 +588,55 @@
589589 ),
590590 explode( PATH_SEPARATOR, getenv( "PATH" ) )
591591 );
592 -
 592+
593593 $names = array( "gdiff3", "diff3", "diff3.exe" );
594594 $versionInfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
595 -
 595+
596596 $haveDiff3 = false;
597 -
 597+
598598 foreach ( $paths as $path ) {
599599 $exe = $this->locateExecutable( $path, $names, $versionInfo );
600 -
 600+
601601 if ($exe !== false) {
602602 $this->setVar( 'wgDiff3', $exe );
603603 $haveDiff3 = true;
604604 break;
605605 }
606606 }
607 -
 607+
608608 if ( $haveDiff3 ) {
609609 $this->showMessage( 'config-diff3-good', $exe );
610610 } else {
611611 $this->setVar( 'wgDiff3', false );
612612 $this->showMessage( 'config-diff3-bad' );
613613 }
614 - }
615 -
 614+ }
 615+
616616 /**
617617 * Environment check for ImageMagick and GD.
618618 */
619619 public function envCheckGraphics() {
620620 $imcheck = array( "/usr/bin", "/opt/csw/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
621 -
 621+
622622 foreach( $imcheck as $dir ) {
623623 $im = "$dir/convert";
624 -
 624+
625625 wfSuppressWarnings();
626626 $file_exists = file_exists( $im );
627 - wfRestoreWarnings();
628 -
 627+ wfRestoreWarnings();
 628+
629629 if( $file_exists ) {
630630 $this->showMessage( 'config-imagemagick', $im );
631631 $this->setVar( 'wgImageMagickConvertCommand', $im );
632632 return true;
633633 }
634634 }
635 -
 635+
636636 if ( function_exists( 'imagejpeg' ) ) {
637637 $this->showMessage( 'config-gd' );
638638 return true;
639639 }
640 -
 640+
641641 $this->showMessage( 'no-scaling' );
642642 }
643643
@@ -646,7 +646,7 @@
647647 public function envCheckPath() {
648648 global $IP;
649649 $IP = dirname( dirname( dirname( __FILE__ ) ) );
650 -
 650+
651651 $this->setVar( 'IP', $IP );
652652 $this->showMessage( 'config-dir', $IP );
653653
@@ -664,7 +664,7 @@
665665 $this->showMessage( 'config-no-uri' );
666666 return false;
667667 }
668 -
 668+
669669 $uri = preg_replace( '{^(.*)/config.*$}', '$1', $path );
670670 $this->setVar( 'wgScriptPath', $uri );
671671 $this->showMessage( 'config-uri', $uri );
@@ -676,16 +676,16 @@
677677 public function envCheckWriteableDir() {
678678 $ipDir = $this->getVar( 'IP' );
679679 $configDir = $ipDir . '/config';
680 -
 680+
681681 if( !is_writeable( $configDir ) ) {
682682 $webserverGroup = self::maybeGetWebserverPrimaryGroup();
683 -
 683+
684684 if ( $webserverGroup !== null ) {
685685 $this->showMessage( 'config-dir-not-writable-group', $ipDir, $webserverGroup );
686686 } else {
687687 $this->showMessage( 'config-dir-not-writable-nogroup', $ipDir, $webserverGroup );
688688 }
689 -
 689+
690690 return false;
691691 }
692692 }
@@ -700,7 +700,7 @@
701701 } else {
702702 $ext = 'php';
703703 }
704 -
 704+
705705 $this->setVar( 'wgScriptExtension', ".$ext" );
706706 $this->showMessage( 'config-file-extension', $ext );
707707 }
@@ -717,7 +717,7 @@
718718
719719 $os = php_uname( 's' );
720720 $supported = array( 'Linux', 'SunOS', 'HP-UX' ); # Tested these
721 -
 721+
722722 if ( !in_array( $os, $supported ) ) {
723723 return true;
724724 }
@@ -725,7 +725,7 @@
726726 # Get a list of available locales.
727727 $lines = $ret = false;
728728 exec( '/usr/bin/locale -a', $lines, $ret );
729 -
 729+
730730 if ( $ret ) {
731731 return true;
732732 }
@@ -733,18 +733,18 @@
734734 $lines = wfArrayMap( 'trim', $lines );
735735 $candidatesByLocale = array();
736736 $candidatesByLang = array();
737 -
 737+
738738 foreach ( $lines as $line ) {
739739 if ( $line === '' ) {
740740 continue;
741741 }
742 -
 742+
743743 if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
744744 continue;
745745 }
746 -
 746+
747747 list( $all, $lang, $territory, $charset, $modifier ) = $m;
748 -
 748+
749749 $candidatesByLocale[$m[0]] = $m;
750750 $candidatesByLang[$lang][] = $m;
751751 }
@@ -768,7 +768,7 @@
769769
770770 # Is there an available locale in the Wiki's language?
771771 $wikiLang = $this->getVar( 'wgLanguageCode' );
772 -
 772+
773773 if ( isset( $candidatesByLang[$wikiLang] ) ) {
774774 $m = reset( $candidatesByLang[$wikiLang] );
775775 $this->setVar( 'wgShellLocale', $m[0] );
@@ -793,18 +793,18 @@
794794 */
795795 public function envCheckUploadsDirectory() {
796796 global $IP, $wgServer;
797 -
 797+
798798 $dir = $IP . '/images/';
799799 $url = $wgServer . $this->getVar( 'wgScriptPath' ) . '/images/';
800800 $safe = !$this->dirIsExecutable( $dir, $url );
801 -
 801+
802802 if ( $safe ) {
803803 $this->showMessage( 'config-uploads-safe' );
804804 } else {
805805 $this->showMessage( 'config-uploads-not-safe', $dir );
806806 }
807 - }
808 -
 807+ }
 808+
809809 /**
810810 * Convert a hex string representing a Unicode code point to that code point.
811811 * @param string $c
@@ -872,7 +872,7 @@
873873 * Search a path for any of the given executable names. Returns the
874874 * executable name if found. Also checks the version string returned
875875 * by each executable.
876 - *
 876+ *
877877 * Used only by environment checks.
878878 *
879879 * @param $path String: path to search
@@ -891,18 +891,18 @@
892892
893893 foreach ( $names as $name ) {
894894 $command = "$path/$name";
895 -
 895+
896896 wfSuppressWarnings();
897897 $file_exists = file_exists( $command );
898898 wfRestoreWarnings();
899 -
 899+
900900 if ( $file_exists ) {
901901 if ( !$versionInfo ) {
902902 return $command;
903903 }
904 -
 904+
905905 $file = str_replace( '$1', $command, $versionInfo[0] );
906 -
 906+
907907 # Should maybe be wfShellExec( $file), but runs into a ulimit, see
908908 # http://www.mediawiki.org/w/index.php?title=New-installer_issues&diff=prev&oldid=335456
909909 if ( strstr( `$file`, $versionInfo[1]) !== false ) {
@@ -910,13 +910,13 @@
911911 }
912912 }
913913 }
914 -
 914+
915915 return false;
916 - }
917 -
 916+ }
 917+
918918 /**
919919 * Checks if scripts located in the given directory can be executed via the given URL.
920 - *
 920+ *
921921 * Used only by environment checks.
922922 */
923923 public function dirIsExecutable( $dir, $url ) {
@@ -926,32 +926,32 @@
927927 "#!/var/env php5\n<?php echo 'ex' . 'ec';",
928928 ),
929929 );
930 -
 930+
931931 // it would be good to check other popular languages here, but it'll be slow.
932932
933933 wfSuppressWarnings();
934 -
 934+
935935 foreach ( $scriptTypes as $ext => $contents ) {
936936 foreach ( $contents as $source ) {
937937 $file = 'exectest.' . $ext;
938 -
 938+
939939 if ( !file_put_contents( $dir . $file, $source ) ) {
940940 break;
941941 }
942 -
 942+
943943 $text = Http::get( $url . $file );
944944 unlink( $dir . $file );
945 -
 945+
946946 if ( $text == 'exec' ) {
947947 wfRestoreWarnings();
948948 return $ext;
949949 }
950950 }
951951 }
952 -
 952+
953953 wfRestoreWarnings();
954 -
 954+
955955 return false;
956 - }
957 -
 956+ }
 957+
958958 }

Status & tagging log