Commit graph

189 commits

Author SHA1 Message Date
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
Ammar Abdulhamid
1adaca51c3 Rename change_tag indexes to have ct_ prefix
Bug: T270033
Change-Id: I8a429726c99f6cadea0d671fd871f66b5611c856
2021-06-08 17:57:15 +01:00
Ammarpad
a8c01d7726 Rename name_title index to have page_ prefix
Bug: T270033
Change-Id: Id70d0e0a37dd0d000079820d51cef2791f5ec42e
2021-06-05 20:21:07 +02:00
DannyS712
e112a5c3a0 Have StructureTest not be an integration test
Does not rely on any integration, its a structure test
that ensures that all test files end in Test.php

MediaWikiUnitTestCase includes a check for the file being
under /unit, but rather than adding an exception there,
just extend the base PHPUnit test case class, since
we don't need anything from MediaWikiUnitTestCase or
MediaWikiTestCaseTrait.

Change-Id: Ie4d4dc0dd41c4d80c8347847ef72b2ce03b72042
2021-05-21 22:17:26 +00:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
daniel
fed7f0b179 Remove $actor field from UsererIdentityValue
Code that needs to store an actor ID in the database to
represent a UserIdentity, or needs to construct a UserIdentity based on
an actor ID loaded from the database, should use the ActorNormalization
service.

Note: The getActorId() method is removed from the UserIdentity interface,
but all concrete classes continue to support it for now.
UsererIdentityValue::getActorId() is hard deprecated and should
be removed in 1.37. It always returns 0.
User::getActorId() is not deprecated at this point.

Bug: T274179
Depends-On: Id2b3ddf6a2a7cdf90f8936a69148d2cce6fde237
Change-Id: I9925906d11e47efaec3c1f48d5cb3f9896a982c1
2021-04-13 18:18:06 +00:00
Ammar Abdulhamid
6a3aa5b5a2 Migrate page to abstract schema
Postgres:
 - Change page_namespace from smallint to int
 - Change page_random from numeric with arbitrary precision to float
 - Make page_touched not nullable

MySQL/SQLite:
 - Change datatype of page_title from varchar (with binary collation)
   to varbinary(255)
 - Drop default empty string from timestamp field of page_touched

Bug: T230428
Bug: T164898
Change-Id: Ibdaf332ea1da309d31d35a6ebbc1b8fefced335e
2021-03-21 12:07:12 +01:00
DannyS712
653c62053e SpecialPageFatalTest: add names to test cases
Jenkins logs show that some of the cases are slow,
but its hard to tell what special page "data set #74"
corresponds to

Change-Id: I9b2a04b35c31bedd71fa575a6d7b9634f8282031
2021-03-13 02:49:49 +00:00
Amir Sarabadani
1053405664 Rename new_name_timestamp on recentchanges to rc_new_name_timestamp
To make it have a uniform prefix for index and column names

Bug: T270033
Change-Id: I8eb600416913092bd5aeb70389bba6e8a54d1d57
2021-03-01 19:00:52 +00:00
Amir Sarabadani
4a6d4baaed Migrate recentchanges table to abstract schema
This table is massive but thankfully we fixed most of its complexities
in previous patches.

For MySQL/Sqlite:
 - Change type of rc_title and rc_source from "varchar binary" to
   "varbinary"
 - Drop default of rc_timestamp
 - Change rc_timestamp from varbinary(14) to binary(14) to standardize
   timestamp datatypes

One index doesn't follow the uniform prefix rule but since it's in a
maintenance script, will fix that in a follow up.

Bug: T230428
Bug: T42626
Change-Id: I13994e02ad3a2293148346ef7be96746578ad854
2021-02-26 13:56:56 +01:00
Timo Tijhof
245bdafd9e resourceloader: Add wikimedia/minify package and remove local copies
- JavaScriptMinifier: The public interface for this internal class is
  ResourceLoader::filter which, except for one caller (minify.php)
  is indeed consistently used already, no other callers need replacing.

- CSSMin: Idem for minification, however, this class has some other
  method as well, which have a number of internal users, but none
  outside core. These have all been replaced in this commit.

- Remove pear/net_url2 as own dependency as this was only used by CSSMin
  and recently added there. This is now a dependency of wikimedia/minify
  instead. This was not part of the public API and no longer mentioned
  here in composer.json or RELEASE-NOTES. (It remains pinned in
  mediawiki-vendor, however.)

