Commit graph

94 commits

Author SHA1 Message Date
jenkins-bot
332310d7a1 Merge "maintenance: Replace deprecated Maintenance::$mOptions" 2024-08-30 21:32:39 +00:00
Dreamy Jazz
bcb2112850 Start on tests for install.php
Why:
* Maintenance scripts in core are mostly untested and testing them
  will help to avoid regressions.

What:
* Create CommandLineInstallerTest.

Bug: T371167
Change-Id: Ia9ef03326d7c25b7eb310c191034932fffcbff8c
2024-08-30 19:44:52 +00:00
Umherirrender
76719d8425 maintenance: Replace deprecated Maintenance::$mOptions
Change-Id: I1b48b3c0b0e4bda5b61307725a2f08bbb5bbaaa9
2024-08-29 22:08:23 +02:00
Dreamy Jazz
e7393b3cc7 Exclude boilerplate maintenance code from code coverage reports
Why:
* Maintenance scripts in core have bolierplate code that is
  added before and after the class to allow directly running
  the maintenance script.
* Running the maintenance script directly has been deprecated
  since 1.40, so this boilerplate code is only to support a now
  deprecated method of running maintenance scripts.
* This code cannot also be marked as covered, due to PHPUnit
  not recognising code coverage for files.
* Therefore, it is best to ignore this boilerplate code in code
  coverage reports as it cannot be marked as covered and also
  is for deprecated code.

What:
* Wrap the boilerplate code (requiring Maintenance.php and then
  later defining the maintenance script class and running if the
  maintenance script was called directly) with @codeCoverageIgnore
  comments.
* Some files use a different boilerplate code, however, these
  should also be marked as ignored for coverage for the same
  reason that coverage is not properly reported for files.

Bug: T371167
Change-Id: I32f5c6362dfb354149a48ce9c28da9a7fc494f7c
2024-08-27 13:22:29 +01:00
addshore
34a17b32fc Add a basic interactive install.php
Start with the basic required arguments.
Leaves room for expansion.

Decided to have:
 - 0 arguments = interactive
 - 1+ argument results in regular validation messages
 - --help outputs help as normal
 - interactive mode mentions you might want --help

Bug: T48076
Change-Id: I972bf55f96c9cdf1a5eaf55c0e0117b190420d30
2024-07-24 22:12:12 +00:00
Bartosz Dziewoński
4108bbe1af Maintenance: Print errors from StatusValue objects in a consistent way
Allow Maintenance::error() and Maintenance::fatalError() to take
StatusValue objects. They now print each error message from the
status on a separate line, in English, ignoring on-wiki message
overrides, as wikitext but after parser function expansion.

Thoughts on the previously commonly used methods:

- $status->getMessage( false, false, 'en' )->text()
  Almost the same as the new output, but it allows on-wiki message
  overrides, and if there is more than one error, it prefixes each
  line with a '*' (like a wikitext list).

- $status->getMessage( false, false, 'en' )->plain()
- $status->getWikiText( false, false, 'en' )
  As above, but these forms do not expand parser functions
  such as {{GENDER:}}.

- print_r( $status->getErrorsArray(), true )
- print_r( $status->getErrors(), true )
  These forms output the message keys instead of the message text,
  which is not very human-readable.

The error messages are now always printed using error() rather
than output(), which means they go to STDERR rather than STDOUT
and they're printed even with the --quiet flag.

Change-Id: I5b8e7c7ed2a896a1029f58857a478d3f1b4b0589
2024-06-12 00:07:02 +02:00
Reedy
8600ee105c installer: Namespace more installer classes
Change-Id: If58d96c311bef728446b517bb7a81316b23aad4d
2024-01-13 23:42:08 +00:00
daniel
cea8aee05e Make Maintenance::finalSetup require a SettingsBuilder
Maintenance::finalSetup should have access to a SettingsBuilder so it
can manipulates config settings without resorting to global variables.
MaintenanceRunner will always provide a SettingsBuilder when calling
this method, so implementations should be able to rely on always getting
one.

