PageRenderTime 77ms CodeModel.GetById 32ms RepoModel.GetById 2ms app.codeStats 0ms

/includes/installer/Installer.php

https://github.com/spenser-roark/OOUG-Wiki
PHP | 1593 lines | 909 code | 188 blank | 496 comment | 111 complexity | 7457039b44895fc4a63d075d9d1da249 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, LGPL-3.0
  1. <?php
  2. /**
  3. * Base code for MediaWiki installer.
  4. *
  5. * @file
  6. * @ingroup Deployment
  7. */
  8. /**
  9. * This documentation group collects source code files with deployment functionality.
  10. *
  11. * @defgroup Deployment Deployment
  12. */
  13. /**
  14. * Base installer class.
  15. *
  16. * This class provides the base for installation and update functionality
  17. * for both MediaWiki core and extensions.
  18. *
  19. * @ingroup Deployment
  20. * @since 1.17
  21. */
  22. abstract class Installer {
  23. // This is the absolute minimum PHP version we can support
  24. const MINIMUM_PHP_VERSION = '5.2.3';
  25. /**
  26. * @var array
  27. */
  28. protected $settings;
  29. /**
  30. * Cached DB installer instances, access using getDBInstaller().
  31. *
  32. * @var array
  33. */
  34. protected $dbInstallers = array();
  35. /**
  36. * Minimum memory size in MB.
  37. *
  38. * @var integer
  39. */
  40. protected $minMemorySize = 50;
  41. /**
  42. * Cached Title, used by parse().
  43. *
  44. * @var Title
  45. */
  46. protected $parserTitle;
  47. /**
  48. * Cached ParserOptions, used by parse().
  49. *
  50. * @var ParserOptions
  51. */
  52. protected $parserOptions;
  53. /**
  54. * Known database types. These correspond to the class names <type>Installer,
  55. * and are also MediaWiki database types valid for $wgDBtype.
  56. *
  57. * To add a new type, create a <type>Installer class and a Database<type>
  58. * class, and add a config-type-<type> message to MessagesEn.php.
  59. *
  60. * @var array
  61. */
  62. protected static $dbTypes = array(
  63. 'mysql',
  64. 'postgres',
  65. 'oracle',
  66. 'sqlite',
  67. 'ibm_db2',
  68. );
  69. /**
  70. * A list of environment check methods called by doEnvironmentChecks().
  71. * These may output warnings using showMessage(), and/or abort the
  72. * installation process by returning false.
  73. *
  74. * @var array
  75. */
  76. protected $envChecks = array(
  77. 'envCheckDB',
  78. 'envCheckRegisterGlobals',
  79. 'envCheckBrokenXML',
  80. 'envCheckPHP531',
  81. 'envCheckMagicQuotes',
  82. 'envCheckMagicSybase',
  83. 'envCheckMbstring',
  84. 'envCheckZE1',
  85. 'envCheckSafeMode',
  86. 'envCheckXML',
  87. 'envCheckPCRE',
  88. 'envCheckMemory',
  89. 'envCheckCache',
  90. 'envCheckModSecurity',
  91. 'envCheckDiff3',
  92. 'envCheckGraphics',
  93. 'envCheckServer',
  94. 'envCheckPath',
  95. 'envCheckExtension',
  96. 'envCheckShellLocale',
  97. 'envCheckUploadsDirectory',
  98. 'envCheckLibicu',
  99. 'envCheckSuhosinMaxValueLength',
  100. 'envCheckCtype',
  101. );
  102. /**
  103. * MediaWiki configuration globals that will eventually be passed through
  104. * to LocalSettings.php. The names only are given here, the defaults
  105. * typically come from DefaultSettings.php.
  106. *
  107. * @var array
  108. */
  109. protected $defaultVarNames = array(
  110. 'wgSitename',
  111. 'wgPasswordSender',
  112. 'wgLanguageCode',
  113. 'wgRightsIcon',
  114. 'wgRightsText',
  115. 'wgRightsUrl',
  116. 'wgMainCacheType',
  117. 'wgEnableEmail',
  118. 'wgEnableUserEmail',
  119. 'wgEnotifUserTalk',
  120. 'wgEnotifWatchlist',
  121. 'wgEmailAuthentication',
  122. 'wgDBtype',
  123. 'wgDiff3',
  124. 'wgImageMagickConvertCommand',
  125. 'IP',
  126. 'wgServer',
  127. 'wgScriptPath',
  128. 'wgScriptExtension',
  129. 'wgMetaNamespace',
  130. 'wgDeletedDirectory',
  131. 'wgEnableUploads',
  132. 'wgLogo',
  133. 'wgShellLocale',
  134. 'wgSecretKey',
  135. 'wgUseInstantCommons',
  136. 'wgUpgradeKey',
  137. 'wgDefaultSkin',
  138. 'wgResourceLoaderMaxQueryLength',
  139. );
  140. /**
  141. * Variables that are stored alongside globals, and are used for any
  142. * configuration of the installation process aside from the MediaWiki
  143. * configuration. Map of names to defaults.
  144. *
  145. * @var array
  146. */
  147. protected $internalDefaults = array(
  148. '_UserLang' => 'en',
  149. '_Environment' => false,
  150. '_CompiledDBs' => array(),
  151. '_SafeMode' => false,
  152. '_RaiseMemory' => false,
  153. '_UpgradeDone' => false,
  154. '_InstallDone' => false,
  155. '_Caches' => array(),
  156. '_InstallPassword' => '',
  157. '_SameAccount' => true,
  158. '_CreateDBAccount' => false,
  159. '_NamespaceType' => 'site-name',
  160. '_AdminName' => '', // will be set later, when the user selects language
  161. '_AdminPassword' => '',
  162. '_AdminPassword2' => '',
  163. '_AdminEmail' => '',
  164. '_Subscribe' => false,
  165. '_SkipOptional' => 'continue',
  166. '_RightsProfile' => 'wiki',
  167. '_LicenseCode' => 'none',
  168. '_CCDone' => false,
  169. '_Extensions' => array(),
  170. '_MemCachedServers' => '',
  171. '_UpgradeKeySupplied' => false,
  172. '_ExistingDBSettings' => false,
  173. );
  174. /**
  175. * The actual list of installation steps. This will be initialized by getInstallSteps()
  176. *
  177. * @var array
  178. */
  179. private $installSteps = array();
  180. /**
  181. * Extra steps for installation, for things like DatabaseInstallers to modify
  182. *
  183. * @var array
  184. */
  185. protected $extraInstallSteps = array();
  186. /**
  187. * Known object cache types and the functions used to test for their existence.
  188. *
  189. * @var array
  190. */
  191. protected $objectCaches = array(
  192. 'xcache' => 'xcache_get',
  193. 'apc' => 'apc_fetch',
  194. 'wincache' => 'wincache_ucache_get'
  195. );
  196. /**
  197. * User rights profiles.
  198. *
  199. * @var array
  200. */
  201. public $rightsProfiles = array(
  202. 'wiki' => array(),
  203. 'no-anon' => array(
  204. '*' => array( 'edit' => false )
  205. ),
  206. 'fishbowl' => array(
  207. '*' => array(
  208. 'createaccount' => false,
  209. 'edit' => false,
  210. ),
  211. ),
  212. 'private' => array(
  213. '*' => array(
  214. 'createaccount' => false,
  215. 'edit' => false,
  216. 'read' => false,
  217. ),
  218. ),
  219. );
  220. /**
  221. * License types.
  222. *
  223. * @var array
  224. */
  225. public $licenses = array(
  226. 'cc-by' => array(
  227. 'url' => 'http://creativecommons.org/licenses/by/3.0/',
  228. 'icon' => '{$wgStylePath}/common/images/cc-by.png',
  229. ),
  230. 'cc-by-sa' => array(
  231. 'url' => 'http://creativecommons.org/licenses/by-sa/3.0/',
  232. 'icon' => '{$wgStylePath}/common/images/cc-by-sa.png',
  233. ),
  234. 'cc-by-nc-sa' => array(
  235. 'url' => 'http://creativecommons.org/licenses/by-nc-sa/3.0/',
  236. 'icon' => '{$wgStylePath}/common/images/cc-by-nc-sa.png',
  237. ),
  238. 'cc-0' => array(
  239. 'url' => 'https://creativecommons.org/publicdomain/zero/1.0/',
  240. 'icon' => '{$wgStylePath}/common/images/cc-0.png',
  241. ),
  242. 'pd' => array(
  243. 'url' => '',
  244. 'icon' => '{$wgStylePath}/common/images/public-domain.png',
  245. ),
  246. 'gfdl' => array(
  247. 'url' => 'http://www.gnu.org/copyleft/fdl.html',
  248. 'icon' => '{$wgStylePath}/common/images/gnu-fdl.png',
  249. ),
  250. 'none' => array(
  251. 'url' => '',
  252. 'icon' => '',
  253. 'text' => ''
  254. ),
  255. 'cc-choose' => array(
  256. // Details will be filled in by the selector.
  257. 'url' => '',
  258. 'icon' => '',
  259. 'text' => '',
  260. ),
  261. );
  262. /**
  263. * URL to mediawiki-announce subscription
  264. */
  265. protected $mediaWikiAnnounceUrl = 'https://lists.wikimedia.org/mailman/subscribe/mediawiki-announce';
  266. /**
  267. * Supported language codes for Mailman
  268. */
  269. protected $mediaWikiAnnounceLanguages = array(
  270. 'ca', 'cs', 'da', 'de', 'en', 'es', 'et', 'eu', 'fi', 'fr', 'hr', 'hu',
  271. 'it', 'ja', 'ko', 'lt', 'nl', 'no', 'pl', 'pt', 'pt-br', 'ro', 'ru',
  272. 'sl', 'sr', 'sv', 'tr', 'uk'
  273. );
  274. /**
  275. * UI interface for displaying a short message
  276. * The parameters are like parameters to wfMsg().
  277. * The messages will be in wikitext format, which will be converted to an
  278. * output format such as HTML or text before being sent to the user.
  279. * @param $msg
  280. */
  281. public abstract function showMessage( $msg /*, ... */ );
  282. /**
  283. * Same as showMessage(), but for displaying errors
  284. * @param $msg
  285. */
  286. public abstract function showError( $msg /*, ... */ );
  287. /**
  288. * Show a message to the installing user by using a Status object
  289. * @param $status Status
  290. */
  291. public abstract function showStatusMessage( Status $status );
  292. /**
  293. * Constructor, always call this from child classes.
  294. */
  295. public function __construct() {
  296. global $wgExtensionMessagesFiles, $wgUser;
  297. // Disable the i18n cache and LoadBalancer
  298. Language::getLocalisationCache()->disableBackend();
  299. LBFactory::disableBackend();
  300. // Load the installer's i18n file.
  301. $wgExtensionMessagesFiles['MediawikiInstaller'] =
  302. dirname( __FILE__ ) . '/Installer.i18n.php';
  303. // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
  304. $wgUser = User::newFromId( 0 );
  305. $this->settings = $this->internalDefaults;
  306. foreach ( $this->defaultVarNames as $var ) {
  307. $this->settings[$var] = $GLOBALS[$var];
  308. }
  309. $compiledDBs = array();
  310. foreach ( self::getDBTypes() as $type ) {
  311. $installer = $this->getDBInstaller( $type );
  312. if ( !$installer->isCompiled() ) {
  313. continue;
  314. }
  315. $compiledDBs[] = $type;
  316. $defaults = $installer->getGlobalDefaults();
  317. foreach ( $installer->getGlobalNames() as $var ) {
  318. if ( isset( $defaults[$var] ) ) {
  319. $this->settings[$var] = $defaults[$var];
  320. } else {
  321. $this->settings[$var] = $GLOBALS[$var];
  322. }
  323. }
  324. }
  325. $this->setVar( '_CompiledDBs', $compiledDBs );
  326. $this->parserTitle = Title::newFromText( 'Installer' );
  327. $this->parserOptions = new ParserOptions; // language will be wrong :(
  328. $this->parserOptions->setEditSection( false );
  329. }
  330. /**
  331. * Get a list of known DB types.
  332. *
  333. * @return array
  334. */
  335. public static function getDBTypes() {
  336. return self::$dbTypes;
  337. }
  338. /**
  339. * Do initial checks of the PHP environment. Set variables according to
  340. * the observed environment.
  341. *
  342. * It's possible that this may be called under the CLI SAPI, not the SAPI
  343. * that the wiki will primarily run under. In that case, the subclass should
  344. * initialise variables such as wgScriptPath, before calling this function.
  345. *
  346. * Under the web subclass, it can already be assumed that PHP 5+ is in use
  347. * and that sessions are working.
  348. *
  349. * @return Status
  350. */
  351. public function doEnvironmentChecks() {
  352. $phpVersion = phpversion();
  353. if( version_compare( $phpVersion, self::MINIMUM_PHP_VERSION, '>=' ) ) {
  354. $this->showMessage( 'config-env-php', $phpVersion );
  355. $good = true;
  356. } else {
  357. $this->showMessage( 'config-env-php-toolow', $phpVersion, self::MINIMUM_PHP_VERSION );
  358. $good = false;
  359. }
  360. if( $good ) {
  361. foreach ( $this->envChecks as $check ) {
  362. $status = $this->$check();
  363. if ( $status === false ) {
  364. $good = false;
  365. }
  366. }
  367. }
  368. $this->setVar( '_Environment', $good );
  369. return $good ? Status::newGood() : Status::newFatal( 'config-env-bad' );
  370. }
  371. /**
  372. * Set a MW configuration variable, or internal installer configuration variable.
  373. *
  374. * @param $name String
  375. * @param $value Mixed
  376. */
  377. public function setVar( $name, $value ) {
  378. $this->settings[$name] = $value;
  379. }
  380. /**
  381. * Get an MW configuration variable, or internal installer configuration variable.
  382. * The defaults come from $GLOBALS (ultimately DefaultSettings.php).
  383. * Installer variables are typically prefixed by an underscore.
  384. *
  385. * @param $name String
  386. * @param $default Mixed
  387. *
  388. * @return mixed
  389. */
  390. public function getVar( $name, $default = null ) {
  391. if ( !isset( $this->settings[$name] ) ) {
  392. return $default;
  393. } else {
  394. return $this->settings[$name];
  395. }
  396. }
  397. /**
  398. * Get an instance of DatabaseInstaller for the specified DB type.
  399. *
  400. * @param $type Mixed: DB installer for which is needed, false to use default.
  401. *
  402. * @return DatabaseInstaller
  403. */
  404. public function getDBInstaller( $type = false ) {
  405. if ( !$type ) {
  406. $type = $this->getVar( 'wgDBtype' );
  407. }
  408. $type = strtolower( $type );
  409. if ( !isset( $this->dbInstallers[$type] ) ) {
  410. $class = ucfirst( $type ). 'Installer';
  411. $this->dbInstallers[$type] = new $class( $this );
  412. }
  413. return $this->dbInstallers[$type];
  414. }
  415. /**
  416. * Determine if LocalSettings.php exists. If it does, return its variables,
  417. * merged with those from AdminSettings.php, as an array.
  418. *
  419. * @return Array
  420. */
  421. public static function getExistingLocalSettings() {
  422. global $IP;
  423. wfSuppressWarnings();
  424. $_lsExists = file_exists( "$IP/LocalSettings.php" );
  425. wfRestoreWarnings();
  426. if( !$_lsExists ) {
  427. return false;
  428. }
  429. unset($_lsExists);
  430. require( "$IP/includes/DefaultSettings.php" );
  431. require( "$IP/LocalSettings.php" );
  432. if ( file_exists( "$IP/AdminSettings.php" ) ) {
  433. require( "$IP/AdminSettings.php" );
  434. }
  435. return get_defined_vars();
  436. }
  437. /**
  438. * Get a fake password for sending back to the user in HTML.
  439. * This is a security mechanism to avoid compromise of the password in the
  440. * event of session ID compromise.
  441. *
  442. * @param $realPassword String
  443. *
  444. * @return string
  445. */
  446. public function getFakePassword( $realPassword ) {
  447. return str_repeat( '*', strlen( $realPassword ) );
  448. }
  449. /**
  450. * Set a variable which stores a password, except if the new value is a
  451. * fake password in which case leave it as it is.
  452. *
  453. * @param $name String
  454. * @param $value Mixed
  455. */
  456. public function setPassword( $name, $value ) {
  457. if ( !preg_match( '/^\*+$/', $value ) ) {
  458. $this->setVar( $name, $value );
  459. }
  460. }
  461. /**
  462. * On POSIX systems return the primary group of the webserver we're running under.
  463. * On other systems just returns null.
  464. *
  465. * This is used to advice the user that he should chgrp his mw-config/data/images directory as the
  466. * webserver user before he can install.
  467. *
  468. * Public because SqliteInstaller needs it, and doesn't subclass Installer.
  469. *
  470. * @return mixed
  471. */
  472. public static function maybeGetWebserverPrimaryGroup() {
  473. if ( !function_exists( 'posix_getegid' ) || !function_exists( 'posix_getpwuid' ) ) {
  474. # I don't know this, this isn't UNIX.
  475. return null;
  476. }
  477. # posix_getegid() *not* getmygid() because we want the group of the webserver,
  478. # not whoever owns the current script.
  479. $gid = posix_getegid();
  480. $getpwuid = posix_getpwuid( $gid );
  481. $group = $getpwuid['name'];
  482. return $group;
  483. }
  484. /**
  485. * Convert wikitext $text to HTML.
  486. *
  487. * This is potentially error prone since many parser features require a complete
  488. * installed MW database. The solution is to just not use those features when you
  489. * write your messages. This appears to work well enough. Basic formatting and
  490. * external links work just fine.
  491. *
  492. * But in case a translator decides to throw in a #ifexist or internal link or
  493. * whatever, this function is guarded to catch the attempted DB access and to present
  494. * some fallback text.
  495. *
  496. * @param $text String
  497. * @param $lineStart Boolean
  498. * @return String
  499. */
  500. public function parse( $text, $lineStart = false ) {
  501. global $wgParser;
  502. try {
  503. $out = $wgParser->parse( $text, $this->parserTitle, $this->parserOptions, $lineStart );
  504. $html = $out->getText();
  505. } catch ( DBAccessError $e ) {
  506. $html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text );
  507. if ( !empty( $this->debug ) ) {
  508. $html .= "<!--\n" . $e->getTraceAsString() . "\n-->";
  509. }
  510. }
  511. return $html;
  512. }
  513. /**
  514. * @return ParserOptions
  515. */
  516. public function getParserOptions() {
  517. return $this->parserOptions;
  518. }
  519. public function disableLinkPopups() {
  520. $this->parserOptions->setExternalLinkTarget( false );
  521. }
  522. public function restoreLinkPopups() {
  523. global $wgExternalLinkTarget;
  524. $this->parserOptions->setExternalLinkTarget( $wgExternalLinkTarget );
  525. }
  526. /**
  527. * Install step which adds a row to the site_stats table with appropriate
  528. * initial values.
  529. *
  530. * @param $installer DatabaseInstaller
  531. *
  532. * @return Status
  533. */
  534. public function populateSiteStats( DatabaseInstaller $installer ) {
  535. $status = $installer->getConnection();
  536. if ( !$status->isOK() ) {
  537. return $status;
  538. }
  539. $status->value->insert( 'site_stats', array(
  540. 'ss_row_id' => 1,
  541. 'ss_total_views' => 0,
  542. 'ss_total_edits' => 0,
  543. 'ss_good_articles' => 0,
  544. 'ss_total_pages' => 0,
  545. 'ss_users' => 0,
  546. 'ss_images' => 0 ),
  547. __METHOD__, 'IGNORE' );
  548. return Status::newGood();
  549. }
  550. /**
  551. * Exports all wg* variables stored by the installer into global scope.
  552. */
  553. public function exportVars() {
  554. foreach ( $this->settings as $name => $value ) {
  555. if ( substr( $name, 0, 2 ) == 'wg' ) {
  556. $GLOBALS[$name] = $value;
  557. }
  558. }
  559. }
  560. /**
  561. * Environment check for DB types.
  562. * @return bool
  563. */
  564. protected function envCheckDB() {
  565. global $wgLang;
  566. $allNames = array();
  567. foreach ( self::getDBTypes() as $name ) {
  568. $allNames[] = wfMsg( "config-type-$name" );
  569. }
  570. // cache initially available databases to make sure that everything will be displayed correctly
  571. // after a refresh on env checks page
  572. $databases = $this->getVar( '_CompiledDBs-preFilter' );
  573. if ( !$databases ) {
  574. $databases = $this->getVar( '_CompiledDBs' );
  575. $this->setVar( '_CompiledDBs-preFilter', $databases );
  576. }
  577. $databases = array_flip ( $databases );
  578. foreach ( array_keys( $databases ) as $db ) {
  579. $installer = $this->getDBInstaller( $db );
  580. $status = $installer->checkPrerequisites();
  581. if ( !$status->isGood() ) {
  582. $this->showStatusMessage( $status );
  583. }
  584. if ( !$status->isOK() ) {
  585. unset( $databases[$db] );
  586. }
  587. }
  588. $databases = array_flip( $databases );
  589. if ( !$databases ) {
  590. $this->showError( 'config-no-db', $wgLang->commaList( $allNames ) );
  591. // @todo FIXME: This only works for the web installer!
  592. return false;
  593. }
  594. $this->setVar( '_CompiledDBs', $databases );
  595. }
  596. /**
  597. * Environment check for register_globals.
  598. */
  599. protected function envCheckRegisterGlobals() {
  600. if( wfIniGetBool( 'register_globals' ) ) {
  601. $this->showMessage( 'config-register-globals' );
  602. }
  603. }
  604. /**
  605. * Some versions of libxml+PHP break < and > encoding horribly
  606. */
  607. protected function envCheckBrokenXML() {
  608. $test = new PhpXmlBugTester();
  609. if ( !$test->ok ) {
  610. $this->showError( 'config-brokenlibxml' );
  611. return false;
  612. }
  613. }
  614. /**
  615. * Test PHP (probably 5.3.1, but it could regress again) to make sure that
  616. * reference parameters to __call() are not converted to null
  617. */
  618. protected function envCheckPHP531() {
  619. $test = new PhpRefCallBugTester;
  620. $test->execute();
  621. if ( !$test->ok ) {
  622. $this->showError( 'config-using531', phpversion() );
  623. return false;
  624. }
  625. }
  626. /**
  627. * Environment check for magic_quotes_runtime.
  628. */
  629. protected function envCheckMagicQuotes() {
  630. if( wfIniGetBool( "magic_quotes_runtime" ) ) {
  631. $this->showError( 'config-magic-quotes-runtime' );
  632. return false;
  633. }
  634. }
  635. /**
  636. * Environment check for magic_quotes_sybase.
  637. */
  638. protected function envCheckMagicSybase() {
  639. if ( wfIniGetBool( 'magic_quotes_sybase' ) ) {
  640. $this->showError( 'config-magic-quotes-sybase' );
  641. return false;
  642. }
  643. }
  644. /**
  645. * Environment check for mbstring.func_overload.
  646. */
  647. protected function envCheckMbstring() {
  648. if ( wfIniGetBool( 'mbstring.func_overload' ) ) {
  649. $this->showError( 'config-mbstring' );
  650. return false;
  651. }
  652. }
  653. /**
  654. * Environment check for zend.ze1_compatibility_mode.
  655. */
  656. protected function envCheckZE1() {
  657. if ( wfIniGetBool( 'zend.ze1_compatibility_mode' ) ) {
  658. $this->showError( 'config-ze1' );
  659. return false;
  660. }
  661. }
  662. /**
  663. * Environment check for safe_mode.
  664. */
  665. protected function envCheckSafeMode() {
  666. if ( wfIniGetBool( 'safe_mode' ) ) {
  667. $this->setVar( '_SafeMode', true );
  668. $this->showMessage( 'config-safe-mode' );
  669. }
  670. }
  671. /**
  672. * Environment check for the XML module.
  673. */
  674. protected function envCheckXML() {
  675. if ( !function_exists( "utf8_encode" ) ) {
  676. $this->showError( 'config-xml-bad' );
  677. return false;
  678. }
  679. }
  680. /**
  681. * Environment check for the PCRE module.
  682. */
  683. protected function envCheckPCRE() {
  684. if ( !function_exists( 'preg_match' ) ) {
  685. $this->showError( 'config-pcre' );
  686. return false;
  687. }
  688. wfSuppressWarnings();
  689. $regexd = preg_replace( '/[\x{0430}-\x{04FF}]/iu', '', '-АБВГД-' );
  690. wfRestoreWarnings();
  691. if ( $regexd != '--' ) {
  692. $this->showError( 'config-pcre-no-utf8' );
  693. return false;
  694. }
  695. }
  696. /**
  697. * Environment check for available memory.
  698. */
  699. protected function envCheckMemory() {
  700. $limit = ini_get( 'memory_limit' );
  701. if ( !$limit || $limit == -1 ) {
  702. return true;
  703. }
  704. $n = wfShorthandToInteger( $limit );
  705. if( $n < $this->minMemorySize * 1024 * 1024 ) {
  706. $newLimit = "{$this->minMemorySize}M";
  707. if( ini_set( "memory_limit", $newLimit ) === false ) {
  708. $this->showMessage( 'config-memory-bad', $limit );
  709. } else {
  710. $this->showMessage( 'config-memory-raised', $limit, $newLimit );
  711. $this->setVar( '_RaiseMemory', true );
  712. }
  713. } else {
  714. return true;
  715. }
  716. }
  717. /**
  718. * Environment check for compiled object cache types.
  719. */
  720. protected function envCheckCache() {
  721. $caches = array();
  722. foreach ( $this->objectCaches as $name => $function ) {
  723. if ( function_exists( $function ) ) {
  724. if ( $name == 'xcache' && !wfIniGetBool( 'xcache.var_size' ) ) {
  725. continue;
  726. }
  727. $caches[$name] = true;
  728. }
  729. }
  730. if ( !$caches ) {
  731. $this->showMessage( 'config-no-cache' );
  732. }
  733. $this->setVar( '_Caches', $caches );
  734. }
  735. /**
  736. * Scare user to death if they have mod_security
  737. */
  738. protected function envCheckModSecurity() {
  739. if ( self::apacheModulePresent( 'mod_security' ) ) {
  740. $this->showMessage( 'config-mod-security' );
  741. }
  742. }
  743. /**
  744. * Search for GNU diff3.
  745. */
  746. protected function envCheckDiff3() {
  747. $names = array( "gdiff3", "diff3", "diff3.exe" );
  748. $versionInfo = array( '$1 --version 2>&1', 'GNU diffutils' );
  749. $diff3 = self::locateExecutableInDefaultPaths( $names, $versionInfo );
  750. if ( $diff3 ) {
  751. $this->setVar( 'wgDiff3', $diff3 );
  752. } else {
  753. $this->setVar( 'wgDiff3', false );
  754. $this->showMessage( 'config-diff3-bad' );
  755. }
  756. }
  757. /**
  758. * Environment check for ImageMagick and GD.
  759. */
  760. protected function envCheckGraphics() {
  761. $names = array( wfIsWindows() ? 'convert.exe' : 'convert' );
  762. $convert = self::locateExecutableInDefaultPaths( $names, array( '$1 -version', 'ImageMagick' ) );
  763. $this->setVar( 'wgImageMagickConvertCommand', '' );
  764. if ( $convert ) {
  765. $this->setVar( 'wgImageMagickConvertCommand', $convert );
  766. $this->showMessage( 'config-imagemagick', $convert );
  767. return true;
  768. } elseif ( function_exists( 'imagejpeg' ) ) {
  769. $this->showMessage( 'config-gd' );
  770. return true;
  771. } else {
  772. $this->showMessage( 'config-no-scaling' );
  773. }
  774. }
  775. /**
  776. * Environment check for the server hostname.
  777. */
  778. protected function envCheckServer() {
  779. $server = $this->envGetDefaultServer();
  780. $this->showMessage( 'config-using-server', $server );
  781. $this->setVar( 'wgServer', $server );
  782. }
  783. /**
  784. * Helper function to be called from envCheckServer()
  785. * @return String
  786. */
  787. protected abstract function envGetDefaultServer();
  788. /**
  789. * Environment check for setting $IP and $wgScriptPath.
  790. * @return bool
  791. */
  792. protected function envCheckPath() {
  793. global $IP;
  794. $IP = dirname( dirname( dirname( __FILE__ ) ) );
  795. $this->setVar( 'IP', $IP );
  796. $this->showMessage( 'config-using-uri', $this->getVar( 'wgServer' ), $this->getVar( 'wgScriptPath' ) );
  797. return true;
  798. }
  799. /**
  800. * Environment check for setting the preferred PHP file extension.
  801. */
  802. protected function envCheckExtension() {
  803. // @todo FIXME: Detect this properly
  804. if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
  805. $ext = 'php5';
  806. } else {
  807. $ext = 'php';
  808. }
  809. $this->setVar( 'wgScriptExtension', ".$ext" );
  810. }
  811. /**
  812. * TODO: document
  813. * @return bool
  814. */
  815. protected function envCheckShellLocale() {
  816. $os = php_uname( 's' );
  817. $supported = array( 'Linux', 'SunOS', 'HP-UX', 'Darwin' ); # Tested these
  818. if ( !in_array( $os, $supported ) ) {
  819. return true;
  820. }
  821. # Get a list of available locales.
  822. $ret = false;
  823. $lines = wfShellExec( '/usr/bin/locale -a', $ret );
  824. if ( $ret ) {
  825. return true;
  826. }
  827. $lines = wfArrayMap( 'trim', explode( "\n", $lines ) );
  828. $candidatesByLocale = array();
  829. $candidatesByLang = array();
  830. foreach ( $lines as $line ) {
  831. if ( $line === '' ) {
  832. continue;
  833. }
  834. if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
  835. continue;
  836. }
  837. list( $all, $lang, $territory, $charset, $modifier ) = $m;
  838. $candidatesByLocale[$m[0]] = $m;
  839. $candidatesByLang[$lang][] = $m;
  840. }
  841. # Try the current value of LANG.
  842. if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
  843. $this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
  844. return true;
  845. }
  846. # Try the most common ones.
  847. $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
  848. foreach ( $commonLocales as $commonLocale ) {
  849. if ( isset( $candidatesByLocale[$commonLocale] ) ) {
  850. $this->setVar( 'wgShellLocale', $commonLocale );
  851. return true;
  852. }
  853. }
  854. # Is there an available locale in the Wiki's language?
  855. $wikiLang = $this->getVar( 'wgLanguageCode' );
  856. if ( isset( $candidatesByLang[$wikiLang] ) ) {
  857. $m = reset( $candidatesByLang[$wikiLang] );
  858. $this->setVar( 'wgShellLocale', $m[0] );
  859. return true;
  860. }
  861. # Are there any at all?
  862. if ( count( $candidatesByLocale ) ) {
  863. $m = reset( $candidatesByLocale );
  864. $this->setVar( 'wgShellLocale', $m[0] );
  865. return true;
  866. }
  867. # Give up.
  868. return true;
  869. }
  870. /**
  871. * TODO: document
  872. */
  873. protected function envCheckUploadsDirectory() {
  874. global $IP;
  875. $dir = $IP . '/images/';
  876. $url = $this->getVar( 'wgServer' ) . $this->getVar( 'wgScriptPath' ) . '/images/';
  877. $safe = !$this->dirIsExecutable( $dir, $url );
  878. if ( $safe ) {
  879. return true;
  880. } else {
  881. $this->showMessage( 'config-uploads-not-safe', $dir );
  882. }
  883. }
  884. /**
  885. * Checks if suhosin.get.max_value_length is set, and if so, sets
  886. * $wgResourceLoaderMaxQueryLength to that value in the generated
  887. * LocalSettings file
  888. */
  889. protected function envCheckSuhosinMaxValueLength() {
  890. $maxValueLength = ini_get( 'suhosin.get.max_value_length' );
  891. if ( $maxValueLength > 0 ) {
  892. if( $maxValueLength < 1024 ) {
  893. # Only warn if the value is below the sane 1024
  894. $this->showMessage( 'config-suhosin-max-value-length', $maxValueLength );
  895. }
  896. } else {
  897. $maxValueLength = -1;
  898. }
  899. $this->setVar( 'wgResourceLoaderMaxQueryLength', $maxValueLength );
  900. }
  901. /**
  902. * Convert a hex string representing a Unicode code point to that code point.
  903. * @param $c String
  904. * @return string
  905. */
  906. protected function unicodeChar( $c ) {
  907. $c = hexdec($c);
  908. if ($c <= 0x7F) {
  909. return chr($c);
  910. } elseif ($c <= 0x7FF) {
  911. return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
  912. } elseif ($c <= 0xFFFF) {
  913. return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F)
  914. . chr(0x80 | $c & 0x3F);
  915. } elseif ($c <= 0x10FFFF) {
  916. return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F)
  917. . chr(0x80 | $c >> 6 & 0x3F)
  918. . chr(0x80 | $c & 0x3F);
  919. } else {
  920. return false;
  921. }
  922. }
  923. /**
  924. * Check the libicu version
  925. */
  926. protected function envCheckLibicu() {
  927. $utf8 = function_exists( 'utf8_normalize' );
  928. $intl = function_exists( 'normalizer_normalize' );
  929. /**
  930. * This needs to be updated something that the latest libicu
  931. * will properly normalize. This normalization was found at
  932. * http://www.unicode.org/versions/Unicode5.2.0/#Character_Additions
  933. * Note that we use the hex representation to create the code
  934. * points in order to avoid any Unicode-destroying during transit.
  935. */
  936. $not_normal_c = $this->unicodeChar("FA6C");
  937. $normal_c = $this->unicodeChar("242EE");
  938. $useNormalizer = 'php';
  939. $needsUpdate = false;
  940. /**
  941. * We're going to prefer the pecl extension here unless
  942. * utf8_normalize is more up to date.
  943. */
  944. if( $utf8 ) {
  945. $useNormalizer = 'utf8';
  946. $utf8 = utf8_normalize( $not_normal_c, UtfNormal::UNORM_NFC );
  947. if ( $utf8 !== $normal_c ) $needsUpdate = true;
  948. }
  949. if( $intl ) {
  950. $useNormalizer = 'intl';
  951. $intl = normalizer_normalize( $not_normal_c, Normalizer::FORM_C );
  952. if ( $intl !== $normal_c ) $needsUpdate = true;
  953. }
  954. // Uses messages 'config-unicode-using-php', 'config-unicode-using-utf8', 'config-unicode-using-intl'
  955. if( $useNormalizer === 'php' ) {
  956. $this->showMessage( 'config-unicode-pure-php-warning' );
  957. } else {
  958. $this->showMessage( 'config-unicode-using-' . $useNormalizer );
  959. if( $needsUpdate ) {
  960. $this->showMessage( 'config-unicode-update-warning' );
  961. }
  962. }
  963. }
  964. protected function envCheckCtype() {
  965. if ( !function_exists( 'ctype_digit' ) ) {
  966. $this->showError( 'config-ctype' );
  967. return false;
  968. }
  969. }
  970. /**
  971. * Get an array of likely places we can find executables. Check a bunch
  972. * of known Unix-like defaults, as well as the PATH environment variable
  973. * (which should maybe make it work for Windows?)
  974. *
  975. * @return Array
  976. */
  977. protected static function getPossibleBinPaths() {
  978. return array_merge(
  979. array( '/usr/bin', '/usr/local/bin', '/opt/csw/bin',
  980. '/usr/gnu/bin', '/usr/sfw/bin', '/sw/bin', '/opt/local/bin' ),
  981. explode( PATH_SEPARATOR, getenv( 'PATH' ) )
  982. );
  983. }
  984. /**
  985. * Search a path for any of the given executable names. Returns the
  986. * executable name if found. Also checks the version string returned
  987. * by each executable.
  988. *
  989. * Used only by environment checks.
  990. *
  991. * @param $path String: path to search
  992. * @param $names Array of executable names
  993. * @param $versionInfo Boolean false or array with two members:
  994. * 0 => Command to run for version check, with $1 for the full executable name
  995. * 1 => String to compare the output with
  996. *
  997. * If $versionInfo is not false, only executables with a version
  998. * matching $versionInfo[1] will be returned.
  999. */
  1000. public static function locateExecutable( $path, $names, $versionInfo = false ) {
  1001. if ( !is_array( $names ) ) {
  1002. $names = array( $names );
  1003. }
  1004. foreach ( $names as $name ) {
  1005. $command = $path . DIRECTORY_SEPARATOR . $name;
  1006. wfSuppressWarnings();
  1007. $file_exists = file_exists( $command );
  1008. wfRestoreWarnings();
  1009. if ( $file_exists ) {
  1010. if ( !$versionInfo ) {
  1011. return $command;
  1012. }
  1013. $file = str_replace( '$1', wfEscapeShellArg( $command ), $versionInfo[0] );
  1014. if ( strstr( wfShellExec( $file ), $versionInfo[1] ) !== false ) {
  1015. return $command;
  1016. }
  1017. }
  1018. }
  1019. return false;
  1020. }
  1021. /**
  1022. * Same as locateExecutable(), but checks in getPossibleBinPaths() by default
  1023. * @see locateExecutable()
  1024. * @param $names
  1025. * @param $versionInfo bool
  1026. * @return bool|string
  1027. */
  1028. public static function locateExecutableInDefaultPaths( $names, $versionInfo = false ) {
  1029. foreach( self::getPossibleBinPaths() as $path ) {
  1030. $exe = self::locateExecutable( $path, $names, $versionInfo );
  1031. if( $exe !== false ) {
  1032. return $exe;
  1033. }
  1034. }
  1035. return false;
  1036. }
  1037. /**
  1038. * Checks if scripts located in the given directory can be executed via the given URL.
  1039. *
  1040. * Used only by environment checks.
  1041. */
  1042. public function dirIsExecutable( $dir, $url ) {
  1043. $scriptTypes = array(
  1044. 'php' => array(
  1045. "<?php echo 'ex' . 'ec';",
  1046. "#!/var/env php5\n<?php echo 'ex' . 'ec';",
  1047. ),
  1048. );
  1049. // it would be good to check other popular languages here, but it'll be slow.
  1050. wfSuppressWarnings();
  1051. foreach ( $scriptTypes as $ext => $contents ) {
  1052. foreach ( $contents as $source ) {
  1053. $file = 'exectest.' . $ext;
  1054. if ( !file_put_contents( $dir . $file, $source ) ) {
  1055. break;
  1056. }
  1057. try {
  1058. $text = Http::get( $url . $file, array( 'timeout' => 3 ) );
  1059. }
  1060. catch( MWException $e ) {
  1061. // Http::get throws with allow_url_fopen = false and no curl extension.
  1062. $text = null;
  1063. }
  1064. unlink( $dir . $file );
  1065. if ( $text == 'exec' ) {
  1066. wfRestoreWarnings();
  1067. return $ext;
  1068. }
  1069. }
  1070. }
  1071. wfRestoreWarnings();
  1072. return false;
  1073. }
  1074. /**
  1075. * Checks for presence of an Apache module. Works only if PHP is running as an Apache module, too.
  1076. *
  1077. * @param $moduleName String: Name of module to check.
  1078. * @return bool
  1079. */
  1080. public static function apacheModulePresent( $moduleName ) {
  1081. if ( function_exists( 'apache_get_modules' ) && in_array( $moduleName, apache_get_modules() ) ) {
  1082. return true;
  1083. }
  1084. // try it the hard way
  1085. ob_start();
  1086. phpinfo( INFO_MODULES );
  1087. $info = ob_get_clean();
  1088. return strpos( $info, $moduleName ) !== false;
  1089. }
  1090. /**
  1091. * ParserOptions are constructed before we determined the language, so fix it
  1092. *
  1093. * @param $lang Language
  1094. */
  1095. public function setParserLanguage( $lang ) {
  1096. $this->parserOptions->setTargetLanguage( $lang );
  1097. $this->parserOptions->setUserLang( $lang );
  1098. }
  1099. /**
  1100. * Overridden by WebInstaller to provide lastPage parameters.
  1101. * @param $page string
  1102. * @return string
  1103. */
  1104. protected function getDocUrl( $page ) {
  1105. return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
  1106. }
  1107. /**
  1108. * Finds extensions that follow the format /extensions/Name/Name.php,
  1109. * and returns an array containing the value for 'Name' for each found extension.
  1110. *
  1111. * @return array
  1112. */
  1113. public function findExtensions() {
  1114. if( $this->getVar( 'IP' ) === null ) {
  1115. return false;
  1116. }
  1117. $exts = array();
  1118. $extDir = $this->getVar( 'IP' ) . '/extensions';
  1119. $dh = opendir( $extDir );
  1120. while ( ( $file = readdir( $dh ) ) !== false ) {
  1121. if( !is_dir( "$extDir/$file" ) ) {
  1122. continue;
  1123. }
  1124. if( file_exists( "$extDir/$file/$file.php" ) ) {
  1125. $exts[] = $file;
  1126. }
  1127. }
  1128. natcasesort( $exts );
  1129. return $exts;
  1130. }
  1131. /**
  1132. * Installs the auto-detected extensions.
  1133. *
  1134. * @return Status
  1135. */
  1136. protected function includeExtensions() {
  1137. global $IP;
  1138. $exts = $this->getVar( '_Extensions' );
  1139. $IP = $this->getVar( 'IP' );
  1140. /**
  1141. * We need to include DefaultSettings before including extensions to avoid
  1142. * warnings about unset variables. However, the only thing we really
  1143. * want here is $wgHooks['LoadExtensionSchemaUpdates']. This won't work
  1144. * if the extension has hidden hook registration in $wgExtensionFunctions,
  1145. * but we're not opening that can of worms
  1146. * @see https://bugzilla.wikimedia.org/show_bug.cgi?id=26857
  1147. */
  1148. global $wgAutoloadClasses;
  1149. $wgAutoloadClasses = array();
  1150. require( "$IP/includes/DefaultSettings.php" );
  1151. foreach( $exts as $e ) {
  1152. require_once( "$IP/extensions/$e/$e.php" );
  1153. }
  1154. $hooksWeWant = isset( $wgHooks['LoadExtensionSchemaUpdates'] ) ?
  1155. $wgHooks['LoadExtensionSchemaUpdates'] : array();
  1156. // Unset everyone else's hooks. Lord knows what someone might be doing
  1157. // in ParserFirstCallInit (see bug 27171)
  1158. $GLOBALS['wgHooks'] = array( 'LoadExtensionSchemaUpdates' => $hooksWeWant );
  1159. return Status::newGood();
  1160. }
  1161. /**
  1162. * Get an array of install steps. Should always be in the format of
  1163. * array(
  1164. * 'name' => 'someuniquename',
  1165. * 'callback' => array( $obj, 'method' ),
  1166. * )
  1167. * There must be a config-install-$name message defined per step, which will
  1168. * be shown on install.
  1169. *
  1170. * @param $installer DatabaseInstaller so we can make callbacks
  1171. * @return array
  1172. */
  1173. protected function getInstallSteps( DatabaseInstaller $installer ) {
  1174. $coreInstallSteps = array(
  1175. array( 'name' => 'database', 'callback' => array( $installer, 'setupDatabase' ) ),
  1176. array( 'name' => 'tables', 'callback' => array( $installer, 'createTables' ) ),
  1177. array( 'name' => 'interwiki', 'callback' => array( $installer, 'populateInterwikiTable' ) ),
  1178. array( 'name' => 'stats', 'callback' => array( $this, 'populateSiteStats' ) ),
  1179. array( 'name' => 'keys', 'callback' => array( $this, 'generateKeys' ) ),
  1180. array( 'name' => 'sysop', 'callback' => array( $this, 'createSysop' ) ),
  1181. array( 'name' => 'mainpage', 'callback' => array( $this, 'createMainpage' ) ),
  1182. );
  1183. // Build the array of install steps starting from the core install list,
  1184. // then adding any callbacks that wanted to attach after a given step
  1185. foreach( $coreInstallSteps as $step ) {
  1186. $this->installSteps[] = $step;
  1187. if( isset( $this->extraInstallSteps[ $step['name'] ] ) ) {
  1188. $this->installSteps = array_merge(
  1189. $this->installSteps,
  1190. $this->extraInstallSteps[ $step['name'] ]
  1191. );
  1192. }
  1193. }
  1194. // Prepend any steps that want to be at the beginning
  1195. if( isset( $this->extraInstallSteps['BEGINNING'] ) ) {
  1196. $this->installSteps = array_merge(
  1197. $this->extraInstallSteps['BEGINNING'],
  1198. $this->installSteps
  1199. );
  1200. }
  1201. // Extensions should always go first, chance to tie into hooks and such
  1202. if( count( $this->getVar( '_Extensions' ) ) ) {
  1203. array_unshift( $this->installSteps,
  1204. array( 'name' => 'extensions', 'callback' => array( $this, 'includeExtensions' ) )
  1205. );
  1206. $this->installSteps[] = array(
  1207. 'name' => 'extension-tables',
  1208. 'callback' => array( $installer, 'createExtensionTables' )
  1209. );
  1210. }
  1211. return $this->installSteps;
  1212. }
  1213. /**
  1214. * Actually perform the installation.
  1215. *
  1216. * @param $startCB Array A callback array for the beginning of each step
  1217. * @param $endCB Array A callback array for the end of each step
  1218. *
  1219. * @return Array of Status objects
  1220. */
  1221. public function performInstallation( $startCB, $endCB ) {
  1222. $installResults = array();
  1223. $installer = $this->getDBInstaller();
  1224. $installer->preInstall();
  1225. $steps = $this->getInstallSteps( $installer );
  1226. foreach( $steps as $stepObj ) {
  1227. $name = $stepObj['name'];
  1228. call_user_func_array( $startCB, array( $name ) );
  1229. // Perform the callback step
  1230. $status = call_user_func( $stepObj['callback'], $installer );
  1231. // Output and save the results
  1232. call_user_func( $endCB, $name, $status );
  1233. $installResults[$name] = $status;
  1234. // If we've hit some sort of fatal, we need to bail.
  1235. // Callback already had a chance to do output above.
  1236. if( !$status->isOk() ) {
  1237. break;
  1238. }
  1239. }
  1240. if( $status->isOk() ) {
  1241. $this->setVar( '_InstallDone', true );
  1242. }
  1243. return $installResults;
  1244. }
  1245. /**
  1246. * Generate $wgSecretKey. Will warn if we had to use an insecure random source.
  1247. *
  1248. * @return Status
  1249. */
  1250. public function generateKeys() {
  1251. $keys = array( 'wgSecretKey' => 64 );
  1252. if ( strval( $this->getVar( 'wgUpgradeKey' ) ) === '' ) {
  1253. $keys['wgUpgradeKey'] = 16;
  1254. }
  1255. return $this->doGenerateKeys( $keys );
  1256. }
  1257. /**
  1258. * Generate a secret value for variables using our CryptRand generator.
  1259. * Produce a warning if the random source was insecure.
  1260. *
  1261. * @param $keys Array
  1262. * @return Status
  1263. */
  1264. protected function doGenerateKeys( $keys ) {
  1265. $status = Status::newGood();
  1266. $strong = true;
  1267. foreach ( $keys as $name => $length ) {
  1268. $secretKey = MWCryptRand::generateHex( $length, true );
  1269. if ( !MWCryptRand::wasStrong() ) {
  1270. $strong = false;
  1271. }
  1272. $this->setVar( $name, $secretKey );
  1273. }
  1274. if ( !$strong ) {
  1275. $names = array_keys( $keys );
  1276. $names = preg_replace( '/^(.*)$/', '\$$1', $names );
  1277. global $wgLang;
  1278. $status->warning( 'config-insecure-keys', $wgLang->listToText( $names ), count( $names ) );
  1279. }
  1280. return $status;
  1281. }
  1282. /**
  1283. * Create the first user account, grant it sysop and bureaucrat rights
  1284. *
  1285. * @return Status
  1286. */
  1287. protected function createSysop() {
  1288. $name = $this->getVar( '_AdminName' );
  1289. $user = User::newFromName( $name );
  1290. if ( !$user ) {
  1291. // We should've validated this earlier anyway!
  1292. return Status::newFatal( 'config-admin-error-user', $name );
  1293. }
  1294. if ( $user->idForName() == 0 ) {
  1295. $user->addToDatabase();
  1296. try {
  1297. $user->setPassword( $this->getVar( '_AdminPassword' ) );
  1298. } catch( PasswordError $pwe ) {
  1299. return Status::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
  1300. }
  1301. $user->addGroup( 'sysop' );
  1302. $user->addGroup( 'bureaucrat' );
  1303. if( $this->getVar( '_AdminEmail' ) ) {
  1304. $user->setEmail( $this->getVar( '_AdminEmail' ) );
  1305. }
  1306. $user->saveSettings();
  1307. // Update user count
  1308. $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
  1309. $ssUpdate->doUpdate();
  1310. }
  1311. $status = Status::newGood();
  1312. if( $this->getVar( '_Subscribe' ) && $this->getVar( '_AdminEmail' ) ) {
  1313. $this->subscribeToMediaWikiAnnounce( $status );
  1314. }
  1315. return $status;
  1316. }
  1317. /**
  1318. * @param $s Status
  1319. */
  1320. private function subscribeToMediaWikiAnnounce( Status $s ) {
  1321. $params = array(
  1322. 'email' => $this->getVar( '_AdminEmail' ),
  1323. 'language' => 'en',
  1324. 'digest' => 0
  1325. );
  1326. // Mailman doesn't support as many languages as we do, so check to make
  1327. // sure their selected language is available
  1328. $myLang = $this->getVar( '_UserLang' );
  1329. if( in_array( $myLang, $this->mediaWikiAnnounceLanguages ) ) {
  1330. $myLang = $myLang == 'pt-br' ? 'pt_BR' : $myLang; // rewrite to Mailman's pt_BR
  1331. $params['language'] = $myLang;
  1332. }
  1333. if( MWHttpRequest::canMakeRequests() ) {
  1334. $res = MWHttpRequest::factory( $this->mediaWikiAnnounceUrl,
  1335. array( 'method' => 'POST', 'postData' => $params ) )->execute();
  1336. if( !$res->isOK() ) {
  1337. $s->warning( 'config-install-subscribe-fail', $res->getMessage() );
  1338. }
  1339. } else {
  1340. $s->warning( 'config-install-subscribe-notpossible' );
  1341. }
  1342. }
  1343. /**
  1344. * Insert Main Page with default content.
  1345. *
  1346. * @param $installer DatabaseInstaller
  1347. * @return Status
  1348. */
  1349. protected function createMainpage( DatabaseInstaller $installer ) {
  1350. $status = Status::newGood();
  1351. try {
  1352. $page = WikiPage::factory( Title::newMainPage() );
  1353. $page->doEdit( wfMsgForContent( 'mainpagetext' ) . "\n\n" .
  1354. wfMsgForContent( 'mainpagedocfooter' ),
  1355. '',
  1356. EDIT_NEW,
  1357. false,
  1358. User::newFromName( 'MediaWiki default' ) );
  1359. } catch (MWException $e) {
  1360. //using raw, because $wgShowExceptionDetails can not be set yet
  1361. $status->fatal( 'config-install-mainpage-failed', $e->getMessage() );
  1362. }
  1363. return $status;
  1364. }
  1365. /**
  1366. * Override the necessary bits of the config to run an installation.
  1367. */
  1368. public static function overrideConfig() {
  1369. define( 'MW_NO_SESSION', 1 );
  1370. // Don't access the database
  1371. $GLOBALS['wgUseDatabaseMessages'] = false;
  1372. // Debug-friendly
  1373. $GLOBALS['wgShowExceptionDetails'] = true;
  1374. // Don't break forms
  1375. $GLOBALS['wgExternalLinkTarget'] = '_blank';
  1376. // Extended debugging
  1377. $GLOBALS['wgShowSQLErrors'] = true;
  1378. $GLOBALS['wgShowDBErrorBacktrace'] = true;
  1379. // Allow multiple ob_flush() calls
  1380. $GLOBALS['wgDisableOutputCompression'] = true;
  1381. // Use a sensible cookie prefix (not my_wiki)
  1382. $GLOBALS['wgCookiePrefix'] = 'mw_installer';
  1383. // Some of the environment checks make shell requests, remove limits
  1384. $GLOBALS['wgMaxShellMemory'] = 0;
  1385. }
  1386. /**
  1387. * Add an installation step following the given step.
  1388. *
  1389. * @param $callback Array A valid installation callback array, in this form:
  1390. * array( 'name' => 'some-unique-name', 'callback' => array( $obj, 'function' ) );
  1391. * @param $findStep String the step to find. Omit to put the step at the beginning
  1392. */
  1393. public function addInstallStep( $callback, $findStep = 'BEGINNING' ) {
  1394. $this->extraInstallSteps[$findStep][] = $callback;
  1395. }
  1396. /**
  1397. * Disable the time limit for execution.
  1398. * Some long-running pages (Install, Upgrade) will want to do this
  1399. */
  1400. protected function disableTimeLimit() {
  1401. wfSuppressWarnings();
  1402. set_time_limit( 0 );
  1403. wfRestoreWarnings();
  1404. }
  1405. }