| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
namespace MediaWiki\Installer; |
| 28 |
|
| 29 |
use AutoLoader; |
| 30 |
use Exception; |
| 31 |
use ExecutableFinder; |
| 32 |
use GuzzleHttp\Psr7\Header; |
| 33 |
use IntlChar; |
| 34 |
use InvalidArgumentException; |
| 35 |
use LogicException; |
| 36 |
use MediaWiki\Config\Config; |
| 37 |
use MediaWiki\Config\GlobalVarConfig; |
| 38 |
use MediaWiki\Config\HashConfig; |
| 39 |
use MediaWiki\Config\MultiConfig; |
| 40 |
use MediaWiki\Content\WikitextContent; |
| 41 |
use MediaWiki\Context\RequestContext; |
| 42 |
use MediaWiki\Deferred\SiteStatsUpdate; |
| 43 |
use MediaWiki\HookContainer\HookContainer; |
| 44 |
use MediaWiki\HookContainer\StaticHookRegistry; |
| 45 |
use MediaWiki\Interwiki\NullInterwikiLookup; |
| 46 |
use MediaWiki\Language\Language; |
| 47 |
use MediaWiki\MainConfigNames; |
| 48 |
use MediaWiki\MainConfigSchema; |
| 49 |
use MediaWiki\MediaWikiServices; |
| 50 |
use MediaWiki\Parser\Parser; |
| 51 |
use MediaWiki\Parser\ParserOptions; |
| 52 |
use MediaWiki\Registration\ExtensionDependencyError; |
| 53 |
use MediaWiki\Registration\ExtensionProcessor; |
| 54 |
use MediaWiki\Registration\ExtensionRegistry; |
| 55 |
use MediaWiki\Settings\SettingsBuilder; |
| 56 |
use MediaWiki\Status\Status; |
| 57 |
use MediaWiki\StubObject\StubGlobalUser; |
| 58 |
use MediaWiki\Title\Title; |
| 59 |
use MediaWiki\User\Options\StaticUserOptionsLookup; |
| 60 |
use MediaWiki\User\User; |
| 61 |
use MediaWiki\Utils\UrlUtils; |
| 62 |
use MWCryptRand; |
| 63 |
use MWLBFactory; |
| 64 |
use RuntimeException; |
| 65 |
use Wikimedia\AtEase\AtEase; |
| 66 |
use Wikimedia\Message\MessageSpecifier; |
| 67 |
use Wikimedia\ObjectCache\EmptyBagOStuff; |
| 68 |
use Wikimedia\Rdbms\LBFactorySingle; |
| 69 |
use Wikimedia\Services\ServiceDisabledException; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
abstract class Installer { |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
private const MEDIAWIKI_ANNOUNCE_URL = |
| 98 |
'https://lists.wikimedia.org/postorius/lists/mediawiki-announce.lists.wikimedia.org/'; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
protected $settings; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
protected $compiledDBs; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
protected $dbInstallers = []; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
protected $minMemorySize = 50; |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
protected $parserTitle; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
protected $parserOptions; |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
protected static $dbTypes = [ |
| 150 |
'mysql', |
| 151 |
'postgres', |
| 152 |
'sqlite', |
| 153 |
]; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
protected $envChecks = [ |
| 167 |
'envCheckLibicu', |
| 168 |
'envCheckDB', |
| 169 |
'envCheckPCRE', |
| 170 |
'envCheckMemory', |
| 171 |
'envCheckCache', |
| 172 |
'envCheckModSecurity', |
| 173 |
'envCheckDiff3', |
| 174 |
'envCheckGraphics', |
| 175 |
'envCheckGit', |
| 176 |
'envCheckServer', |
| 177 |
'envCheckPath', |
| 178 |
'envCheckUploadsDirectory', |
| 179 |
'envCheckUploadsServerResponse', |
| 180 |
'envCheck64Bit', |
| 181 |
]; |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
protected $envPreps = [ |
| 189 |
'envPrepServer', |
| 190 |
'envPrepPath', |
| 191 |
]; |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
private const DEFAULT_VAR_NAMES = [ |
| 199 |
MainConfigNames::Sitename, |
| 200 |
MainConfigNames::PasswordSender, |
| 201 |
MainConfigNames::LanguageCode, |
| 202 |
MainConfigNames::Localtimezone, |
| 203 |
MainConfigNames::RightsIcon, |
| 204 |
MainConfigNames::RightsText, |
| 205 |
MainConfigNames::RightsUrl, |
| 206 |
MainConfigNames::EnableEmail, |
| 207 |
MainConfigNames::EnableUserEmail, |
| 208 |
MainConfigNames::EnotifUserTalk, |
| 209 |
MainConfigNames::EnotifWatchlist, |
| 210 |
MainConfigNames::EmailAuthentication, |
| 211 |
MainConfigNames::DBname, |
| 212 |
MainConfigNames::DBtype, |
| 213 |
MainConfigNames::Diff3, |
| 214 |
MainConfigNames::ImageMagickConvertCommand, |
| 215 |
MainConfigNames::GitBin, |
| 216 |
MainConfigNames::ScriptPath, |
| 217 |
MainConfigNames::MetaNamespace, |
| 218 |
MainConfigNames::DeletedDirectory, |
| 219 |
MainConfigNames::EnableUploads, |
| 220 |
MainConfigNames::SecretKey, |
| 221 |
MainConfigNames::UseInstantCommons, |
| 222 |
MainConfigNames::UpgradeKey, |
| 223 |
MainConfigNames::DefaultSkin, |
| 224 |
MainConfigNames::Pingback, |
| 225 |
]; |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
protected $internalDefaults = [ |
| 235 |
'_UserLang' => 'en', |
| 236 |
'_Environment' => false, |
| 237 |
'_RaiseMemory' => false, |
| 238 |
'_UpgradeDone' => false, |
| 239 |
'_InstallDone' => false, |
| 240 |
'_Caches' => [], |
| 241 |
'_InstallPassword' => '', |
| 242 |
'_SameAccount' => true, |
| 243 |
'_CreateDBAccount' => false, |
| 244 |
'_NamespaceType' => 'site-name', |
| 245 |
'_AdminName' => '', |
| 246 |
'_AdminPassword' => '', |
| 247 |
'_AdminPasswordConfirm' => '', |
| 248 |
'_AdminEmail' => '', |
| 249 |
'_Subscribe' => false, |
| 250 |
'_SkipOptional' => 'continue', |
| 251 |
'_RightsProfile' => 'wiki', |
| 252 |
'_LicenseCode' => 'none', |
| 253 |
'_CCDone' => false, |
| 254 |
'_Extensions' => [], |
| 255 |
'_Skins' => [], |
| 256 |
'_MemCachedServers' => '', |
| 257 |
'_UpgradeKeySupplied' => false, |
| 258 |
'_ExistingDBSettings' => false, |
| 259 |
'_LogoWordmark' => '', |
| 260 |
'_LogoWordmarkWidth' => 119, |
| 261 |
'_LogoWordmarkHeight' => 18, |
| 262 |
|
| 263 |
'_Logo1x' => '$wgResourceBasePath/resources/assets/change-your-logo.svg', |
| 264 |
'_LogoIcon' => '$wgResourceBasePath/resources/assets/change-your-logo-icon.svg', |
| 265 |
'_LogoTagline' => '', |
| 266 |
'_LogoTaglineWidth' => 117, |
| 267 |
'_LogoTaglineHeight' => 13, |
| 268 |
'_WithDevelopmentSettings' => false, |
| 269 |
'wgAuthenticationTokenVersion' => 1, |
| 270 |
]; |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
private $installSteps = []; |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
protected $extraInstallSteps = []; |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
protected $objectCaches = [ |
| 293 |
'apcu' => 'apcu_fetch', |
| 294 |
]; |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
public $rightsProfiles = [ |
| 302 |
'wiki' => [], |
| 303 |
'no-anon' => [ |
| 304 |
'*' => [ 'edit' => false ] |
| 305 |
], |
| 306 |
'fishbowl' => [ |
| 307 |
'*' => [ |
| 308 |
'createaccount' => false, |
| 309 |
'edit' => false, |
| 310 |
], |
| 311 |
], |
| 312 |
'private' => [ |
| 313 |
'*' => [ |
| 314 |
'createaccount' => false, |
| 315 |
'edit' => false, |
| 316 |
'read' => false, |
| 317 |
], |
| 318 |
], |
| 319 |
]; |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
public $licenses = [ |
| 327 |
'cc-by' => [ |
| 328 |
'url' => 'https://creativecommons.org/licenses/by/4.0/', |
| 329 |
'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by.png', |
| 330 |
], |
| 331 |
'cc-by-sa' => [ |
| 332 |
'url' => 'https://creativecommons.org/licenses/by-sa/4.0/', |
| 333 |
'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by-sa.png', |
| 334 |
], |
| 335 |
'cc-by-nc-sa' => [ |
| 336 |
'url' => 'https://creativecommons.org/licenses/by-nc-sa/4.0/', |
| 337 |
'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by-nc-sa.png', |
| 338 |
], |
| 339 |
'cc-0' => [ |
| 340 |
'url' => 'https://creativecommons.org/publicdomain/zero/1.0/', |
| 341 |
'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-0.png', |
| 342 |
], |
| 343 |
'gfdl' => [ |
| 344 |
'url' => 'https://www.gnu.org/copyleft/fdl.html', |
| 345 |
'icon' => '$wgResourceBasePath/resources/assets/licenses/gnu-fdl.png', |
| 346 |
], |
| 347 |
'none' => [ |
| 348 |
'url' => '', |
| 349 |
'icon' => '', |
| 350 |
'text' => '' |
| 351 |
], |
| 352 |
]; |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
protected $autoExtensionHookContainer; |
| 358 |
protected array $virtualDomains = []; |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
abstract public function showMessage( $msg, ...$params ); |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
abstract public function showSuccess( $msg, ...$params ); |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
abstract public function showWarning( $msg, ...$params ); |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
abstract public function showError( $msg, ...$params ); |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
abstract public function showStatusMessage( Status $status ); |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
public static function getInstallerConfig( Config $baseConfig ) { |
| 417 |
$configOverrides = new HashConfig(); |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
$emptyCache = [ 'class' => EmptyBagOStuff::class ]; |
| 422 |
|
| 423 |
$objectCaches = [ |
| 424 |
CACHE_NONE => $emptyCache, |
| 425 |
CACHE_DB => $emptyCache, |
| 426 |
CACHE_ANYTHING => $emptyCache, |
| 427 |
CACHE_MEMCACHED => $emptyCache, |
| 428 |
] + $baseConfig->get( MainConfigNames::ObjectCaches ); |
| 429 |
|
| 430 |
$configOverrides->set( MainConfigNames::ObjectCaches, $objectCaches ); |
| 431 |
|
| 432 |
|
| 433 |
$messageDirs = $baseConfig->get( MainConfigNames::MessagesDirs ); |
| 434 |
$messageDirs['MediaWikiInstaller'] = __DIR__ . '/i18n'; |
| 435 |
|
| 436 |
$configOverrides->set( MainConfigNames::MessagesDirs, $messageDirs ); |
| 437 |
|
| 438 |
$installerConfig = new MultiConfig( [ $configOverrides, $baseConfig ] ); |
| 439 |
|
| 440 |
|
| 441 |
$configRegistry = $baseConfig->get( MainConfigNames::ConfigRegistry ); |
| 442 |
$configRegistry['main'] = static function () use ( $installerConfig ) { |
| 443 |
return $installerConfig; |
| 444 |
}; |
| 445 |
|
| 446 |
$configOverrides->set( MainConfigNames::ConfigRegistry, $configRegistry ); |
| 447 |
|
| 448 |
return $installerConfig; |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
public function __construct() { |
| 455 |
$defaultConfig = new GlobalVarConfig(); |
| 456 |
$installerConfig = self::getInstallerConfig( $defaultConfig ); |
| 457 |
|
| 458 |
|
| 459 |
$this->resetMediaWikiServices( $installerConfig, [], true ); |
| 460 |
|
| 461 |
$this->settings = $this->getDefaultSettings(); |
| 462 |
|
| 463 |
$this->doEnvironmentPreps(); |
| 464 |
|
| 465 |
$this->compiledDBs = []; |
| 466 |
foreach ( self::getDBTypes() as $type ) { |
| 467 |
$installer = $this->getDBInstaller( $type ); |
| 468 |
|
| 469 |
if ( !$installer->isCompiled() ) { |
| 470 |
continue; |
| 471 |
} |
| 472 |
$this->compiledDBs[] = $type; |
| 473 |
} |
| 474 |
|
| 475 |
$this->parserTitle = Title::newFromText( 'Installer' ); |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
private function getDefaultSettings(): array { |
| 482 |
global $wgLocaltimezone; |
| 483 |
|
| 484 |
$ret = $this->internalDefaults; |
| 485 |
|
| 486 |
foreach ( self::DEFAULT_VAR_NAMES as $name ) { |
| 487 |
$var = "wg{$name}"; |
| 488 |
$ret[$var] = MainConfigSchema::getDefaultValue( $name ); |
| 489 |
} |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
$ret['wgLocaltimezone'] = $wgLocaltimezone; |
| 494 |
|
| 495 |
return $ret; |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
public function resetMediaWikiServices( |
| 513 |
?Config $installerConfig = null, |
| 514 |
$serviceOverrides = [], |
| 515 |
bool $disableStorage = false |
| 516 |
) { |
| 517 |
global $wgObjectCaches, $wgLang; |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
MediaWikiServices::resetGlobalInstance( $installerConfig ); |
| 522 |
|
| 523 |
$mwServices = MediaWikiServices::getInstance(); |
| 524 |
|
| 525 |
if ( $disableStorage ) { |
| 526 |
$mwServices->disableStorage(); |
| 527 |
} else { |
| 528 |
|
| 529 |
|
| 530 |
$serviceOverrides += [ |
| 531 |
|
| 532 |
'InterwikiLookup' => static function () { |
| 533 |
return new NullInterwikiLookup(); |
| 534 |
}, |
| 535 |
|
| 536 |
|
| 537 |
'UserOptionsLookup' => static function ( MediaWikiServices $services ) { |
| 538 |
return new StaticUserOptionsLookup( |
| 539 |
[], |
| 540 |
$services->getMainConfig()->get( MainConfigNames::DefaultUserOptions ) |
| 541 |
); |
| 542 |
}, |
| 543 |
|
| 544 |
|
| 545 |
'DBLoadBalancer' => static function ( MediaWikiServices $services ) { |
| 546 |
return $services->getDBLoadBalancerFactory()->getMainLB(); |
| 547 |
}, |
| 548 |
]; |
| 549 |
} |
| 550 |
|
| 551 |
$lang = $this->getVar( '_UserLang', 'en' ); |
| 552 |
|
| 553 |
foreach ( $serviceOverrides as $name => $callback ) { |
| 554 |
|
| 555 |
|
| 556 |
if ( $callback ) { |
| 557 |
$mwServices->redefineService( $name, $callback ); |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
$mwServices->getLocalisationCache()->disableBackend(); |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
$user = User::newFromId( 0 ); |
| 568 |
StubGlobalUser::setUser( $user ); |
| 569 |
|
| 570 |
RequestContext::getMain()->setUser( $user ); |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
RequestContext::getMain()->setLanguage( $lang ); |
| 577 |
$wgLang = RequestContext::getMain()->getLanguage(); |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
$wgObjectCaches = $mwServices->getMainConfig()->get( MainConfigNames::ObjectCaches ); |
| 582 |
|
| 583 |
$this->parserOptions = new ParserOptions( $user ); |
| 584 |
|
| 585 |
$this->setParserLanguage( $mwServices->getLanguageFactory()->getLanguage( 'en' ) ); |
| 586 |
|
| 587 |
return $mwServices; |
| 588 |
} |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
public static function getDBTypes() { |
| 596 |
return self::$dbTypes; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
public function doEnvironmentChecks() { |
| 613 |
|
| 614 |
|
| 615 |
$this->showMessage( 'config-env-php', PHP_VERSION ); |
| 616 |
|
| 617 |
$good = true; |
| 618 |
foreach ( $this->envChecks as $check ) { |
| 619 |
$status = $this->$check(); |
| 620 |
if ( $status === false ) { |
| 621 |
$good = false; |
| 622 |
} |
| 623 |
} |
| 624 |
|
| 625 |
$this->setVar( '_Environment', $good ); |
| 626 |
|
| 627 |
return $good ? Status::newGood() : Status::newFatal( 'config-env-bad' ); |
| 628 |
} |
| 629 |
|
| 630 |
public function doEnvironmentPreps() { |
| 631 |
foreach ( $this->envPreps as $prep ) { |
| 632 |
$this->$prep(); |
| 633 |
} |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
public function setVar( $name, $value ) { |
| 643 |
$this->settings[$name] = $value; |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
public function getVar( $name, $default = null ) { |
| 657 |
return $this->settings[$name] ?? $default; |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
public function getCompiledDBs() { |
| 666 |
return $this->compiledDBs; |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
public static function getDBInstallerClass( $type ) { |
| 677 |
return '\\MediaWiki\\Installer\\' . ucfirst( $type ) . 'Installer'; |
| 678 |
} |
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
public function getDBInstaller( $type = false ) { |
| 688 |
if ( !$type ) { |
| 689 |
$type = $this->getVar( 'wgDBtype' ); |
| 690 |
} |
| 691 |
|
| 692 |
$type = strtolower( $type ); |
| 693 |
|
| 694 |
if ( !isset( $this->dbInstallers[$type] ) ) { |
| 695 |
$class = self::getDBInstallerClass( $type ); |
| 696 |
$this->dbInstallers[$type] = new $class( $this ); |
| 697 |
} |
| 698 |
|
| 699 |
return $this->dbInstallers[$type]; |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
public static function getExistingLocalSettings() { |
| 708 |
$IP = wfDetectInstallPath(); |
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
global $wgAutoloadClasses; |
| 716 |
$wgAutoloadClasses = []; |
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
global $wgExtensionDirectory, $wgStyleDirectory; |
| 722 |
|
| 723 |
|
| 724 |
$lsFile = wfDetectLocalSettingsFile( $IP ); |
| 725 |
|
| 726 |
$lsExists = @file_exists( $lsFile ); |
| 727 |
|
| 728 |
if ( !$lsExists ) { |
| 729 |
return false; |
| 730 |
} |
| 731 |
|
| 732 |
if ( !str_ends_with( $lsFile, '.php' ) ) { |
| 733 |
throw new RuntimeException( |
| 734 |
'The installer cannot yet handle non-php settings files: ' . $lsFile . '. ' . |
| 735 |
'Use `php maintenance/run.php update` to update an existing installation.' |
| 736 |
); |
| 737 |
} |
| 738 |
unset( $lsExists ); |
| 739 |
|
| 740 |
|
| 741 |
foreach ( MainConfigSchema::listDefaultValues( 'wg' ) as $var => $value ) { |
| 742 |
$$var = $value; |
| 743 |
} |
| 744 |
|
| 745 |
$wgExtensionDirectory = "$IP/extensions"; |
| 746 |
$wgStyleDirectory = "$IP/skins"; |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
require $lsFile; |
| 760 |
|
| 761 |
return get_defined_vars(); |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
public function getFakePassword( $realPassword ) { |
| 774 |
return str_repeat( '*', strlen( $realPassword ) ); |
| 775 |
} |
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
public function setPassword( $name, $value ) { |
| 785 |
if ( !preg_match( '/^\*+$/', $value ) ) { |
| 786 |
$this->setVar( $name, $value ); |
| 787 |
} |
| 788 |
} |
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
public static function maybeGetWebserverPrimaryGroup() { |
| 802 |
if ( !function_exists( 'posix_getegid' ) || !function_exists( 'posix_getpwuid' ) ) { |
| 803 |
|
| 804 |
return null; |
| 805 |
} |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
$gid = posix_getegid(); |
| 810 |
return posix_getpwuid( $gid )['name'] ?? null; |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
public function parse( $text, $lineStart = false ) { |
| 830 |
$parser = MediaWikiServices::getInstance()->getParser(); |
| 831 |
|
| 832 |
try { |
| 833 |
$out = $parser->parse( $text, $this->parserTitle, $this->parserOptions, $lineStart ); |
| 834 |
$pipeline = MediaWikiServices::getInstance()->getDefaultOutputPipeline(); |
| 835 |
|
| 836 |
$html = $pipeline->run( $out, $this->parserOptions, [ |
| 837 |
'enableSectionEditLinks' => false, |
| 838 |
'unwrap' => true, |
| 839 |
] )->getContentHolderText(); |
| 840 |
$html = Parser::stripOuterParagraph( $html ); |
| 841 |
} catch ( ServiceDisabledException $e ) { |
| 842 |
$html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text ); |
| 843 |
} |
| 844 |
|
| 845 |
return $html; |
| 846 |
} |
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
public function getParserOptions() { |
| 852 |
return $this->parserOptions; |
| 853 |
} |
| 854 |
|
| 855 |
public function disableLinkPopups() { |
| 856 |
|
| 857 |
|
| 858 |
$this->parserOptions->setExternalLinkTarget( false ); |
| 859 |
} |
| 860 |
|
| 861 |
public function restoreLinkPopups() { |
| 862 |
|
| 863 |
|
| 864 |
global $wgExternalLinkTarget; |
| 865 |
$this->parserOptions->setExternalLinkTarget( $wgExternalLinkTarget ); |
| 866 |
} |
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
public function populateSiteStats( DatabaseInstaller $installer ) { |
| 877 |
$status = $installer->getConnection( DatabaseInstaller::CONN_CREATE_TABLES ); |
| 878 |
if ( !$status->isOK() ) { |
| 879 |
return $status; |
| 880 |
} |
| 881 |
$status->getDB()->newInsertQueryBuilder() |
| 882 |
->insertInto( 'site_stats' ) |
| 883 |
->ignore() |
| 884 |
->row( [ |
| 885 |
'ss_row_id' => 1, |
| 886 |
'ss_total_edits' => 0, |
| 887 |
'ss_good_articles' => 0, |
| 888 |
'ss_total_pages' => 0, |
| 889 |
'ss_users' => 0, |
| 890 |
'ss_active_users' => 0, |
| 891 |
'ss_images' => 0 |
| 892 |
] ) |
| 893 |
->caller( __METHOD__ ) |
| 894 |
->execute(); |
| 895 |
|
| 896 |
return Status::newGood(); |
| 897 |
} |
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
protected function envCheckDB() { |
| 904 |
global $wgLang; |
| 905 |
|
| 906 |
$dbType = $this->getVar( 'wgDBtype' ); |
| 907 |
|
| 908 |
$allNames = []; |
| 909 |
|
| 910 |
|
| 911 |
foreach ( self::getDBTypes() as $name ) { |
| 912 |
$allNames[] = wfMessage( "config-type-$name" )->text(); |
| 913 |
} |
| 914 |
|
| 915 |
$databases = $this->getCompiledDBs(); |
| 916 |
|
| 917 |
$databases = array_flip( $databases ); |
| 918 |
$ok = true; |
| 919 |
foreach ( $databases as $db => $_ ) { |
| 920 |
$installer = $this->getDBInstaller( $db ); |
| 921 |
$status = $installer->checkPrerequisites(); |
| 922 |
if ( !$status->isGood() ) { |
| 923 |
if ( !$this instanceof WebInstaller && $db === $dbType ) { |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
$ok = false; |
| 928 |
} |
| 929 |
$this->showStatusMessage( $status ); |
| 930 |
unset( $databases[$db] ); |
| 931 |
} |
| 932 |
} |
| 933 |
$databases = array_flip( $databases ); |
| 934 |
if ( !$databases ) { |
| 935 |
$this->showError( 'config-no-db', $wgLang->commaList( $allNames ), count( $allNames ) ); |
| 936 |
return false; |
| 937 |
} |
| 938 |
return $ok; |
| 939 |
} |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
protected function envCheckPCRE() { |
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
if ( preg_match( '/^b.*c$/', 'bÄ…c' ) === 0 ) { |
| 955 |
$this->showError( 'config-pcre-invalid-newline' ); |
| 956 |
return false; |
| 957 |
} |
| 958 |
return true; |
| 959 |
} |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
protected function envCheckMemory() { |
| 966 |
$limit = ini_get( 'memory_limit' ); |
| 967 |
|
| 968 |
if ( !$limit || $limit == -1 ) { |
| 969 |
return true; |
| 970 |
} |
| 971 |
|
| 972 |
$n = wfShorthandToInteger( $limit ); |
| 973 |
|
| 974 |
if ( $n < $this->minMemorySize * 1024 * 1024 ) { |
| 975 |
$newLimit = "{$this->minMemorySize}M"; |
| 976 |
|
| 977 |
if ( ini_set( "memory_limit", $newLimit ) === false ) { |
| 978 |
$this->showMessage( 'config-memory-bad', $limit ); |
| 979 |
} else { |
| 980 |
$this->showMessage( 'config-memory-raised', $limit, $newLimit ); |
| 981 |
$this->setVar( '_RaiseMemory', true ); |
| 982 |
} |
| 983 |
} |
| 984 |
|
| 985 |
return true; |
| 986 |
} |
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
protected function envCheckCache() { |
| 992 |
$caches = []; |
| 993 |
foreach ( $this->objectCaches as $name => $function ) { |
| 994 |
if ( function_exists( $function ) ) { |
| 995 |
$caches[$name] = true; |
| 996 |
} |
| 997 |
} |
| 998 |
|
| 999 |
if ( !$caches ) { |
| 1000 |
$this->showMessage( 'config-no-cache-apcu' ); |
| 1001 |
} |
| 1002 |
|
| 1003 |
$this->setVar( '_Caches', $caches ); |
| 1004 |
} |
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
protected function envCheckModSecurity() { |
| 1011 |
if ( self::apacheModulePresent( 'mod_security' ) |
| 1012 |
|| self::apacheModulePresent( 'mod_security2' ) ) { |
| 1013 |
$this->showMessage( 'config-mod-security' ); |
| 1014 |
} |
| 1015 |
|
| 1016 |
return true; |
| 1017 |
} |
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
protected function envCheckDiff3() { |
| 1024 |
$names = [ "gdiff3", "diff3" ]; |
| 1025 |
if ( wfIsWindows() ) { |
| 1026 |
$names[] = 'diff3.exe'; |
| 1027 |
} |
| 1028 |
$versionInfo = [ '--version', 'GNU diffutils' ]; |
| 1029 |
|
| 1030 |
$diff3 = ExecutableFinder::findInDefaultPaths( $names, $versionInfo ); |
| 1031 |
|
| 1032 |
if ( $diff3 ) { |
| 1033 |
$this->setVar( 'wgDiff3', $diff3 ); |
| 1034 |
} else { |
| 1035 |
$this->setVar( 'wgDiff3', false ); |
| 1036 |
$this->showMessage( 'config-diff3-bad' ); |
| 1037 |
} |
| 1038 |
|
| 1039 |
return true; |
| 1040 |
} |
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
protected function envCheckGraphics() { |
| 1047 |
$names = wfIsWindows() ? 'convert.exe' : 'convert'; |
| 1048 |
$versionInfo = [ '-version', 'ImageMagick' ]; |
| 1049 |
$convert = ExecutableFinder::findInDefaultPaths( $names, $versionInfo ); |
| 1050 |
|
| 1051 |
$this->setVar( 'wgImageMagickConvertCommand', '' ); |
| 1052 |
if ( $convert ) { |
| 1053 |
$this->setVar( 'wgImageMagickConvertCommand', $convert ); |
| 1054 |
$this->showMessage( 'config-imagemagick', $convert ); |
| 1055 |
} elseif ( function_exists( 'imagejpeg' ) ) { |
| 1056 |
$this->showMessage( 'config-gd' ); |
| 1057 |
} else { |
| 1058 |
$this->showMessage( 'config-no-scaling' ); |
| 1059 |
} |
| 1060 |
|
| 1061 |
return true; |
| 1062 |
} |
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
protected function envCheckGit() { |
| 1071 |
$names = wfIsWindows() ? 'git.exe' : 'git'; |
| 1072 |
$versionInfo = [ '--version', 'git version' ]; |
| 1073 |
|
| 1074 |
$git = ExecutableFinder::findInDefaultPaths( $names, $versionInfo ); |
| 1075 |
|
| 1076 |
if ( $git ) { |
| 1077 |
$this->setVar( 'wgGitBin', $git ); |
| 1078 |
$this->showMessage( 'config-git', $git ); |
| 1079 |
} else { |
| 1080 |
$this->setVar( 'wgGitBin', false ); |
| 1081 |
$this->showMessage( 'config-git-bad' ); |
| 1082 |
} |
| 1083 |
|
| 1084 |
return true; |
| 1085 |
} |
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
protected function envCheckServer() { |
| 1093 |
$server = $this->envGetDefaultServer(); |
| 1094 |
if ( $server !== null ) { |
| 1095 |
$this->showMessage( 'config-using-server', $server ); |
| 1096 |
} |
| 1097 |
return true; |
| 1098 |
} |
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
protected function envCheckPath() { |
| 1106 |
$this->showMessage( |
| 1107 |
'config-using-uri', |
| 1108 |
$this->getVar( 'wgServer' ), |
| 1109 |
$this->getVar( 'wgScriptPath' ) |
| 1110 |
); |
| 1111 |
return true; |
| 1112 |
} |
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
protected function envCheckUploadsDirectory() { |
| 1119 |
global $IP; |
| 1120 |
|
| 1121 |
$dir = $IP . '/images/'; |
| 1122 |
$url = $this->getVar( 'wgServer' ) . $this->getVar( 'wgScriptPath' ) . '/images/'; |
| 1123 |
$safe = !$this->dirIsExecutable( $dir, $url ); |
| 1124 |
|
| 1125 |
if ( !$safe ) { |
| 1126 |
$this->showWarning( 'config-uploads-not-safe', $dir ); |
| 1127 |
} |
| 1128 |
|
| 1129 |
return true; |
| 1130 |
} |
| 1131 |
|
| 1132 |
protected function envCheckUploadsServerResponse() { |
| 1133 |
$url = $this->getVar( 'wgServer' ) . $this->getVar( 'wgScriptPath' ) . '/images/README'; |
| 1134 |
$httpRequestFactory = MediaWikiServices::getInstance()->getHttpRequestFactory(); |
| 1135 |
$status = null; |
| 1136 |
|
| 1137 |
$req = $httpRequestFactory->create( |
| 1138 |
$url, |
| 1139 |
[ |
| 1140 |
'method' => 'GET', |
| 1141 |
'timeout' => 3, |
| 1142 |
'followRedirects' => true |
| 1143 |
], |
| 1144 |
__METHOD__ |
| 1145 |
); |
| 1146 |
try { |
| 1147 |
$status = $req->execute(); |
| 1148 |
} catch ( Exception $e ) { |
| 1149 |
|
| 1150 |
|
| 1151 |
} |
| 1152 |
|
| 1153 |
if ( !$status || !$status->isGood() ) { |
| 1154 |
$this->showWarning( 'config-uploads-security-requesterror', 'X-Content-Type-Options: nosniff' ); |
| 1155 |
return true; |
| 1156 |
} |
| 1157 |
|
| 1158 |
$headerValue = $req->getResponseHeader( 'X-Content-Type-Options' ) ?? ''; |
| 1159 |
$responseList = Header::splitList( $headerValue ); |
| 1160 |
if ( !in_array( 'nosniff', $responseList, true ) ) { |
| 1161 |
$this->showWarning( 'config-uploads-security-headers', 'X-Content-Type-Options: nosniff' ); |
| 1162 |
} |
| 1163 |
|
| 1164 |
return true; |
| 1165 |
} |
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
protected function envCheck64Bit() { |
| 1174 |
if ( PHP_INT_SIZE == 4 ) { |
| 1175 |
$this->showMessage( 'config-using-32bit' ); |
| 1176 |
} |
| 1177 |
|
| 1178 |
return true; |
| 1179 |
} |
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
protected function envCheckLibicu() { |
| 1185 |
$unicodeVersion = implode( '.', array_slice( IntlChar::getUnicodeVersion(), 0, 3 ) ); |
| 1186 |
$this->showMessage( 'config-env-icu', INTL_ICU_VERSION, $unicodeVersion ); |
| 1187 |
} |
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
protected function envPrepServer() { |
| 1193 |
$server = $this->envGetDefaultServer(); |
| 1194 |
if ( $server !== null ) { |
| 1195 |
$this->setVar( 'wgServer', $server ); |
| 1196 |
} |
| 1197 |
} |
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
abstract protected function envGetDefaultServer(); |
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
protected function envPrepPath() { |
| 1209 |
global $IP; |
| 1210 |
$IP = dirname( dirname( __DIR__ ) ); |
| 1211 |
$this->setVar( 'IP', $IP ); |
| 1212 |
} |
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
public function dirIsExecutable( $dir, $url ) { |
| 1223 |
$scriptTypes = [ |
| 1224 |
'php' => [ |
| 1225 |
"<?php echo 'exec';", |
| 1226 |
"#!/var/env php\n<?php echo 'exec';", |
| 1227 |
], |
| 1228 |
]; |
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
$httpRequestFactory = MediaWikiServices::getInstance()->getHttpRequestFactory(); |
| 1234 |
|
| 1235 |
AtEase::suppressWarnings(); |
| 1236 |
|
| 1237 |
foreach ( $scriptTypes as $ext => $contents ) { |
| 1238 |
foreach ( $contents as $source ) { |
| 1239 |
$file = 'exectest.' . $ext; |
| 1240 |
|
| 1241 |
if ( !file_put_contents( $dir . $file, $source ) ) { |
| 1242 |
break; |
| 1243 |
} |
| 1244 |
|
| 1245 |
try { |
| 1246 |
$text = $httpRequestFactory->get( |
| 1247 |
$url . $file, |
| 1248 |
[ 'timeout' => 3 ], |
| 1249 |
__METHOD__ |
| 1250 |
); |
| 1251 |
} catch ( Exception $e ) { |
| 1252 |
|
| 1253 |
|
| 1254 |
$text = null; |
| 1255 |
} |
| 1256 |
unlink( $dir . $file ); |
| 1257 |
|
| 1258 |
if ( $text == 'exec' ) { |
| 1259 |
AtEase::restoreWarnings(); |
| 1260 |
|
| 1261 |
return $ext; |
| 1262 |
} |
| 1263 |
} |
| 1264 |
} |
| 1265 |
|
| 1266 |
AtEase::restoreWarnings(); |
| 1267 |
|
| 1268 |
return false; |
| 1269 |
} |
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
public static function apacheModulePresent( $moduleName ) { |
| 1278 |
if ( function_exists( 'apache_get_modules' ) && in_array( $moduleName, apache_get_modules() ) ) { |
| 1279 |
return true; |
| 1280 |
} |
| 1281 |
|
| 1282 |
ob_start(); |
| 1283 |
phpinfo( INFO_MODULES ); |
| 1284 |
$info = ob_get_clean(); |
| 1285 |
|
| 1286 |
return strpos( $info, $moduleName ) !== false; |
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
public function setParserLanguage( $lang ) { |
| 1295 |
$this->parserOptions->setTargetLanguage( $lang ); |
| 1296 |
$this->parserOptions->setUserLang( $lang ); |
| 1297 |
} |
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
protected function getDocUrl( $page ) { |
| 1305 |
return "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page ); |
| 1306 |
} |
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
public function findExtensions( $directory = 'extensions' ) { |
| 1318 |
switch ( $directory ) { |
| 1319 |
case 'extensions': |
| 1320 |
return $this->findExtensionsByType( 'extension', 'extensions' ); |
| 1321 |
case 'skins': |
| 1322 |
return $this->findExtensionsByType( 'skin', 'skins' ); |
| 1323 |
default: |
| 1324 |
throw new InvalidArgumentException( "Invalid extension type" ); |
| 1325 |
} |
| 1326 |
} |
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
protected function findExtensionsByType( $type = 'extension', $directory = 'extensions' ) { |
| 1338 |
if ( $this->getVar( 'IP' ) === null ) { |
| 1339 |
return Status::newGood( [] ); |
| 1340 |
} |
| 1341 |
|
| 1342 |
$extDir = $this->getVar( 'IP' ) . '/' . $directory; |
| 1343 |
if ( !is_readable( $extDir ) || !is_dir( $extDir ) ) { |
| 1344 |
return Status::newGood( [] ); |
| 1345 |
} |
| 1346 |
|
| 1347 |
$dh = opendir( $extDir ); |
| 1348 |
$exts = []; |
| 1349 |
$status = new Status; |
| 1350 |
|
| 1351 |
while ( ( $file = readdir( $dh ) ) !== false ) { |
| 1352 |
|
| 1353 |
if ( !is_dir( "$extDir/$file" ) || $file[0] === '.' ) { |
| 1354 |
continue; |
| 1355 |
} |
| 1356 |
$extStatus = $this->getExtensionInfo( $type, $directory, $file ); |
| 1357 |
if ( $extStatus->isOK() ) { |
| 1358 |
$exts[$file] = $extStatus->value; |
| 1359 |
} elseif ( $extStatus->hasMessage( 'config-extension-not-found' ) ) { |
| 1360 |
|
| 1361 |
$status->warning( 'config-extension-not-found', $file ); |
| 1362 |
} else { |
| 1363 |
$status->merge( $extStatus ); |
| 1364 |
} |
| 1365 |
} |
| 1366 |
closedir( $dh ); |
| 1367 |
uksort( $exts, 'strnatcasecmp' ); |
| 1368 |
|
| 1369 |
$status->value = $exts; |
| 1370 |
|
| 1371 |
return $status; |
| 1372 |
} |
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
protected function getExtensionInfo( $type, $parentRelPath, $name ) { |
| 1382 |
if ( $this->getVar( 'IP' ) === null ) { |
| 1383 |
throw new RuntimeException( 'Cannot find extensions since the IP variable is not yet set' ); |
| 1384 |
} |
| 1385 |
if ( $type !== 'extension' && $type !== 'skin' ) { |
| 1386 |
throw new InvalidArgumentException( "Invalid extension type" ); |
| 1387 |
} |
| 1388 |
$absDir = $this->getVar( 'IP' ) . "/$parentRelPath/$name"; |
| 1389 |
$relDir = "../$parentRelPath/$name"; |
| 1390 |
if ( !is_dir( $absDir ) ) { |
| 1391 |
return Status::newFatal( 'config-extension-not-found', $name ); |
| 1392 |
} |
| 1393 |
$jsonFile = $type . '.json'; |
| 1394 |
$fullJsonFile = "$absDir/$jsonFile"; |
| 1395 |
$isJson = file_exists( $fullJsonFile ); |
| 1396 |
$isPhp = false; |
| 1397 |
if ( !$isJson ) { |
| 1398 |
|
| 1399 |
$fullPhpFile = "$absDir/$name.php"; |
| 1400 |
$isPhp = file_exists( $fullPhpFile ); |
| 1401 |
} |
| 1402 |
if ( !$isJson && !$isPhp ) { |
| 1403 |
return Status::newFatal( 'config-extension-not-found', $name ); |
| 1404 |
} |
| 1405 |
|
| 1406 |
|
| 1407 |
$info = []; |
| 1408 |
if ( is_dir( "$absDir/screenshots" ) ) { |
| 1409 |
$paths = glob( "$absDir/screenshots/*.png" ); |
| 1410 |
foreach ( $paths as $path ) { |
| 1411 |
$info['screenshots'][] = str_replace( $absDir, $relDir, $path ); |
| 1412 |
} |
| 1413 |
} |
| 1414 |
|
| 1415 |
if ( $isJson ) { |
| 1416 |
$jsonStatus = $this->readExtension( $fullJsonFile ); |
| 1417 |
if ( !$jsonStatus->isOK() ) { |
| 1418 |
return $jsonStatus; |
| 1419 |
} |
| 1420 |
$info += $jsonStatus->value; |
| 1421 |
} |
| 1422 |
|
| 1423 |
return Status::newGood( $info ); |
| 1424 |
} |
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
private function readExtension( $fullJsonFile, $extDeps = [], $skinDeps = [] ) { |
| 1435 |
$load = [ |
| 1436 |
$fullJsonFile => 1 |
| 1437 |
]; |
| 1438 |
if ( $extDeps ) { |
| 1439 |
$extDir = $this->getVar( 'IP' ) . '/extensions'; |
| 1440 |
foreach ( $extDeps as $dep ) { |
| 1441 |
$fname = "$extDir/$dep/extension.json"; |
| 1442 |
if ( !file_exists( $fname ) ) { |
| 1443 |
return Status::newFatal( 'config-extension-not-found', $dep ); |
| 1444 |
} |
| 1445 |
$load[$fname] = 1; |
| 1446 |
} |
| 1447 |
} |
| 1448 |
if ( $skinDeps ) { |
| 1449 |
$skinDir = $this->getVar( 'IP' ) . '/skins'; |
| 1450 |
foreach ( $skinDeps as $dep ) { |
| 1451 |
$fname = "$skinDir/$dep/skin.json"; |
| 1452 |
if ( !file_exists( $fname ) ) { |
| 1453 |
return Status::newFatal( 'config-extension-not-found', $dep ); |
| 1454 |
} |
| 1455 |
$load[$fname] = 1; |
| 1456 |
} |
| 1457 |
} |
| 1458 |
$registry = new ExtensionRegistry(); |
| 1459 |
try { |
| 1460 |
$info = $registry->readFromQueue( $load ); |
| 1461 |
} catch ( ExtensionDependencyError $e ) { |
| 1462 |
if ( $e->incompatibleCore || $e->incompatibleSkins |
| 1463 |
|| $e->incompatibleExtensions |
| 1464 |
) { |
| 1465 |
|
| 1466 |
|
| 1467 |
return Status::newFatal( 'config-extension-dependency', |
| 1468 |
basename( dirname( $fullJsonFile ) ), $e->getMessage() ); |
| 1469 |
} elseif ( $e->missingExtensions || $e->missingSkins ) { |
| 1470 |
|
| 1471 |
|
| 1472 |
$status = $this->readExtension( |
| 1473 |
$fullJsonFile, |
| 1474 |
array_merge( $extDeps, $e->missingExtensions ), |
| 1475 |
array_merge( $skinDeps, $e->missingSkins ) |
| 1476 |
); |
| 1477 |
if ( !$status->isOK() && !$status->hasMessage( 'config-extension-dependency' ) ) { |
| 1478 |
$status = Status::newFatal( 'config-extension-dependency', |
| 1479 |
basename( dirname( $fullJsonFile ) ), $status->getMessage() ); |
| 1480 |
} |
| 1481 |
return $status; |
| 1482 |
} |
| 1483 |
|
| 1484 |
return Status::newFatal( 'config-extension-dependency', |
| 1485 |
basename( dirname( $fullJsonFile ) ), $e->getMessage() ); |
| 1486 |
} |
| 1487 |
$ret = []; |
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
$i = 0; |
| 1492 |
foreach ( $info['credits'] as $credit ) { |
| 1493 |
$i++; |
| 1494 |
if ( $i == 1 ) { |
| 1495 |
|
| 1496 |
continue; |
| 1497 |
} |
| 1498 |
$type = basename( $credit['path'] ) === 'skin.json' ? 'skins' : 'extensions'; |
| 1499 |
$ret['requires'][$type][] = $credit['name']; |
| 1500 |
} |
| 1501 |
$credits = array_values( $info['credits'] )[0]; |
| 1502 |
if ( isset( $credits['url'] ) ) { |
| 1503 |
$ret['url'] = $credits['url']; |
| 1504 |
} |
| 1505 |
$ret['type'] = $credits['type']; |
| 1506 |
|
| 1507 |
return Status::newGood( $ret ); |
| 1508 |
} |
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
public function getDefaultSkin( array $skinNames ) { |
| 1519 |
$defaultSkin = $GLOBALS['wgDefaultSkin']; |
| 1520 |
|
| 1521 |
if ( in_array( 'vector', $skinNames ) ) { |
| 1522 |
$skinNames[] = 'vector-2022'; |
| 1523 |
} |
| 1524 |
|
| 1525 |
|
| 1526 |
if ( in_array( 'minervaneue', $skinNames ) ) { |
| 1527 |
$minervaNeue = array_search( 'minervaneue', $skinNames ); |
| 1528 |
$skinNames[$minervaNeue] = 'minerva'; |
| 1529 |
} |
| 1530 |
|
| 1531 |
if ( !$skinNames || in_array( $defaultSkin, $skinNames ) ) { |
| 1532 |
return $defaultSkin; |
| 1533 |
} else { |
| 1534 |
return $skinNames[0]; |
| 1535 |
} |
| 1536 |
} |
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
protected function includeExtensions() { |
| 1544 |
|
| 1545 |
|
| 1546 |
define( 'MW_EXTENSIONS_LOADED', true ); |
| 1547 |
|
| 1548 |
$legacySchemaHooks = $this->getAutoExtensionLegacyHooks(); |
| 1549 |
$data = $this->getAutoExtensionData(); |
| 1550 |
if ( isset( $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ) ) { |
| 1551 |
$legacySchemaHooks = array_merge( $legacySchemaHooks, |
| 1552 |
$data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ); |
| 1553 |
} |
| 1554 |
$extDeprecatedHooks = $data['attributes']['DeprecatedHooks'] ?? []; |
| 1555 |
|
| 1556 |
$this->autoExtensionHookContainer = new HookContainer( |
| 1557 |
new StaticHookRegistry( |
| 1558 |
[ 'LoadExtensionSchemaUpdates' => $legacySchemaHooks ], |
| 1559 |
$data['attributes']['Hooks'] ?? [], |
| 1560 |
$extDeprecatedHooks |
| 1561 |
), |
| 1562 |
MediaWikiServices::getInstance()->getObjectFactory() |
| 1563 |
); |
| 1564 |
$this->virtualDomains = $data['attributes']['DatabaseVirtualDomains'] ?? []; |
| 1565 |
|
| 1566 |
return Status::newGood(); |
| 1567 |
} |
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
protected function getAutoExtensionLegacyHooks() { |
| 1577 |
$exts = $this->getVar( '_Extensions' ); |
| 1578 |
$installPath = $this->getVar( 'IP' ); |
| 1579 |
$files = []; |
| 1580 |
foreach ( $exts as $e ) { |
| 1581 |
if ( file_exists( "$installPath/extensions/$e/$e.php" ) ) { |
| 1582 |
$files[] = "$installPath/extensions/$e/$e.php"; |
| 1583 |
} |
| 1584 |
} |
| 1585 |
|
| 1586 |
if ( $files ) { |
| 1587 |
return $this->includeExtensionFiles( $files ); |
| 1588 |
} else { |
| 1589 |
return []; |
| 1590 |
} |
| 1591 |
} |
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
protected function includeExtensionFiles( $files ) { |
| 1601 |
global $IP; |
| 1602 |
$IP = $this->getVar( 'IP' ); |
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
foreach ( MainConfigSchema::listDefaultValues( 'wg' ) as $var => $value ) { |
| 1614 |
$$var = $value; |
| 1615 |
} |
| 1616 |
|
| 1617 |
|
| 1618 |
global $wgAutoloadClasses, $wgExtensionDirectory, $wgStyleDirectory; |
| 1619 |
$wgExtensionDirectory = "$IP/extensions"; |
| 1620 |
$wgStyleDirectory = "$IP/skins"; |
| 1621 |
|
| 1622 |
foreach ( $files as $file ) { |
| 1623 |
require_once $file; |
| 1624 |
} |
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
$hooksWeWant = $wgHooks['LoadExtensionSchemaUpdates'] ?? []; |
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
return [ 'LoadExtensionSchemaUpdates' => $hooksWeWant ]; |
| 1635 |
} |
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
protected function getAutoExtensionData() { |
| 1644 |
$exts = $this->getVar( '_Extensions' ); |
| 1645 |
$installPath = $this->getVar( 'IP' ); |
| 1646 |
|
| 1647 |
$extensionProcessor = new ExtensionProcessor(); |
| 1648 |
foreach ( $exts as $e ) { |
| 1649 |
$jsonPath = "$installPath/extensions/$e/extension.json"; |
| 1650 |
if ( file_exists( $jsonPath ) ) { |
| 1651 |
$extensionProcessor->extractInfoFromFile( $jsonPath ); |
| 1652 |
} |
| 1653 |
} |
| 1654 |
|
| 1655 |
$autoload = $extensionProcessor->getExtractedAutoloadInfo(); |
| 1656 |
AutoLoader::loadFiles( $autoload['files'] ); |
| 1657 |
AutoLoader::registerClasses( $autoload['classes'] ); |
| 1658 |
AutoLoader::registerNamespaces( $autoload['namespaces'] ); |
| 1659 |
|
| 1660 |
return $extensionProcessor->getExtractedInfo(); |
| 1661 |
} |
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
public function getAutoExtensionHookContainer() { |
| 1671 |
if ( !$this->autoExtensionHookContainer ) { |
| 1672 |
throw new LogicException( __METHOD__ . |
| 1673 |
': includeExtensions() has not been called' ); |
| 1674 |
} |
| 1675 |
return $this->autoExtensionHookContainer; |
| 1676 |
} |
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
public function getVirtualDomains(): array { |
| 1686 |
return $this->virtualDomains; |
| 1687 |
} |
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
protected function getInstallSteps( DatabaseInstaller $installer ) { |
| 1703 |
$coreInstallSteps = [ |
| 1704 |
[ 'name' => 'database', 'callback' => [ $installer, 'setupDatabase' ] ], |
| 1705 |
[ 'name' => 'tables', 'callback' => [ $installer, 'createTables' ] ], |
| 1706 |
[ 'name' => 'interwiki', 'callback' => [ $installer, 'populateInterwikiTable' ] ], |
| 1707 |
[ 'name' => 'stats', 'callback' => [ $this, 'populateSiteStats' ] ], |
| 1708 |
[ 'name' => 'keys', 'callback' => [ $this, 'generateKeys' ] ], |
| 1709 |
[ 'name' => 'updates', 'callback' => [ $installer, 'insertUpdateKeys' ] ], |
| 1710 |
[ 'name' => 'restore-services', 'callback' => [ $this, 'restoreServices' ] ], |
| 1711 |
[ 'name' => 'sysop', 'callback' => [ $this, 'createSysop' ] ], |
| 1712 |
[ 'name' => 'mainpage', 'callback' => [ $this, 'createMainpage' ] ], |
| 1713 |
]; |
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
foreach ( $coreInstallSteps as $step ) { |
| 1718 |
$this->installSteps[] = $step; |
| 1719 |
if ( isset( $this->extraInstallSteps[$step['name']] ) ) { |
| 1720 |
$this->installSteps = array_merge( |
| 1721 |
$this->installSteps, |
| 1722 |
$this->extraInstallSteps[$step['name']] |
| 1723 |
); |
| 1724 |
} |
| 1725 |
} |
| 1726 |
|
| 1727 |
|
| 1728 |
if ( isset( $this->extraInstallSteps['BEGINNING'] ) ) { |
| 1729 |
$this->installSteps = array_merge( |
| 1730 |
$this->extraInstallSteps['BEGINNING'], |
| 1731 |
$this->installSteps |
| 1732 |
); |
| 1733 |
} |
| 1734 |
|
| 1735 |
|
| 1736 |
if ( count( $this->getVar( '_Extensions' ) ) ) { |
| 1737 |
array_unshift( $this->installSteps, |
| 1738 |
[ 'name' => 'extensions', 'callback' => [ $this, 'includeExtensions' ] ] |
| 1739 |
); |
| 1740 |
$this->installSteps[] = [ |
| 1741 |
'name' => 'extension-tables', |
| 1742 |
'callback' => [ $installer, 'createExtensionTables' ] |
| 1743 |
]; |
| 1744 |
} |
| 1745 |
|
| 1746 |
return $this->installSteps; |
| 1747 |
} |
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
public function performInstallation( $startCB, $endCB ) { |
| 1758 |
$installResults = []; |
| 1759 |
$installer = $this->getDBInstaller(); |
| 1760 |
$installer->preInstall(); |
| 1761 |
$steps = $this->getInstallSteps( $installer ); |
| 1762 |
foreach ( $steps as $stepObj ) { |
| 1763 |
$name = $stepObj['name']; |
| 1764 |
call_user_func_array( $startCB, [ $name ] ); |
| 1765 |
|
| 1766 |
|
| 1767 |
$status = call_user_func( $stepObj['callback'], $installer ); |
| 1768 |
|
| 1769 |
|
| 1770 |
call_user_func( $endCB, $name, $status ); |
| 1771 |
$installResults[$name] = $status; |
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
if ( !$status->isOK() ) { |
| 1776 |
break; |
| 1777 |
} |
| 1778 |
} |
| 1779 |
|
| 1780 |
|
| 1781 |
if ( $status->isOK() ) { |
| 1782 |
$this->showSuccess( |
| 1783 |
'config-install-db-success' |
| 1784 |
); |
| 1785 |
$this->setVar( '_InstallDone', true ); |
| 1786 |
} |
| 1787 |
|
| 1788 |
return $installResults; |
| 1789 |
} |
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
public function generateKeys() { |
| 1797 |
$keys = [ 'wgSecretKey' => 64 ]; |
| 1798 |
if ( strval( $this->getVar( 'wgUpgradeKey' ) ) === '' ) { |
| 1799 |
$keys['wgUpgradeKey'] = 16; |
| 1800 |
} |
| 1801 |
|
| 1802 |
return $this->doGenerateKeys( $keys ); |
| 1803 |
} |
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
public function restoreServices() { |
| 1810 |
|
| 1811 |
$urlOptions = [ |
| 1812 |
UrlUtils::SERVER => $GLOBALS['wgServer'], |
| 1813 |
]; |
| 1814 |
|
| 1815 |
$connection = $this->getDBInstaller() |
| 1816 |
->definitelyGetConnection( DatabaseInstaller::CONN_CREATE_TABLES ); |
| 1817 |
$virtualDomains = array_merge( |
| 1818 |
$this->getVirtualDomains(), |
| 1819 |
MWLBFactory::CORE_VIRTUAL_DOMAINS |
| 1820 |
); |
| 1821 |
|
| 1822 |
$this->resetMediaWikiServices( null, [ |
| 1823 |
'DBLoadBalancerFactory' => static function () use ( $virtualDomains, $connection ) { |
| 1824 |
return LBFactorySingle::newFromConnection( |
| 1825 |
$connection, |
| 1826 |
[ 'virtualDomains' => $virtualDomains ] |
| 1827 |
); |
| 1828 |
}, |
| 1829 |
'UrlUtils' => static function ( MediaWikiServices $services ) use ( $urlOptions ) { |
| 1830 |
return new UrlUtils( $urlOptions ); |
| 1831 |
}, |
| 1832 |
'UserOptionsLookup' => static function ( MediaWikiServices $services ) { |
| 1833 |
return $services->get( 'UserOptionsManager' ); |
| 1834 |
}, |
| 1835 |
] ); |
| 1836 |
return Status::newGood(); |
| 1837 |
} |
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
protected function doGenerateKeys( $keys ) { |
| 1846 |
foreach ( $keys as $name => $length ) { |
| 1847 |
$secretKey = MWCryptRand::generateHex( $length ); |
| 1848 |
$this->setVar( $name, $secretKey ); |
| 1849 |
} |
| 1850 |
return Status::newGood(); |
| 1851 |
} |
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
protected function createSysop() { |
| 1859 |
$name = $this->getVar( '_AdminName' ); |
| 1860 |
$user = User::newFromName( $name ); |
| 1861 |
|
| 1862 |
if ( !$user ) { |
| 1863 |
|
| 1864 |
return Status::newFatal( 'config-admin-error-user', $name ); |
| 1865 |
} |
| 1866 |
|
| 1867 |
if ( $user->idForName() == 0 ) { |
| 1868 |
$user->addToDatabase(); |
| 1869 |
|
| 1870 |
$password = $this->getVar( '_AdminPassword' ); |
| 1871 |
$status = $user->changeAuthenticationData( [ |
| 1872 |
'username' => $user->getName(), |
| 1873 |
'password' => $password, |
| 1874 |
'retype' => $password, |
| 1875 |
] ); |
| 1876 |
if ( !$status->isGood() ) { |
| 1877 |
return Status::newFatal( 'config-admin-error-password', |
| 1878 |
$name, $status->getWikiText( false, false, $this->getVar( '_UserLang' ) ) ); |
| 1879 |
} |
| 1880 |
|
| 1881 |
$userGroupManager = MediaWikiServices::getInstance()->getUserGroupManager(); |
| 1882 |
$userGroupManager->addUserToGroup( $user, 'sysop' ); |
| 1883 |
$userGroupManager->addUserToGroup( $user, 'bureaucrat' ); |
| 1884 |
$userGroupManager->addUserToGroup( $user, 'interface-admin' ); |
| 1885 |
if ( $this->getVar( '_AdminEmail' ) ) { |
| 1886 |
$user->setEmail( $this->getVar( '_AdminEmail' ) ); |
| 1887 |
} |
| 1888 |
$user->saveSettings(); |
| 1889 |
|
| 1890 |
|
| 1891 |
$ssUpdate = SiteStatsUpdate::factory( [ 'users' => 1 ] ); |
| 1892 |
$ssUpdate->doUpdate(); |
| 1893 |
} |
| 1894 |
|
| 1895 |
if ( $this->getVar( '_Subscribe' ) && $this->getVar( '_AdminEmail' ) ) { |
| 1896 |
return $this->subscribeToMediaWikiAnnounce(); |
| 1897 |
} |
| 1898 |
return Status::newGood(); |
| 1899 |
} |
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
private function subscribeToMediaWikiAnnounce() { |
| 1905 |
$status = Status::newGood(); |
| 1906 |
$http = MediaWikiServices::getInstance()->getHttpRequestFactory(); |
| 1907 |
if ( !$http->canMakeRequests() ) { |
| 1908 |
$status->warning( 'config-install-subscribe-fail', |
| 1909 |
wfMessage( 'config-install-subscribe-notpossible' ) ); |
| 1910 |
return $status; |
| 1911 |
} |
| 1912 |
|
| 1913 |
|
| 1914 |
$params = [ 'email' => $this->getVar( '_AdminEmail' ) ]; |
| 1915 |
$req = $http->create( self::MEDIAWIKI_ANNOUNCE_URL . 'anonymous_subscribe', |
| 1916 |
[ 'method' => 'POST', 'postData' => $params ], __METHOD__ ); |
| 1917 |
|
| 1918 |
|
| 1919 |
$token = str_repeat( 'a', 64 ); |
| 1920 |
$req->setHeader( 'Referer', self::MEDIAWIKI_ANNOUNCE_URL ); |
| 1921 |
$req->setHeader( 'Cookie', "csrftoken=$token" ); |
| 1922 |
$req->setHeader( 'X-CSRFToken', $token ); |
| 1923 |
|
| 1924 |
|
| 1925 |
$reqStatus = $req->execute(); |
| 1926 |
if ( !$reqStatus->isOK() ) { |
| 1927 |
$status->warning( 'config-install-subscribe-fail', |
| 1928 |
Status::wrap( $reqStatus )->getMessage() ); |
| 1929 |
return $status; |
| 1930 |
} |
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
$checkReq = $http->create( self::MEDIAWIKI_ANNOUNCE_URL, [], __METHOD__ ); |
| 1938 |
$checkReq->setCookieJar( $req->getCookieJar() ); |
| 1939 |
if ( !$checkReq->execute()->isOK() ) { |
| 1940 |
$status->warning( 'config-install-subscribe-possiblefail' ); |
| 1941 |
return $status; |
| 1942 |
} |
| 1943 |
$html = $checkReq->getContent(); |
| 1944 |
if ( strpos( $html, 'Please check your inbox for further instructions' ) !== false ) { |
| 1945 |
|
| 1946 |
} elseif ( strpos( $html, 'Member already subscribed' ) !== false ) { |
| 1947 |
$status->warning( 'config-install-subscribe-alreadysubscribed' ); |
| 1948 |
} elseif ( strpos( $html, 'Subscription request already pending' ) !== false ) { |
| 1949 |
$status->warning( 'config-install-subscribe-alreadypending' ); |
| 1950 |
} else { |
| 1951 |
$status->warning( 'config-install-subscribe-possiblefail' ); |
| 1952 |
} |
| 1953 |
return $status; |
| 1954 |
} |
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
protected function createMainpage( DatabaseInstaller $installer ) { |
| 1963 |
$status = Status::newGood(); |
| 1964 |
$title = Title::newMainPage(); |
| 1965 |
if ( $title->exists() ) { |
| 1966 |
$status->warning( 'config-install-mainpage-exists' ); |
| 1967 |
return $status; |
| 1968 |
} |
| 1969 |
try { |
| 1970 |
$page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $title ); |
| 1971 |
$content = new WikitextContent( |
| 1972 |
wfMessage( 'mainpagetext' )->inContentLanguage()->text() . "\n\n" . |
| 1973 |
wfMessage( 'mainpagedocfooter' )->inContentLanguage()->text() |
| 1974 |
); |
| 1975 |
|
| 1976 |
$status = $page->doUserEditContent( |
| 1977 |
$content, |
| 1978 |
User::newSystemUser( 'MediaWiki default' ), |
| 1979 |
'', |
| 1980 |
EDIT_NEW |
| 1981 |
); |
| 1982 |
} catch ( Exception $e ) { |
| 1983 |
|
| 1984 |
$status->fatal( 'config-install-mainpage-failed', $e->getMessage() ); |
| 1985 |
} |
| 1986 |
|
| 1987 |
return $status; |
| 1988 |
} |
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
public static function overrideConfig( SettingsBuilder $settings ) { |
| 1996 |
|
| 1997 |
|
| 1998 |
if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) { |
| 1999 |
define( 'MW_NO_SESSION_HANDLER', 1 ); |
| 2000 |
} |
| 2001 |
|
| 2002 |
$settings->overrideConfigValues( [ |
| 2003 |
|
| 2004 |
|
| 2005 |
MainConfigNames::UseDatabaseMessages => false, |
| 2006 |
|
| 2007 |
|
| 2008 |
MainConfigNames::LanguageConverterCacheType => CACHE_NONE, |
| 2009 |
|
| 2010 |
|
| 2011 |
MainConfigNames::ResourceLoaderUseObjectCacheForDeps => true, |
| 2012 |
|
| 2013 |
|
| 2014 |
MainConfigNames::ShowExceptionDetails => true, |
| 2015 |
MainConfigNames::ShowHostnames => true, |
| 2016 |
|
| 2017 |
|
| 2018 |
MainConfigNames::ExternalLinkTarget => '_blank', |
| 2019 |
|
| 2020 |
|
| 2021 |
MainConfigNames::DisableOutputCompression => true, |
| 2022 |
|
| 2023 |
|
| 2024 |
MainConfigNames::CookiePrefix => 'mw_installer', |
| 2025 |
|
| 2026 |
|
| 2027 |
MainConfigNames::MaxShellMemory => 0, |
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
MainConfigNames::SessionProviders => [ |
| 2032 |
[ |
| 2033 |
'class' => InstallerSessionProvider::class, |
| 2034 |
'args' => [ [ |
| 2035 |
'priority' => 1, |
| 2036 |
] ] |
| 2037 |
] |
| 2038 |
], |
| 2039 |
|
| 2040 |
|
| 2041 |
MainConfigNames::MainStash => CACHE_NONE, |
| 2042 |
|
| 2043 |
|
| 2044 |
MainConfigNames::SessionCacheType => CACHE_NONE, |
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
MainConfigNames::Server => 'https://🌻.invalid', |
| 2049 |
] ); |
| 2050 |
} |
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
public function addInstallStep( $callback, $findStep = 'BEGINNING' ) { |
| 2060 |
$this->extraInstallSteps[$findStep][] = $callback; |
| 2061 |
} |
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
protected function disableTimeLimit() { |
| 2068 |
AtEase::suppressWarnings(); |
| 2069 |
set_time_limit( 0 ); |
| 2070 |
AtEase::restoreWarnings(); |
| 2071 |
} |
| 2072 |
} |