Commit graph

1505 commits

Author SHA1 Message Date
James D. Forrester
7e0bb365bb Drop wfUseMW, deprecated in 1.26
Change-Id: I291d6eace1913a651c5e7136f3f2e0216d89fac5
2018-09-13 18:24:51 -07:00
jenkins-bot
2f86f8dbb9 Merge "Don't throw an exception when waiting for replication times out" 2018-09-04 02:20:12 +00:00
Tim Starling
e8df0fbab1 Don't throw an exception when waiting for replication times out
For maintenance scripts it is usually harmful to throw an exception.
For jobs the exception was already caught and handled appropriately,
so this can continue as before. For DeferredUpdates it was extremely
harmful to throw an exception. So in the web case, reduce the timeout to
1s and continue as normal if the 1s timeout is reached. This allows the
DeferredUpdate to be throttled without being killed.

In the updater, increase the replication wait timeout to 5 minutes.
ALTER TABLE could indeed cause replication lag, but exiting the update
script with an exception will probably ruin your day. Update actions are
not necessarily efficiently restartable.

Do not call JobQueue::waitForBackups() when jobs are popped. Maybe it
makes sense to call a queue-specific replication wait function for
bulk inserts, like copyJobQueue.php, but doing it when jobs are popped
just makes no sense. Surely the worst that could happen is that the
queue would become locally empty? Removing this waitForBackups() call
avoids waiting for replication twice when JobQueueDB is used.

Bug: T201482
Change-Id: Ia820196caccf9c95007aea12175faf809800f084
2018-09-03 12:29:35 +10:00
Kunal Mehta
75c3755666 Remove wfMakeStaticArrayFile()
Replaced by the StaticArrayWriter class.

Bug: T200626
Change-Id: I7c02cf3a7dda2804d2eb8d51716254bd78b7544c
2018-08-17 23:07:17 -07:00
Kunal Mehta
3b1e8a5cef Move wfMakeStaticArrayFile() into a class
And include tests :)

This code is independent of MediaWiki, but not really large enough to be
worth librarizing right now.

Bug: T200626
Change-Id: I022c074e8a708fb5219bc4ff4b53e7e31f60dc4b
2018-08-17 22:48:19 -07:00
Kunal Mehta
49efdca8f5 Deprecate wfGetCache() and wfGetMainCache()
The former is already a wrapper around ObjectCache::getInstance().

The latter was identical to ObjectCache::getLocalClusterInstance().

Bug: T115890
Change-Id: Ib4e43bc8d3f4ac9f7a453e36dcce9b3d962666ba
2018-08-17 17:56:21 +00:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
James D. Forrester
827e143c9e GlobalFunctions: Hard-deprecate wfUseMW, unused
Change-Id: Ifa532f2fb7d482238e4b922f622a79b9ab6540e8
2018-07-28 16:59:08 -07:00
jenkins-bot
4533986087 Merge "Avoid a redirect loop when the request URL is not normalized" 2018-07-24 16:13:39 +00:00
jenkins-bot
1655c86faf Merge "$wgHttpsPort should only be used in very special cases" 2018-07-24 01:13:32 +00:00
Max Semenik
b8dee03d9e GlobalFunctions: use a closure instead of polluting global namespace
Change-Id: Ia587008de75a8bde90ad45d4932284f0b6401845
2018-07-19 23:54:49 -07:00
Max Semenik
9b0c621d7f Deprecate wfArrayFilter() and wfArrayFilterByKey()
Now that all our supported PHP versions have array_filter()
with a third parameter, these functions aren't needed anymore.

Depends-On: I3b097a1a048baabcaca15dc214a3a1bb06e746cc
Depends-On: I0187e27ac47cbab099249572201d1a649226a734
Change-Id: I7cabd0252691a083cb749cf9d3a7a23f1d076c39
2018-07-19 08:40:46 +02:00
Tim Starling
f6d582a91e Avoid a redirect loop when the request URL is not normalized
If the request URL was not normalized, for example having a double slash
in it, this could cause it to fail to match in the PathRouter. But the
canonicalizing redirect was using the normalized URL, causing a redirect
loop exception.

So:

* If the PathRouter fails to match with the original URL, try matching
  against the normalized URL. This allows it to still work for
  normalized URLs with a double slash in the title part of the path.
* Have WebRequest::getFullRequestURL() always return the URL without
  removing dot segments or interpreting double slashes. Just append
  the path to the server.
* Make MediaWikiTest.php use WebRequest instead of FauxRequest, allowing
  it to reproduce the exception in question. Add relevant test.
* Add tests for the new PathRouter behaviour.

