Commit graph

233 commits

Author SHA1 Message Date
Umherirrender
9879723ef3 Use namespaced classes (1)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Ic4d4dd61de5ab896fb6173eb579c81f164a1e4a3
2024-06-16 20:18:23 +02:00
daniel
9638fa314a Introduce entry point classes for media files.
This moves a code out of file scope into classes to make it
testable. The code is left in the same structure as it was before,
global functions have been converted into methods on the new
ThumbnailEntryPoint and Thumbnail404EntryPoint classes.

This test introduces comprehensive phpunit tests covering all functional
code paths in ThumbnailEntryPoint. This is intended to support
refactoring of this code.

Change-Id: I459abc7b11d0ab4ee682a863c9525a945048296f
2024-03-30 21:14:05 +01:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Daimona Eaytoy
7acfa6a0a5 Replace more instances of unchecked MWException
Most (all?) of the remaining usages are caught somewhere and will be
migrated later.

Bug: T328220
Change-Id: I5c36693a5361dd75b4f1e7a0bab5ad48626ed75c
2024-01-23 16:20:53 +00:00
Amir Sarabadani
b7c5d05813 PoolCounter: Namespace classes
Two of the classes in this directory have already namespaced to
MediaWiki\PoolCounter.

Bug: T353458
Change-Id: Ie41f8d935f7623bb40040a5eb78f99c6d7b7b75e
2023-12-20 09:32:19 +00:00
Paladox
a7584dda7a thumb: Fix "PHP Deprecated: strlen(): Passing null to parameter"
Change-Id: I7b31f42c15f9404df865a16936091adc455bb675
2023-12-18 13:03:53 +00:00
daniel
04197cb13f Introduce StatusFormatter
This takes us one step closer to deprecating Status,
so we can isolate StatusValue from presentation logic.

FormatterFactory is introduced as a mechanism for
getting instance of formatters that need access to the user interface
language and other request dependent information.

Usage is demonstrated in thumb.php, SpecialCreateAccount, and
SearchHandler. The examples indicates that there is no work do
be done around ErrorPageError and LocalizedHttpException.

Change-Id: I7fe5fee24cadf934e578c36856cc5d45fb9d0981
2023-10-27 14:56:51 +02:00
daniel
2b3d49e71f Use Authority in thumb.php
Replace usage of deprecated User::pingLimiter.

Tested locally:
* verified the relevant code paths are hit, using xdebug
* renderfile limit is applied when rendering standard sizes
* renderfile-nonstandard limit is applied when rendering non-standard sizes
* rendering standard thumbnail size is not affected by 'renderfile-nonstandard' limit
* rendering works when limits are not hit

Test after merge: Test that thumb.php works on the beta cluster.
But that actually seems to be broken already:
<https://commons.wikimedia.beta.wmflabs.org/w/thumb.php?f=Nummer3.jpg&width=222>

Monitor after deployment: Keep an eye on the Grafana board that tracks
rate limit checks and outcomes:
<https://grafana.wikimedia.org/d/8oA6CWr4z/mw-rate-limiting-overview>

Change-Id: I74c966cde20396381f18c60ec8622a91c8aa7ea6
2023-10-06 17:13:18 +00:00
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01:00
Amir Sarabadani
f4e68e055f Reorg: Move Status to MediaWiki\Status\
This class is used heavily basically everywhere, moving it to Utils
wouldn't make much sense. Also with this change, we can move
StatusValue to MediaWiki\Status as well.

