Commit graph

76 commits

Author SHA1 Message Date
James D. Forrester
eeaec4ce6b ExternalStoreDB: Rename getMaster to getPrimary
Bug: T282894
Change-Id: I6d6361a0b84f7130a27df6a6c75a983c73e5dd95
2021-09-03 13:44:04 -07:00
James D. Forrester
109cf7b25c IDatabase: Rename masterPosWait to primaryPosWait
Hard-deprecating immediately as no known users in git outside of mainteance scripts.

Bug: T282894
Change-Id: I072f3d93a9598df719f76f635bfd477737097ad9
2021-09-02 11:59:06 -07:00
Umherirrender
244ea7c0b5 Simplify else-branches after continue/break
When the if branch continues the loop,
than the next branch does not need to be an else branch

Change-Id: Ia158709b7fd2ea811f1049cf8f53ed12c89719e3
2021-08-17 22:51:43 +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
James D. Forrester
1d71fd91d6 ILoadBalancer and IDatabase: Rename getMasterPos to getPrimaryPos
Bug: T282894
Change-Id: I30a600335af735a13a6ad2d3df56a5f17e05bfab
2021-08-02 18:14:41 +00:00
James D. Forrester
d11c59538a Rename DB primary position interfaces to DBPrimaryPos and MySQLPrimaryPos
And replace all uses.

Bug: T282894
Change-Id: I5222a8568255ac9fa5e2350e2264b8d2ee5eb968
2021-08-02 17:59:39 +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
Umherirrender
e9e784a09e build: Enable phan-taint-check-plugin and suppress issues
Taint check checks for possible security issues by tracking html
escaping and more by using phan.
This slows done the phan-job a bit and requires more ram

Keep the DoubleEscaped issues out to make reviewer easier

Adds suppression for false positives
Adds taint-annotation to help taint-check
Removes suppression for code phan now understand better by the tracking
of keys in taint-check
Fix some small issues by adding int cast or htmlspecialchars calls

Bug: T216348
Bug: T268920
Change-Id: I849ac4f120fd15b483e8939d4db45c98dc351259
2020-12-30 19:02:22 +01:00
Umherirrender
11b71b2a98 Suppress taint-check issues in maintenance scripts/cli context
all places detected as SecurityCheck-XSS by
mediawiki/phan-taint-check-plugin 3.1.0

Bug: T216348
Change-Id: Ib4c8295ad95c2c605fd2f0791e73322f747a00af
2020-12-07 17:20:07 +00:00
James D. Forrester
7282ea26a4 maintenance: Move commandLine from .inc to .php
… and fix the name to match the class.

Bug: T184782
Change-Id: Id3d0d0a6b3f2da6316d18eb57804c5a2b697108b
2020-09-28 15:03:05 +00:00
Umherirrender
5a318bd5bf Pass function name to database functions (maintenance scripts)
Useful for logging

Change-Id: I79fe037abcd74f56c935abc118d706bef0198124
2020-06-07 17:24:10 +00:00
Tim Starling
47a1619027 Remove terminating line breaks from debug messages
A terminating line break has not been required in wfDebug() since 2014,
however no migration was done. Some of these line breaks found their way
into LoggerInterface::debug() calls, where they mess up the formatting
of the debug log.

So, remove terminating line breaks from wfDebug() and
LoggerInterface::debug() calls.

Also:
* Fix the stripping of leading line breaks from the log header emitted
  by Setup.php. This feature, accidentally broken in 2014, allows
  requests to be distinguished in the log file.
* Avoid using the global variable $self.
* Move the logging of the client IP back to Setup.php. It was moved to
  WebRequest in the hopes that it would not always be needed, however
  $wgRequest->getIP() is now called unconditionally a few lines up in
  Setup.php. This means that it is put in its proper place after the
  "start request" message.
* Wrap the log header code in a closure so that variables like $name do
  not leak into global scope.
* In Linker.php, remove a few instances of an unnecessary second
  parameter to wfDebug().

Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
2020-06-03 12:01:16 +10:00
Timo Tijhof
95ec909e52 WikiMap: Add WikiMap::getCurrentWikiId() to make common use case easier
Change-Id: Ie225ebfc37c824e3167742137bbbc9f64aca5f5e
2020-03-03 16:04:21 +00:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Daimona Eaytoy
598c4d7fcb build: Upgrade phan to 0.9.0
Scalar casts are still allowed (for now), because there's a huge amount
of false positives. Ditto for invalid array offsets.

Thoughts about the rest: luckily, many false positives with array offsets
have gone. Moreover, since *Internal issues are suppressed in the base
config, we can remove inline suppressions.

Unfortunately, there are a couple of new issues about array additions
with only false positives, because apparently they don't take
branches into account.