Bug: T273247
Depends-On: Iadff8c2112d5e53bd994ab4882006e8c644a2379
Depends-On: Id3c6dcc0b952a9efe34b3a9ed88b716101a51f87
Depends-On: I589be910f57289fd908b22db87241b0e52da60d4
Change-Id: I8d71fc64aeecdb31db218b02e361ae9bb0d19b48
2021-02-24 21:03:02 +00:00
Lucas Werkmeister
293b061f29 SpecialPageFatalTest: tolerate failure to create page
Sometimes the special page can’t be created – for example, the list of
registered pages could have changed between the data provider and the
test function, due to extensions conditionally registering their special
pages. Skip the test in this case instead of crashing.

Bug: T275661
Change-Id: I573967ac22ed3a596b4f80b76d395ac948f802e8
2021-02-24 19:28:04 +01:00
Petr Pchelko
eb4e26bc03 Use Authority in special pages pagers
Change-Id: I01eccaab42759c186649d69c104318e05e91157a
2021-02-23 14:29:10 -07:00
daniel
0266b57963 Make ActorNormalization a proper service.
ActorNormalization needs to have separate wiring if we want to be able
to access it by name. This is needed to allow access to the service in
declarative wiring, e.g. via ObjectFactory specs.

As an aside, this changes SpecialPageFatalTest to not construct special
pages in a data provider. Accessing services in data providers should be
avoided. This change does not eliminate all such access, but reduces it
by deferring service lookups via ObjectFactory.

Change-Id: I5792cdcc0e5b0d1681f55dbe3e1f70c34a0cb775
2021-02-22 11:58:46 +01:00
Ammarpad
0156a47d8a Fix error message in ExtensionJsonValidation test
Exception::getMessage() always returns string, so it will
never equals boolean false, so the test will always fail, but
with a confusing error message.

Bug: T274591
Change-Id: Icd10e67a70666927eca886c829a4a3b1cd7441eb
2021-02-12 20:53:11 +00:00
Ammarpad
6e2818025f Use generator function in ExtensionJsonValidationTest
Faster run time, less code.

Change-Id: I8e7ce57c0f7b958c0c36ee6ae6c6727ef8d5c76d
2021-02-12 12:05:16 +01:00
Reedy
eb41565a9a Tests: Start marking some closures as static
Bug: T274036
Change-Id: Ib738ecd3bc23d34900bc268c8246702ac3655746
2021-02-06 19:57:42 +00:00
Umherirrender
62002cdcf1 build: Update mediawiki/mediawiki-codesniffer to 35.0.0
Change-Id: Idb413be4b8cba8611afdc022af59810ce1a4531e
2021-01-31 13:34:38 +00:00
Ammar Abdulhamid
dbd4dd19f8 Rename site_identifiers indexes to have si_ prefix
Bug: T270033
Change-Id: I6751f0fd992054b61222ece55c83d05d24af9000
2021-01-30 12:19:55 +01:00
Thiemo Kreuz
b655f382db Remove broken/outdated @param/@throws tags from @dataProviders
My personal best practice is to not document @params when there
is a @dataProvider. I mean, these test…() functions are not
meant to be called from anywhere. They do not really need
documentation. @param tags don't do much but duplicate what the
@dataProvider does. This is error-prone, as demonstrated by the
examples in this patch.

This patch also removes @throws tags from tests. A test…() can
never throw an exception. Otherwise the test would fail.

Most of these are found by the not yet released I10559d8.

Change-Id: I3782bca43f875687cd2be972144a7ab6b298454e
2021-01-21 03:42:42 +00:00
Thiemo Kreuz
2f66b3754f tests: Remove @param docs from test code that just repeat the signature
These are not only 100% identical to the actual code, but also:
* It's error-prone. Some are already wrong.
* These test…() functions are not meant to be called from
  anywhere. What is the target audience for this documentation?
* There is a @dataProvider. What such @param tags actually do is
  document the provider, but in an odd place. Just looking at
  the provider should give the same information.
* The MediaWiki CodeSniffer allows to skip @param when there is
  a @dataProvider, for the reasone listed.

Change-Id: I0f6f42f9a15776df944a0da48a50f9d5a2fb6349
2021-01-21 03:41:23 +00:00
Ammar Abdulhamid
312ed643f5 Add test to assert uniform table prefix usage in abstract schema
At the moment there are some exempted tables

