Commit graph

76 commits

Author SHA1 Message Date
Umherirrender
5b3d3ef802 collation: Create CollationFactory service
Use ObjectFactory specs for collation classes
Avoid the language construction in the factory class,
make it a detail of the implementation of each class

Follow-Up of Ifc96f851e6091ce834dbaf0e91695c648a42169c

Bug: T286079
Change-Id: Ib581f64aec8619986fb8dd49ceee0524d59a1b84
2021-09-04 02:46:06 +02:00
Umherirrender
b4bd3d4ee8 Remove dead variables and functions and unneeded parenthesis
Found by sonarqube

Change-Id: I3464d25e94d98aaca55d9209d5175542b335f994
2021-08-13 21:41:59 +02:00
Ammarpad
48a9e85b01 Prevent passing empty array to max()
This raises ValueError in PHP8 and warning in earlier versions.

Change-Id: I0c0c6065e4c5440ab7f089d364437e2adc056f63
2021-07-26 05:24:40 +00:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Reedy
f648dd236e Fix PSR12.Properties.ConstantVisibility.NotFound in maintenance/
Change-Id: Ib0f081f7b278fdd3f4083fc5020bcac97f6015b4
2020-05-09 23:54:58 +00:00
Reedy
8ba1c75559 Replace wfWaitForSlaves() with LBFactory::waitForReplication()
Change-Id: I337147d61e2ec686a8672d0340dff4b6783f78cd
2020-05-02 02:00:01 +00:00
Ostrzyciel
6f8bd64c6a updateCollation.php: fix PHP error
Currently the updateCollation maintenance script throws an error
when ran, as it calls MediaWikiServices before it's initialized.
See the phab task for more details.

Bug: T246127
Change-Id: Ib9d6b485b55760897ff5152b5d6f22b0d6a36daa
2020-02-25 18:13:09 +01:00
Umherirrender
b4fe9c4bcc Set method visibility on maintenance scripts
Change-Id: I44c82fbe65e1d002803ce065df6563f06dd39cd4
2019-11-16 22:54:17 +00:00
Umherirrender
8f666cabcd Use Maintenance::getConfig in some maintenance scripts
This avoid global state

Change-Id: Id67d07597159a0bd2721a381775230c3cd1d5509
2019-09-01 20:55:08 +02:00
Daimona Eaytoy
e2e543f7c2 Unsuppress more phan issues (part 5)
Bug: T231636
Depends-On: I6e5fba7bd273219b1206559420b5bdb78734aa84
Change-Id: I50377746f01749b058c39fd8229f9d566224cc43
2019-09-01 09:48:31 +00:00
Aryeh Gregor
76661cf129 NamespaceInfo service to replace MWNamespace
MWNamespace::clearCaches() has been removed entirely, along with the
$rebuild parameter to MWNamespace::getCanonicalNamespaces(). The rest of
MWNamespace is deprecated.

Diff best viewed with -C1 so git notices that NamespaceInfo is a copy of
MWNamespace.

Depends-On: Icb7a4a2a5d19fb1f2453b4b57a5271196b0e316d
Depends-On: Ib3c914fc99394e4876ac9fe27317a1eafa2ff69e
Change-Id: I1a03d4e146f5414ae73c7d1a5807c873323e8abc
2019-04-10 02:07:36 +00:00
Thiemo Kreuz
b7cd670cb7 maintenance: Remove unused code from several maintenance scripts
The most notable removal is done in the orphans script. This code was
really never used. Brion introduced it in 2005, already disabled.

I have all the respect for what Brion did. I just think it does not make
much sense to keep code around for so long if it does not work anyway,
and must be rewritten from scratch anyway now that we have multi-content
revisions and such.

Change-Id: I4e8050929f90e44a6e6051bf938993a8b0cdf649
2019-03-03 16:57:19 +00:00
Fomafix
512aa4e551 Use PHP 7 '??' operator instead of if-then-else
Change-Id: Ia86f8433f30a166d38ee63d0d1745b26740767b9
2018-10-27 23:46:13 +02:00
Kevin Israel
a50f61009d MWNamespace: Add getCategoryLinkType() method
This method returns the value used as cl_type for category links that
are "from" pages within the namespace, and is added to avoid duplication
of code across a few classes.

Change-Id: I4e55932a5a27858cfedb12009b455fcd02f9b5df
2018-06-29 15:37:11 +00:00
Umherirrender
bf5a104146 Remove wfWaitForSlaves when using Maintenance::commitTransaction
Maintenance::commitTransaction is calling waitForReplication already.
No need to wait a second time, hopefully the lags are 0 already.

Change-Id: Id457ed2cdd6bfd9663665ba0cd5c4e3dd640b738
2018-02-26 21:05:33 +01:00
Bartosz Dziewoński
75747c0fcc updateCollation.php: Improve --dry-run mode
Now prints the number of rows that would be modified after each batch.
This is meant to be useful for sysadmins who are upgrading the ICU
library on their servers and wondering whether they need to run
`updateCollation.php --force` to avoid ordering problems.

