Commit graph

73 commits

Author SHA1 Message Date
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
Chad Horohoe
518fa756f2 Remove $wgTitle from all maintenance scripts
Shouldn't be needed and aren't for any core operations. If any
extension relies on these $wgTitles being set in maintenance
environments those extensions are broken and should be fixed.

Change-Id: Ie02a5042ab96e155d783d56d5340dd0da8e3d55c
2014-03-12 18:28:47 -07:00
Timo Tijhof
beb1c4a0ec phpcs: More require/include is not a function
Follows-up I1343872de7, Ia533aedf63 and I2df2f80b81.

Also updated usage in text in documentation and the
installer LocalSettingsGenerator.

Most of them were handled by this regex:
- find: (require|include|require_once|include_once)\s*\(\s*(.+?)\s*\)\s*;$
- replace: $1 $2;

Change-Id: I6b38aad9a5149c9c43ce18bd8edbab14b8ce43fa
2013-05-21 23:26:28 +02:00
Timo Tijhof
50e7985d4d phpcs: Fix WhiteSpace.LanguageConstructSpacing warnings
Squiz.WhiteSpace.LanguageConstructSpacing:
   Language constructs must be followed by a single space;
   expected "require_once expression" but found
   "require_once(expression)"

It is a keyword (e.g. like `new`, `return` and `print`). As
such the parentheses don't make sense.

Per our code conventions, we use a space after keywords like
these. We appeared to have an unwritten exception for `require`
that doesn't make sense. About 60% of require/include usage
was missing the space and/or had superfluous parentheses.

It is as silly as print("foo") or return("foo"), it works
because keywords have no significance for whitespace between
it and the expression that follows, and since experessions can
be wrapped in parentheses for clarity (e.g. when doing string
concatenation or mathematical operations) the parenthesis
before and after basiclaly just ignored.

Change-Id: I2df2f80b8123714bea7e0771bf94b51ad5bb4b87
2013-05-09 05:56:26 +02:00
umherirrender
bfb75bc8e2 Fixed spacing around parenthesis in languages/tests/maintenance
Change-Id: Idd4299d17f1fcf98ab1d635484cb4e880f35ee24
2013-04-28 15:57:34 +00:00
umherirrender
b114f5e1c1 Fixed some spacing in maintenance folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: I9657f72996358f8c1c154cea1ea97970d973723c
2013-04-18 20:48:44 +02:00
umherirrender
15abcf71ca Added/Removed spaces around string concatenation
And added/removed spaces around some other tokens,
like +, -, *, /, <, >, =, !

Fixed windows newline style

Change-Id: I0b9c8c408f3f6bfc0d685a074d7ec468fb848fc8
2013-04-13 13:36:24 +02:00
Platonides
32139b0ddf Make update.php and install.php use wfPHPVersionError() and reorganise it
update.php and install.php now use wfPHPVersionError()

Moved to wfPHPVersionError( cli ) the suggestion of another binary name.

Old PHP versions won't have $_SERVER superglobal, hardcode HTTP/1.0 in that case.

Store in a variable the minimum version of PHP supported by MediaWiki.

Changed PHP_VERSION to phpversion(), although it doesn't matter for the version
ranges this works.

phpversion() has been present since PHP-2.0
PHP_VERSION was added in PHP 3.0RC5

On its current form in PHP 4 it was moved from Zend/zend_constants.c
to main/main.c by Zeev in commits 71dddd7db7e768ae8145e085fcbb6b6db4a1c40a and
fb1c77bd4f8a636ba47d720f8ca65fc6baae836d (1999-12-17)
It had been commented there since the beginning of svn history (1999-04-07)

The earliest version we can target seems to be PHP 4.1.0
PHP 4.0.0 produces a parse error on a require_once not followed by a literal
path (although you can use require with an expression), plus its dirname()
is quite dumb, and wouldn't provide the right path (would require you to call
"php ./update.php" from maintenance folder, not "php update.php" or
"php maintenance/update.php" from the main dir)

