summaryrefslogtreecommitdiff
path: root/includes/installer/WebInstaller.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/installer/WebInstaller.php')
-rw-r--r--includes/installer/WebInstaller.php264
1 files changed, 167 insertions, 97 deletions
diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php
index 1f8ee00a..f3dba3a7 100644
--- a/includes/installer/WebInstaller.php
+++ b/includes/installer/WebInstaller.php
@@ -44,13 +44,14 @@ class WebInstaller extends Installer {
/**
* Cached session array.
*
- * @var array
+ * @var array[]
*/
protected $session;
/**
* Captured PHP error text. Temporary.
- * @var array
+ *
+ * @var string[]
*/
protected $phpErrors;
@@ -60,8 +61,9 @@ class WebInstaller extends Installer {
* 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 array
+ * * Add a "WebInstaller<name>" class
+ *
+ * @var string[]
*/
public $pageSequence = array(
'Language',
@@ -78,7 +80,8 @@ class WebInstaller extends Installer {
/**
* Out of sequence pages, selectable by the user at any time.
- * @var array
+ *
+ * @var string[]
*/
protected $otherPages = array(
'Restart',
@@ -91,7 +94,8 @@ class WebInstaller extends Installer {
/**
* Array of pages which have declared that they have been submitted, have validated
* their input, and need no further processing.
- * @var array
+ *
+ * @var bool[]
*/
protected $happyPages;
@@ -99,24 +103,28 @@ class WebInstaller extends Installer {
* 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 array
+ *
+ * @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;
/**
* Name of the page we're on
+ *
* @var string
*/
protected $currentPageName;
@@ -124,7 +132,7 @@ class WebInstaller extends Installer {
/**
* Constructor.
*
- * @param $request WebRequest
+ * @param WebRequest $request
*/
public function __construct( WebRequest $request ) {
parent::__construct();
@@ -140,9 +148,9 @@ class WebInstaller extends Installer {
/**
* Main entry point.
*
- * @param array $session initial session array
+ * @param array[] $session Initial session array
*
- * @return Array: new session array
+ * @return array[] New session array
*/
public function execute( array $session ) {
$this->session = $session;
@@ -172,12 +180,9 @@ class WebInstaller extends Installer {
return $this->session;
}
- $cssDir = $this->request->getVal( 'css' );
- if ( $cssDir ) {
- $cssDir = ( $cssDir == 'rtl' ? 'rtl' : 'ltr' );
- $this->request->response()->header( 'Content-type: text/css' );
- echo $this->output->getCSS( $cssDir );
-
+ $isCSS = $this->request->getVal( 'css' );
+ if ( $isCSS ) {
+ $this->outputCss();
return $this->session;
}
@@ -326,6 +331,7 @@ class WebInstaller extends Installer {
/**
* Start the PHP session. This may be called before execute() to start the PHP session.
*
+ * @throws Exception
* @return bool
*/
public function startSession() {
@@ -336,12 +342,15 @@ class WebInstaller extends Installer {
$this->phpErrors = array();
set_error_handler( array( $this, 'errorHandler' ) );
- session_start();
+ try {
+ session_start();
+ } catch ( Exception $e ) {
+ restore_error_handler();
+ throw $e;
+ }
restore_error_handler();
if ( $this->phpErrors ) {
- $this->showError( 'config-session-error', $this->phpErrors[0] );
-
return false;
}
@@ -378,7 +387,7 @@ class WebInstaller extends Installer {
/**
* Show an error message in a box. Parameters are like wfMessage().
- * @param $msg
+ * @param string $msg
*/
public function showError( $msg /*...*/ ) {
$args = func_get_args();
@@ -390,8 +399,9 @@ class WebInstaller extends Installer {
/**
* Temporary error handler for session start debugging.
- * @param $errno
- * @param $errstr string
+ *
+ * @param int $errno Unused
+ * @param string $errstr
*/
public function errorHandler( $errno, $errstr ) {
$this->phpErrors[] = $errstr;
@@ -400,7 +410,7 @@ class WebInstaller extends Installer {
/**
* Clean up from execute()
*
- * @return array
+ * @return array[]
*/
public function finish() {
$this->output->output();
@@ -424,7 +434,8 @@ class WebInstaller extends Installer {
/**
* Get a URL for submission back to the same script.
*
- * @param $query array
+ * @param string[] $query
+ *
* @return string
*/
public function getUrl( $query = array() ) {
@@ -442,11 +453,11 @@ class WebInstaller extends Installer {
/**
* Get a WebInstallerPage by name.
*
- * @param $pageName String
+ * @param string $pageName
* @return WebInstallerPage
*/
public function getPageByName( $pageName ) {
- $pageClass = 'WebInstaller_' . $pageName;
+ $pageClass = 'WebInstaller' . $pageName;
return new $pageClass( $this );
}
@@ -454,9 +465,10 @@ class WebInstaller extends Installer {
/**
* Get a session variable.
*
- * @param $name String
- * @param $default
- * @return null
+ * @param string $name
+ * @param array $default
+ *
+ * @return array
*/
public function getSession( $name, $default = null ) {
if ( !isset( $this->session[$name] ) ) {
@@ -468,8 +480,9 @@ class WebInstaller extends Installer {
/**
* Set a session variable.
- * @param string $name key for the variable
- * @param $value Mixed
+ *
+ * @param string $name Key for the variable
+ * @param mixed $value
*/
public function setSession( $name, $value ) {
$this->session[$name] = $value;
@@ -477,6 +490,7 @@ class WebInstaller extends Installer {
/**
* Get the next tabindex attribute value.
+ *
* @return int
*/
public function nextTabIndex() {
@@ -523,7 +537,7 @@ class WebInstaller extends Installer {
/**
* Called by execute() before page output starts, to show a page list.
*
- * @param $currentPageName string
+ * @param string $currentPageName
*/
private function startPageWrapper( $currentPageName ) {
$s = "<div class=\"config-page-wrapper\">\n";
@@ -563,9 +577,9 @@ class WebInstaller extends Installer {
/**
* Get a list item for the page list.
*
- * @param $pageName string
- * @param $enabled boolean
- * @param $currentPageName string
+ * @param string $pageName
+ * @param bool $enabled
+ * @param string $currentPageName
*
* @return string
*/
@@ -630,7 +644,7 @@ class WebInstaller extends Installer {
/**
* Get HTML for an error box with an icon.
*
- * @param string $text wikitext, get this with wfMessage()->plain()
+ * @param string $text Wikitext, get this with wfMessage()->plain()
*
* @return string
*/
@@ -641,7 +655,7 @@ class WebInstaller extends Installer {
/**
* Get HTML for a warning box with an icon.
*
- * @param string $text wikitext, get this with wfMessage()->plain()
+ * @param string $text Wikitext, get this with wfMessage()->plain()
*
* @return string
*/
@@ -652,27 +666,27 @@ class WebInstaller extends Installer {
/**
* Get HTML for an info box with an icon.
*
- * @param string $text wikitext, get this with wfMessage()->plain()
- * @param string $icon icon name, file in skins/common/images
- * @param string $class additional class name to add to the wrapper div
+ * @param string $text Wikitext, get this with wfMessage()->plain()
+ * @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
*/
public function getInfoBox( $text, $icon = false, $class = false ) {
$text = $this->parse( $text, true );
$icon = ( $icon == false ) ?
- '../skins/common/images/info-32.png' :
- '../skins/common/images/' . $icon;
+ 'images/info-32.png' :
+ 'images/' . $icon;
$alt = wfMessage( 'config-information' )->text();
- return Html::infoBox( $text, $icon, $alt, $class, false );
+ return Html::infoBox( $text, $icon, $alt, $class );
}
/**
* Get small text indented help for a preceding form field.
* Parameters like wfMessage().
*
- * @param $msg
+ * @param string $msg
* @return string
*/
public function getHelpBox( $msg /*, ... */ ) {
@@ -683,15 +697,16 @@ class WebInstaller extends Installer {
$html = $this->parse( $text, true );
return "<div class=\"mw-help-field-container\">\n" .
- "<span class=\"mw-help-field-hint\">" . wfMessage( 'config-help' )->escaped() .
- "</span>\n" .
+ "<span class=\"mw-help-field-hint\" title=\"" .
+ wfMessage( 'config-help-tooltip' )->escaped() . "\">" .
+ wfMessage( 'config-help' )->escaped() . "</span>\n" .
"<span class=\"mw-help-field-data\">" . $html . "</span>\n" .
"</div>\n";
}
/**
* Output a help box.
- * @param string $msg key for wfMessage()
+ * @param string $msg Key for wfMessage()
*/
public function showHelpBox( $msg /*, ... */ ) {
$args = func_get_args();
@@ -703,7 +718,7 @@ class WebInstaller extends Installer {
* Show a short informational message.
* Output looks like a list.
*
- * @param $msg string
+ * @param string $msg
*/
public function showMessage( $msg /*, ... */ ) {
$args = func_get_args();
@@ -715,7 +730,7 @@ class WebInstaller extends Installer {
}
/**
- * @param $status Status
+ * @param Status $status
*/
public function showStatusMessage( Status $status ) {
$errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
@@ -728,10 +743,10 @@ class WebInstaller extends Installer {
* Label a control by wrapping a config-input div around it and putting a
* label before it.
*
- * @param $msg
- * @param $forId
- * @param $contents
- * @param $helpData string
+ * @param string $msg
+ * @param string $forId
+ * @param string $contents
+ * @param string $helpData
* @return string
*/
public function label( $msg, $forId, $contents, $helpData = "" ) {
@@ -764,7 +779,7 @@ class WebInstaller extends Installer {
/**
* Get a labelled text box to configure a variable.
*
- * @param $params Array
+ * @param mixed[] $params
* Parameters are:
* var: The variable to be configured (required)
* label: The message name for the label (required)
@@ -811,7 +826,7 @@ class WebInstaller extends Installer {
/**
* Get a labelled textarea to configure a variable
*
- * @param $params Array
+ * @param mixed[] $params
* Parameters are:
* var: The variable to be configured (required)
* label: The message name for the label (required)
@@ -860,7 +875,7 @@ class WebInstaller extends Installer {
* Get a labelled password box to configure a variable.
*
* Implements password hiding
- * @param $params Array
+ * @param mixed[] $params
* Parameters are:
* var: The variable to be configured (required)
* label: The message name for the label (required)
@@ -889,7 +904,7 @@ class WebInstaller extends Installer {
/**
* Get a labelled checkbox to configure a boolean variable.
*
- * @param $params Array
+ * @param mixed[] $params
* Parameters are:
* var: The variable to be configured (required)
* label: The message name for the label (required)
@@ -917,10 +932,8 @@ class WebInstaller extends Installer {
}
if ( isset( $params['rawtext'] ) ) {
$labelText = $params['rawtext'];
- } elseif ( isset( $params['label'] ) ) {
- $labelText = $this->parse( wfMessage( $params['label'] )->text() );
} else {
- $labelText = "";
+ $labelText = $this->parse( wfMessage( $params['label'] )->text() );
}
return "<div class=\"config-input-check\">\n" .
@@ -942,11 +955,12 @@ class WebInstaller extends Installer {
/**
* Get a set of labelled radio buttons.
*
- * @param $params Array
+ * @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
@@ -957,23 +971,49 @@ class WebInstaller extends Installer {
* @return string
*/
public function getRadioSet( $params ) {
- if ( !isset( $params['controlName'] ) ) {
- $params['controlName'] = 'config_' . $params['var'];
- }
-
- if ( !isset( $params['value'] ) ) {
- $params['value'] = $this->getVar( $params['var'] );
- }
+ $items = $this->getRadioElements( $params );
if ( !isset( $params['label'] ) ) {
$label = '';
} else {
$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
+ *
+ * @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 = array();
+
foreach ( $params['values'] as $value ) {
$itemAttribs = array();
@@ -990,25 +1030,23 @@ class WebInstaller extends Installer {
$itemAttribs['id'] = $id;
$itemAttribs['tabindex'] = $this->nextTabIndex();
- $s .=
- '<li>' .
+ $items[$value] =
Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
'&#160;' .
Xml::tags( 'label', array( 'for' => $id ), $this->parse(
- wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
- ) ) .
- "</li>\n";
+ isset( $params['itemLabels'] ) ?
+ wfMessage( $params['itemLabels'][$value] )->plain() :
+ wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
+ ) );
}
- $s .= "</ul>\n";
-
- return $this->label( $label, $params['controlName'], $s, $params['help'] );
+ return $items;
}
/**
* Output an error or warning box using a Status object.
*
- * @param $status Status
+ * @param Status $status
*/
public function showStatusBox( $status ) {
if ( !$status->isGood() ) {
@@ -1029,16 +1067,20 @@ class WebInstaller extends Installer {
* Assumes that variables containing "password" in the name are (potentially
* fake) passwords.
*
- * @param $varNames Array
- * @param string $prefix the prefix added to variables to obtain form names
+ * @param string[] $varNames
+ * @param string $prefix The prefix added to variables to obtain form names
*
- * @return array
+ * @return string[]
*/
public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
$newValues = array();
foreach ( $varNames as $name ) {
- $value = trim( $this->request->getVal( $prefix . $name ) );
+ $value = $this->request->getVal( $prefix . $name );
+ // bug 30524, do not trim passwords
+ if ( stripos( $name, 'password' ) === false ) {
+ $value = trim( $value );
+ }
$newValues[$name] = $value;
if ( $value === null ) {
@@ -1059,7 +1101,8 @@ class WebInstaller extends Installer {
/**
* Helper for Installer::docLink()
*
- * @param $page
+ * @param string $page
+ *
* @return string
*/
protected function getDocUrl( $page ) {
@@ -1075,9 +1118,10 @@ class WebInstaller extends Installer {
/**
* Extension tag hook for a documentation link.
*
- * @param $linkText
- * @param $attribs
- * @param $parser
+ * @param string $linkText
+ * @param string[] $attribs
+ * @param Parser $parser Unused
+ *
* @return string
*/
public function docLink( $linkText, $attribs, $parser ) {
@@ -1091,20 +1135,17 @@ class WebInstaller extends Installer {
/**
* Helper for "Download LocalSettings" link on WebInstall_Complete
*
- * @param $text
- * @param $attribs
- * @param $parser
- * @return String Html for download link
+ * @param string $text Unused
+ * @param string[] $attribs Unused
+ * @param Parser $parser Unused
+ *
+ * @return string Html for download link
*/
public function downloadLinkHook( $text, $attribs, $parser ) {
- $img = Html::element( 'img', array(
- 'src' => '../skins/common/images/download-32.png',
- 'width' => '32',
- 'height' => '32',
- ) );
$anchor = Html::rawElement( 'a',
array( 'href' => $this->getURL( array( 'localsettings' => 1 ) ) ),
- $img . ' ' . wfMessage( 'config-download-localsettings' )->parse() );
+ wfMessage( 'config-download-localsettings' )->parse()
+ );
return Html::rawElement( 'div', array( 'class' => 'config-download-link' ), $anchor );
}
@@ -1123,8 +1164,18 @@ class WebInstaller extends Installer {
$path = $_SERVER['SCRIPT_NAME'];
}
if ( $path !== false ) {
- $uri = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
- $this->setVar( 'wgScriptPath', $uri );
+ $scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
+ $scriptExtension = $this->getVar( 'wgScriptExtension' );
+
+ $this->setVar( 'wgScriptPath', "$scriptPath" );
+ // Update variables set from Setup.php that are derived from wgScriptPath
+ $this->setVar( 'wgScript', "$scriptPath/index$scriptExtension" );
+ $this->setVar( 'wgLoadScript', "$scriptPath/load$scriptExtension" );
+ $this->setVar( 'wgStylePath', "$scriptPath/skins" );
+ $this->setVar( 'wgLocalStylePath', "$scriptPath/skins" );
+ $this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" );
+ $this->setVar( 'wgUploadPath', "$scriptPath/images" );
+
} else {
$this->showError( 'config-no-uri' );
@@ -1134,7 +1185,26 @@ class WebInstaller extends Installer {
return parent::envCheckPath();
}
+ /**
+ * @return string
+ */
protected function envGetDefaultServer() {
return WebRequest::detectServer();
}
+
+ /**
+ * 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;
+ }
+
}