Bug: T270033
Change-Id: I394ad9355193d9e9032fb80057fc2665e8f20611
2021-01-20 20:09:09 +00:00
Tim Starling
20d06b34bb Safer autoloading with respect to file-scope code
Many files were in the autoloader despite having potentially harmful
file-scope code.

* Exclude all CommandLineInc maintenance scripts from the autoloader.
* Introduce  "NO_AUTOLOAD" tag which excludes the file containing it
  from the autoloader. Use it on CommandLineInc.php and a few
  suspicious-looking files without classes in case they are refactored
  to add classes in the future.
* Add a test which parses all non-PSR4 class files and confirms that
  they do not contain dangerous file-scope code. It's slow (15s) but
  its results were enlightening.
* Several maintenance scripts define constants in the file scope,
  intending to modify the behaviour of MediaWiki. Either move the
  define() to a later setup function, or protect with NO_AUTOLOAD.
* Use require_once consistently with Maintenance.php and
  doMaintenance.php, per the original convention which is supposed to
  allow one maintenance script to use the class of another maintenance
  script. Using require breaks autoloading of these maintenance class
  files.
* When Maintenance.php is included, check if MediaWiki has already
  started, and if so, return early. Revert the fix for T250003 which
  is incompatible with this safety measure. Hopefully it was superseded
  by splitting out the class file.
* In runScript.php add a redundant PHP_SAPI check since it does some
  things in file-scope code before any other check will be run.
* Change the if(false) class_alias(...) to something more hackish and
  more compatible with the new test.
* Some site-related scripts found Maintenance.php in a non-standard way.
  Use the standard way.
* fileOpPerfTest.php called error_reporting(). Probably debugging code
  left in; removed.
* Moved mediawiki.compress.7z registration from the class file to the
  caller.

Change-Id: I1b1be90343a5ab678df6f1b1bdd03319dcf6537f
2021-01-11 11:59:36 +11:00
Umherirrender
339f86629f AutoLoaderStructureTest: Re-write slashes so test passes on Windows
A difference between UNIX and Windows is the dir separator,
which makes this test failing, because the file name does not match to
filter out the psr4 loaded classes to just keep the alias, which must be
part of the autoloader class list.

1) AutoLoaderStructureTest::testAutoLoadConfig
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'ParserTestFileSuite' => '[...]...te.php'
     'ParserTestTopLevelSuite' => '[...]...te.php'
     'SuiteEventsTrait' => '[...]...it.php'
+    'MediaWiki\Block\DatabaseBlock' => '[...]...ck.php'
+    'MediaWiki\SpecialPage\SpecialPageFactory' => '[...]...ry.php'
+    'MediaWiki\Revision\IncompleteRevisionException' =>
'[...]...on.php'
+    'MediaWiki\Revision\MutableRevisionRecord' => '[...]...rd.php'
+    'MediaWiki\Revision\MutableRevisionSlots' => '[...]...ts.php'
+    'MediaWiki\Revision\RevisionAccessException' => '[...]...on.php'
+    'MediaWiki\Revision\RevisionArchiveRecord' => '[...]...rd.php'
+    'MediaWiki\Revision\RevisionFactory' => '[...]...ry.php'
+    'MediaWiki\Revision\RevisionLookup' => '[...]...up.php'
+    'MediaWiki\Revision\RevisionRecord' => '[...]...rd.php'
+    'MediaWiki\Revision\RevisionSlots' => '[...]...ts.php'
+    'MediaWiki\Revision\RevisionStore' => '[...]...re.php'
+    'MediaWiki\Revision\RevisionStoreRecord' => '[...]...rd.php'
+    'MediaWiki\Revision\SlotRecord' => '[...]...rd.php'
+    'MediaWiki\Revision\SuppressedDataException' => '[...]...on.php'
 )

Change-Id: I1485cc7309c20d131f398473367d281a3ce78a25
2020-12-13 17:16:53 +00:00
Ammar Abdulhamid
308e6c66e1 Use generator in SpecialPageFatalTest
Slightly more performant and took less time to complete

Change-Id: I661057aa1850ecc736253ebb61e00f0199a04f59
2020-11-21 19:45:28 +01:00
Umherirrender
7dccf8c78f [ResourcesTest] Replace ReflectionObject with TestingAccessWrapper
TestingAccessWrapper wraps the reflection codes and avoids invoke etc.

