Commit graph

257 commits

Author SHA1 Message Date
Umherirrender
a9aa1e7346 Fix type of value directly passed to php internal functions
Found by phan strict checks

Change-Id: Icc44cd143f2e98fa3ca188e625a3289441de0f73
2022-03-07 20:41:55 +01:00
Umherirrender
b126dbe3f2 Fix various documentation related to null types
The functions returning null or the class property is set explict null

Found by phan strict checks

Change-Id: I4a271093fb6526564d8083a08249c64cb21f2453
2022-02-26 10:31:24 +01:00
Reedy
86934b2fa8 Replace some more usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: I2eb133a9e32116cd155f59086245bc4d15ecbfcc
2022-02-24 20:27:46 +00:00
daniel
0ebf7786b1 DeferredUpdates: Introduce $wgForceDeferredUpdatesPreSend
Enabling this setting will cause post-send deferred updates to be run
before a response is sent to the client, so the client can observe all
effects of their last request immediately.

This resolves a problem with some end-to-end tests that were failing
because the updates caused by one request had not landed in the database
by the time the subsequent request was made.

This patch re-enabled some e2e tests that were disabled because of this
problem. If $wgForceDeferredUpdatesPreSend works as intended, the tests
should again pass reliably.

Bug: T230211
Bug: T301100
Change-Id: I0e30fdb6acba85cec4bb1499f7063ba6bfb0ffb2
2022-02-15 19:49:14 +01:00
Siddharth VP
b77dd0640c Fix typos in comments (M)
Change-Id: I5ab88a01ba3e5ea2aae853bb6f06492fbc84ceb5
2022-01-09 23:00:20 +05:30
Kunal Mehta
5d5a3c0720 SECURITY: Require 'read' right for most actions
As a security hardening measure to limit exposure on private wikis from
actions on $wgWhitelistRead pages, require an explicit 'read' right on
actions by default. Currently only ViewAction disables this check since
it does its own permissions checking.

This is somewhat duplicative of the permissions check in
MediaWiki::performRequest() but we'll call it defense in depth. It also
matches similar logic in the Action and REST APIs.

Bug: T34716
Bug: T297416
Change-Id: Ib2a6c08dc50c69c3ed6e5708ab72441a90fcd3e1
2021-12-15 16:12:27 +00:00
Legoktm
93f79a9122 Revert "Replace deprecated methods IContextSource::getWikiPage && IContextSource::canUseWikiPage"
This reverts commit ef458e8948.

Reason for revert: Causes page tabs to disappear on Special:WhatLinksHere.

Bug: T297744
Change-Id: I0ee282a9f7a5a9b2cfdc3261d800d9e27eaf977e
2021-12-14 12:43:15 -08:00
Amir Sarabadani
9bcd3fdfa5 Remove ActionAjax
Bug: T42786
Change-Id: I8bda0c281e1f4abbffbddb80ac74a6d61a034d28
2021-12-01 22:31:30 +01:00
jenkins-bot
358f3bebc5 Merge "rdbms: Stop calling LBFactory::setAgentName from MW wiring" 2021-11-22 15:05:58 +00:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
Timo Tijhof
76e1953273 rdbms: Stop calling LBFactory::setAgentName from MW wiring
For web requests, this was attempting to inject the current client's
session user name or XFF-resolved IP address to the SQL query.

However, this has been broken for five years (since around
commit 16b4e3a9f1 / Ibb4f1c0dafea071a) because the relevant objects
are already constructed by the time MediaWiki::main() runs, and so
MediaWiki::setDBProfilingAgent isn't doing much other then changing
the LBFactory state, which rarely gets another chance to pass it down
after that.

This breakage is actually a good thing as otherwise Tendril and
performance_schema tools would not have been able to aggregate slow
queries very well due to being too dynamic/variable (these tools
can't ignore comments per T291420 and T291419, and the comments we
do have for fname are actually useful to aggregate.)