Bug: T100782
Change-Id: Ic0f3a0060904abc364f75dae920480b81175d52f
2018-07-16 15:55:59 +10:00
Brian Wolff
89b21847e1 Start working on phan-taint-check warnings. Fix minor escaping issues.
This fixes 26 of the phan-taint-check warnings on MW core. Some
are outright fixed, others are false positives that were suppressed.

This really only covers some of the easy ones. There are still
314 warnings to go.

Change-Id: I30463bc3a09fd4324d190de8533f51784764dd3a
2018-07-12 03:26:59 +00:00
Tim Starling
8962915449 $wgHttpsPort should only be used in very special cases
When expanding a URL, don't overwrite an explicitly specified port or
add a port to a foreign URL. $wgHttpsPort is only useful for a very
specific case: when $wgServer is protocol-relative and HTTPS is
requested.

Documented correct use of $wgHttpsPort in DefaultSettings.php. Fixed
invalid "@see", in Doxygen it can only point to "classes, functions,
methods, variables, files or URL".

Added test cases which previously failed.

Change-Id: Id65c58300d22712212b6605711ff916916e8768b
2018-07-11 12:31:48 +10:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
jenkins-bot
2ff855cd49 Merge "Add missing use statements" 2018-07-04 00:44:28 +00:00
C. Scott Ananian
6f60ee3b27 Hard deprecate wfBCP47, which was soft deprecated in 1.31
Change-Id: I8632f08a8cb22641b5d16d955f3164dc45843520
2018-07-03 14:04:45 +00: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
Fomafix
3714131b5d Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
This is a followup to 485f66f1.

Change-Id: I7a2a44b7e933103178929b3cdc015859612c8b35
2018-06-11 19:23:15 +02:00
Kunal Mehta
b7116e4f7d Fix phpdoc for wfMessage $params for phan
phan and phpDoc expect that the type of variadic params is the type of
each individual item.

Change-Id: I8229d52b3e4b70a9de6c5bb813bab776c5547e5d
2018-06-08 10:59:22 -07:00
Max Semenik
f16caa5b06 Fix wfMessage() annotation
$params is a variadic parameter now, so it must be treated as an
array. Same thing for wfMessageFallback().

Change-Id: I606deb7ea0fb9be25ac79aadfbab0cc44bdc36a0
2018-06-07 23:07:57 -07:00
Max Semenik
8085c58a4b Replace call_user_func_array(), part 1
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.

Change-Id: Idcec077ef3fdf029b632cceafd0150851ad723e3
2018-06-04 23:39:04 -07:00
Max Semenik
817049ec6b Begin introducing PHP 5.6 variadic parameters where appropriate
Change-Id: I5670b8482e8d3bcb0b3a2b4d2ce9834cfc37e171
2018-06-04 11:53:55 -07:00
jenkins-bot
5a6c78c441 Merge "Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient" 2018-05-31 19:01:07 +00:00
jenkins-bot
a2882874bb Merge "Use PHP 7 '<=>' operator in 'sort()' callbacks" 2018-05-31 18:48:34 +00:00
Timo Tijhof
a930bf7d7b Remove deprecated global $parserMemc and wfGetParserCacheStorage
Deprecated since 1.30, no longer used in core, bundled components,
and WMF-deployed extensions.

Change-Id: I09715f94750f083712719ef599a2ea4260297681
2018-05-31 14:28:42 +01:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Bartosz Dziewoński
b191e5e860 Use PHP 7 '<=>' operator in 'sort()' callbacks
`$a <=> $b` returns `-1` if `$a` is lesser, `1` if `$b` is lesser,
and `0` if they are equal, which are exactly the values 'sort()'
callbacks are supposed to return.

It also enables the neat idiom `$a[x] <=> $b[x] ?: $a[y] <=> $b[y]`
to sort arrays of objects first by 'x', and by 'y' if they are equal.

* Replace a common pattern like `return $a < $b ? -1 : 1` with the
  new operator (and similar patterns with the variables, the numbers
  or the comparison inverted). Some of the uses were previously not
  correctly handling the variables being equal; this is now
  automatically fixed.
* Also replace `return $a - $b`, which is equivalent to `return
  $a <=> $b` if both variables are integers but less intuitive.