Replacing pathinfo( $_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME ); into a pathinfo()
to another variable since pathinfo( "", PATHINFO_DIRNAME ); core dumps in PHP 4.1.0
(works if $path is not empty)

The value of the pragma directive is 'no-cache', not 'nocache'. See section 14.32
of rfc2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32

Change-Id: I6294e86a5f3e11b9ea0f62762815e7c71b9037ce
2013-02-26 21:55:06 +01:00
jan
22c7d82351 Add warnings to install.php for files-options
Add warnings to install.php if dbpass and dbpassfile or pass and passfile is provided.

Change-Id: Ibf73ddd80eebbd9886e18cee8eaf32b7127b660f
2012-10-07 08:26:49 +02:00
jan
b22791b8dc Add passfile option to install.php
Add passfile option to install.php so a file with the password can be used.

Change-Id: Ibf45933971374c90726359cff16617cb37d002fc
2012-10-07 08:15:28 +02:00
jeroendedauw
38c7f444e1 Use __DIR__ instead of dirname( __FILE__ )
We can now do this since we finally switched to PHP 5.3 for MW 1.20 and get rid of the silly dirname(__FILE__) stuff :)

Change-Id: Id9b2c9cd2e678197aa81c78adced5d1d31ff57b1
2012-08-27 21:45:00 +02:00
Alexandre Emsenhuber
32515c4bda Improve documentation of maintenance scripts.
Change-Id: If0af9922ede902c2c6f18b627d5810f3e888c944
2012-07-24 18:10:43 +02:00
Mark A. Hershberger
7e6dfd88a0 Bug 26911 - cli install doesn't ask for a password
Make the password parameter mandatory and change the help message.

Change-Id: Ibea29858be70a5188d167b9c1267b2db2564a96b
2012-06-22 19:51:20 -04:00
Max Semenik
63fb18bd4e Add a way for packagers to override some installation details
...after a discussion with Debian packagers. They can now override installer
classes and change LocalSettings.php the installer generates. The file
intended for such overrides, mw-config/overrides.php, has intentionally been
placed outside of includes to underline the "don't change includes" paradigm.

Change-Id: Id82b90f6740307609bc6c6f4fb8765bc3484dbe7
2012-06-12 20:18:44 +04:00
Reedy
f1bec81eba Various updates needed to bump min php version to 5.3.2
Change-Id: I22015387e4ac5839a907059086d787f352746886
2012-04-16 15:38:22 +01:00
Sam Reed
1c8186ac0d * (bug 30062) Add $wgDBprefix option to cli installer
Patch by Grunny
2011-11-11 00:05:04 +00:00
Max Semenik
8782b86117 Follow-up r68645: back out --email, still not used 2011-10-06 17:00:18 +00:00
Platonides
dcf288ad43 Remove trailing newline from pass, which is very unlikely to be intended. 2011-06-16 21:01:52 +00:00
Platonides
5cf5ec639b Allow to provide the db password inside a file instead of using
the command line, so that it isn't exposed in the process list.

Sadly, use of /dev/stdin or <(process) doesn't work in Linux, 
since they are shown as symlinks to pipe:[12345678] and php 
dereferences all of them. It has to be a real file.
However, such constructs work in Solaris, where they are 
presented as character devices.
2011-06-16 20:58:12 +00:00
Max Semenik
8b12b25902 Follow-up r89254 and r89481: re-did loading extension updates properly, now upgrading extension tables from web interface really works, and without notices 2011-06-05 19:52:03 +00:00
Tim Starling
6fec4e3fde Revert r87635, r87637, r87639, r87643 (MW_MIN_PHP_VERSION etc.): breaks HipHop support. 2011-05-15 13:21:16 +00:00
Happy-melon
cd128f4496 Follow-up r87637: the terrors of copy-and-paste. 2011-05-07 15:37:23 +00:00