As of I6e9939e34287d27430, this lack of dynamic variability (apart
from standard SQL syntax conditions that can vary) is now documented
as desirable for wikimedia/rdbms. To avoid confusion or from this
code accidentally becoming undead, let's remove it.

While at it, remove it for CLI in MWLBFactory as well. This one did
work currently, but as I understand it was not very useful on its
own but rather filling in data to keep a consistant shape with the
web format, which is broken. In particular, afaik dbuser and
sender webserver hostname are already known to MySQL for all queries
and present in processlist and other tooling.

Bug: T193050
Change-Id: I033140ddbb04df97de3391a247d1ca937b3bc918
2021-11-19 00:51:41 +00:00
Roman Stolar
ef458e8948 Replace deprecated methods IContextSource::getWikiPage && IContextSource::canUseWikiPage
Bug: T275710
Change-Id: I74b8f76a525793bc029d9ee1f7297b46ac0a9174
2021-11-16 13:58:39 +02:00
Timo Tijhof
df32228920 profiler: Remove dependency on WebRequest from Profiler
I intent to remove Profiler::getContext/setContext after a week
without deprecation. I consider these methods as internal (they
predate the stable interface policy, and we forgot to triage this
class, it has neither `@stable` nor `@internal`).

The hard-deprecation in this commit is to detect any use that may
have gone unnoticed in WMF production from Codesearch analysis alone,
where no usage was found.

Bug: T292269
Change-Id: Id40679f21cc7a3f77a1b96a4bbd55daeaea16892
2021-10-09 03:00:45 +00:00
jenkins-bot
63ec950b15 Merge "Metrics: Wire up MetricsFactory into ServiceWiring and emit steps" 2021-10-07 15:12:10 +00:00
Cole White
0e150f8cb2 Metrics: Wire up MetricsFactory into ServiceWiring and emit steps
* Adds DefaultSettings options
 * Wires up MetricsFactory into ServiceWiring
 * Performs MetricsFactory->flush() in restInPeace()

Bug: T240685
Bug: T205870
Change-Id: I46f0a09f4dab38fa4c9495aa2da9ecab60376ca7
2021-10-07 16:19:42 +02:00
Timo Tijhof
c49a45f6bf Deprecate wfLogProfilingData(), improve statsd/profiling docs
* Document that Maintenance::shutdown is the CLI equivalent of
  MediaWiki::restInPeace.

* Centrally document in the emitStats method why we flush stats
  regularly, and clarify that these OOM concerns are specific to
  CLI processes there. That isn't to say it could never happen on a
  web request, but all our early flush handling (even DB trx hooks)
  are explicitly limited to command-line mode today and always have
  been.

* Ref T253547. It is now clear why --profiler=text doesn't work on
  the CLI (it is missing the non-external profiler output handling),
  which I'll fix in a follow-up.

* Ref T292269. The WebRequest-dependency in Profiler is now much more
  clearly problematic. Previously this was masked by wfLogProfilingData
  effectively silencing the warning on the CLI without it being so
  obviously wrong. I'll fix that in a follow-up.

* Ref T292253. All this is already post-send, and flame graphs confirm
  that we don't have any calls to emitBufferedStatsdData nor
  StatsdClient::send apart from the post-send one via restInPeace.

Bug: T253547
Bug: T292269
Bug: T292253
Change-Id: If78c37046cf8651c7a8d6690e01d38c3ca29d8d8
2021-10-02 23:23:01 +01:00
James D. Forrester
3407458ea0 MWExceptionHandler: Rename rollbackMasterChangesAndLog to rollbackPrimaryChangesAndLog
Change-Id: I9a90b4f74eb65cd9e20ae9faa6d1949be96543c0
2021-09-03 17:36:34 -07:00
James D. Forrester
8a659ca2fe ILoadBalancer/ILBFactory: Rename hasOrMadeRecentMasterChanges to hasOrMadeRecentPrimaryChanges
Bug: T282894
Change-Id: I1d6130bcd09019f9e2de2974878902c7aafe8f0a
2021-09-02 16:34:44 -07:00
James D. Forrester
5ad7ca7eba ILoadBalancer/ILBFactory: Rename commitMasterChanges() to commitPrimaryChanges()
Bug: T282894
Change-Id: I0d80be56e683924254c4e38d05e1109ea74eeab5
2021-09-02 11:27:10 -07:00
Timo Tijhof
e387cd9c35 Change trivial use of getVal('action') to getRawVal
Per docs added in I18767cd809f67b, these don't need normalization
as they are only compared against predefined strings, and besides
are generally entered manually in a form, and even then would not
require the kinds of Unicode chars that have multiple/non-normalized
forms.