* (Do not replace `return strcmp( $a, $b )`. It is also equivalent
  when both variables are strings, but if any of the variables is not,
  'strcmp()' converts it to a string before comparison, which could
  give different results than '<=>', so changing this would require
  careful review and isn't worth it.)
* Also replace `return $a > $b`, which presumably sort of works most
  of the time (returns `1` if `$b` is lesser, and `0` if they are
  equal or `$a` is lesser) but is erroneous.

Change-Id: I19a3d2fc8fcdb208c10330bd7a42c4e05d7f5cf3
2018-05-30 18:05:20 -07:00
jenkins-bot
d8a144d38e Merge "languages: Use static array files for normalizer data" 2018-05-25 23:03:18 +00:00
jenkins-bot
2542abb6f6 Merge "Enable merging of WrappedStringList between 'bottomscripts' and 'reportime'" 2018-05-25 19:52:13 +00:00
James D. Forrester
9d875febd5 Bump PHP version requirement to 7.0.0+
Bug: T172165
Change-Id: I740f32ac859d9bb3787fdf8414f82ae6f410492f
2018-05-24 16:15:56 +01:00
Timo Tijhof
03db2f5b3c Enable merging of WrappedStringList between 'bottomscripts' and 'reportime'
* Fix ResourceLoaderClientHtml to return what it was documented to
  return, a WrappedStringList. It accidentally used the wrong join()
  method, causing it to create a plain string too early.

* Update method documentations from ClientHtml::getBodyHtml to
  BaseTemplate::getTrail for 'bottomscripts', and from
  ResourceLoader::makeInlineScript for 'reporttime'.

* Update BaseTemplate::getTrail to join by new line instead of native string
  concatenation.

This by itself would suffice for the most common case, but in order
to also account for the possibility of extensions using hooks for
'SkinAfterBottomScripts' that concatenate, update bottomScripts()
to pass a plain string to the hook and merge it later.

Change-Id: If0d227cb9db67229a27d489c082db790ea8e3840
2018-05-24 14:23:17 +01:00
Timo Tijhof
4f22361759 languages: Use static array files for normalizer data
This reduces the number of '.ser' files to 1 (we still have
first-letters-root.ser).

Change-Id: Ib0ee0d826da34b1825fd5bb74563c6bbadeec75c
2018-05-22 21:38:43 +00:00
Kunal Mehta
06ca92eb8c Re-enable MediaWiki.Usage.SuperGlobalsUsage.SuperGlobals sniff
Disable it in specific files and places where there are legitimate uses
to access $_GET and $_POST directly.

For EditPage, which wants to output $_POST for debugging information,
introduce WebRequest::getPostValues() as a wrapper, matching the
existing ::getQueryValues().

Change-Id: I2cb0a7012fb7ed29dcd720056b42f56508ddc5fa
2018-05-19 15:07:25 -07:00
Kunal Mehta
230958d97c Autofix MediaWiki.Commenting.FunctionComment.SpacingDoc* errors
Change-Id: I63761ebce04c03b9b13237919c27cc10180f198f
2018-05-19 14:07:03 -07:00
Brian Wolff
70941efd35 Initial support for Content Security Policy, disabled by default
The primary goal here is a defense in depth measure to
stop an attacker who found a bug in the parser allowing
them to insert malicious attributes.

This wouldn't stop someone who could insert a full
script tag (since at current it can't distinguish between
malicious and legit user js). It also would not prevent
DOM-based or reflected XSS for anons, as the nonce value
is guessable for anons when receiving a response cached
by varnish. However, the limited protection of just stopping
stored XSS where the attacker only has control of attributes,
is still a big win in my opinion. (But it wouldn't prevent
someone who has that type of xss from abusing things like
data-ooui attribute).

This will likely break many gadgets. Its expected that any
sort of rollout on Wikimedia will be done very slowly, with
lots of testing and the report-only option to begin with.

This is behind feature flags that are off by default, so
merging this patch should not cause any change in default
behaviour.

This may break some extensions (The most obvious one
is charinsert (See fe648d41005), but will probably need
some testing in report-only mode to see if anything else breaks)

This uses the unsafe-eval option of CSP, in order to
support RL's local storage thingy. For better security,
we may want to remove some of the sillier uses of eval
(e.g. jquery.ui.datepicker.js).

For more info, see spec: https://www.w3.org/TR/CSP2/
Additionally see:
https://www.mediawiki.org/wiki/Requests_for_comment/Content-Security-Policy

Bug: T135963
Change-Id: I80f6f469ba4c0b608385483457df96ccb7429ae5
2018-05-13 21:01:11 -07:00
Reedy
1e7aea9089 Add since tag to wfRemoveDotSegments
Looked it up for another commit, so might aswell make it easier to find for others :)

Change-Id: I432b13b35481cbca9ed6e7328b3b9115fdd203ea
2018-04-28 12:06:10 +00:00
Max Semenik
c751f05d21 Hard-deprecate wfUsePHP()
Deprecated in 1.30, no callers anywhere.