Change-Id: I5a3913c6e762f77bfdae55051a395fae95d1f841
2019-12-07 20:16:19 +00:00
Umherirrender
b4fe9c4bcc Set method visibility on maintenance scripts
Change-Id: I44c82fbe65e1d002803ce065df6563f06dd39cd4
2019-11-16 22:54:17 +00: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
jenkins-bot
72e141a5e3 Merge "Remove Revision::getRevisionText and gated pre-MCR schema access" 2019-09-27 18:38:09 +00:00
Petr Pchelko
854b044ab7 Remove Revision::getRevisionText and gated pre-MCR schema access
- fixT22757.php appears to have been written for T22757 which has been
resolved, I assume it can be removed.

- compressOld.php - rev_text_id access is gated on MCRSchemaMigrationStage
READ_OLD. IT's safe to use the old_text and old_flags directly as we
select for them. Also the query ensures external blobs are not selected,
so we can use decompressData instead of Revision::getRevisionText.
Tested locally.

- recompressTracked.php uses a temporary table for tracking the blobs.
Table is populated by trackBlobs which explicitly queries for old_id,
so using it directly in recompressTracked is ok.
Tested locally.

- checkStorage.php the affected code attempts to fix broken revisions
from a dump, however, it looks like it doesn't work - the code expects
revision IDs as input, however it receives an array of text table old_id
values. Untested.

Bug: T198343
Change-Id: I753019565c15d270c831c995c07c7f1aad887cb6
2019-09-27 09:40:02 -07:00
Tim Starling
45db9a49cc In recompressTracked.php, fix the names of things related to child processes
The forbidden word was used in two senses, confusing the search and
replace done in 3d5016569d.

Change-Id: I220a58fd536c828ab5e03a779e45f222d0298f9a
2019-09-27 10:58:21 +10:00
Daimona Eaytoy
5d40cff293 maintenance: Explicitly declare all used properties
All uses were checked with codesearch, and the visibility was chosen as
strict as possible.

Change-Id: I56666299cc04ccc418e05949422876583982eb3c
2019-09-09 09:47:41 +00:00
Umherirrender
697900e477 recompressTracked.php: Fix typehint of RecompressTracked::dispatch()
Follows-up 4a55e578ff. This must be the same type as
RecompressTracked::dispatchToReplica().

Caught by PhanTypeMismatchArgument, to be enabled in I34d65fe3ff1916f.

Change-Id: Ifff0d92752e6664d7745efeb4840c8b5ddb974a4
2019-09-08 04:06:27 +00:00
Daimona Eaytoy
e70b5b3309 Unsuppress other phan issues (part 4)
Bug: T231636
Depends-On: I58e67c2b38389df874438deada4239510d21654f
Change-Id: I6e5fba7bd273219b1206559420b5bdb78734aa84
2019-08-31 17:13:39 +00:00
Aaron Schulz
4a55e578ff Convert maintenance scripts to LoadBalancer::getMaintenanceConnectionRef()
Change-Id: I8944a052f51a1941ad3b76a40fc9c46d1363c426
2019-08-02 22:29:43 +00:00
jenkins-bot
9d37c792b2 Merge "Replace wfWiki() usage with WikiMap in some additional places" 2019-07-23 15:02:47 +00:00
Aaron Schulz
7710afe569 Migrate various callers away from wfWikiId() to WikiMap
Change-Id: Idc2980c05873c428fb5ffa6ab89f723d33217a8e
2019-07-12 01:02:00 +00:00
Aaron Schulz
12531d2ae6 Replace wfWiki() usage with WikiMap in some additional places
Change-Id: Ide4518292bd9392d09f701b2c301673687d19f3b
2019-07-04 21:58:42 +00:00
Aaron Schulz
baafb5adb4 Make ExternalStore wrap ExternalStoreFactory and create access class
* Inject settings and global instances as dependencies to the
  ExternalStoreMedium instances. This includes the local wiki
  domain, so that wfWikiId() calls are not scattered around.
* Create ExternalStoreAccess service for read/write logic.
* Deprecate the ExternalStore wrapper methods.
* Add some exception cases for bogus store URLs are used instead
  of just giving PHP warnings and failing later.
* Make moveToExternal.php require the type/protocol to decide
  which ExternalStoreMedium to use instead of assuming "DB".
* Convert logging calls to use LoggerInterface.

Change-Id: I40c3b5534fc8a31116c4c5eb64ee6e4903a6197a
2019-06-28 14:31:44 -07:00
Aryeh Gregor
7b4489e019 Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints.  This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases).  As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User.  If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args().  Some of the changes are definitely safe, like
functions and test classes.

In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:

* Forwarding all arguments to another function. It's useful to keep
  func_get_args() here where we want to keep the list of expected
  arguments and their meanings in the function signature line for
  documentation purposes, but don't want to copy-paste a long line of
  argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
  arguments individually but want to use them as an array as well for
  some reason.

Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2019-04-12 20:17:01 +00:00
Derick Alangi
84292b7728 Replace deprecated function wfEscapeShellArg with Shell::escape()
Change-Id: I4046d593d1450cfffc489ca2abadba1084a540e4
2019-04-07 20:17:39 +01:00
Kunal Mehta
4ef179e335 Fix/suppress misc phan errors (#5)
Add lots of missing return statements, or remove incorrect doc blocks.

Change-Id: I0881e98fbb9d0d4cf79ecc824064d24538055d3f
2019-04-05 15:53:37 -07:00
Umherirrender
ae2f5d6232 Add missing use statements
Swap some ResultWrapper/Database to interface IResultWrapper/IDatabase

Change-Id: I312cb3cca5742f72efdb0965ba35362f2eb1129d
2018-06-27 20:49:23 +02:00
Max Semenik
6e956d55aa Replace call_user_func_array(), part 2
Uses new PHP 5.6 syntax like ...parameter unpacking and
calling anything looking like a callback to make the code more readable.
There are much more occurrences but this commit is intentionally limited
to an easily reviewable size.

In one occurrence, a simple conditional instead of trickery was much more readable.

This patch finishes all the easy stuf in the core, the remainder is either unobvious
or would result in smaller readability gains. It will be carefully dealt with in
further commits.

Change-Id: I79a16c48bfb98b75e5b99f2f6f4fa07b3ae02c5b
2018-06-07 20:19:26 -07:00
Umherirrender
554f9c857c Replace wfGetLBFactory
@deprecated since 1.27

Change-Id: I11a7253cebe525948a55cebee183e6de128fdc39
2018-02-27 20:02:48 +00: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
Aaron Schulz
30f4b3c103 Replace DatabaseBase => Database in more places
Change-Id: If37a7909056bf2c31a8228cbc84f0fbbf5f1c517
2016-09-28 15:53:02 -07:00
Aaron Schulz
3d5016569d More replication var cleanups in /maintenance
* Fix option check in sql.php
* Rename RecompressTracked vars and avoid deprecated
  method calls

Change-Id: Ie04f6e841d68d69c9243a185de1bd13a612b2070
2016-09-05 23:00:43 -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
Aaron Schulz
c0a9ab0f6d Change "slave" => "replica DB" in /maintenance
Change-Id: Ibd3d617901130378a935402326cd4eefbb382c9e
2016-09-06 00:13:08 +00:00
Chad Horohoe
78c4afeaff RecompressTracked: Remove useless member variable
It's only checked once and has no external users

Change-Id: I6951b799759f1d8b0063a3059bec5c1c64a35815
2016-05-18 13:40:39 -07: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
Aaron Schulz
d0dc081a50 Fix numerious errors in RecompressTracked
* Fix method calls to wrong classes
* Cleanup IDEA errors in static analysis

Change-Id: Ibd0fdb52db884abefb149f5340a4a4b5dad2c89b
2015-12-30 16:21:46 -08: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
umherirrender
2320f5cfe2 Change some line comments to multi line comments
This allows empty lines inside the comment as found by the
MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.EmptyComment sniff

Change-Id: Iac155bbda4a84562db2b452baeae9b8973899453
2015-10-14 09:40:50 +02:00
Aaron Schulz
4c4325e98c Modernized slave wait checks in recompressTracked.php
Change-Id: I5771af8135530677dc8223389f572896918c6b72
2015-10-02 00:19:54 +00: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
Bryan Davis
1195e11a8a Move MWLogger classes to MediaWiki\Logger namespace
Move the MWLogger PSR-3 logging related classes into the
MediaWiki\Logger namespace. Create shim classes to ease migration of
existing MWLoggerFactory usage to the namespaced classes.

Bug: T93406
Change-Id: I359cc81fbd2dcf8937742311dcc7d3dee08747b0
2015-04-03 11:32:24 -07:00
Bryan Davis
6a8c686c7a Deprecate wfErrorLog
When a logging service other than MWLoggerLegacySpi is used, the
behavior of wfErrorLog is not guaranteed.

Change-Id: I8543bfd556aa752665f7a3daa855d3c2f7fc8956
2014-12-15 16:26:03 -07:00
umherirrender
c0151eec5f Fix case of various newFromID/newFromId functions
User::newFromID -> User::newFromId
Revision::newFromID -> Revision::newFromId
RecentChange::newFromID -> RecentChange::newFromId

WikiPage::newFromId -> WikiPage::newFromID
Title::newFromId -> Title::newFromID

Change-Id: I310f26653613951e9b21ce915a92d205a87937f1
2014-12-10 19:40:27 +00:00