In nearby areas to also fix some trivial cases:

* getVal('title') obviously needs normalization.
  Use getText() to make this more obvious.

* getVal() compared against simple string literals within the code
  obviously don't need normalization (e.g. printable === 'no').

* Change hot code in MediaWiki checking for whether 'diff' or 'oldid'
  are set to getCheck (which uses getRawVal) instead of getVal.
  As a bonus this means it now handles values like "0" correctly,
  which could theoretically have caused bad behaviour before.

Change-Id: Ied721cfdf59c7ba11d1afa6f4cc59ede1381238e
2021-08-26 22:11:58 +01:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Derick A
65e6fa5c43 MediaWiki: Avoid usage of deprecated JobQueueGroup::singleton()
Make use of the `JobQueueGroupFactory` service provisioned in 1.37

Change-Id: I12fe943fc1e62402dcfb7d0f66495fdbc76d751d
2021-07-12 23:39:28 +01:00
Tim Starling
a4922b5cc1 Add statsd timing for actions
So that we can see how slow history pages are.

Details are by analogy with API action timing.

Bug: T284274
Change-Id: I8a679b8bc94fe2a062b9d62ecff0a7584e65a4db
2021-06-29 03:34:21 +00:00
Gergő Tisza
8925ba9c50 Add TransactionProfiler::silenceForScope()
Add a helper method for the common use case of temporarily silencing
transaction profiler warnings.

Change-Id: I40de4daf8756da693de969e5526b471b624b2cee
2021-05-16 18:19:53 +02:00
James D. Forrester
f2f9345e39 Replace uses of DB_MASTER with DB_PRIMARY in documentation and local variables
This is just a start.

Bug: T254646
Change-Id: I9213aad4660e27afe7ff9e5d2e730cbf03911068
2021-05-14 12:40:34 -07:00
DannyS712
c6216377bb Remove deprecated https-related hooks
All hard deprecated in 1.35
* BeforeHttpsRedirect
* CanIPUseHTTPS
* UserRequiresHTTPS

Also soft deprecate the wfCanIPUseHTTPS
method, which always returns true. Will
be hard deprecated once callers are updated

Change-Id: Ie6d71809d09edf6be9b8280debeb152ef7fce398
2021-04-30 11:53:18 -07:00
James D. Forrester
64898405cb build: Upgrade mediawiki-codesniffer from v35.0.0 to v36.0.0
Change-Id: I8905d0d69738a1cd6997c104080fdf128d315e8b
2021-04-29 13:00:15 -07:00
Tim Starling
9f4eb79c2e Reapply Content-Length deferred updates patches
* Revert "Disable DEFER_SET_LENGTH_AND_FLUSH headers to avoid HTTP
  errors"
* Reapply "Avoid HTTP protocol errors when fastcgi_finish_request() is
  unavailable"
* Reapply "Move logDataPageOutputOnly() call to
  outputResponsePayload()"

This reverts commit 0393ddbb2a.
This reverts commit 89065a22aa.
This reverts commit e70757f58b.

Change-Id: I8a362a80bb1aa147192218a37df34aadba34fb2e
2021-04-08 09:25:56 +00:00
Aaron Schulz
0393ddbb2a Disable DEFER_SET_LENGTH_AND_FLUSH headers to avoid HTTP errors
This partially reverts 4f11b61454, which landed in 1.35.