Bug: T321882
Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3
Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
2023-08-25 15:44:17 +02:00
Tim Starling
be3018b268 Just another 80 or so PHPStorm inspection fixes (#4)
* Unnecessary regex modifier. I agree with this inspection which flags
  /s modifiers on regexes that don't use a dot.
* Property declared dynamically.
* Unused local variable. But it's acceptable for an unused local
  variable to take the return value of a method under test, when it is
  being tested for its side-effects. And it's acceptable for an unused
  local variable to document unused list expansion elements, or the
  nature of array keys in a foreach.

Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
2023-03-25 00:39:06 +00:00
jenkins-bot
7c92610ada Merge "Fix some typos" 2023-03-23 12:20:11 +00:00
Aaron Schulz
29bab859fc profiler: Add ProfilingContext class
Use this class to track the entry point and handler used for requests,
making it available for use in profiling, stats, and logging code.

This makes it possible for periodic and/or shutdown profiling callbacks
to know the basic action handler that applies to the request (if any).
Metric names can easily include this string along with MW_ENTRY_POINT
to create per-action profiling dashboards.

This info cannot otherwise be acquired from things like excimer stack
traces since the router and handler classes do not appear in the stack
during PRESEND deferred updates and variations like ApiMain/SpecialPage
"inclusion mode" would have to be detected somehow.

Bug: T330810
Change-Id: Icca5a7a343faeeb18652994c96752acb61a61fd1
2023-03-23 00:08:49 +00:00
Matěj Suchánek
c231736471 Fix some typos
Bug: T201491
Change-Id: I5c9408c262f09c936525f35abfacfa92a193b791
2023-03-21 15:58:09 +01:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
jenkins-bot
137238ab0a Merge "Replace deprecated PermissionManager::getGroupPermissions" 2022-12-14 21:54:17 +00:00
Umherirrender
4b638c585f thumb.php: Replace deprecated MWHttpRequest::factory
Bug: T324918
Change-Id: Ia40349ec97b10fe7d55e80a2c219afc9c253543a
2022-12-11 15:42:25 +01:00
Umherirrender
8350ab4d9d Replace deprecated PermissionManager::getGroupPermissions
Change-Id: I271473cedb1d10b8a2b9529d4af0c42f04bfcd98
2022-11-13 22:38:29 +00:00
Amir Sarabadani
7690ab4e33 Reorg: Move HeaderCallback to Request directory
Cleaning root of includes/

Bug: T321882
Change-Id: I1844da95d4fd79824646fdf4b6063cb771ca3000
2022-11-08 10:53:27 +01:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Thiemo Kreuz
67c56155c7 Replace trivial usages of code in strings with concatenation
This is really hard to read. What is code, what is string? These
places are so simple, they really don't need the "{$var}" syntax.

Change-Id: I589dedb8c0193eec4eef500bbb896b5b790b727b
2022-08-26 12:26:44 +00:00
Reedy
8016d7262f maintenance: Replace some usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: Id1a2d0dedd3326083b6a9727f1ab68ddd8f65df8
2022-02-24 12:52:05 +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
Ppchelko
bdb5f394d3 Revert "Enhance GroupPermissionsLookup and use it."
This reverts commit 900c6663b0.

Reason for revert: breaks Parsoid CI. Instead of fixing the test in presence of the FlaggedRevs hook, I would rather convert DefaultPreferencesFactory to Authority and fix the tests once instead of doing it twice.

Change-Id: Iaa440a9804c9ed97339e737162ef64ccf29ceb51
2021-01-12 04:48:49 +00:00
Petr Pchelko
900c6663b0 Enhance GroupPermissionsLookup and use it.
Added new methods:
- ::getGroupsWithAnyPermissions
- ::getGroupsWithAllPermissions
- ::groupHasAnyPermission
- ::groupHasAllPermission

Replaced relevant calls to PermissionManager with
calls to GroupPermissionsLookup.

Bug: T254537
Change-Id: I0b9c3352c5bebc94e1649239fe0527144e7c2eb2
2021-01-11 11:05:54 -06:00
DannyS712
3c0268da7a thumb.php - wfExtractThumbParams can return null
Change-Id: If0450a185966141b3ab59451b6136ac31de6d345
2020-12-17 06:22:46 +00:00
Paladox
df95c45ad2 Introduce new wgThumbPath config
This fixes behaviour introduced by 507501d6ee.

$relPath returned false.
This "substr( $requestPath, 0, strlen( $basePath ) ) !== $basePath"
returned true, thus returned false.
$requestPath returned "/w/thumb_handler.php/7/7d/Cloudflare_dashboard_3.png/800px-Cloudflare_dashboard_3.png"
$basePath returned "/metawiki/thumb/".

Introducing wgThumbPath resolves this by allowing us to set it to
"$wgScriptPath/thumb_handler.php".

Bug: T266619
Change-Id: If9430b5b4b5db2670bb3e361b03795871aed65da
2020-10-28 02:36:30 +00:00
Timo Tijhof
8f6b0723af docs: Improve entry point documentation
* Unlink the word "Action" in api.php description, which was unhelpfully
  being autolinked to the index.php Action baseclass.

* Add links in the first sentence to the primary classes involved in
  their handling so that the "Entry points" overview page includes
  these links (subsequent sentence/paragraphs require an additional
  click).

Change-Id: Ibe882746ea7753d5d4c90a04f6974ea807122d1c
2020-07-02 02:07:25 +00:00
Tim Starling
63b0fa3590 In Web entry points, move file scope code into a main function
Avoid leaking local variables into the global scope by accident, by
moving the entry point code to a function.

In index.php, document the intentional $mediaWiki global so that
nobody removes it by accident.

Change-Id: Ie1a181ae3ebdda90cd2321f0c1b50e31fb0d586e
2020-06-25 11:31:45 +01:00
Tim Starling
507501d6ee Stop using SCRIPT_NAME where possible, rely on statically configured routing
It has become apparent that $_SERVER['SCRIPT_NAME'] may contain the same
thing as REQUEST_URI, for example in WMF production. PATH_INFO is not
set, so there is no way to split the URL into SCRIPT_NAME and PATH_INFO
components apart from configuration.

* Revert the fix for T34486, which added a route for SCRIPT_NAME to the
  PathRouter for the benefit of img_auth.php. In T235357, the route thus
  added contained $1, breaking everything.
* Remove calls to WebRequest::getPathInfo() from everywhere other than
  index.php. Dynamic modification of $wgArticlePath in order to make
  PathRouter work was weird and broken anyway. All that is really needed
  is a suffix of REQUEST_URI, so I added a function which provides that.
* Add $wgImgAuthPath, for use as a last resort workaround for T34486.
* Avoid the use of $_SERVER['SCRIPT_NAME'] to detect the currently
  running script.
* Deprecated wfGetScriptUrl(), a fairly simple wrapper for SCRIPT_NAME.
  Apparently no callers in core or extensions.

Bug: T235357
Change-Id: If2b82759f3f4aecec79d6e2d88cd4330927fdeca
2020-04-01 12:33:38 -04:00
Umherirrender
e28b4bd8af Use MediaWikiServices::getRepoGroup in file related classes
Change-Id: Iceec961de4f0cc689f7d3b981afac923b46c98f6
2020-03-14 12:36:27 +00:00
Timo Tijhof
7639aa869a docs: Add api.php to "API" doc group
Follow-up bc1f601382, which added a group to load.php, but I forgot
to add api.php to its group.

Also, fix the pre-existing group that thumb.php and thumb_handler.php
were a part of. It looks like the entire "Media" group was not
defined anywhere, so it was ignored by Doxygen. This is now fixed.

Change-Id: Iba487aac5883f66b81f2496a38a3c978d5e6600b
2020-02-05 22:53:25 +00:00
Timo Tijhof
bc1f601382 docs: Improve "Entry points" documentation page
Turn this into a doc group, and let the descriptions come
directly from the files in question. This makes the list easier
to maintain, and alsom means that the overview page becomes
discoverable whenever one is looking at the entry point file
as well. Previously the doc page pointed to the entry points,
but not the other way around. This is also fixed.

Bug: T244294
Change-Id: I891c5a37e17592edc1136d7367949927121c8bc8
2020-02-04 21:44:38 +00:00
daniel
a7eb0fad72 thumb.php: Use 'thumbnail' channel to report errors
The 'thumb' channel was being ignored.

Quoting Timo:
Those two lines using thumb are the only two in the
codebase that use that channel. The previous one being
introduced in 2015 and never enabled in prod from what
I can see. There is however a more common thumbnail
channel enabled in prod.

Bug: T225197
Change-Id: Icf25135baf3de09a8a734bb32b0364990b465a42
2020-01-16 00:15:30 +01:00
jenkins-bot
a2df6d34ea Merge "thumb.php: don't try to send errors after data has been sent." 2020-01-14 21:27:27 +00:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
daniel
c771f252f3 thumb.php: don't try to send errors after data has been sent.
If an error ocurrs after output streaming has already started, don't try
to report the error to the user. Just log it internally.

Bug: T225197
Change-Id: I8fd02987844161cf2fcb6cbe5a08e211256c3d4d
2020-01-07 20:50:34 +01:00
Paladox
10cfb5ca59 Remove space from strings
Change-Id: Id81dab1d806f2b93b5bad47cfd2a9fa37dedcd02
2019-12-23 22:42:40 +00:00
Reedy
8e6926212a Don't redefine MW_ENTRY_POINT in thumb.php if already defined
Bug: T241340
Change-Id: I95914267bf22910391a54ec524ed11bc076f83e3
2019-12-23 18:19:13 +00:00
Aaron Schulz
4f11b61454 Avoid using "enqueue" mode for deferred updates in doPostOutputShutdown
Set appropriate headers and flush the output as needed to avoid blocking
the client on post-send updates for the stock apache2 server scenario.
Several cases have bits of header logic to avoid delay:

a) basic GET/POST requests that succeed (e.g. HTTP 2XX)
b) requests that fail with errors (e.g. HTTP 500)
c) If-Modified-Since requests (e.g. HTTP 304)
d) HEAD requests