Change-Id: Ie0c37d279d4e5bc1c69408d714246625c81c70fa
2018-02-15 19:39:48 +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
Aaron Schulz
21e71e0235 Use IDatabase type hints in /maintenance
Relatedly, move lockTables()/unlockTables() to IMaintainableDatabase

Change-Id: Ib53e9fa948deb2f9a70f0ce16c002613d0060bf9
2017-04-07 23:37:41 +00:00
Aaron Schulz
30f4b3c103 Replace DatabaseBase => Database in more places
Change-Id: If37a7909056bf2c31a8228cbc84f0fbbf5f1c517
2016-09-28 15:53:02 -07:00
Aaron Schulz
950cf6016c Rename DB_SLAVE constant to DB_REPLICA
This is more consistent with LoadBalancer, modern, and inclusive
of master/master mysql, NDB cluster, and MariaDB galera cluster.

The old constant is an alias now.

Change-Id: I0b37299ecb439cc446ffbe8c341365d1eef45849
2016-09-05 22:55:53 -07:00
jenkins-bot
a206443c0e Merge "Change "slave" => "replica DB" in /maintenance" 2016-09-06 01:05:50 +00:00
Aaron Schulz
c0a9ab0f6d Change "slave" => "replica DB" in /maintenance
Change-Id: Ibd3d617901130378a935402326cd4eefbb382c9e
2016-09-06 00:13:08 +00:00
Kaldari
c1bf1f369e Fixing dry-run logic in updateCollation.php
Currently if you run updateCollation.php in dry-run mode, it ignores
the other parameters and doesn't give you a row estimate. Now it
will behave the same as an actual run (just without making any
changes to the database).

Change-Id: I25a9751d8ab7554e7975e5f08122dd1ddaaf40a7
2016-08-29 16:29:24 -07:00
jenkins-bot
e2eefa3a97 Merge "Make updateCollation wait for slaves every 500 (instead of 2000)" 2016-05-12 11:47:08 +00:00
Brian Wolff
d9a965c69d Make updateCollation wait for slaves every 500 (instead of 2000)
2000 writes per wfWaitForSlaves() seems a bit high. There was a
report of this script causing some slave lag when being run.
Note that, the amount of time between wfWaitForSlaves() was
previously increased in r97146.

Bug: T58041
Change-Id: I07a29499775a17255865f25e6b9f1058f898193b
2016-05-12 06:32:47 -04:00
jenkins-bot
1b526b27d3 Merge "use slave for row estimate in updateCollation.php" 2016-05-11 17:06:05 +00:00
Brian Wolff
09205b2954 use slave for row estimate in updateCollation.php
jcrespo reported a lag spike at the very beginning of running this
script. I'm guessing that's due to counting how many rows in
categorylinks to give the progress bar. Since we only need a
rough estimate for the progress meter, make that query run on
a slave. Also add a wfWaitForSlaves() immediately after it for
good measure.

Bug: T58041
Change-Id: I3cba392f0013fcb2ef86803632e2d9b1b88b3b29
2016-05-10 15:38:27 -04:00
Brian Wolff
01bcb5a9e6 Use STRAIGHT_JOIN on updateCollation.php per jcrespo
Was not using the right index on ruwiktionary

Bug: T58041
Change-Id: Ib55a2cdd7807a96df7076a1b54457dd4f74912ce
2016-05-10 15:30:03 -04:00
Brian Wolff
0d4e0ca543 Add -f as an alias of --force to cli args of updateCollation.php
Because I kept accidentally using -f without realizing it didn't
work.

Change-Id: I71da15c81ca12c630304f594d144c4c7289ec28c
2016-04-26 17:07:30 +00:00
Brian Wolff
eec016ece6 Add new index to make updateCollation.php painless
We want to update categories in order, to minimize disruption
to users. Previous indexes required a filesort to do this, which
exploded things on large wikis. See bug for details

Bug: T58041
Change-Id: Iee6cd997ff87a313a46fda19d8ab063d0fed8ce8
2016-03-22 16:32:52 -06: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
Kevin Israel
1dd4c867e5 updateCollation.php: Switch back to using cl_from index for now
Using the cl_sortkey index instead (to reduce disruption to a live
site), as currently implemented, seems to have two serious problems:

* MySQL / MariaDB filesorts all rows that "sort above the given row
  [the last row of the previous batch]", not just a single category
  at a time until the row limit is reached.
* The current approach to pagination is broken in that it does not
  work with ENUM columns such as cl_type, causing 'file' rows to be
  skipped, or rows of any type to be repeated. See T119173.

This reverts part of commit a43f751cf6.

