Commit graph

57 commits

Author SHA1 Message Date
Timo Tijhof
be2dbcc219 ResourceLoader: Follow-up creation of ResourceLoaderEntryPoint
Follows-up Iadea44b7867f48a2be6ccbf00c0e56911a5af74e.

ResourceLoaderEntryPoint:
* Rename from Resource to ResourceLoader, as it is the entry point
  for ResourceLoader.
* Fix accidental use of ingroup on the file docblock
  instead of the class.
  https://phabricator.wikimedia.org/F42046908
* Fix broken "see" reference to "/load.php" on the ResourceEntryPoint
  class on doc.wikimedia.org. Files are indexed in Doxygen by full
  name without leading slash.
* Remove load.php from docgroup, akin to index.php.

tests:
* Remove unrelated Rest namespace from test suite.
* Remove redundant default values in newResourceLoader(),
  especially null values were confusing by showing an
  apparent intent to set a value without actually
  isplacing the default, given that isset/?? treat
  set null as not set.
* Simplify test by using the built-in startup module instead.

EntryPoint:
* Remove comment in test about doPostOutputShutdown.
  It sounded like it was explaining that we use getCapturedOutput()
  instead of run() because the latter calls doPostOutputShutdown
  which we want to avoid. Except, we don't avoid it,
  since run() is called and does call doPostOutputShutdown.
  Unclear what it was explaining.
* Improve docs around getCapturedOutput() in the base class,
  and make explicit that this seemingly unused complexity
  exists for the purpose of testing.

Bug: T354216
Change-Id: I5139fda90a3d5ac7ea1ed917c8045d1a09961d78
2024-02-22 22:30:39 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
daniel
4ea8c705a3 ResourceLoader: Factor out ResourceEntryPoint from load.php
The idea is that all entry points should share the code in the
MediaWikiEntryPoint base class. This change by itself doesn't achieve much, it should be followed up by a change moving request handling logic from ResourceLoader into ResourceEntryPoint.

Bug: T354216
Change-Id: Iadea44b7867f48a2be6ccbf00c0e56911a5af74e
2024-02-02 17:06:31 -05:00
Amir Sarabadani
788d2f0a28 Centralize logic behind building ChronologyProtector object
Building blocks of CP don't really need to depend on LBF. Even the
config value for CP stash type is also different. But it's being passed
around along the rest of LB/LBF config and possibly down to the DB
object.

This is making the code much harder to understand, adds more coupling
than it needs to, and it's making pieces that don't need to rely on LFB
(like load.php) actually depend on LBF just to disable CP.

This clean up also helps improving DI of LB/LBF and building of DB
objects down the road.

Bug: T275713
Change-Id: Ic27269a1f1190ee7a03c6a422ada7ff293c3cab1
2023-08-30 18:44:09 +00:00
Timo Tijhof
85892edce5 resourceloader: Minor doc changes following PSR-4 namepace change
Follows Id08a220e1d60 (after I92998ae6a82e).

Change-Id: I33d20201bfee4595baa39c01eaf8b7de6034a8ed
2022-05-29 16:41:19 +00:00
Tim Starling
3e2653f83b ResourceLoader namespace (attempt 2)
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader itself.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Revert of a241d83e0a.

Bug: T308718
Change-Id: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659
2022-05-24 15:41:46 +00:00
Lucas Werkmeister (WMDE)
a241d83e0a Revert "ResourceLoader namespace"
This reverts commit e08ea8ccb9.

Reason for revert: Breaks Phan in extensions, and as far as I’m aware,
this change isn’t urgently needed for anything, so the simplest fix is
to revert it again for now. After PHP 7.4 it should be safer to try this
again (we hopefully won’t need the two “hack” classes by then).

Bug: T308443
Change-Id: Iff3318cbf97a67f821f78e60da62a583f63e389e
2022-05-16 14:43:33 +00:00
Tim Starling
e08ea8ccb9 ResourceLoader namespace
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader and
ResourceLoaderContext.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Change-Id: I92998ae6a82e0b935c13e02a183e7c324fa410a3
2022-05-16 14:41:27 +10:00
Umherirrender
0d390c46c9 resourceloader: Avoid repeatly calls to getter functions
Use local variable instead

Change-Id: If90f510558a138b2294a57c7bbb9dc53ea355f9c
2021-09-26 01:55:13 +02: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
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
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
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
Tim Starling
164a3ac1f0 Remove IE 6 security features from server-side code
* Deprecate WebRequest::checkUrlExtension() and have it always return
  true. This reverts the security fixes made for T30235.