Change-Id: I40e26b8bfb2386f20a8f5e763560608ba58a5de5
2020-10-30 13:34:58 +00:00
David Barratt
c36b320454
Handle CORS preflight request and prevent anon users from unsafe methods
Creates an OPTIONS handler that handles any OPTIONS requests that are
not already handled by a handler. CORS has no mechanism to ensure the
user is authenticated, so the Router will reject cross-origin requests
from anon users.

This change allows authenticated users to make cross-origin
requests if they authenticate with OAuth or if
$wgRestAllowCrossOriginCookieAuth is enabled.

Bug: T232176
Bug: T262712
Change-Id: I128b4bdbec4f6bea35142153c951fd7b79617106
2020-09-21 19:29:40 -04:00
Kunal Mehta
61c751cf89 Add structure test to verify all PSR-4 directories exist
We use AutoLoader::$psr4Namespaces to include extension entries too.

All PSR-4 directories need to exist, otherwise there's no point in trying
to autoload from them.

I verified that this test would have caught T259448 and prevented it from
happening.

Change-Id: If2df3b79a926847e443f887218ab09274ace1a44
2020-08-06 12:07:46 -07:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00
Thiemo Kreuz
5f3a92385b Fix visibility of setUp/tearDown
Change-Id: I636be48eb9f713680abac35d46091f7b49374696
2020-06-16 21:02:05 +02:00
jenkins-bot
aba6046377 Merge "Fix SpecialPageFatalTest failing on unrelated deprecations" 2020-06-05 23:10:59 +00:00
Tim Starling
b9907ca9b6 Remove DatabaseIntegrationTest::testStoredFunctions()
As was pointed out in CR on the original change from December 2011, the
test requires elevated privileges when it is run against a database with
binlogging enabled, which is a nuisance when I'm trying to test replication-
related code. The author commented that the test was to support GeoData,
but that was only true until the "schema revamp" of February 2012.

I considered mocking the database and making it into a test of
streamStatementEnd, since that code was introduced at the same time, but
we already have DatabaseMysqlBaseTest::testStreamStatementEnd().

I also removed the restoreFlags() call since that was apparently left
over from testFlagSetting(), which has been moved to DatabaseTest.

Refs:

* https://www.mediawiki.org/wiki/Special:Code/MediaWiki/107376
* https://www.mediawiki.org/wiki/Special:Code/MediaWiki/108603
* https://www.mediawiki.org/wiki/Special:Code/MediaWiki/110649
* 67f08d6990

Change-Id: I1a6b9d0cd91c8539ac1080a423b519743088733e
2020-06-02 10:47:29 +10:00
Thiemo Kreuz
9cc1cd36c0 Fix SpecialPageFatalTest failing on unrelated deprecations
Bug: T236809
Change-Id: Ibf8175c957a51befe4c4853814502bccb5d17991
2020-05-29 08:17:38 +02:00
jenkins-bot
71316f93e9 Merge "phpunit: Acknowledge known dberror from SpecialPageFatalTest" 2020-05-19 09:29:23 +00: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
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
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
Aaron Schulz
dc5c0242de phpunit: Add structure test for suite.xml registering all test suites
Follows-up 1f493dfca7.

Change-Id: I4eabc2b7238ac99d7b1f287fc73e023c45125204
2020-04-02 01:47:48 +00:00
Max Semenik
b04e62f31d phpunit: Simplify StructureTest
* Get rid of a long regexp that had to be maintained and
  was broken anyway, resulting in a false negative.
* Fix that false negative.
* Make the failures array a bit more readable.

Bug: T248075
Change-Id: I4e4e5d6487d23b0d64f29c113d84bddce758e516
2020-03-29 15:40:45 +00:00
Clara Andrew-Wani
dffacb0057 Update RestStructureTest to include HTTP Method
Change-Id: If05ba2884ba8e256c7fee45164eee1fc2d014589
2020-03-24 11:29:39 -04:00
Tim Starling
f81462048a Add PSR-4 mappings for existing namespaces and the top level
This reduces the size of the class map ($wgAutoloadLocalClasses),
and allows new classes and namespaces to be added without modifying
the class or namespace map as long as they conform to PSR-4.

Adding a PSR-4 mapping for the top-level MediaWiki namespace means that
conforming subnamespaces do not need to be listed.