Bug: T58041
Change-Id: I619564e85b2122f249bdacc45d547b9ce1b3beb5
2016-01-21 05:57:48 +00:00
Aaron Schulz
fa8e1a9b00 Clean up transactions in maintenance scripts
Add transaction methods to complement getDB().
This makes it easy to grep for direct begin()/commit()
calls to IDatabase by having script use their own
wrapper. Maintenance scripts are one of the few places
that can (and need to) use begin/commit instead of the
start/end atomic methods.

Eventually, there should be almost no direct callers
and those methods can be made stricter about throwing
errors on nested calls.

Change-Id: Ibbfc7a77c0d2a55f7fc2261087f6c3a19061e0aa
2015-12-30 23:40:35 +00:00
Kevin Israel
924a34c298 Remove --max-slave-lag options and remnants from maintenance scripts
Change-Id: Id01fb9a82bcfe1af8cbce23a9aec7eccaa0f6b21
2015-03-26 19:33:35 -04:00
umherirrender
b0cfcd0fcb Add missing @return and @param to doc blocks
Change-Id: I9d99ba1968ed8f97624d957754c8847dfe1b41da
2014-08-27 21:57:45 +02:00
umherirrender
6b4c44c2db Add missing @param to function docs
Change-Id: Ib26407bc55dff7969d8a3b1e2ae51751b202d8fb
2014-08-18 16:24:59 +00:00
Siebrand Mazeland
606c680b21 Update formatting in maintenance/ (4/4)
Change-Id: I6b58d014a4bfd6600e4e6f80188fdcfce18482ca
2014-04-23 20:09:26 +02:00
Mark A. Hershberger
0b5acd0623 Move reference to $row where it is in-scope and doesn't produce
E_STRICT notices.

Bug: 57575
Change-Id: Ic508ebbb0816acd32be355b5f19b46637d58c36a
2013-11-25 22:18:55 -05:00
MatmaRex
c9e8cffc81 updateCollation.php: sanity check the collation before proceeding
In some cases the constructor will work, but trying to access first
letter data will raise an exception, breaking all category pages.

Bug: 46615
Change-Id: I77de040f97080653fe0d1734d38490eaa2d322db
2013-07-04 05:21:04 +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
Brian Wolff
af6d3572fa Revert "(bug 46615) updateCollation.php: sanity check the collation before proceeding"
Sorry, forgot that method was not in the base class, and I had only tested with uca based collations. This breaks on uppercase type collations.

This reverts commit 6eb84144df

Change-Id: Ib7b9597ff842a76185ba5c153922834ffb741237
2013-05-15 22:40:29 +00: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
MatmaRex
6eb84144df (bug 46615) updateCollation.php: sanity check the collation before proceeding
Change-Id: I5be1b1ec1823fdb7438c3f501fb6194142c1e9dc
2013-03-27 21:16:57 +01:00
Platonides
c3f1a3c9ea a43f751 removed the usage of $wgMiserMode
Change-Id: I5528dba582d218721324431015bd930b9b6ab57e
2013-03-18 04:21:55 +00:00
Tim Starling
1db83c1b76 Restore SET cl_timestamp=cl_timestamp
Apparently cl_timestamp=cl_timestamp is a workaround for obscure
behaviour of the timestamp type in MySQL

Change-Id: I803f20bcf4e28e8e2833a07bcf00e7edc00ad84b
2013-03-13 10:18:12 +11:00
Tim Starling
a43f751cf6 Reduce disruption during updateCollation.php
Have updateCollation.php order by cl_to, so that each category is
updated all at once. This minimises the time during which a category
will appear to be incorrectly sorted, while the maintenance script is in
progress.

Mark the cl_collation index as needing deletion, it was always pretty
pointless. You can't do much better than a full table scan when you're
changing the collation value on a wiki.

Increase the batch size since the lack of a cl_to,cl_from index means
that it will have to filesort each category. A larger batch size means
less sorts. As noted by Liangent on bug 45970, you can't order by
cl_sortkey since that will change during execution.

Also fix an inappropriate use of $wgMiserMode and remove a no-op from
the SET clause of the UPDATE.

Very lightly tested.

Change-Id: I19bc8d6701f5f78040aa9c521427ac98ef488d89
2013-03-12 23:08:29 +00:00
Marius Hoch
652c4be7c2 Clean up: Declare variables with public instead of var
Variables in classes should be declared using public $foo
instead of var $foo for various reasons. As we require PHP 5.3
we don't have to take care about that PHP4 left over, but can
get rid of it in favour of the more clear and better readable
public.
See also: http://php.net/manual/en/language.oop5.visibility.php
(Divided into several commits to keep reviewable)

Change-Id: Ic723d0347ab2e3c78bc0097345c68bbee3dc035a
2012-09-14 21:00:00 +02:00
Alexandre Emsenhuber
2a7478b4fb Improve documentation of maintenance scripts.
Change-Id: Id7a04ff816dc47a8cc81a4da5ab0dff26b688bd5
2012-09-03 20:10:09 +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