aboutsummaryrefslogtreecommitdiffstats
path: root/maintenance/Maintenance.php
Commit message (Collapse)AuthorAgeFilesLines
* Fix even more PHPStorm inspections (#3)Tim Starling2023-03-251-1/+1
| | | | | | | | | | | | | | | * Inappropriate @inheritDoc usage. Arguably all @inheritDoc is inappropriate but these are the ones PHPStorm flags as misleading due to the method not being inherited. * Doc comment type does not match actual argument/return type. * I replaced "@return void|never" with "@return void" since never means never, it doesn't make sense for it to be conditional. If a method can return (even if that is unlikely) then @return contains the type that it returns. "@return never" means that there is no such type because the method never returns. * Incomplete/partial/broken doc tags Change-Id: Ide86bd6d2b44387f37d234c2b059d6fbc42ec962
* MaintenanceRunner: Pull some checks out of initInternal()Kevin Israel2023-01-111-0/+7
| | | | | | | | | | | | | | | | | | | | | | * Move the PHP_SAPI check to the earliest convenient point in Maintenance.php, well before we attempt to access $argv. * Remove the register_argc_argv check altogether; we don't allow "cgi" SAPI to be used for running scripts from the command line any more. Any value from php.ini is overridden by "cli" and "phpdbg" SAPIs: https://www.php.net/manual/en/features.commandline.differences.php https://github.com/php/php-src/blob/php-8.2.1/sapi/phpdbg/phpdbg.c#L991 And using "-d register_argc_argv=0" or similar seems unlikely. * Don't check if $IP is null (reverts b0647c30bc30874c). This specific check is not useful any more, as $IP is now initialized before the Maintenance object is constructed, and addOption() and similar methods happen to generate PHP errors in the described situation. If desired, a check serving the same purpose could be added in a separate commit. Change-Id: I8032ab18cb26d92ee01ab9851ea1d45b3f9eadbf
* Allow main settings file to be selected via env variable.daniel2022-02-061-0/+1
| | | | | | | | | | | | | | This allows a file other than LocalSettings.php to be used as the primary settings file by setting the MW_CONFIG_FILE environment variable. This also allows the primary settings file to use YAML or JSON format. Using static configuration files should be the default in the future. However, YAML files in the document root could easily be exposed to the public. Better not to encourage that, and require them to be enabled explicitly and loaded from a different place. Bug: T294750 Change-Id: I7747f83481cb05a6d05f819be652259951183819
* Make sure RUN_MAINTENANCE_IF_MAIN is defined in tests.daniel2021-01-191-12/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | This moves the definition of the RUN_MAINTENANCE_IF_MAIN constant in Maintenance.php before the check on MEDIAWIKI, so the constant will be defined even if MEDIAWIKI is also defined. This allows maintenance scripts to be successfully loaded in a context in which MEDIAWIKI is already defined, but RUN_MAINTENANCE_IF_MAIN is not. Without this change, such an attempt would fail with a warning that the constant is undefined at the bottom of the maintenance script. A notable use case for loading a maintenance script inline is calling RunJobs in a test case. This would work fine if the test is called via MediaWiki's phpunit wrapper, since that wrapper is itself written as a maintenance script, and thus declared RUN_MAINTENANCE_IF_MAIN. However, integration tests may also be invoked without the wrapper, using the phpunit.xml.dist config file instead. This is the standard way to invoke PHPUnit from within an IDE like PhpStorm, allowing for debugging of unit tests. So, without this patch, integration tests that call RunJobs fail due to an undeclared constant when run via IDE integration. With this patch, they work properly. Change-Id: I52889e092cc9f20bf892c297635b87a972dafa41
* Safer autoloading with respect to file-scope codeTim Starling2021-01-111-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix various MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineCommentReedy2020-05-211-4/+3
| | | | Change-Id: I50c7c93f1534e966224f98a835ca01f93eb9416d
* maintenance: Move FakeMaintenance and LoggedUpdateMaintenance to their own filesDaimona Eaytoy2020-04-211-1706/+3
| | | | | | | | | | | Originally submitted as commit 2cdeb26d0c2bc6f3fb4d05d7b8b72c4a601b3da7. This patch is fully backwards compatible. The Maintenance.php entry point is now a true entry point (i.e. no classes defined), and it requires all the *Maintenance classes. Bug: T246780 Change-Id: I75b22f54b19fe560ab71349189598245af1c5693
* maintenance: Add `@return-taint none` to getArg and getOptionDaimona Eaytoy2020-04-181-0/+2
| | | | | | | | | | | | In a generic context, $argv would be considered tainted by taint-check, which makes sense for certain applications. In the context of MW maintenance scripts, however, we can assume that arguments are trusted, because maintenance scripts can only be executed by sysadmins, who are generally trusted (and even if they aren't, they have other ways to compromise a wiki). Bug: T216348 Change-Id: I8e171f5dcd5b9232d45e85d775cd794f2ebb2dfc
* maintenance: Move $IP and MEDIAWIKI assignment to doMaintenance.phpTimo Tijhof2020-04-141-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | Per 4eb1e679d5, these are now documented as the bare minimum entry point responsibilities. For WebStart these are already consolidated, but for the CLI use case they were a bit scattered. Consolidate these in the CLI entry point (doMaintenance.php) for clarity. * $IP was previously assigned in Maintenance::__construct, which is called from doMaintenance.php. It still executes at the same logical time, one line above 'new $maintClass()'. * MEDIAWIKI was (for CLI) previously defined in Maintenance::setup() which is called from doMaintenance.php. This is now done a few lines earlier, and in the entry point file instead. For both of these, they are still available and set in all the same scenarios as before. Bug: T246076 Bug: T250003 Change-Id: I2a6f5e997a36502535eb383a95deac0ce74d83fb
* Maintenance: Don't redefine MW_ENTRY_POINT if it's already setArtBaltai2020-04-141-2/+3
| | | | | | | | | Maintenance.php may be included after other entry points in certain configurations (like IDE bootstrapping). So if MW_ENTRY_POINT is already set, don't try and define() it as another value. Bug: T250003 Change-Id: Ide011ad11d8dd29fe786a745c6e67259e46b9bfb
* Maintenance: Don't create DBLoadBalancerFactory to destroy itMarius Hoch2020-03-261-2/+8
| | | | | | | This is the right way to do this, per the documentation of ServiceContainer::peekService. Change-Id: I47c622faacea2ab49e16903e3b5aa9d1215d5bfb
* Deprecate Revision::loadFromPageIdPetr Pchelko2020-03-251-6/+8
| | | | | | Bug: T246284 Depends-On: Id4ec83cc0ac0685857064486697a7daed979ea69 Change-Id: I5de750322e30052700f509d2908456ebd5be95ef
* Remove compat code for pre-MCR schema.daniel2020-03-241-35/+10
| | | | | | | | NOTE: This was manually tested to ensure it does not break updates, see T242764. Bug: T198557 Change-Id: I1d9f5465018bae10124514bc38169e23e0e613e6
* Remove $wgProfileLimit settingTimo Tijhof2020-03-191-3/+3
| | | | | | | | Deprecated since MediaWiki 1.25. Bug: T247777 Bug: T228895 Change-Id: I638d9a219df7b5c661548354fd3d219ada340a86
* maintenance: Remove --mwdebug optionTimo Tijhof2020-03-111-7/+0
| | | | | | | | | | | | | | | | | | | | | | | | | I added this in fdb7d36903 when DevelopmentSettings.php was fairly basic and might have even been harmless to include in production (unverified at this point). The use case was easy injection by WMF CI and Travis CI, but we never ended up using that. Both for CI and for local development we have converged on the debuggable/non-magical way of injecting it, which is explicitly placing it in LocalSettings.php at the point where the developer is in control of it. It also means it consistently applies no matter which script you run, including on the web, which makes sense as the site settings shouldn't change unexpectedly. An alternative might be to make this configurable and only available in a special development mode, and not in prod. However that creates a bit of a paradox. If we require admins to place something in LocalSettings to make this available, might as well make that line of code be "require DevelopmentSettings.php", equally easy to copy/paste and comment out. Change-Id: Iffc58599581bf20b5880b7c57259e8b37ddf9dcb
* Revert "Split FakeMaintenance and LoggedUpdateMaintenance to their own files"Daimona Eaytoy2020-03-031-0/+66
| | | | | | | | | This reverts commit 2cdeb26d0c2bc6f3fb4d05d7b8b72c4a601b3da7. Reason for revert: broke roughly all scripts extending LoggedUpdateMaintenance. Bug: T246754 Change-Id: Icfe3da924c364b4b4f9286871aeb0aa9f1bbff1a
* Split FakeMaintenance and LoggedUpdateMaintenance to their own filesReedy2020-02-281-66/+0
| | | | Change-Id: I4c95f910993fffa060c2860847b8cfff1612ccf5
* Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNullJames D. Forrester2020-01-101-2/+2
| | | | Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
* Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUseJames D. Forrester2020-01-101-0/+2
| | | | Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
* Merge "Show the PHPUnit help in phpunit.php --help"jenkins-bot2019-12-021-3/+9
|\
| * Show the PHPUnit help in phpunit.php --helpTim Starling2019-11-251-3/+9
| | | | | | | | | | | | | | | | | | | | Split Maintenance::showHelp() from Maintenance::maybeHelp(), and override it in phpunit.php. Expose PHPUnit's protected method Command::showHelp() in our subclass and call it, so that running "phpunit.php --help" causes the MediaWiki options to be shown, followed by the PHPUnit options. Change-Id: I4687d484e322a465af0492789645819cd8a7b67c
* | Improve param docsUmherirrender2019-11-281-4/+4
|/ | | | Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
* Fix new phan errors, part 7Daimona Eaytoy2019-10-211-0/+1
| | | | | Bug: T231636 Change-Id: Ia5e0abee7163c5a1abd0bb53b89603cc2e7a9b5c
* Add type hint for $maintClassUmherirrender2019-10-041-0/+4
| | | | Change-Id: I0ba7fd7eb6145ab12625796c842bb2b664d362ab
* Maintenance.php: Fix mwdebug errorTheSandDoctor2019-09-231-1/+1
| | | | | | | | | | | Resolve error with showJobs.php --mwdebug option. Previously, it displayed an error if not followed by "=1". This was resolved by changing $this->addOption( 'mwdebug', 'Enable built-in MediaWiki development settings', false, true ); to $this->addOption( 'mwdebug', 'Enable built-in MediaWiki development settings', false, false ); Bug: T233257 Change-Id: I322fa539a302c2726fffd2420f7f56aec476b32b
* maintenance/Maintenance.php: Fix MW_ENTRY_POINT definition (followup I24099f4c)Brad Jorsch2019-09-091-1/+1
| | | | | | Quotes were omitted. This currently works in PHP, but raises a warning. Change-Id: I4c9ce4b5ea9fb9f30215f646cc8fa60db0ed7d1c
* Merge "Add MW_REST_API and MW_ENTRY_POINT"jenkins-bot2019-09-091-0/+2
|\
| * Add MW_REST_API and MW_ENTRY_POINTTim Starling2019-09-031-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Define the global constant MW_REST_API in rest.php, by analogy with MW_API. Also generalize this by adding MW_ENTRY_POINT, which contains the entry script name, "cli" or "unknown". This allows tests such as if ( MW_ENTRY_POINT !== 'index' ) which is probably what is really intended by defined('MW_API') in many cases. Change-Id: I24099f4cdd170de17afd6e1bbad67c9b204071fc
* | Upgrade phan config to 0.7.1Daimona Eaytoy2019-09-041-3/+15
| | | | | | | | | | | | | | | | This allows us to remove many suppressions for phan false positives. Bug: T231636 Depends-On: I82a279e1f7b0fdefd3bb712e46c7d0665429d065 Change-Id: I5c251e9584a1ae9fb1577afcafb5001e0dcd41c7
* | Unsuppress phan issues, part 8Daimona Eaytoy2019-09-041-0/+1
| | | | | | | | | | | | | | | | And also clean up the config. Bug: T231636 Depends-On: Ie6233561de78457cae5e4e44e220feec2d1272d8 Change-Id: I82a279e1f7b0fdefd3bb712e46c7d0665429d065
* | Unsuppress another phan issue (part 7)Daimona Eaytoy2019-09-031-0/+1
|/ | | | | | | Bug: T231636 Depends-On: I2cd24e73726394e3200a570c45d5e86b6849bfa9 Depends-On: I4fa3e6aad872434ca397325ed7a83f94973661d0 Change-Id: Ie6233561de78457cae5e4e44e220feec2d1272d8
* profiler: Centralise output responsibility from ProfilerOutputText to ProfilerTimo Tijhof2019-08-281-1/+1
| | | | | | | | | | | | | | | | | | | | Make it Profiler.php's responsibility to enforce this, based on the existing signal from ProfilerOutput::logsToOutput(). The ProfilerOutputText class should not have to double-check this a second time. Long-term, I'd like even this check in Profiler::logDataPageOutputOnly to be removed, because really the external caller of that should know whether it is safe to output stuff or not rather than stashing its own state inside Profiler::$allowOutput and then implicitly reading it back out again later on. But, that's for another time. Also: * Remove use of deprecated Profiler::setTemplated while at it. * Make 'visible' parameter explicit, as for other parameters. Change-Id: Iaa3fc4ea25a059b90235d769db60c04b8f152f05
* Merge "Convert maintenance scripts to ↵jenkins-bot2019-08-021-8/+14
|\ | | | | | | LoadBalancer::getMaintenanceConnectionRef()"
| * Convert maintenance scripts to LoadBalancer::getMaintenanceConnectionRef()Aaron Schulz2019-08-021-8/+14
| | | | | | | | Change-Id: I8944a052f51a1941ad3b76a40fc9c46d1363c426
* | Simplify SearchUpdate constructor and hard deprecate some param typesDavid Causse2019-08-011-1/+1
|/ | | | Change-Id: I5677041169402014f1afc1a9012460c760ca24b6
* Tell users how they can force a maintenance script to run again.daniel2019-07-051-1/+1
| | | | | | | | | Subclasses of LoggedUpdateMaintenance tell the user that "Update '{$key}' already logged as completed". This adds "Use --force to run it again." Bug: T200653 Change-Id: I8cf3c5383c0fecdc92b58048138332855b5602a6
* Merge "Fix documentation of Maintenance::updateSearchIndex"jenkins-bot2019-06-101-2/+3
|\
| * Fix documentation of Maintenance::updateSearchIndexUmherirrender2019-06-071-2/+3
| | | | | | | | | | | | | | | | Document callback as callable type and the results part as IResultWrapper to match the implementation, which is passing return of Database::query to this function Change-Id: I63ee8d4907590a21ef34d0b761b8fabfe0ff2569
* | Pass options as array to IDatabase::insertUmherirrender2019-06-071-1/+1
|/ | | | | | The documentation only allows arrays there Change-Id: I00c6e47a817a70bed9a443aebc675ef4c3d6b1e5
* Remove usage of deprecated SkinFactory::getDefaultInstance()Kunal Mehta2019-06-021-1/+1
| | | | Change-Id: I3bd50f8ca5baabd34dbc0e3bbc2f97e94650a17a
* Merge "Set MW_INSTALL_PATH in Maintenance.php"jenkins-bot2019-04-121-4/+8
|\
| * Set MW_INSTALL_PATH in Maintenance.phpAryeh Gregor2019-04-111-4/+8
| | | | | | | | | | | | | | | | Otherwise, if running update.php, there are require_once failures from extensions (at least Echo and Flow) if they aren't inside extensions/ -- e.g., if they're just symlinked from there. Change-Id: Iaf4231abae1621627f01171f955b5bb7a0fa77d8
* | Fix order of @var parameter in PHPFomafix2019-04-081-2/+2
|/ | | | | | | | | | | | Replace @var $foo type by @var type $foo Change-Id: Iec8b90ffea4028a1005daef422b7c4ec38c2715f
* Replace deprecated function wfEscapeShellArg with Shell::escape()Derick Alangi2019-04-071-3/+3
| | | | Change-Id: I4046d593d1450cfffc489ca2abadba1084a540e4
* Merge "maintenance: Deprecate Maintenance::hasArg/getArg with no param"jenkins-bot2019-03-311-0/+8
|\
| * maintenance: Deprecate Maintenance::hasArg/getArg with no paramThiemo Kreuz2019-03-291-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Benefit of keeping the parameter optional: - In maintenance scripts that really only have one parameter, it's a little more convenient to be able to ask for *the* parameter via an empty getArg(). Disadvantages: - It's unclear what getArg() means when there is no indication *which* argument the code asks for. This might as well return the last argument, or an array of all arguments. - In scripts with two or more arguments, it's confusing to see getArg( 1 ) next to an empty getArg(). - The methods are more complex and a bit more complicated to use with the extra feature of this parameter being optional. Users need to look up what the default is to be able to use it safely. Change-Id: I22a43bfdfc0f0c9ffdb468c13aba73b888d1f15e
* | Merge "Allow extensions to add params to the update.php maintenance script"jenkins-bot2019-03-291-9/+16
|\ \ | |/ |/|
| * Allow extensions to add params to the update.php maintenance scriptBill Pirkle2019-03-261-9/+16
| | | | | | | | | | | | | | | | | | | | | | | | T110209 caused maintenance scripts to fail on unknown parameters, which is normally desirable. However, some extensions (notably SemanticMediaWiki) need to support additional params and had no way to add them to the list of expected parameters. It will now be possible them to update.php via a new hook: MaintenanceUpdateAddParams. Bug: T213893 Change-Id: Ia40949ccb2f32090f21e0f3f7e5b9c4aef322330
* | maintenance: Use the ?? feature together with explode()Thiemo Kreuz2019-03-261-12/+2
|/ | | | | | | This gets rid of a few if(), count() and such that make the code appear quite complicated, even if it isn't. Change-Id: Iade6589eba2a9496b28042bfc777b92258b3332a
* Fix fatal due to lock name mismatch in Maintenance::unlockSearchindexAaron Schulz2019-03-191-2/+2
| | | | Change-Id: Id18c0c8eb20c215ba7421e087b721ac7dc57227a