This last two still block on deferred updates, so schedulePostSendJobs()
does not trigger on them as a form of mitigation. Slow deferred updates
should only trigger on POST anyway (inline and redirect responses are
OK), so this should not be much of a problem.

Deprecate triggerJobs() and implement post-send job runs as a deferred.
This makes it easy to check for the existence of post-send updates by
calling DeferredUpdates::pendingUpdatesCount() after the pre-send stage.
Also, avoid running jobs on requests that had exceptions. Relatedly,
remove $mode option from restInPeace() and doPostOutputShutdown()
Only one caller was using the non-default options.

Bug: T206283
Change-Id: I2dd2b71f1ced0f4ef8b16ff41ffb23bb5b4c7028
2019-09-30 22:59:59 +00:00
DannyS712
fb654ae087 Fix a typo (folow -> follow)
Bug: T201491
Change-Id: I1083f6f0e29b9f3e9c2d0dd2bdb9e1f524327c0a
2019-09-13 16:05:16 +00:00
jenkins-bot
1880c8401a Merge "Add MW_REST_API and MW_ENTRY_POINT" 2019-09-09 15:29:21 +00:00
Tim Starling
0c0676c34e Stop mangling $_GET and provide WebRequest::getQueryValuesOnly()
I doubt there was ever a good reason for mangling $_GET to add the
title, this was just b/c for the sake of b/c. It was formerly used in
core but that was so long ago that I doubt there was any usage in
extensions at the time. Now there is one usage of $_GET['title'] in an
unmaintained extension, but it was only added in 2017.

