Commit graph

8833 commits

Author SHA1 Message Date
DannyS712
1e36b2c12f Hard deprecate Revision::getUserText, ::isMinor, and ::isCurrent
Bug: T250579
Bug: T250580
Bug: T250608
Change-Id: I89ac77c436245cad3e746b33aec5a42247fda67d
2020-05-26 22:19:54 +00:00
jenkins-bot
f11aee48da Merge "CreationHandler: fix redirect URL" 2020-05-26 19:07:43 +00:00
Reedy
229b2c15e8 Fix a plethora of class and function call case mismatches
Bug: T231412
Change-Id: I597a25de3294a6673424f30475760280ef209a8a
2020-05-26 14:14:46 +01:00
jenkins-bot
9d1bd65aa2 Merge "REST Handler: add unit tests for base class" 2020-05-26 10:53:00 +00:00
daniel
ad6879e6b6 REST Handler: add unit tests for base class
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
2020-05-26 10:33:36 +00:00
daniel
504e9c446f CreationHandler: fix redirect URL
Add missing version prefix to Location header emitted after successful
creation.

Bug: T253143
Change-Id: I6262f61668cefacce12ed6f2a976340e10cf105b
2020-05-25 11:13:18 +02:00
jenkins-bot
67d6d6d14a Merge "Revision: Ensure getRevisionByTitle() works for foreign wikis" 2020-05-25 01:59:01 +00:00
jenkins-bot
78b1ff0ec9 Merge "linker: Move Linker::normaliseSpecialPage to LinkRenderer class" 2020-05-24 23:31:43 +00:00
jenkins-bot
a5f1fe5827 Merge "ParserOptionsTest: Rename non-global variable $wgLang" 2020-05-24 23:31:34 +00:00
Derick A
707567bd73 linker: Move Linker::normaliseSpecialPage to LinkRenderer class
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
2020-05-24 23:11:55 +00:00
DannyS712
a8ba047008 ParserOptionsTest: Rename non-global variable $wgLang
Bug: T160814
Change-Id: I281e71e22f335427829e07b9fce25a753e7f5246
2020-05-24 23:10:55 +00:00
Ori Livneh
7c9e19ed5e mime: Document null return from MimeAnalyzer::improveTypeFromExtension()
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
2020-05-24 15:51:08 -04:00
jenkins-bot
c33ca73e03 Merge "VueComponentParser: Add test case for self-closing tags" 2020-05-23 20:01:19 +00:00
Aaron Schulz
88e17d3f7c filerepo: make LocalRepo::getSharedCacheKey() use makeGlobalKey()
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
2020-05-23 17:32:55 +00:00
Roan Kattouw
f6135a5995 VueComponentParser: Add test case for self-closing tags
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
2020-05-22 22:16:01 -07:00
Ori Livneh
9971d4dced mime: Add test for MimeAnalyzer::addExtra{Types,Info}
..and for adding file extensions by modifying the mExtToMime field.
All three interfaces will be deprecated in a follow-up change.

Change-Id: I7ec940a8b2fe02cd0fe01593cd6897f75777a8fa
2020-05-23 01:11:41 -04:00
jenkins-bot
276261bcf6 Merge "upload: Fix incorrect handling of missing file extension in UploadStash" 2020-05-23 01:08:58 +00:00
jenkins-bot
e7b6ee8b1c Merge "phpunit: Move "Logs generated by test" from middle to end of result" 2020-05-22 23:34:21 +00:00
Ori Livneh
0a82600a27 upload: Fix incorrect handling of missing file extension in UploadStash
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
2020-05-22 18:26:18 -04:00
jenkins-bot
a001686895 Merge "Hard deprecate Revision::insertOn" 2020-05-22 20:42:22 +00:00
Timo Tijhof
0c910b1684 phpunit: Move "Logs generated by test" from middle to end of result
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
2020-05-22 20:48:28 +01:00
jenkins-bot
7097484a21 Merge "Make MessageCacheTest::makePage private, return RevisionRecord" 2020-05-22 18:13:17 +00:00
jenkins-bot
b227bdd42c Merge "Respect configured default HTTP timeouts, and introduce max timeouts" 2020-05-21 20:00:45 +00:00
jenkins-bot
f40f3e8b27 Merge "Add rawTables(), getQueryInfo() and queryInfo() to SelectQueryBuilder" 2020-05-21 18:18:30 +00:00
DannyS712
d349b03db9 Make MessageCacheTest::makePage private, return RevisionRecord
Replace WikiPage::doEditContent with PageUpdater