I did not add some odd or broken cases, since I figure it's better to
fix them by moving the files, which can be done in a separate commit.

I removed testPSR4Completeness, since PSR-4 completeness is no longer
required, that's the point.

Bug: T166010
Change-Id: Ie5e50ecb519b99a1197688c046c7be245ce6da1b
2020-03-10 21:08:30 +11:00
Thiemo Kreuz
e1dd371e11 Make use of PHPUnit's assertCount feature where possible
… and avoid assertEmpty() on arrays, in favor of a much more strict
assertSame( [] ).

Change-Id: I20266b0b1fc38a3a87666ba1b0793cb2b37d94a9
2020-03-02 15:58:41 +00:00
Tim Starling
44d51cb04e Fix the namespace of SpecialPageFactory
Follows-up d4045035b0.

This class was added to the MediaWiki\Special namespace, contrary to the
plan in T166010 which reserves that namespace for core special pages.
Instead, use MediaWiki\SpecialPage, following the directory in which it
is located.

Also, fix two bugs which prevented the introduction of a namespaced
class alias.

Bug: T166010
Change-Id: I6e31340aaae32a89beb7e45b79d76a7fea9808d2
2020-02-21 13:46:19 +11:00
Petr Pchelko
204fa7e509 Remove usages of deprecated Language methods
Change-Id: Iad3375b141b1d87c890baec6ecd16ed92f93e699
2020-02-16 00:45:48 +00:00
jenkins-bot
879488996e Merge "resourceloader: Separate style processing from style file loading" 2020-02-12 21:09:32 +00:00
Roan Kattouw
ca7fa28615 resourceloader: Separate style processing from style file loading
ResourceLoaderFileModule::readStyleFile() both reads a style file from
disk and processes it through LESS, CSSJanus and CSSMin. Factor out the
processing part into ResourceLoaderFileModule::processStyle(), which
takes a string of unprocessed CSS/LESS rather than a file. This is
needed for future support for styles that don't come (directly) from a
file, but are generated through packageFiles.

Other changes:
- Use a hash of the source instead of the file name in the cache keys
  for the LESS compilation output
- Also prefix the cache key with 'resourceloader' while we're changing
  it anyway
- LESS compilation no longer adds the source file itself as a dependency
- Don't pass down $flip, just use $this>getFlip()

Change-Id: I86e880d06af724f0fbae93e042c85e0395771912
2020-02-12 20:23:24 +00:00
Timo Tijhof
f43d5c26bb resourceloader: Speed up structure/ResourcesTest
Avoid data providers for dynamic expansion over all JS, CSS
and images files known to MW and extensions (1000+), because
there's non-trivival overhead in PHPUnit for creating a separate
"test" wrapper and iteration for each.

Instead, make each group a single test with each of the checks
being an assertion within that.

Reduces test count of 'php phpunit.php structure/ResourcesTest.php'
(with MW core + Vector + Minerva installed) from 1039 tests to
37 tests, and reduces runtime from ~1.6min to ~40sec.

This is the same pattern I previously adapted in a5a672b1a5
for the biggest part test of this suite (dependency verification),
but I forgot to apply it to all the others.

Bug: T225730
Change-Id: Iae46b2d9ff8cd70aa6e64aaddf6ccf839591153b
2020-02-12 17:06:26 +00:00
Holger Knust
f60d04d3ea resourceloader: Add test to validate existence of ImageModule "images" files
New data provider and test method were added to ensure file paths are correct and the file is present.

Bug: T231430
Change-Id: Iadafe0df1104de8829ea87632d65b3008cf80d76
2020-02-12 14:04:33 +00:00
jenkins-bot
9b2199bcf1 Merge "ApiDisabled: Correctly fall back to api-help-no-extended-description" 2020-02-12 00:11:14 +00:00
ArtBaltai
30e54b3962 Introduce ContentHandlerFactory
Added:
- ContentHandlerFactory
Tests:
- PHPUnit
Changed
- Calls of changed and deprecated
- DI for some service/api
Deprecated:
- ContentHandler::* then similar to ContentHandlerFactory
- ContentHandler::getForTitle
- ContentHandler::$handlers

Bug: T235165
Change-Id: I59246938c7ad7b3e70e46c9e698708ef9bc672c6
2020-02-07 00:53:51 +03:00