Also I added WebRequest::getQueryValuesOnly() which is an interface to
the unmodified $_GET. The motivation is allowing OAuth to work with the
REST API, since OAuth needs an unmangled view of $_GET for signature
generation. The Action API gets around the problem with a special hack
in interpolateTitle(), disabling it for the Action API only.

A review of callers of getQueryValues() suggests that many would
benefit from using getQueryValuesOnly() instead. But I only changed it for
callers in api.php and thumb.php since the effect of the change there is
certainly beneficial, whereas callers under index.php may possibly be using
the path parameters to construct self-links.

Rest\RequestFromGlobals uses $_GET directly, which means that this
change causes it to not return PathRouter matches as GET parameters
anymore.

Change-Id: Ic469577fae17c0b1ac69466df7bc9f03e61c74e3
2019-09-05 15:00:28 +10:00
Tim Starling
b7ce7aacb0 Add MW_REST_API and MW_ENTRY_POINT
Define the global constant MW_REST_API in rest.php, by analogy with
MW_API. Also generalize this by adding MW_ENTRY_POINT, which contains
the entry script name, "cli" or "unknown". This allows tests such as

  if ( MW_ENTRY_POINT !== 'index' )

which is probably what is really intended by defined('MW_API') in many
cases.

Change-Id: I24099f4cdd170de17afd6e1bbad67c9b204071fc
2019-09-03 11:43:18 +10:00
Petr Pchelko
acaa3e3136 Remove deprecated User groups/permission static calls.
Bug: T220191
Change-Id: Ifa8afa90c432723b0bba0033a46b6a499c77e6fc
2019-08-21 19:42:01 -07:00
jenkins-bot
61544d6eb2 Merge "Migrate remaining usages of Title::userCan() to PermissionManager" 2019-06-14 11:19:47 +00:00
Gergő Tisza
e25c45e2e3 Log headers sent errors more usefully in thumb.php
Bug: T225197
Change-Id: Ifcb02b3d5794061f27c005b32164ac014f926357
2019-06-06 15:13:49 +00:00
Máté Szabó
6420c79320 Migrate remaining usages of Title::userCan() to PermissionManager
T208768 introduced the PermissionManager service that can now be used
for page specific permission checks. This change replaces remaining calls
to Title::userCan() with the new service in MediaWiki core.

Bug: T220191
Change-Id: Ie45e0cb6aa49a8c66147b470946161fc18160fc1
2019-06-03 13:03:46 +02:00