* Remove IEUrlExtension. This is a helper for checkUrlExtension() which
  is not used in any extensions.
* Remove CSS sanitization code which is specific to IE6. This reverts
  the changes made to fix T57332, and related followups. I confirmed
  that the relevant test cases do not result in XSS on IE8.
* Remove related tests.

Bug: T232563
Change-Id: I7318ea4a63210252ebc64968691d4f62d79a63e9
2019-11-28 15:11:56 +11: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
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
Timo Tijhof
8a87ec2778 profiler: Centralise output responsibility from ProfilerOutputText to Profiler
Make it Profiler.php's responsibility to enforce this, based on the
existing signal from ProfilerOutput::logsToOutput().

The ProfilerOutputText class should not have to double-check this
a second time.

Long-term, I'd like even this check in Profiler::logDataPageOutputOnly
to be removed, because really the external caller of that should
know whether it is safe to output stuff or not rather than stashing
its own state inside Profiler::$allowOutput and then implicitly
reading it back out again later on. But, that's for another time.

Also:
* Remove use of deprecated Profiler::setTemplated while at it.
* Make 'visible' parameter explicit, as for other parameters.

Change-Id: Iaa3fc4ea25a059b90235d769db60c04b8f152f05
2019-08-28 16:07:18 +00:00
Timo Tijhof
a186dc62fd resourceloader: Instantiate main class via ServiceWiring
It also removes some code duplication which is nice.

This unlocks various future changes, including:

* Making the `$config` parameter mandatory for the ResourceLoader class
  constructor, which currently falls back to global state.
  This should be deprecated and removed.

* Making it possible to instantiate the ResourceLoader class
  without all the default MW modules being registered from
  global state. E.g. move MW module registration from main class
  constructor to ServiceWiring, and remove the 'EmptyResourceLoader'
  class hack from unit tests, and use regular 'new ResourceLoader'
  instead.

* Making ResourceLoader a standalone library (some day),
  e.g. allowing it to be instantiated from a basic PHP script,
  in a way that is still useful and perhaps able to serve
  (most) RL modules without MW itself.

Bug: T32956
Change-Id: I4939f296c705b268e9cf8de635e923a739410470
2019-02-18 17:55:09 +00:00
Timo Tijhof
0612ce2896 resourceloader: Disable ChronologyProtector on load.php (again)
This was already disabled in 2016 with 98c6743413 by calling
setRequestInfo() to override the default 'ChronologyProtection' value
from Setup.php.

This stopped working since 4ccb228bde which made
getDBLoadBalancerFactory (in ServiceWiring) obtains a LoadBalancer
from MWLBFactory::setSchemaAliases, and requestInfo is not
re-evaluated after that.

Bug: T192611
Change-Id: I68748e8f15bcd7bfa8d7921964788e2798682e05
2018-04-20 01:15:29 +01:00
Timo Tijhof
98c6743413 resourceloader: Disable ChronologyProtector to speed up wfGetLB()
For load.php requests, Xenon in Wikimedia production measures that half
the time for wfGetLB() is spent in ChronologyProtector::initPositions,
and its query to Memcached.

Change-Id: I24f90897e56fd679c6bd1acf764722ed58e51c67
2016-09-28 21:47:23 +01:00
Brad Jorsch
40accc9733 Enforce load.php's no-session constraint
Attempts to use session data via this endpoint will now cause exceptions
to be thrown.

Bug: T127233
Change-Id: Id83eda9564314bb4e11368aa395127f349b2cff4
2016-04-18 20:56:51 +00:00
Timo Tijhof
a2100e39c1 resourceloader: Create ResourceLoaderContext::msg() method
This makes it easier to fetch messages without having to manually
call inLanguage() on each wfMessage() call, which is currently
causing some code forget this and use plain wfMessage() which
defaults to MediaWiki user language from session.

I've considered setting $wgLang or RequestContext::getMain(),
but that's still bad since modules get passed a context in their
methods and shouldn't be using global context either.

The warnings provided by MW_NO_SESSION are exactly what we want.

Change-Id: I1288fa5622d9f82d21bb66c8eb6518b90e7cddb4
2016-03-11 00:22:33 +00:00
Brad Jorsch
8b4c9c1131 Log violations of load.php's no-session constraint
Bug: T127233
Change-Id: I3d9538b36f707ed69c2d163ccf1f807af4b02fc0
2016-03-07 20:25:43 +00:00
Timo Tijhof
49bd40cc3f resourceloader: Remove PHP4-compat code
No longer relevant per 3df53167a2.