Change-Id: I5168234f4e8cfffbccc9dd43026255ee2dcd878d
2018-04-18 18:45:47 -07:00
Max Semenik
686de25786 Hard-deprecate wfCountDown()
Deprecated in 1.31, the only callers left are in BlueSpice.

Change-Id: I3d59b0967c161eff0190a6f577e571230a7e7a2f
2018-04-18 18:43:02 -07:00
Max Semenik
f4668d6c12 Remove deprecated function wfShellExecDisabled()
Deprecated in 1.30, never had many callers.

Change-Id: Ie77c3df696313f691a68f21b15804539ffcc7f88
2018-04-18 18:41:00 -07:00
Max Semenik
0f50320502 Remove deprecated function wfInitShellLocale()
Deprecated in 1.30, never had more than 2-3 callers.

Change-Id: Ia023ede41affaf8e1b5fd1fed77cdbcefc9dc243
2018-04-18 18:35:41 -07:00
Max Semenik
efa586fddd Restrict shell commands by default
Before it's too late, let's boil the oceans
and just do it. This patch assumes that old code
calling wfShellExec() doesn't know about restrictions
so it doesn't restrict anything. New code, however,
needs to specify its restrictions or deal with defaults.

Change-Id: I58963901087202d4a405bcdb6bd12758bb6b0ff7
2018-04-16 11:50:13 -07:00
Max Semenik
5cf4575ea3 Deprecate wfShellWikiCmd()
Bug: T184339

Change-Id: Ic86a451e0e9d609e06865a4969560d151efa844c
2018-04-16 16:38:05 +00:00
Aaron Schulz
7f24eb5d78 Normalize and lower the default DB lag wait timeout
Bug: T190960
Change-Id: I49aca118583b20314e6bf82f196f3413571f5bd9
2018-03-28 13:49:25 -07:00
Timo Tijhof
665e9b7bf2 Convert OutputHandler functions to a class
* Convert OutputHandler.php from global functions to a class.

  - wfOutputHandler → OutputHandler::handle
    (no alias, no usage outside core)
  - wfGzipHandler → OutputHandler::handleGzip
    (private, no usage outside class)
  - wfRequestExtension → OutputHandler::findUriExtension
    (private, no usage outside class)
  - wfMangleFlashPolicy → OutputHandler::mangleFlashPolicy
    (private, no usage outside class)
  - wfDoContentLength → OutputHandler::emitContentLength
    (private, no usage outside class)
  - wfHtmlValidationHandler → OutputHandler::validateAllHtml
    (private, no usage outside class)

* Add the class to autoload.php for exposure outside WebStart.
  Specifically, for use in ApiFormatPhpTest. This also removes the
  need to manually load the class because this code runs after
  Setup.php loads AutoLoader.php.

Bug: T189966
Change-Id: I27a41ec0ae0ee30aeb313a616323b967605c4055
2018-03-20 21:11:32 -07:00
Kevin Israel
06ba5ca383 Remove internal use of deprecated $wgRequestTime
* Use $_SERVER['REQUEST_TIME_FLOAT'] unconditionally in WebRequest.php
  and libs/Timing.php. WebStart.php was doing this already without issue.
  The key existst since PHP 5.4, for both Web and CLI (we require 5.5).

* In wfDebug() and wfReportTime(), use $_SERVER['REQUEST_TIME_FLOAT'] instead.

* In ApiFormatBase and MWDebug, use WebRequest::getElapsedTime() instead.

* In Maintenance.php, remove setting of $wgRequestTime.

* In rebuildFileCache.php, update mocking to $_SERVER['REQUEST_TIME_FLOAT']
  so that we avoid re-introducing bug T24852.

Change-Id: I1b647da2862f815029caa533b592ec8a05b33806
2018-03-18 04:41:12 +00:00
Jayprakash12345
c48f489ba6 Remove deprecated function wfBaseConvert()
Bug: T189300
Change-Id: I5f05beb105dca8e8079e770df562c004a689c2ed
2018-03-09 16:41:54 +00:00
Umherirrender
554f9c857c Replace wfGetLBFactory
@deprecated since 1.27

Change-Id: I11a7253cebe525948a55cebee183e6de128fdc39
2018-02-27 20:02:48 +00:00
Umherirrender
b5dd5c769a Remove wfProfileIn/wfProfileOut
@deprecated since 1.25

Change-Id: Ie13c31816280fa577ef6bfb5fef172163f83c408
2018-02-24 10:45:31 +01:00