Bug: T235554
Change-Id: I2c840776612b3e355465eddb45e235083a2d2fda
2021-04-06 04:30:22 +00:00
Reedy
89065a22aa Revert "Avoid HTTP protocol errors when fastcgi_finish_request() is unavailable"
This reverts commit f4f0ad970e.

Bug: T278579
Change-Id: I3071209eff16b5dcc853f497a243a9af0883b67a
2021-04-02 13:31:24 +01:00
Reedy
e70757f58b Revert "Move logDataPageOutputOnly() call to outputResponsePayload()"
This reverts commit d32c481a64.

Bug: T278579
Change-Id: Ic66827d9ced6aff652962f4b97f6ad0cfd398e4f
2021-04-02 13:31:13 +01:00
Aaron Schulz
d32c481a64 Move logDataPageOutputOnly() call to outputResponsePayload()
Trap the extra profiling output via a buffer and append it to the
payload string parameter. This way, the Content-Length will be set
correctly with the text profiler.

Update other entry points to call logDataPageOutputOnly().

Follow-up to f4f0ad970e.

Bug: T235554
Change-Id: I4915d1096801a063d493443a3606fd3851e771a6
2021-03-29 10:53:08 -07:00
jenkins-bot
0db01dbc43 Merge "Avoid HTTP protocol errors when fastcgi_finish_request() is unavailable" 2021-03-24 23:12:14 +00:00
Aaron Schulz
f4f0ad970e Avoid HTTP protocol errors when fastcgi_finish_request() is unavailable
This fixes problem that arise with apache2/mod_php due to deferred updates

* Do not send unnecessary and invalid "Content-Encoding: identity" header
* Do not send "Connection: close" if HTTP2 is detected (per the HTTP spec)
  pending, which reduces the use of output buffer and HTTP header tricks
* Make sure that no output is emitted in doPostOutputShutdown() from any
  deferred updates since the response will have already been flushed to
  the client by that point
* Make the Content-Length header logic in outputResponsePayload() account
  for cases where there is a non-empty output buffer, cases where there
  are several output buffers (bail out), and limit the use of the header
  to HTTP 200/404 responses (avoids violation of the HTTP spec)
* Make sure OutputHandler::handle() does not send payloads for responses
  that must not have one (e.g. "204 No Content")
* If an output buffer using OutputHandler::handle is active, then let it
  handle the setting of Content-Length rather than outputResponsePayload()
* Do not bother trying to disable zlib.output_compression, since that did
  not actually stop the client from getting blocked
* Set "no-gzip" via apache_setenv() unconditionally

Bug: T235554
Change-Id: I26f16457698c2c45e561b0c79c78a74e7f47126c
2021-03-24 12:53:31 -07:00
Aaron Schulz
06ef99a4b4 Limit the scope of when ErrorPageError is expected to be thrown
Move the try/catch logic to the performRequest() call in main()

Change-Id: I30fee12ad2f04368386fae0221d2b513e9013ce0
2021-03-22 17:07:18 -07:00
jenkins-bot
bbe83dab42 Merge "Remove MediaWiki::triggerJobs()" 2021-03-21 22:12:03 +00:00
Tim Starling
1dea86d6a2 Remove MediaWiki::triggerJobs()
Nothing calls it in Code Search, and it complicates Aaron's refactor
of post-send job execution.

Change-Id: I78c4dbe34d98fc31a00144e099e5b390a5a60eb8
2021-03-18 14:12:50 +11:00
Petr Pchelko
eec331897e Replace various usages of PermissionManager with Authority
Change-Id: Idc303bdbbe2b7ce9e7011ee1f3926c781c56af71
2021-03-17 20:23:58 -06:00
Cormac Parle
adda9c0555 Allow top-right search form target to be modifiable
Before this patch, if 'search' is in the request params then we always
go to Special:Search. Also, the 'title' param on the top-right search
form is always set to Special:Search, which means that form always goes
to Special:Search too.