The $settings parameter was introduced as optional in order to maintain
backwards compatibility with implementations that did not declare the
parameter. But these should all have been fixed since.

Depends-On: I8a3699b13bfb4dc15f3bed562731ed9d525651cc
Change-Id: I334a103e02fd905faafc43c7c5b95996bc91fd18
2024-01-08 09:40:18 -05:00
Kosta Harlan
06176a71b4
mw-install:sqlite: Load DevelopmentSettings
Why:

- We want developers to have DevelopmentSettings loaded by default

What:

- Define a new `--with-developmentsettings` argument for install.php,
  Set it to true in the `composer mw-install:sqlite` invocation

For now, this option is not supported in the web installer.

Bug: T347347
Change-Id: Icba2d614fd1349463fb745ef31f53a3b3834e5ad
2023-11-29 10:00:48 +01:00
Sam Wilson
d670dd7746 maintenance: Remove commented-out code from install.php
These commented-out options have been pending for many years, and
there doesn't seem to be a plan to make them work. They can easily
be re-added if required.

Change-Id: I6aa9bfe4509062b0f204800fcee70ba767fbc517
2023-11-21 20:06:47 +08:00
Waldir Pimenta
efe27a3399 Improve default scriptpath in installer.php
If the parameters to installer.php aren't specified,
it uses the default values as defined in DefaultSettings.php.
In the case of scriptpath, this doesn't work out of the box,
unless the server has previously been configured
to route /wiki (the default $wgScriptPath).

This change makes installer.php use mediawiki's core directory
as scriptpath, which at least would work without any special
configurations on the server.

