| 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 |
namespace MediaWiki\Installer; |
| 25 |
|
| 26 |
use Exception; |
| 27 |
use HtmlArmor; |
| 28 |
use MediaWiki\Context\RequestContext; |
| 29 |
use MediaWiki\Html\Html; |
| 30 |
use MediaWiki\Languages\LanguageNameUtils; |
| 31 |
use MediaWiki\MediaWikiServices; |
| 32 |
use MediaWiki\Message\Message; |
| 33 |
use MediaWiki\Request\WebRequest; |
| 34 |
use MediaWiki\Status\Status; |
| 35 |
use MediaWiki\Xml\Xml; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
class WebInstaller extends Installer { |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public $output; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public $request; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
protected $session; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
protected $phpErrors; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public $pageSequence = [ |
| 82 |
'Language', |
| 83 |
'ExistingWiki', |
| 84 |
'Welcome', |
| 85 |
'DBConnect', |
| 86 |
'Upgrade', |
| 87 |
'DBSettings', |
| 88 |
'Name', |
| 89 |
'Options', |
| 90 |
'Install', |
| 91 |
'Complete', |
| 92 |
]; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
protected $otherPages = [ |
| 100 |
'Restart', |
| 101 |
'ReleaseNotes', |
| 102 |
'Copying', |
| 103 |
'UpgradeDoc', |
| 104 |
]; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
protected $happyPages; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
protected $skippedPages; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
public $showSessionWarning = false; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
protected $tabIndex = 1; |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
protected $helpBoxId = 1; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
protected $currentPageName; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
public function __construct( WebRequest $request ) { |
| 155 |
parent::__construct(); |
| 156 |
$this->output = new WebInstallerOutput( $this ); |
| 157 |
$this->request = $request; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
public function execute( array $session ) { |
| 168 |
$this->session = $session; |
| 169 |
|
| 170 |
if ( isset( $session['settings'] ) ) { |
| 171 |
$this->settings = $session['settings'] + $this->settings; |
| 172 |
|
| 173 |
foreach ( $this->settings as $key => $val ) { |
| 174 |
$GLOBALS[$key] = $val; |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
$this->setupLanguage(); |
| 179 |
|
| 180 |
if ( ( $this->getVar( '_InstallDone' ) || $this->getVar( '_UpgradeDone' ) ) |
| 181 |
&& $this->request->getVal( 'localsettings' ) |
| 182 |
) { |
| 183 |
$this->outputLS(); |
| 184 |
return $this->session; |
| 185 |
} |
| 186 |
|
| 187 |
$isCSS = $this->request->getCheck( 'css' ); |
| 188 |
if ( $isCSS ) { |
| 189 |
$this->outputCss(); |
| 190 |
return $this->session; |
| 191 |
} |
| 192 |
|
| 193 |
$this->happyPages = $session['happyPages'] ?? []; |
| 194 |
|
| 195 |
$this->skippedPages = $session['skippedPages'] ?? []; |
| 196 |
|
| 197 |
$lowestUnhappy = $this->getLowestUnhappy(); |
| 198 |
|
| 199 |
|
| 200 |
$pageName = $this->request->getVal( 'page', '' ); |
| 201 |
|
| 202 |
if ( in_array( $pageName, $this->otherPages ) ) { |
| 203 |
|
| 204 |
$pageId = false; |
| 205 |
$page = $this->getPageByName( $pageName ); |
| 206 |
} else { |
| 207 |
|
| 208 |
if ( !$pageName || !in_array( $pageName, $this->pageSequence ) ) { |
| 209 |
$pageId = $lowestUnhappy; |
| 210 |
} else { |
| 211 |
$pageId = array_search( $pageName, $this->pageSequence ); |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
if ( $pageId > $lowestUnhappy ) { |
| 216 |
$pageId = $lowestUnhappy; |
| 217 |
if ( $lowestUnhappy == 0 ) { |
| 218 |
|
| 219 |
$this->showSessionWarning = true; |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
$pageName = $this->pageSequence[$pageId]; |
| 224 |
$page = $this->getPageByName( $pageName ); |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
if ( $this->request->wasPosted() && $this->request->getBool( 'submit-back' ) ) { |
| 229 |
if ( $this->request->getVal( 'lastPage' ) ) { |
| 230 |
$nextPage = $this->request->getVal( 'lastPage' ); |
| 231 |
} elseif ( $pageId !== false ) { |
| 232 |
|
| 233 |
|
| 234 |
$nextPageId = $pageId; |
| 235 |
|
| 236 |
do { |
| 237 |
$nextPageId--; |
| 238 |
$nextPage = $this->pageSequence[$nextPageId]; |
| 239 |
} while ( isset( $this->skippedPages[$nextPage] ) ); |
| 240 |
} else { |
| 241 |
$nextPage = $this->pageSequence[$lowestUnhappy]; |
| 242 |
} |
| 243 |
|
| 244 |
$this->output->redirect( $this->getUrl( [ 'page' => $nextPage ] ) ); |
| 245 |
|
| 246 |
return $this->finish(); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
$this->currentPageName = $page->getName(); |
| 251 |
$this->startPageWrapper( $pageName ); |
| 252 |
|
| 253 |
if ( $page->isSlow() ) { |
| 254 |
$this->disableTimeLimit(); |
| 255 |
} |
| 256 |
|
| 257 |
$result = $page->execute(); |
| 258 |
|
| 259 |
$this->endPageWrapper(); |
| 260 |
|
| 261 |
if ( $result == 'skip' ) { |
| 262 |
|
| 263 |
|
| 264 |
$this->skippedPages[$pageName] = true; |
| 265 |
$result = 'continue'; |
| 266 |
} else { |
| 267 |
unset( $this->skippedPages[$pageName] ); |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
if ( $result === 'continue' && !$this->output->headerDone() ) { |
| 272 |
if ( $pageId !== false ) { |
| 273 |
$this->happyPages[$pageId] = true; |
| 274 |
} |
| 275 |
|
| 276 |
$lowestUnhappy = $this->getLowestUnhappy(); |
| 277 |
|
| 278 |
if ( $this->request->getVal( 'lastPage' ) ) { |
| 279 |
$nextPage = $this->request->getVal( 'lastPage' ); |
| 280 |
} elseif ( $pageId !== false ) { |
| 281 |
$nextPage = $this->pageSequence[$pageId + 1]; |
| 282 |
} else { |
| 283 |
$nextPage = $this->pageSequence[$lowestUnhappy]; |
| 284 |
} |
| 285 |
|
| 286 |
if ( array_search( $nextPage, $this->pageSequence ) > $lowestUnhappy ) { |
| 287 |
$nextPage = $this->pageSequence[$lowestUnhappy]; |
| 288 |
} |
| 289 |
|
| 290 |
$this->output->redirect( $this->getUrl( [ 'page' => $nextPage ] ) ); |
| 291 |
} |
| 292 |
|
| 293 |
return $this->finish(); |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
public function getLowestUnhappy() { |
| 301 |
if ( count( $this->happyPages ) == 0 ) { |
| 302 |
return 0; |
| 303 |
} else { |
| 304 |
return max( array_keys( $this->happyPages ) ) + 1; |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
public function startSession() { |
| 315 |
if ( wfIniGetBool( 'session.auto_start' ) || session_id() ) { |
| 316 |
|
| 317 |
return true; |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
$options = []; |
| 322 |
if ( $this->request->getProtocol() === 'https' ) { |
| 323 |
$options['cookie_secure'] = '1'; |
| 324 |
} |
| 325 |
|
| 326 |
$this->phpErrors = []; |
| 327 |
set_error_handler( [ $this, 'errorHandler' ] ); |
| 328 |
try { |
| 329 |
session_name( 'mw_installer_session' ); |
| 330 |
session_start( $options ); |
| 331 |
} catch ( Exception $e ) { |
| 332 |
restore_error_handler(); |
| 333 |
throw $e; |
| 334 |
} |
| 335 |
restore_error_handler(); |
| 336 |
|
| 337 |
if ( $this->phpErrors ) { |
| 338 |
return false; |
| 339 |
} |
| 340 |
|
| 341 |
return true; |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
public function getFingerprint() { |
| 353 |
|
| 354 |
$url = $this->request->getFullRequestURL(); |
| 355 |
if ( preg_match( '!^(.*\?)!', $url, $m ) ) { |
| 356 |
|
| 357 |
$url = $m[1]; |
| 358 |
} |
| 359 |
if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) { |
| 360 |
|
| 361 |
|
| 362 |
$url = $m[1]; |
| 363 |
} |
| 364 |
|
| 365 |
return md5( serialize( [ |
| 366 |
'local path' => dirname( __DIR__ ), |
| 367 |
'url' => $url, |
| 368 |
'version' => MW_VERSION |
| 369 |
] ) ); |
| 370 |
} |
| 371 |
|
| 372 |
public function showError( $msg, ...$params ) { |
| 373 |
if ( !( $msg instanceof Message ) ) { |
| 374 |
$msg = wfMessage( |
| 375 |
$msg, |
| 376 |
array_map( 'htmlspecialchars', $params ) |
| 377 |
); |
| 378 |
} |
| 379 |
$text = $msg->useDatabase( false )->parse(); |
| 380 |
$box = Html::errorBox( $text, '', 'config-error-box' ); |
| 381 |
$this->output->addHTML( $box ); |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
public function errorHandler( $errno, $errstr ) { |
| 391 |
$this->phpErrors[] = $errstr; |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
public function finish() { |
| 400 |
$this->output->output(); |
| 401 |
|
| 402 |
$this->session['happyPages'] = $this->happyPages; |
| 403 |
$this->session['skippedPages'] = $this->skippedPages; |
| 404 |
$this->session['settings'] = $this->settings; |
| 405 |
|
| 406 |
return $this->session; |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
public function reset() { |
| 413 |
$this->session = []; |
| 414 |
$this->happyPages = []; |
| 415 |
$this->settings = []; |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
public function getUrl( $query = [] ) { |
| 426 |
$url = $this->request->getRequestURL(); |
| 427 |
|
| 428 |
$url = preg_replace( '/\?.*$/', '', $url ); |
| 429 |
|
| 430 |
if ( $query ) { |
| 431 |
$url .= '?' . wfArrayToCgi( $query ); |
| 432 |
} |
| 433 |
|
| 434 |
return $url; |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
public function getPageByName( $pageName ) { |
| 444 |
$pageClass = 'MediaWiki\\Installer\\WebInstaller' . $pageName; |
| 445 |
|
| 446 |
return new $pageClass( $this ); |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
public function getSession( $name, $default = null ) { |
| 458 |
return $this->session[$name] ?? $default; |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
public function setSession( $name, $value ) { |
| 468 |
$this->session[$name] = $value; |
| 469 |
} |
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
public function nextTabIndex() { |
| 477 |
return $this->tabIndex++; |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
public function setupLanguage() { |
| 484 |
global $wgLang, $wgLanguageCode; |
| 485 |
|
| 486 |
if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) { |
| 487 |
$wgLanguageCode = $this->getAcceptLanguage(); |
| 488 |
$wgLang = MediaWikiServices::getInstance()->getLanguageFactory() |
| 489 |
->getLanguage( $wgLanguageCode ); |
| 490 |
RequestContext::getMain()->setLanguage( $wgLang ); |
| 491 |
$this->setVar( 'wgLanguageCode', $wgLanguageCode ); |
| 492 |
$this->setVar( '_UserLang', $wgLanguageCode ); |
| 493 |
} else { |
| 494 |
$wgLanguageCode = $this->getVar( 'wgLanguageCode' ); |
| 495 |
} |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
public function getAcceptLanguage() { |
| 505 |
global $wgLanguageCode; |
| 506 |
|
| 507 |
$mwLanguages = MediaWikiServices::getInstance() |
| 508 |
->getLanguageNameUtils() |
| 509 |
->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED ); |
| 510 |
$headerLanguages = array_keys( $this->request->getAcceptLang() ); |
| 511 |
|
| 512 |
foreach ( $headerLanguages as $lang ) { |
| 513 |
if ( isset( $mwLanguages[$lang] ) ) { |
| 514 |
return $lang; |
| 515 |
} |
| 516 |
} |
| 517 |
|
| 518 |
return $wgLanguageCode; |
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
private function startPageWrapper( $currentPageName ) { |
| 527 |
$s = "<div class=\"config-page-wrapper\">\n"; |
| 528 |
$s .= "<div class=\"config-page\">\n"; |
| 529 |
$s .= "<div class=\"config-page-list cdx-card\"><span class=\"cdx-card__text\">"; |
| 530 |
$s .= "<span class=\"cdx-card__text__description\"><ul>\n"; |
| 531 |
$lastHappy = -1; |
| 532 |
|
| 533 |
foreach ( $this->pageSequence as $id => $pageName ) { |
| 534 |
$happy = !empty( $this->happyPages[$id] ); |
| 535 |
$s .= $this->getPageListItem( |
| 536 |
$pageName, |
| 537 |
$happy || $lastHappy == $id - 1, |
| 538 |
$currentPageName |
| 539 |
); |
| 540 |
|
| 541 |
if ( $happy ) { |
| 542 |
$lastHappy = $id; |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
$s .= "</ul><br/><ul>\n"; |
| 547 |
$s .= $this->getPageListItem( 'Restart', true, $currentPageName ); |
| 548 |
|
| 549 |
$s .= "</ul></span></span></div>\n"; |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
$s .= Html::element( 'h2', [], |
| 557 |
wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() ); |
| 558 |
|
| 559 |
$this->output->addHTMLNoFlush( $s ); |
| 560 |
} |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
private function getPageListItem( $pageName, $enabled, $currentPageName ) { |
| 572 |
$s = "<li class=\"config-page-list-item\">"; |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
$name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text(); |
| 580 |
|
| 581 |
if ( $enabled ) { |
| 582 |
$query = [ 'page' => $pageName ]; |
| 583 |
|
| 584 |
if ( !in_array( $pageName, $this->pageSequence ) ) { |
| 585 |
if ( in_array( $currentPageName, $this->pageSequence ) ) { |
| 586 |
$query['lastPage'] = $currentPageName; |
| 587 |
} |
| 588 |
|
| 589 |
$link = Html::element( 'a', |
| 590 |
[ |
| 591 |
'href' => $this->getUrl( $query ) |
| 592 |
], |
| 593 |
$name |
| 594 |
); |
| 595 |
} else { |
| 596 |
$link = htmlspecialchars( $name ); |
| 597 |
} |
| 598 |
|
| 599 |
if ( $pageName == $currentPageName ) { |
| 600 |
$s .= "<span class=\"config-page-current\">$link</span>"; |
| 601 |
} else { |
| 602 |
$s .= $link; |
| 603 |
} |
| 604 |
} else { |
| 605 |
$s .= Html::element( 'span', |
| 606 |
[ |
| 607 |
'class' => 'config-page-disabled' |
| 608 |
], |
| 609 |
$name |
| 610 |
); |
| 611 |
} |
| 612 |
|
| 613 |
$s .= "</li>\n"; |
| 614 |
|
| 615 |
return $s; |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
private function endPageWrapper() { |
| 622 |
$this->output->addHTMLNoFlush( |
| 623 |
"<div class=\"visualClear\"></div>\n" . |
| 624 |
"</div>\n" . |
| 625 |
"<div class=\"visualClear\"></div>\n" . |
| 626 |
"</div>" ); |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
public function getHelpBox( $msg, ...$args ) { |
| 639 |
$args = array_map( 'htmlspecialchars', $args ); |
| 640 |
$text = wfMessage( $msg, $args )->useDatabase( false )->plain(); |
| 641 |
$html = $this->parse( $text, true ); |
| 642 |
|
| 643 |
return "<div class=\"config-help-field-container\">\n" . |
| 644 |
"<a class=\"config-help-field-hint\" title=\"" . |
| 645 |
wfMessage( 'config-help-tooltip' )->escaped() . "\">ℹ️ " . |
| 646 |
wfMessage( 'config-help' )->escaped() . "</a>\n" . |
| 647 |
"<div class=\"config-help-field-content config-help-field-content-hidden " . |
| 648 |
"cdx-message cdx-message--block cdx-message--notice\" style=\"margin: 10px\">" . |
| 649 |
"<div class=\"cdx-message__content\">" . $html . "</div></div>\n" . |
| 650 |
"</div>\n"; |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
public function showHelpBox( $msg, ...$params ) { |
| 659 |
$html = $this->getHelpBox( $msg, ...$params ); |
| 660 |
$this->output->addHTML( $html ); |
| 661 |
} |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
public function getInfoBox( $text ) { |
| 670 |
$html = ( $text instanceof HtmlArmor ) ? |
| 671 |
HtmlArmor::getHtml( $text ) : |
| 672 |
$this->parse( $text, true ); |
| 673 |
return '<div class="cdx-message cdx-message--block cdx-message--notice">' . |
| 674 |
'<span class="cdx-message__icon"></span><div class="cdx-message__content">' . |
| 675 |
'<p><strong>' . wfMessage( 'config-information' )->escaped() . '</strong></p>' . |
| 676 |
$html . |
| 677 |
"</div></div>\n"; |
| 678 |
} |
| 679 |
|
| 680 |
public function showSuccess( $msg, ...$params ) { |
| 681 |
$html = '<div class="cdx-message cdx-message--block cdx-message--success">' . |
| 682 |
'<span class="cdx-message__icon"></span><div class="cdx-message__content">' . |
| 683 |
$this->parse( wfMessage( $msg, $params )->useDatabase( false )->plain() ) . |
| 684 |
"</div></div>\n"; |
| 685 |
$this->output->addHTML( $html ); |
| 686 |
} |
| 687 |
|
| 688 |
public function showMessage( $msg, ...$params ) { |
| 689 |
$html = '<div class="cdx-message cdx-message--block cdx-message--notice">' . |
| 690 |
'<span class="cdx-message__icon"></span><div class="cdx-message__content">' . |
| 691 |
$this->parse( wfMessage( $msg, $params )->useDatabase( false )->plain() ) . |
| 692 |
"</div></div>\n"; |
| 693 |
$this->output->addHTML( $html ); |
| 694 |
} |
| 695 |
|
| 696 |
public function showWarning( $msg, ...$params ) { |
| 697 |
$html = '<div class="cdx-message cdx-message--block cdx-message--warning">' . |
| 698 |
'<span class="cdx-message__icon"></span><div class="cdx-message__content">' . |
| 699 |
$this->parse( wfMessage( $msg, $params )->useDatabase( false )->plain() ) . |
| 700 |
"</div></div>\n"; |
| 701 |
$this->output->addHTML( $html ); |
| 702 |
} |
| 703 |
|
| 704 |
public function showStatusMessage( Status $status ) { |
| 705 |
|
| 706 |
foreach ( $status->getMessages( 'error' ) as $msg ) { |
| 707 |
$this->showWarning( $msg ); |
| 708 |
} |
| 709 |
foreach ( $status->getMessages( 'warning' ) as $msg ) { |
| 710 |
$this->showWarning( $msg ); |
| 711 |
} |
| 712 |
} |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
public function label( $msg, $forId, $contents, $helpData = "" ) { |
| 726 |
if ( strval( $msg ) == '' ) { |
| 727 |
$labelText = "\u{00A0}"; |
| 728 |
} else { |
| 729 |
$labelText = wfMessage( $msg )->escaped(); |
| 730 |
} |
| 731 |
|
| 732 |
$attributes = [ 'class' => 'config-label' ]; |
| 733 |
|
| 734 |
if ( $forId ) { |
| 735 |
$attributes['for'] = $forId; |
| 736 |
} |
| 737 |
|
| 738 |
return "<div class=\"config-block\">\n" . |
| 739 |
" <div class=\"config-block-label\">\n" . |
| 740 |
Xml::tags( 'label', |
| 741 |
$attributes, |
| 742 |
$labelText |
| 743 |
) . "\n" . |
| 744 |
$helpData . |
| 745 |
" </div>\n" . |
| 746 |
" <div class=\"config-block-elements\">\n" . |
| 747 |
$contents . |
| 748 |
" </div>\n" . |
| 749 |
"</div>\n"; |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
public function getTextBox( $params ) { |
| 768 |
if ( !isset( $params['controlName'] ) ) { |
| 769 |
$params['controlName'] = 'config_' . $params['var']; |
| 770 |
} |
| 771 |
|
| 772 |
if ( !isset( $params['value'] ) ) { |
| 773 |
$params['value'] = $this->getVar( $params['var'] ); |
| 774 |
} |
| 775 |
|
| 776 |
if ( !isset( $params['attribs'] ) ) { |
| 777 |
$params['attribs'] = []; |
| 778 |
} |
| 779 |
if ( !isset( $params['help'] ) ) { |
| 780 |
$params['help'] = ""; |
| 781 |
} |
| 782 |
|
| 783 |
return $this->label( |
| 784 |
$params['label'], |
| 785 |
$params['controlName'], |
| 786 |
"<div class=\"cdx-text-input\">" . |
| 787 |
Xml::input( |
| 788 |
$params['controlName'], |
| 789 |
30, |
| 790 |
$params['value'], |
| 791 |
$params['attribs'] + [ |
| 792 |
'id' => $params['controlName'], |
| 793 |
'class' => 'cdx-text-input__input', |
| 794 |
'tabindex' => $this->nextTabIndex() |
| 795 |
] |
| 796 |
) . "</div>", |
| 797 |
$params['help'] |
| 798 |
); |
| 799 |
} |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
public function getTextArea( $params ) { |
| 816 |
if ( !isset( $params['controlName'] ) ) { |
| 817 |
$params['controlName'] = 'config_' . $params['var']; |
| 818 |
} |
| 819 |
|
| 820 |
if ( !isset( $params['value'] ) ) { |
| 821 |
$params['value'] = $this->getVar( $params['var'] ); |
| 822 |
} |
| 823 |
|
| 824 |
if ( !isset( $params['attribs'] ) ) { |
| 825 |
$params['attribs'] = []; |
| 826 |
} |
| 827 |
if ( !isset( $params['help'] ) ) { |
| 828 |
$params['help'] = ""; |
| 829 |
} |
| 830 |
|
| 831 |
return $this->label( |
| 832 |
$params['label'], |
| 833 |
$params['controlName'], |
| 834 |
Xml::textarea( |
| 835 |
$params['controlName'], |
| 836 |
$params['value'], |
| 837 |
30, |
| 838 |
5, |
| 839 |
$params['attribs'] + [ |
| 840 |
'id' => $params['controlName'], |
| 841 |
'class' => 'config-input-text', |
| 842 |
'tabindex' => $this->nextTabIndex() |
| 843 |
] |
| 844 |
), |
| 845 |
$params['help'] |
| 846 |
); |
| 847 |
} |
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
public function getPasswordBox( $params ) { |
| 866 |
if ( !isset( $params['value'] ) ) { |
| 867 |
$params['value'] = $this->getVar( $params['var'] ); |
| 868 |
} |
| 869 |
|
| 870 |
if ( !isset( $params['attribs'] ) ) { |
| 871 |
$params['attribs'] = []; |
| 872 |
} |
| 873 |
|
| 874 |
$params['value'] = $this->getFakePassword( $params['value'] ); |
| 875 |
$params['attribs']['type'] = 'password'; |
| 876 |
|
| 877 |
return $this->getTextBox( $params ); |
| 878 |
} |
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
private static function addClassAttrib( &$attribs, $class ) { |
| 888 |
if ( isset( $attribs['class'] ) ) { |
| 889 |
$attribs['class'] .= ' ' . $class; |
| 890 |
} else { |
| 891 |
$attribs['class'] = $class; |
| 892 |
} |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
public function getCheckBox( $params ) { |
| 912 |
if ( !isset( $params['controlName'] ) ) { |
| 913 |
$params['controlName'] = 'config_' . $params['var']; |
| 914 |
} |
| 915 |
|
| 916 |
if ( !isset( $params['value'] ) ) { |
| 917 |
$params['value'] = $this->getVar( $params['var'] ); |
| 918 |
} |
| 919 |
|
| 920 |
if ( !isset( $params['attribs'] ) ) { |
| 921 |
$params['attribs'] = []; |
| 922 |
} |
| 923 |
if ( !isset( $params['help'] ) ) { |
| 924 |
$params['help'] = ""; |
| 925 |
} |
| 926 |
if ( !isset( $params['labelAttribs'] ) ) { |
| 927 |
$params['labelAttribs'] = []; |
| 928 |
} |
| 929 |
$labelText = $params['rawtext'] ?? $this->parse( wfMessage( $params['label'] )->plain() ); |
| 930 |
self::addClassAttrib( $params['attribs'], 'cdx-checkbox__input' ); |
| 931 |
self::addClassAttrib( $params['labelAttribs'], 'cdx-checkbox__label' ); |
| 932 |
|
| 933 |
return "<div class=\"cdx-checkbox\" style=\"margin-top: 12px; margin-bottom: 2px;\">\n" . |
| 934 |
Xml::check( |
| 935 |
$params['controlName'], |
| 936 |
$params['value'], |
| 937 |
$params['attribs'] + [ |
| 938 |
'id' => $params['controlName'], |
| 939 |
'tabindex' => $this->nextTabIndex() |
| 940 |
] |
| 941 |
) . |
| 942 |
"<span class=\"cdx-checkbox__icon\"></span>" . |
| 943 |
Html::rawElement( |
| 944 |
'label', |
| 945 |
$params['labelAttribs'] + [ |
| 946 |
'for' => $params['controlName'] |
| 947 |
], |
| 948 |
$labelText |
| 949 |
) . |
| 950 |
"</div>\n" . $params['help']; |
| 951 |
} |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
public function getRadioSet( $params ) { |
| 974 |
$items = $this->getRadioElements( $params ); |
| 975 |
|
| 976 |
$label = $params['label'] ?? ''; |
| 977 |
|
| 978 |
if ( !isset( $params['controlName'] ) ) { |
| 979 |
$params['controlName'] = 'config_' . $params['var']; |
| 980 |
} |
| 981 |
|
| 982 |
if ( !isset( $params['help'] ) ) { |
| 983 |
$params['help'] = ""; |
| 984 |
} |
| 985 |
|
| 986 |
$s = ""; |
| 987 |
foreach ( $items as $item ) { |
| 988 |
$s .= "$item\n"; |
| 989 |
} |
| 990 |
|
| 991 |
return $this->label( $label, $params['controlName'], $s, $params['help'] ); |
| 992 |
} |
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
public function getRadioElements( $params ) { |
| 1004 |
if ( !isset( $params['controlName'] ) ) { |
| 1005 |
$params['controlName'] = 'config_' . $params['var']; |
| 1006 |
} |
| 1007 |
|
| 1008 |
if ( !isset( $params['value'] ) ) { |
| 1009 |
$params['value'] = $this->getVar( $params['var'] ); |
| 1010 |
} |
| 1011 |
|
| 1012 |
$items = []; |
| 1013 |
|
| 1014 |
foreach ( $params['values'] as $value ) { |
| 1015 |
$itemAttribs = []; |
| 1016 |
|
| 1017 |
if ( isset( $params['commonAttribs'] ) ) { |
| 1018 |
$itemAttribs = $params['commonAttribs']; |
| 1019 |
} |
| 1020 |
|
| 1021 |
if ( isset( $params['itemAttribs'][$value] ) ) { |
| 1022 |
$itemAttribs = $params['itemAttribs'][$value] + $itemAttribs; |
| 1023 |
} |
| 1024 |
|
| 1025 |
$checked = $value == $params['value']; |
| 1026 |
$id = $params['controlName'] . '_' . $value; |
| 1027 |
$itemAttribs['id'] = $id; |
| 1028 |
$itemAttribs['tabindex'] = $this->nextTabIndex(); |
| 1029 |
self::addClassAttrib( $itemAttribs, 'cdx-radio__input' ); |
| 1030 |
|
| 1031 |
$items[$value] = |
| 1032 |
'<span class="cdx-radio">' . |
| 1033 |
Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) . |
| 1034 |
"<span class=\"cdx-radio__icon\"></span>\u{00A0}" . |
| 1035 |
Xml::tags( 'label', [ 'for' => $id, 'class' => 'cdx-radio__label' ], $this->parse( |
| 1036 |
isset( $params['itemLabels'] ) ? |
| 1037 |
wfMessage( $params['itemLabels'][$value] )->plain() : |
| 1038 |
wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain() |
| 1039 |
) ) . '</span>'; |
| 1040 |
} |
| 1041 |
|
| 1042 |
return $items; |
| 1043 |
} |
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
public function showStatusBox( $status ) { |
| 1051 |
if ( !$status->isGood() ) { |
| 1052 |
$html = $status->getHTML(); |
| 1053 |
|
| 1054 |
if ( $status->isOK() ) { |
| 1055 |
$box = Html::warningBox( $html, 'config-warning-box' ); |
| 1056 |
} else { |
| 1057 |
$box = Html::errorBox( $html, '', 'config-error-box' ); |
| 1058 |
} |
| 1059 |
|
| 1060 |
$this->output->addHTML( $box ); |
| 1061 |
} |
| 1062 |
} |
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
public function setVarsFromRequest( $varNames, $prefix = 'config_' ) { |
| 1075 |
$newValues = []; |
| 1076 |
|
| 1077 |
foreach ( $varNames as $name ) { |
| 1078 |
$value = $this->request->getVal( $prefix . $name ); |
| 1079 |
|
| 1080 |
if ( $value !== null && stripos( $name, 'password' ) === false ) { |
| 1081 |
$value = trim( $value ); |
| 1082 |
} |
| 1083 |
$newValues[$name] = $value; |
| 1084 |
|
| 1085 |
if ( $value === null ) { |
| 1086 |
|
| 1087 |
$this->setVar( $name, false ); |
| 1088 |
} elseif ( stripos( $name, 'password' ) !== false ) { |
| 1089 |
$this->setPassword( $name, $value ); |
| 1090 |
} else { |
| 1091 |
$this->setVar( $name, $value ); |
| 1092 |
} |
| 1093 |
} |
| 1094 |
|
| 1095 |
return $newValues; |
| 1096 |
} |
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
public function getDocUrl( $page ) { |
| 1106 |
$query = [ 'page' => $page ]; |
| 1107 |
|
| 1108 |
if ( in_array( $this->currentPageName, $this->pageSequence ) ) { |
| 1109 |
$query['lastPage'] = $this->currentPageName; |
| 1110 |
} |
| 1111 |
|
| 1112 |
return $this->getUrl( $query ); |
| 1113 |
} |
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
public function makeLinkItem( $url, $linkText ) { |
| 1124 |
return Html::rawElement( 'li', [], |
| 1125 |
Html::element( 'a', [ 'href' => $url ], $linkText ) |
| 1126 |
); |
| 1127 |
} |
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
public function getLocalSettingsLocation() { |
| 1140 |
return false; |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
public function envCheckPath() { |
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
$path = false; |
| 1151 |
if ( !empty( $_SERVER['PHP_SELF'] ) ) { |
| 1152 |
$path = $_SERVER['PHP_SELF']; |
| 1153 |
} elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) { |
| 1154 |
$path = $_SERVER['SCRIPT_NAME']; |
| 1155 |
} |
| 1156 |
if ( $path === false ) { |
| 1157 |
$this->showError( 'config-no-uri' ); |
| 1158 |
return false; |
| 1159 |
} |
| 1160 |
|
| 1161 |
return parent::envCheckPath(); |
| 1162 |
} |
| 1163 |
|
| 1164 |
public function envPrepPath() { |
| 1165 |
parent::envPrepPath(); |
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
$path = false; |
| 1170 |
if ( !empty( $_SERVER['PHP_SELF'] ) ) { |
| 1171 |
$path = $_SERVER['PHP_SELF']; |
| 1172 |
} elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) { |
| 1173 |
$path = $_SERVER['SCRIPT_NAME']; |
| 1174 |
} |
| 1175 |
if ( $path !== false ) { |
| 1176 |
$scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path ); |
| 1177 |
|
| 1178 |
$this->setVar( 'wgScriptPath', "$scriptPath" ); |
| 1179 |
|
| 1180 |
$this->setVar( 'wgScript', "$scriptPath/index.php" ); |
| 1181 |
$this->setVar( 'wgLoadScript', "$scriptPath/load.php" ); |
| 1182 |
$this->setVar( 'wgStylePath', "$scriptPath/skins" ); |
| 1183 |
$this->setVar( 'wgLocalStylePath', "$scriptPath/skins" ); |
| 1184 |
$this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" ); |
| 1185 |
$this->setVar( 'wgUploadPath', "$scriptPath/images" ); |
| 1186 |
$this->setVar( 'wgResourceBasePath', "$scriptPath" ); |
| 1187 |
} |
| 1188 |
} |
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
protected function envGetDefaultServer() { |
| 1194 |
$assumeProxiesUseDefaultProtocolPorts = |
| 1195 |
$this->getVar( 'wgAssumeProxiesUseDefaultProtocolPorts' ); |
| 1196 |
|
| 1197 |
return WebRequest::detectServer( $assumeProxiesUseDefaultProtocolPorts ); |
| 1198 |
} |
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
private function outputLS() { |
| 1204 |
$this->request->response()->header( 'Content-type: application/x-httpd-php' ); |
| 1205 |
$this->request->response()->header( |
| 1206 |
'Content-Disposition: attachment; filename="LocalSettings.php"' |
| 1207 |
); |
| 1208 |
|
| 1209 |
$ls = InstallerOverrides::getLocalSettingsGenerator( $this ); |
| 1210 |
$rightsProfile = $this->rightsProfiles[$this->getVar( '_RightsProfile' )]; |
| 1211 |
foreach ( $rightsProfile as $group => $rightsArr ) { |
| 1212 |
$ls->setGroupRights( $group, $rightsArr ); |
| 1213 |
} |
| 1214 |
echo $ls->getText(); |
| 1215 |
} |
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
public function outputCss() { |
| 1221 |
$this->request->response()->header( 'Content-type: text/css' ); |
| 1222 |
echo $this->output->getCSS(); |
| 1223 |
} |
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
public function getPhpErrors() { |
| 1229 |
return $this->phpErrors; |
| 1230 |
} |
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
public function needsUpgrade() { |
| 1239 |
return $this->getDBInstaller()->needsUpgrade(); |
| 1240 |
} |
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
public function doUpgrade() { |
| 1248 |
$dbInstaller = $this->getDBInstaller(); |
| 1249 |
$dbInstaller->preUpgrade(); |
| 1250 |
$this->restoreServices(); |
| 1251 |
|
| 1252 |
$ret = true; |
| 1253 |
ob_start( [ $this, 'outputHandler' ] ); |
| 1254 |
$up = DatabaseUpdater::newForDB( |
| 1255 |
$dbInstaller->definitelyGetConnection( DatabaseInstaller::CONN_CREATE_TABLES ) ); |
| 1256 |
try { |
| 1257 |
$up->doUpdates(); |
| 1258 |
$up->purgeCache(); |
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
if ( !$this->getVar( '_ExistingDBSettings' ) ) { |
| 1263 |
$this->generateKeys(); |
| 1264 |
} |
| 1265 |
$this->setVar( '_UpgradeDone', true ); |
| 1266 |
} catch ( Exception $e ) { |
| 1267 |
|
| 1268 |
echo "\nAn error occurred:\n"; |
| 1269 |
echo $e->getMessage(); |
| 1270 |
$ret = false; |
| 1271 |
} |
| 1272 |
ob_end_flush(); |
| 1273 |
|
| 1274 |
return $ret; |
| 1275 |
} |
| 1276 |
|
| 1277 |
public function outputHandler( $string ) { |
| 1278 |
return htmlspecialchars( $string ); |
| 1279 |
} |
| 1280 |
|
| 1281 |
} |