Change-Id: I23b82fd699f7f61eba5d1828f5007d398cf7b159
2016-02-25 21:00:56 +00:00
umherirrender
54c1e18eec Remove various double empty newlines
The double empty newline is not needed between functions, variable or at
end of file

Change-Id: Ib866a95084c4601ac150a2b402cfa184ebc18afa
2015-12-27 18:55:12 +00:00
Timo Tijhof
3df53167a2 Remove PHP detection from entry points other than index.php
The following entry points already didn't have it:

* opensearch.php
* thumb.php
* thumb_handlers.php

Now removed from api.php and load.php as well. The check was broken
because these entry points use the 'use' keyword for PHP namespaces,
which results in a syntax error on PHP < 5.3.

The check remains in index.php, mw-config/index.php, and
Maintenance (for e.g. install.php).

Bug: T112942
Change-Id: I9026d69ddfb3e02612256b4a9df525c432bb33c6
2015-11-12 22:36:50 +00:00
Timo Tijhof
afcfc3290c resourceloader: Consistently refer to the framework as ResourceLoader
Change-Id: Ia59e4eac9662723e80d62f7cfcb9e4292e3ee4de
2015-10-28 03:24:40 +00:00
Timo Tijhof
636cc420c6 resourceloader: Make ResourceLoader logger aware
Change-Id: Ifa197cce1906bc0530dfa873dfde91abbe540637
2015-06-04 20:13:14 +00:00
Aaron Schulz
016fd0b776 Refactored entry points to have uniform shutdown handling
* Added doPreOutputCommit() and doPostOutputShutdown(),
  which most entry points just using the later
* Also fixed problem where text profiling did not show up
* Avoid calling triggerJobs() in the file streaming
  entry points

Bug: T100127
Bug: T100085
Change-Id: Ibc7e768fd483389a01847f08cdeba4058c853d3f
2015-05-29 20:40:46 +00:00
aude
9880d5b60b Check for dependencies in entry point and Maintenance.php
This way, if someone tries to install MediaWiki via
either web installer or install.php maintenance script,
after obtaining from git, they get some useful information
on what to do.

Put the checks alongside the php version check, as
stuff installed via composer (mustache / lightncandy)
is used for NoLocalSettings.php and install.php
attempts to use logging stuff.

Also tried to make PHPVersionError look slightly nicer,
with some <h2> elements and more padding for the <p>
elements.

and centralized this code in one place, as much as possible,
for improved ease of maintenance.

Bug: T90438
Bug: T88951
Change-Id: Iae4eb42c4266dbe9213c5de8a96fccfbeaa9acb0
2015-05-23 15:05:11 +00:00
Aaron Schulz
e58e4b498d Flush lazy jobs in load.php and api.php too
* A more proper solution will have one method for all this stuff

Bug: T99775
Bug: T99849
Change-Id: I16a32b260386a85504eb85ea58f1156b4e581a83
2015-05-20 16:01:51 -07:00
Aaron Schulz
3ca6ab1031 Made text profiling actually work with load.php
Change-Id: I8d28ad8669e8c2f5d7025fe67fb75d0551975e07
2015-03-31 17:51:50 +00:00
Aaron Schulz
4ff8136807 Removed remaining profile calls
Change-Id: I31c81c78715048004fc8fca0f27d09c1fa71c118
2015-01-08 02:49:33 -08:00
Bartosz Dziewoński
e65d02d585 Make load.php parse in PHP 4 again
Not sure what for, but if it "needs" to parse, then let's make it parse…

Change-Id: I28ec3b3a86f6eb90e3341f967649fb4c910966d7
2014-11-04 17:33:01 +00:00
Kunal Mehta
0e17070d40 Require PHP >= 5.3.3
Bug: T839
Change-Id: Iac827ef8505ff0653a40e45d759b0f79619351ee
2014-10-30 10:10:52 -07:00
Kunal Mehta
1d9d9b4d76 resourceloader: Pass a Config to the ResourceLoader constructor
Instead of relying on the default being main, which is deprecated.