This is similar to what the web installer does already
(see envCheckPath() at includes/installer/WebInstaller.php#L1153),
so this change also improves consistency between the installers.

Change-Id: Ie50be570a29eca9a734beee0337d667a8b29f65a
2023-05-20 15:50:30 +03:00
mainframe98
823d242933 installer: Support SSL in the installer
Only MySQL/MariaDB and PostgreSQL will show this option,
as SQLite connects to a file.

Bug: T335828
Change-Id: If29429bcf32807620755dd0b8797d12a13668266
2023-05-03 20:39:17 +02:00
Kevin Israel
63e07eed60 MaintenanceRunner: load script file early if possible
If possible, load the script file before running Setup.php. This way,
script files can control the setup process by defining constants. This
is needed by scome scripts, namely:
- instal.php, to override config loading by defining MW_CONFIG_CALLBACK
- generateConfigSchema.php, for setting MW_USE_CONFIG_SCHEMA_CLASS
- mergeMessageFileList.php, for setting MW_NO_EXTENSION_MESSAGES
- shell.php, for setting MW_NO_SESSION

Note that this will not work for scripts defined in extensions.

In order to allow script files to be loaded based on class name,
AutoLoader.php is included before Setup.php is run.

This is a modified version of I638f99c3cc6f8ab8216bd65ada959a6a11ff454b.

Co-authored-by: PleaseStand <pleasestand@live.com>
Change-Id: I2bf3b91c0a7162413cd1392252cb4f29a0d3d594
2023-03-14 10:18:29 +01:00
daniel
7dcfbf2a62 Allow some maintenance scripts to be called without a LocalSettings
Subclasses of Maintenance that can function without database access can
now override canExecuteWithoutLocalSettings to return true.
This is useful for scripts that need to be able to run before or without
installing MediaWiki.

When no config file is present, the storage backend will be disabled.
Any attempt to access the database will result in an error.

NOTE: This makes MediaWikiServices::disableBackendServices() more
comprehensive, to avoid premature failures during service
construction. This change makes it necessary to adjust how the
installer manages service overrides.

The CLI installer is covered by CI, I tested the web installer
manually.

Change-Id: Ie84010c80f32cbdfd34aff9dde1bfde1ed531793
2023-02-16 21:11:33 +00:00
daniel
52ebdb1ed0
Maintenance: Add support for documenting multi-args
Add suppor for documenting multi-value positional args.

Also fixes an issue with errors about missing args being shown even when
--help is given.

Change-Id: I6e07115aaa0f557614979adcd3f0423dd37fe8bc
2023-01-28 22:34:52 -08:00
jenkins-bot
00e065161a Merge "installer: Improve message handling for cli installer/install.php" 2023-01-10 00:17:08 +00:00
daniel
180f0a6468 Introduce run.php for running maintenance scripts
Maintenance scripts can now be run like this:

    maintenance/run.php <class>

NOTE: This introduces a new callback into Setup.php,
MW_FINAL_SETUP_CALLBACK. In contrast to MW_SETUP_CALLBACK, it is
called after extensions have been initialized.

Bug: T99268
Change-Id: Ia221f72d6b7d23df74623d60ade7fe3e5d913074
2022-12-21 06:52:04 +00:00
Umherirrender
8552ceabc4 installer: Improve message handling for cli installer/install.php
Avoid showing the error messages twice

Make the installer responsible to show the detail error text

Bug: T253341
Change-Id: I8f146cb1affca3711c102284534783cc50b514f8
2022-12-16 15:30:57 +00:00
daniel
7f8e3c5360 Docs: remove references to DefaultSettings.php
Bug: T300129
Change-Id: I1e83a0dde6235bed91d28d7d43691c6a5d979f2f
2022-05-30 21:27:09 +02:00
Umherirrender
e3acf723de installer,rdbms: Remove hints to Oracle and Microsoft SQL Server
Fix i18n messages still refers to both rdbms

Bug: T230418
Change-Id: I830c192331786d0dcf58eaf09e34f49fa4c88a06
2022-05-27 23:47:42 +00:00
Reedy
8016d7262f maintenance: Replace some usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: Id1a2d0dedd3326083b6a9727f1ab68ddd8f65df8
2022-02-24 12:52:05 +00:00
Tim Starling
20d06b34bb Safer autoloading with respect to file-scope code
Many files were in the autoloader despite having potentially harmful
file-scope code.

* Exclude all CommandLineInc maintenance scripts from the autoloader.
* Introduce  "NO_AUTOLOAD" tag which excludes the file containing it
  from the autoloader. Use it on CommandLineInc.php and a few
  suspicious-looking files without classes in case they are refactored
  to add classes in the future.
* Add a test which parses all non-PSR4 class files and confirms that
  they do not contain dangerous file-scope code. It's slow (15s) but
  its results were enlightening.
* Several maintenance scripts define constants in the file scope,
  intending to modify the behaviour of MediaWiki. Either move the
  define() to a later setup function, or protect with NO_AUTOLOAD.
* Use require_once consistently with Maintenance.php and
  doMaintenance.php, per the original convention which is supposed to
  allow one maintenance script to use the class of another maintenance
  script. Using require breaks autoloading of these maintenance class
  files.
* When Maintenance.php is included, check if MediaWiki has already
  started, and if so, return early. Revert the fix for T250003 which
  is incompatible with this safety measure. Hopefully it was superseded
  by splitting out the class file.
* In runScript.php add a redundant PHP_SAPI check since it does some
  things in file-scope code before any other check will be run.
* Change the if(false) class_alias(...) to something more hackish and
  more compatible with the new test.
* Some site-related scripts found Maintenance.php in a non-standard way.
  Use the standard way.
* fileOpPerfTest.php called error_reporting(). Probably debugging code
  left in; removed.
* Moved mediawiki.compress.7z registration from the class file to the
  caller.

Change-Id: I1b1be90343a5ab678df6f1b1bdd03319dcf6537f
2021-01-11 11:59:36 +11:00
Kunal Mehta
03078991c4 Disable $wgServer autodetection to prevent cache poisoning attacks
Since MediaWiki 1.18, $wgServer has been automatically set by the web installer
when it generates LocalSettings.php, so this shouldn't be an issue for most
wikis. The CLI installer now supports a --server optional parameter to
specify $wgServer, otherwise it'll be set to 'http://localhost' by default.

Users will see a fatal error pointing them to the on-wiki $wgServer
documentation that I've updated as well.

Originally this functionality was slated for removal in 1.20, but now is
just a good time as any. It also calls into other parts of MediaWiki before
most things are initialized, making it difficult to librarize some code.

Bug: T30798
Bug: T232931
Change-Id: Ia5d616e7fafbab01655067c24c5a3a073b254f21
2019-10-30 15:49:41 +11:00
Umherirrender
7363e38ddf Set public for override of Maintenance functions
The following function are set to public in the parent class and cannot
have another visibility in subclasses
Maintenance::__construct
Maintenance::execute
Maintenance::getDbType
Maintenance::validateParamsAndArgs
Maintenance::setDB

Change-Id: I0cd6514642d479aca20f1221bf673b0713c21631
2019-10-09 20:41:33 +02:00
Umherirrender
1eb5d8e44d Do not output wikitext in maintenance script
Also remove print_r with a string
Always use english for maintenance scripts

Bug: T229843
Change-Id: I539a1ac1f6a201dd8ee9ce89599cc34bebfba79f
2019-09-20 18:28:34 +02:00
Reedy
f1f9006707 Display error if Installer->execute() doesn't return a good status object
Bug: T232425
Change-Id: Ic41acdfd6cdd96a393e0b2af28f69da1ff6653b7
2019-09-10 03:19:51 +01:00
Brad Jorsch
0aec1401e5 Revert and fix "Revert "Modify -—with-extensions to throw extension dependency errors""
This reverts commit cc7ec36a57.

It makes the following changes from the original patch:
* findExtensions() will not consider config-extension-not-found as an
  error.
* Fixed a bug where extension info wouldn't actually be returned by
  findExtensions().
* When an extension's dependency doesn't exist, wrap the
  config-extension-not-found error in config-extension-dependency.
  This makes it more clear, and prevents the error from being ignored
  per the first bullet.
* maintenance/install.php will use ->text() rather than ->parse()
  when printing thrown errors.
* Change the stuff done to make phan happy.

Bug: T225512
Change-Id: I7d29700e8b7e91841556847d669b350cbd306fe6
2019-09-05 13:16:40 -04:00
RazeSoldier
b873e9294b Make CliInstaller control the processing logic of the error
Previously, if there was an error during CLI installation,
CliInstaller::showStatusMessage() exited the script directly. The exit
timing of the script should be given to the caller, not the callee.
So, I coding:
[1] Remove `exit()` from CliInstaller::showStatusMessage()
[2] Make the callee to return Status, the caller determine how to handle these Status
[3] Strictly check the key database type instead of just outputting message

Bug: T46511
Change-Id: I72ffd33fe5c592b9ea78f37bae5a9c081295c624
2019-07-29 20:18:08 +08:00
Brian Wolff
2295414fae Only show config-install-success on command line installer where it makes sense
In the web installer this isn't the last step and there is a different
success message. Replace the existing config-install-success with a
much more generic config-install-db-success message.

Previously we were telling people to go to their wiki prior to
them downloading LocalSettings.php which would obviously not work.

Change-Id: I56e28157a1a4d55e4eeda5fdd536289960511938
2019-01-08 13:34:24 +00:00
Tim Starling
5e9ada5882 install.php: Allow extensions and skins to be specified
Allow the extensions and skins installed by maintenance/install.php to
be customised using --skins= and --extensions=. If the argument is
am empty string then no extensions/skins are installed. For backwards
compatibility, the default is to install all skins, but to install all
extensions only if --with-extensions is given.

The new CLI options may be specified multiple times, but for
convenience, comma-separated lists can also be used.

Also:
* Rename $option to $options
* If an extension has a dependency error, propagate the very readable
  error message generated by ExtensionRegistry back to the user.
* Split getExtensionInfo() from the loop body of findExtensionsByType(),
  so that CliInstaller can use it to validate its parameters and get
  error messages.
* I didn't like the idea of removing the "s" from the directory name in
  order to construct the JSON file name, so I split
  findExtensionsByType() from findExtensions(), with the former not
  having this hack. In findExtensions(), make the previous assumption
  that the directory name is always "extensions" or "skins" explicit,
  throwing an exception if it is otherwise.

Change-Id: Id0fb63cd4e61a047ef3396ee1c38d6073dfc7fd1
2018-10-10 03:26:14 +00:00
Antoine Musso
836890daf0 Let install.php detect and inject extensions [2]
For CI, I went with a dirty trick to find extensions and either
wfLoadExtension() or include them. That has since been ported to
Installer::findExtensions() and LocalSettingsGenerator::getText().

The WebInstaller() relies on that to detect extensions and let the user
tick the ones to be installed.

Add --with-extensions to install.php so one can include all extensions
from the command line.

Note: The CliInstaller always wfLoad() any skin it can find.

The original patch 53926d9d was broken and got reverted. This is the
proper one.

Bug: T189567
Change-Id: I41820fce12e01224d64ab711e016835ef4d4febc
2018-04-04 14:25:30 +02:00
Hashar
493c2c765f Revert "Let install.php detect and inject extensions"
It is blatantly broken using non existing variables:
$installer and $options

This reverts commit 53926d9d69.

Bug: T189567
Change-Id: Idd1f002bbd5d474f9fe386cd0e326e1fbfdec097
2018-03-14 22:11:21 +00:00
Antoine Musso
53926d9d69 Let install.php detect and inject extensions
For CI, I went with a dirty trick to find extensions and either
wfLoadExtension() or include them. That has since been ported to
Installer::findExtensions() and LocalSettingsGenerator::getText().

The WebInstaller() relies on that to detect extensions and let the user
tick the ones to be installed.

Add --with-extensions to install.php so one can include all extensions
from the command line.

Note: The CliInstaller always wfLoad() any skin it can find.

Bug: T189567
Change-Id: Ic8aa6bea4e7294e54fd5b71df267c9e934f78fce
2018-03-13 10:36:16 +01:00
Reedy
39f0f919c5 Update suppressWarning()/restoreWarning() calls
Bug: T182273
Change-Id: I9e1b628fe5949ca54258424c2e45b2fb6d491d0f
2018-02-10 08:50:12 +00:00
Umherirrender
ad776c7d5f Use ::class to resolve class names in maintenance scripts
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: I1d4567f47f93eb1436cb98558388e48d35258666
2018-01-23 17:40:16 +00:00
Bryan Davis
9e34eeff23 Maintenance: add fatalError() method
Deprecate the second argument to Maintenance::error() in favor of a new
Maintenance::fatalError() method. This is intended to make it easier to
review flow control in maintenance scripts.

Change-Id: I75699008638f7e99b11210c7bb9e2e131fca7c9e
2017-11-21 21:34:16 -07:00
addshore
ba87c9a6c6 Allow install.php to run env-checks with no db
Bug: T169668
Change-Id: Ibb05b26cbf2d26c02ee7f26497e16d2c98e97de2
2017-07-04 19:39:42 +01:00
addshore
99b0296945 Don't ask for password for env-checks in install.php
Bug: T169669
Change-Id: I00dbaca0e4532ecc499317ec8f1cb7f9eb872db3
2017-07-04 19:31:22 +01:00
Kevin Israel
e257d0313f Maintenance: Use __DIR__ instead of dirname( __FILE__ )
dirname( __FILE__ ) was used because it worked in PHP 5.2, allowing
the version check to function correctly. However, Maintenance.php
now uses the short array syntax, which is a parse error before 5.4:

> Parse error: syntax error, unexpected '[' in maintenance/Maintenance.php
> on line 66

Also, do the same in install.php where it includes Maintenance.php.

Change-Id: I3373a02c684bb6cbde83d7bedc204818f3394602
2016-06-14 20:44:30 -04:00
umherirrender
04bef3dd66 phpcs: Use __DIR__ constant instead of calling
Replaced all dirname(__FILE__) by __DIR__ or added
@codingStandardsIgnore

Found by tests:
https://integration.wikimedia.org/ci/job/mediawiki-core-phpcs/2736/consoleFull

Change-Id: I90ff10f183ed60175fe580c43d73c0e57fd04234
2015-11-15 21:14:42 +01:00
C. Scott Ananian
50109405df Typo fix for maintenance/install.php.
Change-Id: Ic5d906ade363dc544bc239eb553e2567759dd17f
2015-10-27 15:48:52 -04:00
Kunal Mehta
f6e5079a69 Use mediawiki/at-ease library for suppressing warnings
wfSuppressWarnings() and wfRestoreWarnings() were split out into a
separate library. All usages in core were replaced with the new
functions, and the wf* global functions are marked as deprecated.

Additionally, some uses of @ were replaced due to composer's autoloader
being loaded even earlier.

Ie1234f8c12693408de9b94bf6f84480a90bd4f8e adds the library to
mediawiki/vendor.

Bug: T100923
Change-Id: I5c35079a0a656180852be0ae6b1262d40f6534c4
2015-06-11 18:49:29 +00:00
jenkins-bot
aa59d1955d Merge "Remove check for PHP version in install.php" 2014-07-30 15:47:47 +00:00
umherirrender
d15f1cc5e1 Break some long lines in maintenance, skins, tests
Change-Id: I5d86ad3e0c90e09440268a670f5af3e2bf080612
2014-07-24 19:03:17 +02:00
withoutaname
a0711d669b Remove check for PHP version in install.php
It's redundant to the check already done in Maintenance.php

Change-Id: I525dc8ac5a9872b82209b1a94bb306568dc0901b
2014-07-20 11:16:55 -07:00
Chad Horohoe
a4334bbef5 Use PHP_VERSION constant instead of phpversion() function call
Change-Id: Ifb3d1bd92d6abaa561e7337b311b4cb10c38a2b6
2014-07-09 16:46:35 -07:00
Skizzerz
30a82aae9c Set the default database schema to "mediawiki" so as not to break the CLI installer.
Due to changes made to support Microsoft SQL Server, $wgDBmwschema changed its default from
"mediawiki" to null in DefaultSettings.php, as anything else horribly broke every DBMS that did
not use schemas (such as MySQL and SQLite). This change makes it so that the default value can
be properly overridden again by PostgreSQL and Microsoft SQL Server, and also enables the
--dbschema flag to the CLI installer.

Bug: 64043
Change-Id: Id364306d883e0d494b948854e05f3f79ba7dd6d2
2014-07-09 00:20:36 +00:00
Waldir Pimenta
af724895e3 Several tweaks to the install.php script
- Fix description of the "admin" option, which says there's a default,
  "WikiSysop", when this isn't the case.
- Use "MediaWiki" instead of "Don't care" as the default value
  for the "name" argument
- make the "name" argument optional, so that its default value
  can actually work as such
- test for getOption's default parameter value (null)
  rather than providing one (false) and testing for it
- fix indication of default value for --dbpath
  and document where it comes from
- format the default for --confpath
  the same way as other defaults are displayed
- add description
- use trim() for --passfile, as is done for --dbpassfile
- use single quotes where possible
- mention in the documentation where the default values come from
- various minor text adjustments
- bonus: typo fix in a comment in Maintenance.php

Change-Id: Icbc0b02cfbf09b3f97ed86f4a68c3b35a9c839c8
2014-05-11 01:51:50 +00:00
Siebrand Mazeland
5a77286a1e Update formatting in maintenance/ (3/4)
Change-Id: I4390c4ea12a6a626b0e6817b6446635116ca9fe3
2014-04-23 20:09:13 +02:00
Siebrand Mazeland
cb8a938105 Pass phpcs-strict on maintenance/ (4/8)
Change-Id: Ib9ee255740681f0d32d76b75ef33b369bc87bcc1
2014-04-23 10:26:09 +02:00