123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248 |
- <?php
- /**
- * Core installer web interface.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- * @ingroup Deployment
- */
- use MediaWiki\MediaWikiServices;
- /**
- * Class for the core installer web interface.
- *
- * @ingroup Deployment
- * @since 1.17
- */
- class WebInstaller extends Installer {
- /**
- * @var WebInstallerOutput
- */
- public $output;
- /**
- * WebRequest object.
- *
- * @var WebRequest
- */
- public $request;
- /**
- * Cached session array.
- *
- * @var array[]
- */
- protected $session;
- /**
- * Captured PHP error text. Temporary.
- *
- * @var string[]
- */
- protected $phpErrors;
- /**
- * The main sequence of page names. These will be displayed in turn.
- *
- * To add a new installer page:
- * * Add it to this WebInstaller::$pageSequence property
- * * Add a "config-page-<name>" message
- * * Add a "WebInstaller<name>" class
- *
- * @var string[]
- */
- public $pageSequence = [
- 'Language',
- 'ExistingWiki',
- 'Welcome',
- 'DBConnect',
- 'Upgrade',
- 'DBSettings',
- 'Name',
- 'Options',
- 'Install',
- 'Complete',
- ];
- /**
- * Out of sequence pages, selectable by the user at any time.
- *
- * @var string[]
- */
- protected $otherPages = [
- 'Restart',
- 'Readme',
- 'ReleaseNotes',
- 'Copying',
- 'UpgradeDoc', // Can't use Upgrade due to Upgrade step
- ];
- /**
- * Array of pages which have declared that they have been submitted, have validated
- * their input, and need no further processing.
- *
- * @var bool[]
- */
- protected $happyPages;
- /**
- * List of "skipped" pages. These are pages that will automatically continue
- * to the next page on any GET request. To avoid breaking the "back" button,
- * they need to be skipped during a back operation.
- *
- * @var bool[]
- */
- protected $skippedPages;
- /**
- * Flag indicating that session data may have been lost.
- *
- * @var bool
- */
- public $showSessionWarning = false;
- /**
- * Numeric index of the page we're on
- *
- * @var int
- */
- protected $tabIndex = 1;
- /**
- * Numeric index of the help box
- *
- * @var int
- */
- protected $helpBoxId = 1;
- /**
- * Name of the page we're on
- *
- * @var string
- */
- protected $currentPageName;
- /**
- * @param WebRequest $request
- */
- public function __construct( WebRequest $request ) {
- parent::__construct();
- $this->output = new WebInstallerOutput( $this );
- $this->request = $request;
- }
- /**
- * Main entry point.
- *
- * @param array[] $session Initial session array
- *
- * @return array[] New session array
- */
- public function execute( array $session ) {
- $this->session = $session;
- if ( isset( $session['settings'] ) ) {
- $this->settings = $session['settings'] + $this->settings;
- // T187586 MediaWikiServices works with globals
- foreach ( $this->settings as $key => $val ) {
- $GLOBALS[$key] = $val;
- }
- }
- $this->setupLanguage();
- if ( ( $this->getVar( '_InstallDone' ) || $this->getVar( '_UpgradeDone' ) )
- && $this->request->getVal( 'localsettings' )
- ) {
- $this->outputLS();
- return $this->session;
- }
- $isCSS = $this->request->getVal( 'css' );
- if ( $isCSS ) {
- $this->outputCss();
- return $this->session;
- }
- $this->happyPages = $session['happyPages'] ?? [];
- $this->skippedPages = $session['skippedPages'] ?? [];
- $lowestUnhappy = $this->getLowestUnhappy();
- # Special case for Creative Commons partner chooser box.
- if ( $this->request->getVal( 'SubmitCC' ) ) {
- /** @var WebInstallerOptions $page */
- $page = $this->getPageByName( 'Options' );
- '@phan-var WebInstallerOptions $page';
- $this->output->useShortHeader();
- $this->output->allowFrames();
- $page->submitCC();
- return $this->finish();
- }
- if ( $this->request->getVal( 'ShowCC' ) ) {
- /** @var WebInstallerOptions $page */
- $page = $this->getPageByName( 'Options' );
- '@phan-var WebInstallerOptions $page';
- $this->output->useShortHeader();
- $this->output->allowFrames();
- $this->output->addHTML( $page->getCCDoneBox() );
- return $this->finish();
- }
- # Get the page name.
- $pageName = $this->request->getVal( 'page' );
- if ( in_array( $pageName, $this->otherPages ) ) {
- # Out of sequence
- $pageId = false;
- $page = $this->getPageByName( $pageName );
- } else {
- # Main sequence
- if ( !$pageName || !in_array( $pageName, $this->pageSequence ) ) {
- $pageId = $lowestUnhappy;
- } else {
- $pageId = array_search( $pageName, $this->pageSequence );
- }
- # If necessary, move back to the lowest-numbered unhappy page
- if ( $pageId > $lowestUnhappy ) {
- $pageId = $lowestUnhappy;
- if ( $lowestUnhappy == 0 ) {
- # Knocked back to start, possible loss of session data.
- $this->showSessionWarning = true;
- }
- }
- $pageName = $this->pageSequence[$pageId];
- $page = $this->getPageByName( $pageName );
- }
- # If a back button was submitted, go back without submitting the form data.
- if ( $this->request->wasPosted() && $this->request->getBool( 'submit-back' ) ) {
- if ( $this->request->getVal( 'lastPage' ) ) {
- $nextPage = $this->request->getVal( 'lastPage' );
- } elseif ( $pageId !== false ) {
- # Main sequence page
- # Skip the skipped pages
- $nextPageId = $pageId;
- do {
- $nextPageId--;
- $nextPage = $this->pageSequence[$nextPageId];
- } while ( isset( $this->skippedPages[$nextPage] ) );
- } else {
- $nextPage = $this->pageSequence[$lowestUnhappy];
- }
- $this->output->redirect( $this->getUrl( [ 'page' => $nextPage ] ) );
- return $this->finish();
- }
- # Execute the page.
- $this->currentPageName = $page->getName();
- $this->startPageWrapper( $pageName );
- if ( $page->isSlow() ) {
- $this->disableTimeLimit();
- }
- $result = $page->execute();
- $this->endPageWrapper();
- if ( $result == 'skip' ) {
- # Page skipped without explicit submission.
- # Skip it when we click "back" so that we don't just go forward again.
- $this->skippedPages[$pageName] = true;
- $result = 'continue';
- } else {
- unset( $this->skippedPages[$pageName] );
- }
- # If it was posted, the page can request a continue to the next page.
- if ( $result === 'continue' && !$this->output->headerDone() ) {
- if ( $pageId !== false ) {
- $this->happyPages[$pageId] = true;
- }
- $lowestUnhappy = $this->getLowestUnhappy();
- if ( $this->request->getVal( 'lastPage' ) ) {
- $nextPage = $this->request->getVal( 'lastPage' );
- } elseif ( $pageId !== false ) {
- $nextPage = $this->pageSequence[$pageId + 1];
- } else {
- $nextPage = $this->pageSequence[$lowestUnhappy];
- }
- if ( array_search( $nextPage, $this->pageSequence ) > $lowestUnhappy ) {
- $nextPage = $this->pageSequence[$lowestUnhappy];
- }
- $this->output->redirect( $this->getUrl( [ 'page' => $nextPage ] ) );
- }
- return $this->finish();
- }
- /**
- * Find the next page in sequence that hasn't been completed
- * @return int
- */
- public function getLowestUnhappy() {
- if ( count( $this->happyPages ) == 0 ) {
- return 0;
- } else {
- return max( array_keys( $this->happyPages ) ) + 1;
- }
- }
- /**
- * Start the PHP session. This may be called before execute() to start the PHP session.
- *
- * @throws Exception
- * @return bool
- */
- public function startSession() {
- if ( wfIniGetBool( 'session.auto_start' ) || session_id() ) {
- // Done already
- return true;
- }
- $this->phpErrors = [];
- set_error_handler( [ $this, 'errorHandler' ] );
- try {
- session_name( 'mw_installer_session' );
- session_start();
- } catch ( Exception $e ) {
- restore_error_handler();
- throw $e;
- }
- restore_error_handler();
- if ( $this->phpErrors ) {
- return false;
- }
- return true;
- }
- /**
- * Get a hash of data identifying this MW installation.
- *
- * This is used by mw-config/index.php to prevent multiple installations of MW
- * on the same cookie domain from interfering with each other.
- *
- * @return string
- */
- public function getFingerprint() {
- // Get the base URL of the installation
- $url = $this->request->getFullRequestURL();
- if ( preg_match( '!^(.*\?)!', $url, $m ) ) {
- // Trim query string
- $url = $m[1];
- }
- if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
- // This... seems to try to get the base path from
- // the /mw-config/index.php. Kinda scary though?
- $url = $m[1];
- }
- return md5( serialize( [
- 'local path' => dirname( __DIR__ ),
- 'url' => $url,
- 'version' => $GLOBALS['wgVersion']
- ] ) );
- }
- /**
- * Show an error message in a box. Parameters are like wfMessage(), or
- * alternatively, pass a Message object in.
- * @param string|Message $msg
- * @param mixed ...$params
- */
- public function showError( $msg, ...$params ) {
- if ( !( $msg instanceof Message ) ) {
- $msg = wfMessage(
- $msg,
- array_map( 'htmlspecialchars', $params )
- );
- }
- $text = $msg->useDatabase( false )->plain();
- $box = Html::errorBox( $text, '', 'config-error-box' );
- $this->output->addHTML( $box );
- }
- /**
- * Temporary error handler for session start debugging.
- *
- * @param int $errno Unused
- * @param string $errstr
- */
- public function errorHandler( $errno, $errstr ) {
- $this->phpErrors[] = $errstr;
- }
- /**
- * Clean up from execute()
- *
- * @return array[]
- */
- public function finish() {
- $this->output->output();
- $this->session['happyPages'] = $this->happyPages;
- $this->session['skippedPages'] = $this->skippedPages;
- $this->session['settings'] = $this->settings;
- return $this->session;
- }
- /**
- * We're restarting the installation, reset the session, happyPages, etc
- */
- public function reset() {
- $this->session = [];
- $this->happyPages = [];
- $this->settings = [];
- }
- /**
- * Get a URL for submission back to the same script.
- *
- * @param string[] $query
- *
- * @return string
- */
- public function getUrl( $query = [] ) {
- $url = $this->request->getRequestURL();
- # Remove existing query
- $url = preg_replace( '/\?.*$/', '', $url );
- if ( $query ) {
- $url .= '?' . wfArrayToCgi( $query );
- }
- return $url;
- }
- /**
- * Get a WebInstallerPage by name.
- *
- * @param string $pageName
- * @return WebInstallerPage
- */
- public function getPageByName( $pageName ) {
- $pageClass = 'WebInstaller' . $pageName;
- return new $pageClass( $this );
- }
- /**
- * Get a session variable.
- *
- * @param string $name
- * @param array|null $default
- *
- * @return array
- */
- public function getSession( $name, $default = null ) {
- return $this->session[$name] ?? $default;
- }
- /**
- * Set a session variable.
- *
- * @param string $name Key for the variable
- * @param mixed $value
- */
- public function setSession( $name, $value ) {
- $this->session[$name] = $value;
- }
- /**
- * Get the next tabindex attribute value.
- *
- * @return int
- */
- public function nextTabIndex() {
- return $this->tabIndex++;
- }
- /**
- * Initializes language-related variables.
- */
- public function setupLanguage() {
- global $wgLang, $wgContLang, $wgLanguageCode;
- if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
- $wgLanguageCode = $this->getAcceptLanguage();
- $wgLang = Language::factory( $wgLanguageCode );
- RequestContext::getMain()->setLanguage( $wgLang );
- $this->setVar( 'wgLanguageCode', $wgLanguageCode );
- $this->setVar( '_UserLang', $wgLanguageCode );
- } else {
- $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
- }
- $wgContLang = MediaWikiServices::getInstance()->getContentLanguage();
- }
- /**
- * Retrieves MediaWiki language from Accept-Language HTTP header.
- *
- * @return string
- */
- public function getAcceptLanguage() {
- global $wgLanguageCode, $wgRequest;
- $mwLanguages = Language::fetchLanguageNames( null, 'mwfile' );
- $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
- foreach ( $headerLanguages as $lang ) {
- if ( isset( $mwLanguages[$lang] ) ) {
- return $lang;
- }
- }
- return $wgLanguageCode;
- }
- /**
- * Called by execute() before page output starts, to show a page list.
- *
- * @param string $currentPageName
- */
- private function startPageWrapper( $currentPageName ) {
- $s = "<div class=\"config-page-wrapper\">\n";
- $s .= "<div class=\"config-page\">\n";
- $s .= "<div class=\"config-page-list\"><ul>\n";
- $lastHappy = -1;
- foreach ( $this->pageSequence as $id => $pageName ) {
- $happy = !empty( $this->happyPages[$id] );
- $s .= $this->getPageListItem(
- $pageName,
- $happy || $lastHappy == $id - 1,
- $currentPageName
- );
- if ( $happy ) {
- $lastHappy = $id;
- }
- }
- $s .= "</ul><br/><ul>\n";
- $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
- // End list pane
- $s .= "</ul></div>\n";
- // Messages:
- // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
- // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
- // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
- // config-page-copying, config-page-upgradedoc, config-page-existingwiki
- $s .= Html::element( 'h2', [],
- wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() );
- $this->output->addHTMLNoFlush( $s );
- }
- /**
- * Get a list item for the page list.
- *
- * @param string $pageName
- * @param bool $enabled
- * @param string $currentPageName
- *
- * @return string
- */
- private function getPageListItem( $pageName, $enabled, $currentPageName ) {
- $s = "<li class=\"config-page-list-item\">";
- // Messages:
- // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
- // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
- // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
- // config-page-copying, config-page-upgradedoc, config-page-existingwiki
- $name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text();
- if ( $enabled ) {
- $query = [ 'page' => $pageName ];
- if ( !in_array( $pageName, $this->pageSequence ) ) {
- if ( in_array( $currentPageName, $this->pageSequence ) ) {
- $query['lastPage'] = $currentPageName;
- }
- $link = Html::element( 'a',
- [
- 'href' => $this->getUrl( $query )
- ],
- $name
- );
- } else {
- $link = htmlspecialchars( $name );
- }
- if ( $pageName == $currentPageName ) {
- $s .= "<span class=\"config-page-current\">$link</span>";
- } else {
- $s .= $link;
- }
- } else {
- $s .= Html::element( 'span',
- [
- 'class' => 'config-page-disabled'
- ],
- $name
- );
- }
- $s .= "</li>\n";
- return $s;
- }
- /**
- * Output some stuff after a page is finished.
- */
- private function endPageWrapper() {
- $this->output->addHTMLNoFlush(
- "<div class=\"visualClear\"></div>\n" .
- "</div>\n" .
- "<div class=\"visualClear\"></div>\n" .
- "</div>" );
- }
- /**
- * Get HTML for an error box with an icon.
- *
- * @deprecated since 1.34 Use Html::errorBox() instead.
- * @param string $text Wikitext, get this with wfMessage()->plain()
- *
- * @return string
- */
- public function getErrorBox( $text ) {
- wfDeprecated( __METHOD__, '1.34' );
- return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
- }
- /**
- * Get HTML for a warning box with an icon.
- *
- * @deprecated since 1.34 Use Html::warningBox() instead.
- * @param string $text Wikitext, get this with wfMessage()->plain()
- *
- * @return string
- */
- public function getWarningBox( $text ) {
- wfDeprecated( __METHOD__, '1.34' );
- return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
- }
- /**
- * Get HTML for an information message box with an icon.
- *
- * @deprecated since 1.34.
- * @param string|HtmlArmor $text Wikitext to be parsed (from Message::plain) or raw HTML.
- * @param string|bool $icon Icon name, file in mw-config/images. Default: false
- * @param string|bool $class Additional class name to add to the wrapper div. Default: false.
- * @return string HTML
- */
- public function getInfoBox( $text, $icon = false, $class = false ) {
- wfDeprecated( __METHOD__, '1.34' );
- $html = ( $text instanceof HtmlArmor ) ?
- HtmlArmor::getHtml( $text ) :
- $this->parse( $text, true );
- $icon = ( $icon == false ) ?
- 'images/info-32.png' :
- 'images/' . $icon;
- $alt = wfMessage( 'config-information' )->text();
- return Html::infoBox( $html, $icon, $alt, $class );
- }
- /**
- * Get small text indented help for a preceding form field.
- * Parameters like wfMessage().
- *
- * @param string $msg
- * @return string
- */
- public function getHelpBox( $msg, ...$args ) {
- $args = array_map( 'htmlspecialchars', $args );
- $text = wfMessage( $msg, $args )->useDatabase( false )->plain();
- $html = $this->parse( $text, true );
- $id = 'helpBox-' . $this->helpBoxId++;
- return "<div class=\"config-help-field-container\">\n" .
- "<input type=\"checkbox\" class=\"config-help-field-checkbox\" id=\"$id\" />" .
- "<label class=\"config-help-field-hint\" for=\"$id\" title=\"" .
- wfMessage( 'config-help-tooltip' )->escaped() . "\">" .
- wfMessage( 'config-help' )->escaped() . "</label>\n" .
- "<div class=\"config-help-field-data\">" . $html . "</div>\n" .
- "</div>\n";
- }
- /**
- * Output a help box.
- * @param string $msg Key for wfMessage()
- * @param mixed ...$params
- */
- public function showHelpBox( $msg, ...$params ) {
- $html = $this->getHelpBox( $msg, ...$params );
- $this->output->addHTML( $html );
- }
- /**
- * Show a short informational message.
- * Output looks like a list.
- *
- * @param string $msg
- * @param mixed ...$params
- */
- public function showMessage( $msg, ...$params ) {
- $html = '<div class="config-message">' .
- $this->parse( wfMessage( $msg, $params )->useDatabase( false )->plain() ) .
- "</div>\n";
- $this->output->addHTML( $html );
- }
- /**
- * @param Status $status
- */
- public function showStatusMessage( Status $status ) {
- $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
- foreach ( $errors as $error ) {
- $this->showMessage( ...$error );
- }
- }
- /**
- * Label a control by wrapping a config-input div around it and putting a
- * label before it.
- *
- * @param string $msg
- * @param string $forId
- * @param string $contents
- * @param string $helpData
- * @return string
- */
- public function label( $msg, $forId, $contents, $helpData = "" ) {
- if ( strval( $msg ) == '' ) {
- $labelText = "\u{00A0}";
- } else {
- $labelText = wfMessage( $msg )->escaped();
- }
- $attributes = [ 'class' => 'config-label' ];
- if ( $forId ) {
- $attributes['for'] = $forId;
- }
- return "<div class=\"config-block\">\n" .
- " <div class=\"config-block-label\">\n" .
- Xml::tags( 'label',
- $attributes,
- $labelText
- ) . "\n" .
- $helpData .
- " </div>\n" .
- " <div class=\"config-block-elements\">\n" .
- $contents .
- " </div>\n" .
- "</div>\n";
- }
- /**
- * Get a labelled text box to configure a variable.
- *
- * @param mixed[] $params
- * Parameters are:
- * var: The variable to be configured (required)
- * label: The message name for the label (required)
- * attribs: Additional attributes for the input element (optional)
- * controlName: The name for the input element (optional)
- * value: The current value of the variable (optional)
- * help: The html for the help text (optional)
- *
- * @return string
- */
- public function getTextBox( $params ) {
- if ( !isset( $params['controlName'] ) ) {
- $params['controlName'] = 'config_' . $params['var'];
- }
- if ( !isset( $params['value'] ) ) {
- $params['value'] = $this->getVar( $params['var'] );
- }
- if ( !isset( $params['attribs'] ) ) {
- $params['attribs'] = [];
- }
- if ( !isset( $params['help'] ) ) {
- $params['help'] = "";
- }
- return $this->label(
- $params['label'],
- $params['controlName'],
- Xml::input(
- $params['controlName'],
- 30, // intended to be overridden by CSS
- $params['value'],
- $params['attribs'] + [
- 'id' => $params['controlName'],
- 'class' => 'config-input-text',
- 'tabindex' => $this->nextTabIndex()
- ]
- ),
- $params['help']
- );
- }
- /**
- * Get a labelled textarea to configure a variable
- *
- * @param mixed[] $params
- * Parameters are:
- * var: The variable to be configured (required)
- * label: The message name for the label (required)
- * attribs: Additional attributes for the input element (optional)
- * controlName: The name for the input element (optional)
- * value: The current value of the variable (optional)
- * help: The html for the help text (optional)
- *
- * @return string
- */
- public function getTextArea( $params ) {
- if ( !isset( $params['controlName'] ) ) {
- $params['controlName'] = 'config_' . $params['var'];
- }
- if ( !isset( $params['value'] ) ) {
- $params['value'] = $this->getVar( $params['var'] );
- }
- if ( !isset( $params['attribs'] ) ) {
- $params['attribs'] = [];
- }
- if ( !isset( $params['help'] ) ) {
- $params['help'] = "";
- }
- return $this->label(
- $params['label'],
- $params['controlName'],
- Xml::textarea(
- $params['controlName'],
- $params['value'],
- 30,
- 5,
- $params['attribs'] + [
- 'id' => $params['controlName'],
- 'class' => 'config-input-text',
- 'tabindex' => $this->nextTabIndex()
- ]
- ),
- $params['help']
- );
- }
- /**
- * Get a labelled password box to configure a variable.
- *
- * Implements password hiding
- * @param mixed[] $params
- * Parameters are:
- * var: The variable to be configured (required)
- * label: The message name for the label (required)
- * attribs: Additional attributes for the input element (optional)
- * controlName: The name for the input element (optional)
- * value: The current value of the variable (optional)
- * help: The html for the help text (optional)
- *
- * @return string
- */
- public function getPasswordBox( $params ) {
- if ( !isset( $params['value'] ) ) {
- $params['value'] = $this->getVar( $params['var'] );
- }
- if ( !isset( $params['attribs'] ) ) {
- $params['attribs'] = [];
- }
- $params['value'] = $this->getFakePassword( $params['value'] );
- $params['attribs']['type'] = 'password';
- return $this->getTextBox( $params );
- }
- /**
- * Get a labelled checkbox to configure a boolean variable.
- *
- * @param mixed[] $params
- * Parameters are:
- * var: The variable to be configured (required)
- * label: The message name for the label (required)
- * labelAttribs:Additional attributes for the label element (optional)
- * attribs: Additional attributes for the input element (optional)
- * controlName: The name for the input element (optional)
- * value: The current value of the variable (optional)
- * help: The html for the help text (optional)
- *
- * @return string
- */
- public function getCheckBox( $params ) {
- if ( !isset( $params['controlName'] ) ) {
- $params['controlName'] = 'config_' . $params['var'];
- }
- if ( !isset( $params['value'] ) ) {
- $params['value'] = $this->getVar( $params['var'] );
- }
- if ( !isset( $params['attribs'] ) ) {
- $params['attribs'] = [];
- }
- if ( !isset( $params['help'] ) ) {
- $params['help'] = "";
- }
- if ( !isset( $params['labelAttribs'] ) ) {
- $params['labelAttribs'] = [];
- }
- $labelText = $params['rawtext'] ?? $this->parse( wfMessage( $params['label'] )->plain() );
- return "<div class=\"config-input-check\">\n" .
- $params['help'] .
- Html::rawElement(
- 'label',
- $params['labelAttribs'],
- Xml::check(
- $params['controlName'],
- $params['value'],
- $params['attribs'] + [
- 'id' => $params['controlName'],
- 'tabindex' => $this->nextTabIndex(),
- ]
- ) .
- $labelText . "\n"
- ) .
- "</div>\n";
- }
- /**
- * Get a set of labelled radio buttons.
- *
- * @param mixed[] $params
- * Parameters are:
- * var: The variable to be configured (required)
- * label: The message name for the label (required)
- * itemLabelPrefix: The message name prefix for the item labels (required)
- * itemLabels: List of message names to use for the item labels instead
- * of itemLabelPrefix, keyed by values
- * values: List of allowed values (required)
- * itemAttribs: Array of attribute arrays, outer key is the value name (optional)
- * commonAttribs: Attribute array applied to all items
- * controlName: The name for the input element (optional)
- * value: The current value of the variable (optional)
- * help: The html for the help text (optional)
- *
- * @return string
- */
- public function getRadioSet( $params ) {
- $items = $this->getRadioElements( $params );
- $label = $params['label'] ?? '';
- if ( !isset( $params['controlName'] ) ) {
- $params['controlName'] = 'config_' . $params['var'];
- }
- if ( !isset( $params['help'] ) ) {
- $params['help'] = "";
- }
- $s = "<ul>\n";
- foreach ( $items as $value => $item ) {
- $s .= "<li>$item</li>\n";
- }
- $s .= "</ul>\n";
- return $this->label( $label, $params['controlName'], $s, $params['help'] );
- }
- /**
- * Get a set of labelled radio buttons. You probably want to use getRadioSet(), not this.
- *
- * @see getRadioSet
- *
- * @param mixed[] $params
- * @return array
- */
- public function getRadioElements( $params ) {
- if ( !isset( $params['controlName'] ) ) {
- $params['controlName'] = 'config_' . $params['var'];
- }
- if ( !isset( $params['value'] ) ) {
- $params['value'] = $this->getVar( $params['var'] );
- }
- $items = [];
- foreach ( $params['values'] as $value ) {
- $itemAttribs = [];
- if ( isset( $params['commonAttribs'] ) ) {
- $itemAttribs = $params['commonAttribs'];
- }
- if ( isset( $params['itemAttribs'][$value] ) ) {
- $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
- }
- $checked = $value == $params['value'];
- $id = $params['controlName'] . '_' . $value;
- $itemAttribs['id'] = $id;
- $itemAttribs['tabindex'] = $this->nextTabIndex();
- $items[$value] =
- Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
- "\u{00A0}" .
- Xml::tags( 'label', [ 'for' => $id ], $this->parse(
- isset( $params['itemLabels'] ) ?
- wfMessage( $params['itemLabels'][$value] )->plain() :
- wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
- ) );
- }
- return $items;
- }
- /**
- * Output an error or warning box using a Status object.
- *
- * @param Status $status
- */
- public function showStatusBox( $status ) {
- if ( !$status->isGood() ) {
- $text = $status->getWikiText();
- if ( $status->isOK() ) {
- $box = Html::warningBox( $text, 'config-warning-box' );
- } else {
- $box = Html::errorBox( $text, '', 'config-error-box' );
- }
- $this->output->addHTML( $box );
- }
- }
- /**
- * Convenience function to set variables based on form data.
- * Assumes that variables containing "password" in the name are (potentially
- * fake) passwords.
- *
- * @param string[] $varNames
- * @param string $prefix The prefix added to variables to obtain form names
- *
- * @return string[]
- */
- public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
- $newValues = [];
- foreach ( $varNames as $name ) {
- $value = $this->request->getVal( $prefix . $name );
- // T32524, do not trim passwords
- if ( stripos( $name, 'password' ) === false ) {
- $value = trim( $value );
- }
- $newValues[$name] = $value;
- if ( $value === null ) {
- // Checkbox?
- $this->setVar( $name, false );
- } elseif ( stripos( $name, 'password' ) !== false ) {
- $this->setPassword( $name, $value );
- } else {
- $this->setVar( $name, $value );
- }
- }
- return $newValues;
- }
- /**
- * Helper for WebInstallerOutput
- *
- * @internal For use by WebInstallerOutput
- * @param string $page
- * @return string
- */
- public function getDocUrl( $page ) {
- $query = [ 'page' => $page ];
- if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
- $query['lastPage'] = $this->currentPageName;
- }
- return $this->getUrl( $query );
- }
- /**
- * Helper for sidebar links.
- *
- * @internal For use in WebInstallerOutput class
- * @param string $url
- * @param string $linkText
- * @return string HTML
- */
- public function makeLinkItem( $url, $linkText ) {
- return Html::rawElement( 'li', [],
- Html::element( 'a', [ 'href' => $url ], $linkText )
- );
- }
- /**
- * Helper for "Download LocalSettings" link.
- *
- * @internal For use in WebInstallerComplete class
- * @return string Html for download link
- */
- public function makeDownloadLinkHtml() {
- $anchor = Html::rawElement( 'a',
- [ 'href' => $this->getUrl( [ 'localsettings' => 1 ] ) ],
- wfMessage( 'config-download-localsettings' )->parse()
- );
- return Html::rawElement( 'div', [ 'class' => 'config-download-link' ], $anchor );
- }
- /**
- * If the software package wants the LocalSettings.php file
- * to be placed in a specific location, override this function
- * (see mw-config/overrides/README) to return the path of
- * where the file should be saved, or false for a generic
- * "in the base of your install"
- *
- * @since 1.27
- * @return string|bool
- */
- public function getLocalSettingsLocation() {
- return false;
- }
- /**
- * @return bool
- */
- public function envCheckPath() {
- // PHP_SELF isn't available sometimes, such as when PHP is CGI but
- // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
- // to get the path to the current script... hopefully it's reliable. SIGH
- $path = false;
- if ( !empty( $_SERVER['PHP_SELF'] ) ) {
- $path = $_SERVER['PHP_SELF'];
- } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
- $path = $_SERVER['SCRIPT_NAME'];
- }
- if ( $path === false ) {
- $this->showError( 'config-no-uri' );
- return false;
- }
- return parent::envCheckPath();
- }
- public function envPrepPath() {
- parent::envPrepPath();
- // PHP_SELF isn't available sometimes, such as when PHP is CGI but
- // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
- // to get the path to the current script... hopefully it's reliable. SIGH
- $path = false;
- if ( !empty( $_SERVER['PHP_SELF'] ) ) {
- $path = $_SERVER['PHP_SELF'];
- } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
- $path = $_SERVER['SCRIPT_NAME'];
- }
- if ( $path !== false ) {
- $scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
- $this->setVar( 'wgScriptPath', "$scriptPath" );
- // Update variables set from Setup.php that are derived from wgScriptPath
- $this->setVar( 'wgScript', "$scriptPath/index.php" );
- $this->setVar( 'wgLoadScript', "$scriptPath/load.php" );
- $this->setVar( 'wgStylePath', "$scriptPath/skins" );
- $this->setVar( 'wgLocalStylePath', "$scriptPath/skins" );
- $this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" );
- $this->setVar( 'wgUploadPath', "$scriptPath/images" );
- $this->setVar( 'wgResourceBasePath', "$scriptPath" );
- }
- }
- /**
- * @return string
- */
- protected function envGetDefaultServer() {
- return WebRequest::detectServer();
- }
- /**
- * Actually output LocalSettings.php for download
- *
- * @suppress SecurityCheck-XSS
- */
- private function outputLS() {
- $this->request->response()->header( 'Content-type: application/x-httpd-php' );
- $this->request->response()->header(
- 'Content-Disposition: attachment; filename="LocalSettings.php"'
- );
- $ls = InstallerOverrides::getLocalSettingsGenerator( $this );
- $rightsProfile = $this->rightsProfiles[$this->getVar( '_RightsProfile' )];
- foreach ( $rightsProfile as $group => $rightsArr ) {
- $ls->setGroupRights( $group, $rightsArr );
- }
- echo $ls->getText();
- }
- /**
- * Output stylesheet for web installer pages
- */
- public function outputCss() {
- $this->request->response()->header( 'Content-type: text/css' );
- echo $this->output->getCSS();
- }
- /**
- * @return string[]
- */
- public function getPhpErrors() {
- return $this->phpErrors;
- }
- }
|