This adds unit tests for the Handler base class.
This includes tests for public and protected methods.
Since the Handler base class is an extension point, the protected methods
are part of the stable public interface.
Change-Id: Ibe9fcbb139683dad03b92cd0618c3c0e8feb8b94
Would have love to just kill Linker::normaliseSpecialPage() but
the deprecation policy has to be followed and we'll drop the above
method in 1.36.
For now, we'll just soft and hard deprecate it, also, callers have
been updated.
Dependency inject SpecialPageFactory to LinkRenderer service and
note that ->normalizeTarget() is only for internal use by Linker
& DummyLinker via their `->normaliseSpecialPage()` methods.
Also, updated unit tests to capture injecting the special page
factory class.
Change-Id: I951403c89ff497fd1f7441ad0304dd5bc9442ad7
This method returns null when $mime is 'unknown/unknown' and the file
extension is unknown to MediaWiki. The inline documentation and @return
annotation omitted this.
I don't think this was an intentional design choice, but it's the
existing behavior and I'm not sure it's safe to change.
Since it is the existing behavior, document it and add a test case, to
ensure that any changes to this behavior are intentional.
Bug: T253483
Change-Id: Ie6615a4bd9ae77e9ab59cfe76edb237cace693b1
Also rename image_redirect key to file_redirect while at it.
This assures that stale keys are not still in use.
Bug: T253405
Change-Id: I31a9bb6672b33fbfa1b974955d78fdfd8d58f5da
Some HTML parsers don't deal with this the way we want. libxml does, so
this test case passes, but I'm adding it for if we try switching to a
different HTML parser that breaks this.
Change-Id: I02d14e1d78320217646cda9691a78bcbf2005f52
..and for adding file extensions by modifying the mExtToMime field.
All three interfaces will be deprecated in a follow-up change.
Change-Id: I7ec940a8b2fe02cd0fe01593cd6897f75777a8fa
The problematic code:
$extensions = explode( ' ', $magic->getExtensionsForType( $mimeType ) );
if ( count( $extensions ) ) {
$extension = $extensions[0];
}
If $mimeType is not known to MediaWiki,
$magic->getExtensionsForType($mimeType) will return null.
explode( ' ', null ) is [""]. (Thank you so much, PHP!)
This means $extensions is nonempty (it contains the empty string), so
$extension is set to ''.
Change-Id: Icf387a9c93cb7351c2f48c69f413e7ad2224ba6b
The previous output meant that when reviewing the build output,
it was quite hard to quickly find what the problem was and in
which test because the start of the result (which mentions the
test suite) and the expected/actual diff, were often separated
by dozens or hundreds of lines of "helpful" debug logs.
These are now moved to the after the expected/actual/stacktrace
portion so that "Name of test" and "expected/actual" remain
together.
Before
> 1) ResourceLoaderFilePathTest::testGetters
> === Logs generated by test case
> …
> …
> …
> …
> …
> …
> …
> ===
> Failed asserting that two strings are identical.
> --- Expected
> +++ Actual
> @@ @@
> -'dummy/pat'
> +'bla'
> /var/mediawiki/tests/phpunit/resourceloader/ResourceLoaderFilePathTest.php:22
After
> 1) ResourceLoaderFilePathTest::testGetters
> Failed asserting that two strings are identical.
> --- Expected
> +++ Actual
> @@ @@
> -'dummy/pat'
> +'bla'
> /var/mediawiki/tests/phpunit/resourceloader/ResourceLoaderFilePathTest.php:22
> === Logs generated by test case
> …
> …
> …
> …
> …
> …
> …
> ===
Change-Id: I31f1a4b730a0dd8597a059034b4e6abdc5f48552
* Add HttpRequestFactory::createMultiClient(), which returns a
MultiHttpClient with configured defaults applied. This is similar to
the recently-deprecated Http::createMultiClient().
* Introduce $wgHTTPMaxTimeout and $wgHTTPMaxConnectTimeout which, if set
to a lower value than their defaults of infinity, will limit the
applied HTTP timeouts, whether configured or passed on a per-request
basis. This is based on the frequently correct assumption that ops know
more about timeouts than developers.
* In case developers believe, after becoming aware of this new situation,
that they actually do know more about timeouts than ops, it is possible
to override the configured maximum by passing similarly named options
to HttpRequestFactory::createMultiClient() and
HttpRequestFactory::create().
* Apply modern standards to HttpRequestFactory by injecting a logger and
all configuration parameters used by its backends.
* As in Http, the new createMultiClient() will use a MediaWiki/1.35
User-Agent and the 'http' channel for logging.
* Document that no proxy will be used for createMultiClient().
Proxy config is weird and was previously a good reason to use
MultiHttpClient over HttpRequestFactory.
* Deprecate direct construction of MWHttpRequest without a timeout
parameter
Bug: T245170
Change-Id: I8252f6c854b98059f4916d5460ea71cf4b580149
Filter out the expired items from:
* Watcher counts in an article info page (Number of page watchers,
Number of page watchers who visited recent edits).
* Mediawiki API when getting the properties `watchers` and
`visitingwatchers` for an article.
Bug: T251327
Change-Id: I48489b685f8aec2c265b316c68e626ad5126b123
Currently, MimeAnalyzer builds the internal mappings of MIME types <=> file
extensions by concatenating several string buffers in mime.type format into a
giant string, and then parsing it. The mapping of MIME types to internal
media types is built up in a similar way, except we use a dubious homegrown
format with undocumented conventions. It's a mess, and an expensive one --
~1.5% of api.php CPU time on the WMF cluster is spent building these buffers
and parsing them. Converting the mappings to PHP associative arrays makes
them much cheaper to load and easier to maintain.
Doing this without breaking compatibility with existing behaviors requires
some delicate footwork. The current mime.types buffer is made up of the
following fragments, in order:
1) MimeAnalyzer::$wellKnownTypes
2) If $wgMimeTypeFile == 'includes/mime.types' (sic!):
the contents of includes/libs/mime/mime.types.
If $wgMimeTypeFile is another file path (e.g., '/etc/mime.types'):
the contents of that file.
If !wg$MimeTypeFile, this fragment is blank.
3) MimeAnalyzer::$extraTypes (populated by extensions via hook).
The mime.info buffer is built up in the exact same way, except it's
MimeAnalyzer::$wellKnownInfo, $wgMimeInfoFile, and MimeAnalyzer::$extraInfo.
What this means in effect is that some built-in MediaWiki MIME mappings are
"baked in" (anything in MimeAnalyzer::$wellKnown*), and others can be
overridden (anything in includes/libs/mime/mime.*).
To avoid breaking backward compatibility, we have to preserve the
distinction. Thus this change has two MIME mappings, encapsulated in two
classes: 'MimeMapMinimal', which contains just the baked-in mappings, and
'MimeMap' which contains both the baked-in and overridable mappings. We also
have to keep the code for parsing mime.types and the ad-hoc mime.info format,
at least for now.
In a FUTURE change (i.e., not here), I think we can:
* Deprecate $wgMimeTypeFile in favor of a new config var,
$wgExtraMimeTypeFile. $wgMimeTypeFile is evil because if you are using to
add support for additional MIME types, you can end up unwittingly dropping
support for other types that exist in MediaWiki's mime.types but not your
file. The new $wgExtraMimeTypeFile would only be used to add new MIME
mappings on top of the standard MimeMappings, which was probably the
original intent for $wgMimeTypeFile.
* Deprecate $wgMimeInfoFile. I don't think we need to provide a replacement,
because extensions can use the hook, and I doubt anyone is using the config
var. But if we wanted to provide an alternative, we could have a
$wgExtraMimeInfoMap that has an array of extra mappings.
* Deprecate MimeAnalyzer::addExtraTypes and MimeAnalyzer::addExtraInfo, and
provide alternative interfaces that take structured input instead of string
blobs.
I tested this by dumping the internal state of MimeAnalyzer before and after
this CL using the script in Ib856a69fe, using both default and custom values
for $wgMimeInfo(File|Type).
Bug: T252228
Change-Id: I9b2979d3c9c0dee96bb19e0290f680724e718891
Clean up the recursive DB dependency mitigation logic by having
ServiceContainer detect recursion and throw an appropriate error.
Catch the error and use EmptyBagOStuff in such cases. This works
better than checking getQoS() since that begs the question by
requiring the cache instance to begin with.
Also add support for using different LoadBalancer instances for
local and global keys in SqlBagOStuff. This makes it easier to
share keys between projects.
Bug: T229062
Change-Id: Ib8ec1845bcf1b86cbb3bededa0ca7621a0ca293a
This is specifically for fatal errors, so it's fine that some
queries encounter (non-fatal) errors. Surpress them for now,
so that we can safely re-enable enforcement for everything else.
Bug: T248191
Change-Id: I962ee2dbb0568cc869fda6fa7312edc45ba43215
To support direct access to the underlying arrays as required by the
ApiQueryBaseBeforeQuery hook. It was a design goal of SelectQueryBuilder
to retain these arrays for the benefit of legacy code.
Change-Id: I523a9e53d17659ad35098e586e8a501f57e4de25
This helps preventing mistakes, for example if you don't know or you
forget to generate the sql schema for one or all of them.
Also it helps preventing malicious changes to the generated files that
might go in without much scrutiny as the manual files.
Bug: T252919
Change-Id: I50e2715a55914f7712f9925c149bd09e8265a20b
Note that some (not all) of these are flipped, listing the expected
value second. I guess this is because it's like this in QUnit.
This patch also replaces loose assertEquals() checks with the more
strict assertSame(), which should be preferred when comparing strings.
Change-Id: I5bb27a6b63ab1642fab60483647d6b663100b144