Change-Id: I200e2c2dc922ae1fa5fa68d449403d0287e41786
2014-09-05 22:59:45 +00:00
Chad Horohoe
a4334bbef5 Use PHP_VERSION constant instead of phpversion() function call
Change-Id: Ifb3d1bd92d6abaa561e7337b311b4cb10c38a2b6
2014-07-09 16:46:35 -07: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
Tim Starling
1fe9340bb3 Remove hphpc support and deprecate related functions
hphpc has been superseded by hhvm, so support for hphpc is no longer
needed.

* Continue to use Preprocessor_Hash under HipHop since it is still
  faster under hhvm
* Keep $wgCompiledFiles for now, so that wikihiero doesn't give an error
  before Ic9d1e795 is merged
* Migrate the run-server script and associated configuration file to
  hhvm. Enable EnableStaticContentFromDisk since it doesn't seem
  ridiculously inefficient at first glance. Run from $IP rather than
  $IP/.. since hhvm is apparently not picky about sourcing files from
  outside of the current directory.

Change-Id: Ic3e769f1fbad4f7ad26dd819406796fee48c6b45
2013-05-09 08:28:05 +10:00
Hoo man
d13c6fa967 Follow up to dirname( __FILE__ ) clean up
Remove a trailing whitespace added by me in dirname( __FILE__ )
clean up and add some comments to the PHP version checks (they
can't use __DIR__ as they have to run in older PHP versions.

Change-Id: I6a7e8cb7dbf384d91dda4d0ecbef7ce588bc3073
2012-08-28 23:47:56 +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
Alexandre Emsenhuber
f27ff698fb Added missing GPLv2 headers in some places.
Also made file documentation more consistent.

Change-Id: I30e124514396f110a572467b94ca06cefd5f7b46
2012-05-23 13:41:30 +02:00
Reedy
f1bec81eba Various updates needed to bump min php version to 5.3.2
Change-Id: I22015387e4ac5839a907059086d787f352746886
2012-04-16 15:38:22 +01:00
Chad Horohoe
b91ace27d9 Clean up the mess that is wfDie (resolves r85918). wfDie() doesn't exist anymore, so don't use it.
The only two usages left since r91590 are php version checks for index/load/api.php, and $wgAPIEnabled check in api.php. Consolidate all of the "bailing for invalid version" into PHPVersionError.php. Leaving $wgAPIEnabled as the only user was silly, so just echo and die like wfDie() would've done
2011-07-06 21:01:12 +00:00
Tim Starling
97ff30ddb4 (bug 28840) If the query string hits bug 28235, redirect to a safer URL instead of showing an unhelpful error message. IE 6 will only use the extension of the final destination for its cache filename. 2011-06-03 05:32:51 +00:00
Tim Starling
ff1dc8a175 HipHop improvements:
* Added the ability to compile extensions. The build process is bootstrapped by running MediaWiki in interpreted mode. Extension setup file inclusions are slightly modified in a way that makes them register themselves for compilation. Then the same LocalSettings.php uses the compiled extension setup file when the compiled binary runs.
* Tested with Cite and ParserFunctions. The code which lets you have an extensions directory in a place other than $IP/../extensions is untested.
* Simplified WebStart.php slightly by using a custom $_SERVER variable to mark compiled mode. It will break if you don't use the supplied server.conf, but that will break a lot of things so don't do that.
* Fixed the core web entry points to include WebStart.php in compiled mode instead of interpreted.
* Made the build directory configurable. This is mostly so that I can grep the source tree without seeing loads of generated C++.
* In server.conf, added a rewrite rule allowing a /wiki/$1 article path.
* Removed server.conf log file location "/dev/stdout", breaks when you switch user
* Disable static content cache, breaks horribly when you set SourceRoot to a directory containing 7GB of files.
* Rewrote the run-server script in PHP, mostly to support the configurable build directory feature.
* Added an option to the run-server script to allow running in interpreted (hphpi) mode.
2011-05-30 13:49:09 +00:00
Tim Starling
6fec4e3fde Revert r87635, r87637, r87639, r87643 (MW_MIN_PHP_VERSION etc.): breaks HipHop support. 2011-05-15 13:21:16 +00:00
Happy-melon
7055add799 Centralise the minimum-required-php-version in a MW_MIN_PHP_VERSION constant in Defines.php. This requires loading Defines.php before the PHP4 version checks, so include a big note reminding people not to include anything other than vanilla define() statements in there.
I have a sneaking suspicion that including Defines.php in the entry points might not play nicely with HipHop, but I can't test it (wrong OS).
2011-05-07 15:16:01 +00:00