Commit graph

61 commits

Author SHA1 Message Date
Umherirrender
94792e97be maintenance: Cleanup use of exit in Maintenance::execute implementation
Returning void from execute() is success.
Returning true is success, false is failure with exit(1)
Using fatalError also using exit(1)

Change-Id: I1d40430ad6226e4aab8f0810b03ee1213282d123
2021-08-30 19:48:27 +00:00
DannyS712
4f9970f30b Fix a bunch of random typos
* yeild -> yield
* paramter -> parameter
* seperator -> separator
* neccesary -> necessary
* inital -> initial
* intial -> initial
* repsonse -> response
* retreived -> retrieved

Bug: T201491
Change-Id: I461941b027590997448f3bdd8a137a48bb338beb
2021-06-29 11:32:04 +00:00
Timo Tijhof
0af11e2740 rebuildLocalisationCache: Add --skip-message-purge and accompanying script
== Adding --skip-message-purge

Follows-up d91c6627a9. Per CR and Phab comments, I don't think we
can (yet) promise a generic "--offline" mode. This seems too easy to
misuse. Both for users of the script, as well as for future development
to the script. It can fall out out of sync with requirements of the
overall system and leaves no natural place to discover what
responsibilities are being deferred and how the operator should fulfill
those duties.

We know LCStoreDB doesn't work offline, but there are likely other
aspects of this that don't yet work offline for some users. It would
require a much more rigorous refactor (and dropping signifant extension
hooks) to make this reliably offline. I'd welcome a standalone script
using only vendor libs, that does nothing other than scan directories
and build JSON/PHP/CDB files, but that's not what it is today.

What we can do is skip the one operation we know requires a live
DB connection, and (my main motivation for this commit) then document
that skipping it, require the user to perform the purge by other means
instead, since the purge itself is not actually optional.

Also, make this not a WMF-specific option in MW core, by committing
the accompanying script needed for this to work. This was previously
in the WikimediaMaintenance extension as "refreshMessageBlobs.php".

== Keeping --offline (as --no-database)

As far as I know, the purge is the only action we ran into that needed
a database connection, and important to note was that it's not optional.

I think for WMF we did not run into any other logic in our configuration
that uses a database, so --skip-message-purge should suffice. However,
I've kept the option for two reasons:

1. To recognise in some way the business need for WMF to use this
   script in an offline manner, and thus document that the script
   should at least have a way to work offline, even if there may be
   site configurations and extensions that make this impossible, from
   a core perspective we want to (experimentally) try to support this.

2. There is unimportant setup logic that happens in doMaintenance.php
   where the service wiring for LBFactory is activated by default.
   This seems avoidable and technical debt, but at least for now
   we do need a way to skip that, so this option will continue to
   have that effect.

However, I've renamed the option and inverted its promise. This is not
a promise from core *to* the user to offer an offline mode. Rather,
it is a promise *from* the user that they think nothing DB-needy is in
use.

Bug: T268698
Bug: T263872
Change-Id: I7878fdf4a901fb5e75da540293bb9df9fb508c20
2021-04-07 00:36:59 +01:00
Dan Duvall
d91c6627a9 maintenance: rebuildLocalisationCache should be DB_NONE if possible
This change should allow `rebuildLocalisationCache` to be run in a truly
offline environment as long as `LCStoreDB` is not being used.

Renames the `--no-clear-message-blob-store` option to `--offline` to
signal that no database dependent action will be performed.

Implements `getDbType()` which returns `DB_NONE` when `--offline` is
passed. This will avoid maintenance setup that tries to initialize a DB
load balancer.

Passing `--offline` when the store class is configured as `LCStoreDB`
will result in a fatal error.

Bug: T260827
Bug: T237148
Change-Id: I3e69b1ffad81a8c48f11a94973e7697461bb08ff
2021-03-02 11:13:43 -08:00
Ahmon Dancy
aa35f40476 rebuildLocalisationCache.php: Fix typo
staus => status

Change-Id: Id371f18861674331c75132305eeda190bb9b604f
2021-02-15 09:46:49 -08:00
jenkins-bot
5ea464b234 Merge "Use static closures where safe to use" 2021-02-14 23:05:48 +00:00
Ahmon Dancy
31e0a6c951 rebuildLocalisationCache.php: handle killed children
Before:

If a child terminated due to a signal (for example, being killed by
the kernel OOM killer), that would go unnoticed in the parent process
and the parent would ultimately exit with a status of 0.

After:

pcntl_wifexited() and pcntl_wifsignaled() are now used to determine if
a child process terminated normally or via signal.  In the case of
normal termination with a non-zero exit status or termination by
signal, a message is printed.  In either case the parent will exit
non-zero.

Change-Id: I646ac6cbd8cd653553718d55055cad7cbd4b6bc1
2021-02-13 08:15:05 -08:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Ahmon Dancy
815def7ae2 Add flag to rebuildLocalisationCache.php to skip MessageBlobStore clear
maintenance/rebuildLocalisationCache now accepts a
--no-clear-message-blob-store option to skip the call to
MessageBlobStore::clearGlobalCacheEntry() when a language file has
been rebuilt.

Bug: T268698
Change-Id: I0907b51149402ad60e924d17e6ef9d0084e8c2cc
2020-11-24 15:42:38 -08:00
Tim Starling
c7dc05550a Fix failure of rebuildLocalisationCache.php due to RL hook
rebuildLocalisationCache.php can fail when clearing the MessageBlobStore
due to a hook while constructing a ResourceLoader. This problem was also
encountered in T231866, but the fix was only applied to
ServiceWiring.php and not this duplicated code in
rebuildLocalisationCache.php.

So, fix rebuildLocalisationCache.php to similarly not construct a
ResourceLoader object.

Bug: T262900
Change-Id: I4e28c0f4e06efd219226154ab955395e00be504f
2020-09-16 05:05:18 +00:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
Reedy
c7eb28aac9 Fix various MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment
Change-Id: I50c7c93f1534e966224f98a835ca01f93eb9416d
2020-05-21 01:06:05 +00:00
Thiemo Kreuz
510cd47e4a Update misleading PHPDocs in rebuildLocalisationCache
This method does not need to know what subclass the parameter is. All
details it needs to know exist in the base class.

Change-Id: I994fbd9b236c5369d8d8221b8f4ba4e7db0ee8bc
2020-03-19 17:16:28 +00:00
Petr Pchelko
204fa7e509 Remove usages of deprecated Language methods
Change-Id: Iad3375b141b1d87c890baec6ecd16ed92f93e699
2020-02-16 00:45:48 +00:00
Amir Sarabadani
1bea7c5c44 Add option to override storeClass in rebuildLocalisationCache
This is useful when migrating between several LC stores and you need
to rebuild them in several stores.

Bug: T105683
Bug: T99740
Change-Id: I64ef1812ea0605f9b3ed037459c6510a5ebe3dec
2019-12-23 19:56:18 +01:00
jenkins-bot
52b44696ba Merge "Split some Language methods to LanguageNameUtils" 2019-10-08 21:10:07 +00:00
James D. Forrester
ebac0247cf Services: Convert LocalisationCache's static to a const now HHVM is gone
Change-Id: If5c015debed7efc034613b976bc5292ac30036d7
2019-10-08 11:25:30 -07:00
Aryeh Gregor
6d80b6c082 Split some Language methods to LanguageNameUtils
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.

In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).

There is 100% test coverage for the code in the new class.

This was previously committed as 2e52f48c2e and reverted because it
depended on e4468a1d6b, which had to be reverted for performance
issues. There should be no changes other than rebasing.

Bug: T201405
Change-Id: Ifa346c8a92bf1eb57dc5e79458b32b7b26f1ee8a
2019-10-07 15:20:52 -07:00
Aryeh Gregor
043d88f680 Make LocalisationCache a service
This removes Language::$dataCache without deprecation, because 1) I
don't know of a way to properly simulate it in the new paradigm, and 2)
I found no direct access to the member outside of the Language and
LanguageTest classes.

An earlier version of this patch (e4468a1d6b) had to be reverted
because of a massive slowdown on test runs. Based on some local testing,
this should fix the problem. Running all tests in languages is slowed
down by only around 20% instead of a factor of five, and memory usage is
actually reduced greatly (~350 MB -> ~200 MB). The slowdown is still not
great, but I assume it's par for the course for converting things to
services and is acceptable. If not, I can try to optimize further.