Bug: T249393
Bug: T250638
Change-Id: I69bfe2c8e47a75171584fd0a984a4f37f88a3d4b
2020-05-21 03:25:05 +00:00
DannyS712
1c8afac4c2 Hard deprecate Revision::insertOn
Soft deprecated as part of the class in 1.31
Includes a fallback to $wgUser

Bug: T251856
Change-Id: I91702f3d541aeae37bf024a27346d7d773c29330
2020-05-21 03:22:05 +00:00
jenkins-bot
789088bc40 Merge "objectcache: dependency inject LoadBalancer into SqlBagOStuff" 2020-05-21 01:07:23 +00:00
jenkins-bot
3f2937810e Merge "mime: Convert built-in MIME mappings to PHP arrays" 2020-05-21 01:01:06 +00:00
Tim Starling
504fe2af11 Respect configured default HTTP timeouts, and introduce max timeouts
* 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
2020-05-21 09:30:57 +10:00
jenkins-bot
fedbf6ba82 Merge "Use new TalkPageNotificationManager" 2020-05-20 19:21:52 +00:00
jenkins-bot
4771b8de10 Merge "Filter out expired items from watcher counts" 2020-05-19 19:57:24 +00:00
hmonroy
763c8a6265 Filter out expired items from watcher counts
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
2020-05-19 12:13:09 -07:00
jenkins-bot
71316f93e9 Merge "phpunit: Acknowledge known dberror from SpecialPageFatalTest" 2020-05-19 09:29:23 +00:00
Ori Livneh
cb44ddf85b mime: Convert built-in MIME mappings to PHP arrays
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
2020-05-19 00:59:52 -04:00
Aaron Schulz
6a8943d8c5 objectcache: dependency inject LoadBalancer into SqlBagOStuff
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
2020-05-18 21:04:17 -07:00
Timo Tijhof
fffc34a52a phpunit: Acknowledge known dberror from SpecialPageFatalTest
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
2020-05-18 22:41:31 +01:00
jenkins-bot
752bdc2652 Merge "Call BitmapMetadataHandler functions statically" 2020-05-18 19:42:28 +00:00
Tim Starling
8c1904a4d4 Add rawTables(), getQueryInfo() and queryInfo() to SelectQueryBuilder
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
2020-05-18 14:42:42 +10:00
Tim Starling
09809678d5 Fix testAutomaticSqlGeneration: don't write to the source tree
Tests should not write to the MediaWiki source tree. They should use
temporary files.

Change-Id: Ifc8f6e3822e76493d6a750c2bc0d78262f1d2a4a
2020-05-18 12:29:18 +10:00
Reedy
f4f95e9f94 Call BitmapMetadataHandler functions statically
Change-Id: I88ff55ce68505fceffa2148ab26813c9ea2f6335
2020-05-18 00:53:43 +01:00
Reedy
5f1000f7bd Fix languages/ PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I6f88f2eaf2fc69016b99124eeb9f6e2616c148d2
2020-05-16 21:49:02 +01:00
Reedy
07faedc8c6 Fix more libs PSR12.Properties.ConstantVisibility.NotFound
Change-Id: If3bac6b0ff6fbb89bfa2b9fa91809135a76c610b
2020-05-16 20:13:22 +00:00
jenkins-bot
c54453b7e9 Merge "Add test to compare generated sql with the abstract schema" 2020-05-16 18:36:38 +00:00
Amir Sarabadani
bfe636bb18 Add test to compare generated sql with the abstract schema
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
2020-05-16 19:57:54 +02:00
Reedy
a8b006426e Fix tests/ PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I0beed1a35e046705fb84c9d1f63cf92afd009bb4
2020-05-16 04:30:21 +01:00
jenkins-bot
e1fa782031 Merge "Fix inverted assertions in ContentSecurityPolicyTest" 2020-05-15 17:58:37 +00:00
DannyS712
cc8296b309 Add Unit tests for SpamChecker service
Brings coverage to 100% (up from 0%)

Bug: T251015
Change-Id: I264f9c6cd0d9926ee73b48f33d5083c12338b09d
2020-05-15 17:02:30 +00:00
Clara Andrew-Wani
b3a5c7c0d5 Use new TalkPageNotificationManager
Bug: T239640
Change-Id: I7c06d145854ab39faaef528e169f6b51de1c8d99
2020-05-15 12:35:45 -04:00
Clara Andrew-Wani
ebcfc952ad TalkPageNotificationManager: Undeprecate passing null to setUserHasNewMessages
See: T239640#6130351

Bug: T239640
Change-Id: I27222d21383455f81f292a88f19da88a699275cf
2020-05-14 16:29:48 -04:00
Thiemo Kreuz
31b4b8d65b Fix inverted assertions in ContentSecurityPolicyTest
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
2020-05-14 19:23:37 +02:00