In order to allow the search form to go to a different page, this
patch:
1. moves the hardcoded redirect to Special:Search based on 'search' in
the request params, so that it only happens if we cannot determine
the page title in the usual way
2. adds a setter for the default search page title in \Skin, so that
it can be set in a hook

Bug: T273879
Change-Id: If62573d19ca76ed1db53a5117182172233e514ab
2021-03-12 17:38:13 +00:00
Aaron Schulz
ce27d87b27 Hard-deprecate MediaWiki::triggerJobs()
Soft-deprecated in MW 1.34, not used anywhere in Codesearch.

Change-Id: Ibc523744b7451d692a4bc7d8688d157d0effe831
2021-03-12 02:30:59 +00:00
Aaron Schulz
bd7cf4dce9 Add $wgChronologyProtectorStash and improve $wgMainStash comments
Remove WRITE_SYNC flag from ChronologyProtector since the current
plan is to simply use a datacenter-local storage cluster.

Move the touched timestamps into the same stash key that holds the
replication positions. Update the ChronologyProtector::getTouched()
comments.

Also:
* Use $wgMainCacheType as a $wgChronologyProtectorStash fallback
  since the main stash will be 'db-replicated' for most sites.
* Remove HashBagOStuff default for position store since that can
  result in timeouts waiting on a write position index to appear
  since the data does not actually persist accress requests.
* Rename ChronologyProtector::saveSessionReplicationPosition()
  since it does not actually save replication positions to storage.
* Make ChronologyProtector::getTouched() check the "enabled" field.
* Allow mocking the current time in ChronologyProtector.
* Mark some internal methods with @internal.
* Migrate various comments from $wgMainStash to BagOStuff.
* Update some other ObjectCache related comments.

Bug: T254634
Change-Id: I0456f5d40a558122a1b50baf4ab400c5cf0b623d
2021-03-01 20:34:34 +00: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
Timo Tijhof
613df39569 rdbms: Use PSR-3 for ChronologyProtector shutdown debug message
This is sent at the end of the LBFactory::shutdown wrapper, so will
still happen at the same logical point in time.

Use LBFactory->replLogger since that it is also the logger used
by ChronologyProtector.

Bug: T254634
Change-Id: Ic4a9573e6cd3ea00f77b2f44c03453c5b96fa486
2021-01-07 23:35:37 +00:00
James D. Forrester
abdc94a3da Swap out uses of User->isLoggedIn() with ->isRegistered()
Bug: T270450
Change-Id: I90ff94a553ebae9a4ef97c25c333f067f19c327d
2020-12-22 03:13:37 +00:00
jenkins-bot
6415fd72a1 Merge "Replace deprecated Title::getCdnUrls" 2020-11-13 08:22:53 +00:00
Umherirrender
b786edbb22 Replace deprecated WikiPage::factory in MediaWiki class
Change-Id: If5d59eecd07c95606887fed9f3384c557cfda40e
2020-11-11 22:49:35 +01:00
Umherirrender
1b80321f39 Replace deprecated Title::getCdnUrls
Change-Id: Ie3cd9ebd6ef442af19a054a1bb81e5c3574fb2bb
2020-11-03 11:58:05 +01:00
ArtBaltai
e7dbd69de0 Hard deprecation of Language::convertTitle(),
::findVariantLink(), ::updateConversionTable()

Co-authored-by: C. Scott Ananian <cananian@wikimedia.org>
Bug: T226832
Change-Id: I41a3b67490fc6b9d4c484f566d346a0d10c670e9
2020-10-20 16:49:17 -04:00
jenkins-bot
84d82a7cd8 Merge "Change invalid 'Content-Encoding: none' header" 2020-10-12 10:33:13 +00:00
Ed Sanders
7683f7d839 Use strict (in)equality with namespaces constants when LHS is definitely an integer
Change-Id: I8fede00dfe1270d93c5d78d3c36e788cddfc8a99
2020-07-31 18:03:28 +01:00