Bug: T231220
Bug: T231198
Bug: T231200
Bug: T201405
Change-Id: Ieadbd820379a006d8ad2d2e4a1e96241e172ec5a
2019-10-07 13:18:47 -07:00
Amir Sarabadani
308e6427ae Revert "Make LocalisationCache a service"
This reverts commits:
 - 76a940350d
 - b78b8804d0
 - 2e52f48c2e
 - e4468a1d6b

Bug: T231200
Bug: T231198
Change-Id: I1a7e46a979ae5c9c8130dd3927f6663a216ba753
2019-08-26 18:28:26 +02:00
Aryeh Gregor
76a940350d Pass correct store to rebuildLocalisationCache.php
e4468a1d6b completely broke rebuildLocalisationCache.php by
unconditionally passing in LCStoreDB( [] ) instead of constructing the
correct object.

Bug: T231183
Change-Id: I0d52662e8745cf0e10091169b3b08eff48ef2b8f
2019-08-26 12:56:52 +03:00
Aryeh Gregor
2e52f48c2e Split some Language methods to LanguageNameUtils
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.

In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).

There is 100% test coverage for the code in the new class.

Change-Id: I245ae94bfc1f62b6af75ea57525139adf2539fe6
2019-08-23 12:52:35 +03:00
Aryeh Gregor
e4468a1d6b Make LocalisationCache a service
This removes Language::$dataCache without deprecation, because 1) I
don't know of a way to properly simulate it in the new paradigm, and 2)
I found no direct access to the member outside of the Language and
LanguageTest classes.

Change-Id: Iaa86c48e7434f081a53f5bae8723c37c5a34f503
2019-08-22 14:25:18 +03: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
Fomafix
202f695f67 Update weblinks in comments from HTTP to HTTPS
Use HTTPS instead of HTTP where the HTTP link is a redirect to the HTTPS link.

Also update some defect links.

Change-Id: Ic3a5eac910d098ed5c2a21e9f47c9b6ee06b2643
2016-11-07 15:24:46 +01:00
Bryan Davis
ee8b8f1d37 Fix RebuildLocalisationCache bug from MediaWikiServices
Revert changes to rebuildLocalisationCache.php introduced in Ie98bf5a.
The forked children do not need separate service connections and the
reset process fails due to MW_SERVICE_BOOTSTRAP_COMPLETE being defined.

Bug: T132370
Change-Id: I0d7ddcd66e7c6945fabd91fea29a48805bf14793
2016-04-11 19:16:31 +00:00
daniel
8e7a0a0912 Allow reset of global services.
This change provides a mechanism to reset global service instances
in an orderly manner. There are three use cases for this:

* the installation process
* forking processes
* integration tests (which must of the existing phpunit tests are)

Depends-On: I5d638ad415fc3840186a0beaa09ac02ea688539b
Change-Id: Ie98bf5af59208f186dba59a9e971c72ea0b63e69
2016-04-11 16:22:40 +02:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Max Semenik
59db24e90b Use addDescription() instead of accessing mDescription directly
Change-Id: I0e2aa83024b8abf5298cfea4b21bf45722ad3103
2016-01-30 01:28:32 -08:00
Ori Livneh
ef2822f76f rebuildLocalisationCache: don't limit memory usage
The 1000 MB limit seems to have crept in without good reason, and crashing when
crossing an arbitrary threshold like that isn't very useful. LCStoreStaticArray
ends up using more than the default limit allows.

Change-Id: I1d9ab743720f5a1fbe320180c1dcdb4ad03c5aa1
2015-07-13 02:26:34 -07:00
Tim Starling
1e5efc85f3 Fix exit code from rebuildLocalisationCache.php
When --threads was used, the exit code was unconditionally 0, even if a
child thread threw an exception, because the exit code was "abused" for
the count of rebuilt languages. So, don't do that. We don't really need
a count of rebuilt languages that badly, just pass through the exit
status of the child.

Bug: T92900
Change-Id: I77922e686fe7da4fc25bb7f579ed70e1b107eaca
2015-03-18 15:03:28 +00:00
Siebrand Mazeland
606c680b21 Update formatting in maintenance/ (4/4)
Change-Id: I6b58d014a4bfd6600e4e6f80188fdcfce18482ca
2014-04-23 20:09:26 +02:00
umherirrender
e78776373e Fixed some @params documentation (maintenance)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: I727deec35a712de0f0c676cc87dfa661f1ee965b
2014-04-17 22:48:32 +02:00
Siebrand Mazeland
04021a8e81 Remove underscore from class LocalisationCache_BulkLoad
Part of program to remove underscores from class names. Checked core and
600+ extensions for occurrences. All uses are in core, and are updated in
this change.

Change-Id: Ib157c3cf209677718ff184552cf872b1d3f4e969
2013-11-17 22:00:34 +01:00
Reedy
297129a4fc Return values from finalSetup() aren't evaluated
Not that parent::finalSetup() returns anything anyway...

Change-Id: I21cb5e13cc83297f24a30ef37859430b0fefb695
2013-08-15 22:53:40 +00: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
umherirrender
c6894adefc Fixed spacing
Added spaces around some parenthesis

Change-Id: If1e50e2a7b0046e91c0bbce8bf6641d8b2446a1d
2013-05-09 19:48:10 +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
Antoine Musso
a677d0fae0 rebuildLocalisationCache: Implement --lang option
It would rebuild all language caches by default.
We were lacking an option to rebuild only one language, for example when
it get corrupted or the cache file for a language got removed.

The new --lang accepts a list of comma separated langs to rebuild the
cache for.  Example usage:

 php rebuildLocalisationCache.php --lang en,fr,de

Nonexistent languages are simply ignored. The script dies if it ends up
with no languages to rebuild.

Change-Id: I4c5e69abb76ffd8b88b595e3687edab3bb267ccc
2013-05-01 12:33:12 +02:00
Brad Jorsch
05edbe67d2 Allow non-English wikis to rebuild l10n cache
If a wiki is configured to use the l10n cache and $wgLanguageCode is set
to anything other that 'en', all maintenance scripts will fail until the
l10n cache is build for the first time. This includes
maintenance/rebuildLocalisationCache.php, the maintenance script that
builds the l10n cache.

To break this dependency, have maintenance/rebuildLocalisationCache.php
force $wgLanguageCode = 'en'.

Change-Id: Ia93998b0f85fd122dd7b01eeeef698f595360945
2013-01-10 15:54:15 -05: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
6015071beb Improve documentation of maintenance scripts.
Change-Id: I21b4fb873e88026108754eb7206e62c82648df0e
2012-08-09 19:28:14 +02:00
Reedy
d07bdcf0b3 Make rebuildLocalisationCache.php also obey --memory-limit if set.
Same as https://gerrit.wikimedia.org/r/17473 for runJobs.php

Change-Id: I352df6c2f46606fe575ef5f52a39175b4aad9f75
2012-08-02 23:35:20 +01:00
Robin Pepermans
9184dc83d6 Update core usage of getLanguageName[s]. 2012-03-08 20:56:26 +00:00
Tim Starling
a8ab6c0df7 This script uses about 550MB of RAM on 1.19wmf1. Increase memory limit appropriately. 2012-02-22 06:14:57 +00:00
Tim Starling
691e79c405 Output directory option, to allow messages to be put directly into /h/w/c 2012-02-22 02:09:05 +00:00
Sam Reed
f3f180850a Fixing up undefined types in maintenance documentation 2012-02-09 21:08:06 +00:00
Sam Reed
39ece40f46 Followup r101449, just changing forceRecache isn't actually enough
Add a method to set force to true on the options array to RebuildLocalisationCache
2011-11-01 07:34:56 +00:00
Chad Horohoe
26505b170a Fix concern raised by Brion in r74108 (but has really existed since the maintenance rewrite). Right now, including a maintenance script causes it to execute. This is bad when you want to reuse the particular class but not have it start executing all by itself.
Until now, we relied on setting MW_NO_SETUP which was a) hacky, b) irreversable, and c) likely to be forgotten if you didn't use one of the wrappers like runChild().

Instead, move the freaky magic to doMaintenance and have *it* check if it's in a specific call stack that indicates this is being run from the file scope and should be executed. Rename DO_MAINTENANCE to RUN_MAINTENANCE_IF_MAIN so it's nice and clear what magic happens behind the require_once().
2011-01-13 22:58:55 +00:00